0
4
0
... | ... |
@@ -721,26 +721,26 @@ |
721 | 721 |
} |
722 | 722 |
|
723 | 723 |
void restoreSnapshot(const Snapshot &s) |
724 | 724 |
{ |
725 | 725 |
while(s.arc_num<arcs.size()) { |
726 | 726 |
int n=arcs.size()-1; |
727 | 727 |
Edge arc=edgeFromId(n/2); |
728 | 728 |
Parent::notifier(Edge()).erase(arc); |
729 | 729 |
std::vector<Arc> dir; |
730 | 730 |
dir.push_back(arcFromId(n)); |
731 | 731 |
dir.push_back(arcFromId(n-1)); |
732 | 732 |
Parent::notifier(Arc()).erase(dir); |
733 |
nodes[arcs[n].target].first_out=arcs[n].next_out; |
|
734 |
nodes[arcs[n-1].target].first_out=arcs[n-1].next_out; |
|
733 |
nodes[arcs[n-1].target].first_out=arcs[n].next_out; |
|
734 |
nodes[arcs[n].target].first_out=arcs[n-1].next_out; |
|
735 | 735 |
arcs.pop_back(); |
736 | 736 |
arcs.pop_back(); |
737 | 737 |
} |
738 | 738 |
while(s.node_num<nodes.size()) { |
739 | 739 |
int n=nodes.size()-1; |
740 | 740 |
Node node = nodeFromId(n); |
741 | 741 |
Parent::notifier(Node()).erase(node); |
742 | 742 |
nodes.pop_back(); |
743 | 743 |
} |
744 | 744 |
} |
745 | 745 |
|
746 | 746 |
public: |
... | ... |
@@ -20,25 +20,25 @@ |
20 | 20 |
#include <lemon/list_graph.h> |
21 | 21 |
#include <lemon/smart_graph.h> |
22 | 22 |
//#include <lemon/full_graph.h> |
23 | 23 |
//#include <lemon/hypercube_graph.h> |
24 | 24 |
|
25 | 25 |
#include "test_tools.h" |
26 | 26 |
#include "graph_test.h" |
27 | 27 |
|
28 | 28 |
using namespace lemon; |
29 | 29 |
using namespace lemon::concepts; |
30 | 30 |
|
31 | 31 |
template <class Digraph> |
32 |
void |
|
32 |
void checkDigraphBuild() { |
|
33 | 33 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
34 | 34 |
Digraph G; |
35 | 35 |
|
36 | 36 |
checkGraphNodeList(G, 0); |
37 | 37 |
checkGraphArcList(G, 0); |
38 | 38 |
|
39 | 39 |
Node |
40 | 40 |
n1 = G.addNode(), |
41 | 41 |
n2 = G.addNode(), |
42 | 42 |
n3 = G.addNode(); |
43 | 43 |
checkGraphNodeList(G, 3); |
44 | 44 |
checkGraphArcList(G, 0); |
... | ... |
@@ -49,46 +49,255 @@ |
49 | 49 |
checkGraphArcList(G, 1); |
50 | 50 |
|
51 | 51 |
checkGraphOutArcList(G, n1, 1); |
52 | 52 |
checkGraphOutArcList(G, n2, 0); |
53 | 53 |
checkGraphOutArcList(G, n3, 0); |
54 | 54 |
|
55 | 55 |
checkGraphInArcList(G, n1, 0); |
56 | 56 |
checkGraphInArcList(G, n2, 1); |
57 | 57 |
checkGraphInArcList(G, n3, 0); |
58 | 58 |
|
59 | 59 |
checkGraphConArcList(G, 1); |
60 | 60 |
|
61 |
Arc a2 = G.addArc(n2, n1), |
|
61 |
Arc a2 = G.addArc(n2, n1), |
|
62 |
a3 = G.addArc(n2, n3), |
|
63 |
a4 = G.addArc(n2, n3); |
|
64 |
|
|
65 |
checkGraphNodeList(G, 3); |
|
66 |
checkGraphArcList(G, 4); |
|
67 |
|
|
68 |
checkGraphOutArcList(G, n1, 1); |
|
69 |
checkGraphOutArcList(G, n2, 3); |
|
70 |
checkGraphOutArcList(G, n3, 0); |
|
71 |
|
|
72 |
checkGraphInArcList(G, n1, 1); |
|
73 |
checkGraphInArcList(G, n2, 1); |
|
74 |
checkGraphInArcList(G, n3, 2); |
|
75 |
|
|
76 |
checkGraphConArcList(G, 4); |
|
77 |
|
|
78 |
checkNodeIds(G); |
|
79 |
checkArcIds(G); |
|
80 |
checkGraphNodeMap(G); |
|
81 |
checkGraphArcMap(G); |
|
82 |
} |
|
83 |
|
|
84 |
template <class Digraph> |
|
85 |
void checkDigraphSplit() { |
|
86 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
|
87 |
|
|
88 |
Digraph G; |
|
89 |
Node n1 = G.addNode(), n2 = G.addNode(), n3 = G.addNode(); |
|
90 |
Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n2, n1), |
|
91 |
a3 = G.addArc(n2, n3), a4 = G.addArc(n2, n3); |
|
92 |
|
|
93 |
Node n4 = G.split(n2); |
|
94 |
|
|
95 |
check(G.target(OutArcIt(G, n2)) == n4 && |
|
96 |
G.source(InArcIt(G, n4)) == n2, |
|
97 |
"Wrong split."); |
|
98 |
|
|
99 |
checkGraphNodeList(G, 4); |
|
100 |
checkGraphArcList(G, 5); |
|
101 |
|
|
102 |
checkGraphOutArcList(G, n1, 1); |
|
103 |
checkGraphOutArcList(G, n2, 1); |
|
104 |
checkGraphOutArcList(G, n3, 0); |
|
105 |
checkGraphOutArcList(G, n4, 3); |
|
106 |
|
|
107 |
checkGraphInArcList(G, n1, 1); |
|
108 |
checkGraphInArcList(G, n2, 1); |
|
109 |
checkGraphInArcList(G, n3, 2); |
|
110 |
checkGraphInArcList(G, n4, 1); |
|
111 |
|
|
112 |
checkGraphConArcList(G, 5); |
|
113 |
} |
|
114 |
|
|
115 |
template <class Digraph> |
|
116 |
void checkDigraphAlter() { |
|
117 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
|
118 |
|
|
119 |
Digraph G; |
|
120 |
Node n1 = G.addNode(), n2 = G.addNode(), |
|
121 |
n3 = G.addNode(), n4 = G.addNode(); |
|
122 |
Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n4, n1), |
|
123 |
a3 = G.addArc(n4, n3), a4 = G.addArc(n4, n3), |
|
124 |
a5 = G.addArc(n2, n4); |
|
125 |
|
|
126 |
checkGraphNodeList(G, 4); |
|
127 |
checkGraphArcList(G, 5); |
|
128 |
|
|
129 |
// Check changeSource() and changeTarget() |
|
130 |
G.changeTarget(a4, n1); |
|
131 |
|
|
132 |
checkGraphNodeList(G, 4); |
|
133 |
checkGraphArcList(G, 5); |
|
134 |
|
|
135 |
checkGraphOutArcList(G, n1, 1); |
|
136 |
checkGraphOutArcList(G, n2, 1); |
|
137 |
checkGraphOutArcList(G, n3, 0); |
|
138 |
checkGraphOutArcList(G, n4, 3); |
|
139 |
|
|
140 |
checkGraphInArcList(G, n1, 2); |
|
141 |
checkGraphInArcList(G, n2, 1); |
|
142 |
checkGraphInArcList(G, n3, 1); |
|
143 |
checkGraphInArcList(G, n4, 1); |
|
144 |
|
|
145 |
checkGraphConArcList(G, 5); |
|
146 |
|
|
147 |
G.changeSource(a4, n3); |
|
148 |
|
|
149 |
checkGraphNodeList(G, 4); |
|
150 |
checkGraphArcList(G, 5); |
|
151 |
|
|
152 |
checkGraphOutArcList(G, n1, 1); |
|
153 |
checkGraphOutArcList(G, n2, 1); |
|
154 |
checkGraphOutArcList(G, n3, 1); |
|
155 |
checkGraphOutArcList(G, n4, 2); |
|
156 |
|
|
157 |
checkGraphInArcList(G, n1, 2); |
|
158 |
checkGraphInArcList(G, n2, 1); |
|
159 |
checkGraphInArcList(G, n3, 1); |
|
160 |
checkGraphInArcList(G, n4, 1); |
|
161 |
|
|
162 |
checkGraphConArcList(G, 5); |
|
163 |
|
|
164 |
// Check contract() |
|
165 |
G.contract(n2, n4, false); |
|
166 |
|
|
167 |
checkGraphNodeList(G, 3); |
|
168 |
checkGraphArcList(G, 5); |
|
169 |
|
|
170 |
checkGraphOutArcList(G, n1, 1); |
|
171 |
checkGraphOutArcList(G, n2, 3); |
|
172 |
checkGraphOutArcList(G, n3, 1); |
|
173 |
|
|
174 |
checkGraphInArcList(G, n1, 2); |
|
175 |
checkGraphInArcList(G, n2, 2); |
|
176 |
checkGraphInArcList(G, n3, 1); |
|
177 |
|
|
178 |
checkGraphConArcList(G, 5); |
|
179 |
|
|
180 |
G.contract(n2, n1); |
|
181 |
|
|
182 |
checkGraphNodeList(G, 2); |
|
183 |
checkGraphArcList(G, 3); |
|
184 |
|
|
185 |
checkGraphOutArcList(G, n2, 2); |
|
186 |
checkGraphOutArcList(G, n3, 1); |
|
187 |
|
|
188 |
checkGraphInArcList(G, n2, 2); |
|
189 |
checkGraphInArcList(G, n3, 1); |
|
190 |
|
|
191 |
checkGraphConArcList(G, 3); |
|
192 |
} |
|
193 |
|
|
194 |
template <class Digraph> |
|
195 |
void checkDigraphErase() { |
|
196 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
|
197 |
|
|
198 |
Digraph G; |
|
199 |
Node n1 = G.addNode(), n2 = G.addNode(), |
|
200 |
n3 = G.addNode(), n4 = G.addNode(); |
|
201 |
Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n4, n1), |
|
202 |
a3 = G.addArc(n4, n3), a4 = G.addArc(n3, n1), |
|
203 |
a5 = G.addArc(n2, n4); |
|
204 |
|
|
205 |
// Check arc deletion |
|
206 |
G.erase(a1); |
|
207 |
|
|
208 |
checkGraphNodeList(G, 4); |
|
209 |
checkGraphArcList(G, 4); |
|
210 |
|
|
211 |
checkGraphOutArcList(G, n1, 0); |
|
212 |
checkGraphOutArcList(G, n2, 1); |
|
213 |
checkGraphOutArcList(G, n3, 1); |
|
214 |
checkGraphOutArcList(G, n4, 2); |
|
215 |
|
|
216 |
checkGraphInArcList(G, n1, 2); |
|
217 |
checkGraphInArcList(G, n2, 0); |
|
218 |
checkGraphInArcList(G, n3, 1); |
|
219 |
checkGraphInArcList(G, n4, 1); |
|
220 |
|
|
221 |
checkGraphConArcList(G, 4); |
|
222 |
|
|
223 |
// Check node deletion |
|
224 |
G.erase(n4); |
|
225 |
|
|
226 |
checkGraphNodeList(G, 3); |
|
227 |
checkGraphArcList(G, 1); |
|
228 |
|
|
229 |
checkGraphOutArcList(G, n1, 0); |
|
230 |
checkGraphOutArcList(G, n2, 0); |
|
231 |
checkGraphOutArcList(G, n3, 1); |
|
232 |
checkGraphOutArcList(G, n4, 0); |
|
233 |
|
|
234 |
checkGraphInArcList(G, n1, 1); |
|
235 |
checkGraphInArcList(G, n2, 0); |
|
236 |
checkGraphInArcList(G, n3, 0); |
|
237 |
checkGraphInArcList(G, n4, 0); |
|
238 |
|
|
239 |
checkGraphConArcList(G, 1); |
|
240 |
} |
|
241 |
|
|
242 |
|
|
243 |
template <class Digraph> |
|
244 |
void checkDigraphSnapshot() { |
|
245 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
|
246 |
|
|
247 |
Digraph G; |
|
248 |
Node n1 = G.addNode(), n2 = G.addNode(), n3 = G.addNode(); |
|
249 |
Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n2, n1), |
|
250 |
a3 = G.addArc(n2, n3), a4 = G.addArc(n2, n3); |
|
251 |
|
|
252 |
typename Digraph::Snapshot snapshot(G); |
|
253 |
|
|
254 |
Node n = G.addNode(); |
|
255 |
G.addArc(n3, n); |
|
256 |
G.addArc(n, n3); |
|
257 |
|
|
258 |
checkGraphNodeList(G, 4); |
|
259 |
checkGraphArcList(G, 6); |
|
260 |
|
|
261 |
snapshot.restore(); |
|
262 |
|
|
62 | 263 |
checkGraphNodeList(G, 3); |
63 | 264 |
checkGraphArcList(G, 4); |
64 | 265 |
|
65 | 266 |
checkGraphOutArcList(G, n1, 1); |
66 | 267 |
checkGraphOutArcList(G, n2, 3); |
67 | 268 |
checkGraphOutArcList(G, n3, 0); |
68 | 269 |
|
69 | 270 |
checkGraphInArcList(G, n1, 1); |
70 | 271 |
checkGraphInArcList(G, n2, 1); |
71 | 272 |
checkGraphInArcList(G, n3, 2); |
72 | 273 |
|
73 | 274 |
checkGraphConArcList(G, 4); |
74 | 275 |
|
75 | 276 |
checkNodeIds(G); |
76 | 277 |
checkArcIds(G); |
77 | 278 |
checkGraphNodeMap(G); |
78 | 279 |
checkGraphArcMap(G); |
79 | 280 |
|
281 |
G.addNode(); |
|
282 |
snapshot.save(G); |
|
283 |
|
|
284 |
G.addArc(G.addNode(), G.addNode()); |
|
285 |
|
|
286 |
snapshot.restore(); |
|
287 |
|
|
288 |
checkGraphNodeList(G, 4); |
|
289 |
checkGraphArcList(G, 4); |
|
80 | 290 |
} |
81 | 291 |
|
82 |
|
|
83 | 292 |
void checkConcepts() { |
84 | 293 |
{ // Checking digraph components |
85 | 294 |
checkConcept<BaseDigraphComponent, BaseDigraphComponent >(); |
86 | 295 |
|
87 | 296 |
checkConcept<IDableDigraphComponent<>, |
88 | 297 |
IDableDigraphComponent<> >(); |
89 | 298 |
|
90 | 299 |
checkConcept<IterableDigraphComponent<>, |
91 | 300 |
IterableDigraphComponent<> >(); |
92 | 301 |
|
93 | 302 |
checkConcept<MappableDigraphComponent<>, |
94 | 303 |
MappableDigraphComponent<> >(); |
... | ... |
@@ -160,26 +369,32 @@ |
160 | 369 |
check(!g.valid(n1), "Wrong validity check"); |
161 | 370 |
check(g.valid(n2), "Wrong validity check"); |
162 | 371 |
check(g.valid(n3), "Wrong validity check"); |
163 | 372 |
check(!g.valid(e1), "Wrong validity check"); |
164 | 373 |
check(g.valid(e2), "Wrong validity check"); |
165 | 374 |
|
166 | 375 |
check(!g.valid(g.nodeFromId(-1)), "Wrong validity check"); |
167 | 376 |
check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); |
168 | 377 |
} |
169 | 378 |
|
170 | 379 |
void checkDigraphs() { |
171 | 380 |
{ // Checking ListDigraph |
172 |
|
|
381 |
checkDigraphBuild<ListDigraph>(); |
|
382 |
checkDigraphSplit<ListDigraph>(); |
|
383 |
checkDigraphAlter<ListDigraph>(); |
|
384 |
checkDigraphErase<ListDigraph>(); |
|
385 |
checkDigraphSnapshot<ListDigraph>(); |
|
173 | 386 |
checkDigraphValidityErase<ListDigraph>(); |
174 | 387 |
} |
175 | 388 |
{ // Checking SmartDigraph |
176 |
|
|
389 |
checkDigraphBuild<SmartDigraph>(); |
|
390 |
checkDigraphSplit<SmartDigraph>(); |
|
391 |
checkDigraphSnapshot<SmartDigraph>(); |
|
177 | 392 |
checkDigraphValidity<SmartDigraph>(); |
178 | 393 |
} |
179 | 394 |
} |
180 | 395 |
|
181 | 396 |
int main() { |
182 | 397 |
checkDigraphs(); |
183 | 398 |
checkConcepts(); |
184 | 399 |
return 0; |
185 | 400 |
} |
... | ... |
@@ -20,90 +20,256 @@ |
20 | 20 |
#include <lemon/list_graph.h> |
21 | 21 |
#include <lemon/smart_graph.h> |
22 | 22 |
// #include <lemon/full_graph.h> |
23 | 23 |
// #include <lemon/grid_graph.h> |
24 | 24 |
|
25 | 25 |
#include "test_tools.h" |
26 | 26 |
#include "graph_test.h" |
27 | 27 |
|
28 | 28 |
using namespace lemon; |
29 | 29 |
using namespace lemon::concepts; |
30 | 30 |
|
31 | 31 |
template <class Graph> |
32 |
void |
|
32 |
void checkGraphBuild() { |
|
33 | 33 |
TEMPLATE_GRAPH_TYPEDEFS(Graph); |
34 | 34 |
|
35 | 35 |
Graph G; |
36 | 36 |
checkGraphNodeList(G, 0); |
37 | 37 |
checkGraphEdgeList(G, 0); |
38 |
checkGraphArcList(G, 0); |
|
38 | 39 |
|
39 | 40 |
Node |
40 | 41 |
n1 = G.addNode(), |
41 | 42 |
n2 = G.addNode(), |
42 | 43 |
n3 = G.addNode(); |
43 | 44 |
checkGraphNodeList(G, 3); |
44 | 45 |
checkGraphEdgeList(G, 0); |
46 |
checkGraphArcList(G, 0); |
|
45 | 47 |
|
46 | 48 |
Edge e1 = G.addEdge(n1, n2); |
47 | 49 |
check((G.u(e1) == n1 && G.v(e1) == n2) || (G.u(e1) == n2 && G.v(e1) == n1), |
48 | 50 |
"Wrong edge"); |
51 |
|
|
49 | 52 |
checkGraphNodeList(G, 3); |
53 |
checkGraphEdgeList(G, 1); |
|
50 | 54 |
checkGraphArcList(G, 2); |
51 |
checkGraphEdgeList(G, 1); |
|
52 | 55 |
|
53 |
checkGraphOutArcList(G, n1, 1); |
|
54 |
checkGraphOutArcList(G, n2, 1); |
|
55 |
|
|
56 |
checkGraphIncEdgeArcLists(G, n1, 1); |
|
57 |
checkGraphIncEdgeArcLists(G, n2, 1); |
|
58 |
checkGraphIncEdgeArcLists(G, n3, 0); |
|
56 | 59 |
|
57 |
checkGraphInArcList(G, n1, 1); |
|
58 |
checkGraphInArcList(G, n2, 1); |
|
59 |
|
|
60 |
checkGraphConEdgeList(G, 1); |
|
61 |
checkGraphConArcList(G, 2); |
|
60 | 62 |
|
61 |
checkGraphIncEdgeList(G, n1, 1); |
|
62 |
checkGraphIncEdgeList(G, n2, 1); |
|
63 |
|
|
63 |
Edge e2 = G.addEdge(n2, n1), |
|
64 |
e3 = G.addEdge(n2, n3); |
|
64 | 65 |
|
65 |
checkGraphConArcList(G, 2); |
|
66 |
checkGraphConEdgeList(G, 1); |
|
66 |
checkGraphNodeList(G, 3); |
|
67 |
checkGraphEdgeList(G, 3); |
|
68 |
checkGraphArcList(G, 6); |
|
67 | 69 |
|
68 |
Edge e2 = G.addEdge(n2, n1), e3 = G.addEdge(n2, n3); |
|
69 |
checkGraphNodeList(G, 3); |
|
70 |
checkGraphArcList(G, 6); |
|
71 |
checkGraphEdgeList(G, 3); |
|
70 |
checkGraphIncEdgeArcLists(G, n1, 2); |
|
71 |
checkGraphIncEdgeArcLists(G, n2, 3); |
|
72 |
checkGraphIncEdgeArcLists(G, n3, 1); |
|
72 | 73 |
|
73 |
checkGraphOutArcList(G, n1, 2); |
|
74 |
checkGraphOutArcList(G, n2, 3); |
|
75 |
checkGraphOutArcList(G, n3, 1); |
|
76 |
|
|
77 |
checkGraphInArcList(G, n1, 2); |
|
78 |
checkGraphInArcList(G, n2, 3); |
|
79 |
checkGraphInArcList(G, n3, 1); |
|
80 |
|
|
81 |
checkGraphIncEdgeList(G, n1, 2); |
|
82 |
checkGraphIncEdgeList(G, n2, 3); |
|
83 |
checkGraphIncEdgeList(G, n3, 1); |
|
84 |
|
|
74 |
checkGraphConEdgeList(G, 3); |
|
85 | 75 |
checkGraphConArcList(G, 6); |
86 |
checkGraphConEdgeList(G, 3); |
|
87 | 76 |
|
88 | 77 |
checkArcDirections(G); |
89 | 78 |
|
90 | 79 |
checkNodeIds(G); |
91 | 80 |
checkArcIds(G); |
92 | 81 |
checkEdgeIds(G); |
93 | 82 |
checkGraphNodeMap(G); |
94 | 83 |
checkGraphArcMap(G); |
95 | 84 |
checkGraphEdgeMap(G); |
96 | 85 |
} |
97 | 86 |
|
87 |
template <class Graph> |
|
88 |
void checkGraphAlter() { |
|
89 |
TEMPLATE_GRAPH_TYPEDEFS(Graph); |
|
90 |
|
|
91 |
Graph G; |
|
92 |
Node n1 = G.addNode(), n2 = G.addNode(), |
|
93 |
n3 = G.addNode(), n4 = G.addNode(); |
|
94 |
Edge e1 = G.addEdge(n1, n2), e2 = G.addEdge(n2, n1), |
|
95 |
e3 = G.addEdge(n2, n3), e4 = G.addEdge(n1, n4), |
|
96 |
e5 = G.addEdge(n4, n3); |
|
97 |
|
|
98 |
checkGraphNodeList(G, 4); |
|
99 |
checkGraphEdgeList(G, 5); |
|
100 |
checkGraphArcList(G, 10); |
|
101 |
|
|
102 |
// Check changeU() and changeV() |
|
103 |
if (G.u(e2) == n2) { |
|
104 |
G.changeU(e2, n3); |
|
105 |
} else { |
|
106 |
G.changeV(e2, n3); |
|
107 |
} |
|
108 |
|
|
109 |
checkGraphNodeList(G, 4); |
|
110 |
checkGraphEdgeList(G, 5); |
|
111 |
checkGraphArcList(G, 10); |
|
112 |
|
|
113 |
checkGraphIncEdgeArcLists(G, n1, 3); |
|
114 |
checkGraphIncEdgeArcLists(G, n2, 2); |
|
115 |
checkGraphIncEdgeArcLists(G, n3, 3); |
|
116 |
checkGraphIncEdgeArcLists(G, n4, 2); |
|
117 |
|
|
118 |
checkGraphConEdgeList(G, 5); |
|
119 |
checkGraphConArcList(G, 10); |
|
120 |
|
|
121 |
if (G.u(e2) == n1) { |
|
122 |
G.changeU(e2, n2); |
|
123 |
} else { |
|
124 |
G.changeV(e2, n2); |
|
125 |
} |
|
126 |
|
|
127 |
checkGraphNodeList(G, 4); |
|
128 |
checkGraphEdgeList(G, 5); |
|
129 |
checkGraphArcList(G, 10); |
|
130 |
|
|
131 |
checkGraphIncEdgeArcLists(G, n1, 2); |
|
132 |
checkGraphIncEdgeArcLists(G, n2, 3); |
|
133 |
checkGraphIncEdgeArcLists(G, n3, 3); |
|
134 |
checkGraphIncEdgeArcLists(G, n4, 2); |
|
135 |
|
|
136 |
checkGraphConEdgeList(G, 5); |
|
137 |
checkGraphConArcList(G, 10); |
|
138 |
|
|
139 |
// Check contract() |
|
140 |
G.contract(n1, n4, false); |
|
141 |
|
|
142 |
checkGraphNodeList(G, 3); |
|
143 |
checkGraphEdgeList(G, 5); |
|
144 |
checkGraphArcList(G, 10); |
|
145 |
|
|
146 |
checkGraphIncEdgeArcLists(G, n1, 4); |
|
147 |
checkGraphIncEdgeArcLists(G, n2, 3); |
|
148 |
checkGraphIncEdgeArcLists(G, n3, 3); |
|
149 |
|
|
150 |
checkGraphConEdgeList(G, 5); |
|
151 |
checkGraphConArcList(G, 10); |
|
152 |
|
|
153 |
G.contract(n2, n3); |
|
154 |
|
|
155 |
checkGraphNodeList(G, 2); |
|
156 |
checkGraphEdgeList(G, 3); |
|
157 |
checkGraphArcList(G, 6); |
|
158 |
|
|
159 |
checkGraphIncEdgeArcLists(G, n1, 4); |
|
160 |
checkGraphIncEdgeArcLists(G, n2, 2); |
|
161 |
|
|
162 |
checkGraphConEdgeList(G, 3); |
|
163 |
checkGraphConArcList(G, 6); |
|
164 |
} |
|
165 |
|
|
166 |
template <class Graph> |
|
167 |
void checkGraphErase() { |
|
168 |
TEMPLATE_GRAPH_TYPEDEFS(Graph); |
|
169 |
|
|
170 |
Graph G; |
|
171 |
Node n1 = G.addNode(), n2 = G.addNode(), |
|
172 |
n3 = G.addNode(), n4 = G.addNode(); |
|
173 |
Edge e1 = G.addEdge(n1, n2), e2 = G.addEdge(n2, n1), |
|
174 |
e3 = G.addEdge(n2, n3), e4 = G.addEdge(n1, n4), |
|
175 |
e5 = G.addEdge(n4, n3); |
|
176 |
|
|
177 |
// Check edge deletion |
|
178 |
G.erase(e2); |
|
179 |
|
|
180 |
checkGraphNodeList(G, 4); |
|
181 |
checkGraphEdgeList(G, 4); |
|
182 |
checkGraphArcList(G, 8); |
|
183 |
|
|
184 |
checkGraphIncEdgeArcLists(G, n1, 2); |
|
185 |
checkGraphIncEdgeArcLists(G, n2, 2); |
|
186 |
checkGraphIncEdgeArcLists(G, n3, 2); |
|
187 |
checkGraphIncEdgeArcLists(G, n4, 2); |
|
188 |
|
|
189 |
checkGraphConEdgeList(G, 4); |
|
190 |
checkGraphConArcList(G, 8); |
|
191 |
|
|
192 |
// Check node deletion |
|
193 |
G.erase(n3); |
|
194 |
|
|
195 |
checkGraphNodeList(G, 3); |
|
196 |
checkGraphEdgeList(G, 2); |
|
197 |
checkGraphArcList(G, 4); |
|
198 |
|
|
199 |
checkGraphIncEdgeArcLists(G, n1, 2); |
|
200 |
checkGraphIncEdgeArcLists(G, n2, 1); |
|
201 |
checkGraphIncEdgeArcLists(G, n4, 1); |
|
202 |
|
|
203 |
checkGraphConEdgeList(G, 2); |
|
204 |
checkGraphConArcList(G, 4); |
|
205 |
} |
|
206 |
|
|
207 |
|
|
208 |
template <class Graph> |
|
209 |
void checkGraphSnapshot() { |
|
210 |
TEMPLATE_GRAPH_TYPEDEFS(Graph); |
|
211 |
|
|
212 |
Graph G; |
|
213 |
Node n1 = G.addNode(), n2 = G.addNode(), n3 = G.addNode(); |
|
214 |
Edge e1 = G.addEdge(n1, n2), e2 = G.addEdge(n2, n1), |
|
215 |
e3 = G.addEdge(n2, n3); |
|
216 |
|
|
217 |
checkGraphNodeList(G, 3); |
|
218 |
checkGraphEdgeList(G, 3); |
|
219 |
checkGraphArcList(G, 6); |
|
220 |
|
|
221 |
typename Graph::Snapshot snapshot(G); |
|
222 |
|
|
223 |
Node n = G.addNode(); |
|
224 |
G.addEdge(n3, n); |
|
225 |
G.addEdge(n, n3); |
|
226 |
G.addEdge(n3, n2); |
|
227 |
|
|
228 |
checkGraphNodeList(G, 4); |
|
229 |
checkGraphEdgeList(G, 6); |
|
230 |
checkGraphArcList(G, 12); |
|
231 |
|
|
232 |
snapshot.restore(); |
|
233 |
|
|
234 |
checkGraphNodeList(G, 3); |
|
235 |
checkGraphEdgeList(G, 3); |
|
236 |
checkGraphArcList(G, 6); |
|
237 |
|
|
238 |
checkGraphIncEdgeArcLists(G, n1, 2); |
|
239 |
checkGraphIncEdgeArcLists(G, n2, 3); |
|
240 |
checkGraphIncEdgeArcLists(G, n3, 1); |
|
241 |
|
|
242 |
checkGraphConEdgeList(G, 3); |
|
243 |
checkGraphConArcList(G, 6); |
|
244 |
|
|
245 |
checkNodeIds(G); |
|
246 |
checkEdgeIds(G); |
|
247 |
checkArcIds(G); |
|
248 |
checkGraphNodeMap(G); |
|
249 |
checkGraphEdgeMap(G); |
|
250 |
checkGraphArcMap(G); |
|
251 |
|
|
252 |
G.addNode(); |
|
253 |
snapshot.save(G); |
|
254 |
|
|
255 |
G.addEdge(G.addNode(), G.addNode()); |
|
256 |
|
|
257 |
snapshot.restore(); |
|
258 |
|
|
259 |
checkGraphNodeList(G, 4); |
|
260 |
checkGraphEdgeList(G, 3); |
|
261 |
checkGraphArcList(G, 6); |
|
262 |
} |
|
263 |
|
|
98 | 264 |
void checkConcepts() { |
99 | 265 |
{ // Checking graph components |
100 | 266 |
checkConcept<BaseGraphComponent, BaseGraphComponent >(); |
101 | 267 |
|
102 | 268 |
checkConcept<IDableGraphComponent<>, |
103 | 269 |
IDableGraphComponent<> >(); |
104 | 270 |
|
105 | 271 |
checkConcept<IterableGraphComponent<>, |
106 | 272 |
IterableGraphComponent<> >(); |
107 | 273 |
|
108 | 274 |
checkConcept<MappableGraphComponent<>, |
109 | 275 |
MappableGraphComponent<> >(); |
... | ... |
@@ -225,29 +391,33 @@ |
225 | 391 |
|
226 | 392 |
// for (int j = 0; j < h; ++j) { |
227 | 393 |
// for (int i = 1; i < w; ++i) { |
228 | 394 |
// check(g.source(g.left(g(i, j))) == g(i, j), "Wrong left"); |
229 | 395 |
// check(g.target(g.left(g(i, j))) == g(i - 1, j), "Wrong left"); |
230 | 396 |
// } |
231 | 397 |
// check(g.left(g(0, j)) == INVALID, "Wrong left"); |
232 | 398 |
// } |
233 | 399 |
// } |
234 | 400 |
|
235 | 401 |
void checkGraphs() { |
236 | 402 |
{ // Checking ListGraph |
237 |
|
|
403 |
checkGraphBuild<ListGraph>(); |
|
404 |
checkGraphAlter<ListGraph>(); |
|
405 |
checkGraphErase<ListGraph>(); |
|
406 |
checkGraphSnapshot<ListGraph>(); |
|
238 | 407 |
checkGraphValidityErase<ListGraph>(); |
239 | 408 |
} |
240 | 409 |
{ // Checking SmartGraph |
241 |
|
|
410 |
checkGraphBuild<SmartGraph>(); |
|
411 |
checkGraphSnapshot<SmartGraph>(); |
|
242 | 412 |
checkGraphValidity<SmartGraph>(); |
243 | 413 |
} |
244 | 414 |
// { // Checking FullGraph |
245 | 415 |
// FullGraph g(5); |
246 | 416 |
// checkGraphNodeList(g, 5); |
247 | 417 |
// checkGraphEdgeList(g, 10); |
248 | 418 |
// } |
249 | 419 |
// { // Checking GridGraph |
250 | 420 |
// GridGraph g(5, 6); |
251 | 421 |
// checkGraphNodeList(g, 30); |
252 | 422 |
// checkGraphEdgeList(g, 49); |
253 | 423 |
// checkGridGraph(g, 5, 6); |
... | ... |
@@ -108,24 +108,33 @@ |
108 | 108 |
check(e!=INVALID,"Wrong IncEdge list linking."); |
109 | 109 |
check(n==G.u(e) || n==G.v(e),"Wrong IncEdge list linking."); |
110 | 110 |
check(n==G.baseNode(e),"Wrong OutArc list linking."); |
111 | 111 |
check(G.u(e)==G.runningNode(e) || G.v(e)==G.runningNode(e), |
112 | 112 |
"Wrong OutArc list linking."); |
113 | 113 |
++e; |
114 | 114 |
} |
115 | 115 |
check(e==INVALID,"Wrong IncEdge list linking."); |
116 | 116 |
check(countIncEdges(G,n)==cnt,"Wrong IncEdge number."); |
117 | 117 |
} |
118 | 118 |
|
119 | 119 |
template <class Graph> |
120 |
void checkGraphIncEdgeArcLists(const Graph &G, typename Graph::Node n, |
|
121 |
int cnt) |
|
122 |
{ |
|
123 |
checkGraphIncEdgeList(G, n, cnt); |
|
124 |
checkGraphOutArcList(G, n, cnt); |
|
125 |
checkGraphInArcList(G, n, cnt); |
|
126 |
} |
|
127 |
|
|
128 |
template <class Graph> |
|
120 | 129 |
void checkGraphConArcList(const Graph &G, int cnt) { |
121 | 130 |
int i = 0; |
122 | 131 |
for (typename Graph::NodeIt u(G); u != INVALID; ++u) { |
123 | 132 |
for (typename Graph::NodeIt v(G); v != INVALID; ++v) { |
124 | 133 |
for (ConArcIt<Graph> a(G, u, v); a != INVALID; ++a) { |
125 | 134 |
check(G.source(a) == u, "Wrong iterator."); |
126 | 135 |
check(G.target(a) == v, "Wrong iterator."); |
127 | 136 |
++i; |
128 | 137 |
} |
129 | 138 |
} |
130 | 139 |
} |
131 | 140 |
check(cnt == i, "Wrong iterator."); |
0 comments (0 inline)