3
17
2
21
35
61
36
21
36
90
28
16
20
77
109
160
88
9
143
149
1 |
/* -*- C++ -*- |
|
2 |
* |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
4 |
* |
|
5 |
* Copyright (C) 2003-2008 |
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
|
8 |
* |
|
9 |
* Permission to use, modify and distribute this software is granted |
|
10 |
* provided that this copyright notice appears in all copies. For |
|
11 |
* precise terms see the accompanying LICENSE file. |
|
12 |
* |
|
13 |
* This software is provided "AS IS" with no warranty of any kind, |
|
14 |
* express or implied, and with no claim as to its suitability for any |
|
15 |
* purpose. |
|
16 |
* |
|
17 |
*/ |
|
18 |
|
|
19 |
#ifndef LEMON_TEST_MAP_TEST_H |
|
20 |
#define LEMON_TEST_MAP_TEST_H |
|
21 |
|
|
22 |
#include <vector> |
|
23 |
#include <lemon/maps.h> |
|
24 |
|
|
25 |
#include "test_tools.h" |
|
26 |
|
|
27 |
namespace lemon { |
|
28 |
|
|
29 |
template <typename Graph> |
|
30 |
void checkGraphNodeMap() { |
|
31 |
Graph graph; |
|
32 |
const int num = 16; |
|
33 |
|
|
34 |
typedef typename Graph::Node Node; |
|
35 |
|
|
36 |
std::vector<Node> nodes; |
|
37 |
for (int i = 0; i < num; ++i) { |
|
38 |
nodes.push_back(graph.addNode()); |
|
39 |
} |
|
40 |
typedef typename Graph::template NodeMap<int> IntNodeMap; |
|
41 |
IntNodeMap map(graph, 42); |
|
42 |
for (int i = 0; i < int(nodes.size()); ++i) { |
|
43 |
check(map[nodes[i]] == 42, "Wrong map constructor."); |
|
44 |
} |
|
45 |
for (int i = 0; i < num; ++i) { |
|
46 |
nodes.push_back(graph.addNode()); |
|
47 |
map[nodes.back()] = 23; |
|
48 |
check(map[nodes.back()] == 23, "Wrong operator[]."); |
|
49 |
} |
|
50 |
map = constMap<Node>(12); |
|
51 |
for (int i = 0; i < int(nodes.size()); ++i) { |
|
52 |
check(map[nodes[i]] == 12, "Wrong map constructor."); |
|
53 |
} |
|
54 |
graph.clear(); |
|
55 |
nodes.clear(); |
|
56 |
} |
|
57 |
|
|
58 |
template <typename Graph> |
|
59 |
void checkGraphArcMap() { |
|
60 |
Graph graph; |
|
61 |
const int num = 16; |
|
62 |
|
|
63 |
typedef typename Graph::Node Node; |
|
64 |
typedef typename Graph::Arc Arc; |
|
65 |
|
|
66 |
std::vector<Node> nodes; |
|
67 |
for (int i = 0; i < num; ++i) { |
|
68 |
nodes.push_back(graph.addNode()); |
|
69 |
} |
|
70 |
|
|
71 |
std::vector<Arc> arcs; |
|
72 |
for (int i = 0; i < num; ++i) { |
|
73 |
for (int j = 0; j < i; ++j) { |
|
74 |
arcs.push_back(graph.addArc(nodes[i], nodes[j])); |
|
75 |
} |
|
76 |
} |
|
77 |
|
|
78 |
typedef typename Graph::template ArcMap<int> IntArcMap; |
|
79 |
IntArcMap map(graph, 42); |
|
80 |
|
|
81 |
for (int i = 0; i < int(arcs.size()); ++i) { |
|
82 |
check(map[arcs[i]] == 42, "Wrong map constructor."); |
|
83 |
} |
|
84 |
|
|
85 |
for (int i = 0; i < num; ++i) { |
|
86 |
for (int j = i + 1; j < num; ++j) { |
|
87 |
arcs.push_back(graph.addArc(nodes[i], nodes[j])); |
|
88 |
map[arcs.back()] = 23; |
|
89 |
check(map[arcs.back()] == 23, "Wrong operator[]."); |
|
90 |
} |
|
91 |
} |
|
92 |
map = constMap<Arc>(12); |
|
93 |
for (int i = 0; i < int(arcs.size()); ++i) { |
|
94 |
check(map[arcs[i]] == 12, "Wrong map constructor."); |
|
95 |
} |
|
96 |
graph.clear(); |
|
97 |
arcs.clear(); |
|
98 |
} |
|
99 |
|
|
100 |
template <typename Graph> |
|
101 |
void checkGraphEdgeMap() { |
|
102 |
Graph graph; |
|
103 |
const int num = 16; |
|
104 |
|
|
105 |
typedef typename Graph::Node Node; |
|
106 |
typedef typename Graph::Edge Edge; |
|
107 |
|
|
108 |
std::vector<Node> nodes; |
|
109 |
for (int i = 0; i < num; ++i) { |
|
110 |
nodes.push_back(graph.addNode()); |
|
111 |
} |
|
112 |
|
|
113 |
std::vector<Edge> edges; |
|
114 |
for (int i = 0; i < num; ++i) { |
|
115 |
for (int j = 0; j < i; ++j) { |
|
116 |
edges.push_back(graph.addEdge(nodes[i], nodes[j])); |
|
117 |
} |
|
118 |
} |
|
119 |
|
|
120 |
typedef typename Graph::template EdgeMap<int> IntEdgeMap; |
|
121 |
IntEdgeMap map(graph, 42); |
|
122 |
|
|
123 |
for (int i = 0; i < int(edges.size()); ++i) { |
|
124 |
check(map[edges[i]] == 42, "Wrong map constructor."); |
|
125 |
} |
|
126 |
|
|
127 |
for (int i = 0; i < num; ++i) { |
|
128 |
for (int j = i + 1; j < num; ++j) { |
|
129 |
edges.push_back(graph.addEdge(nodes[i], nodes[j])); |
|
130 |
map[edges.back()] = 23; |
|
131 |
check(map[edges.back()] == 23, "Wrong operator[]."); |
|
132 |
} |
|
133 |
} |
|
134 |
map = constMap<Edge>(12); |
|
135 |
for (int i = 0; i < int(edges.size()); ++i) { |
|
136 |
check(map[edges[i]] == 12, "Wrong map constructor."); |
|
137 |
} |
|
138 |
graph.clear(); |
|
139 |
edges.clear(); |
|
140 |
} |
|
141 |
|
|
142 |
} |
|
143 |
|
|
144 |
#endif |
1 |
/* -*- C++ -*- |
|
2 |
* |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
4 |
* |
|
5 |
* Copyright (C) 2003-2008 |
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
|
8 |
* |
|
9 |
* Permission to use, modify and distribute this software is granted |
|
10 |
* provided that this copyright notice appears in all copies. For |
|
11 |
* precise terms see the accompanying LICENSE file. |
|
12 |
* |
|
13 |
* This software is provided "AS IS" with no warranty of any kind, |
|
14 |
* express or implied, and with no claim as to its suitability for any |
|
15 |
* purpose. |
|
16 |
* |
|
17 |
*/ |
|
18 |
|
|
19 |
#ifndef LEMON_TEST_GRAPH_TEST_H |
|
20 |
#define LEMON_TEST_GRAPH_TEST_H |
|
21 |
|
|
22 |
#include <lemon/graph_utils.h> |
|
23 |
#include "test_tools.h" |
|
24 |
|
|
25 |
namespace lemon { |
|
26 |
|
|
27 |
template<class Graph> |
|
28 |
void checkGraphNodeList(const Graph &G, int cnt) |
|
29 |
{ |
|
30 |
typename Graph::NodeIt n(G); |
|
31 |
for(int i=0;i<cnt;i++) { |
|
32 |
check(n!=INVALID,"Wrong Node list linking."); |
|
33 |
++n; |
|
34 |
} |
|
35 |
check(n==INVALID,"Wrong Node list linking."); |
|
36 |
check(countNodes(G)==cnt,"Wrong Node number."); |
|
37 |
} |
|
38 |
|
|
39 |
template<class Graph> |
|
40 |
void checkGraphArcList(const Graph &G, int cnt) |
|
41 |
{ |
|
42 |
typename Graph::ArcIt e(G); |
|
43 |
for(int i=0;i<cnt;i++) { |
|
44 |
check(e!=INVALID,"Wrong Arc list linking."); |
|
45 |
++e; |
|
46 |
} |
|
47 |
check(e==INVALID,"Wrong Arc list linking."); |
|
48 |
check(countArcs(G)==cnt,"Wrong Arc number."); |
|
49 |
} |
|
50 |
|
|
51 |
template<class Graph> |
|
52 |
void checkGraphOutArcList(const Graph &G, typename Graph::Node n, int cnt) |
|
53 |
{ |
|
54 |
typename Graph::OutArcIt e(G,n); |
|
55 |
for(int i=0;i<cnt;i++) { |
|
56 |
check(e!=INVALID,"Wrong OutArc list linking."); |
|
57 |
check(n==G.source(e),"Wrong OutArc list linking."); |
|
58 |
++e; |
|
59 |
} |
|
60 |
check(e==INVALID,"Wrong OutArc list linking."); |
|
61 |
check(countOutArcs(G,n)==cnt,"Wrong OutArc number."); |
|
62 |
} |
|
63 |
|
|
64 |
template<class Graph> |
|
65 |
void checkGraphInArcList(const Graph &G, typename Graph::Node n, int cnt) |
|
66 |
{ |
|
67 |
typename Graph::InArcIt e(G,n); |
|
68 |
for(int i=0;i<cnt;i++) { |
|
69 |
check(e!=INVALID,"Wrong InArc list linking."); |
|
70 |
check(n==G.target(e),"Wrong InArc list linking."); |
|
71 |
++e; |
|
72 |
} |
|
73 |
check(e==INVALID,"Wrong InArc list linking."); |
|
74 |
check(countInArcs(G,n)==cnt,"Wrong InArc number."); |
|
75 |
} |
|
76 |
|
|
77 |
template<class Graph> |
|
78 |
void checkGraphEdgeList(const Graph &G, int cnt) |
|
79 |
{ |
|
80 |
typename Graph::EdgeIt e(G); |
|
81 |
for(int i=0;i<cnt;i++) { |
|
82 |
check(e!=INVALID,"Wrong Edge list linking."); |
|
83 |
++e; |
|
84 |
} |
|
85 |
check(e==INVALID,"Wrong Edge list linking."); |
|
86 |
check(countEdges(G)==cnt,"Wrong Edge number."); |
|
87 |
} |
|
88 |
|
|
89 |
template<class Graph> |
|
90 |
void checkGraphIncEdgeList(const Graph &G, typename Graph::Node n, int cnt) |
|
91 |
{ |
|
92 |
typename Graph::IncEdgeIt e(G,n); |
|
93 |
for(int i=0;i<cnt;i++) { |
|
94 |
check(e!=INVALID,"Wrong IncEdge list linking."); |
|
95 |
check(n==G.u(e) || n==G.v(e),"Wrong IncEdge list linking."); |
|
96 |
++e; |
|
97 |
} |
|
98 |
check(e==INVALID,"Wrong IncEdge list linking."); |
|
99 |
check(countIncEdges(G,n)==cnt,"Wrong IncEdge number."); |
|
100 |
} |
|
101 |
|
|
102 |
template <class Digraph> |
|
103 |
void checkDigraphIterators() { |
|
104 |
typedef typename Digraph::Node Node; |
|
105 |
typedef typename Digraph::NodeIt NodeIt; |
|
106 |
typedef typename Digraph::Arc Arc; |
|
107 |
typedef typename Digraph::ArcIt ArcIt; |
|
108 |
typedef typename Digraph::InArcIt InArcIt; |
|
109 |
typedef typename Digraph::OutArcIt OutArcIt; |
|
110 |
} |
|
111 |
|
|
112 |
template <class Graph> |
|
113 |
void checkGraphIterators() { |
|
114 |
checkDigraphIterators<Graph>(); |
|
115 |
typedef typename Graph::Edge Edge; |
|
116 |
typedef typename Graph::EdgeIt EdgeIt; |
|
117 |
typedef typename Graph::IncEdgeIt IncEdgeIt; |
|
118 |
} |
|
119 |
|
|
120 |
// Structure returned by addPetersen() |
|
121 |
template<class Digraph> |
|
122 |
struct PetStruct |
|
123 |
{ |
|
124 |
// Vector containing the outer nodes |
|
125 |
std::vector<typename Digraph::Node> outer; |
|
126 |
// Vector containing the inner nodes |
|
127 |
std::vector<typename Digraph::Node> inner; |
|
128 |
// Vector containing the arcs of the inner circle |
|
129 |
std::vector<typename Digraph::Arc> incir; |
|
130 |
// Vector containing the arcs of the outer circle |
|
131 |
std::vector<typename Digraph::Arc> outcir; |
|
132 |
// Vector containing the chord arcs |
|
133 |
std::vector<typename Digraph::Arc> chords; |
|
134 |
}; |
|
135 |
|
|
136 |
// Adds the reverse pair of all arcs to a digraph |
|
137 |
template<class Digraph> |
|
138 |
void bidirDigraph(Digraph &G) |
|
139 |
{ |
|
140 |
typedef typename Digraph::Arc Arc; |
|
141 |
typedef typename Digraph::ArcIt ArcIt; |
|
142 |
|
|
143 |
std::vector<Arc> ee; |
|
144 |
|
|
145 |
for(ArcIt e(G);e!=INVALID;++e) ee.push_back(e); |
|
146 |
|
|
147 |
for(int i=0;i<int(ee.size());++i) |
|
148 |
G.addArc(G.target(ee[i]),G.source(ee[i])); |
|
149 |
} |
|
150 |
|
|
151 |
// Adds a Petersen digraph to G. |
|
152 |
// Returns the nodes and arcs of the generated digraph. |
|
153 |
template<typename Digraph> |
|
154 |
PetStruct<Digraph> addPetersen(Digraph &G,int num = 5) |
|
155 |
{ |
|
156 |
PetStruct<Digraph> n; |
|
157 |
|
|
158 |
for(int i=0;i<num;i++) { |
|
159 |
n.outer.push_back(G.addNode()); |
|
160 |
n.inner.push_back(G.addNode()); |
|
161 |
} |
|
162 |
|
|
163 |
for(int i=0;i<num;i++) { |
|
164 |
n.chords.push_back(G.addArc(n.outer[i],n.inner[i])); |
|
165 |
n.outcir.push_back(G.addArc(n.outer[i],n.outer[(i+1) % num])); |
|
166 |
n.incir.push_back(G.addArc(n.inner[i],n.inner[(i+2) % num])); |
|
167 |
} |
|
168 |
|
|
169 |
return n; |
|
170 |
} |
|
171 |
|
|
172 |
// Checks the bidirectioned Petersen digraph |
|
173 |
template<class Digraph> |
|
174 |
void checkBidirPetersen(const Digraph &G, int num = 5) |
|
175 |
{ |
|
176 |
typedef typename Digraph::NodeIt NodeIt; |
|
177 |
|
|
178 |
checkGraphNodeList(G, 2 * num); |
|
179 |
checkGraphArcList(G, 6 * num); |
|
180 |
|
|
181 |
for(NodeIt n(G);n!=INVALID;++n) { |
|
182 |
checkGraphInArcList(G, n, 3); |
|
183 |
checkGraphOutArcList(G, n, 3); |
|
184 |
} |
|
185 |
} |
|
186 |
|
|
187 |
// Structure returned by addUPetersen() |
|
188 |
template<class Graph> |
|
189 |
struct UPetStruct |
|
190 |
{ |
|
191 |
// Vector containing the outer nodes |
|
192 |
std::vector<typename Graph::Node> outer; |
|
193 |
// Vector containing the inner nodes |
|
194 |
std::vector<typename Graph::Node> inner; |
|
195 |
// Vector containing the edges of the inner circle |
|
196 |
std::vector<typename Graph::Edge> incir; |
|
197 |
// Vector containing the edges of the outer circle |
|
198 |
std::vector<typename Graph::Edge> outcir; |
|
199 |
// Vector containing the chord edges |
|
200 |
std::vector<typename Graph::Edge> chords; |
|
201 |
}; |
|
202 |
|
|
203 |
// Adds a Petersen graph to \c G. |
|
204 |
// Returns the nodes and edges of the generated graph. |
|
205 |
template<typename Graph> |
|
206 |
UPetStruct<Graph> addUPetersen(Graph &G,int num=5) |
|
207 |
{ |
|
208 |
UPetStruct<Graph> n; |
|
209 |
|
|
210 |
for(int i=0;i<num;i++) { |
|
211 |
n.outer.push_back(G.addNode()); |
|
212 |
n.inner.push_back(G.addNode()); |
|
213 |
} |
|
214 |
|
|
215 |
for(int i=0;i<num;i++) { |
|
216 |
n.chords.push_back(G.addEdge(n.outer[i],n.inner[i])); |
|
217 |
n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%num])); |
|
218 |
n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%num])); |
|
219 |
} |
|
220 |
|
|
221 |
return n; |
|
222 |
} |
|
223 |
|
|
224 |
// Checks the undirected Petersen graph |
|
225 |
template<class Graph> |
|
226 |
void checkUndirPetersen(const Graph &G, int num = 5) |
|
227 |
{ |
|
228 |
typedef typename Graph::NodeIt NodeIt; |
|
229 |
|
|
230 |
checkGraphNodeList(G, 2 * num); |
|
231 |
checkGraphEdgeList(G, 3 * num); |
|
232 |
checkGraphArcList(G, 6 * num); |
|
233 |
|
|
234 |
for(NodeIt n(G);n!=INVALID;++n) { |
|
235 |
checkGraphIncEdgeList(G, n, 3); |
|
236 |
} |
|
237 |
} |
|
238 |
|
|
239 |
template <class Digraph> |
|
240 |
void checkDigraph() { |
|
241 |
const int num = 5; |
|
242 |
Digraph G; |
|
243 |
checkGraphNodeList(G, 0); |
|
244 |
checkGraphArcList(G, 0); |
|
245 |
addPetersen(G, num); |
|
246 |
bidirDigraph(G); |
|
247 |
checkBidirPetersen(G, num); |
|
248 |
} |
|
249 |
|
|
250 |
template <class Graph> |
|
251 |
void checkGraph() { |
|
252 |
const int num = 5; |
|
253 |
Graph G; |
|
254 |
checkGraphNodeList(G, 0); |
|
255 |
checkGraphEdgeList(G, 0); |
|
256 |
addUPetersen(G, num); |
|
257 |
checkUndirPetersen(G, num); |
|
258 |
} |
|
259 |
|
|
260 |
} //namespace lemon |
|
261 |
|
|
262 |
#endif |
... | ... |
@@ -17,30 +17,23 @@ |
17 | 17 |
*/ |
18 | 18 |
|
19 |
#include "test_tools.h" |
|
20 |
//#include <lemon/smart_graph.h> |
|
19 |
#include <lemon/concepts/digraph.h> |
|
20 |
#include <lemon/smart_graph.h> |
|
21 | 21 |
#include <lemon/list_graph.h> |
22 | 22 |
#include <lemon/bfs.h> |
23 | 23 |
#include <lemon/path.h> |
24 |
|
|
24 |
|
|
25 |
#include "graph_test.h" |
|
26 |
#include "test_tools.h" |
|
25 | 27 |
|
26 | 28 |
using namespace lemon; |
27 | 29 |
|
28 |
const int PET_SIZE =5; |
|
29 |
|
|
30 |
|
|
31 |
void check_Bfs_Compile() |
|
30 |
void checkBfsCompile() |
|
32 | 31 |
{ |
33 | 32 |
typedef concepts::Digraph Digraph; |
34 |
|
|
35 |
typedef Digraph::Arc Arc; |
|
36 |
typedef Digraph::Node Node; |
|
37 |
typedef Digraph::ArcIt ArcIt; |
|
38 |
typedef Digraph::NodeIt NodeIt; |
|
39 |
|
|
40 | 33 |
typedef Bfs<Digraph> BType; |
41 | 34 |
|
42 | 35 |
Digraph G; |
43 |
Node n; |
|
44 |
Arc e; |
|
36 |
Digraph::Node n; |
|
37 |
Digraph::Arc e; |
|
45 | 38 |
int l; |
46 | 39 |
bool b; |
... | ... |
@@ -64,14 +57,10 @@ |
64 | 57 |
} |
65 | 58 |
|
66 |
void |
|
59 |
void checkBfsFunctionCompile() |
|
67 | 60 |
{ |
68 | 61 |
typedef int VType; |
69 | 62 |
typedef concepts::Digraph Digraph; |
70 |
|
|
71 | 63 |
typedef Digraph::Arc Arc; |
72 | 64 |
typedef Digraph::Node Node; |
73 |
typedef Digraph::ArcIt ArcIt; |
|
74 |
typedef Digraph::NodeIt NodeIt; |
|
75 |
typedef concepts::ReadMap<Arc,VType> LengthMap; |
|
76 | 65 |
|
77 | 66 |
Digraph g; |
... | ... |
@@ -84,22 +73,13 @@ |
84 | 73 |
.processedMap(concepts::WriteMap<Node,bool>()) |
85 | 74 |
.run(Node()); |
86 |
|
|
87 | 75 |
} |
88 | 76 |
|
89 |
int main() |
|
90 |
{ |
|
91 |
|
|
92 |
// typedef SmartDigraph Digraph; |
|
93 |
typedef ListDigraph Digraph; |
|
94 |
|
|
95 |
typedef Digraph::Arc Arc; |
|
96 |
typedef Digraph::Node Node; |
|
97 |
typedef Digraph::ArcIt ArcIt; |
|
98 |
typedef Digraph::NodeIt NodeIt; |
|
99 |
|
|
77 |
template <class Digraph> |
|
78 |
void checkBfs() { |
|
79 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
|
100 | 80 |
|
101 | 81 |
Digraph G; |
102 | 82 |
Node s, t; |
103 |
PetStruct<Digraph> ps = addPetersen(G, |
|
83 |
PetStruct<Digraph> ps = addPetersen(G, 5); |
|
104 | 84 |
|
105 | 85 |
s=ps.outer[2]; |
... | ... |
@@ -109,8 +89,8 @@ |
109 | 89 |
bfs_test.run(s); |
110 | 90 |
|
111 |
check(bfs_test.dist(t)==3,"Bfs found a wrong path. |
|
91 |
check(bfs_test.dist(t)==3,"Bfs found a wrong path." << bfs_test.dist(t)); |
|
112 | 92 |
|
113 | 93 |
Path<Digraph> p = bfs_test.path(t); |
114 |
check(p.length()==3," |
|
94 |
check(p.length()==3,"path() found a wrong path."); |
|
115 | 95 |
check(checkPath(G, p),"path() found a wrong path."); |
116 | 96 |
check(pathSource(G, p) == s,"path() found a wrong path."); |
... | ... |
@@ -140,2 +120,8 @@ |
140 | 120 |
} |
141 | 121 |
|
122 |
int main() |
|
123 |
{ |
|
124 |
checkBfs<ListDigraph>(); |
|
125 |
checkBfs<SmartDigraph>(); |
|
126 |
return 0; |
|
127 |
} |
... | ... |
@@ -18,48 +18,73 @@ |
18 | 18 |
|
19 | 19 |
#include <lemon/counter.h> |
20 |
#include <vector> |
|
20 | 21 |
|
21 |
///\file \brief Test cases for time_measure.h |
|
22 |
/// |
|
23 |
|
|
22 |
using namespace lemon; |
|
24 | 23 |
|
24 |
template <typename T> |
|
25 |
void bubbleSort(std::vector<T>& v) { |
|
26 |
Counter op("Bubble Sort - Operations: "); |
|
27 |
Counter::NoSubCounter as(op, "Assignments: "); |
|
28 |
Counter::NoSubCounter co(op, "Comparisons: "); |
|
29 |
for (int i = v.size()-1; i > 0; --i) { |
|
30 |
for (int j = 0; j < i; ++j) { |
|
31 |
if (v[j] > v[j+1]) { |
|
32 |
T tmp = v[j]; |
|
33 |
v[j] = v[j+1]; |
|
34 |
v[j+1] = tmp; |
|
35 |
as += 3; |
|
36 |
} |
|
37 |
++co; |
|
38 |
} |
|
39 |
} |
|
40 |
} |
|
25 | 41 |
|
26 |
int fibonacci(int f) |
|
27 |
{ |
|
28 |
static lemon::Counter count("Fibonacci steps: "); |
|
29 |
count++; |
|
30 |
if(f<1) return 0; |
|
31 |
else if(f==1) return 1; |
|
32 |
|
|
42 |
template <typename T> |
|
43 |
void insertionSort(std::vector<T>& v) { |
|
44 |
Counter op("Insertion Sort - Operations: "); |
|
45 |
Counter::NoSubCounter as(op, "Assignments: "); |
|
46 |
Counter::NoSubCounter co(op, "Comparisons: "); |
|
47 |
for (int i = 1; i < int(v.size()); ++i) { |
|
48 |
T value = v[i]; |
|
49 |
++as; |
|
50 |
int j = i; |
|
51 |
while (j > 0 && v[j-1] > value) { |
|
52 |
v[j] = v[j-1]; |
|
53 |
--j; |
|
54 |
++co; ++as; |
|
55 |
} |
|
56 |
v[j] = value; |
|
57 |
++as; |
|
58 |
} |
|
59 |
} |
|
60 |
|
|
61 |
template <typename MyCounter> |
|
62 |
void counterTest() { |
|
63 |
MyCounter c("Main Counter: "); |
|
64 |
c++; |
|
65 |
typename MyCounter::SubCounter d(c, "SubCounter: "); |
|
66 |
d++; |
|
67 |
typename MyCounter::SubCounter::NoSubCounter e(d, "SubSubCounter: "); |
|
68 |
e++; |
|
69 |
d+=3; |
|
70 |
c-=4; |
|
71 |
e-=2; |
|
72 |
c.reset(2); |
|
73 |
c.reset(); |
|
74 |
} |
|
75 |
|
|
76 |
void init(std::vector<int>& v) { |
|
77 |
v[0] = 10; v[1] = 60; v[2] = 20; v[3] = 90; v[4] = 100; |
|
78 |
v[5] = 80; v[6] = 40; v[7] = 30; v[8] = 50; v[9] = 70; |
|
33 | 79 |
} |
34 | 80 |
|
35 | 81 |
int main() |
36 | 82 |
{ |
37 |
|
|
83 |
counterTest<Counter>(); |
|
84 |
counterTest<NoCounter>(); |
|
38 | 85 |
|
39 |
{ |
|
40 |
typedef lemon::Counter MyCounter; |
|
41 |
MyCounter c("Main counter: "); |
|
42 |
c++; |
|
43 |
c++; |
|
44 |
MyCounter::SubCounter d(c,"Subcounter: "); |
|
45 |
d++; |
|
46 |
d++; |
|
47 |
MyCounter::SubCounter::SubCounter e(d,"SubSubCounter: "); |
|
48 |
e++; |
|
49 |
e++; |
|
50 |
} |
|
51 |
|
|
52 |
{ |
|
53 |
typedef lemon::NoCounter MyCounter; |
|
54 |
MyCounter c("Main counter: "); |
|
55 |
c++; |
|
56 |
c++; |
|
57 |
MyCounter::SubCounter d(c,"Subcounter: "); |
|
58 |
d++; |
|
59 |
d++; |
|
60 |
MyCounter::SubCounter::SubCounter e(d,"SubSubCounter: "); |
|
61 |
e++; |
|
62 |
e++; |
|
63 |
|
|
86 |
std::vector<int> x(10); |
|
87 |
init(x); bubbleSort(x); |
|
88 |
init(x); insertionSort(x); |
|
64 | 89 |
|
65 | 90 |
return 0; |
... | ... |
@@ -17,30 +17,23 @@ |
17 | 17 |
*/ |
18 | 18 |
|
19 |
#include "test_tools.h" |
|
20 |
// #include <lemon/smart_graph.h> |
|
19 |
#include <lemon/concepts/digraph.h> |
|
20 |
#include <lemon/smart_graph.h> |
|
21 | 21 |
#include <lemon/list_graph.h> |
22 | 22 |
#include <lemon/dfs.h> |
23 | 23 |
#include <lemon/path.h> |
24 |
|
|
24 |
|
|
25 |
#include "graph_test.h" |
|
26 |
#include "test_tools.h" |
|
25 | 27 |
|
26 | 28 |
using namespace lemon; |
27 | 29 |
|
28 |
const int PET_SIZE =5; |
|
29 |
|
|
30 |
|
|
31 |
void check_Dfs_SmartDigraph_Compile() |
|
30 |
void checkDfsCompile() |
|
32 | 31 |
{ |
33 | 32 |
typedef concepts::Digraph Digraph; |
34 |
|
|
35 |
typedef Digraph::Arc Arc; |
|
36 |
typedef Digraph::Node Node; |
|
37 |
typedef Digraph::ArcIt ArcIt; |
|
38 |
typedef Digraph::NodeIt NodeIt; |
|
39 |
|
|
40 | 33 |
typedef Dfs<Digraph> DType; |
41 | 34 |
|
42 | 35 |
Digraph G; |
43 |
Node n; |
|
44 |
Arc e; |
|
36 |
Digraph::Node n; |
|
37 |
Digraph::Arc e; |
|
45 | 38 |
int l; |
46 | 39 |
bool b; |
... | ... |
@@ -64,15 +57,10 @@ |
64 | 57 |
} |
65 | 58 |
|
66 |
|
|
67 |
void check_Dfs_Function_Compile() |
|
59 |
void checkDfsFunctionCompile() |
|
68 | 60 |
{ |
69 | 61 |
typedef int VType; |
70 | 62 |
typedef concepts::Digraph Digraph; |
71 |
|
|
72 | 63 |
typedef Digraph::Arc Arc; |
73 | 64 |
typedef Digraph::Node Node; |
74 |
typedef Digraph::ArcIt ArcIt; |
|
75 |
typedef Digraph::NodeIt NodeIt; |
|
76 |
typedef concepts::ReadMap<Arc,VType> LengthMap; |
|
77 | 65 |
|
78 | 66 |
Digraph g; |
... | ... |
@@ -84,23 +72,14 @@ |
84 | 72 |
.reachedMap(concepts::ReadWriteMap<Node,bool>()) |
85 | 73 |
.processedMap(concepts::WriteMap<Node,bool>()) |
86 |
.run(Node()); |
|
87 |
|
|
74 |
.run(Node()); |
|
88 | 75 |
} |
89 | 76 |
|
90 |
int main() |
|
91 |
{ |
|
92 |
|
|
93 |
// typedef SmartDigraph Digraph; |
|
94 |
typedef ListDigraph Digraph; |
|
95 |
|
|
96 |
typedef Digraph::Arc Arc; |
|
97 |
typedef Digraph::Node Node; |
|
98 |
typedef Digraph::ArcIt ArcIt; |
|
99 |
typedef Digraph::NodeIt NodeIt; |
|
100 |
|
|
77 |
template <class Digraph> |
|
78 |
void checkDfs() { |
|
79 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
|
101 | 80 |
|
102 | 81 |
Digraph G; |
103 | 82 |
Node s, t; |
104 |
PetStruct<Digraph> ps = addPetersen(G, |
|
83 |
PetStruct<Digraph> ps = addPetersen(G, 5); |
|
105 | 84 |
|
106 | 85 |
s=ps.outer[2]; |
... | ... |
@@ -111,5 +90,5 @@ |
111 | 90 |
|
112 | 91 |
Path<Digraph> p = dfs_test.path(t); |
113 |
check(p.length()==dfs_test.dist(t),"path() found a wrong path."); |
|
92 |
check(p.length() == dfs_test.dist(t),"path() found a wrong path."); |
|
114 | 93 |
check(checkPath(G, p),"path() found a wrong path."); |
115 | 94 |
check(pathSource(G, p) == s,"path() found a wrong path."); |
... | ... |
@@ -129,2 +108,8 @@ |
129 | 108 |
} |
130 | 109 |
|
110 |
int main() |
|
111 |
{ |
|
112 |
checkDfs<ListDigraph>(); |
|
113 |
checkDfs<SmartDigraph>(); |
|
114 |
return 0; |
|
115 |
} |
... | ... |
@@ -17,24 +17,19 @@ |
17 | 17 |
*/ |
18 | 18 |
|
19 |
#include <iostream> |
|
20 |
#include <vector> |
|
21 |
|
|
22 | 19 |
#include <lemon/concepts/digraph.h> |
23 | 20 |
#include <lemon/list_graph.h> |
24 |
|
|
21 |
#include <lemon/smart_graph.h> |
|
25 | 22 |
//#include <lemon/full_graph.h> |
26 | 23 |
//#include <lemon/hypercube_graph.h> |
27 | 24 |
|
28 | 25 |
#include "test_tools.h" |
29 |
#include "digraph_test.h" |
|
30 |
#include "map_test.h" |
|
31 |
|
|
26 |
#include "graph_test.h" |
|
27 |
#include "graph_maps_test.h" |
|
32 | 28 |
|
33 | 29 |
using namespace lemon; |
34 | 30 |
using namespace lemon::concepts; |
35 | 31 |
|
36 |
|
|
37 |
int main() { |
|
38 |
|
|
32 |
void check_concepts() { |
|
33 |
{ // Checking digraph components |
|
39 | 34 |
checkConcept<BaseDigraphComponent, BaseDigraphComponent >(); |
40 | 35 |
|
... | ... |
@@ -47,36 +42,103 @@ |
47 | 42 |
checkConcept<MappableDigraphComponent<>, |
48 | 43 |
MappableDigraphComponent<> >(); |
49 |
|
|
50 | 44 |
} |
51 |
{ // |
|
45 |
{ // Checking skeleton digraph |
|
52 | 46 |
checkConcept<Digraph, Digraph>(); |
53 | 47 |
} |
54 |
{ // checking list digraph |
|
55 |
checkConcept<Digraph, ListDigraph >(); |
|
48 |
{ // Checking ListDigraph |
|
49 |
checkConcept<Digraph, ListDigraph>(); |
|
56 | 50 |
checkConcept<AlterableDigraphComponent<>, ListDigraph>(); |
57 | 51 |
checkConcept<ExtendableDigraphComponent<>, ListDigraph>(); |
58 | 52 |
checkConcept<ClearableDigraphComponent<>, ListDigraph>(); |
59 | 53 |
checkConcept<ErasableDigraphComponent<>, ListDigraph>(); |
54 |
checkDigraphIterators<ListDigraph>(); |
|
55 |
} |
|
56 |
{ // Checking SmartDigraph |
|
57 |
checkConcept<Digraph, SmartDigraph>(); |
|
58 |
checkConcept<AlterableDigraphComponent<>, SmartDigraph>(); |
|
59 |
checkConcept<ExtendableDigraphComponent<>, SmartDigraph>(); |
|
60 |
checkConcept<ClearableDigraphComponent<>, SmartDigraph>(); |
|
61 |
checkDigraphIterators<SmartDigraph>(); |
|
62 |
} |
|
63 |
// { // Checking FullDigraph |
|
64 |
// checkConcept<Digraph, FullDigraph>(); |
|
65 |
// checkDigraphIterators<FullDigraph>(); |
|
66 |
// } |
|
67 |
// { // Checking HyperCubeDigraph |
|
68 |
// checkConcept<Digraph, HyperCubeDigraph>(); |
|
69 |
// checkDigraphIterators<HyperCubeDigraph>(); |
|
70 |
// } |
|
71 |
} |
|
60 | 72 |
|
73 |
template <typename Digraph> |
|
74 |
void check_graph_validity() { |
|
75 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
|
76 |
Digraph g; |
|
77 |
|
|
78 |
Node |
|
79 |
n1 = g.addNode(), |
|
80 |
n2 = g.addNode(), |
|
81 |
n3 = g.addNode(); |
|
82 |
|
|
83 |
Arc |
|
84 |
e1 = g.addArc(n1, n2), |
|
85 |
e2 = g.addArc(n2, n3); |
|
86 |
|
|
87 |
check(g.valid(n1), "Wrong validity check"); |
|
88 |
check(g.valid(e1), "Wrong validity check"); |
|
89 |
|
|
90 |
check(!g.valid(g.nodeFromId(-1)), "Wrong validity check"); |
|
91 |
check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); |
|
92 |
} |
|
93 |
|
|
94 |
template <typename Digraph> |
|
95 |
void check_graph_validity_erase() { |
|
96 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
|
97 |
Digraph g; |
|
98 |
|
|
99 |
Node |
|
100 |
n1 = g.addNode(), |
|
101 |
n2 = g.addNode(), |
|
102 |
n3 = g.addNode(); |
|
103 |
|
|
104 |
Arc |
|
105 |
e1 = g.addArc(n1, n2), |
|
106 |
e2 = g.addArc(n2, n3); |
|
107 |
|
|
108 |
check(g.valid(n1), "Wrong validity check"); |
|
109 |
check(g.valid(e1), "Wrong validity check"); |
|
110 |
|
|
111 |
g.erase(n1); |
|
112 |
|
|
113 |
check(!g.valid(n1), "Wrong validity check"); |
|
114 |
check(g.valid(n2), "Wrong validity check"); |
|
115 |
check(g.valid(n3), "Wrong validity check"); |
|
116 |
check(!g.valid(e1), "Wrong validity check"); |
|
117 |
check(g.valid(e2), "Wrong validity check"); |
|
118 |
|
|
119 |
check(!g.valid(g.nodeFromId(-1)), "Wrong validity check"); |
|
120 |
check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); |
|
121 |
} |
|
122 |
|
|
123 |
void check_digraphs() { |
|
124 |
{ // Checking ListDigraph |
|
61 | 125 |
checkDigraph<ListDigraph>(); |
62 | 126 |
checkGraphNodeMap<ListDigraph>(); |
63 | 127 |
checkGraphArcMap<ListDigraph>(); |
128 |
|
|
129 |
check_graph_validity_erase<ListDigraph>(); |
|
64 | 130 |
} |
65 |
// { // checking smart digraph |
|
66 |
// checkConcept<Digraph, SmartDigraph >(); |
|
131 |
{ // Checking SmartDigraph |
|
132 |
checkDigraph<SmartDigraph>(); |
|
133 |
checkGraphNodeMap<SmartDigraph>(); |
|
134 |
checkGraphArcMap<SmartDigraph>(); |
|
67 | 135 |
|
68 |
// checkDigraph<SmartDigraph>(); |
|
69 |
// checkDigraphNodeMap<SmartDigraph>(); |
|
70 |
// checkDigraphArcMap<SmartDigraph>(); |
|
71 |
// } |
|
72 |
// { // checking full digraph |
|
73 |
// checkConcept<Digraph, FullDigraph >(); |
|
74 |
// } |
|
75 |
// { // checking full digraph |
|
76 |
// checkConcept<Digraph, HyperCubeDigraph >(); |
|
77 |
// } |
|
136 |
check_graph_validity<SmartDigraph>(); |
|
137 |
} |
|
138 |
} |
|
78 | 139 |
|
79 |
std::cout << __FILE__ ": All tests passed.\n"; |
|
80 |
|
|
140 |
int main() { |
|
141 |
check_concepts(); |
|
142 |
check_digraphs(); |
|
81 | 143 |
return 0; |
82 | 144 |
} |
... | ... |
@@ -17,7 +17,4 @@ |
17 | 17 |
*/ |
18 | 18 |
|
19 |
///\file |
|
20 |
///\brief Test cases for Dijkstra algorithm. |
|
21 |
|
|
22 | 19 |
#include <lemon/concepts/digraph.h> |
23 | 20 |
#include <lemon/smart_graph.h> |
... | ... |
@@ -27,4 +24,5 @@ |
27 | 24 |
#include <lemon/path.h> |
28 | 25 |
|
26 |
#include "graph_test.h" |
|
29 | 27 |
#include "test_tools.h" |
30 | 28 |
... | ... |
@@ -26,37 +26,35 @@ |
26 | 26 |
int main() |
27 | 27 |
{ |
28 |
cout << "Testing classes 'dim2::Point' and 'dim2::BoundingBox'." << endl; |
|
29 |
|
|
30 | 28 |
typedef dim2::Point<int> Point; |
31 | 29 |
|
32 | 30 |
Point p; |
33 |
check(p.size()==2, "Wrong |
|
31 |
check(p.size()==2, "Wrong dim2::Point initialization."); |
|
34 | 32 |
|
35 | 33 |
Point a(1,2); |
36 | 34 |
Point b(3,4); |
37 |
check(a[0]==1 && a[1]==2, "Wrong |
|
35 |
check(a[0]==1 && a[1]==2, "Wrong dim2::Point initialization."); |
|
38 | 36 |
|
39 | 37 |
p = a+b; |
40 |
check(p.x==4 && p.y==6, "Wrong |
|
38 |
check(p.x==4 && p.y==6, "Wrong dim2::Point addition."); |
|
41 | 39 |
|
42 | 40 |
p = a-b; |
43 |
check(p.x==-2 && p.y==-2, "Wrong |
|
41 |
check(p.x==-2 && p.y==-2, "Wrong dim2::Point subtraction."); |
|
44 | 42 |
|
45 |
check(a.normSquare()==5,"Wrong vector norm calculation."); |
|
46 |
check(a*b==11, "Wrong vector scalar product."); |
|
43 |
check(a.normSquare()==5,"Wrong dim2::Point norm calculation."); |
|
44 |
check(a*b==11, "Wrong dim2::Point scalar product."); |
|
47 | 45 |
|
48 | 46 |
int l=2; |
49 | 47 |
p = a*l; |
50 |
check(p.x==2 && p.y==4, "Wrong |
|
48 |
check(p.x==2 && p.y==4, "Wrong dim2::Point multiplication by a scalar."); |
|
51 | 49 |
|
52 | 50 |
p = b/l; |
53 |
check(p.x==1 && p.y==2, "Wrong |
|
51 |
check(p.x==1 && p.y==2, "Wrong dim2::Point division by a scalar."); |
|
54 | 52 |
|
55 | 53 |
typedef dim2::BoundingBox<int> BB; |
56 | 54 |
BB box1; |
57 |
check(box1.empty(), " |
|
55 |
check(box1.empty(), "Wrong empty() in dim2::BoundingBox."); |
|
58 | 56 |
|
59 | 57 |
box1.add(a); |
60 |
check(!box1.empty(), " |
|
58 |
check(!box1.empty(), "Wrong empty() in dim2::BoundingBox."); |
|
61 | 59 |
box1.add(b); |
62 | 60 |
|
... | ... |
@@ -65,22 +63,20 @@ |
65 | 63 |
box1.topRight().x==3 && |
66 | 64 |
box1.topRight().y==4, |
67 |
"Wrong addition of points to |
|
65 |
"Wrong addition of points to dim2::BoundingBox."); |
|
68 | 66 |
|
69 | 67 |
p.x=2; p.y=3; |
70 |
check(box1.inside(p), " |
|
68 |
check(box1.inside(p), "Wrong inside() in dim2::BoundingBox."); |
|
71 | 69 |
|
72 | 70 |
p.x=1; p.y=3; |
73 |
check(box1.inside(p), " |
|
71 |
check(box1.inside(p), "Wrong inside() in dim2::BoundingBox."); |
|
74 | 72 |
|
75 | 73 |
p.x=0; p.y=3; |
76 |
check(!box1.inside(p), " |
|
74 |
check(!box1.inside(p), "Wrong inside() in dim2::BoundingBox."); |
|
77 | 75 |
|
78 | 76 |
BB box2(p); |
79 |
check(!box2.empty(), |
|
80 |
"It should not be empty. Constructed from 1 point."); |
|
77 |
check(!box2.empty(), "Wrong empty() in dim2::BoundingBox."); |
|
81 | 78 |
|
82 | 79 |
box2.add(box1); |
83 |
check(box2.inside(p), |
|
84 |
"It should be inside. Incremented a box with another one."); |
|
80 |
check(box2.inside(p), "Wrong inside() in dim2::BoundingBox."); |
|
85 | 81 |
|
86 | 82 |
return 0; |
... | ... |
@@ -23,8 +23,7 @@ |
23 | 23 |
// #include <lemon/grid_graph.h> |
24 | 24 |
|
25 |
#include <lemon/graph_utils.h> |
|
26 |
|
|
27 | 25 |
#include "test_tools.h" |
28 |
|
|
26 |
#include "graph_test.h" |
|
27 |
#include "graph_maps_test.h" |
|
29 | 28 |
|
30 | 29 |
using namespace lemon; |
... | ... |
@@ -32,6 +31,5 @@ |
32 | 31 |
|
33 | 32 |
void check_concepts() { |
34 |
|
|
35 |
{ // checking digraph components |
|
33 |
{ // Checking graph components |
|
36 | 34 |
checkConcept<BaseGraphComponent, BaseGraphComponent >(); |
37 | 35 |
|
... | ... |
@@ -44,50 +42,38 @@ |
44 | 42 |
checkConcept<MappableGraphComponent<>, |
45 | 43 |
MappableGraphComponent<> >(); |
46 |
|
|
47 | 44 |
} |
48 |
{ |
|
49 |
checkConcept<Graph, ListGraph>(); |
|
50 |
checkConcept<Graph, SmartGraph>(); |
|
51 |
// checkConcept<Graph, FullGraph>(); |
|
52 |
// checkConcept<Graph, Graph>(); |
|
53 |
// checkConcept<Graph, GridGraph>(); |
|
45 |
{ // Checking skeleton graph |
|
46 |
checkConcept<Graph, Graph>(); |
|
54 | 47 |
} |
48 |
{ // Checking ListGraph |
|
49 |
checkConcept<Graph, ListGraph>(); |
|
50 |
checkConcept<AlterableGraphComponent<>, ListGraph>(); |
|
51 |
checkConcept<ExtendableGraphComponent<>, ListGraph>(); |
|
52 |
checkConcept<ClearableGraphComponent<>, ListGraph>(); |
|
53 |
checkConcept<ErasableGraphComponent<>, ListGraph>(); |
|
54 |
checkGraphIterators<ListGraph>(); |
|
55 |
} |
|
56 |
{ // Checking SmartGraph |
|
57 |
checkConcept<Graph, SmartGraph>(); |
|
58 |
checkConcept<AlterableGraphComponent<>, SmartGraph>(); |
|
59 |
checkConcept<ExtendableGraphComponent<>, SmartGraph>(); |
|
60 |
checkConcept<ClearableGraphComponent<>, SmartGraph>(); |
|
61 |
checkGraphIterators<SmartGraph>(); |
|
62 |
} |
|
63 |
// { // Checking FullGraph |
|
64 |
// checkConcept<Graph, FullGraph>(); |
|
65 |
// checkGraphIterators<FullGraph>(); |
|
66 |
// } |
|
67 |
// { // Checking GridGraph |
|
68 |
// checkConcept<Graph, GridGraph>(); |
|
69 |
// checkGraphIterators<GridGraph>(); |
|
70 |
// } |
|
55 | 71 |
} |
56 | 72 |
|
57 | 73 |
template <typename Graph> |
58 |
void check_item_counts(Graph &g, int n, int e) { |
|
59 |
int nn = 0; |
|
60 |
for (typename Graph::NodeIt it(g); it != INVALID; ++it) { |
|
61 |
++nn; |
|
62 |
} |
|
63 |
|
|
64 |
check(nn == n, "Wrong node number."); |
|
65 |
// check(countNodes(g) == n, "Wrong node number."); |
|
66 |
|
|
67 |
int ee = 0; |
|
68 |
for (typename Graph::ArcIt it(g); it != INVALID; ++it) { |
|
69 |
++ee; |
|
70 |
} |
|
71 |
|
|
72 |
check(ee == 2*e, "Wrong arc number."); |
|
73 |
// check(countArcs(g) == 2*e, "Wrong arc number."); |
|
74 |
|
|
75 |
int uee = 0; |
|
76 |
for (typename Graph::EdgeIt it(g); it != INVALID; ++it) { |
|
77 |
++uee; |
|
78 |
} |
|
79 |
|
|
80 |
check(uee == e, "Wrong edge number."); |
|
81 |
// check(countEdges(g) == e, "Wrong edge number."); |
|
82 |
} |
|
83 |
|
|
84 |
template <typename Graph> |
|
85 |
void check_graph_counts() { |
|
86 |
|
|
74 |
void check_graph_validity() { |
|
87 | 75 |
TEMPLATE_GRAPH_TYPEDEFS(Graph); |
88 | 76 |
Graph g; |
89 | 77 |
|
90 |
check_item_counts(g,0,0); |
|
91 |
|
|
92 | 78 |
Node |
93 | 79 |
n1 = g.addNode(), |
... | ... |
@@ -99,15 +85,18 @@ |
99 | 85 |
e2 = g.addEdge(n2, n3); |
100 | 86 |
|
101 |
|
|
87 |
check(g.valid(n1), "Wrong validity check"); |
|
88 |
check(g.valid(e1), "Wrong validity check"); |
|
89 |
check(g.valid(g.direct(e1, true)), "Wrong validity check"); |
|
90 |
|
|
91 |
check(!g.valid(g.nodeFromId(-1)), "Wrong validity check"); |
|
92 |
check(!g.valid(g.edgeFromId(-1)), "Wrong validity check"); |
|
93 |
check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); |
|
102 | 94 |
} |
103 | 95 |
|
104 | 96 |
template <typename Graph> |
105 |
void check_graph_validity() { |
|
106 |
|
|
97 |
void check_graph_validity_erase() { |
|
107 | 98 |
TEMPLATE_GRAPH_TYPEDEFS(Graph); |
108 | 99 |
Graph g; |
109 | 100 |
|
110 |
check_item_counts(g,0,0); |
|
111 |
|
|
112 | 101 |
Node |
113 | 102 |
n1 = g.addNode(), |
... | ... |
@@ -119,51 +108,21 @@ |
119 | 108 |
e2 = g.addEdge(n2, n3); |
120 | 109 |
|
121 |
check(g.valid(n1), "Validity check"); |
|
122 |
check(g.valid(e1), "Validity check"); |
|
123 |
check(g.valid(g.direct(e1, true)), "Validity check"); |
|
124 |
|
|
125 |
check(!g.valid(g.nodeFromId(-1)), "Validity check"); |
|
126 |
check(!g.valid(g.edgeFromId(-1)), "Validity check"); |
|
127 |
check(!g.valid(g.arcFromId(-1)), "Validity check"); |
|
128 |
|
|
129 |
} |
|
130 |
|
|
131 |
template <typename Graph> |
|
132 |
void check_graph_validity_erase() { |
|
133 |
|
|
134 |
TEMPLATE_GRAPH_TYPEDEFS(Graph); |
|
135 |
Graph g; |
|
136 |
|
|
137 |
check_item_counts(g,0,0); |
|
138 |
|
|
139 |
Node |
|
140 |
n1 = g.addNode(), |
|
141 |
n2 = g.addNode(), |
|
142 |
n3 = g.addNode(); |
|
143 |
|
|
144 |
Edge |
|
145 |
e1 = g.addEdge(n1, n2), |
|
146 |
e2 = g.addEdge(n2, n3); |
|
147 |
|
|
148 |
check(g.valid(n1), "Validity check"); |
|
149 |
check(g.valid(e1), "Validity check"); |
|
150 |
check(g.valid(g.direct(e1, true)), "Validity check"); |
|
110 |
check(g.valid(n1), "Wrong validity check"); |
|
111 |
check(g.valid(e1), "Wrong validity check"); |
|
112 |
check(g.valid(g.direct(e1, true)), "Wrong validity check"); |
|
151 | 113 |
|
152 | 114 |
g.erase(n1); |
153 | 115 |
|
154 |
check(!g.valid(n1), "Validity check"); |
|
155 |
check(g.valid(n2), "Validity check"); |
|
156 |
check(g.valid(n3), "Validity check"); |
|
157 |
check(!g.valid(e1), "Validity check"); |
|
158 |
check(g.valid( |
|
116 |
check(!g.valid(n1), "Wrong validity check"); |
|
117 |
check(g.valid(n2), "Wrong validity check"); |
|
118 |
check(g.valid(n3), "Wrong validity check"); |
|
119 |
check(!g.valid(e1), "Wrong validity check"); |
|
120 |
check(g.valid(e2), "Wrong validity check"); |
|
159 | 121 |
|
160 |
check(!g.valid(g.nodeFromId(-1)), "Validity check"); |
|
161 |
check(!g.valid(g.edgeFromId(-1)), "Validity check"); |
|
162 |
check(!g.valid(g.arcFromId(-1)), "Validity check"); |
|
163 |
|
|
122 |
check(!g.valid(g.nodeFromId(-1)), "Wrong validity check"); |
|
123 |
check(!g.valid(g.edgeFromId(-1)), "Wrong validity check"); |
|
124 |
check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); |
|
164 | 125 |
} |
165 | 126 |
|
166 |
|
|
167 |
|
|
168 | 127 |
// void checkGridGraph(const GridGraph& g, int w, int h) { |
169 | 128 |
// check(g.width() == w, "Wrong width"); |
... | ... |
@@ -210,26 +169,35 @@ |
210 | 169 |
// } |
211 | 170 |
|
171 |
void check_graphs() { |
|
172 |
{ // Checking ListGraph |
|
173 |
checkGraph<ListGraph>(); |
|
174 |
checkGraphNodeMap<ListGraph>(); |
|
175 |
checkGraphEdgeMap<ListGraph>(); |
|
176 |
|
|
177 |
check_graph_validity_erase<ListGraph>(); |
|
178 |
} |
|
179 |
{ // Checking SmartGraph |
|
180 |
checkGraph<SmartGraph>(); |
|
181 |
checkGraphNodeMap<SmartGraph>(); |
|
182 |
checkGraphEdgeMap<SmartGraph>(); |
|
183 |
|
|
184 |
check_graph_validity<SmartGraph>(); |
|
185 |
} |
|
186 |
// { // Checking FullGraph |
|
187 |
// FullGraph g(5); |
|
188 |
// checkGraphNodeList(g, 5); |
|
189 |
// checkGraphEdgeList(g, 10); |
|
190 |
// } |
|
191 |
// { // Checking GridGraph |
|
192 |
// GridGraph g(5, 6); |
|
193 |
// checkGraphNodeList(g, 30); |
|
194 |
// checkGraphEdgeList(g, 49); |
|
195 |
// checkGridGraph(g, 5, 6); |
|
196 |
// } |
|
197 |
} |
|
198 |
|
|
212 | 199 |
int main() { |
213 | 200 |
check_concepts(); |
214 |
|
|
215 |
check_graph_counts<ListGraph>(); |
|
216 |
check_graph_counts<SmartGraph>(); |
|
217 |
|
|
218 |
check_graph_validity_erase<ListGraph>(); |
|
219 |
check_graph_validity<SmartGraph>(); |
|
220 |
|
|
221 |
// { |
|
222 |
// FullGraph g(5); |
|
223 |
// check_item_counts(g, 5, 10); |
|
224 |
// } |
|
225 |
|
|
226 |
// { |
|
227 |
// GridGraph g(5, 6); |
|
228 |
// check_item_counts(g, 30, 49); |
|
229 |
// checkGridGraph(g, 5, 6); |
|
230 |
// } |
|
231 |
|
|
232 |
std::cout << __FILE__ ": All tests passed.\n"; |
|
233 |
|
|
201 |
check_graphs(); |
|
234 | 202 |
return 0; |
235 | 203 |
} |
... | ... |
@@ -17,32 +17,168 @@ |
17 | 17 |
*/ |
18 | 18 |
|
19 |
#include <iostream> |
|
20 |
#include <vector> |
|
19 |
#include <cstdlib> |
|
20 |
#include <ctime> |
|
21 | 21 |
|
22 |
#include <lemon/random.h> |
|
22 | 23 |
#include <lemon/graph_utils.h> |
23 |
|
|
24 | 24 |
#include <lemon/list_graph.h> |
25 | 25 |
#include <lemon/smart_graph.h> |
26 | 26 |
|
27 |
#include "graph_test.h" |
|
27 | 28 |
#include "test_tools.h" |
28 |
#include "graph_utils_test.h" |
|
29 |
|
|
30 | 29 |
|
31 | 30 |
using namespace lemon; |
32 | 31 |
|
33 |
template <class Graph> |
|
34 |
void checkSnapDeg() |
|
32 |
template <typename Digraph> |
|
33 |
void checkFindArcs() { |
|
34 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
|
35 |
|
|
36 |
{ |
|
37 |
Digraph digraph; |
|
38 |
for (int i = 0; i < 10; ++i) { |
|
39 |
digraph.addNode(); |
|
40 |
} |
|
41 |
DescriptorMap<Digraph, Node> nodes(digraph); |
|
42 |
typename DescriptorMap<Digraph, Node>::InverseMap invNodes(nodes); |
|
43 |
for (int i = 0; i < 100; ++i) { |
|
44 |
int src = rnd[invNodes.size()]; |
|
45 |
int trg = rnd[invNodes.size()]; |
|
46 |
digraph.addArc(invNodes[src], invNodes[trg]); |
|
47 |
} |
|
48 |
typename Digraph::template ArcMap<bool> found(digraph, false); |
|
49 |
DescriptorMap<Digraph, Arc> arcs(digraph); |
|
50 |
for (NodeIt src(digraph); src != INVALID; ++src) { |
|
51 |
for (NodeIt trg(digraph); trg != INVALID; ++trg) { |
|
52 |
for (ConArcIt<Digraph> con(digraph, src, trg); con != INVALID; ++con) { |
|
53 |
check(digraph.source(con) == src, "Wrong source."); |
|
54 |
check(digraph.target(con) == trg, "Wrong target."); |
|
55 |
check(found[con] == false, "The arc found already."); |
|
56 |
found[con] = true; |
|
57 |
} |
|
58 |
} |
|
59 |
} |
|
60 |
for (ArcIt it(digraph); it != INVALID; ++it) { |
|
61 |
check(found[it] == true, "The arc is not found."); |
|
62 |
} |
|
63 |
} |
|
64 |
|
|
65 |
{ |
|
66 |
int num = 5; |
|
67 |
Digraph fg; |
|
68 |
std::vector<Node> nodes; |
|
69 |
for (int i = 0; i < num; ++i) { |
|
70 |
nodes.push_back(fg.addNode()); |
|
71 |
} |
|
72 |
for (int i = 0; i < num * num; ++i) { |
|
73 |
fg.addArc(nodes[i / num], nodes[i % num]); |
|
74 |
} |
|
75 |
check(countNodes(fg) == num, "Wrong node number."); |
|
76 |
check(countArcs(fg) == num*num, "Wrong arc number."); |
|
77 |
for (NodeIt src(fg); src != INVALID; ++src) { |
|
78 |
for (NodeIt trg(fg); trg != INVALID; ++trg) { |
|
79 |
ConArcIt<Digraph> con(fg, src, trg); |
|
80 |
check(con != INVALID, "There is no connecting arc."); |
|
81 |
check(fg.source(con) == src, "Wrong source."); |
|
82 |
check(fg.target(con) == trg, "Wrong target."); |
|
83 |
check(++con == INVALID, "There is more connecting arc."); |
|
84 |
} |
|
85 |
} |
|
86 |
ArcLookUp<Digraph> al1(fg); |
|
87 |
DynArcLookUp<Digraph> al2(fg); |
|
88 |
AllArcLookUp<Digraph> al3(fg); |
|
89 |
for (NodeIt src(fg); src != INVALID; ++src) { |
|
90 |
for (NodeIt trg(fg); trg != INVALID; ++trg) { |
|
91 |
Arc con1 = al1(src, trg); |
|
92 |
Arc con2 = al2(src, trg); |
|
93 |
Arc con3 = al3(src, trg); |
|
94 |
Arc con4 = findArc(fg, src, trg); |
|
95 |
check(con1 == con2 && con2 == con3 && con3 == con4, "Different results.") |
|
96 |
check(con1 != INVALID, "There is no connecting arc."); |
|
97 |
check(fg.source(con1) == src, "Wrong source."); |
|
98 |
check(fg.target(con1) == trg, "Wrong target."); |
|
99 |
check(al3(src, trg, con3) == INVALID, "There is more connecting arc."); |
|
100 |
check(findArc(fg, src, trg, con4) == INVALID, "There is more connecting arc."); |
|
101 |
} |
|
102 |
} |
|
103 |
} |
|
104 |
} |
|
105 |
|
|
106 |
template <typename Graph> |
|
107 |
void checkFindEdges() { |
|
108 |
TEMPLATE_GRAPH_TYPEDEFS(Graph); |
|
109 |
Graph graph; |
|
110 |
for (int i = 0; i < 10; ++i) { |
|
111 |
graph.addNode(); |
|
112 |
} |
|
113 |
DescriptorMap<Graph, Node> nodes(graph); |
|
114 |
typename DescriptorMap<Graph, Node>::InverseMap invNodes(nodes); |
|
115 |
for (int i = 0; i < 100; ++i) { |
|
116 |
int src = rnd[invNodes.size()]; |
|
117 |
int trg = rnd[invNodes.size()]; |
|
118 |
graph.addEdge(invNodes[src], invNodes[trg]); |
|
119 |
} |
|
120 |
typename Graph::template EdgeMap<int> found(graph, 0); |
|
121 |
DescriptorMap<Graph, Edge> edges(graph); |
|
122 |
for (NodeIt src(graph); src != INVALID; ++src) { |
|
123 |
for (NodeIt trg(graph); trg != INVALID; ++trg) { |
|
124 |
for (ConEdgeIt<Graph> con(graph, src, trg); con != INVALID; ++con) { |
|
125 |
check( (graph.u(con) == src && graph.v(con) == trg) || |
|
126 |
(graph.v(con) == src && graph.u(con) == trg), "Wrong end nodes."); |
|
127 |
++found[con]; |
|
128 |
check(found[con] <= 2, "The edge found more than twice."); |
|
129 |
} |
|
130 |
} |
|
131 |
} |
|
132 |
for (EdgeIt it(graph); it != INVALID; ++it) { |
|
133 |
check( (graph.u(it) != graph.v(it) && found[it] == 2) || |
|
134 |
(graph.u(it) == graph.v(it) && found[it] == 1), |
|
135 |
"The edge is not found correctly."); |
|
136 |
} |
|
137 |
} |
|
138 |
|
|
139 |
template <class Digraph> |
|
140 |
void checkDeg() |
|
35 | 141 |
{ |
36 |
Graph g; |
|
37 |
typename Graph::Node n1=g.addNode(); |
|
38 |
typename Graph::Node n2=g.addNode(); |
|
39 |
|
|
40 |
InDegMap<Graph> ind(g); |
|
41 |
|
|
142 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
|
143 |
|
|
144 |
const int nodeNum = 10; |
|
145 |
const int arcNum = 100; |
|
146 |
Digraph digraph; |
|
147 |
InDegMap<Digraph> inDeg(digraph); |
|
148 |
OutDegMap<Digraph> outDeg(digraph); |
|
149 |
std::vector<Node> nodes(nodeNum); |
|
150 |
for (int i = 0; i < nodeNum; ++i) { |
|
151 |
nodes[i] = digraph.addNode(); |
|
152 |
} |
|
153 |
std::vector<Arc> arcs(arcNum); |
|
154 |
for (int i = 0; i < arcNum; ++i) { |
|
155 |
arcs[i] = digraph.addArc(nodes[rnd[nodeNum]], nodes[rnd[nodeNum]]); |
|
156 |
} |
|
157 |
for (int i = 0; i < nodeNum; ++i) { |
|
158 |
check(inDeg[nodes[i]] == countInArcs(digraph, nodes[i]), |
|
159 |
"Wrong in degree map"); |
|
160 |
} |
|
161 |
for (int i = 0; i < nodeNum; ++i) { |
|
162 |
check(outDeg[nodes[i]] == countOutArcs(digraph, nodes[i]), |
|
163 |
"Wrong out degree map"); |
|
164 |
} |
|
165 |
} |
|
166 |
|
|
167 |
template <class Digraph> |
|
168 |
void checkSnapDeg() |
|
169 |
{ |
|
170 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
|
171 |
|
|
172 |
Digraph g; |
|
173 |
Node n1=g.addNode(); |
|
174 |
Node n2=g.addNode(); |
|
175 |
|
|
176 |
InDegMap<Digraph> ind(g); |
|
177 |
|
|
42 | 178 |
g.addArc(n1,n2); |
43 | 179 |
|
44 |
typename |
|
180 |
typename Digraph::Snapshot snap(g); |
|
45 | 181 |
|
46 |
OutDegMap< |
|
182 |
OutDegMap<Digraph> outd(g); |
|
47 | 183 |
|
48 | 184 |
check(ind[n1]==0 && ind[n2]==1, "Wrong InDegMap value."); |
... | ... |
@@ -51,5 +187,5 @@ |
51 | 187 |
g.addArc(n1,n2); |
52 | 188 |
g.addArc(n2,n1); |
53 |
|
|
189 |
|
|
54 | 190 |
check(ind[n1]==1 && ind[n2]==2, "Wrong InDegMap value."); |
55 | 191 |
check(outd[n1]==2 && outd[n2]==1, "Wrong OutDegMap value."); |
... | ... |
@@ -59,82 +195,18 @@ |
59 | 195 |
check(ind[n1]==0 && ind[n2]==1, "Wrong InDegMap value."); |
60 | 196 |
check(outd[n1]==1 && outd[n2]==0, "Wrong OutDegMap value."); |
61 |
|
|
62 | 197 |
} |
63 | 198 |
|
64 | 199 |
int main() { |
65 |
///\file |
|
66 |
{ // checking list graph |
|
67 |
checkDigraphCounters<ListDigraph>(); |
|
68 |
checkFindArc<ListDigraph>(); |
|
69 |
} |
|
70 |
{ // checking smart graph |
|
71 |
checkDigraphCounters<SmartDigraph>(); |
|
72 |
checkFindArc<SmartDigraph>(); |
|
73 |
} |
|
74 |
{ |
|
75 |
int num = 5; |
|
76 |
SmartDigraph fg; |
|
77 |
std::vector<SmartDigraph::Node> nodes; |
|
78 |
for (int i = 0; i < num; ++i) { |
|
79 |
nodes.push_back(fg.addNode()); |
|
80 |
} |
|
81 |
for (int i = 0; i < num * num; ++i) { |
|
82 |
fg.addArc(nodes[i / num], nodes[i % num]); |
|
83 |
} |
|
84 |
check(countNodes(fg) == num, "FullGraph: wrong node number."); |
|
85 |
check(countArcs(fg) == num*num, "FullGraph: wrong arc number."); |
|
86 |
for (SmartDigraph::NodeIt src(fg); src != INVALID; ++src) { |
|
87 |
for (SmartDigraph::NodeIt trg(fg); trg != INVALID; ++trg) { |
|
88 |
ConArcIt<SmartDigraph> con(fg, src, trg); |
|
89 |
check(con != INVALID, "There is no connecting arc."); |
|
90 |
check(fg.source(con) == src, "Wrong source."); |
|
91 |
check(fg.target(con) == trg, "Wrong target."); |
|
92 |
check(++con == INVALID, "There is more connecting arc."); |
|
93 |
} |
|
94 |
} |
|
95 |
AllArcLookUp<SmartDigraph> el(fg); |
|
96 |
for (SmartDigraph::NodeIt src(fg); src != INVALID; ++src) { |
|
97 |
for (SmartDigraph::NodeIt trg(fg); trg != INVALID; ++trg) { |
|
98 |
SmartDigraph::Arc con = el(src, trg); |
|
99 |
check(con != INVALID, "There is no connecting arc."); |
|
100 |
check(fg.source(con) == src, "Wrong source."); |
|
101 |
check(fg.target(con) == trg, "Wrong target."); |
|
102 |
check(el(src,trg,con) == INVALID, "There is more connecting arc."); |
|
103 |
} |
|
104 |
} |
|
105 |
|
|
200 |
// Checking ConArcIt, ConEdgeIt, ArcLookUp, AllArcLookUp, and DynArcLookUp |
|
201 |
checkFindArcs<ListDigraph>(); |
|
202 |
checkFindArcs<SmartDigraph>(); |
|
203 |
checkFindEdges<ListGraph>(); |
|
204 |
checkFindEdges<SmartGraph>(); |
|
106 | 205 |
|
107 |
//check In/OutDegMap (and Snapshot feature) |
|
108 |
|
|
206 |
// Checking In/OutDegMap (and Snapshot feature) |
|
207 |
checkDeg<ListDigraph>(); |
|
208 |
checkDeg<SmartDigraph>(); |
|
109 | 209 |
checkSnapDeg<ListDigraph>(); |
110 | 210 |
checkSnapDeg<SmartDigraph>(); |
111 |
|
|
112 |
{ |
|
113 |
const int nodeNum = 10; |
|
114 |
const int arcNum = 100; |
|
115 |
ListDigraph digraph; |
|
116 |
InDegMap<ListDigraph> inDeg(digraph); |
|
117 |
OutDegMap<ListDigraph> outDeg(digraph); |
|
118 |
std::vector<ListDigraph::Node> nodes(nodeNum); |
|
119 |
for (int i = 0; i < nodeNum; ++i) { |
|
120 |
nodes[i] = digraph.addNode(); |
|
121 |
} |
|
122 |
std::vector<ListDigraph::Arc> arcs(arcNum); |
|
123 |
for (int i = 0; i < arcNum; ++i) { |
|
124 |
arcs[i] = |
|
125 |
digraph.addArc(nodes[rnd[nodeNum]], nodes[rnd[nodeNum]]); |
|
126 |
} |
|
127 |
for (int i = 0; i < nodeNum; ++i) { |
|
128 |
check(inDeg[nodes[i]] == countInArcs(digraph, nodes[i]), |
|
129 |
"Wrong in degree map"); |
|
130 |
} |
|
131 |
for (int i = 0; i < nodeNum; ++i) { |
|
132 |
check(outDeg[nodes[i]] == countOutArcs(digraph, nodes[i]), |
|
133 |
"Wrong in degree map"); |
|
134 |
} |
|
135 |
} |
|
136 |
|
|
137 |
///Everything is OK |
|
138 |
std::cout << __FILE__ ": All tests passed.\n"; |
|
139 | 211 |
|
140 | 212 |
return 0; |
... | ... |
@@ -43,5 +43,4 @@ |
43 | 43 |
using namespace lemon::concepts; |
44 | 44 |
|
45 |
|
|
46 | 45 |
int main() { |
47 | 46 |
|
... | ... |
@@ -78,5 +77,5 @@ |
78 | 77 |
|
79 | 78 |
{ |
80 |
std:: |
|
79 |
std::cout << "Checking Bin Heap" << std::endl; |
|
81 | 80 |
|
82 | 81 |
typedef BinHeap<Prio, ItemIntMap> IntHeap; |
... | ... |
@@ -92,5 +91,5 @@ |
92 | 91 |
} |
93 | 92 |
{ |
94 |
std:: |
|
93 |
std::cout << "Checking Fib Heap" << std::endl; |
|
95 | 94 |
|
96 | 95 |
typedef FibHeap<Prio, ItemIntMap> IntHeap; |
... | ... |
@@ -106,5 +105,5 @@ |
106 | 105 |
} |
107 | 106 |
{ |
108 |
std:: |
|
107 |
std::cout << "Checking Radix Heap" << std::endl; |
|
109 | 108 |
|
110 | 109 |
typedef RadixHeap<ItemIntMap> IntHeap; |
... | ... |
@@ -121,5 +120,5 @@ |
121 | 120 |
|
122 | 121 |
{ |
123 |
std:: |
|
122 |
std::cout << "Checking Bucket Heap" << std::endl; |
|
124 | 123 |
|
125 | 124 |
typedef BucketHeap<ItemIntMap> IntHeap; |
... | ... |
@@ -135,6 +134,4 @@ |
135 | 134 |
} |
136 | 135 |
|
137 |
std::cout << __FILE__ ": All tests passed.\n"; |
|
138 |
|
|
139 | 136 |
return 0; |
140 | 137 |
} |
... | ... |
@@ -29,5 +29,4 @@ |
29 | 29 |
#include <lemon/concepts/graph.h> |
30 | 30 |
|
31 |
|
|
32 | 31 |
using namespace std; |
33 | 32 |
using namespace lemon; |
... | ... |
@@ -58,5 +57,4 @@ |
58 | 57 |
kruskal(g, r, ws.begin()); |
59 | 58 |
kruskal(ug, ur, uws.begin()); |
60 |
|
|
61 | 59 |
} |
62 | 60 |
|
... | ... |
@@ -98,5 +96,5 @@ |
98 | 96 |
check(kruskal(G, ConstMap<ListGraph::Edge,int>(2), tree_map)==10, |
99 | 97 |
"Total cost should be 10"); |
100 |
//Test with |
|
98 |
//Test with an edge map (filled with uniform costs). |
|
101 | 99 |
check(kruskal(G, edge_cost_map, tree_map)==10, |
102 | 100 |
"Total cost should be 10"); |
... | ... |
@@ -20,25 +20,13 @@ |
20 | 20 |
#define LEMON_TEST_TEST_TOOLS_H |
21 | 21 |
|
22 |
///\ingroup misc |
|
23 |
///\file |
|
24 |
///\brief Some utilities to write test programs. |
|
25 |
|
|
22 | 26 |
#include <iostream> |
23 |
#include <vector> |
|
24 | 27 |
|
25 |
#include <cstdlib> |
|
26 |
#include <ctime> |
|
28 |
///If \c rc is fail, writes an error message and exits. |
|
27 | 29 |
|
28 |
#include <lemon/concept_check.h> |
|
29 |
#include <lemon/concepts/digraph.h> |
|
30 |
|
|
31 |
#include <lemon/random.h> |
|
32 |
|
|
33 |
using namespace lemon; |
|
34 |
|
|
35 |
//! \ingroup misc |
|
36 |
//! \file |
|
37 |
//! \brief Some utilities to write test programs. |
|
38 |
|
|
39 |
|
|
40 |
///If \c rc is fail, writes an error message end exit. |
|
41 |
|
|
42 |
///If \c rc is fail, writes an error message |
|
30 |
///If \c rc is fail, writes an error message and exits. |
|
43 | 31 |
///The error message contains the file name and the line number of the |
44 | 32 |
///source code in a standard from, which makes it possible to go there |
... | ... |
@@ -47,8 +35,8 @@ |
47 | 35 |
///For example |
48 | 36 |
///\code check(0==1,"This is obviously false.");\endcode will |
49 |
///print this (and then exits). |
|
50 |
///\verbatim digraph_test.cc:123: error: This is obviously false. \endverbatim |
|
37 |
///print something like this (and then exits). |
|
38 |
///\verbatim file_name.cc:123: error: This is obviously false. \endverbatim |
|
51 | 39 |
/// |
52 |
///\todo It should be in \c |
|
40 |
///\todo It should be in \c assert.h |
|
53 | 41 |
#define check(rc, msg) \ |
54 | 42 |
if(!(rc)) { \ |
... | ... |
@@ -57,125 +45,3 @@ |
57 | 45 |
} else { } \ |
58 | 46 |
|
59 |
///Structure returned by \ref addPetersen(). |
|
60 |
|
|
61 |
///Structure returned by \ref addPetersen(). |
|
62 |
/// |
|
63 |
template<class Digraph> struct PetStruct |
|
64 |
{ |
|
65 |
///Vector containing the outer nodes. |
|
66 |
std::vector<typename Digraph::Node> outer; |
|
67 |
///Vector containing the inner nodes. |
|
68 |
std::vector<typename Digraph::Node> inner; |
|
69 |
///Vector containing the arcs of the inner circle. |
|
70 |
std::vector<typename Digraph::Arc> incir; |
|
71 |
///Vector containing the arcs of the outer circle. |
|
72 |
std::vector<typename Digraph::Arc> outcir; |
|
73 |
///Vector containing the chord arcs. |
|
74 |
std::vector<typename Digraph::Arc> chords; |
|
75 |
}; |
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
///Adds a Petersen digraph to \c G. |
|
80 |
|
|
81 |
///Adds a Petersen digraph to \c G. |
|
82 |
///\return The nodes and arcs of the generated digraph. |
|
83 |
|
|
84 |
template<typename Digraph> |
|
85 |
PetStruct<Digraph> addPetersen(Digraph &G,int num = 5) |
|
86 |
{ |
|
87 |
PetStruct<Digraph> n; |
|
88 |
|
|
89 |
for(int i=0;i<num;i++) { |
|
90 |
n.outer.push_back(G.addNode()); |
|
91 |
n.inner.push_back(G.addNode()); |
|
92 |
} |
|
93 |
|
|
94 |
for(int i=0;i<num;i++) { |
|
95 |
n.chords.push_back(G.addArc(n.outer[i],n.inner[i])); |
|
96 |
n.outcir.push_back(G.addArc(n.outer[i],n.outer[(i+1) % num])); |
|
97 |
n.incir.push_back(G.addArc(n.inner[i],n.inner[(i+2) % num])); |
|
98 |
} |
|
99 |
return n; |
|
100 |
} |
|
101 |
|
|
102 |
/// \brief Adds to the digraph the reverse pair of all arcs. |
|
103 |
/// |
|
104 |
/// Adds to the digraph the reverse pair of all arcs. |
|
105 |
/// |
|
106 |
template<class Digraph> void bidirDigraph(Digraph &G) |
|
107 |
{ |
|
108 |
typedef typename Digraph::Arc Arc; |
|
109 |
typedef typename Digraph::ArcIt ArcIt; |
|
110 |
|
|
111 |
std::vector<Arc> ee; |
|
112 |
|
|
113 |
for(ArcIt e(G);e!=INVALID;++e) ee.push_back(e); |
|
114 |
|
|
115 |
for(typename std::vector<Arc>::iterator p=ee.begin();p!=ee.end();p++) |
|
116 |
G.addArc(G.target(*p),G.source(*p)); |
|
117 |
} |
|
118 |
|
|
119 |
|
|
120 |
/// \brief Checks the bidirectioned Petersen digraph. |
|
121 |
/// |
|
122 |
/// Checks the bidirectioned Petersen digraph. |
|
123 |
/// |
|
124 |
template<class Digraph> void checkBidirPetersen(Digraph &G, int num = 5) |
|
125 |
{ |
|
126 |
typedef typename Digraph::Node Node; |
|
127 |
|
|
128 |
typedef typename Digraph::ArcIt ArcIt; |
|
129 |
typedef typename Digraph::NodeIt NodeIt; |
|
130 |
|
|
131 |
checkDigraphNodeList(G, 2 * num); |
|
132 |
checkDigraphArcList(G, 6 * num); |
|
133 |
|
|
134 |
for(NodeIt n(G);n!=INVALID;++n) { |
|
135 |
checkDigraphInArcList(G, n, 3); |
|
136 |
checkDigraphOutArcList(G, n, 3); |
|
137 |
} |
|
138 |
} |
|
139 |
|
|
140 |
///Structure returned by \ref addUPetersen(). |
|
141 |
|
|
142 |
///Structure returned by \ref addUPetersen(). |
|
143 |
/// |
|
144 |
template<class Digraph> struct UPetStruct |
|
145 |
{ |
|
146 |
///Vector containing the outer nodes. |
|
147 |
std::vector<typename Digraph::Node> outer; |
|
148 |
///Vector containing the inner nodes. |
|
149 |
std::vector<typename Digraph::Node> inner; |
|
150 |
///Vector containing the arcs of the inner circle. |
|
151 |
std::vector<typename Digraph::Edge> incir; |
|
152 |
///Vector containing the arcs of the outer circle. |
|
153 |
std::vector<typename Digraph::Edge> outcir; |
|
154 |
///Vector containing the chord arcs. |
|
155 |
std::vector<typename Digraph::Edge> chords; |
|
156 |
}; |
|
157 |
|
|
158 |
///Adds a Petersen digraph to the undirected \c G. |
|
159 |
|
|
160 |
///Adds a Petersen digraph to the undirected \c G. |
|
161 |
///\return The nodes and arcs of the generated digraph. |
|
162 |
|
|
163 |
template<typename Digraph> |
|
164 |
UPetStruct<Digraph> addUPetersen(Digraph &G,int num=5) |
|
165 |
{ |
|
166 |
UPetStruct<Digraph> n; |
|
167 |
|
|
168 |
for(int i=0;i<num;i++) { |
|
169 |
n.outer.push_back(G.addNode()); |
|
170 |
n.inner.push_back(G.addNode()); |
|
171 |
} |
|
172 |
|
|
173 |
for(int i=0;i<num;i++) { |
|
174 |
n.chords.push_back(G.addArc(n.outer[i],n.inner[i])); |
|
175 |
n.outcir.push_back(G.addArc(n.outer[i],n.outer[(i+1)%5])); |
|
176 |
n.incir.push_back(G.addArc(n.inner[i],n.inner[(i+2)%5])); |
|
177 |
} |
|
178 |
return n; |
|
179 |
} |
|
180 |
|
|
181 | 47 |
#endif |
... | ... |
@@ -17,6 +17,4 @@ |
17 | 17 |
*/ |
18 | 18 |
|
19 |
#include <iostream> |
|
20 |
|
|
21 | 19 |
#include <lemon/list_graph.h> |
22 | 20 |
#include <lemon/maps.h> |
... | ... |
@@ -40,5 +38,5 @@ |
40 | 38 |
U.insert(n[2]); |
41 | 39 |
|
42 |
check(U.join(n[1],n[2]) != -1," |
|
40 |
check(U.join(n[1],n[2]) != -1, "Something is wrong with UnionFindEnum"); |
|
43 | 41 |
|
44 | 42 |
U.insert(n[3]); |
... | ... |
@@ -49,7 +47,7 @@ |
49 | 47 |
|
50 | 48 |
|
51 |
check(U.join(n[1],n[4]) != -1,"Test failed."); |
|
52 |
check(U.join(n[2],n[4]) == -1,"Test failed."); |
|
53 |
check(U.join(n[ |
|
49 |
check(U.join(n[1],n[4]) != -1, "Something is wrong with UnionFindEnum"); |
|
50 |
check(U.join(n[2],n[4]) == -1, "Something is wrong with UnionFindEnum"); |
|
51 |
check(U.join(n[3],n[5]) != -1, "Something is wrong with UnionFindEnum"); |
|
54 | 52 |
|
55 | 53 |
|
... | ... |
@@ -57,8 +55,8 @@ |
57 | 55 |
|
58 | 56 |
|
59 |
check(U.size(U.find(n[4])) == 3,"Test failed."); |
|
60 |
check(U.size(U.find(n[5])) == 3,"Test failed."); |
|
61 |
check(U.size(U.find(n[6])) == 1,"Test failed."); |
|
62 |
check(U.size(U.find(n[2])) == 3,"Test failed."); |
|
57 |
check(U.size(U.find(n[4])) == 3, "Something is wrong with UnionFindEnum"); |
|
58 |
check(U.size(U.find(n[5])) == 3, "Something is wrong with UnionFindEnum"); |
|
59 |
check(U.size(U.find(n[6])) == 1, "Something is wrong with UnionFindEnum"); |
|
60 |
check(U.size(U.find(n[2])) == 3, "Something is wrong with UnionFindEnum"); |
|
63 | 61 |
|
64 | 62 |
|
... | ... |
@@ -67,17 +65,17 @@ |
67 | 65 |
|
68 | 66 |
|
69 |
check(U.join(n[8],n[10]) != -1," |
|
67 |
check(U.join(n[8],n[10]) != -1, "Something is wrong with UnionFindEnum"); |
|
70 | 68 |
|
71 | 69 |
|
72 |
check(U.size(U.find(n[4])) == 3,"Test failed."); |
|
73 |
check(U.size(U.find(n[9])) == 5,"Test failed."); |
|
70 |
check(U.size(U.find(n[4])) == 3, "Something is wrong with UnionFindEnum"); |
|
71 |
check(U.size(U.find(n[9])) == 5, "Something is wrong with UnionFindEnum"); |
|
74 | 72 |
|
75 |
check(U.size(U.find(n[8])) == 5," |
|
73 |
check(U.size(U.find(n[8])) == 5, "Something is wrong with UnionFindEnum"); |
|
76 | 74 |
|
77 | 75 |
U.erase(n[9]); |
78 | 76 |
U.erase(n[1]); |
79 | 77 |
|
80 |
check(U.size(U.find(n[10])) == 4,"Test failed."); |
|
81 |
check(U.size(U.find(n[2])) == 2,"Test failed."); |
|
78 |
check(U.size(U.find(n[10])) == 4, "Something is wrong with UnionFindEnum"); |
|
79 |
check(U.size(U.find(n[2])) == 2, "Something is wrong with UnionFindEnum"); |
|
82 | 80 |
|
83 | 81 |
U.erase(n[6]); |
... | ... |
@@ -85,16 +83,16 @@ |
85 | 83 |
|
86 | 84 |
|
87 |
check(U.size(U.find(n[4])) == 2,"Test failed."); |
|
88 |
check(U.size(U.find(n[3])) == 1,"Test failed."); |
|
89 |
check(U.size(U.find(n[ |
|
85 |
check(U.size(U.find(n[4])) == 2, "Something is wrong with UnionFindEnum"); |
|
86 |
check(U.size(U.find(n[3])) == 1, "Something is wrong with UnionFindEnum"); |
|
87 |
check(U.size(U.find(n[2])) == 2, "Something is wrong with UnionFindEnum"); |
|
90 | 88 |
|
91 | 89 |
|
92 |
check(U.join(n[3],n[4]) != -1,"Test failed."); |
|
93 |
check(U.join(n[2],n[4]) == -1,"Test failed."); |
|
90 |
check(U.join(n[3],n[4]) != -1, "Something is wrong with UnionFindEnum"); |
|
91 |
check(U.join(n[2],n[4]) == -1, "Something is wrong with UnionFindEnum"); |
|
94 | 92 |
|
95 | 93 |
|
96 |
check(U.size(U.find(n[4])) == 3,"Test failed."); |
|
97 |
check(U.size(U.find(n[3])) == 3,"Test failed."); |
|
98 |
check(U.size(U.find(n[ |
|
94 |
check(U.size(U.find(n[4])) == 3, "Something is wrong with UnionFindEnum"); |
|
95 |
check(U.size(U.find(n[3])) == 3, "Something is wrong with UnionFindEnum"); |
|
96 |
check(U.size(U.find(n[2])) == 3, "Something is wrong with UnionFindEnum"); |
|
99 | 97 |
|
100 | 98 |
U.eraseClass(U.find(n[4])); |
1 |
/* -*- C++ -*- |
|
2 |
* |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
4 |
* |
|
5 |
* Copyright (C) 2003-2008 |
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
|
8 |
* |
|
9 |
* Permission to use, modify and distribute this software is granted |
|
10 |
* provided that this copyright notice appears in all copies. For |
|
11 |
* precise terms see the accompanying LICENSE file. |
|
12 |
* |
|
13 |
* This software is provided "AS IS" with no warranty of any kind, |
|
14 |
* express or implied, and with no claim as to its suitability for any |
|
15 |
* purpose. |
|
16 |
* |
|
17 |
*/ |
|
18 |
|
|
19 |
#ifndef LEMON_TEST_GRAPH_TEST_H |
|
20 |
#define LEMON_TEST_GRAPH_TEST_H |
|
21 |
|
|
22 |
//#include <lemon/graph_utils.h> |
|
23 |
#include "test_tools.h" |
|
24 |
|
|
25 |
//! \ingroup misc |
|
26 |
//! \file |
|
27 |
//! \brief Some utility and test cases to test digraph classes. |
|
28 |
namespace lemon { |
|
29 |
|
|
30 |
///Structure returned by \ref addPetersen(). |
|
31 |
|
|
32 |
///Structure returned by \ref addPetersen(). |
|
33 |
/// |
|
34 |
template<class Digraph> |
|
35 |
struct PetStruct |
|
36 |
{ |
|
37 |
///Vector containing the outer nodes. |
|
38 |
std::vector<typename Digraph::Node> outer; |
|
39 |
///Vector containing the inner nodes. |
|
40 |
std::vector<typename Digraph::Node> inner; |
|
41 |
///Vector containing the edges of the inner circle. |
|
42 |
std::vector<typename Digraph::Arc> incir; |
|
43 |
///Vector containing the edges of the outer circle. |
|
44 |
std::vector<typename Digraph::Arc> outcir; |
|
45 |
///Vector containing the chord edges. |
|
46 |
std::vector<typename Digraph::Arc> chords; |
|
47 |
}; |
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
///Adds a Petersen graph to \c G. |
|
52 |
|
|
53 |
///Adds a Petersen graph to \c G. |
|
54 |
///\return The nodes and edges of the generated graph. |
|
55 |
|
|
56 |
template<typename Digraph> |
|
57 |
PetStruct<Digraph> addPetersen(Digraph &G,int num = 5) |
|
58 |
{ |
|
59 |
PetStruct<Digraph> n; |
|
60 |
|
|
61 |
for(int i=0;i<num;i++) { |
|
62 |
n.outer.push_back(G.addNode()); |
|
63 |
n.inner.push_back(G.addNode()); |
|
64 |
} |
|
65 |
|
|
66 |
for(int i=0;i<num;i++) { |
|
67 |
n.chords.push_back(G.addArc(n.outer[i],n.inner[i])); |
|
68 |
n.outcir.push_back(G.addArc(n.outer[i],n.outer[(i+1) % num])); |
|
69 |
n.incir.push_back(G.addArc(n.inner[i],n.inner[(i+2) % num])); |
|
70 |
} |
|
71 |
return n; |
|
72 |
} |
|
73 |
|
|
74 |
/// \brief Adds to the digraph the reverse pair of all edges. |
|
75 |
/// |
|
76 |
/// Adds to the digraph the reverse pair of all edges. |
|
77 |
/// |
|
78 |
template<class Digraph> |
|
79 |
void bidirDigraph(Digraph &G) |
|
80 |
{ |
|
81 |
typedef typename Digraph::Arc Arc; |
|
82 |
typedef typename Digraph::ArcIt ArcIt; |
|
83 |
|
|
84 |
std::vector<Arc> ee; |
|
85 |
|
|
86 |
for(ArcIt e(G);e!=INVALID;++e) ee.push_back(e); |
|
87 |
|
|
88 |
for(typename std::vector<Arc>::iterator p=ee.begin();p!=ee.end();p++) |
|
89 |
G.addArc(G.target(*p),G.source(*p)); |
|
90 |
} |
|
91 |
|
|
92 |
|
|
93 |
/// \brief Checks the bidirectioned Petersen graph. |
|
94 |
/// |
|
95 |
/// Checks the bidirectioned Petersen graph. |
|
96 |
/// |
|
97 |
template<class Digraph> |
|
98 |
void checkBidirPetersen(Digraph &G, int num = 5) |
|
99 |
{ |
|
100 |
typedef typename Digraph::Node Node; |
|
101 |
|
|
102 |
typedef typename Digraph::ArcIt ArcIt; |
|
103 |
typedef typename Digraph::NodeIt NodeIt; |
|
104 |
|
|
105 |
checkDigraphNodeList(G, 2 * num); |
|
106 |
checkDigraphArcList(G, 6 * num); |
|
107 |
|
|
108 |
for(NodeIt n(G);n!=INVALID;++n) { |
|
109 |
checkDigraphInArcList(G, n, 3); |
|
110 |
checkDigraphOutArcList(G, n, 3); |
|
111 |
} |
|
112 |
} |
|
113 |
|
|
114 |
template<class Digraph> void checkDigraphNodeList(Digraph &G, int nn) |
|
115 |
{ |
|
116 |
typename Digraph::NodeIt n(G); |
|
117 |
for(int i=0;i<nn;i++) { |
|
118 |
check(n!=INVALID,"Wrong Node list linking."); |
|
119 |
++n; |
|
120 |
} |
|
121 |
check(n==INVALID,"Wrong Node list linking."); |
|
122 |
} |
|
123 |
|
|
124 |
template<class Digraph> |
|
125 |
void checkDigraphArcList(Digraph &G, int nn) |
|
126 |
{ |
|
127 |
typedef typename Digraph::ArcIt ArcIt; |
|
128 |
|
|
129 |
ArcIt e(G); |
|
130 |
for(int i=0;i<nn;i++) { |
|
131 |
check(e!=INVALID,"Wrong Arc list linking."); |
|
132 |
++e; |
|
133 |
} |
|
134 |
check(e==INVALID,"Wrong Arc list linking."); |
|
135 |
} |
|
136 |
|
|
137 |
template<class Digraph> |
|
138 |
void checkDigraphOutArcList(Digraph &G, typename Digraph::Node n, int nn) |
|
139 |
{ |
|
140 |
typename Digraph::OutArcIt e(G,n); |
|
141 |
for(int i=0;i<nn;i++) { |
|
142 |
check(e!=INVALID,"Wrong OutArc list linking."); |
|
143 |
check(n==G.source(e), "Wrong OutArc list linking."); |
|
144 |
++e; |
|
145 |
} |
|
146 |
check(e==INVALID,"Wrong OutArc list linking."); |
|
147 |
} |
|
148 |
|
|
149 |
template<class Digraph> void |
|
150 |
checkDigraphInArcList(Digraph &G, typename Digraph::Node n, int nn) |
|
151 |
{ |
|
152 |
typename Digraph::InArcIt e(G,n); |
|
153 |
for(int i=0;i<nn;i++) { |
|
154 |
check(e!=INVALID,"Wrong InArc list linking."); |
|
155 |
check(n==G.target(e), "Wrong InArc list linking."); |
|
156 |
++e; |
|
157 |
} |
|
158 |
check(e==INVALID,"Wrong InArc list linking."); |
|
159 |
} |
|
160 |
|
|
161 |
template <class Digraph> |
|
162 |
void checkDigraph() { |
|
163 |
const int num = 5; |
|
164 |
Digraph G; |
|
165 |
addPetersen(G, num); |
|
166 |
bidirDigraph(G); |
|
167 |
checkBidirPetersen(G, num); |
|
168 |
} |
|
169 |
|
|
170 |
template <class Digraph> |
|
171 |
void checkDigraphIterators(const Digraph& digraph) { |
|
172 |
typedef typename Digraph::Node Node; |
|
173 |
typedef typename Digraph::NodeIt NodeIt; |
|
174 |
typedef typename Digraph::Arc Arc; |
|
175 |
typedef typename Digraph::ArcIt ArcIt; |
|
176 |
typedef typename Digraph::InArcIt InArcIt; |
|
177 |
typedef typename Digraph::OutArcIt OutArcIt; |
|
178 |
// typedef ConArcIt<Digraph> ConArcIt; |
|
179 |
} |
|
180 |
|
|
181 |
///\file |
|
182 |
///\todo Check target(), source() as well; |
|
183 |
|
|
184 |
|
|
185 |
} //namespace lemon |
|
186 |
|
|
187 |
|
|
188 |
#endif |
1 |
/* -*- C++ -*- |
|
2 |
* |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
4 |
* |
|
5 |
* Copyright (C) 2003-2008 |
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
|
8 |
* |
|
9 |
* Permission to use, modify and distribute this software is granted |
|
10 |
* provided that this copyright notice appears in all copies. For |
|
11 |
* precise terms see the accompanying LICENSE file. |
|
12 |
* |
|
13 |
* This software is provided "AS IS" with no warranty of any kind, |
|
14 |
* express or implied, and with no claim as to its suitability for any |
|
15 |
* purpose. |
|
16 |
* |
|
17 |
*/ |
|
18 |
|
|
19 |
#ifndef LEMON_TEST_GRAPH_UTILS_TEST_H |
|
20 |
#define LEMON_TEST_GRAPH_UTILS_TEST_H |
|
21 |
|
|
22 |
|
|
23 |
#include "test_tools.h" |
|
24 |
#include <cstdlib> |
|
25 |
#include <ctime> |
|
26 |
|
|
27 |
//! \ingroup misc |
|
28 |
//! \file |
|
29 |
//! \brief Test cases for graph utils. |
|
30 |
namespace lemon { |
|
31 |
|
|
32 |
template <typename Digraph> |
|
33 |
void checkDigraphCounters() { |
|
34 |
const int num = 5; |
|
35 |
Digraph digraph; |
|
36 |
addPetersen(digraph, num); |
|
37 |
bidirDigraph(digraph); |
|
38 |
check(countNodes(digraph) == 2*num, "Wrong node number."); |
|
39 |
check(countArcs(digraph) == 6*num, "Wrong arc number."); |
|
40 |
for (typename Digraph::NodeIt it(digraph); it != INVALID; ++it) { |
|
41 |
check(countOutArcs(digraph, it) == 3, "Wrong out degree number."); |
|
42 |
check(countInArcs(digraph, it) == 3, "Wrong in degree number."); |
|
43 |
} |
|
44 |
} |
|
45 |
|
|
46 |
template <typename Digraph> |
|
47 |
void checkFindArc() { |
|
48 |
typedef typename Digraph::Node Node; |
|
49 |
typedef typename Digraph::Arc Arc; |
|
50 |
typedef typename Digraph::NodeIt NodeIt; |
|
51 |
typedef typename Digraph::ArcIt ArcIt; |
|
52 |
Digraph digraph; |
|
53 |
for (int i = 0; i < 10; ++i) { |
|
54 |
digraph.addNode(); |
|
55 |
} |
|
56 |
DescriptorMap<Digraph, Node> nodes(digraph); |
|
57 |
typename DescriptorMap<Digraph, Node>::InverseMap invNodes(nodes); |
|
58 |
for (int i = 0; i < 100; ++i) { |
|
59 |
int src = rnd[invNodes.size()]; |
|
60 |
int trg = rnd[invNodes.size()]; |
|
61 |
digraph.addArc(invNodes[src], invNodes[trg]); |
|
62 |
} |
|
63 |
typename Digraph::template ArcMap<bool> found(digraph, false); |
|
64 |
DescriptorMap<Digraph, Arc> arcs(digraph); |
|
65 |
for (NodeIt src(digraph); src != INVALID; ++src) { |
|
66 |
for (NodeIt trg(digraph); trg != INVALID; ++trg) { |
|
67 |
for (ConArcIt<Digraph> con(digraph, src, trg); con != INVALID; ++con) { |
|
68 |
check(digraph.source(con) == src, "Wrong source."); |
|
69 |
check(digraph.target(con) == trg, "Wrong target."); |
|
70 |
check(found[con] == false, "The arc found already."); |
|
71 |
found[con] = true; |
|
72 |
} |
|
73 |
} |
|
74 |
} |
|
75 |
for (ArcIt it(digraph); it != INVALID; ++it) { |
|
76 |
check(found[it] == true, "The arc is not found."); |
|
77 |
} |
|
78 |
} |
|
79 |
|
|
80 |
} //namespace lemon |
|
81 |
|
|
82 |
|
|
83 |
#endif |
1 |
/* -*- C++ -*- |
|
2 |
* |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
4 |
* |
|
5 |
* Copyright (C) 2003-2008 |
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
|
8 |
* |
|
9 |
* Permission to use, modify and distribute this software is granted |
|
10 |
* provided that this copyright notice appears in all copies. For |
|
11 |
* precise terms see the accompanying LICENSE file. |
|
12 |
* |
|
13 |
* This software is provided "AS IS" with no warranty of any kind, |
|
14 |
* express or implied, and with no claim as to its suitability for any |
|
15 |
* purpose. |
|
16 |
* |
|
17 |
*/ |
|
18 |
|
|
19 |
#ifndef LEMON_TEST_MAP_TEST_H |
|
20 |
#define LEMON_TEST_MAP_TEST_H |
|
21 |
|
|
22 |
|
|
23 |
#include <vector> |
|
24 |
#include <lemon/maps.h> |
|
25 |
|
|
26 |
#include "test_tools.h" |
|
27 |
|
|
28 |
|
|
29 |
//! \ingroup misc |
|
30 |
//! \file |
|
31 |
//! \brief Some utilities to test map classes. |
|
32 |
|
|
33 |
namespace lemon { |
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
template <typename Graph> |
|
38 |
void checkGraphNodeMap() { |
|
39 |
Graph graph; |
|
40 |
const int num = 16; |
|
41 |
|
|
42 |
typedef typename Graph::Node Node; |
|
43 |
|
|
44 |
std::vector<Node> nodes; |
|
45 |
for (int i = 0; i < num; ++i) { |
|
46 |
nodes.push_back(graph.addNode()); |
|
47 |
} |
|
48 |
typedef typename Graph::template NodeMap<int> IntNodeMap; |
|
49 |
IntNodeMap map(graph, 42); |
|
50 |
for (int i = 0; i < int(nodes.size()); ++i) { |
|
51 |
check(map[nodes[i]] == 42, "Wrong map constructor."); |
|
52 |
} |
|
53 |
for (int i = 0; i < num; ++i) { |
|
54 |
nodes.push_back(graph.addNode()); |
|
55 |
map[nodes.back()] = 23; |
|
56 |
} |
|
57 |
map = constMap<Node>(12); |
|
58 |
for (int i = 0; i < int(nodes.size()); ++i) { |
|
59 |
check(map[nodes[i]] == 12, "Wrong map constructor."); |
|
60 |
} |
|
61 |
graph.clear(); |
|
62 |
nodes.clear(); |
|
63 |
} |
|
64 |
|
|
65 |
template <typename Graph> |
|
66 |
void checkGraphArcMap() { |
|
67 |
Graph graph; |
|
68 |
const int num = 16; |
|
69 |
|
|
70 |
typedef typename Graph::Node Node; |
|
71 |
typedef typename Graph::Arc Arc; |
|
72 |
|
|
73 |
std::vector<Node> nodes; |
|
74 |
for (int i = 0; i < num; ++i) { |
|
75 |
nodes.push_back(graph.addNode()); |
|
76 |
} |
|
77 |
|
|
78 |
std::vector<Arc> edges; |
|
79 |
for (int i = 0; i < num; ++i) { |
|
80 |
for (int j = 0; j < i; ++j) { |
|
81 |
edges.push_back(graph.addArc(nodes[i], nodes[j])); |
|
82 |
} |
|
83 |
} |
|
84 |
|
|
85 |
typedef typename Graph::template ArcMap<int> IntArcMap; |
|
86 |
IntArcMap map(graph, 42); |
|
87 |
|
|
88 |
for (int i = 0; i < int(edges.size()); ++i) { |
|
89 |
check(map[edges[i]] == 42, "Wrong map constructor."); |
|
90 |
} |
|
91 |
|
|
92 |
for (int i = 0; i < num; ++i) { |
|
93 |
for (int j = i + 1; j < num; ++j) { |
|
94 |
edges.push_back(graph.addArc(nodes[i], nodes[j])); |
|
95 |
map[edges.back()] = 23; |
|
96 |
} |
|
97 |
} |
|
98 |
map = constMap<Arc>(12); |
|
99 |
for (int i = 0; i < int(edges.size()); ++i) { |
|
100 |
check(map[edges[i]] == 12, "Wrong map constructor."); |
|
101 |
} |
|
102 |
graph.clear(); |
|
103 |
edges.clear(); |
|
104 |
} |
|
105 |
|
|
106 |
template <typename Graph> |
|
107 |
void checkGraphEdgeMap() { |
|
108 |
Graph graph; |
|
109 |
const int num = 16; |
|
110 |
|
|
111 |
typedef typename Graph::Node Node; |
|
112 |
typedef typename Graph::Edge Edge; |
|
113 |
|
|
114 |
std::vector<Node> nodes; |
|
115 |
for (int i = 0; i < num; ++i) { |
|
116 |
nodes.push_back(graph.addNode()); |
|
117 |
} |
|
118 |
|
|
119 |
std::vector<Edge> edges; |
|
120 |
for (int i = 0; i < num; ++i) { |
|
121 |
for (int j = 0; j < i; ++j) { |
|
122 |
edges.push_back(graph.addEdge(nodes[i], nodes[j])); |
|
123 |
} |
|
124 |
} |
|
125 |
|
|
126 |
typedef typename Graph::template EdgeMap<int> IntEdgeMap; |
|
127 |
IntEdgeMap map(graph, 42); |
|
128 |
|
|
129 |
for (int i = 0; i < int(edges.size()); ++i) { |
|
130 |
check(map[edges[i]] == 42, "Wrong map constructor."); |
|
131 |
} |
|
132 |
|
|
133 |
for (int i = 0; i < num; ++i) { |
|
134 |
for (int j = i + 1; j < num; ++j) { |
|
135 |
edges.push_back(graph.addEdge(nodes[i], nodes[j])); |
|
136 |
map[edges.back()] = 23; |
|
137 |
} |
|
138 |
} |
|
139 |
map = constMap<Edge>(12); |
|
140 |
for (int i = 0; i < int(edges.size()); ++i) { |
|
141 |
check(map[edges[i]] == 12, "Wrong map constructor."); |
|
142 |
} |
|
143 |
graph.clear(); |
|
144 |
edges.clear(); |
|
145 |
} |
|
146 |
|
|
147 |
} |
|
148 |
|
|
149 |
#endif |
0 comments (0 inline)