-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathscc_test.cpp
More file actions
142 lines (111 loc) · 4.53 KB
/
scc_test.cpp
File metadata and controls
142 lines (111 loc) · 4.53 KB
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
#include <stinger_net/stinger_alg.h>
#include "scc_test.h"
#define restrict
class SCCTest : public ::testing::Test {
protected:
virtual void SetUp() {
stinger_config = (struct stinger_config_t *)xcalloc(1,sizeof(struct stinger_config_t));
stinger_config->nv = 1<<13;
stinger_config->nebs = 1<<16;
stinger_config->netypes = 2;
stinger_config->nvtypes = 2;
stinger_config->memory_size = 1<<30;
S = stinger_new_full(stinger_config);
xfree(stinger_config);
}
virtual void TearDown() {
stinger_free_all(S);
}
struct stinger_config_t * stinger_config;
struct stinger * S;
};
TEST_F(SCCTest, UndirectedGraph) {
stinger_insert_edge_pair(S, 0, 0, 1, 1, 1);
stinger_insert_edge_pair(S, 0, 1, 2, 1, 1);
stinger_insert_edge_pair(S, 0, 1, 3, 1, 1);
stinger_insert_edge_pair(S, 0, 1, 4, 1, 1);
stinger_insert_edge_pair(S, 0, 2, 8, 1, 1);
stinger_insert_edge_pair(S, 0, 3, 5, 1, 1);
stinger_insert_edge_pair(S, 0, 3, 6, 1, 1);
stinger_insert_edge_pair(S, 0, 4, 5, 1, 1);
stinger_insert_edge_pair(S, 0, 5, 6, 1, 1);
stinger_insert_edge_pair(S, 0, 5, 7, 1, 1);
stinger_insert_edge_pair(S, 0, 7, 8, 1, 1);
int64_t nv = stinger_max_nv(S);
stinger_scc_internal scc_internal;
stinger_scc_initialize_internals(S,nv,&scc_internal,4);
stinger_connected_components_stats stats;
stinger_scc_reset_stats(&stats);
stinger_edge_update insertion,deletion;
insertion.source = 3;
insertion.destination = 8;
deletion.source = 1;
deletion.destination = 2;
stinger_insert_edge_pair(S, 0, insertion.source, insertion.destination, 1, 2);
stinger_remove_edge_pair(S, 0, deletion.source, deletion.destination);
stinger_scc_insertion(S,nv,scc_internal,&stats,&insertion,1);
stinger_scc_deletion(S,nv,scc_internal,&stats,&deletion,1);
const int64_t* actual_components = stinger_scc_get_components(scc_internal);
int64_t* expected_components = (int64_t*)malloc(sizeof(int64_t)*nv);
parallel_shiloach_vishkin_components_of_type(S, expected_components,0);
uint64_t expected_num_components = 0,actual_num_components=0;
for(uint64_t v = 0; v < nv; v++) {
if (v==expected_components[v])
expected_num_components++;
if (v==actual_components[v])
actual_num_components++;
}
EXPECT_EQ(actual_num_components,expected_num_components);
for(uint64_t v = 0; v < nv; v++) {
EXPECT_EQ(actual_components[v],expected_components[v]);
}
free(expected_components);
stinger_scc_release_internals(&scc_internal);
}
TEST_F(SCCTest, UndirectedGraphDumbbell) {
int64_t nv = stinger_max_nv(S);
stinger_scc_internal scc_internal;
stinger_scc_initialize_internals(S,nv,&scc_internal,4);
stinger_connected_components_stats stats;
stinger_scc_reset_stats(&stats);
// Insert (1,2)
stinger_edge_update insertion = {0};
insertion.source = 1; insertion.destination = 2;
stinger_insert_edge_pair(S, 0, insertion.source, insertion.destination, 1, 1);
stinger_scc_insertion(S, nv, scc_internal, &stats, &insertion, 1);
// Insert (2,3)
insertion.source = 2; insertion.destination = 3;
stinger_insert_edge_pair(S, 0, insertion.source, insertion.destination, 1, 1);
stinger_scc_insertion(S, nv, scc_internal, &stats, &insertion, 1);
// Insert (3,4)
insertion.source = 3; insertion.destination = 4;
stinger_insert_edge_pair(S, 0, insertion.source, insertion.destination, 1, 1);
stinger_scc_insertion(S, nv, scc_internal, &stats, &insertion, 1);
// Now we have a simple chain, 1-2-3-4
// We delete (2,3) breaking the chain into two components 1-2 3-4
stinger_edge_update deletion = {0};
deletion.source = 2; deletion.destination = 3;
stinger_remove_edge_pair(S, 0, deletion.source, deletion.destination);
stinger_scc_deletion(S,nv,scc_internal,&stats,&deletion,1);
const int64_t* actual_components = stinger_scc_get_components(scc_internal);
int64_t* expected_components = (int64_t*)malloc(sizeof(int64_t)*nv);
parallel_shiloach_vishkin_components_of_type(S, expected_components,0);
uint64_t expected_num_components = 0,actual_num_components=0;
for(uint64_t v = 0; v < nv; v++) {
if (v==expected_components[v])
expected_num_components++;
if (v==actual_components[v])
actual_num_components++;
}
EXPECT_EQ(actual_num_components,expected_num_components);
for(uint64_t v = 0; v < nv; v++) {
EXPECT_EQ(actual_components[v],expected_components[v]);
}
free(expected_components);
stinger_scc_release_internals(&scc_internal);
}
int main (int argc, char *argv[])
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}