deba@909
|
1 |
/* -*- C++ -*-
|
deba@909
|
2 |
* src/test/sym_graph_test.h - Part of HUGOlib, a generic C++ optimization library
|
deba@909
|
3 |
*
|
deba@909
|
4 |
* Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
deba@909
|
5 |
* (Egervary Combinatorial Optimization Research Group, EGRES).
|
deba@909
|
6 |
*
|
deba@909
|
7 |
* Permission to use, modify and distribute this software is granted
|
deba@909
|
8 |
* provided that this copyright notice appears in all copies. For
|
deba@909
|
9 |
* precise terms see the accompanying LICENSE file.
|
deba@909
|
10 |
*
|
deba@909
|
11 |
* This software is provided "AS IS" with no warranty of any kind,
|
deba@909
|
12 |
* express or implied, and with no claim as to its suitability for any
|
deba@909
|
13 |
* purpose.
|
deba@909
|
14 |
*
|
deba@909
|
15 |
*/
|
deba@909
|
16 |
#ifndef HUGO_TEST_SYM_GRAPH_TEST_H
|
deba@909
|
17 |
#define HUGO_TEST_SYM_GRAPH_TEST_H
|
deba@909
|
18 |
|
deba@909
|
19 |
|
deba@909
|
20 |
#include "graph_test.h"
|
deba@909
|
21 |
#include "test_tools.h"
|
deba@909
|
22 |
|
deba@909
|
23 |
//! \ingroup misc
|
deba@909
|
24 |
//! \file
|
deba@909
|
25 |
//! \brief Some utility to test symmetric graph classes.
|
deba@909
|
26 |
namespace hugo {
|
deba@909
|
27 |
|
deba@909
|
28 |
template<class Graph> void checkCompileStaticSymGraph(Graph &G)
|
deba@909
|
29 |
{
|
deba@909
|
30 |
typedef typename Graph::Node Node;
|
deba@909
|
31 |
typedef typename Graph::NodeIt NodeIt;
|
deba@909
|
32 |
typedef typename Graph::SymEdge SymEdge;
|
deba@909
|
33 |
typedef typename Graph::SymEdgeIt SymEdgeIt;
|
deba@909
|
34 |
typedef typename Graph::Edge Edge;
|
deba@909
|
35 |
typedef typename Graph::EdgeIt EdgeIt;
|
deba@909
|
36 |
typedef typename Graph::InEdgeIt InEdgeIt;
|
deba@909
|
37 |
typedef typename Graph::OutEdgeIt OutEdgeIt;
|
deba@909
|
38 |
|
deba@909
|
39 |
checkCompileStaticGraph(G);
|
deba@909
|
40 |
|
deba@909
|
41 |
{
|
deba@909
|
42 |
SymEdge i; SymEdge j(i); SymEdge k(INVALID);
|
deba@909
|
43 |
i=j;
|
deba@909
|
44 |
bool b; b=true;
|
deba@909
|
45 |
b=(i==INVALID); b=(i!=INVALID);
|
deba@909
|
46 |
b=(i==j); b=(i!=j); b=(i<j);
|
deba@909
|
47 |
Edge e;
|
deba@909
|
48 |
e = G.forward(i);
|
deba@909
|
49 |
e = G.backward(i);
|
deba@909
|
50 |
}
|
deba@909
|
51 |
{
|
deba@909
|
52 |
SymEdgeIt i; SymEdgeIt j(i); SymEdgeIt k(INVALID); SymEdgeIt l(G);
|
deba@909
|
53 |
i=j;
|
deba@909
|
54 |
j=G.first(i);
|
deba@909
|
55 |
j=++i;
|
deba@909
|
56 |
bool b; b=true;
|
deba@909
|
57 |
b=(i==INVALID); b=(i!=INVALID);
|
deba@909
|
58 |
SymEdge n(i);
|
deba@909
|
59 |
n=i;
|
deba@909
|
60 |
b=(i==j); b=(i!=j); b=(i<j);
|
deba@909
|
61 |
//SymEdge ->SymEdgeIt conversion
|
deba@909
|
62 |
SymEdgeIt ni(G,n);
|
deba@909
|
63 |
}
|
deba@909
|
64 |
{
|
deba@909
|
65 |
Edge i, j;
|
deba@909
|
66 |
j = G.opposite(i);
|
deba@909
|
67 |
}
|
deba@909
|
68 |
{
|
deba@909
|
69 |
Node n;
|
deba@909
|
70 |
SymEdge se;
|
deba@909
|
71 |
se=INVALID;
|
deba@909
|
72 |
n=G.tail(se);
|
deba@909
|
73 |
n=G.head(se);
|
deba@909
|
74 |
}
|
deba@909
|
75 |
// id tests
|
deba@909
|
76 |
{ SymEdge n; int i=G.id(n); i=i; }
|
deba@909
|
77 |
//SymEdgeMap tests
|
deba@909
|
78 |
{
|
deba@909
|
79 |
SymEdge k;
|
deba@909
|
80 |
typename Graph::template SymEdgeMap<int> m(G);
|
deba@909
|
81 |
typename Graph::template SymEdgeMap<int> const &cm = m; //Const map
|
deba@909
|
82 |
//Inicialize with default value
|
deba@909
|
83 |
typename Graph::template SymEdgeMap<int> mdef(G,12);
|
deba@909
|
84 |
typename Graph::template SymEdgeMap<int> mm(cm); //Copy
|
deba@909
|
85 |
typename Graph::template SymEdgeMap<double> dm(cm); //Copy from another type
|
deba@909
|
86 |
int v;
|
deba@909
|
87 |
v=m[k]; m[k]=v; m.set(k,v);
|
deba@909
|
88 |
v=cm[k];
|
deba@909
|
89 |
|
deba@909
|
90 |
m=cm;
|
deba@909
|
91 |
dm=cm; //Copy from another type
|
deba@909
|
92 |
{
|
deba@909
|
93 |
//Check the typedef's
|
deba@909
|
94 |
typename Graph::template SymEdgeMap<int>::ValueType val;
|
deba@909
|
95 |
val = 1;
|
deba@909
|
96 |
typename Graph::template SymEdgeMap<int>::KeyType key;
|
deba@909
|
97 |
key = typename Graph::SymEdgeIt(G);
|
deba@909
|
98 |
}
|
deba@909
|
99 |
}
|
deba@909
|
100 |
{ //bool SymEdgeMap
|
deba@909
|
101 |
SymEdge k;
|
deba@909
|
102 |
typename Graph::template SymEdgeMap<bool> m(G);
|
deba@909
|
103 |
typename Graph::template SymEdgeMap<bool> const &cm = m; //Const map
|
deba@909
|
104 |
//Inicialize with default value
|
deba@909
|
105 |
typename Graph::template SymEdgeMap<bool> mdef(G,12);
|
deba@909
|
106 |
typename Graph::template SymEdgeMap<bool> mm(cm); //Copy
|
deba@909
|
107 |
typename Graph::template SymEdgeMap<int> dm(cm); //Copy from another type
|
deba@909
|
108 |
bool v;
|
deba@909
|
109 |
v=m[k]; m[k]=v; m.set(k,v);
|
deba@909
|
110 |
v=cm[k];
|
deba@909
|
111 |
|
deba@909
|
112 |
m=cm;
|
deba@909
|
113 |
dm=cm; //Copy from another type
|
deba@909
|
114 |
m=dm; //Copy to another type
|
deba@909
|
115 |
{
|
deba@909
|
116 |
//Check the typedef's
|
deba@909
|
117 |
typename Graph::template SymEdgeMap<bool>::ValueType val;
|
deba@909
|
118 |
val=true;
|
deba@909
|
119 |
typename Graph::template SymEdgeMap<bool>::KeyType key;
|
deba@909
|
120 |
key= typename Graph::SymEdgeIt(G);
|
deba@909
|
121 |
}
|
deba@909
|
122 |
}
|
deba@909
|
123 |
}
|
deba@909
|
124 |
|
deba@909
|
125 |
template<class Graph> void checkCompileSymGraph(Graph &G)
|
deba@909
|
126 |
{
|
deba@909
|
127 |
checkCompileStaticSymGraph(G);
|
deba@909
|
128 |
|
deba@909
|
129 |
typedef typename Graph::Node Node;
|
deba@909
|
130 |
typedef typename Graph::NodeIt NodeIt;
|
deba@909
|
131 |
typedef typename Graph::SymEdge SymEdge;
|
deba@909
|
132 |
typedef typename Graph::SymEdgeIt SymEdgeIt;
|
deba@909
|
133 |
typedef typename Graph::Edge Edge;
|
deba@909
|
134 |
typedef typename Graph::EdgeIt EdgeIt;
|
deba@909
|
135 |
typedef typename Graph::InEdgeIt InEdgeIt;
|
deba@909
|
136 |
typedef typename Graph::OutEdgeIt OutEdgeIt;
|
deba@909
|
137 |
|
deba@909
|
138 |
Node n,m;
|
deba@909
|
139 |
n=G.addNode();
|
deba@909
|
140 |
m=G.addNode();
|
deba@909
|
141 |
SymEdge e;
|
deba@909
|
142 |
e = G.addEdge(n,m);
|
deba@909
|
143 |
|
deba@909
|
144 |
// G.clear();
|
deba@909
|
145 |
}
|
deba@909
|
146 |
|
deba@909
|
147 |
template<class Graph> void checkCompileSymGraphEraseSymEdge(Graph &G)
|
deba@909
|
148 |
{
|
deba@909
|
149 |
typename Graph::SymEdge n;
|
deba@909
|
150 |
G.erase(n);
|
deba@909
|
151 |
}
|
deba@909
|
152 |
|
deba@909
|
153 |
template<class Graph> void checkCompileErasableSymGraph(Graph &G)
|
deba@909
|
154 |
{
|
deba@909
|
155 |
checkCompileSymGraph(G);
|
deba@909
|
156 |
checkCompileGraphEraseNode(G);
|
deba@909
|
157 |
checkCompileSymGraphEraseSymEdge(G);
|
deba@909
|
158 |
}
|
deba@909
|
159 |
|
deba@909
|
160 |
template<class Graph> void checkGraphSymEdgeList(Graph &G, int nn)
|
deba@909
|
161 |
{
|
deba@909
|
162 |
typedef typename Graph::SymEdgeIt SymEdgeIt;
|
deba@909
|
163 |
|
deba@909
|
164 |
SymEdgeIt e(G);
|
deba@909
|
165 |
for(int i=0;i<nn;i++) {
|
deba@909
|
166 |
check(e!=INVALID,"Wrong SymEdge list linking.");
|
deba@909
|
167 |
++e;
|
deba@909
|
168 |
}
|
deba@909
|
169 |
check(e==INVALID,"Wrong SymEdge list linking.");
|
deba@909
|
170 |
}
|
deba@909
|
171 |
|
deba@909
|
172 |
///\file
|
deba@909
|
173 |
///\todo Check head(), tail() as well;
|
deba@909
|
174 |
|
deba@909
|
175 |
|
deba@909
|
176 |
} //namespace hugo
|
deba@909
|
177 |
|
deba@909
|
178 |
|
deba@909
|
179 |
#endif
|