0
12
1
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 |
* |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 |
* |
|
5 |
* Copyright (C) 2003-2011 |
|
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 |
#include <lemon/list_graph.h> |
|
20 |
#include <lemon/lgf_reader.h> |
|
21 |
#include "test_tools.h" |
|
22 |
|
|
23 |
using namespace lemon; |
|
24 |
|
|
25 |
char test_lgf[] = |
|
26 |
"@nodes\n" |
|
27 |
"label\n" |
|
28 |
"0\n" |
|
29 |
"1\n" |
|
30 |
"@arcs\n" |
|
31 |
" label\n" |
|
32 |
"0 1 0\n" |
|
33 |
"1 0 1\n" |
|
34 |
"@attributes\n" |
|
35 |
"source 0\n" |
|
36 |
"target 1\n"; |
|
37 |
|
|
38 |
char test_lgf_nomap[] = |
|
39 |
"@nodes\n" |
|
40 |
"label\n" |
|
41 |
"0\n" |
|
42 |
"1\n" |
|
43 |
"@arcs\n" |
|
44 |
" -\n" |
|
45 |
"0 1\n"; |
|
46 |
|
|
47 |
char test_lgf_bad1[] = |
|
48 |
"@nodes\n" |
|
49 |
"label\n" |
|
50 |
"0\n" |
|
51 |
"1\n" |
|
52 |
"@arcs\n" |
|
53 |
" - another\n" |
|
54 |
"0 1\n"; |
|
55 |
|
|
56 |
char test_lgf_bad2[] = |
|
57 |
"@nodes\n" |
|
58 |
"label\n" |
|
59 |
"0\n" |
|
60 |
"1\n" |
|
61 |
"@arcs\n" |
|
62 |
" label -\n" |
|
63 |
"0 1\n"; |
|
64 |
|
|
65 |
|
|
66 |
int main() |
|
67 |
{ |
|
68 |
{ |
|
69 |
ListDigraph d; |
|
70 |
ListDigraph::Node s,t; |
|
71 |
ListDigraph::ArcMap<int> label(d); |
|
72 |
std::istringstream input(test_lgf); |
|
73 |
digraphReader(d, input). |
|
74 |
node("source", s). |
|
75 |
node("target", t). |
|
76 |
arcMap("label", label). |
|
77 |
run(); |
|
78 |
check(countNodes(d) == 2,"There should be 2 nodes"); |
|
79 |
check(countArcs(d) == 2,"There should be 2 arcs"); |
|
80 |
} |
|
81 |
{ |
|
82 |
ListGraph g; |
|
83 |
ListGraph::Node s,t; |
|
84 |
ListGraph::EdgeMap<int> label(g); |
|
85 |
std::istringstream input(test_lgf); |
|
86 |
graphReader(g, input). |
|
87 |
node("source", s). |
|
88 |
node("target", t). |
|
89 |
edgeMap("label", label). |
|
90 |
run(); |
|
91 |
check(countNodes(g) == 2,"There should be 2 nodes"); |
|
92 |
check(countEdges(g) == 2,"There should be 2 arcs"); |
|
93 |
} |
|
94 |
|
|
95 |
{ |
|
96 |
ListDigraph d; |
|
97 |
std::istringstream input(test_lgf_nomap); |
|
98 |
digraphReader(d, input). |
|
99 |
run(); |
|
100 |
check(countNodes(d) == 2,"There should be 2 nodes"); |
|
101 |
check(countArcs(d) == 1,"There should be 1 arc"); |
|
102 |
} |
|
103 |
{ |
|
104 |
ListGraph g; |
|
105 |
std::istringstream input(test_lgf_nomap); |
|
106 |
graphReader(g, input). |
|
107 |
run(); |
|
108 |
check(countNodes(g) == 2,"There should be 2 nodes"); |
|
109 |
check(countEdges(g) == 1,"There should be 1 edge"); |
|
110 |
} |
|
111 |
|
|
112 |
{ |
|
113 |
ListDigraph d; |
|
114 |
std::istringstream input(test_lgf_bad1); |
|
115 |
bool ok=false; |
|
116 |
try { |
|
117 |
digraphReader(d, input). |
|
118 |
run(); |
|
119 |
} |
|
120 |
catch (FormatError&) |
|
121 |
{ |
|
122 |
ok = true; |
|
123 |
} |
|
124 |
check(ok,"FormatError exception should have occured"); |
|
125 |
} |
|
126 |
{ |
|
127 |
ListGraph g; |
|
128 |
std::istringstream input(test_lgf_bad1); |
|
129 |
bool ok=false; |
|
130 |
try { |
|
131 |
graphReader(g, input). |
|
132 |
run(); |
|
133 |
} |
|
134 |
catch (FormatError&) |
|
135 |
{ |
|
136 |
ok = true; |
|
137 |
} |
|
138 |
check(ok,"FormatError exception should have occured"); |
|
139 |
} |
|
140 |
|
|
141 |
{ |
|
142 |
ListDigraph d; |
|
143 |
std::istringstream input(test_lgf_bad2); |
|
144 |
bool ok=false; |
|
145 |
try { |
|
146 |
digraphReader(d, input). |
|
147 |
run(); |
|
148 |
} |
|
149 |
catch (FormatError&) |
|
150 |
{ |
|
151 |
ok = true; |
|
152 |
} |
|
153 |
check(ok,"FormatError exception should have occured"); |
|
154 |
} |
|
155 |
{ |
|
156 |
ListGraph g; |
|
157 |
std::istringstream input(test_lgf_bad2); |
|
158 |
bool ok=false; |
|
159 |
try { |
|
160 |
graphReader(g, input). |
|
161 |
run(); |
|
162 |
} |
|
163 |
catch (FormatError&) |
|
164 |
{ |
|
165 |
ok = true; |
|
166 |
} |
|
167 |
check(ok,"FormatError exception should have occured"); |
|
168 |
} |
|
169 |
} |
... | ... |
@@ -14,13 +14,13 @@ |
14 | 14 |
* Mihaly Barasz <klao@cs.elte.hu> |
15 | 15 |
* Johanna Becker <beckerjc@cs.elte.hu> |
16 | 16 |
* Attila Bernath <athos@cs.elte.hu> |
17 | 17 |
* Balazs Dezso <deba@inf.elte.hu> |
18 | 18 |
* Peter Hegyi <hegyi@tmit.bme.hu> |
19 | 19 |
* Alpar Juttner <alpar@cs.elte.hu> |
20 | 20 |
* Peter Kovacs <kpeter@inf.elte.hu> |
21 | 21 |
* Akos Ladanyi <ladanyi@tmit.bme.hu> |
22 | 22 |
* Marton Makai <marci@cs.elte.hu> |
23 | 23 |
* Jacint Szabo <jacint@cs.elte.hu> |
24 | 24 |
|
25 | 25 |
Again, please visit the history of the old LEMON repository for more |
26 |
details: http://lemon.cs.elte.hu/ |
|
26 |
details: http://lemon.cs.elte.hu/hg/lemon-0.x |
|
... | ... |
No newline at end of file |
... | ... |
@@ -54,43 +54,54 @@ |
54 | 54 |
non-empty lines until the next section describes nodes of the |
55 | 55 |
graph. Each line contains the values of the node maps |
56 | 56 |
associated to the current node. |
57 | 57 |
|
58 | 58 |
\code |
59 | 59 |
@nodes |
60 | 60 |
label coordinates size title |
61 | 61 |
1 (10,20) 10 "First node" |
62 | 62 |
2 (80,80) 8 "Second node" |
63 | 63 |
3 (40,10) 10 "Third node" |
64 | 64 |
\endcode |
65 | 65 |
|
66 |
The \c \@arcs section is very similar to the \c \@nodes section, |
|
67 |
it again starts with a header line describing the names of the maps, |
|
68 |
but the \c "label" map is not obligatory here. The following lines |
|
69 |
describe the arcs. The first two tokens of each line are |
|
70 |
|
|
66 |
The \c \@arcs section is very similar to the \c \@nodes section, it |
|
67 |
again starts with a header line describing the names of the maps, but |
|
68 |
the \c "label" map is not obligatory here. The following lines |
|
69 |
describe the arcs. The first two tokens of each line are the source |
|
70 |
and the target node of the arc, respectively, then come the map |
|
71 | 71 |
values. The source and target tokens must be node labels. |
72 | 72 |
|
73 | 73 |
\code |
74 | 74 |
@arcs |
75 | 75 |
capacity |
76 | 76 |
1 2 16 |
77 | 77 |
1 3 12 |
78 | 78 |
2 3 18 |
79 | 79 |
\endcode |
80 | 80 |
|
81 |
If there is no map in the \c \@arcs section at all, then it must be |
|
82 |
indicated by a sole '-' sign in the first line. |
|
83 |
|
|
84 |
\code |
|
85 |
@arcs |
|
86 |
- |
|
87 |
1 2 |
|
88 |
1 3 |
|
89 |
2 3 |
|
90 |
\endcode |
|
91 |
|
|
81 | 92 |
The \c \@edges is just a synonym of \c \@arcs. The \@arcs section can |
82 | 93 |
also store the edge set of an undirected graph. In such case there is |
83 | 94 |
a conventional method for store arc maps in the file, if two columns |
84 |
|
|
95 |
have the same caption with \c '+' and \c '-' prefix, then these columns |
|
85 | 96 |
can be regarded as the values of an arc map. |
86 | 97 |
|
87 | 98 |
The \c \@attributes section contains key-value pairs, each line |
88 | 99 |
consists of two tokens, an attribute name, and then an attribute |
89 | 100 |
value. The value of the attribute could be also a label value of a |
90 | 101 |
node or an edge, or even an edge label prefixed with \c '+' or \c '-', |
91 | 102 |
which regards to the forward or backward directed arc of the |
92 | 103 |
corresponding edge. |
93 | 104 |
|
94 | 105 |
\code |
95 | 106 |
@attributes |
96 | 107 |
source 1 |
1 | 1 |
EXTRA_DIST += \ |
2 | 2 |
lemon/lemon.pc.in \ |
3 |
lemon/lemon.pc.cmake \ |
|
3 | 4 |
lemon/CMakeLists.txt \ |
4 | 5 |
lemon/config.h.cmake |
5 | 6 |
|
6 | 7 |
pkgconfig_DATA += lemon/lemon.pc |
7 | 8 |
|
8 | 9 |
lib_LTLIBRARIES += lemon/libemon.la |
9 | 10 |
|
10 | 11 |
lemon_libemon_la_SOURCES = \ |
11 | 12 |
lemon/arg_parser.cc \ |
12 | 13 |
lemon/base.cc \ |
13 | 14 |
lemon/color.cc \ |
14 | 15 |
lemon/lp_base.cc \ |
... | ... |
@@ -40,25 +40,25 @@ |
40 | 40 |
int length() const { |
41 | 41 |
int len = 0; |
42 | 42 |
typename Digraph::Node node = target; |
43 | 43 |
typename Digraph::Arc arc; |
44 | 44 |
while ((arc = predMap[node]) != INVALID) { |
45 | 45 |
node = digraph.source(arc); |
46 | 46 |
++len; |
47 | 47 |
} |
48 | 48 |
return len; |
49 | 49 |
} |
50 | 50 |
|
51 | 51 |
bool empty() const { |
52 |
return predMap[target] |
|
52 |
return predMap[target] == INVALID; |
|
53 | 53 |
} |
54 | 54 |
|
55 | 55 |
class RevArcIt { |
56 | 56 |
public: |
57 | 57 |
RevArcIt() {} |
58 | 58 |
RevArcIt(Invalid) : path(0), current(INVALID) {} |
59 | 59 |
RevArcIt(const PredMapPath& _path) |
60 | 60 |
: path(&_path), current(_path.target) { |
61 | 61 |
if (path->predMap[current] == INVALID) current = INVALID; |
62 | 62 |
} |
63 | 63 |
|
64 | 64 |
operator const typename Digraph::Arc() const { |
... | ... |
@@ -114,25 +114,25 @@ |
114 | 114 |
int length() const { |
115 | 115 |
int len = 0; |
116 | 116 |
typename Digraph::Node node = target; |
117 | 117 |
typename Digraph::Arc arc; |
118 | 118 |
while ((arc = predMatrixMap(source, node)) != INVALID) { |
119 | 119 |
node = digraph.source(arc); |
120 | 120 |
++len; |
121 | 121 |
} |
122 | 122 |
return len; |
123 | 123 |
} |
124 | 124 |
|
125 | 125 |
bool empty() const { |
126 |
return source |
|
126 |
return predMatrixMap(source, target) == INVALID; |
|
127 | 127 |
} |
128 | 128 |
|
129 | 129 |
class RevArcIt { |
130 | 130 |
public: |
131 | 131 |
RevArcIt() {} |
132 | 132 |
RevArcIt(Invalid) : path(0), current(INVALID) {} |
133 | 133 |
RevArcIt(const PredMatrixMapPath& _path) |
134 | 134 |
: path(&_path), current(_path.target) { |
135 | 135 |
if (path->predMatrixMap(path->source, current) == INVALID) |
136 | 136 |
current = INVALID; |
137 | 137 |
} |
138 | 138 |
... | ... |
@@ -385,24 +385,25 @@ |
385 | 385 |
} |
386 | 386 |
} |
387 | 387 |
|
388 | 388 |
private: |
389 | 389 |
CrossRef& _cmap; |
390 | 390 |
}; |
391 | 391 |
|
392 | 392 |
template <typename Digraph, typename Enable = void> |
393 | 393 |
struct DigraphCopySelector { |
394 | 394 |
template <typename From, typename NodeRefMap, typename ArcRefMap> |
395 | 395 |
static void copy(const From& from, Digraph &to, |
396 | 396 |
NodeRefMap& nodeRefMap, ArcRefMap& arcRefMap) { |
397 |
to.clear(); |
|
397 | 398 |
for (typename From::NodeIt it(from); it != INVALID; ++it) { |
398 | 399 |
nodeRefMap[it] = to.addNode(); |
399 | 400 |
} |
400 | 401 |
for (typename From::ArcIt it(from); it != INVALID; ++it) { |
401 | 402 |
arcRefMap[it] = to.addArc(nodeRefMap[from.source(it)], |
402 | 403 |
nodeRefMap[from.target(it)]); |
403 | 404 |
} |
404 | 405 |
} |
405 | 406 |
}; |
406 | 407 |
|
407 | 408 |
template <typename Digraph> |
408 | 409 |
struct DigraphCopySelector< |
... | ... |
@@ -412,24 +413,25 @@ |
412 | 413 |
template <typename From, typename NodeRefMap, typename ArcRefMap> |
413 | 414 |
static void copy(const From& from, Digraph &to, |
414 | 415 |
NodeRefMap& nodeRefMap, ArcRefMap& arcRefMap) { |
415 | 416 |
to.build(from, nodeRefMap, arcRefMap); |
416 | 417 |
} |
417 | 418 |
}; |
418 | 419 |
|
419 | 420 |
template <typename Graph, typename Enable = void> |
420 | 421 |
struct GraphCopySelector { |
421 | 422 |
template <typename From, typename NodeRefMap, typename EdgeRefMap> |
422 | 423 |
static void copy(const From& from, Graph &to, |
423 | 424 |
NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) { |
425 |
to.clear(); |
|
424 | 426 |
for (typename From::NodeIt it(from); it != INVALID; ++it) { |
425 | 427 |
nodeRefMap[it] = to.addNode(); |
426 | 428 |
} |
427 | 429 |
for (typename From::EdgeIt it(from); it != INVALID; ++it) { |
428 | 430 |
edgeRefMap[it] = to.addEdge(nodeRefMap[from.u(it)], |
429 | 431 |
nodeRefMap[from.v(it)]); |
430 | 432 |
} |
431 | 433 |
} |
432 | 434 |
}; |
433 | 435 |
|
434 | 436 |
template <typename Graph> |
435 | 437 |
struct GraphCopySelector< |
... | ... |
@@ -548,25 +548,25 @@ |
548 | 548 |
/// |
549 | 549 |
///This method runs the %DFS algorithm from the root node |
550 | 550 |
///in order to compute the DFS path to \c t. |
551 | 551 |
/// |
552 | 552 |
///The algorithm computes |
553 | 553 |
///- the %DFS path to \c t, |
554 | 554 |
///- the distance of \c t from the root in the %DFS tree. |
555 | 555 |
/// |
556 | 556 |
///\pre init() must be called and a root node should be |
557 | 557 |
///added with addSource() before using this function. |
558 | 558 |
void start(Node t) |
559 | 559 |
{ |
560 |
while ( !emptyQueue() && |
|
560 |
while ( !emptyQueue() && !(*_reached)[t] ) |
|
561 | 561 |
processNextArc(); |
562 | 562 |
} |
563 | 563 |
|
564 | 564 |
///Executes the algorithm until a condition is met. |
565 | 565 |
|
566 | 566 |
///Executes the algorithm until a condition is met. |
567 | 567 |
/// |
568 | 568 |
///This method runs the %DFS algorithm from the root node |
569 | 569 |
///until an arc \c a with <tt>am[a]</tt> true is found. |
570 | 570 |
/// |
571 | 571 |
///\param am A \c bool (or convertible) arc map. The algorithm |
572 | 572 |
///will stop when it reaches an arc \c a with <tt>am[a]</tt> true. |
... | ... |
@@ -1500,25 +1500,25 @@ |
1500 | 1500 |
/// Executes the algorithm until the given target node is reached. |
1501 | 1501 |
/// |
1502 | 1502 |
/// This method runs the %DFS algorithm from the root node |
1503 | 1503 |
/// in order to compute the DFS path to \c t. |
1504 | 1504 |
/// |
1505 | 1505 |
/// The algorithm computes |
1506 | 1506 |
/// - the %DFS path to \c t, |
1507 | 1507 |
/// - the distance of \c t from the root in the %DFS tree. |
1508 | 1508 |
/// |
1509 | 1509 |
/// \pre init() must be called and a root node should be added |
1510 | 1510 |
/// with addSource() before using this function. |
1511 | 1511 |
void start(Node t) { |
1512 |
while ( !emptyQueue() && |
|
1512 |
while ( !emptyQueue() && !(*_reached)[t] ) |
|
1513 | 1513 |
processNextArc(); |
1514 | 1514 |
} |
1515 | 1515 |
|
1516 | 1516 |
/// \brief Executes the algorithm until a condition is met. |
1517 | 1517 |
/// |
1518 | 1518 |
/// Executes the algorithm until a condition is met. |
1519 | 1519 |
/// |
1520 | 1520 |
/// This method runs the %DFS algorithm from the root node |
1521 | 1521 |
/// until an arc \c a with <tt>am[a]</tt> true is found. |
1522 | 1522 |
/// |
1523 | 1523 |
/// \param am A \c bool (or convertible) arc map. The algorithm |
1524 | 1524 |
/// will stop when it reaches an arc \c a with <tt>am[a]</tt> true. |
... | ... |
@@ -675,27 +675,27 @@ |
675 | 675 |
|
676 | 676 |
{ |
677 | 677 |
os << "%%CreationDate: "; |
678 | 678 |
#ifndef WIN32 |
679 | 679 |
timeval tv; |
680 | 680 |
gettimeofday(&tv, 0); |
681 | 681 |
|
682 | 682 |
char cbuf[26]; |
683 | 683 |
ctime_r(&tv.tv_sec,cbuf); |
684 | 684 |
os << cbuf; |
685 | 685 |
#else |
686 | 686 |
os << bits::getWinFormattedDate(); |
687 |
os << std::endl; |
|
687 | 688 |
#endif |
688 | 689 |
} |
689 |
os << std::endl; |
|
690 | 690 |
|
691 | 691 |
if (_autoArcWidthScale) { |
692 | 692 |
double max_w=0; |
693 | 693 |
for(ArcIt e(g);e!=INVALID;++e) |
694 | 694 |
max_w=std::max(double(_arcWidths[e]),max_w); |
695 | 695 |
if(max_w>EPSILON) { |
696 | 696 |
_arcWidthScale/=max_w; |
697 | 697 |
} |
698 | 698 |
} |
699 | 699 |
|
700 | 700 |
if (_autoNodeScale) { |
701 | 701 |
double max_s=0; |
1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
4 | 4 |
* |
5 |
* Copyright (C) 2003- |
|
5 |
* Copyright (C) 2003-2011 |
|
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 |
*/ |
... | ... |
@@ -955,24 +955,31 @@ |
955 | 955 |
if (!_arc_maps.empty()) |
956 | 956 |
throw FormatError("Cannot find map names"); |
957 | 957 |
return; |
958 | 958 |
} |
959 | 959 |
line.putback(c); |
960 | 960 |
|
961 | 961 |
{ |
962 | 962 |
std::map<std::string, int> maps; |
963 | 963 |
|
964 | 964 |
std::string map; |
965 | 965 |
int index = 0; |
966 | 966 |
while (_reader_bits::readToken(line, map)) { |
967 |
if(map == "-") { |
|
968 |
if(index!=0) |
|
969 |
throw FormatError("'-' is not allowed as a map name"); |
|
970 |
else if (line >> std::ws >> c) |
|
971 |
throw FormatError("Extra character at the end of line"); |
|
972 |
else break; |
|
973 |
} |
|
967 | 974 |
if (maps.find(map) != maps.end()) { |
968 | 975 |
std::ostringstream msg; |
969 | 976 |
msg << "Multiple occurence of arc map: " << map; |
970 | 977 |
throw FormatError(msg.str()); |
971 | 978 |
} |
972 | 979 |
maps.insert(std::make_pair(map, index)); |
973 | 980 |
++index; |
974 | 981 |
} |
975 | 982 |
|
976 | 983 |
for (int i = 0; i < static_cast<int>(_arc_maps.size()); ++i) { |
977 | 984 |
std::map<std::string, int>::iterator jt = |
978 | 985 |
maps.find(_arc_maps[i].first); |
... | ... |
@@ -1825,24 +1832,31 @@ |
1825 | 1832 |
if (!_edge_maps.empty()) |
1826 | 1833 |
throw FormatError("Cannot find map names"); |
1827 | 1834 |
return; |
1828 | 1835 |
} |
1829 | 1836 |
line.putback(c); |
1830 | 1837 |
|
1831 | 1838 |
{ |
1832 | 1839 |
std::map<std::string, int> maps; |
1833 | 1840 |
|
1834 | 1841 |
std::string map; |
1835 | 1842 |
int index = 0; |
1836 | 1843 |
while (_reader_bits::readToken(line, map)) { |
1844 |
if(map == "-") { |
|
1845 |
if(index!=0) |
|
1846 |
throw FormatError("'-' is not allowed as a map name"); |
|
1847 |
else if (line >> std::ws >> c) |
|
1848 |
throw FormatError("Extra character at the end of line"); |
|
1849 |
else break; |
|
1850 |
} |
|
1837 | 1851 |
if (maps.find(map) != maps.end()) { |
1838 | 1852 |
std::ostringstream msg; |
1839 | 1853 |
msg << "Multiple occurence of edge map: " << map; |
1840 | 1854 |
throw FormatError(msg.str()); |
1841 | 1855 |
} |
1842 | 1856 |
maps.insert(std::make_pair(map, index)); |
1843 | 1857 |
++index; |
1844 | 1858 |
} |
1845 | 1859 |
|
1846 | 1860 |
for (int i = 0; i < static_cast<int>(_edge_maps.size()); ++i) { |
1847 | 1861 |
std::map<std::string, int>::iterator jt = |
1848 | 1862 |
maps.find(_edge_maps[i].first); |
... | ... |
@@ -22,24 +22,25 @@ |
22 | 22 |
dijkstra_test |
23 | 23 |
dim_test |
24 | 24 |
edge_set_test |
25 | 25 |
error_test |
26 | 26 |
euler_test |
27 | 27 |
gomory_hu_test |
28 | 28 |
graph_copy_test |
29 | 29 |
graph_test |
30 | 30 |
graph_utils_test |
31 | 31 |
hao_orlin_test |
32 | 32 |
heap_test |
33 | 33 |
kruskal_test |
34 |
lgf_test |
|
34 | 35 |
maps_test |
35 | 36 |
matching_test |
36 | 37 |
min_cost_arborescence_test |
37 | 38 |
min_cost_flow_test |
38 | 39 |
path_test |
39 | 40 |
preflow_test |
40 | 41 |
radix_sort_test |
41 | 42 |
random_test |
42 | 43 |
suurballe_test |
43 | 44 |
time_measure_test |
44 | 45 |
unionfind_test |
45 | 46 |
) |
... | ... |
@@ -16,24 +16,25 @@ |
16 | 16 |
test/dijkstra_test \ |
17 | 17 |
test/dim_test \ |
18 | 18 |
test/edge_set_test \ |
19 | 19 |
test/error_test \ |
20 | 20 |
test/euler_test \ |
21 | 21 |
test/gomory_hu_test \ |
22 | 22 |
test/graph_copy_test \ |
23 | 23 |
test/graph_test \ |
24 | 24 |
test/graph_utils_test \ |
25 | 25 |
test/hao_orlin_test \ |
26 | 26 |
test/heap_test \ |
27 | 27 |
test/kruskal_test \ |
28 |
test/lgf_test \ |
|
28 | 29 |
test/maps_test \ |
29 | 30 |
test/matching_test \ |
30 | 31 |
test/min_cost_arborescence_test \ |
31 | 32 |
test/min_cost_flow_test \ |
32 | 33 |
test/path_test \ |
33 | 34 |
test/preflow_test \ |
34 | 35 |
test/radix_sort_test \ |
35 | 36 |
test/random_test \ |
36 | 37 |
test/suurballe_test \ |
37 | 38 |
test/test_tools_fail \ |
38 | 39 |
test/test_tools_pass \ |
39 | 40 |
test/time_measure_test \ |
... | ... |
@@ -61,24 +62,25 @@ |
61 | 62 |
test_dijkstra_test_SOURCES = test/dijkstra_test.cc |
62 | 63 |
test_dim_test_SOURCES = test/dim_test.cc |
63 | 64 |
test_edge_set_test_SOURCES = test/edge_set_test.cc |
64 | 65 |
test_error_test_SOURCES = test/error_test.cc |
65 | 66 |
test_euler_test_SOURCES = test/euler_test.cc |
66 | 67 |
test_gomory_hu_test_SOURCES = test/gomory_hu_test.cc |
67 | 68 |
test_graph_copy_test_SOURCES = test/graph_copy_test.cc |
68 | 69 |
test_graph_test_SOURCES = test/graph_test.cc |
69 | 70 |
test_graph_utils_test_SOURCES = test/graph_utils_test.cc |
70 | 71 |
test_heap_test_SOURCES = test/heap_test.cc |
71 | 72 |
test_kruskal_test_SOURCES = test/kruskal_test.cc |
72 | 73 |
test_hao_orlin_test_SOURCES = test/hao_orlin_test.cc |
74 |
test_lgf_test_SOURCES = test/lgf_test.cc |
|
73 | 75 |
test_lp_test_SOURCES = test/lp_test.cc |
74 | 76 |
test_maps_test_SOURCES = test/maps_test.cc |
75 | 77 |
test_mip_test_SOURCES = test/mip_test.cc |
76 | 78 |
test_matching_test_SOURCES = test/matching_test.cc |
77 | 79 |
test_min_cost_arborescence_test_SOURCES = test/min_cost_arborescence_test.cc |
78 | 80 |
test_min_cost_flow_test_SOURCES = test/min_cost_flow_test.cc |
79 | 81 |
test_path_test_SOURCES = test/path_test.cc |
80 | 82 |
test_preflow_test_SOURCES = test/preflow_test.cc |
81 | 83 |
test_radix_sort_test_SOURCES = test/radix_sort_test.cc |
82 | 84 |
test_suurballe_test_SOURCES = test/suurballe_test.cc |
83 | 85 |
test_random_test_SOURCES = test/random_test.cc |
84 | 86 |
test_test_tools_fail_SOURCES = test/test_tools_fail.cc |
... | ... |
@@ -41,25 +41,28 @@ |
41 | 41 |
"@arcs\n" |
42 | 42 |
" label\n" |
43 | 43 |
"0 1 0\n" |
44 | 44 |
"1 2 1\n" |
45 | 45 |
"2 3 2\n" |
46 | 46 |
"1 4 3\n" |
47 | 47 |
"4 2 4\n" |
48 | 48 |
"4 5 5\n" |
49 | 49 |
"5 0 6\n" |
50 | 50 |
"6 3 7\n" |
51 | 51 |
"@attributes\n" |
52 | 52 |
"source 0\n" |
53 |
"target 5\n" |
|
53 |
"target 5\n" |
|
54 |
"source1 6\n" |
|
55 |
"target1 3\n"; |
|
56 |
|
|
54 | 57 |
|
55 | 58 |
void checkDfsCompile() |
56 | 59 |
{ |
57 | 60 |
typedef concepts::Digraph Digraph; |
58 | 61 |
typedef Dfs<Digraph> DType; |
59 | 62 |
typedef Digraph::Node Node; |
60 | 63 |
typedef Digraph::Arc Arc; |
61 | 64 |
|
62 | 65 |
Digraph G; |
63 | 66 |
Node s, t; |
64 | 67 |
Arc e; |
65 | 68 |
int l, i; |
... | ... |
@@ -170,29 +173,32 @@ |
170 | 173 |
.distMap(concepts::ReadWriteMap<Node,VType>()) |
171 | 174 |
.reachedMap(concepts::ReadWriteMap<Node,bool>()) |
172 | 175 |
.processedMap(concepts::WriteMap<Node,bool>()) |
173 | 176 |
.run(); |
174 | 177 |
} |
175 | 178 |
|
176 | 179 |
template <class Digraph> |
177 | 180 |
void checkDfs() { |
178 | 181 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
179 | 182 |
|
180 | 183 |
Digraph G; |
181 | 184 |
Node s, t; |
185 |
Node s1, t1; |
|
182 | 186 |
|
183 | 187 |
std::istringstream input(test_lgf); |
184 | 188 |
digraphReader(G, input). |
185 | 189 |
node("source", s). |
186 | 190 |
node("target", t). |
191 |
node("source1", s1). |
|
192 |
node("target1", t1). |
|
187 | 193 |
run(); |
188 | 194 |
|
189 | 195 |
Dfs<Digraph> dfs_test(G); |
190 | 196 |
dfs_test.run(s); |
191 | 197 |
|
192 | 198 |
Path<Digraph> p = dfs_test.path(t); |
193 | 199 |
check(p.length() == dfs_test.dist(t),"path() found a wrong path."); |
194 | 200 |
check(checkPath(G, p),"path() found a wrong path."); |
195 | 201 |
check(pathSource(G, p) == s,"path() found a wrong path."); |
196 | 202 |
check(pathTarget(G, p) == t,"path() found a wrong path."); |
197 | 203 |
|
198 | 204 |
for(NodeIt v(G); v!=INVALID; ++v) { |
... | ... |
@@ -201,23 +207,28 @@ |
201 | 207 |
if (dfs_test.predArc(v)!=INVALID ) { |
202 | 208 |
Arc e=dfs_test.predArc(v); |
203 | 209 |
Node u=G.source(e); |
204 | 210 |
check(u==dfs_test.predNode(v),"Wrong tree."); |
205 | 211 |
check(dfs_test.dist(v) - dfs_test.dist(u) == 1, |
206 | 212 |
"Wrong distance. (" << dfs_test.dist(u) << "->" |
207 | 213 |
<< dfs_test.dist(v) << ")"); |
208 | 214 |
} |
209 | 215 |
} |
210 | 216 |
} |
211 | 217 |
|
212 | 218 |
{ |
219 |
Dfs<Digraph> dfs(G); |
|
220 |
check(dfs.run(s1,t1) && dfs.reached(t1),"Node 3 is reachable from Node 6."); |
|
221 |
} |
|
222 |
|
|
223 |
{ |
|
213 | 224 |
NullMap<Node,Arc> myPredMap; |
214 | 225 |
dfs(G).predMap(myPredMap).run(s); |
215 | 226 |
} |
216 | 227 |
} |
217 | 228 |
|
218 | 229 |
int main() |
219 | 230 |
{ |
220 | 231 |
checkDfs<ListDigraph>(); |
221 | 232 |
checkDfs<SmartDigraph>(); |
222 | 233 |
return 0; |
223 | 234 |
} |
... | ... |
@@ -20,90 +20,102 @@ |
20 | 20 |
#include <lemon/list_graph.h> |
21 | 21 |
#include <lemon/lgf_reader.h> |
22 | 22 |
#include <lemon/error.h> |
23 | 23 |
|
24 | 24 |
#include "test_tools.h" |
25 | 25 |
|
26 | 26 |
using namespace std; |
27 | 27 |
using namespace lemon; |
28 | 28 |
|
29 | 29 |
void digraph_copy_test() { |
30 | 30 |
const int nn = 10; |
31 | 31 |
|
32 |
// Build a digraph |
|
32 | 33 |
SmartDigraph from; |
33 | 34 |
SmartDigraph::NodeMap<int> fnm(from); |
34 | 35 |
SmartDigraph::ArcMap<int> fam(from); |
35 | 36 |
SmartDigraph::Node fn = INVALID; |
36 | 37 |
SmartDigraph::Arc fa = INVALID; |
37 | 38 |
|
38 | 39 |
std::vector<SmartDigraph::Node> fnv; |
39 | 40 |
for (int i = 0; i < nn; ++i) { |
40 | 41 |
SmartDigraph::Node node = from.addNode(); |
41 | 42 |
fnv.push_back(node); |
42 | 43 |
fnm[node] = i * i; |
43 | 44 |
if (i == 0) fn = node; |
44 | 45 |
} |
45 | 46 |
|
46 | 47 |
for (int i = 0; i < nn; ++i) { |
47 | 48 |
for (int j = 0; j < nn; ++j) { |
48 | 49 |
SmartDigraph::Arc arc = from.addArc(fnv[i], fnv[j]); |
49 | 50 |
fam[arc] = i + j * j; |
50 | 51 |
if (i == 0 && j == 0) fa = arc; |
51 | 52 |
} |
52 | 53 |
} |
53 | 54 |
|
55 |
// Test digraph copy |
|
54 | 56 |
ListDigraph to; |
55 | 57 |
ListDigraph::NodeMap<int> tnm(to); |
56 | 58 |
ListDigraph::ArcMap<int> tam(to); |
57 | 59 |
ListDigraph::Node tn; |
58 | 60 |
ListDigraph::Arc ta; |
59 | 61 |
|
60 | 62 |
SmartDigraph::NodeMap<ListDigraph::Node> nr(from); |
61 | 63 |
SmartDigraph::ArcMap<ListDigraph::Arc> er(from); |
62 | 64 |
|
63 | 65 |
ListDigraph::NodeMap<SmartDigraph::Node> ncr(to); |
64 | 66 |
ListDigraph::ArcMap<SmartDigraph::Arc> ecr(to); |
65 | 67 |
|
66 | 68 |
digraphCopy(from, to). |
67 | 69 |
nodeMap(fnm, tnm).arcMap(fam, tam). |
68 | 70 |
nodeRef(nr).arcRef(er). |
69 | 71 |
nodeCrossRef(ncr).arcCrossRef(ecr). |
70 | 72 |
node(fn, tn).arc(fa, ta).run(); |
73 |
|
|
74 |
check(countNodes(from) == countNodes(to), "Wrong copy."); |
|
75 |
check(countArcs(from) == countArcs(to), "Wrong copy."); |
|
71 | 76 |
|
72 | 77 |
for (SmartDigraph::NodeIt it(from); it != INVALID; ++it) { |
73 | 78 |
check(ncr[nr[it]] == it, "Wrong copy."); |
74 | 79 |
check(fnm[it] == tnm[nr[it]], "Wrong copy."); |
75 | 80 |
} |
76 | 81 |
|
77 | 82 |
for (SmartDigraph::ArcIt it(from); it != INVALID; ++it) { |
78 | 83 |
check(ecr[er[it]] == it, "Wrong copy."); |
79 | 84 |
check(fam[it] == tam[er[it]], "Wrong copy."); |
80 | 85 |
check(nr[from.source(it)] == to.source(er[it]), "Wrong copy."); |
81 | 86 |
check(nr[from.target(it)] == to.target(er[it]), "Wrong copy."); |
82 | 87 |
} |
83 | 88 |
|
84 | 89 |
for (ListDigraph::NodeIt it(to); it != INVALID; ++it) { |
85 | 90 |
check(nr[ncr[it]] == it, "Wrong copy."); |
86 | 91 |
} |
87 | 92 |
|
88 | 93 |
for (ListDigraph::ArcIt it(to); it != INVALID; ++it) { |
89 | 94 |
check(er[ecr[it]] == it, "Wrong copy."); |
90 | 95 |
} |
91 | 96 |
check(tn == nr[fn], "Wrong copy."); |
92 | 97 |
check(ta == er[fa], "Wrong copy."); |
98 |
|
|
99 |
// Test repeated copy |
|
100 |
digraphCopy(from, to).run(); |
|
101 |
|
|
102 |
check(countNodes(from) == countNodes(to), "Wrong copy."); |
|
103 |
check(countArcs(from) == countArcs(to), "Wrong copy."); |
|
93 | 104 |
} |
94 | 105 |
|
95 | 106 |
void graph_copy_test() { |
96 | 107 |
const int nn = 10; |
97 | 108 |
|
109 |
// Build a graph |
|
98 | 110 |
SmartGraph from; |
99 | 111 |
SmartGraph::NodeMap<int> fnm(from); |
100 | 112 |
SmartGraph::ArcMap<int> fam(from); |
101 | 113 |
SmartGraph::EdgeMap<int> fem(from); |
102 | 114 |
SmartGraph::Node fn = INVALID; |
103 | 115 |
SmartGraph::Arc fa = INVALID; |
104 | 116 |
SmartGraph::Edge fe = INVALID; |
105 | 117 |
|
106 | 118 |
std::vector<SmartGraph::Node> fnv; |
107 | 119 |
for (int i = 0; i < nn; ++i) { |
108 | 120 |
SmartGraph::Node node = from.addNode(); |
109 | 121 |
fnv.push_back(node); |
... | ... |
@@ -113,46 +125,51 @@ |
113 | 125 |
|
114 | 126 |
for (int i = 0; i < nn; ++i) { |
115 | 127 |
for (int j = 0; j < nn; ++j) { |
116 | 128 |
SmartGraph::Edge edge = from.addEdge(fnv[i], fnv[j]); |
117 | 129 |
fem[edge] = i * i + j * j; |
118 | 130 |
fam[from.direct(edge, true)] = i + j * j; |
119 | 131 |
fam[from.direct(edge, false)] = i * i + j; |
120 | 132 |
if (i == 0 && j == 0) fa = from.direct(edge, true); |
121 | 133 |
if (i == 0 && j == 0) fe = edge; |
122 | 134 |
} |
123 | 135 |
} |
124 | 136 |
|
137 |
// Test graph copy |
|
125 | 138 |
ListGraph to; |
126 | 139 |
ListGraph::NodeMap<int> tnm(to); |
127 | 140 |
ListGraph::ArcMap<int> tam(to); |
128 | 141 |
ListGraph::EdgeMap<int> tem(to); |
129 | 142 |
ListGraph::Node tn; |
130 | 143 |
ListGraph::Arc ta; |
131 | 144 |
ListGraph::Edge te; |
132 | 145 |
|
133 | 146 |
SmartGraph::NodeMap<ListGraph::Node> nr(from); |
134 | 147 |
SmartGraph::ArcMap<ListGraph::Arc> ar(from); |
135 | 148 |
SmartGraph::EdgeMap<ListGraph::Edge> er(from); |
136 | 149 |
|
137 | 150 |
ListGraph::NodeMap<SmartGraph::Node> ncr(to); |
138 | 151 |
ListGraph::ArcMap<SmartGraph::Arc> acr(to); |
139 | 152 |
ListGraph::EdgeMap<SmartGraph::Edge> ecr(to); |
140 | 153 |
|
141 | 154 |
graphCopy(from, to). |
142 | 155 |
nodeMap(fnm, tnm).arcMap(fam, tam).edgeMap(fem, tem). |
143 | 156 |
nodeRef(nr).arcRef(ar).edgeRef(er). |
144 | 157 |
nodeCrossRef(ncr).arcCrossRef(acr).edgeCrossRef(ecr). |
145 | 158 |
node(fn, tn).arc(fa, ta).edge(fe, te).run(); |
146 | 159 |
|
160 |
check(countNodes(from) == countNodes(to), "Wrong copy."); |
|
161 |
check(countEdges(from) == countEdges(to), "Wrong copy."); |
|
162 |
check(countArcs(from) == countArcs(to), "Wrong copy."); |
|
163 |
|
|
147 | 164 |
for (SmartGraph::NodeIt it(from); it != INVALID; ++it) { |
148 | 165 |
check(ncr[nr[it]] == it, "Wrong copy."); |
149 | 166 |
check(fnm[it] == tnm[nr[it]], "Wrong copy."); |
150 | 167 |
} |
151 | 168 |
|
152 | 169 |
for (SmartGraph::ArcIt it(from); it != INVALID; ++it) { |
153 | 170 |
check(acr[ar[it]] == it, "Wrong copy."); |
154 | 171 |
check(fam[it] == tam[ar[it]], "Wrong copy."); |
155 | 172 |
check(nr[from.source(it)] == to.source(ar[it]), "Wrong copy."); |
156 | 173 |
check(nr[from.target(it)] == to.target(ar[it]), "Wrong copy."); |
157 | 174 |
} |
158 | 175 |
|
... | ... |
@@ -171,21 +188,28 @@ |
171 | 188 |
check(nr[ncr[it]] == it, "Wrong copy."); |
172 | 189 |
} |
173 | 190 |
|
174 | 191 |
for (ListGraph::ArcIt it(to); it != INVALID; ++it) { |
175 | 192 |
check(ar[acr[it]] == it, "Wrong copy."); |
176 | 193 |
} |
177 | 194 |
for (ListGraph::EdgeIt it(to); it != INVALID; ++it) { |
178 | 195 |
check(er[ecr[it]] == it, "Wrong copy."); |
179 | 196 |
} |
180 | 197 |
check(tn == nr[fn], "Wrong copy."); |
181 | 198 |
check(ta == ar[fa], "Wrong copy."); |
182 | 199 |
check(te == er[fe], "Wrong copy."); |
200 |
|
|
201 |
// Test repeated copy |
|
202 |
graphCopy(from, to).run(); |
|
203 |
|
|
204 |
check(countNodes(from) == countNodes(to), "Wrong copy."); |
|
205 |
check(countEdges(from) == countEdges(to), "Wrong copy."); |
|
206 |
check(countArcs(from) == countArcs(to), "Wrong copy."); |
|
183 | 207 |
} |
184 | 208 |
|
185 | 209 |
|
186 | 210 |
int main() { |
187 | 211 |
digraph_copy_test(); |
188 | 212 |
graph_copy_test(); |
189 | 213 |
|
190 | 214 |
return 0; |
191 | 215 |
} |
0 comments (0 inline)