-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemoryGraph.h
206 lines (175 loc) · 5.92 KB
/
MemoryGraph.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#pragma once
#ifndef MEMORYGRAPH_H
#define MEMORYGRAPH_H
#include "storage\GraphLoader.h"
#include "storage\GDBEdge.h"
#include "storage\IdAlloter.h"
#include <iostream>
#include <map>
#include <unordered_map>
#include <fstream>
#include <string>
#include <vector>
#include <set>
#include <unordered_set>
#include <algorithm>
using namespace std;
class GraphLoader;
struct LabelVList
{
public:
int label;
unordered_set<int> vList;
};
struct degmodel
{
int degree;
int node_id;
};
static bool mydegcomp(const degmodel& a, const degmodel& b)
{
return a.degree < b.degree;
}
struct DegreePos {
int degree;
int pos;
};
class MemoryGraph {
public:
MemoryGraph();
MemoryGraph(vector<int> n, unordered_map<int, unordered_map<string, string>>* na
, unordered_map<int, unordered_map<int, unordered_map<string, string>>>* ea
, vector<unordered_map<int, vector<int>>>* oe, vector<unordered_map<int, vector<int>>>* ie, int labnum
, vector<int>* nl = NULL, bool pre = true);
MemoryGraph(vector<int> n, unordered_map<int, unordered_map<string, string>>* na
, unordered_map<int, unordered_map<int, unordered_map<string, string>>>* ea
, vector<unordered_map<int, vector<string>>>* oe, vector<unordered_map<int, vector<string>>>* ie, int labnum
, vector<string>* nl = NULL);
MemoryGraph(string file, string labelfile="");
MemoryGraph(MemoryGraph* mg);
~MemoryGraph();
void setInfo(int nnum, int cnum, int nodetype, int commtype, string path, string ndval, string commdvale);
void initIdAlloter();
//void loadFromFile(string file, string labelfile="");
//void loadNetworkFromFile(string file);
void initAfterLoadNetwork();
//void loadLabelFromFile(string file);
void preprocess();
int communityNum;
int nodeNum;
int labelnum;
//int edgeNum;
int maxCommSize;
bool hasNodeLabel;
bool hasEdgeLabel;
GraphLoader* gLoader;
bool istemporal;
bool loadtemporal;
vector<int> nodes;
vector<int> communities;
//set<int> graphNodes;
//vector<vector<int>> communityNodes;
// unordered_map<int, vector<int>> communityNodes;
vector<vector<int>> nodeInfo; //0 - Community, 1 - Label
vector<int> nodeLabels;
vector<vector<vector<unordered_set<int>>>> commNetworkSet; // node - community - label - neighbours
vector<unordered_map<int, vector<int>>> netWorkSet;//±£´æËùÓб߱ãÓÚ²éÕÒ
unordered_map<string, vector<int>> temporal_info;
vector<unordered_map<int, vector<vector<int>>>> temporal_network;
vector<vector<int>> netWorkVec;
//unordered_map<int, unordered_map<int, unordered_set<int>>> netWorkSetComm;
//vector<unordered_set<int>> inNetWorkSet;
//vector<vector<int>> inNetWorkVec;
vector<vector<vector<vector<DegreePos>>>> degreePosOut;
vector<vector<vector<vector<DegreePos>>>> degreePosIn;
vector<vector<vector<vector<int>>>> commOutBoundary;
vector<vector<vector<vector<int>>>> commInBoundary;
//vector<vector<unordered_map<int, unordered_map<int, int>>>> twoHopLimitation;
vector<vector<vector<unordered_map<int, int>*>>> twoHopLimitation;
//vector<vector<vector<vector<int>>>> twoHopLimitation;
vector<vector<vector<bool>>> hasTwoHopComms;
vector<vector<vector<vector<bool>>>> len4Limitation;
vector<vector<vector<bool>>> triangleLimitation;
vector<vector<vector<vector<vector<bool>>>>> len5Limitation;
//vector<vector<vector<vector<int>>>> hasTwoHopLabels;
vector<vector<int>> commTotalNumTag, commMaxNumTag;
//int** commTotalNumTag;
//int** commMaxNumTag;
unordered_map<int, unordered_map<int, unordered_map<int, degmodel>>> commOuts, commIns;
//unordered_map<int, unordered_set<int>> graphEqualNodes;
//unordered_set<int> includedNodes;
//unordered_map<int, unordered_map<int, unordered_set<int>>> needMoreSet;
void readCommunity(const string& pathFile);
bool inMemory;
int outMaxDegree;
int inMaxDegree;
int maxDegree;
vector<vector<int>> labelList;
//vector<vector<LabelVList*>> labelNetWorkVec; // include all labels, without is null
unordered_map<int, unordered_map<string, string>> nodeAttributes;
unordered_map<int, unordered_map<int, unordered_map<string, string>>> edgeAttributes;
vector<unordered_map<int, vector<int>>>* outedges;
vector<unordered_map<int, vector<int>>>* inedges;
vector<vector<int>>* invec;
vector<vector<int>>* outvec;
vector<int>* outvecp;
vector<vector<LabelVList*>>* labelEdgesVec;
unordered_map<int, unordered_set<int>> neighLabels;
// subgraph matching related
int* degrees;;
double avgdegree;
int* largerbound;
int edgenum;
vector<int> idMapping;
// temporal combo searching related
int t_edge_num;
// Storage related
int nodeIdAlloterType, communityIdAlloterType; // 0 - i2i, 1 - s2i
union {
IdAlloter<int>* i2iAlloter;
IdAlloter<string>* s2iAlloter;
} nodeIdAlloter;
union {
IdAlloter<int>* i2iAlloter;
IdAlloter<string>* s2iAlloter;
} communityIdAlloter;
vector<vector<int>> communityNodes;
vector<unordered_set<int>> nodeCommunitySet;
vector<unordered_map<int, vector<int>>::iterator> destIter;
vector<vector<int>::iterator> typeIter;
vector<int> nodeEdges;
vector<int> initialNodes;
unordered_set<int> graphNodes;
vector<EdgePos> edge_dest_head;
vector<unordered_set<int>> nodeblock;
unordered_map<int, int> nodeType;
unordered_map<int, int> node_startEdge;
void releaseNetwork();
void initNetwork(int n);
void initCommunity(int m, int n);
void init(int n, int m);
bool existNode(int node);
void insertNode(int node, vector<int>& comm_id, bool resize = false);
void removeNode(int node);
bool nodeHasCommunity(int node);
int getNodeFirstCommunity(int node);
int getNodeNum();
int getCommunityNum();
int getMaxNodeId();
int getMaxCommunityId();
void reAllotNodeSpace(int nodeId);
void reAllotCommSpace(int commId);
bool hasEdge(int src, int dst)
{
return (netWorkSet[src].find(dst) != netWorkSet[src].end());
}
bool HasEdge(int src, int dst) {
return ((*outedges)[src].find(dst) != (*outedges)[src].end());
}
void addEdge(int src, int dst, int type) {
netWorkSet[src][dst].push_back(type);
// netWorkVec[src].push_back(dst);
}
void getdegrees();
};
#endif