Finished MinLengthPaths: a specialization of MinCostFlows.
2 #include<hugo/smart_graph.h>
3 #include<hugo/skeletons/graph.h>
4 #include<hugo/list_graph.h>
5 #include<hugo/full_graph.h>
10 This test makes consistency checks of list graph structures.
12 G.addNode(), G.addEdge(), G.valid(), G.tail(), G.head()
14 \todo Checks for empty graphs and isolated points.
19 template<class Graph> void checkCompileStaticGraph(Graph &G)
21 typedef typename Graph::Node Node;
22 typedef typename Graph::NodeIt NodeIt;
23 typedef typename Graph::Edge Edge;
24 typedef typename Graph::EdgeIt EdgeIt;
25 typedef typename Graph::InEdgeIt InEdgeIt;
26 typedef typename Graph::OutEdgeIt OutEdgeIt;
29 Node i; Node j(i); Node k(INVALID);
31 bool b=G.valid(i); b=b;
32 b=(i==j); b=(i!=j); b=(i<j);
35 NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);
39 bool b=G.valid(i); b=b;
42 b=(i==j); b=(i!=j); b=(i<j);
45 Edge i; Edge j(i); Edge k(INVALID);
47 bool b=G.valid(i); b=b;
48 b=(i==j); b=(i!=j); b=(i<j);
51 EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);
55 bool b=G.valid(i); b=b;
58 b=(i==j); b=(i!=j); b=(i<j);
62 InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n);
66 bool b=G.valid(i); b=b;
69 b=(i==j); b=(i!=j); b=(i<j);
73 OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n);
77 bool b=G.valid(i); b=b;
80 b=(i==j); b=(i!=j); b=(i<j);
93 { int i=G.id(n); i=i; }
94 { int i=G.id(e); i=i; }
101 typename Graph::template NodeMap<int> m(G);
102 typename Graph::template NodeMap<int> const &cm = m; //Const map
103 //Inicialize with default value
104 typename Graph::template NodeMap<int> mdef(G,12);
105 typename Graph::template NodeMap<int> mm(cm); //Copy
106 typename Graph::template NodeMap<double> dm(cm); //Copy from another type
108 v=m[k]; m[k]=v; m.set(k,v);
112 dm=cm; //Copy from another type
116 typename Graph::template NodeMap<bool> m(G);
117 typename Graph::template NodeMap<bool> const &cm = m; //Const map
118 //Inicialize with default value
119 typename Graph::template NodeMap<bool> mdef(G,12);
120 typename Graph::template NodeMap<bool> mm(cm); //Copy
121 typename Graph::template NodeMap<int> dm(cm); //Copy from another type
123 v=m[k]; m[k]=v; m.set(k,v);
127 dm=cm; //Copy from another type
128 m=dm; //Copy to another type
133 typename Graph::template EdgeMap<int> m(G);
134 typename Graph::template EdgeMap<int> const &cm = m; //Const map
135 //Inicialize with default value
136 typename Graph::template EdgeMap<int> mdef(G,12);
137 typename Graph::template EdgeMap<int> mm(cm); //Copy
138 typename Graph::template EdgeMap<double> dm(cm); //Copy from another type
140 v=m[k]; m[k]=v; m.set(k,v);
144 dm=cm; //Copy from another type
148 typename Graph::template EdgeMap<bool> m(G);
149 typename Graph::template EdgeMap<bool> const &cm = m; //Const map
150 //Inicialize with default value
151 typename Graph::template EdgeMap<bool> mdef(G,12);
152 typename Graph::template EdgeMap<bool> mm(cm); //Copy
153 typename Graph::template EdgeMap<int> dm(cm); //Copy from another type
155 v=m[k]; m[k]=v; m.set(k,v);
159 dm=cm; //Copy from another type
160 m=dm; //Copy to another type
165 template<class Graph> void checkCompile(Graph &G)
167 checkCompileStaticGraph(G);
169 typedef typename Graph::Node Node;
170 typedef typename Graph::NodeIt NodeIt;
171 typedef typename Graph::Edge Edge;
172 typedef typename Graph::EdgeIt EdgeIt;
173 typedef typename Graph::InEdgeIt InEdgeIt;
174 typedef typename Graph::OutEdgeIt OutEdgeIt;
184 template<class Graph> void checkNodeList(Graph &G, int nn)
186 typename Graph::NodeIt n(G);
187 for(int i=0;i<nn;i++) {
188 check(G.valid(n),"Wrong Node list linking.");
191 check(!G.valid(n),"Wrong Node list linking.");
194 template<class Graph> void checkEdgeList(Graph &G, int nn)
196 typedef typename Graph::EdgeIt EdgeIt;
199 for(int i=0;i<nn;i++) {
200 check(G.valid(e),"Wrong Edge list linking.");
203 check(!G.valid(e),"Wrong Edge list linking.");
206 template<class Graph> void checkOutEdgeList(Graph &G,
207 typename Graph::Node n,
210 typename Graph::OutEdgeIt e(G,n);
211 for(int i=0;i<nn;i++) {
212 check(G.valid(e),"Wrong OutEdge list linking.");
215 check(!G.valid(e),"Wrong OutEdge list linking.");
218 template<class Graph> void checkInEdgeList(Graph &G,
219 typename Graph::Node n,
222 typename Graph::InEdgeIt e(G,n);
223 for(int i=0;i<nn;i++) {
224 check(G.valid(e),"Wrong InEdge list linking.");
227 check(!G.valid(e),"Wrong InEdge list linking.");
230 //Checks head(), tail() as well;
231 template<class Graph> void bidirPetersen(Graph &G)
233 typedef typename Graph::Edge Edge;
234 typedef typename Graph::EdgeIt EdgeIt;
238 std::vector<Edge> ee;
240 for(EdgeIt e(G);G.valid(e);G.next(e)) ee.push_back(e);
242 for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++)
243 G.addEdge(G.head(*p),G.tail(*p));
246 template<class Graph> void checkPetersen(Graph &G)
248 typedef typename Graph::Node Node;
250 typedef typename Graph::EdgeIt EdgeIt;
251 typedef typename Graph::NodeIt NodeIt;
256 for(NodeIt n(G);G.valid(n);G.next(n)) {
257 checkInEdgeList(G,n,3);
258 checkOutEdgeList(G,n,3);
263 template void checkCompile<GraphSkeleton>(GraphSkeleton &);
264 template void checkCompile<SmartGraph>(SmartGraph &);
265 template void checkCompile<SymSmartGraph>(SymSmartGraph &);
266 template void checkCompile<ListGraph>(ListGraph &);
267 template void checkCompile<SymListGraph>(SymListGraph &);
268 template void checkCompileStaticGraph<FullGraph>(FullGraph &);
270 //Due to some mysterious problems it does not work.
271 template void checkCompile<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
272 //template void checkCompile<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
300 //\todo copy constr tests.
302 std::cout << __FILE__ ": All tests passed.\n";