Do not rely on the autodetection of cplex and glpk.
3 #include <lemon/bits/graph_extender.h>
4 #include <lemon/concept/ugraph.h>
5 #include <lemon/list_graph.h>
6 #include <lemon/smart_graph.h>
7 #include <lemon/full_graph.h>
8 #include <lemon/grid_graph.h>
10 #include <lemon/graph_utils.h>
12 #include "test_tools.h"
15 using namespace lemon;
16 using namespace lemon::concept;
18 void check_concepts() {
19 typedef UGraphExtender<ListGraphBase> ListUGraphBase;
21 typedef IterableUGraphExtender<
22 AlterableUGraphExtender<ListUGraphBase> > IterableListUGraph;
24 typedef MappableUGraphExtender<IterableListUGraph>
27 typedef ErasableUGraphExtender<
28 ClearableUGraphExtender<
29 ExtendableUGraphExtender<MappableListUGraph> > > Graph;
31 checkConcept<BaseIterableUGraphConcept, Graph>();
32 checkConcept<IterableUGraphConcept, Graph>();
33 checkConcept<MappableUGraphConcept, Graph>();
35 checkConcept<UGraph, Graph>();
36 checkConcept<ErasableUGraph, Graph>();
38 checkConcept<UGraph, ListUGraph>();
39 checkConcept<ErasableUGraph, ListUGraph>();
41 checkConcept<UGraph, SmartUGraph>();
42 checkConcept<ExtendableUGraph, SmartUGraph>();
44 checkConcept<UGraph, FullUGraph>();
46 checkConcept<UGraph, UGraph>();
48 checkConcept<UGraph, GridGraph>();
51 template <typename Graph>
52 void check_item_counts(Graph &g, int n, int e) {
54 for (typename Graph::NodeIt it(g); it != INVALID; ++it) {
58 check(nn == n, "Wrong node number.");
59 check(countNodes(g) == n, "Wrong node number.");
62 for (typename Graph::EdgeIt it(g); it != INVALID; ++it) {
66 check(ee == 2*e, "Wrong edge number.");
67 check(countEdges(g) == 2*e, "Wrong edge number.");
70 for (typename Graph::UEdgeIt it(g); it != INVALID; ++it) {
74 check(uee == e, "Wrong uedge number.");
75 check(countUEdges(g) == e, "Wrong uedge number.");
78 template <typename Graph>
79 void print_items(Graph &g) {
81 typedef typename Graph::NodeIt NodeIt;
82 typedef typename Graph::UEdgeIt UEdgeIt;
83 typedef typename Graph::EdgeIt EdgeIt;
85 std::cout << "Nodes" << std::endl;
87 for(NodeIt it(g); it!=INVALID; ++it, ++i) {
88 std::cout << " " << i << ": " << g.id(it) << std::endl;
91 std::cout << "UEdge" << std::endl;
93 for(UEdgeIt it(g); it!=INVALID; ++it, ++i) {
94 std::cout << " " << i << ": " << g.id(it)
95 << " (" << g.id(g.source(it)) << ", " << g.id(g.target(it))
99 std::cout << "Edge" << std::endl;
101 for(EdgeIt it(g); it!=INVALID; ++it, ++i) {
102 std::cout << " " << i << ": " << g.id(it)
103 << " (" << g.id(g.source(it)) << ", " << g.id(g.target(it))
109 template <typename Graph>
112 typedef typename Graph::Node Node;
113 typedef typename Graph::UEdge UEdge;
114 typedef typename Graph::Edge Edge;
115 typedef typename Graph::NodeIt NodeIt;
116 typedef typename Graph::UEdgeIt UEdgeIt;
117 typedef typename Graph::EdgeIt EdgeIt;
121 check_item_counts(g,0,0);
129 e1 = g.addEdge(n1, n2),
130 e2 = g.addEdge(n2, n3);
134 check_item_counts(g,3,2);
137 void checkGridGraph(const GridGraph& g, int w, int h) {
138 check(g.width() == w, "Wrong width");
139 check(g.height() == h, "Wrong height");
141 for (int i = 0; i < w; ++i) {
142 for (int j = 0; j < h; ++j) {
143 check(g.col(g(i, j)) == i, "Wrong col");
144 check(g.row(g(i, j)) == j, "Wrong row");
148 for (int i = 0; i < w; ++i) {
149 for (int j = 0; j < h - 1; ++j) {
150 check(g.source(g.down(g(i, j))) == g(i, j), "Wrong down");
151 check(g.target(g.down(g(i, j))) == g(i, j + 1), "Wrong down");
153 check(g.down(g(i, h - 1)) == INVALID, "Wrong down");
156 for (int i = 0; i < w; ++i) {
157 for (int j = 1; j < h; ++j) {
158 check(g.source(g.up(g(i, j))) == g(i, j), "Wrong up");
159 check(g.target(g.up(g(i, j))) == g(i, j - 1), "Wrong up");
161 check(g.up(g(i, 0)) == INVALID, "Wrong up");
164 for (int j = 0; j < h; ++j) {
165 for (int i = 0; i < w - 1; ++i) {
166 check(g.source(g.right(g(i, j))) == g(i, j), "Wrong right");
167 check(g.target(g.right(g(i, j))) == g(i + 1, j), "Wrong right");
169 check(g.right(g(w - 1, j)) == INVALID, "Wrong right");
172 for (int j = 0; j < h; ++j) {
173 for (int i = 1; i < w; ++i) {
174 check(g.source(g.left(g(i, j))) == g(i, j), "Wrong left");
175 check(g.target(g.left(g(i, j))) == g(i - 1, j), "Wrong left");
177 check(g.left(g(0, j)) == INVALID, "Wrong left");
184 check_graph<ListUGraph>();
185 check_graph<SmartUGraph>();
189 check_item_counts(g, 5, 10);
194 check_item_counts(g, 30, 49);
195 checkGridGraph(g, 5, 6);
198 std::cout << __FILE__ ": All tests passed.\n";