Newer
Older
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
#include <gp-bnb/partition.hpp>
partition::partition(graph* g) : supergraph(g), outgoing_edges(0) {
// Assigns all vertices to none
for (unsigned int i = 0; i < g->num_vertices(); i++) {
vertex_assignments[i] = none;
}
// Initializes vertex counting map
vertices[sg_a] = 0;
vertices[sg_b] = 0;
vertices[none] = g->num_vertices();
}
unsigned int partition::num_vertices(subgraph sg) {
return vertices[sg];
}
void partition::assign_vertex(vertex_id v, subgraph sg) {
// Returns if v is already assigned to a subgraph
if (vertex_assignments[v-1] != none) {
return;
}
// Increments outgoing edges
for (auto const& target : supergraph->get_adjacency(v)) {
if (vertex_assignments[target-1] == -sg) {
outgoing_edges++;
}
}
// Assigns vertex to subgraph
vertex_assignments[v-1] = sg;
vertices[sg]++;
vertices[none]--;
}
void partition::unassign_vertex(vertex_id v) {
subgraph sg = vertex_assignments[v-1];
// Returns if v is not assigned to a subgraph
if (sg == none) {
return;
}
// Decrements outgoing edges
for (auto const& target : supergraph->get_adjacency(v)) {
if (vertex_assignments[target-1] == -sg) {
outgoing_edges--;
}
}
// Reverts assignment to subgraph
vertex_assignments[v-1] = none;
vertices[sg]--;
vertices[none]++;
}