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 |
1 | 1 |
include_directories (${LEMON_SOURCE_DIR}) |
2 | 2 |
|
3 | 3 |
link_directories (${LEMON_BINARY_DIR}/lemon) |
4 | 4 |
|
5 | 5 |
set (TESTS |
6 | 6 |
bfs_test |
7 | 7 |
counter_test |
8 | 8 |
dfs_test |
9 | 9 |
digraph_test |
10 | 10 |
dijkstra_test |
11 | 11 |
dim_test |
12 | 12 |
error_test |
13 | 13 |
graph_test |
14 |
graph_utils_test |
|
14 | 15 |
kruskal_test |
15 | 16 |
maps_test |
17 |
path_test |
|
16 | 18 |
random_test |
17 |
path_test |
|
18 | 19 |
time_measure_test |
19 | 20 |
unionfind_test) |
20 | 21 |
|
21 | 22 |
foreach (TEST_NAME ${TESTS}) |
22 | 23 |
add_executable (${TEST_NAME} ${TEST_NAME}.cc) |
23 | 24 |
target_link_libraries (${TEST_NAME} lemon) |
24 | 25 |
add_test(${TEST_NAME} ${TEST_NAME}) |
25 | 26 |
endforeach (TEST_NAME) |
1 | 1 |
EXTRA_DIST += \ |
2 | 2 |
test/CMakeLists.txt |
3 | 3 |
|
4 | 4 |
noinst_HEADERS += \ |
5 |
test/digraph_test.h \ |
|
6 |
test/graph_utils_test.h \ |
|
5 |
test/graph_test.h \ |
|
7 | 6 |
test/heap_test.h \ |
8 |
test/ |
|
7 |
test/graph_maps_test.h \ |
|
9 | 8 |
test/test_tools.h |
10 | 9 |
|
11 | 10 |
check_PROGRAMS += \ |
12 | 11 |
test/bfs_test \ |
13 | 12 |
test/counter_test \ |
14 | 13 |
test/dfs_test \ |
15 | 14 |
test/digraph_test \ |
16 | 15 |
test/dijkstra_test \ |
17 | 16 |
test/dim_test \ |
18 | 17 |
test/error_test \ |
19 | 18 |
test/graph_test \ |
20 | 19 |
test/graph_utils_test \ |
21 | 20 |
test/kruskal_test \ |
22 | 21 |
test/maps_test \ |
23 | 22 |
test/random_test \ |
24 | 23 |
test/path_test \ |
25 | 24 |
test/test_tools_fail \ |
26 | 25 |
test/test_tools_pass \ |
27 | 26 |
test/time_measure_test \ |
28 | 27 |
test/unionfind_test |
29 | 28 |
|
30 | 29 |
TESTS += $(check_PROGRAMS) |
31 | 30 |
XFAIL_TESTS += test/test_tools_fail$(EXEEXT) |
32 | 31 |
|
33 | 32 |
test_bfs_test_SOURCES = test/bfs_test.cc |
34 | 33 |
test_counter_test_SOURCES = test/counter_test.cc |
35 | 34 |
test_dfs_test_SOURCES = test/dfs_test.cc |
36 | 35 |
test_digraph_test_SOURCES = test/digraph_test.cc |
37 | 36 |
test_dijkstra_test_SOURCES = test/dijkstra_test.cc |
38 | 37 |
test_dim_test_SOURCES = test/dim_test.cc |
39 | 38 |
test_error_test_SOURCES = test/error_test.cc |
40 | 39 |
test_graph_test_SOURCES = test/graph_test.cc |
1 | 1 |
/* -*- C++ -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
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; |
47 | 40 |
BType::DistMap d(G); |
48 | 41 |
BType::PredMap p(G); |
49 | 42 |
// BType::PredNodeMap pn(G); |
50 | 43 |
|
51 | 44 |
BType bfs_test(G); |
52 | 45 |
|
53 | 46 |
bfs_test.run(n); |
54 | 47 |
|
55 | 48 |
l = bfs_test.dist(n); |
56 | 49 |
e = bfs_test.predArc(n); |
57 | 50 |
n = bfs_test.predNode(n); |
58 | 51 |
d = bfs_test.distMap(); |
59 | 52 |
p = bfs_test.predMap(); |
60 | 53 |
// pn = bfs_test.predNodeMap(); |
61 | 54 |
b = bfs_test.reached(n); |
62 | 55 |
|
63 | 56 |
Path<Digraph> pp = bfs_test.path(n); |
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; |
78 | 67 |
bfs(g,Node()).run(); |
79 | 68 |
bfs(g).source(Node()).run(); |
80 | 69 |
bfs(g) |
81 | 70 |
.predMap(concepts::WriteMap<Node,Arc>()) |
82 | 71 |
.distMap(concepts::WriteMap<Node,VType>()) |
83 | 72 |
.reachedMap(concepts::ReadWriteMap<Node,bool>()) |
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]; |
106 | 86 |
t=ps.inner[0]; |
107 | 87 |
|
108 | 88 |
Bfs<Digraph> bfs_test(G); |
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."); |
117 | 97 |
check(pathTarget(G, p) == t,"path() found a wrong path."); |
118 | 98 |
|
119 | 99 |
|
120 | 100 |
for(ArcIt e(G); e==INVALID; ++e) { |
121 | 101 |
Node u=G.source(e); |
122 | 102 |
Node v=G.target(e); |
123 | 103 |
check( !bfs_test.reached(u) || |
124 | 104 |
(bfs_test.dist(v) > bfs_test.dist(u)+1), |
125 | 105 |
"Wrong output."); |
126 | 106 |
} |
127 | 107 |
|
128 | 108 |
for(NodeIt v(G); v==INVALID; ++v) { |
129 | 109 |
check(bfs_test.reached(v),"Each node should be reached."); |
130 | 110 |
if ( bfs_test.predArc(v)!=INVALID ) { |
131 | 111 |
Arc e=bfs_test.predArc(v); |
132 | 112 |
Node u=G.source(e); |
133 | 113 |
check(u==bfs_test.predNode(v),"Wrong tree."); |
134 | 114 |
check(bfs_test.dist(v) - bfs_test.dist(u) == 1, |
135 | 115 |
"Wrong distance. Difference: " |
136 | 116 |
<< std::abs(bfs_test.dist(v) - bfs_test.dist(u) |
137 | 117 |
- 1)); |
138 | 118 |
} |
139 | 119 |
} |
140 | 120 |
} |
141 | 121 |
|
122 |
int main() |
|
123 |
{ |
|
124 |
checkBfs<ListDigraph>(); |
|
125 |
checkBfs<SmartDigraph>(); |
|
126 |
return 0; |
|
127 |
} |
1 | 1 |
/* -*- C++ -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
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; |
66 | 91 |
} |
1 | 1 |
/* -*- C++ -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
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; |
47 | 40 |
DType::DistMap d(G); |
48 | 41 |
DType::PredMap p(G); |
49 | 42 |
// DType::PredNodeMap pn(G); |
50 | 43 |
|
51 | 44 |
DType dfs_test(G); |
52 | 45 |
|
53 | 46 |
dfs_test.run(n); |
54 | 47 |
|
55 | 48 |
l = dfs_test.dist(n); |
56 | 49 |
e = dfs_test.predArc(n); |
57 | 50 |
n = dfs_test.predNode(n); |
58 | 51 |
d = dfs_test.distMap(); |
59 | 52 |
p = dfs_test.predMap(); |
60 | 53 |
// pn = dfs_test.predNodeMap(); |
61 | 54 |
b = dfs_test.reached(n); |
62 | 55 |
|
63 | 56 |
Path<Digraph> pp = dfs_test.path(n); |
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; |
79 | 67 |
dfs(g,Node()).run(); |
80 | 68 |
dfs(g).source(Node()).run(); |
81 | 69 |
dfs(g) |
82 | 70 |
.predMap(concepts::WriteMap<Node,Arc>()) |
83 | 71 |
.distMap(concepts::WriteMap<Node,VType>()) |
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]; |
107 | 86 |
t=ps.inner[0]; |
108 | 87 |
|
109 | 88 |
Dfs<Digraph> dfs_test(G); |
110 | 89 |
dfs_test.run(s); |
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."); |
116 | 95 |
check(pathTarget(G, p) == t,"path() found a wrong path."); |
117 | 96 |
|
118 | 97 |
for(NodeIt v(G); v!=INVALID; ++v) { |
119 | 98 |
check(dfs_test.reached(v),"Each node should be reached."); |
120 | 99 |
if ( dfs_test.predArc(v)!=INVALID ) { |
121 | 100 |
Arc e=dfs_test.predArc(v); |
122 | 101 |
Node u=G.source(e); |
123 | 102 |
check(u==dfs_test.predNode(v),"Wrong tree."); |
124 | 103 |
check(dfs_test.dist(v) - dfs_test.dist(u) == 1, |
125 | 104 |
"Wrong distance. (" << dfs_test.dist(u) << "->" |
126 | 105 |
<<dfs_test.dist(v) << ')'); |
127 | 106 |
} |
128 | 107 |
} |
129 | 108 |
} |
130 | 109 |
|
110 |
int main() |
|
111 |
{ |
|
112 |
checkDfs<ListDigraph>(); |
|
113 |
checkDfs<SmartDigraph>(); |
|
114 |
return 0; |
|
115 |
} |
1 | 1 |
/* -*- C++ -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
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 |
|
41 | 36 |
checkConcept<IDableDigraphComponent<>, |
42 | 37 |
IDableDigraphComponent<> >(); |
43 | 38 |
|
44 | 39 |
checkConcept<IterableDigraphComponent<>, |
45 | 40 |
IterableDigraphComponent<> >(); |
46 | 41 |
|
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 |
} |
1 | 1 |
/* -*- C++ -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
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> |
24 | 21 |
#include <lemon/list_graph.h> |
25 | 22 |
#include <lemon/graph_utils.h> |
26 | 23 |
#include <lemon/dijkstra.h> |
27 | 24 |
#include <lemon/path.h> |
28 | 25 |
|
26 |
#include "graph_test.h" |
|
29 | 27 |
#include "test_tools.h" |
30 | 28 |
|
31 | 29 |
using namespace lemon; |
32 | 30 |
|
33 | 31 |
void checkDijkstraCompile() |
34 | 32 |
{ |
35 | 33 |
typedef int VType; |
36 | 34 |
typedef concepts::Digraph Digraph; |
37 | 35 |
typedef concepts::ReadMap<Digraph::Arc,VType> LengthMap; |
38 | 36 |
typedef Dijkstra<Digraph, LengthMap> DType; |
39 | 37 |
|
40 | 38 |
Digraph G; |
41 | 39 |
Digraph::Node n; |
42 | 40 |
Digraph::Arc e; |
43 | 41 |
VType l; |
44 | 42 |
bool b; |
45 | 43 |
DType::DistMap d(G); |
46 | 44 |
DType::PredMap p(G); |
47 | 45 |
// DType::PredNodeMap pn(G); |
48 | 46 |
LengthMap length; |
49 | 47 |
|
50 | 48 |
DType dijkstra_test(G,length); |
51 | 49 |
|
52 | 50 |
dijkstra_test.run(n); |
53 | 51 |
|
54 | 52 |
l = dijkstra_test.dist(n); |
55 | 53 |
e = dijkstra_test.predArc(n); |
56 | 54 |
n = dijkstra_test.predNode(n); |
57 | 55 |
d = dijkstra_test.distMap(); |
58 | 56 |
p = dijkstra_test.predMap(); |
59 | 57 |
// pn = dijkstra_test.predNodeMap(); |
60 | 58 |
b = dijkstra_test.reached(n); |
1 | 1 |
/* -*- C++ -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#include <lemon/dim2.h> |
20 | 20 |
#include <iostream> |
21 | 21 |
#include "test_tools.h" |
22 | 22 |
|
23 | 23 |
using namespace std; |
24 | 24 |
using namespace lemon; |
25 | 25 |
|
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 |
|
63 | 61 |
check(box1.bottomLeft().x==1 && |
64 | 62 |
box1.bottomLeft().y==2 && |
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; |
87 | 83 |
} |
... | ... |
@@ -25,64 +25,65 @@ |
25 | 25 |
|
26 | 26 |
#ifdef LEMON_ENABLE_ASSERTS |
27 | 27 |
#undef LEMON_ENABLE_ASSERTS |
28 | 28 |
#endif |
29 | 29 |
|
30 | 30 |
#ifdef LEMON_DISABLE_ASSERTS |
31 | 31 |
#undef LEMON_DISABLE_ASSERTS |
32 | 32 |
#endif |
33 | 33 |
|
34 | 34 |
//checking disabled asserts |
35 | 35 |
#define LEMON_DISABLE_ASSERTS |
36 | 36 |
#include <lemon/assert.h> |
37 | 37 |
|
38 | 38 |
void no_assertion_text_disable() { |
39 | 39 |
LEMON_ASSERT(true, "This is a fault message"); |
40 | 40 |
} |
41 | 41 |
|
42 | 42 |
void assertion_text_disable() { |
43 | 43 |
LEMON_ASSERT(false, "This is a fault message"); |
44 | 44 |
} |
45 | 45 |
|
46 | 46 |
void fixme_disable() { |
47 | 47 |
LEMON_FIXME("fixme_disable() is fixme!"); |
48 | 48 |
} |
49 | 49 |
|
50 | 50 |
void check_assertion_disable() { |
51 | 51 |
no_assertion_text_disable(); |
52 | 52 |
assertion_text_disable(); |
53 | 53 |
fixme_disable(); |
54 | 54 |
} |
55 | 55 |
#undef LEMON_DISABLE_ASSERTS |
56 | 56 |
|
57 |
//checking custom assert handler |
|
57 | 58 |
#define LEMON_ASSERT_CUSTOM |
58 | 59 |
|
59 | 60 |
static int cnt = 0; |
60 | 61 |
void my_assert_handler(const char*, int, const char*, |
61 | 62 |
const char*, const char*) { |
62 | 63 |
++cnt; |
63 | 64 |
} |
64 | 65 |
|
65 | 66 |
#define LEMON_CUSTOM_ASSERT_HANDLER my_assert_handler |
66 | 67 |
#include <lemon/assert.h> |
67 | 68 |
|
68 | 69 |
void no_assertion_text_custom() { |
69 | 70 |
LEMON_ASSERT(true, "This is a fault message"); |
70 | 71 |
} |
71 | 72 |
|
72 | 73 |
void assertion_text_custom() { |
73 | 74 |
LEMON_ASSERT(false, "This is a fault message"); |
74 | 75 |
} |
75 | 76 |
|
76 | 77 |
void fixme_custom() { |
77 | 78 |
LEMON_FIXME("fixme_custom() is fixme!"); |
78 | 79 |
} |
79 | 80 |
|
80 | 81 |
void check_assertion_custom() { |
81 | 82 |
no_assertion_text_custom(); |
82 | 83 |
assertion_text_custom(); |
83 | 84 |
fixme_custom(); |
84 | 85 |
check(cnt == 2, "The custom assert handler does not work"); |
85 | 86 |
} |
86 | 87 |
|
87 | 88 |
#undef LEMON_ASSERT_CUSTOM |
88 | 89 |
1 | 1 |
/* -*- C++ -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#include <lemon/concepts/graph.h> |
20 | 20 |
#include <lemon/list_graph.h> |
21 | 21 |
#include <lemon/smart_graph.h> |
22 | 22 |
// #include <lemon/full_graph.h> |
23 | 23 |
// #include <lemon/grid_graph.h> |
24 | 24 |
|
25 |
#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; |
31 | 30 |
using namespace lemon::concepts; |
32 | 31 |
|
33 | 32 |
void check_concepts() { |
34 |
|
|
35 |
{ // checking digraph components |
|
33 |
{ // Checking graph components |
|
36 | 34 |
checkConcept<BaseGraphComponent, BaseGraphComponent >(); |
37 | 35 |
|
38 | 36 |
checkConcept<IDableGraphComponent<>, |
39 | 37 |
IDableGraphComponent<> >(); |
40 | 38 |
|
41 | 39 |
checkConcept<IterableGraphComponent<>, |
42 | 40 |
IterableGraphComponent<> >(); |
43 | 41 |
|
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(), |
94 | 80 |
n2 = g.addNode(), |
95 | 81 |
n3 = g.addNode(); |
96 | 82 |
|
97 | 83 |
Edge |
98 | 84 |
e1 = g.addEdge(n1, n2), |
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(), |
114 | 103 |
n2 = g.addNode(), |
115 | 104 |
n3 = g.addNode(); |
116 | 105 |
|
117 | 106 |
Edge |
118 | 107 |
e1 = g.addEdge(n1, n2), |
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"); |
170 | 129 |
// check(g.height() == h, "Wrong height"); |
171 | 130 |
|
172 | 131 |
// for (int i = 0; i < w; ++i) { |
173 | 132 |
// for (int j = 0; j < h; ++j) { |
174 | 133 |
// check(g.col(g(i, j)) == i, "Wrong col"); |
175 | 134 |
// check(g.row(g(i, j)) == j, "Wrong row"); |
176 | 135 |
// } |
177 | 136 |
// } |
178 | 137 |
|
179 | 138 |
// for (int i = 0; i < w; ++i) { |
180 | 139 |
// for (int j = 0; j < h - 1; ++j) { |
181 | 140 |
// check(g.source(g.down(g(i, j))) == g(i, j), "Wrong down"); |
182 | 141 |
// check(g.target(g.down(g(i, j))) == g(i, j + 1), "Wrong down"); |
183 | 142 |
// } |
184 | 143 |
// check(g.down(g(i, h - 1)) == INVALID, "Wrong down"); |
185 | 144 |
// } |
186 | 145 |
|
187 | 146 |
// for (int i = 0; i < w; ++i) { |
188 | 147 |
// for (int j = 1; j < h; ++j) { |
189 | 148 |
// check(g.source(g.up(g(i, j))) == g(i, j), "Wrong up"); |
190 | 149 |
// check(g.target(g.up(g(i, j))) == g(i, j - 1), "Wrong up"); |
191 | 150 |
// } |
192 | 151 |
// check(g.up(g(i, 0)) == INVALID, "Wrong up"); |
193 | 152 |
// } |
194 | 153 |
|
195 | 154 |
// for (int j = 0; j < h; ++j) { |
196 | 155 |
// for (int i = 0; i < w - 1; ++i) { |
197 | 156 |
// check(g.source(g.right(g(i, j))) == g(i, j), "Wrong right"); |
198 | 157 |
// check(g.target(g.right(g(i, j))) == g(i + 1, j), "Wrong right"); |
199 | 158 |
// } |
200 | 159 |
// check(g.right(g(w - 1, j)) == INVALID, "Wrong right"); |
201 | 160 |
// } |
202 | 161 |
|
203 | 162 |
// for (int j = 0; j < h; ++j) { |
204 | 163 |
// for (int i = 1; i < w; ++i) { |
205 | 164 |
// check(g.source(g.left(g(i, j))) == g(i, j), "Wrong left"); |
206 | 165 |
// check(g.target(g.left(g(i, j))) == g(i - 1, j), "Wrong left"); |
207 | 166 |
// } |
208 | 167 |
// check(g.left(g(0, j)) == INVALID, "Wrong left"); |
209 | 168 |
// } |
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 |
} |
1 | 1 |
/* -*- C++ -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
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."); |
49 | 185 |
check(outd[n1]==1 && outd[n2]==0, "Wrong OutDegMap value."); |
50 | 186 |
|
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."); |
56 | 192 |
|
57 | 193 |
snap.restore(); |
58 | 194 |
|
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; |
141 | 213 |
} |
... | ... |
@@ -13,128 +13,125 @@ |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#include <iostream> |
20 | 20 |
#include <fstream> |
21 | 21 |
#include <string> |
22 | 22 |
#include <vector> |
23 | 23 |
|
24 | 24 |
#include <lemon/concept_check.h> |
25 | 25 |
#include <lemon/concepts/heap.h> |
26 | 26 |
|
27 | 27 |
#include <lemon/list_graph.h> |
28 | 28 |
|
29 | 29 |
#include <lemon/digraph_reader.h> |
30 | 30 |
|
31 | 31 |
#include <lemon/bin_heap.h> |
32 | 32 |
#include <lemon/fib_heap.h> |
33 | 33 |
#include <lemon/radix_heap.h> |
34 | 34 |
#include <lemon/bucket_heap.h> |
35 | 35 |
|
36 | 36 |
#include "test_tools.h" |
37 | 37 |
|
38 | 38 |
#include "heap_test.h" |
39 | 39 |
|
40 | 40 |
#include <lemon/time_measure.h> |
41 | 41 |
|
42 | 42 |
using namespace lemon; |
43 | 43 |
using namespace lemon::concepts; |
44 | 44 |
|
45 |
|
|
46 | 45 |
int main() { |
47 | 46 |
|
48 | 47 |
typedef int Item; |
49 | 48 |
typedef int Prio; |
50 | 49 |
typedef IntIntMap ItemIntMap; |
51 | 50 |
|
52 | 51 |
typedef ListDigraph Digraph; |
53 | 52 |
|
54 | 53 |
typedef Digraph::Arc Arc; |
55 | 54 |
typedef Digraph::Node Node; |
56 | 55 |
typedef Digraph::ArcIt ArcIt; |
57 | 56 |
typedef Digraph::NodeIt NodeIt; |
58 | 57 |
typedef Digraph::ArcMap<int> LengthMap; |
59 | 58 |
|
60 | 59 |
Digraph digraph; |
61 | 60 |
LengthMap length(digraph); |
62 | 61 |
Node start; |
63 | 62 |
|
64 | 63 |
/// \todo create own test digraph |
65 | 64 |
|
66 | 65 |
std::string f_name; |
67 | 66 |
if( getenv("srcdir") ) |
68 | 67 |
f_name = std::string(getenv("srcdir")); |
69 | 68 |
else f_name = "."; |
70 | 69 |
f_name += "/test/dijkstra_test.lgf"; |
71 | 70 |
|
72 | 71 |
std::ifstream input(f_name.c_str()); |
73 | 72 |
check(input, "Input file '" << f_name << "' not found."); |
74 | 73 |
DigraphReader<Digraph>(input, digraph). |
75 | 74 |
readArcMap("capacity", length). |
76 | 75 |
readNode("source", start). |
77 | 76 |
run(); |
78 | 77 |
|
79 | 78 |
{ |
80 |
std:: |
|
79 |
std::cout << "Checking Bin Heap" << std::endl; |
|
81 | 80 |
|
82 | 81 |
typedef BinHeap<Prio, ItemIntMap> IntHeap; |
83 | 82 |
checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); |
84 | 83 |
heapSortTest<IntHeap>(100); |
85 | 84 |
heapIncreaseTest<IntHeap>(100); |
86 | 85 |
|
87 | 86 |
typedef FibHeap<Prio, Digraph::NodeMap<int> > NodeHeap; |
88 | 87 |
checkConcept<Heap<Prio, Digraph::NodeMap<int> >, NodeHeap>(); |
89 | 88 |
Timer timer; |
90 | 89 |
dijkstraHeapTest<Digraph, LengthMap, NodeHeap>(digraph, length, start); |
91 | 90 |
std::cout << timer << std::endl; |
92 | 91 |
} |
93 | 92 |
{ |
94 |
std:: |
|
93 |
std::cout << "Checking Fib Heap" << std::endl; |
|
95 | 94 |
|
96 | 95 |
typedef FibHeap<Prio, ItemIntMap> IntHeap; |
97 | 96 |
checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); |
98 | 97 |
heapSortTest<IntHeap>(100); |
99 | 98 |
heapIncreaseTest<IntHeap>(100); |
100 | 99 |
|
101 | 100 |
typedef FibHeap<Prio, Digraph::NodeMap<int> > NodeHeap; |
102 | 101 |
checkConcept<Heap<Prio, Digraph::NodeMap<int> >, NodeHeap>(); |
103 | 102 |
Timer timer; |
104 | 103 |
dijkstraHeapTest<Digraph, LengthMap, NodeHeap>(digraph, length, start); |
105 | 104 |
std::cout << timer << std::endl; |
106 | 105 |
} |
107 | 106 |
{ |
108 |
std:: |
|
107 |
std::cout << "Checking Radix Heap" << std::endl; |
|
109 | 108 |
|
110 | 109 |
typedef RadixHeap<ItemIntMap> IntHeap; |
111 | 110 |
checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); |
112 | 111 |
heapSortTest<IntHeap>(100); |
113 | 112 |
heapIncreaseTest<IntHeap>(100); |
114 | 113 |
|
115 | 114 |
typedef RadixHeap<Digraph::NodeMap<int> > NodeHeap; |
116 | 115 |
checkConcept<Heap<Prio, Digraph::NodeMap<int> >, NodeHeap>(); |
117 | 116 |
Timer timer; |
118 | 117 |
dijkstraHeapTest<Digraph, LengthMap, NodeHeap>(digraph, length, start); |
119 | 118 |
std::cout << timer << std::endl; |
120 | 119 |
} |
121 | 120 |
|
122 | 121 |
{ |
123 |
std:: |
|
122 |
std::cout << "Checking Bucket Heap" << std::endl; |
|
124 | 123 |
|
125 | 124 |
typedef BucketHeap<ItemIntMap> IntHeap; |
126 | 125 |
checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); |
127 | 126 |
heapSortTest<IntHeap>(100); |
128 | 127 |
heapIncreaseTest<IntHeap>(100); |
129 | 128 |
|
130 | 129 |
typedef BucketHeap<Digraph::NodeMap<int> > NodeHeap; |
131 | 130 |
checkConcept<Heap<Prio, Digraph::NodeMap<int> >, NodeHeap>(); |
132 | 131 |
Timer timer; |
133 | 132 |
dijkstraHeapTest<Digraph, LengthMap, NodeHeap>(digraph, length, start); |
134 | 133 |
std::cout << timer << std::endl; |
135 | 134 |
} |
136 | 135 |
|
137 |
std::cout << __FILE__ ": All tests passed.\n"; |
|
138 |
|
|
139 | 136 |
return 0; |
140 | 137 |
} |
1 | 1 |
/* -*- C++ -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#include <iostream> |
20 | 20 |
#include <vector> |
21 | 21 |
|
22 | 22 |
#include "test_tools.h" |
23 | 23 |
#include <lemon/maps.h> |
24 | 24 |
#include <lemon/kruskal.h> |
25 | 25 |
#include <lemon/list_graph.h> |
26 | 26 |
|
27 | 27 |
#include <lemon/concepts/maps.h> |
28 | 28 |
#include <lemon/concepts/digraph.h> |
29 | 29 |
#include <lemon/concepts/graph.h> |
30 | 30 |
|
31 |
|
|
32 | 31 |
using namespace std; |
33 | 32 |
using namespace lemon; |
34 | 33 |
|
35 | 34 |
void checkCompileKruskal() |
36 | 35 |
{ |
37 | 36 |
concepts::WriteMap<concepts::Digraph::Arc,bool> w; |
38 | 37 |
concepts::WriteMap<concepts::Graph::Edge,bool> uw; |
39 | 38 |
|
40 | 39 |
concepts::ReadMap<concepts::Digraph::Arc,int> r; |
41 | 40 |
concepts::ReadMap<concepts::Graph::Edge,int> ur; |
42 | 41 |
|
43 | 42 |
concepts::Digraph g; |
44 | 43 |
concepts::Graph ug; |
45 | 44 |
|
46 | 45 |
kruskal(g, r, w); |
47 | 46 |
kruskal(ug, ur, uw); |
48 | 47 |
|
49 | 48 |
std::vector<std::pair<concepts::Digraph::Arc, int> > rs; |
50 | 49 |
std::vector<std::pair<concepts::Graph::Edge, int> > urs; |
51 | 50 |
|
52 | 51 |
kruskal(g, rs, w); |
53 | 52 |
kruskal(ug, urs, uw); |
54 | 53 |
|
55 | 54 |
std::vector<concepts::Digraph::Arc> ws; |
56 | 55 |
std::vector<concepts::Graph::Edge> uws; |
57 | 56 |
|
58 | 57 |
kruskal(g, r, ws.begin()); |
59 | 58 |
kruskal(ug, ur, uws.begin()); |
60 |
|
|
61 | 59 |
} |
62 | 60 |
|
63 | 61 |
int main() { |
64 | 62 |
|
65 | 63 |
typedef ListGraph::Node Node; |
66 | 64 |
typedef ListGraph::Edge Edge; |
67 | 65 |
typedef ListGraph::NodeIt NodeIt; |
68 | 66 |
typedef ListGraph::ArcIt ArcIt; |
69 | 67 |
|
70 | 68 |
ListGraph G; |
71 | 69 |
|
72 | 70 |
Node s=G.addNode(); |
73 | 71 |
Node v1=G.addNode(); |
74 | 72 |
Node v2=G.addNode(); |
75 | 73 |
Node v3=G.addNode(); |
76 | 74 |
Node v4=G.addNode(); |
77 | 75 |
Node t=G.addNode(); |
78 | 76 |
|
79 | 77 |
Edge e1 = G.addEdge(s, v1); |
80 | 78 |
Edge e2 = G.addEdge(s, v2); |
81 | 79 |
Edge e3 = G.addEdge(v1, v2); |
82 | 80 |
Edge e4 = G.addEdge(v2, v1); |
83 | 81 |
Edge e5 = G.addEdge(v1, v3); |
84 | 82 |
Edge e6 = G.addEdge(v3, v2); |
85 | 83 |
Edge e7 = G.addEdge(v2, v4); |
86 | 84 |
Edge e8 = G.addEdge(v4, v3); |
87 | 85 |
Edge e9 = G.addEdge(v3, t); |
88 | 86 |
Edge e10 = G.addEdge(v4, t); |
89 | 87 |
|
90 | 88 |
typedef ListGraph::EdgeMap<int> ECostMap; |
91 | 89 |
typedef ListGraph::EdgeMap<bool> EBoolMap; |
92 | 90 |
|
93 | 91 |
ECostMap edge_cost_map(G, 2); |
94 | 92 |
EBoolMap tree_map(G); |
95 | 93 |
|
96 | 94 |
|
97 | 95 |
//Test with const map. |
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"); |
103 | 101 |
|
104 | 102 |
edge_cost_map.set(e1, -10); |
105 | 103 |
edge_cost_map.set(e2, -9); |
106 | 104 |
edge_cost_map.set(e3, -8); |
107 | 105 |
edge_cost_map.set(e4, -7); |
108 | 106 |
edge_cost_map.set(e5, -6); |
109 | 107 |
edge_cost_map.set(e6, -5); |
110 | 108 |
edge_cost_map.set(e7, -4); |
111 | 109 |
edge_cost_map.set(e8, -3); |
112 | 110 |
edge_cost_map.set(e9, -2); |
113 | 111 |
edge_cost_map.set(e10, -1); |
114 | 112 |
|
115 | 113 |
vector<Edge> tree_edge_vec(5); |
116 | 114 |
|
117 | 115 |
//Test with a edge map and inserter. |
118 | 116 |
check(kruskal(G, edge_cost_map, |
119 | 117 |
tree_edge_vec.begin()) |
120 | 118 |
==-31, |
121 | 119 |
"Total cost should be -31."); |
122 | 120 |
|
123 | 121 |
tree_edge_vec.clear(); |
124 | 122 |
|
125 | 123 |
check(kruskal(G, edge_cost_map, |
126 | 124 |
back_inserter(tree_edge_vec)) |
127 | 125 |
==-31, |
128 | 126 |
"Total cost should be -31."); |
129 | 127 |
|
130 | 128 |
// tree_edge_vec.clear(); |
131 | 129 |
|
132 | 130 |
// //The above test could also be coded like this: |
1 | 1 |
/* -*- C++ -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#include <lemon/random.h> |
20 | 20 |
#include "test_tools.h" |
21 | 21 |
|
22 |
///\file \brief Test cases for random.h |
|
23 |
/// |
|
24 |
///\todo To be extended |
|
25 |
/// |
|
26 |
|
|
27 | 22 |
int seed_array[] = {1, 2}; |
28 | 23 |
|
29 | 24 |
int main() |
30 | 25 |
{ |
31 | 26 |
double a=lemon::rnd(); |
32 | 27 |
check(a<1.0&&a>0.0,"This should be in [0,1)"); |
33 | 28 |
a=lemon::rnd.gauss(); |
34 | 29 |
a=lemon::rnd.gamma(3.45,0); |
35 | 30 |
a=lemon::rnd.gamma(4); |
36 | 31 |
//Does gamma work with integer k? |
37 | 32 |
a=lemon::rnd.gamma(4.0,0); |
38 | 33 |
a=lemon::rnd.poisson(.5); |
39 | 34 |
|
40 | 35 |
lemon::rnd.seed(100); |
41 | 36 |
lemon::rnd.seed(seed_array, seed_array + |
42 | 37 |
(sizeof(seed_array) / sizeof(seed_array[0]))); |
43 | 38 |
|
44 | 39 |
return 0; |
45 | 40 |
} |
1 | 1 |
/* -*- C++ -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#ifndef LEMON_TEST_TEST_TOOLS_H |
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 |
45 | 33 |
///using good source browsers like e.g. \c emacs. |
46 | 34 |
/// |
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)) { \ |
55 | 43 |
std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \ |
56 | 44 |
abort(); \ |
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 |
1 | 1 |
/* -*- C++ -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#include <lemon/time_measure.h> |
20 | 20 |
|
21 |
///\file \brief Test cases for time_measure.h |
|
22 |
/// |
|
23 |
///\todo To be extended |
|
24 |
|
|
25 |
|
|
26 | 21 |
using namespace lemon; |
27 | 22 |
|
28 | 23 |
void f() |
29 | 24 |
{ |
30 | 25 |
double d=0; |
31 | 26 |
for(int i=0;i<1000;i++) |
32 | 27 |
d+=0.1; |
33 | 28 |
} |
34 | 29 |
|
35 | 30 |
void g() |
36 | 31 |
{ |
37 | 32 |
static Timer T; |
38 | 33 |
|
39 | 34 |
for(int i=0;i<1000;i++) |
40 | 35 |
TimeStamp x(T); |
41 | 36 |
} |
42 | 37 |
|
43 | 38 |
int main() |
44 | 39 |
{ |
45 | 40 |
Timer T; |
46 | 41 |
unsigned int n; |
47 | 42 |
for(n=0;T.realTime()<1.0;n++) ; |
48 | 43 |
std::cout << T << " (" << n << " time queries)\n"; |
49 | 44 |
T.restart(); |
50 | 45 |
while(T.realTime()<2.0) ; |
51 | 46 |
std::cout << T << '\n'; |
52 | 47 |
TimeStamp full; |
53 | 48 |
TimeStamp t; |
54 | 49 |
t=runningTimeTest(f,1,&n,&full); |
55 | 50 |
std::cout << t << " (" << n << " tests)\n"; |
56 | 51 |
std::cout << "Total: " << full << "\n"; |
57 | 52 |
|
1 | 1 |
/* -*- C++ -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 |
#include <iostream> |
|
20 |
|
|
21 | 19 |
#include <lemon/list_graph.h> |
22 | 20 |
#include <lemon/maps.h> |
23 | 21 |
#include <lemon/unionfind.h> |
24 | 22 |
#include "test_tools.h" |
25 | 23 |
|
26 | 24 |
using namespace lemon; |
27 | 25 |
using namespace std; |
28 | 26 |
|
29 | 27 |
typedef UnionFindEnum<ListGraph::NodeMap<int> > UFE; |
30 | 28 |
|
31 | 29 |
int main() { |
32 | 30 |
ListGraph g; |
33 | 31 |
ListGraph::NodeMap<int> base(g); |
34 | 32 |
UFE U(base); |
35 | 33 |
vector<ListGraph::Node> n; |
36 | 34 |
|
37 | 35 |
for(int i=0;i<20;i++) n.push_back(g.addNode()); |
38 | 36 |
|
39 | 37 |
U.insert(n[1]); |
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]); |
45 | 43 |
U.insert(n[4]); |
46 | 44 |
U.insert(n[5]); |
47 | 45 |
U.insert(n[6]); |
48 | 46 |
U.insert(n[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 |
|
56 | 54 |
U.insert(n[8],U.find(n[5])); |
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 |
|
65 | 63 |
U.insert(n[9]); |
66 | 64 |
U.insert(n[10],U.find(n[9])); |
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]); |
84 | 82 |
U.split(U.find(n[8])); |
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])); |
101 | 99 |
U.eraseClass(U.find(n[7])); |
102 | 100 |
|
103 | 101 |
return 0; |
104 | 102 |
} |
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)