madarasip@1141
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*-
|
madarasip@1141
|
2 |
*
|
madarasip@1141
|
3 |
* This file is a part of LEMON, a generic C++ optimization library.
|
madarasip@1141
|
4 |
*
|
madarasip@1186
|
5 |
* Copyright (C) 2015-2017
|
madarasip@1141
|
6 |
* EMAXA Kutato-fejleszto Kft. (EMAXA Research Ltd.)
|
madarasip@1141
|
7 |
*
|
madarasip@1141
|
8 |
* Permission to use, modify and distribute this software is granted
|
madarasip@1141
|
9 |
* provided that this copyright notice appears in all copies. For
|
madarasip@1141
|
10 |
* precise terms see the accompanying LICENSE file.
|
madarasip@1141
|
11 |
*
|
madarasip@1141
|
12 |
* This software is provided "AS IS" with no warranty of any kind,
|
madarasip@1141
|
13 |
* express or implied, and with no claim as to its suitability for any
|
madarasip@1141
|
14 |
* purpose.
|
madarasip@1141
|
15 |
*
|
madarasip@1141
|
16 |
*/
|
madarasip@1141
|
17 |
|
madarasip@1141
|
18 |
#include <lemon/vf2.h>
|
kpeter@1187
|
19 |
#include <lemon/vf2pp.h>
|
madarasip@1141
|
20 |
#include <lemon/concepts/digraph.h>
|
madarasip@1141
|
21 |
#include <lemon/smart_graph.h>
|
madarasip@1141
|
22 |
#include <lemon/lgf_reader.h>
|
madarasip@1141
|
23 |
#include <lemon/concepts/maps.h>
|
madarasip@1141
|
24 |
|
madarasip@1141
|
25 |
#include <test/test_tools.h>
|
madarasip@1141
|
26 |
#include <sstream>
|
madarasip@1141
|
27 |
|
madarasip@1141
|
28 |
using namespace lemon;
|
madarasip@1141
|
29 |
|
madarasip@1141
|
30 |
char petersen_lgf[] =
|
madarasip@1141
|
31 |
"@nodes\n"
|
madarasip@1141
|
32 |
"label col1 col2\n"
|
madarasip@1141
|
33 |
"0 1 1\n"
|
madarasip@1141
|
34 |
"1 1 2\n"
|
madarasip@1141
|
35 |
"2 1 3\n"
|
madarasip@1141
|
36 |
"3 1 4\n"
|
madarasip@1141
|
37 |
"4 2 5\n"
|
madarasip@1141
|
38 |
"5 2 1\n"
|
madarasip@1141
|
39 |
"6 2 2\n"
|
madarasip@1141
|
40 |
"7 2 3\n"
|
madarasip@1141
|
41 |
"8 2 4\n"
|
madarasip@1141
|
42 |
"9 2 5\n"
|
madarasip@1141
|
43 |
"@arcs\n"
|
madarasip@1141
|
44 |
" -\n"
|
madarasip@1141
|
45 |
"0 1\n"
|
madarasip@1141
|
46 |
"1 2\n"
|
madarasip@1141
|
47 |
"2 3\n"
|
madarasip@1141
|
48 |
"3 4\n"
|
madarasip@1141
|
49 |
"4 0\n"
|
madarasip@1141
|
50 |
"0 5\n"
|
madarasip@1141
|
51 |
"1 6\n"
|
madarasip@1141
|
52 |
"2 7\n"
|
madarasip@1141
|
53 |
"3 8\n"
|
madarasip@1141
|
54 |
"4 9\n"
|
madarasip@1141
|
55 |
"5 8\n"
|
madarasip@1141
|
56 |
"5 7\n"
|
madarasip@1141
|
57 |
"9 6\n"
|
madarasip@1141
|
58 |
"9 7\n"
|
madarasip@1141
|
59 |
"6 8\n";
|
madarasip@1141
|
60 |
|
madarasip@1141
|
61 |
char c5_lgf[] =
|
madarasip@1141
|
62 |
"@nodes\n"
|
madarasip@1141
|
63 |
"label col\n"
|
madarasip@1141
|
64 |
"0 1\n"
|
madarasip@1141
|
65 |
"1 2\n"
|
madarasip@1141
|
66 |
"2 3\n"
|
madarasip@1141
|
67 |
"3 4\n"
|
madarasip@1141
|
68 |
"4 5\n"
|
madarasip@1141
|
69 |
"@arcs\n"
|
madarasip@1141
|
70 |
" -\n"
|
madarasip@1141
|
71 |
"0 1\n"
|
madarasip@1141
|
72 |
"1 2\n"
|
madarasip@1141
|
73 |
"2 3\n"
|
madarasip@1141
|
74 |
"3 4\n"
|
madarasip@1141
|
75 |
"4 0\n";
|
madarasip@1141
|
76 |
|
madarasip@1141
|
77 |
char c7_lgf[] =
|
madarasip@1141
|
78 |
"@nodes\n"
|
madarasip@1141
|
79 |
"label\n"
|
madarasip@1141
|
80 |
"0\n"
|
madarasip@1141
|
81 |
"1\n"
|
madarasip@1141
|
82 |
"2\n"
|
madarasip@1141
|
83 |
"3\n"
|
madarasip@1141
|
84 |
"4\n"
|
madarasip@1141
|
85 |
"5\n"
|
madarasip@1141
|
86 |
"6\n"
|
madarasip@1141
|
87 |
"@arcs\n"
|
madarasip@1141
|
88 |
" -\n"
|
madarasip@1141
|
89 |
"0 1\n"
|
madarasip@1141
|
90 |
"1 2\n"
|
madarasip@1141
|
91 |
"2 3\n"
|
madarasip@1141
|
92 |
"3 4\n"
|
madarasip@1141
|
93 |
"4 5\n"
|
madarasip@1141
|
94 |
"5 6\n"
|
madarasip@1141
|
95 |
"6 0\n";
|
madarasip@1141
|
96 |
|
madarasip@1141
|
97 |
char c10_lgf[] =
|
madarasip@1141
|
98 |
"@nodes\n"
|
madarasip@1141
|
99 |
"label\n"
|
madarasip@1141
|
100 |
"0\n"
|
madarasip@1141
|
101 |
"1\n"
|
madarasip@1141
|
102 |
"2\n"
|
madarasip@1141
|
103 |
"3\n"
|
madarasip@1141
|
104 |
"4\n"
|
madarasip@1141
|
105 |
"5\n"
|
madarasip@1141
|
106 |
"6\n"
|
madarasip@1141
|
107 |
"7\n"
|
madarasip@1141
|
108 |
"8\n"
|
madarasip@1141
|
109 |
"9\n"
|
madarasip@1141
|
110 |
"@arcs\n"
|
madarasip@1141
|
111 |
" -\n"
|
madarasip@1141
|
112 |
"0 1\n"
|
madarasip@1141
|
113 |
"1 2\n"
|
madarasip@1141
|
114 |
"2 3\n"
|
madarasip@1141
|
115 |
"3 4\n"
|
madarasip@1141
|
116 |
"4 5\n"
|
madarasip@1141
|
117 |
"5 6\n"
|
madarasip@1141
|
118 |
"6 7\n"
|
madarasip@1141
|
119 |
"7 8\n"
|
madarasip@1141
|
120 |
"8 9\n"
|
madarasip@1141
|
121 |
"9 0\n";
|
madarasip@1141
|
122 |
|
madarasip@1141
|
123 |
char p10_lgf[] =
|
madarasip@1141
|
124 |
"@nodes\n"
|
madarasip@1141
|
125 |
"label\n"
|
madarasip@1141
|
126 |
"0\n"
|
madarasip@1141
|
127 |
"1\n"
|
madarasip@1141
|
128 |
"2\n"
|
madarasip@1141
|
129 |
"3\n"
|
madarasip@1141
|
130 |
"4\n"
|
madarasip@1141
|
131 |
"5\n"
|
madarasip@1141
|
132 |
"6\n"
|
madarasip@1141
|
133 |
"7\n"
|
madarasip@1141
|
134 |
"8\n"
|
madarasip@1141
|
135 |
"9\n"
|
madarasip@1141
|
136 |
"@arcs\n"
|
madarasip@1141
|
137 |
" -\n"
|
madarasip@1141
|
138 |
"0 1\n"
|
madarasip@1141
|
139 |
"1 2\n"
|
madarasip@1141
|
140 |
"2 3\n"
|
madarasip@1141
|
141 |
"3 4\n"
|
madarasip@1141
|
142 |
"4 5\n"
|
madarasip@1141
|
143 |
"5 6\n"
|
madarasip@1141
|
144 |
"6 7\n"
|
madarasip@1141
|
145 |
"7 8\n"
|
madarasip@1141
|
146 |
"8 9\n";
|
madarasip@1141
|
147 |
|
madarasip@1141
|
148 |
SmartGraph petersen, c5, c7, c10, p10;
|
madarasip@1141
|
149 |
SmartGraph::NodeMap<int> petersen_col1(petersen);
|
madarasip@1141
|
150 |
SmartGraph::NodeMap<int> petersen_col2(petersen);
|
madarasip@1141
|
151 |
SmartGraph::NodeMap<int> c5_col(c5);
|
madarasip@1141
|
152 |
|
madarasip@1141
|
153 |
void make_graphs() {
|
madarasip@1141
|
154 |
std::stringstream ss(petersen_lgf);
|
madarasip@1141
|
155 |
graphReader(petersen, ss)
|
kpeter@1187
|
156 |
.nodeMap("col1", petersen_col1)
|
kpeter@1187
|
157 |
.nodeMap("col2", petersen_col2)
|
madarasip@1141
|
158 |
.run();
|
madarasip@1141
|
159 |
|
madarasip@1141
|
160 |
ss.clear();
|
madarasip@1141
|
161 |
ss.str("");
|
kpeter@1187
|
162 |
ss << c5_lgf;
|
madarasip@1141
|
163 |
//std::stringstream ss2(c5_lgf);
|
madarasip@1141
|
164 |
graphReader(c5, ss)
|
kpeter@1187
|
165 |
.nodeMap("col", c5_col)
|
madarasip@1141
|
166 |
.run();
|
madarasip@1141
|
167 |
|
madarasip@1141
|
168 |
ss.clear();
|
madarasip@1141
|
169 |
ss.str("");
|
kpeter@1187
|
170 |
ss << c7_lgf;
|
madarasip@1141
|
171 |
graphReader(c7, ss).run();
|
madarasip@1141
|
172 |
|
madarasip@1141
|
173 |
ss.clear();
|
madarasip@1141
|
174 |
ss.str("");
|
kpeter@1187
|
175 |
ss << c10_lgf;
|
madarasip@1141
|
176 |
graphReader(c10, ss).run();
|
madarasip@1141
|
177 |
|
madarasip@1141
|
178 |
ss.clear();
|
madarasip@1141
|
179 |
ss.str("");
|
kpeter@1187
|
180 |
ss << p10_lgf;
|
madarasip@1141
|
181 |
graphReader(p10, ss).run();
|
madarasip@1141
|
182 |
|
madarasip@1141
|
183 |
}
|
madarasip@1141
|
184 |
|
madarasip@1141
|
185 |
class EqComparable {
|
madarasip@1141
|
186 |
public:
|
madarasip@1186
|
187 |
bool operator==(const EqComparable&) {
|
madarasip@1186
|
188 |
return false;
|
madarasip@1186
|
189 |
}
|
madarasip@1141
|
190 |
};
|
madarasip@1141
|
191 |
|
madarasip@1141
|
192 |
template<class A, class B>
|
madarasip@1141
|
193 |
class EqClass {
|
madarasip@1141
|
194 |
public:
|
madarasip@1186
|
195 |
bool operator()(A, B){
|
madarasip@1186
|
196 |
return false;
|
madarasip@1186
|
197 |
}
|
madarasip@1141
|
198 |
};
|
madarasip@1141
|
199 |
|
kpeter@1187
|
200 |
class IntConvertible1 {
|
kpeter@1187
|
201 |
public:
|
kpeter@1187
|
202 |
operator int() {
|
kpeter@1187
|
203 |
return 0;
|
kpeter@1187
|
204 |
}
|
kpeter@1187
|
205 |
};
|
kpeter@1187
|
206 |
|
kpeter@1187
|
207 |
class IntConvertible2 {
|
kpeter@1187
|
208 |
public:
|
kpeter@1187
|
209 |
operator int() {
|
kpeter@1187
|
210 |
return 0;
|
kpeter@1187
|
211 |
}
|
kpeter@1187
|
212 |
};
|
kpeter@1187
|
213 |
|
madarasip@1141
|
214 |
template<class G1,class G2>
|
madarasip@1186
|
215 |
void checkVf2Compile() {
|
madarasip@1141
|
216 |
G1 g;
|
madarasip@1141
|
217 |
G2 h;
|
madarasip@1141
|
218 |
concepts::ReadWriteMap<typename G1::Node, typename G2::Node> r;
|
madarasip@1141
|
219 |
bool succ;
|
madarasip@1141
|
220 |
::lemon::ignore_unused_variable_warning(succ);
|
madarasip@1141
|
221 |
|
madarasip@1141
|
222 |
succ = vf2(g,h).run();
|
madarasip@1141
|
223 |
succ = vf2(g,h).induced().run();
|
madarasip@1141
|
224 |
succ = vf2(g,h).iso().run();
|
madarasip@1141
|
225 |
succ = vf2(g,h).mapping(r).run();
|
madarasip@1186
|
226 |
|
madarasip@1186
|
227 |
Vf2<G1,G2,concepts::ReadWriteMap<typename G1::Node, typename G2::Node>,
|
madarasip@1186
|
228 |
EqClass<typename G1::Node,typename G2::Node> >
|
madarasip@1186
|
229 |
myVf2(g,h,r,EqClass<typename G1::Node,typename G2::Node>());
|
madarasip@1186
|
230 |
myVf2.find();
|
madarasip@1186
|
231 |
|
madarasip@1141
|
232 |
succ = vf2(g,h).induced().mapping(r).run();
|
madarasip@1141
|
233 |
succ = vf2(g,h).iso().mapping(r).run();
|
madarasip@1186
|
234 |
|
madarasip@1141
|
235 |
concepts::ReadMap<typename G1::Node, EqComparable> l1;
|
madarasip@1141
|
236 |
concepts::ReadMap<typename G2::Node, EqComparable> l2;
|
madarasip@1141
|
237 |
succ = vf2(g,h).nodeLabels(l1,l2).mapping(r).run();
|
madarasip@1141
|
238 |
succ = vf2(g,h).nodeEq(EqClass<typename G1::Node,typename G2::Node>())
|
madarasip@1141
|
239 |
.mapping(r).run();
|
madarasip@1141
|
240 |
}
|
madarasip@1141
|
241 |
|
kpeter@1187
|
242 |
void vf2Compile() {
|
madarasip@1141
|
243 |
checkVf2Compile<concepts::Graph,concepts::Graph>();
|
madarasip@1141
|
244 |
checkVf2Compile<concepts::Graph,SmartGraph>();
|
madarasip@1141
|
245 |
checkVf2Compile<SmartGraph,concepts::Graph>();
|
madarasip@1141
|
246 |
}
|
madarasip@1141
|
247 |
|
kpeter@1187
|
248 |
template<class G1,class G2>
|
kpeter@1187
|
249 |
void checkVf2ppCompile() {
|
kpeter@1187
|
250 |
G1 g;
|
kpeter@1187
|
251 |
G2 h;
|
kpeter@1187
|
252 |
concepts::ReadWriteMap<typename G1::Node, typename G2::Node> r;
|
kpeter@1187
|
253 |
bool succ;
|
kpeter@1187
|
254 |
::lemon::ignore_unused_variable_warning(succ);
|
kpeter@1187
|
255 |
|
kpeter@1187
|
256 |
succ = vf2pp(g,h).run();
|
kpeter@1187
|
257 |
succ = vf2pp(g,h).induced().run();
|
kpeter@1187
|
258 |
succ = vf2pp(g,h).iso().run();
|
kpeter@1187
|
259 |
succ = vf2pp(g,h).mapping(r).run();
|
kpeter@1187
|
260 |
succ = vf2pp(g,h).induced().mapping(r).run();
|
kpeter@1187
|
261 |
succ = vf2pp(g,h).iso().mapping(r).run();
|
kpeter@1187
|
262 |
|
kpeter@1187
|
263 |
concepts::ReadMap<typename G1::Node, int> c1;
|
kpeter@1187
|
264 |
concepts::ReadMap<typename G2::Node, int> c2;
|
kpeter@1187
|
265 |
Vf2pp<G1,G2,concepts::ReadWriteMap<typename G1::Node, typename G2::Node>,
|
kpeter@1187
|
266 |
concepts::ReadMap<typename G1::Node, int>,
|
kpeter@1187
|
267 |
concepts::ReadMap<typename G2::Node, int> >
|
kpeter@1187
|
268 |
myVf2pp(g,h,r,c1,c2);
|
kpeter@1187
|
269 |
myVf2pp.find();
|
kpeter@1187
|
270 |
|
kpeter@1187
|
271 |
succ = vf2pp(g,h).nodeLabels(c1,c2).mapping(r).run();
|
kpeter@1187
|
272 |
succ = vf2pp(g,h).nodeLabels(c1,c2).mapping(r).run();
|
kpeter@1187
|
273 |
|
kpeter@1187
|
274 |
concepts::ReadMap<typename G1::Node, char> c1_c;
|
kpeter@1187
|
275 |
concepts::ReadMap<typename G2::Node, char> c2_c;
|
kpeter@1187
|
276 |
Vf2pp<G1,G2,concepts::ReadWriteMap<typename G1::Node, typename G2::Node>,
|
kpeter@1187
|
277 |
concepts::ReadMap<typename G1::Node, char>,
|
kpeter@1187
|
278 |
concepts::ReadMap<typename G2::Node, char> >
|
kpeter@1187
|
279 |
myVf2pp_c(g,h,r,c1_c,c2_c);
|
kpeter@1187
|
280 |
myVf2pp_c.find();
|
kpeter@1187
|
281 |
|
kpeter@1187
|
282 |
succ = vf2pp(g,h).nodeLabels(c1_c,c2_c).mapping(r).run();
|
kpeter@1187
|
283 |
succ = vf2pp(g,h).nodeLabels(c1_c,c2_c).mapping(r).run();
|
kpeter@1187
|
284 |
|
kpeter@1187
|
285 |
concepts::ReadMap<typename G1::Node, IntConvertible1> c1_IntConv;
|
kpeter@1187
|
286 |
concepts::ReadMap<typename G2::Node, IntConvertible2> c2_IntConv;
|
kpeter@1187
|
287 |
Vf2pp<G1,G2,concepts::ReadWriteMap<typename G1::Node, typename G2::Node>,
|
kpeter@1187
|
288 |
concepts::ReadMap<typename G1::Node, IntConvertible1>,
|
kpeter@1187
|
289 |
concepts::ReadMap<typename G2::Node, IntConvertible2> >
|
kpeter@1187
|
290 |
myVf2pp_IntConv(g,h,r,c1_IntConv,c2_IntConv);
|
kpeter@1187
|
291 |
myVf2pp_IntConv.find();
|
kpeter@1187
|
292 |
|
kpeter@1187
|
293 |
succ = vf2pp(g,h).nodeLabels(c1_IntConv,c2_IntConv).mapping(r).run();
|
kpeter@1187
|
294 |
succ = vf2pp(g,h).nodeLabels(c1_IntConv,c2_IntConv).mapping(r).run();
|
kpeter@1187
|
295 |
}
|
kpeter@1187
|
296 |
|
kpeter@1187
|
297 |
void vf2ppCompile() {
|
kpeter@1187
|
298 |
checkVf2ppCompile<concepts::Graph,concepts::Graph>();
|
kpeter@1187
|
299 |
checkVf2ppCompile<concepts::Graph,SmartGraph>();
|
kpeter@1187
|
300 |
checkVf2ppCompile<SmartGraph,concepts::Graph>();
|
madarasip@1141
|
301 |
}
|
madarasip@1141
|
302 |
|
madarasip@1141
|
303 |
template<class G1, class G2, class I>
|
kpeter@1187
|
304 |
void checkSubIso(const G1 &g1, const G2 &g2, const I &i) {
|
madarasip@1141
|
305 |
std::set<typename G2::Node> image;
|
kpeter@1187
|
306 |
for (typename G1::NodeIt n(g1);n!=INVALID;++n){
|
madarasip@1141
|
307 |
check(i[n]!=INVALID, "Wrong isomorphism: incomplete mapping.");
|
madarasip@1141
|
308 |
check(image.count(i[n])==0,"Wrong isomorphism: not injective.");
|
madarasip@1141
|
309 |
image.insert(i[n]);
|
madarasip@1186
|
310 |
}
|
kpeter@1187
|
311 |
for (typename G1::EdgeIt e(g1);e!=INVALID;++e) {
|
kpeter@1187
|
312 |
check(findEdge(g2,i[g1.u(e)],i[g1.v(e)])!=INVALID,
|
kpeter@1187
|
313 |
"Wrong isomorphism: missing edge(checkSub).");
|
kpeter@1187
|
314 |
}
|
kpeter@1187
|
315 |
}
|
kpeter@1187
|
316 |
|
kpeter@1187
|
317 |
template<class G1, class G2, class I>
|
kpeter@1187
|
318 |
void checkIndIso(const G1 &g1, const G2 &g2, const I &i) {
|
kpeter@1187
|
319 |
std::set<typename G2::Node> image;
|
kpeter@1187
|
320 |
for (typename G1::NodeIt n(g1);n!=INVALID;++n) {
|
kpeter@1187
|
321 |
check(i[n]!=INVALID, "Wrong isomorphism: incomplete mapping.");
|
kpeter@1187
|
322 |
check(image.count(i[n])==0,"Wrong isomorphism: not injective.");
|
kpeter@1187
|
323 |
image.insert(i[n]);
|
kpeter@1187
|
324 |
}
|
kpeter@1187
|
325 |
for (typename G1::NodeIt n(g1); n!=INVALID; ++n) {
|
kpeter@1187
|
326 |
for (typename G1::NodeIt m(g1); m!=INVALID; ++m) {
|
madarasip@1186
|
327 |
if((findEdge(g1,n,m)==INVALID) != (findEdge(g2,i[n],i[m])==INVALID)) {
|
madarasip@1141
|
328 |
std::cout << "Wrong isomorphism: edge mismatch";
|
madarasip@1141
|
329 |
exit(1);
|
madarasip@1186
|
330 |
}
|
kpeter@1187
|
331 |
}
|
kpeter@1187
|
332 |
}
|
madarasip@1141
|
333 |
}
|
madarasip@1141
|
334 |
|
kpeter@1187
|
335 |
template<class G1,class G2,class T>
|
kpeter@1187
|
336 |
bool checkSub(const G1 &g1, const G2 &g2, const T &vf2) {
|
madarasip@1141
|
337 |
typename G1:: template NodeMap<typename G2::Node> iso(g1,INVALID);
|
kpeter@1187
|
338 |
if (const_cast<T&>(vf2).mapping(iso).run()) {
|
kpeter@1187
|
339 |
checkSubIso(g1,g2,iso);
|
madarasip@1186
|
340 |
return true;
|
madarasip@1186
|
341 |
}
|
kpeter@1187
|
342 |
return false;
|
madarasip@1141
|
343 |
}
|
madarasip@1141
|
344 |
|
kpeter@1187
|
345 |
template<class G1,class G2,class T>
|
kpeter@1187
|
346 |
bool checkInd(const G1 &g1, const G2 &g2, const T &vf2) {
|
madarasip@1141
|
347 |
typename G1:: template NodeMap<typename G2::Node> iso(g1,INVALID);
|
kpeter@1187
|
348 |
if (const_cast<T&>(vf2).induced().mapping(iso).run()) {
|
kpeter@1187
|
349 |
checkIndIso(g1,g2,iso);
|
madarasip@1186
|
350 |
return true;
|
madarasip@1186
|
351 |
}
|
kpeter@1187
|
352 |
return false;
|
madarasip@1186
|
353 |
}
|
madarasip@1186
|
354 |
|
kpeter@1187
|
355 |
template<class G1,class G2,class T>
|
kpeter@1187
|
356 |
bool checkIso(const G1 &g1, const G2 &g2, const T &vf2) {
|
madarasip@1186
|
357 |
typename G1:: template NodeMap<typename G2::Node> iso(g1,INVALID);
|
kpeter@1187
|
358 |
if (const_cast<T&>(vf2).iso().mapping(iso).run()) {
|
madarasip@1186
|
359 |
check(countNodes(g1)==countNodes(g2),
|
madarasip@1186
|
360 |
"Wrong iso alg.: they are not isomophic.");
|
kpeter@1187
|
361 |
checkIndIso(g1,g2,iso);
|
madarasip@1186
|
362 |
return true;
|
madarasip@1186
|
363 |
}
|
kpeter@1187
|
364 |
return false;
|
madarasip@1141
|
365 |
}
|
madarasip@1141
|
366 |
|
madarasip@1141
|
367 |
template<class G1, class G2, class L1, class L2, class I>
|
madarasip@1141
|
368 |
void checkLabel(const G1 &g1, const G2 &,
|
kpeter@1187
|
369 |
const L1 &l1, const L2 &l2, const I &i) {
|
kpeter@1187
|
370 |
for (typename G1::NodeIt n(g1);n!=INVALID;++n) {
|
madarasip@1186
|
371 |
check(l1[n]==l2[i[n]],"Wrong isomorphism: label mismatch.");
|
kpeter@1187
|
372 |
}
|
kpeter@1187
|
373 |
}
|
kpeter@1187
|
374 |
|
kpeter@1187
|
375 |
template<class G1,class G2,class L1,class L2,class T>
|
kpeter@1187
|
376 |
bool checkSub(const G1 &g1, const G2 &g2, const L1 &l1, const L2 &l2, const T &vf2) {
|
kpeter@1187
|
377 |
typename G1:: template NodeMap<typename G2::Node> iso(g1,INVALID);
|
kpeter@1187
|
378 |
if (const_cast<T&>(vf2).nodeLabels(l1,l2).mapping(iso).run()){
|
kpeter@1187
|
379 |
checkSubIso(g1,g2,iso);
|
kpeter@1187
|
380 |
checkLabel(g1,g2,l1,l2,iso);
|
kpeter@1187
|
381 |
return true;
|
kpeter@1187
|
382 |
}
|
kpeter@1187
|
383 |
return false;
|
kpeter@1187
|
384 |
}
|
kpeter@1187
|
385 |
|
kpeter@1187
|
386 |
template<class G1,class G2>
|
kpeter@1187
|
387 |
void checkSub(const G1 &g1, const G2 &g2, bool expected, const char* msg) {
|
kpeter@1187
|
388 |
check(checkSub(g1,g2,vf2(g1,g2)) == expected, msg);
|
kpeter@1187
|
389 |
check(checkSub(g1,g2,vf2pp(g1,g2)) == expected, msg);
|
kpeter@1187
|
390 |
}
|
kpeter@1187
|
391 |
|
kpeter@1187
|
392 |
template<class G1,class G2>
|
kpeter@1187
|
393 |
void checkInd(const G1 &g1, const G2 &g2, bool expected, const char* msg) {
|
kpeter@1187
|
394 |
check(checkInd(g1,g2,vf2(g1,g2)) == expected, msg);
|
kpeter@1187
|
395 |
check(checkInd(g1,g2,vf2pp(g1,g2)) == expected, msg);
|
kpeter@1187
|
396 |
}
|
kpeter@1187
|
397 |
|
kpeter@1187
|
398 |
template<class G1,class G2>
|
kpeter@1187
|
399 |
void checkIso(const G1 &g1, const G2 &g2, bool expected, const char* msg) {
|
kpeter@1187
|
400 |
check(checkIso(g1,g2,vf2(g1,g2)) == expected, msg);
|
kpeter@1187
|
401 |
check(checkIso(g1,g2,vf2pp(g1,g2)) == expected, msg);
|
madarasip@1141
|
402 |
}
|
madarasip@1141
|
403 |
|
madarasip@1141
|
404 |
template<class G1,class G2,class L1,class L2>
|
kpeter@1187
|
405 |
void checkSub(const G1 &g1, const G2 &g2, const L1 &l1, const L2 &l2, bool expected, const char* msg) {
|
kpeter@1187
|
406 |
check(checkSub(g1,g2,l1,l2,vf2(g1,g2)) == expected, msg);
|
kpeter@1187
|
407 |
check(checkSub(g1,g2,l1,l2,vf2pp(g1,g2)) == expected, msg);
|
madarasip@1141
|
408 |
}
|
madarasip@1141
|
409 |
|
madarasip@1141
|
410 |
int main() {
|
madarasip@1141
|
411 |
make_graphs();
|
madarasip@1141
|
412 |
|
kpeter@1187
|
413 |
checkSub(c5,petersen,true,
|
kpeter@1187
|
414 |
"There should exist a C5->Petersen mapping.");
|
kpeter@1187
|
415 |
checkSub(c7,petersen,false,
|
kpeter@1187
|
416 |
"There should not exist a C7->Petersen mapping.");
|
kpeter@1187
|
417 |
checkSub(p10,petersen,true,
|
kpeter@1187
|
418 |
"There should exist a P10->Petersen mapping.");
|
kpeter@1187
|
419 |
checkSub(c10,petersen,false,
|
kpeter@1187
|
420 |
"There should not exist a C10->Petersen mapping.");
|
kpeter@1187
|
421 |
checkSub(petersen,petersen,true,
|
kpeter@1187
|
422 |
"There should exist a Petersen->Petersen mapping.");
|
kpeter@1187
|
423 |
|
kpeter@1187
|
424 |
checkInd(c5,petersen,true,
|
kpeter@1187
|
425 |
"There should exist a C5->Petersen spanned mapping.");
|
kpeter@1187
|
426 |
checkInd(c7,petersen,false,
|
kpeter@1187
|
427 |
"There should exist a C7->Petersen spanned mapping.");
|
kpeter@1187
|
428 |
checkInd(p10,petersen,false,
|
kpeter@1187
|
429 |
"There should not exist a P10->Petersen spanned mapping.");
|
kpeter@1187
|
430 |
checkInd(c10,petersen,false,
|
kpeter@1187
|
431 |
"There should not exist a C10->Petersen spanned mapping.");
|
kpeter@1187
|
432 |
checkInd(petersen,petersen,true,
|
madarasip@1141
|
433 |
"There should exist a Petersen->Petersen spanned mapping.");
|
madarasip@1141
|
434 |
|
kpeter@1187
|
435 |
checkSub(petersen,c10,false,
|
kpeter@1187
|
436 |
"There should not exist a Petersen->C10 mapping.");
|
kpeter@1187
|
437 |
checkSub(p10,c10,true,
|
kpeter@1187
|
438 |
"There should exist a P10->C10 mapping.");
|
kpeter@1187
|
439 |
checkInd(p10,c10,false,
|
kpeter@1187
|
440 |
"There should not exist a P10->C10 spanned mapping.");
|
kpeter@1187
|
441 |
checkSub(c10,p10,false,
|
kpeter@1187
|
442 |
"There should not exist a C10->P10 mapping.");
|
madarasip@1141
|
443 |
|
kpeter@1187
|
444 |
checkIso(p10,c10,false,
|
kpeter@1187
|
445 |
"P10 and C10 are not isomorphic.");
|
kpeter@1187
|
446 |
checkIso(c10,c10,true,
|
kpeter@1187
|
447 |
"C10 and C10 are isomorphic.");
|
alpar@1143
|
448 |
|
kpeter@1187
|
449 |
checkSub(c5,petersen,c5_col,petersen_col1,false,
|
kpeter@1187
|
450 |
"There should exist a C5->Petersen mapping.");
|
kpeter@1187
|
451 |
checkSub(c5,petersen,c5_col,petersen_col2,true,
|
kpeter@1187
|
452 |
"There should exist a C5->Petersen mapping.");
|
madarasip@1141
|
453 |
|
kpeter@1187
|
454 |
check(!vf2(p10,c10).iso().run(), "P10 and C10 are not isomorphic.");
|
kpeter@1187
|
455 |
check(!vf2pp(p10,c10).iso().run(), "P10 and C10 are not isomorphic.");
|
kpeter@1187
|
456 |
|
kpeter@1187
|
457 |
check(vf2(c10,c10).iso().run(), "C10 and C10 are isomorphic.");
|
kpeter@1187
|
458 |
check(vf2pp(c10,c10).iso().run(), "C10 and C10 are isomorphic.");
|
madarasip@1141
|
459 |
}
|