-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathslicer.h
185 lines (155 loc) · 5.04 KB
/
slicer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/* slicer.h
* Copyright (C) (2011) V.A. Traag, P. Van Dooren, Y. Nesterov
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In case of any problems or bugs, please contact Vincent Traag at
* vincent (dot) traag (at) uclouvain (dot) be
*
* This software is based on the article
*
* V.A. Traag, P. Van Dooren, Y. Nesterov, "Narrow scope for resolution-free
* community detection" (2011) arXiv:1104.3083v1.
*
*/
// Originally based on:
//-----------------------------------------------------------------------------
// Community detection
// Based on the article "Fast unfolding of community hierarchies in large networks"
// Copyright (C) 2008 V. Blondel, J.-L. Guillaume, R. Lambiotte, E. Lefebvre
//
// This program must not be distributed without agreement of the above mentionned authors.
//-----------------------------------------------------------------------------
// Author : E. Lefebvre, adapted by J.-L. Guillaume
// Email : [email protected]
// Location : Paris, France
// Time : February 2008
//-----------------------------------------------------------------------------
#ifndef SLICER_H
#define SLICER_H
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include "graph.h"
#define WEIGHTED 0
#define UNWEIGHTED 1
// The file format for the slice is the following:
// First a list of node names.
// Node Name
// 1 Node A
// 2 Node B
// ...
//
// Then a list of slices:
// Slice Name
// 1 Slice A
// 2 Slice B
//
// Then a list of links in the format:
// From To Weight Slice
// 1 2 2 1
// 3 1 1 2
// ...
// Each section is started with a line containing only a '>'. The complete
// file would thus look something like this:
// >
// 1 Node A
// 2 Node B
// >
// 1 Slice A
// 2 Slice B
// >
// 1 2 2 1
// 3 1 1 2
//
// The same node can appear in various slices, connected by an interslice link.
// This means the nodes are renumbered (that is done anyhow), taking into account
// the actual slice. For example, Node 1 in Slice 1 will be renumbered to 0, and
// Node 1 in Slice 2 to 1, etc...
//
// It is assumed that if the graph is undirected, that each link is two times in the
// file. In other words, we assume it is directed.
#define NO_NULL 1
#define ER_NULL 2 //currently not implemented
#define CONF_NULL 3
#define POSITIVE 1
#define NEGATIVE -1
using namespace std;
class Slicer {
public:
struct LinkInfo
{
LinkInfo (int n, double w)
{
node = n;
weight = w;
};
int node;
double weight;
};
map<int, char*> node_names;
map<int, char*> slice_names;
//in_links[from_node][slice][neighbour_1]
//in_links[from_node][slice][neighbour_2]
//etc...
map< int, map< int, vector< Slicer::LinkInfo > > > in_links;
map< int, map< int, vector< Slicer::LinkInfo > > > out_links;
map< int, map< int, vector< Slicer::LinkInfo > > > neg_in_links;
map< int, map< int, vector< Slicer::LinkInfo > > > neg_out_links;
map< int, vector< Slicer::LinkInfo > > interslice_in_links;
map< int, vector< Slicer::LinkInfo > > interslice_out_links;
/*vector< vector< vector< Slicer::LinkInfo > > > in_links;
vector< vector< vector< Slicer::LinkInfo > > > out_links;
vector< vector< vector< Slicer::LinkInfo > > > neg_in_links;
vector< vector< vector< Slicer::LinkInfo > > > neg_out_links;
vector< vector< Slicer::LinkInfo > > interslice_in_links;
vector< vector< Slicer::LinkInfo > > interslice_out_links;
*/
map<long,int> node_map;
map<int,int> slice_map;
map<int,int> slice_rmap;
int nb_links;
int nb_slices;
int nb_nodes;
int is_directed;
int is_weighted;
int is_single_slice;
int* nb_links_per_slice;
Slicer (char *filename, double weight, int is_directed, int is_weighted, int is_single_slice);
Slicer (Slicer& s);
~Slicer();
int max_node_id;
int max_slice_id;
void readNodes(ifstream& finput);
void readSlices(ifstream& finput);
void readLinks(ifstream& finput);
void init_slice_links();
long getNodeSliceId(int node, int slice);
void setId(long nodeSliceId, int &node, int &slice);
void add_interslice_links(double w);
void clean();
void renumber();
Graph* get_graph();
void display(char *filename);
void display_node_mapping(char *filename);
void display_binary(char *filename);
void display_conf(char* filename, int modelType);
};
#endif // SLICER_H