-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsplicing.cpp
44 lines (33 loc) · 933 Bytes
/
splicing.cpp
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
#include "splicing.hpp"
Graph<MetaNode> splice (Graph<MetaNode> graph, bool optimize) {
for (MetaNode & mn : graph.nodes) {
set<int> neiToRemove;
// Looks for hub nodes
if (mn.neighbors.size() > 2) {
for (int neiIdx : mn.neighbors) {
MetaNode & nei = graph.getNodeFromIdx(neiIdx);
// If the neighbor is not from the same component
if (nei.neighbors.size() <= 2) {
// Remove the neighbor to main node link
nei.neighbors.erase(
remove(nei.neighbors.begin(), nei.neighbors.end(), mn.idx),
nei.neighbors.end()
);
neiToRemove.insert(neiIdx);
// optimize the nodes in the components that are not hubs
if (optimize) {
// TODO
}
}
}
}
for (int idx : neiToRemove) {
// Remove the main node to neighbor link
mn.neighbors.erase(
remove(mn.neighbors.begin(), mn.neighbors.end(), idx),
mn.neighbors.end()
);
}
}
return graph;
}