-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.cpp
More file actions
305 lines (253 loc) · 8.76 KB
/
Copy pathtests.cpp
File metadata and controls
305 lines (253 loc) · 8.76 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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
#include "tests.h"
void printDescription () {
std::cout << "Tests are done as follows.\n";
std::cout << "There are test folders. Each test folder:\n";
std::cout << " Tests with every method (Ullmann, SIDT, GTSI):\n";
std::cout << " pattern_*.dot are learnt.\n";
std::cout << " test.dot is tested against learnt graphs.\n";
std::cout << " Once with symbols (labels) checking, once without.\n";
std::cout << "\n";
std::cout << "Ullmann:\n";
std::cout << " No learning.\n";
std::cout << " Counting the subgraph isomorphisms between each pattern graph and the test graph.\n";
std::cout << " The result is the addition.\n";
std::cout << "\n";
std::cout << "SIDT:\n";
std::cout << " Pattern graphs are cut into sites (site size: minimum size between pattern graphs).\n";
std::cout << " Learning: via decision tree.\n";
std::cout << " Testing: via decision tree (with sites)\n";
std::cout << " The result is the number of matching sites.\n";
std::cout << "\n";
std::cout << "GTSI:\n";
std::cout << " Pattern graphs are cut into sites (site size: minimum size between pattern graphs).\n";
std::cout << " Learning: via traversal tree.\n";
std::cout << " Testing: via traversal tree (with sites)\n";
std::cout << " The result is the number of possible traversals.\n";
std::cout << "\n";
std::cout << "Test 0: small identical graphs.\n";
std::cout << "Test 1: small test graph with one child more (to a leaf) than pattern.\n";
std::cout << "Test 2: small test graph with one edge more (leaf -> leaf) than pattern.\n";
std::cout << "Test 3: small test graph with one child more (to a leaf) and an edge more (leaf -> root) than pattern.\n";
std::cout << "Test 4: same as test 3 but with different labels.\n";
std::cout << "Test 5: small test graph with two JCC (that have two children).\n";
}
int main (int argc, char *argv[]) {
if (argc >= 2) {
printDescription ();
return 1;
}
char *color;
Red = "\e[1;31m";
Green = "\e[1;32m";
char *Blue = "\e[1;33m";
Color_Off = "\e[0m";
optionMCSByPattern = 0;
optionMCS = 0;
optionNoPerm = 0;
optionCheckSymb = 0;
optionCount = 1;
optionRedInt = 0;
optionRec = 0;
optionQuiet = 0;
optionVerbose = 0;
optionOutSmall = 0;
optionExport = 0;
optionMultiThreaded = 0;
optionForceRoots = 0;
optionIsoOnly = 0;
optionDebug = 0;
optionInfo = 0;
optionOnlyInduced = 0;
nThreads = 1;
FILEeP;
FILEeT;
FILEenP;
FILEenT;
FILEesP;
FILEesT;
mutexExport;
mutexIsoTotal;
mutexnSgraphP;
mutexStructRead;
mutexBSFPattern;
isThreadBusy;
maxFound = 0;
maxPatternFound = 0;
isoTotal = 0;
wP = 0;
wT = 0;
nSgraphP = 0;
// optionLabels=0;
graph_t **grPattern;
graph_t *grTest;
FILE *fpPattern;
FILE *fpTest;
int i = 0;
while (i < std::numeric_limits < int >::max ()) {
std::string dirPath = "tests_graphs/test" + std::to_string (i) + "/";
// std::string pathTest = dirPath + "test.edg";
std::string pathTest = dirPath + "test.dot";
// fpTest = fopen(pathTest.c_str(), "r");
// read expected results
int expected_ullmann_with_labels = -1;
int expected_ullmann_no_labels = -1;
int expected_sidt_with_labels = -1;
int expected_sidt_no_labels = -1;
int expected_gtsi_with_labels = -1;
int expected_gtsi_no_labels = -1;
std::ifstream f_res_ullmann (dirPath + "expected_ullmann");
std::ifstream f_res_sidt (dirPath + "expected_sidt");
std::ifstream f_res_gtsi (dirPath + "expected_gtsi");
if (f_res_ullmann.good ()and f_res_sidt.good ()and f_res_gtsi.good ()) {
string sLine;
getline (f_res_ullmann, sLine);
expected_ullmann_with_labels = atoi (sLine.c_str ());
getline (f_res_ullmann, sLine);
expected_ullmann_no_labels = atoi (sLine.c_str ());
getline (f_res_sidt, sLine);
expected_sidt_with_labels = atoi (sLine.c_str ());
getline (f_res_sidt, sLine);
expected_sidt_no_labels = atoi (sLine.c_str ());
getline (f_res_gtsi, sLine);
expected_gtsi_with_labels = atoi (sLine.c_str ());
getline (f_res_gtsi, sLine);
expected_gtsi_no_labels = atoi (sLine.c_str ());
}
f_res_ullmann.close ();
f_res_sidt.close ();
f_res_gtsi.close ();
if (fpTest == NULL) {
// fprintf(stderr, "Can't open pattern or test graph\n");
break;
}
printf ("%s", Blue);
std::cout << "Running test " + std::to_string (i) + "\n";
printf ("%s", Color_Off);
int j = 0;
int nPattern = 0;
grPattern = (graph_t **) std::malloc (sizeof (graph_t *));
while (j < std::numeric_limits < int >::max ()) {
std::string pathPattern = dirPath + "pattern_" + to_string (j) + ".dot";
grPattern = (graph_t **) std::realloc (grPattern, (j + 1) * sizeof (graph_t *));
fpPattern = fopen (pathPattern.c_str (), "r");
if (fpPattern == NULL)
break;
fclose (fpPattern);
grPattern[j] = getGraphFromPath (pathPattern.c_str ());
// graph_from_file(&grPattern[j], fpPattern);
j++;
nPattern++;
}
if (nPattern == 0)
break;
// graph_from_file(&grTest, fpTest);
grTest = getGraphFromPath (pathTest.c_str ());
// fclose(fpTest);
// graph_fprint(stdout, grPattern);
graph_fprint (stdout, grTest);
// Ullmann
test_Ullmann (grPattern, nPattern, grTest, expected_ullmann_with_labels, true, " (Check labels)");
test_Ullmann (grPattern, nPattern, grTest, expected_ullmann_no_labels, false, " (Don't check labels)");
std::cout << "\n";
// SIDT
test_SIDT (grPattern, nPattern, grTest, expected_sidt_with_labels, true, " (Check labels)");
test_SIDT (grPattern, nPattern, grTest, expected_sidt_no_labels, false, " (Don't check labels)");
std::cout << "\n";
// GTSIs
test_GTSI (grPattern, nPattern, grTest, expected_gtsi_with_labels, true, " (Check labels)");
test_GTSI (grPattern, nPattern, grTest, expected_gtsi_no_labels, false, " (Don't check labels)");
std::cout << "\n";
i++;
}
}
void test_Ullmann (graph_t ** grPattern, int nPattern, graph_t * grTest, int expected, bool checkLabels, std::string desc) {
std::cout << "Ullmann" + desc + ":\n";
if (checkLabels)
optionCheckSymb = 1;
else
optionCheckSymb = 0;
int i;
int isoTotal = 0;
for (i = 0; i < nPattern; i++) {
int res = isoUllman (grPattern[i], grTest);
isoTotal += res;
}
char *color;
if (isoTotal != expected) {
color = Red;
}
else {
color = Green;
}
printf ("%sisoTotal: %d (expected: %d).%s\n", color, isoTotal, expected, Color_Off);
}
void test_SIDT (graph_t ** grPattern, int nPattern, graph_t * grTest, int expected, bool checkLabels, std::string desc) {
char *color;
std::cout << "SIDT" + desc + ":\n";
optionFuncs = 0;
char optionLearn = 0;
char optionLearnList = 0;
char learnOk = 0;
char scanOk = 0;
char optionTest = 0;
char optionShowStats = 0;
char optionOutputDt = 0;
char *pathDT;
int siteCountLimit = 0;
int i;
int siteSize = grPattern[0]->nodes.count;
for (i = 1; i < nPattern; i++) {
if (grPattern[i]->nodes.count < siteSize)
siteSize = grPattern[i]->nodes.count;
}
char withLabels;
if (checkLabels)
char withLabels = 1;
else
withLabels = 0;
bool optionInfo = false;
int *scanFuncs;
int valence = 2;
char debug = 1;
ProgInfo *scanInfo = NULL;
decisionTree *dt = newDecisionTree (siteSize, valence);
std::string st = "Pattern";
char *msg = (char *) st.c_str ();
int learnt_pattern = 0;
for (i = 0; i < nPattern; i++) {
learnt_pattern += learnGraph (grPattern[i], dt, msg, siteCountLimit, withLabels);
}
printf ("%d sites learned from pattern graph.\n", learnt_pattern);
int *countByProg = (int *) calloc (dt->nProgs, sizeof (int));
int n = findGraph (grTest, dt, countByProg, scanInfo, scanFuncs, withLabels);
if (n != expected) {
color = Red;
}
else {
color = Green;
}
printf ("%s%d sites from test graph found matching (expected: %d).%s\n", color, n, expected, Color_Off);
}
void test_GTSI (graph_t ** grPattern, int nPattern, graph_t * grTest, int expected, bool checkLabels, std::string desc) {
char *color;
std::cout << "GTSI" + desc + ":\n";
int i;
int siteSize = grPattern[0]->nodes.count;
for (i = 1; i < nPattern; i++) {
if (grPattern[i]->nodes.count < siteSize)
siteSize = grPattern[i]->nodes.count;
}
ParcoursNode *tree = new ParcoursNode ();
for (i = 0; i < nPattern; i++) {
tree->addGraph (grPattern[i], siteSize, 0, checkLabels);
}
printf ("%d traversals reconstructed from pattern graph.\n", tree->countLeaves ());
vsize_t count = tree->parcourir (grTest, siteSize, checkLabels);
if (count != expected) {
color = Red;
}
else {
color = Green;
}
printf ("%s%d traversals possible in test graph (expected: %d).%s\n", color, count, expected, Color_Off);
}