ResGraphWrapper mods.
2 #include<hugo/smart_graph.h>
3 #include<hugo/skeletons/graph.h>
4 //#include<../work/alpar/list_graph.h>
7 This test makes consistency checks of list graph structures.
9 G.addNode(), G.addEdge(), G.valid(), G.tail(), G.head()
15 // void check(bool rc, const char *msg) {
17 // std::cerr << msg << std::endl;
22 #define check(rc, msg) \
24 std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \
29 template<class Graph> void checkCompile(Graph &G)
31 typedef typename Graph::Node Node;
32 typedef typename Graph::NodeIt NodeIt;
33 typedef typename Graph::Edge Edge;
34 typedef typename Graph::EdgeIt EdgeIt;
35 typedef typename Graph::InEdgeIt InEdgeIt;
36 typedef typename Graph::OutEdgeIt OutEdgeIt;
39 Node i; Node j(i); Node k(INVALID);
41 bool b=G.valid(i); b=b;
42 b=(i==j); b=(i!=j); b=(i<j);
45 NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);
49 bool b=G.valid(i); b=b;
52 b=(i==j); b=(i!=j); b=(i<j);
55 Edge i; Edge j(i); Edge k(INVALID);
57 bool b=G.valid(i); b=b;
58 b=(i==j); b=(i!=j); b=(i<j);
61 EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);
65 bool b=G.valid(i); b=b;
68 b=(i==j); b=(i!=j); b=(i<j);
72 InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n);
76 bool b=G.valid(i); b=b;
79 b=(i==j); b=(i!=j); b=(i<j);
83 OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n);
87 bool b=G.valid(i); b=b;
90 b=(i==j); b=(i!=j); b=(i<j);
103 { int i=G.id(n); i=i; }
104 { int i=G.id(e); i=i; }
111 typename Graph::template NodeMap<int> m(G);
112 typename Graph::template NodeMap<int> const &cm = m; //Const map
113 //Inicialize with default value
114 typename Graph::template NodeMap<int> mdef(G,12);
115 typename Graph::template NodeMap<int> mm(cm); //Copy
116 typename Graph::template NodeMap<double> dm(cm); //Copy from another type
118 v=m[k]; m[k]=v; m.set(k,v);
122 dm=cm; //Copy from another type
126 typename Graph::template NodeMap<bool> m(G);
127 typename Graph::template NodeMap<bool> const &cm = m; //Const map
128 //Inicialize with default value
129 typename Graph::template NodeMap<bool> mdef(G,12);
130 typename Graph::template NodeMap<bool> mm(cm); //Copy
131 typename Graph::template NodeMap<int> dm(cm); //Copy from another type
133 v=m[k]; m[k]=v; m.set(k,v);
137 dm=cm; //Copy from another type
138 m=dm; //Copy to another type
143 typename Graph::template EdgeMap<int> m(G);
144 typename Graph::template EdgeMap<int> const &cm = m; //Const map
145 //Inicialize with default value
146 typename Graph::template EdgeMap<int> mdef(G,12);
147 typename Graph::template EdgeMap<int> mm(cm); //Copy
148 typename Graph::template EdgeMap<double> dm(cm); //Copy from another type
150 v=m[k]; m[k]=v; m.set(k,v);
154 dm=cm; //Copy from another type
158 typename Graph::template EdgeMap<bool> m(G);
159 typename Graph::template EdgeMap<bool> const &cm = m; //Const map
160 //Inicialize with default value
161 typename Graph::template EdgeMap<bool> mdef(G,12);
162 typename Graph::template EdgeMap<bool> mm(cm); //Copy
163 typename Graph::template EdgeMap<int> dm(cm); //Copy from another type
165 v=m[k]; m[k]=v; m.set(k,v);
169 dm=cm; //Copy from another type
170 m=dm; //Copy to another type
175 template<class Graph> struct PetNodes
177 std::vector<typename Graph::Node> outer, inner;
178 std::vector<typename Graph::Edge> outcir, incir, cons;
181 template<class Graph> PetNodes<Graph> addPetersen(Graph &G,int num=5)
183 //std::vector<typename Graph::Node> outer, inner;
187 for(int i=0;i<num;i++) {
188 n.outer.push_back(G.addNode());
189 n.inner.push_back(G.addNode());
192 for(int i=0;i<num;i++) {
193 n.cons.push_back(G.addEdge(n.outer[i],n.inner[i]));
194 n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%5]));
195 n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%5]));
200 template<class Graph> void checkNodeList(Graph &G, int nn)
202 typename Graph::NodeIt n(G);
203 for(int i=0;i<nn;i++) {
204 check(G.valid(n),"Wrong Node list linking.");
207 check(!G.valid(n),"Wrong Node list linking.");
210 template<class Graph> void checkEdgeList(Graph &G, int nn)
212 typedef typename Graph::EdgeIt EdgeIt;
215 for(int i=0;i<nn;i++) {
216 check(G.valid(e),"Wrong Edge list linking.");
219 check(!G.valid(e),"Wrong Edge list linking.");
222 template<class Graph> void checkOutEdgeList(Graph &G,
223 typename Graph::Node n,
226 typename Graph::OutEdgeIt e(G,n);
227 for(int i=0;i<nn;i++) {
228 check(G.valid(e),"Wrong OutEdge list linking.");
231 check(!G.valid(e),"Wrong OutEdge list linking.");
234 template<class Graph> void checkInEdgeList(Graph &G,
235 typename Graph::Node n,
238 typename Graph::InEdgeIt e(G,n);
239 for(int i=0;i<nn;i++) {
240 check(G.valid(e),"Wrong InEdge list linking.");
243 check(!G.valid(e),"Wrong InEdge list linking.");
246 //Checks head(), tail() as well;
247 template<class Graph> void bidirPetersen(Graph &G)
249 typedef typename Graph::Edge Edge;
250 typedef typename Graph::EdgeIt EdgeIt;
254 std::vector<Edge> ee;
256 for(EdgeIt e(G);G.valid(e);G.next(e)) ee.push_back(e);
258 for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++)
259 G.addEdge(G.head(*p),G.tail(*p));
262 template<class Graph> void checkPetersen(Graph &G)
264 typedef typename Graph::Node Node;
266 typedef typename Graph::EdgeIt EdgeIt;
267 typedef typename Graph::NodeIt NodeIt;
272 for(NodeIt n(G);G.valid(n);G.next(n)) {
273 checkInEdgeList(G,n,3);
274 checkOutEdgeList(G,n,3);
279 template void checkCompile<GraphSkeleton>(GraphSkeleton &);
280 template void checkCompile<SmartGraph>(SmartGraph &);
281 template void checkCompile<SymSmartGraph>(SymSmartGraph &);
282 //template void checkCompile<ListGraph>(ListGraph &);
283 //template void checkCompile<SymListGraph>(SymListGraph &);
285 //Due to some mysterious and some conceptual problems it does not work.
286 //template void checkCompile<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
314 //\todo copy constr tests.
316 std::cout << __FILE__ ": All tests passed.\n";