!
!
!
42
42
139
139
9
5
2
2
1
1
2
2
10
10
4
3
41
41
9
5
7
7
89
89
10
10
11
11
2
2
46
46
11
11
15
15
2
2
4
4
31
31
12
12
54
53
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-2010 |
|
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 |
... | ... |
@@ -68,9 +68,9 @@ |
68 | 68 |
// Throw an exception when problems occurs. The default behavior is to |
69 | 69 |
// exit(1) on these cases, but this makes Valgrind falsely warn |
70 | 70 |
// about memory leaks. |
71 | 71 |
ap.throwOnProblems(); |
72 |
|
|
72 |
|
|
73 | 73 |
// Perform the parsing process |
74 | 74 |
// (in case of any error it terminates the program) |
75 | 75 |
// The try {} construct is necessary only if the ap.trowOnProblems() |
76 | 76 |
// setting is in use. |
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-2010 |
|
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 |
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-2010 |
|
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 |
... | ... |
@@ -24,9 +24,9 @@ |
24 | 24 |
<b>LEMON</b> stands for <i><b>L</b>ibrary for <b>E</b>fficient <b>M</b>odeling |
25 | 25 |
and <b>O</b>ptimization in <b>N</b>etworks</i>. |
26 | 26 |
It is a C++ template library providing efficient implementations of common |
27 | 27 |
data structures and algorithms with focus on combinatorial optimization |
28 |
tasks connected mainly with graphs and networks. |
|
28 |
tasks connected mainly with graphs and networks. |
|
29 | 29 |
|
30 | 30 |
<b> |
31 | 31 |
LEMON is an <a class="el" href="http://opensource.org/">open source</a> |
32 | 32 |
project. |
... | ... |
@@ -34,9 +34,9 @@ |
34 | 34 |
non-commercial applications under very permissive |
35 | 35 |
\ref license "license terms". |
36 | 36 |
</b> |
37 | 37 |
|
38 |
The project is maintained by the |
|
38 |
The project is maintained by the |
|
39 | 39 |
<a href="http://www.cs.elte.hu/egres/">Egerváry Research Group on |
40 | 40 |
Combinatorial Optimization</a> \ref egres |
41 | 41 |
at the Operations Research Department of the |
42 | 42 |
<a href="http://www.elte.hu/en/">Eötvös Loránd University</a>, |
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-2010 |
|
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 |
... | ... |
@@ -80,9 +80,9 @@ |
80 | 80 |
- For all \f$u\in V\f$ nodes: |
81 | 81 |
- \f$\pi(u)\leq 0\f$; |
82 | 82 |
- if \f$\sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \neq sup(u)\f$, |
83 | 83 |
then \f$\pi(u)=0\f$. |
84 |
|
|
84 |
|
|
85 | 85 |
Here \f$cost^\pi(uv)\f$ denotes the \e reduced \e cost of the arc |
86 | 86 |
\f$uv\in A\f$ with respect to the potential function \f$\pi\f$, i.e. |
87 | 87 |
\f[ cost^\pi(uv) = cost(uv) + \pi(u) - \pi(v).\f] |
88 | 88 |
|
... | ... |
@@ -118,9 +118,9 @@ |
118 | 118 |
\f[ \sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \leq |
119 | 119 |
sup(u) \quad \forall u\in V \f] |
120 | 120 |
\f[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A \f] |
121 | 121 |
|
122 |
It means that the total demand must be less or equal to the |
|
122 |
It means that the total demand must be less or equal to the |
|
123 | 123 |
total supply (i.e. \f$\sum_{u\in V} sup(u)\f$ must be zero or |
124 | 124 |
positive) and all the demands have to be satisfied, but there |
125 | 125 |
could be supplies that are not carried out from the supply |
126 | 126 |
nodes. |
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-2010 |
|
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 |
... | ... |
@@ -420,9 +420,9 @@ |
420 | 420 |
|
421 | 421 |
void initialize(DGR& digraph, NF& node_filter, AF& arc_filter) { |
422 | 422 |
Parent::initialize(digraph); |
423 | 423 |
_node_filter = &node_filter; |
424 |
_arc_filter = &arc_filter; |
|
424 |
_arc_filter = &arc_filter; |
|
425 | 425 |
} |
426 | 426 |
|
427 | 427 |
public: |
428 | 428 |
|
... | ... |
@@ -507,13 +507,13 @@ |
507 | 507 |
|
508 | 508 |
public: |
509 | 509 |
|
510 | 510 |
template <typename V> |
511 |
class NodeMap |
|
512 |
: public SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>, |
|
513 |
|
|
511 |
class NodeMap |
|
512 |
: public SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>, |
|
513 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> { |
|
514 | 514 |
typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>, |
515 |
|
|
515 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> Parent; |
|
516 | 516 |
|
517 | 517 |
public: |
518 | 518 |
typedef V Value; |
519 | 519 |
|
... | ... |
@@ -534,11 +534,11 @@ |
534 | 534 |
} |
535 | 535 |
}; |
536 | 536 |
|
537 | 537 |
template <typename V> |
538 |
class ArcMap |
|
538 |
class ArcMap |
|
539 | 539 |
: public SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>, |
540 |
|
|
540 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> { |
|
541 | 541 |
typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>, |
542 | 542 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> Parent; |
543 | 543 |
|
544 | 544 |
public: |
... | ... |
@@ -581,9 +581,9 @@ |
581 | 581 |
|
582 | 582 |
void initialize(DGR& digraph, NF& node_filter, AF& arc_filter) { |
583 | 583 |
Parent::initialize(digraph); |
584 | 584 |
_node_filter = &node_filter; |
585 |
_arc_filter = &arc_filter; |
|
585 |
_arc_filter = &arc_filter; |
|
586 | 586 |
} |
587 | 587 |
|
588 | 588 |
public: |
589 | 589 |
|
... | ... |
@@ -650,12 +650,12 @@ |
650 | 650 |
return arc; |
651 | 651 |
} |
652 | 652 |
|
653 | 653 |
template <typename V> |
654 |
class NodeMap |
|
654 |
class NodeMap |
|
655 | 655 |
: public SubMapExtender<SubDigraphBase<DGR, NF, AF, false>, |
656 | 656 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> { |
657 |
typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, false>, |
|
657 |
typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, false>, |
|
658 | 658 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> Parent; |
659 | 659 |
|
660 | 660 |
public: |
661 | 661 |
typedef V Value; |
... | ... |
@@ -677,9 +677,9 @@ |
677 | 677 |
} |
678 | 678 |
}; |
679 | 679 |
|
680 | 680 |
template <typename V> |
681 |
class ArcMap |
|
681 |
class ArcMap |
|
682 | 682 |
: public SubMapExtender<SubDigraphBase<DGR, NF, AF, false>, |
683 | 683 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> { |
684 | 684 |
typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, false>, |
685 | 685 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> Parent; |
... | ... |
@@ -1020,12 +1020,12 @@ |
1020 | 1020 |
return edge; |
1021 | 1021 |
} |
1022 | 1022 |
|
1023 | 1023 |
template <typename V> |
1024 |
class NodeMap |
|
1024 |
class NodeMap |
|
1025 | 1025 |
: public SubMapExtender<SubGraphBase<GR, NF, EF, ch>, |
1026 | 1026 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> { |
1027 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>, |
|
1027 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>, |
|
1028 | 1028 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> Parent; |
1029 | 1029 |
|
1030 | 1030 |
public: |
1031 | 1031 |
typedef V Value; |
... | ... |
@@ -1047,12 +1047,12 @@ |
1047 | 1047 |
} |
1048 | 1048 |
}; |
1049 | 1049 |
|
1050 | 1050 |
template <typename V> |
1051 |
class ArcMap |
|
1051 |
class ArcMap |
|
1052 | 1052 |
: public SubMapExtender<SubGraphBase<GR, NF, EF, ch>, |
1053 | 1053 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> { |
1054 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>, |
|
1054 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>, |
|
1055 | 1055 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> Parent; |
1056 | 1056 |
|
1057 | 1057 |
public: |
1058 | 1058 |
typedef V Value; |
... | ... |
@@ -1074,12 +1074,12 @@ |
1074 | 1074 |
} |
1075 | 1075 |
}; |
1076 | 1076 |
|
1077 | 1077 |
template <typename V> |
1078 |
class EdgeMap |
|
1078 |
class EdgeMap |
|
1079 | 1079 |
: public SubMapExtender<SubGraphBase<GR, NF, EF, ch>, |
1080 | 1080 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> { |
1081 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>, |
|
1081 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>, |
|
1082 | 1082 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> Parent; |
1083 | 1083 |
|
1084 | 1084 |
public: |
1085 | 1085 |
typedef V Value; |
... | ... |
@@ -1116,10 +1116,10 @@ |
1116 | 1116 |
typedef SubGraphBase Adaptor; |
1117 | 1117 |
protected: |
1118 | 1118 |
NF* _node_filter; |
1119 | 1119 |
EF* _edge_filter; |
1120 |
SubGraphBase() |
|
1121 |
: Parent(), _node_filter(0), _edge_filter(0) { } |
|
1120 |
SubGraphBase() |
|
1121 |
: Parent(), _node_filter(0), _edge_filter(0) { } |
|
1122 | 1122 |
|
1123 | 1123 |
void initialize(GR& graph, NF& node_filter, EF& edge_filter) { |
1124 | 1124 |
Parent::initialize(graph); |
1125 | 1125 |
_node_filter = &node_filter; |
... | ... |
@@ -1218,12 +1218,12 @@ |
1218 | 1218 |
return edge; |
1219 | 1219 |
} |
1220 | 1220 |
|
1221 | 1221 |
template <typename V> |
1222 |
class NodeMap |
|
1222 |
class NodeMap |
|
1223 | 1223 |
: public SubMapExtender<SubGraphBase<GR, NF, EF, false>, |
1224 | 1224 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> { |
1225 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>, |
|
1225 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>, |
|
1226 | 1226 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> Parent; |
1227 | 1227 |
|
1228 | 1228 |
public: |
1229 | 1229 |
typedef V Value; |
... | ... |
@@ -1245,12 +1245,12 @@ |
1245 | 1245 |
} |
1246 | 1246 |
}; |
1247 | 1247 |
|
1248 | 1248 |
template <typename V> |
1249 |
class ArcMap |
|
1249 |
class ArcMap |
|
1250 | 1250 |
: public SubMapExtender<SubGraphBase<GR, NF, EF, false>, |
1251 | 1251 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> { |
1252 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>, |
|
1252 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>, |
|
1253 | 1253 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> Parent; |
1254 | 1254 |
|
1255 | 1255 |
public: |
1256 | 1256 |
typedef V Value; |
... | ... |
@@ -1272,13 +1272,13 @@ |
1272 | 1272 |
} |
1273 | 1273 |
}; |
1274 | 1274 |
|
1275 | 1275 |
template <typename V> |
1276 |
class EdgeMap |
|
1276 |
class EdgeMap |
|
1277 | 1277 |
: public SubMapExtender<SubGraphBase<GR, NF, EF, false>, |
1278 | 1278 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> { |
1279 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>, |
|
1280 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> Parent; |
|
1279 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>, |
|
1280 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> Parent; |
|
1281 | 1281 |
|
1282 | 1282 |
public: |
1283 | 1283 |
typedef V Value; |
1284 | 1284 |
|
... | ... |
@@ -1503,9 +1503,9 @@ |
1503 | 1503 |
SubDigraphBase<GR, NF, ConstMap<typename GR::Arc, Const<bool, true> >, |
1504 | 1504 |
true> > { |
1505 | 1505 |
#endif |
1506 | 1506 |
typedef DigraphAdaptorExtender< |
1507 |
SubDigraphBase<GR, NF, ConstMap<typename GR::Arc, Const<bool, true> >, |
|
1507 |
SubDigraphBase<GR, NF, ConstMap<typename GR::Arc, Const<bool, true> >, |
|
1508 | 1508 |
true> > Parent; |
1509 | 1509 |
|
1510 | 1510 |
public: |
1511 | 1511 |
|
... | ... |
@@ -1524,9 +1524,9 @@ |
1524 | 1524 |
/// \brief Constructor |
1525 | 1525 |
/// |
1526 | 1526 |
/// Creates a subgraph for the given digraph or graph with the |
1527 | 1527 |
/// given node filter map. |
1528 |
FilterNodes(GR& graph, NF& node_filter) |
|
1528 |
FilterNodes(GR& graph, NF& node_filter) |
|
1529 | 1529 |
: Parent(), const_true_map() |
1530 | 1530 |
{ |
1531 | 1531 |
Parent::initialize(graph, node_filter, const_true_map); |
1532 | 1532 |
} |
... | ... |
@@ -1562,13 +1562,13 @@ |
1562 | 1562 |
template<typename GR, typename NF> |
1563 | 1563 |
class FilterNodes<GR, NF, |
1564 | 1564 |
typename enable_if<UndirectedTagIndicator<GR> >::type> : |
1565 | 1565 |
public GraphAdaptorExtender< |
1566 |
SubGraphBase<GR, NF, ConstMap<typename GR::Edge, Const<bool, true> >, |
|
1566 |
SubGraphBase<GR, NF, ConstMap<typename GR::Edge, Const<bool, true> >, |
|
1567 | 1567 |
true> > { |
1568 | 1568 |
|
1569 | 1569 |
typedef GraphAdaptorExtender< |
1570 |
SubGraphBase<GR, NF, ConstMap<typename GR::Edge, Const<bool, true> >, |
|
1570 |
SubGraphBase<GR, NF, ConstMap<typename GR::Edge, Const<bool, true> >, |
|
1571 | 1571 |
true> > Parent; |
1572 | 1572 |
|
1573 | 1573 |
public: |
1574 | 1574 |
|
... | ... |
@@ -1652,9 +1652,9 @@ |
1652 | 1652 |
SubDigraphBase<DGR, ConstMap<typename DGR::Node, Const<bool, true> >, |
1653 | 1653 |
AF, false> > { |
1654 | 1654 |
#endif |
1655 | 1655 |
typedef DigraphAdaptorExtender< |
1656 |
SubDigraphBase<DGR, ConstMap<typename DGR::Node, Const<bool, true> >, |
|
1656 |
SubDigraphBase<DGR, ConstMap<typename DGR::Node, Const<bool, true> >, |
|
1657 | 1657 |
AF, false> > Parent; |
1658 | 1658 |
|
1659 | 1659 |
public: |
1660 | 1660 |
|
... | ... |
@@ -1760,13 +1760,13 @@ |
1760 | 1760 |
template<typename GR, |
1761 | 1761 |
typename EF = typename GR::template EdgeMap<bool> > |
1762 | 1762 |
class FilterEdges : |
1763 | 1763 |
public GraphAdaptorExtender< |
1764 |
SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true> >, |
|
1764 |
SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true> >, |
|
1765 | 1765 |
EF, false> > { |
1766 | 1766 |
#endif |
1767 | 1767 |
typedef GraphAdaptorExtender< |
1768 |
SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true > >, |
|
1768 |
SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true > >, |
|
1769 | 1769 |
EF, false> > Parent; |
1770 | 1770 |
|
1771 | 1771 |
public: |
1772 | 1772 |
|
... | ... |
@@ -1789,9 +1789,9 @@ |
1789 | 1789 |
/// \brief Constructor |
1790 | 1790 |
/// |
1791 | 1791 |
/// Creates a subgraph for the given graph with the given edge |
1792 | 1792 |
/// filter map. |
1793 |
FilterEdges(GR& graph, EF& edge_filter) |
|
1793 |
FilterEdges(GR& graph, EF& edge_filter) |
|
1794 | 1794 |
: Parent(), const_true_map() { |
1795 | 1795 |
Parent::initialize(graph, const_true_map, edge_filter); |
1796 | 1796 |
} |
1797 | 1797 |
|
... | ... |
@@ -1857,9 +1857,9 @@ |
1857 | 1857 |
protected: |
1858 | 1858 |
Edge _edge; |
1859 | 1859 |
bool _forward; |
1860 | 1860 |
|
1861 |
Arc(const Edge& edge, bool forward) |
|
1861 |
Arc(const Edge& edge, bool forward) |
|
1862 | 1862 |
: _edge(edge), _forward(forward) {} |
1863 | 1863 |
|
1864 | 1864 |
public: |
1865 | 1865 |
Arc() {} |
... | ... |
@@ -2097,9 +2097,9 @@ |
2097 | 2097 |
ArcMapBase(const UndirectorBase<DGR>& adaptor) : |
2098 | 2098 |
_forward(*adaptor._digraph), _backward(*adaptor._digraph) {} |
2099 | 2099 |
|
2100 | 2100 |
ArcMapBase(const UndirectorBase<DGR>& adaptor, const V& value) |
2101 |
: _forward(*adaptor._digraph, value), |
|
2101 |
: _forward(*adaptor._digraph, value), |
|
2102 | 2102 |
_backward(*adaptor._digraph, value) {} |
2103 | 2103 |
|
2104 | 2104 |
void set(const Arc& a, const V& value) { |
2105 | 2105 |
if (direction(a)) { |
... | ... |
@@ -2215,9 +2215,9 @@ |
2215 | 2215 |
NodeNotifier& notifier(Node) const { return _digraph->notifier(Node()); } |
2216 | 2216 |
|
2217 | 2217 |
typedef typename ItemSetTraits<DGR, Edge>::ItemNotifier EdgeNotifier; |
2218 | 2218 |
EdgeNotifier& notifier(Edge) const { return _digraph->notifier(Edge()); } |
2219 |
|
|
2219 |
|
|
2220 | 2220 |
typedef EdgeNotifier ArcNotifier; |
2221 | 2221 |
ArcNotifier& notifier(Arc) const { return _digraph->notifier(Edge()); } |
2222 | 2222 |
|
2223 | 2223 |
protected: |
... | ... |
@@ -2727,9 +2727,9 @@ |
2727 | 2727 |
template<typename DGR, |
2728 | 2728 |
typename CM = typename DGR::template ArcMap<int>, |
2729 | 2729 |
typename FM = CM, |
2730 | 2730 |
typename TL = Tolerance<typename CM::Value> > |
2731 |
class ResidualDigraph |
|
2731 |
class ResidualDigraph |
|
2732 | 2732 |
: public SubDigraph< |
2733 | 2733 |
Undirector<const DGR>, |
2734 | 2734 |
ConstMap<typename DGR::Node, Const<bool, true> >, |
2735 | 2735 |
typename Undirector<const DGR>::template CombinedArcMap< |
... | ... |
@@ -2784,9 +2784,9 @@ |
2784 | 2784 |
/// Constructor of the residual digraph adaptor. The parameters are the |
2785 | 2785 |
/// digraph, the capacity map, the flow map, and a tolerance object. |
2786 | 2786 |
ResidualDigraph(const DGR& digraph, const CM& capacity, |
2787 | 2787 |
FM& flow, const TL& tolerance = Tolerance()) |
2788 |
: Parent(), _capacity(&capacity), _flow(&flow), |
|
2788 |
: Parent(), _capacity(&capacity), _flow(&flow), |
|
2789 | 2789 |
_graph(digraph), _node_filter(), |
2790 | 2790 |
_forward_filter(capacity, flow, tolerance), |
2791 | 2791 |
_backward_filter(capacity, flow, tolerance), |
2792 | 2792 |
_arc_filter(_forward_filter, _backward_filter) |
... | ... |
@@ -2866,9 +2866,9 @@ |
2866 | 2866 |
/// The value type of the map |
2867 | 2867 |
typedef typename CapacityMap::Value Value; |
2868 | 2868 |
|
2869 | 2869 |
/// Constructor |
2870 |
ResidualCapacity(const ResidualDigraph<DGR, CM, FM, TL>& adaptor) |
|
2870 |
ResidualCapacity(const ResidualDigraph<DGR, CM, FM, TL>& adaptor) |
|
2871 | 2871 |
: _adaptor(&adaptor) {} |
2872 | 2872 |
|
2873 | 2873 |
/// Returns the value associated with the given residual arc |
2874 | 2874 |
Value operator[](const Arc& a) const { |
... | ... |
@@ -3446,9 +3446,9 @@ |
3446 | 3446 |
/// |
3447 | 3447 |
/// This map adaptor class adapts two node maps of the original digraph |
3448 | 3448 |
/// to get a node map of the split digraph. |
3449 | 3449 |
/// Its value type is inherited from the first node map type (\c IN). |
3450 |
/// \tparam IN The type of the node map for the in-nodes. |
|
3450 |
/// \tparam IN The type of the node map for the in-nodes. |
|
3451 | 3451 |
/// \tparam OUT The type of the node map for the out-nodes. |
3452 | 3452 |
template <typename IN, typename OUT> |
3453 | 3453 |
class CombinedNodeMap { |
3454 | 3454 |
public: |
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-2010 |
|
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 |
... | ... |
@@ -25,10 +25,10 @@ |
25 | 25 |
if(_exit_on_problems) |
26 | 26 |
exit(1); |
27 | 27 |
else throw(ArgParserException(reason)); |
28 | 28 |
} |
29 |
|
|
30 |
|
|
29 |
|
|
30 |
|
|
31 | 31 |
void ArgParser::_showHelp(void *p) |
32 | 32 |
{ |
33 | 33 |
(static_cast<ArgParser*>(p))->showHelp(); |
34 | 34 |
(static_cast<ArgParser*>(p))->_terminate(ArgParserException::HELP); |
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-2010 |
|
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 |
... | ... |
@@ -41,12 +41,12 @@ |
41 | 41 |
HELP, /// <tt>--help</tt> option was given |
42 | 42 |
UNKNOWN_OPT, /// Unknown option was given |
43 | 43 |
INVALID_OPT /// Invalid combination of options |
44 | 44 |
}; |
45 |
|
|
45 |
|
|
46 | 46 |
private: |
47 | 47 |
Reason _reason; |
48 |
|
|
48 |
|
|
49 | 49 |
public: |
50 | 50 |
///Constructor |
51 | 51 |
ArgParserException(Reason r) throw() : _reason(r) {} |
52 | 52 |
///Virtual destructor |
... | ... |
@@ -140,9 +140,9 @@ |
140 | 140 |
std::vector<OtherArg> _others_help; |
141 | 141 |
std::vector<std::string> _file_args; |
142 | 142 |
std::string _command_name; |
143 | 143 |
|
144 |
|
|
144 |
|
|
145 | 145 |
private: |
146 | 146 |
//Bind a function to an option. |
147 | 147 |
|
148 | 148 |
//\param name The name of the option. The leading '-' must be omitted. |
... | ... |
@@ -154,9 +154,9 @@ |
154 | 154 |
const std::string &help, |
155 | 155 |
void (*func)(void *),void *data); |
156 | 156 |
|
157 | 157 |
bool _exit_on_problems; |
158 |
|
|
158 |
|
|
159 | 159 |
void _terminate(ArgParserException::Reason reason) const; |
160 | 160 |
|
161 | 161 |
public: |
162 | 162 |
|
... | ... |
@@ -422,9 +422,9 @@ |
422 | 422 |
///not starting with a '-' character. |
423 | 423 |
const std::vector<std::string> &files() const { return _file_args; } |
424 | 424 |
|
425 | 425 |
///Throw instead of exit in case of problems |
426 |
void throwOnProblems() |
|
426 |
void throwOnProblems() |
|
427 | 427 |
{ |
428 | 428 |
_exit_on_problems=false; |
429 | 429 |
} |
430 | 430 |
}; |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 |
* Copyright (C) 2003- |
|
5 |
* Copyright (C) 2003-2010 |
|
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 |
... | ... |
@@ -35,18 +35,18 @@ |
35 | 35 |
|
36 | 36 |
namespace lemon { |
37 | 37 |
|
38 | 38 |
/// \brief Default operation traits for the BellmanFord algorithm class. |
39 |
/// |
|
39 |
/// |
|
40 | 40 |
/// This operation traits class defines all computational operations |
41 | 41 |
/// and constants that are used in the Bellman-Ford algorithm. |
42 | 42 |
/// The default implementation is based on the \c numeric_limits class. |
43 | 43 |
/// If the numeric type does not have infinity value, then the maximum |
44 | 44 |
/// value is used as extremal infinity value. |
45 | 45 |
/// |
46 | 46 |
/// \see BellmanFordToleranceOperationTraits |
47 | 47 |
template < |
48 |
typename V, |
|
48 |
typename V, |
|
49 | 49 |
bool has_inf = std::numeric_limits<V>::has_infinity> |
50 | 50 |
struct BellmanFordDefaultOperationTraits { |
51 | 51 |
/// \brief Value type for the algorithm. |
52 | 52 |
typedef V Value; |
... | ... |
@@ -85,9 +85,9 @@ |
85 | 85 |
static bool less(const Value& left, const Value& right) { |
86 | 86 |
return left < right; |
87 | 87 |
} |
88 | 88 |
}; |
89 |
|
|
89 |
|
|
90 | 90 |
/// \brief Operation traits for the BellmanFord algorithm class |
91 | 91 |
/// using tolerance. |
92 | 92 |
/// |
93 | 93 |
/// This operation traits class defines all computational operations |
... | ... |
@@ -138,9 +138,9 @@ |
138 | 138 |
/// \param GR The type of the digraph. |
139 | 139 |
/// \param LEN The type of the length map. |
140 | 140 |
template<typename GR, typename LEN> |
141 | 141 |
struct BellmanFordDefaultTraits { |
142 |
/// The type of the digraph the algorithm runs on. |
|
142 |
/// The type of the digraph the algorithm runs on. |
|
143 | 143 |
typedef GR Digraph; |
144 | 144 |
|
145 | 145 |
/// \brief The type of the map that stores the arc lengths. |
146 | 146 |
/// |
... | ... |
@@ -157,20 +157,20 @@ |
157 | 157 |
/// given \c Value type. |
158 | 158 |
/// \see BellmanFordDefaultOperationTraits, |
159 | 159 |
/// BellmanFordToleranceOperationTraits |
160 | 160 |
typedef BellmanFordDefaultOperationTraits<Value> OperationTraits; |
161 |
|
|
162 |
/// \brief The type of the map that stores the last arcs of the |
|
161 |
|
|
162 |
/// \brief The type of the map that stores the last arcs of the |
|
163 | 163 |
/// shortest paths. |
164 |
/// |
|
164 |
/// |
|
165 | 165 |
/// The type of the map that stores the last |
166 | 166 |
/// arcs of the shortest paths. |
167 | 167 |
/// It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
168 | 168 |
typedef typename GR::template NodeMap<typename GR::Arc> PredMap; |
169 | 169 |
|
170 | 170 |
/// \brief Instantiates a \c PredMap. |
171 |
/// |
|
172 |
/// This function instantiates a \ref PredMap. |
|
171 |
/// |
|
172 |
/// This function instantiates a \ref PredMap. |
|
173 | 173 |
/// \param g is the digraph to which we would like to define the |
174 | 174 |
/// \ref PredMap. |
175 | 175 |
static PredMap *createPredMap(const GR& g) { |
176 | 176 |
return new PredMap(g); |
... | ... |
@@ -183,21 +183,21 @@ |
183 | 183 |
typedef typename GR::template NodeMap<typename LEN::Value> DistMap; |
184 | 184 |
|
185 | 185 |
/// \brief Instantiates a \c DistMap. |
186 | 186 |
/// |
187 |
/// This function instantiates a \ref DistMap. |
|
188 |
/// \param g is the digraph to which we would like to define the |
|
187 |
/// This function instantiates a \ref DistMap. |
|
188 |
/// \param g is the digraph to which we would like to define the |
|
189 | 189 |
/// \ref DistMap. |
190 | 190 |
static DistMap *createDistMap(const GR& g) { |
191 | 191 |
return new DistMap(g); |
192 | 192 |
} |
193 | 193 |
|
194 | 194 |
}; |
195 |
|
|
195 |
|
|
196 | 196 |
/// \brief %BellmanFord algorithm class. |
197 | 197 |
/// |
198 | 198 |
/// \ingroup shortest_path |
199 |
/// This class provides an efficient implementation of the Bellman-Ford |
|
199 |
/// This class provides an efficient implementation of the Bellman-Ford |
|
200 | 200 |
/// algorithm. The maximum time complexity of the algorithm is |
201 | 201 |
/// <tt>O(ne)</tt>. |
202 | 202 |
/// |
203 | 203 |
/// The Bellman-Ford algorithm solves the single-source shortest path |
... | ... |
@@ -206,9 +206,9 @@ |
206 | 206 |
/// If all arc costs are non-negative, consider to use the Dijkstra |
207 | 207 |
/// algorithm instead, since it is more efficient. |
208 | 208 |
/// |
209 | 209 |
/// The arc lengths are passed to the algorithm using a |
210 |
/// \ref concepts::ReadMap "ReadMap", so it is easy to change it to any |
|
210 |
/// \ref concepts::ReadMap "ReadMap", so it is easy to change it to any |
|
211 | 211 |
/// kind of length. The type of the length values is determined by the |
212 | 212 |
/// \ref concepts::ReadMap::Value "Value" type of the length map. |
213 | 213 |
/// |
214 | 214 |
/// There is also a \ref bellmanFord() "function-type interface" for the |
... | ... |
@@ -236,9 +236,9 @@ |
236 | 236 |
public: |
237 | 237 |
|
238 | 238 |
///The type of the underlying digraph. |
239 | 239 |
typedef typename TR::Digraph Digraph; |
240 |
|
|
240 |
|
|
241 | 241 |
/// \brief The type of the arc lengths. |
242 | 242 |
typedef typename TR::LengthMap::Value Value; |
243 | 243 |
/// \brief The type of the map that stores the arc lengths. |
244 | 244 |
typedef typename TR::LengthMap LengthMap; |
... | ... |
@@ -283,22 +283,22 @@ |
283 | 283 |
|
284 | 284 |
// Creates the maps if necessary. |
285 | 285 |
void create_maps() { |
286 | 286 |
if(!_pred) { |
287 |
_local_pred = true; |
|
288 |
_pred = Traits::createPredMap(*_gr); |
|
287 |
_local_pred = true; |
|
288 |
_pred = Traits::createPredMap(*_gr); |
|
289 | 289 |
} |
290 | 290 |
if(!_dist) { |
291 |
_local_dist = true; |
|
292 |
_dist = Traits::createDistMap(*_gr); |
|
291 |
_local_dist = true; |
|
292 |
_dist = Traits::createDistMap(*_gr); |
|
293 | 293 |
} |
294 | 294 |
if(!_mask) { |
295 | 295 |
_mask = new MaskMap(*_gr); |
296 | 296 |
} |
297 | 297 |
} |
298 |
|
|
298 |
|
|
299 | 299 |
public : |
300 |
|
|
300 |
|
|
301 | 301 |
typedef BellmanFord Create; |
302 | 302 |
|
303 | 303 |
/// \name Named Template Parameters |
304 | 304 |
|
... | ... |
@@ -319,13 +319,13 @@ |
319 | 319 |
/// \ref named-templ-param "Named parameter" for setting |
320 | 320 |
/// \c PredMap type. |
321 | 321 |
/// It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
322 | 322 |
template <class T> |
323 |
struct SetPredMap |
|
323 |
struct SetPredMap |
|
324 | 324 |
: public BellmanFord< Digraph, LengthMap, SetPredMapTraits<T> > { |
325 | 325 |
typedef BellmanFord< Digraph, LengthMap, SetPredMapTraits<T> > Create; |
326 | 326 |
}; |
327 |
|
|
327 |
|
|
328 | 328 |
template <class T> |
329 | 329 |
struct SetDistMapTraits : public Traits { |
330 | 330 |
typedef T DistMap; |
331 | 331 |
static DistMap *createDistMap(const Digraph&) { |
... | ... |
@@ -340,19 +340,19 @@ |
340 | 340 |
/// \ref named-templ-param "Named parameter" for setting |
341 | 341 |
/// \c DistMap type. |
342 | 342 |
/// It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
343 | 343 |
template <class T> |
344 |
struct SetDistMap |
|
344 |
struct SetDistMap |
|
345 | 345 |
: public BellmanFord< Digraph, LengthMap, SetDistMapTraits<T> > { |
346 | 346 |
typedef BellmanFord< Digraph, LengthMap, SetDistMapTraits<T> > Create; |
347 | 347 |
}; |
348 | 348 |
|
349 | 349 |
template <class T> |
350 | 350 |
struct SetOperationTraitsTraits : public Traits { |
351 | 351 |
typedef T OperationTraits; |
352 | 352 |
}; |
353 |
|
|
354 |
/// \brief \ref named-templ-param "Named parameter" for setting |
|
353 |
|
|
354 |
/// \brief \ref named-templ-param "Named parameter" for setting |
|
355 | 355 |
/// \c OperationTraits type. |
356 | 356 |
/// |
357 | 357 |
/// \ref named-templ-param "Named parameter" for setting |
358 | 358 |
/// \c OperationTraits type. |
... | ... |
@@ -362,17 +362,17 @@ |
362 | 362 |
: public BellmanFord< Digraph, LengthMap, SetOperationTraitsTraits<T> > { |
363 | 363 |
typedef BellmanFord< Digraph, LengthMap, SetOperationTraitsTraits<T> > |
364 | 364 |
Create; |
365 | 365 |
}; |
366 |
|
|
366 |
|
|
367 | 367 |
///@} |
368 | 368 |
|
369 | 369 |
protected: |
370 |
|
|
370 |
|
|
371 | 371 |
BellmanFord() {} |
372 | 372 |
|
373 |
public: |
|
374 |
|
|
373 |
public: |
|
374 |
|
|
375 | 375 |
/// \brief Constructor. |
376 | 376 |
/// |
377 | 377 |
/// Constructor. |
378 | 378 |
/// \param g The digraph the algorithm runs on. |
... | ... |
@@ -380,9 +380,9 @@ |
380 | 380 |
BellmanFord(const Digraph& g, const LengthMap& length) : |
381 | 381 |
_gr(&g), _length(&length), |
382 | 382 |
_pred(0), _local_pred(false), |
383 | 383 |
_dist(0), _local_dist(false), _mask(0) {} |
384 |
|
|
384 |
|
|
385 | 385 |
///Destructor. |
386 | 386 |
~BellmanFord() { |
387 | 387 |
if(_local_pred) delete _pred; |
388 | 388 |
if(_local_dist) delete _dist; |
... | ... |
@@ -407,10 +407,10 @@ |
407 | 407 |
/// of course. |
408 | 408 |
/// \return <tt>(*this)</tt> |
409 | 409 |
BellmanFord &predMap(PredMap &map) { |
410 | 410 |
if(_local_pred) { |
411 |
delete _pred; |
|
412 |
_local_pred=false; |
|
411 |
delete _pred; |
|
412 |
_local_pred=false; |
|
413 | 413 |
} |
414 | 414 |
_pred = ↦ |
415 | 415 |
return *this; |
416 | 416 |
} |
... | ... |
@@ -425,10 +425,10 @@ |
425 | 425 |
/// of course. |
426 | 426 |
/// \return <tt>(*this)</tt> |
427 | 427 |
BellmanFord &distMap(DistMap &map) { |
428 | 428 |
if(_local_dist) { |
429 |
delete _dist; |
|
430 |
_local_dist=false; |
|
429 |
delete _dist; |
|
430 |
_local_dist=false; |
|
431 | 431 |
} |
432 | 432 |
_dist = ↦ |
433 | 433 |
return *this; |
434 | 434 |
} |
... | ... |
@@ -444,39 +444,39 @@ |
444 | 444 |
|
445 | 445 |
///@{ |
446 | 446 |
|
447 | 447 |
/// \brief Initializes the internal data structures. |
448 |
/// |
|
448 |
/// |
|
449 | 449 |
/// Initializes the internal data structures. The optional parameter |
450 | 450 |
/// is the initial distance of each node. |
451 | 451 |
void init(const Value value = OperationTraits::infinity()) { |
452 | 452 |
create_maps(); |
453 | 453 |
for (NodeIt it(*_gr); it != INVALID; ++it) { |
454 |
_pred->set(it, INVALID); |
|
455 |
_dist->set(it, value); |
|
454 |
_pred->set(it, INVALID); |
|
455 |
_dist->set(it, value); |
|
456 | 456 |
} |
457 | 457 |
_process.clear(); |
458 | 458 |
if (OperationTraits::less(value, OperationTraits::infinity())) { |
459 |
for (NodeIt it(*_gr); it != INVALID; ++it) { |
|
460 |
_process.push_back(it); |
|
461 |
_mask->set(it, true); |
|
462 |
} |
|
459 |
for (NodeIt it(*_gr); it != INVALID; ++it) { |
|
460 |
_process.push_back(it); |
|
461 |
_mask->set(it, true); |
|
462 |
} |
|
463 | 463 |
} else { |
464 |
for (NodeIt it(*_gr); it != INVALID; ++it) { |
|
465 |
_mask->set(it, false); |
|
466 |
|
|
464 |
for (NodeIt it(*_gr); it != INVALID; ++it) { |
|
465 |
_mask->set(it, false); |
|
466 |
} |
|
467 | 467 |
} |
468 | 468 |
} |
469 |
|
|
469 |
|
|
470 | 470 |
/// \brief Adds a new source node. |
471 | 471 |
/// |
472 | 472 |
/// This function adds a new source node. The optional second parameter |
473 | 473 |
/// is the initial distance of the node. |
474 | 474 |
void addSource(Node source, Value dst = OperationTraits::zero()) { |
475 | 475 |
_dist->set(source, dst); |
476 | 476 |
if (!(*_mask)[source]) { |
477 |
_process.push_back(source); |
|
478 |
_mask->set(source, true); |
|
477 |
_process.push_back(source); |
|
478 |
_mask->set(source, true); |
|
479 | 479 |
} |
480 | 480 |
} |
481 | 481 |
|
482 | 482 |
/// \brief Executes one round from the Bellman-Ford algorithm. |
... | ... |
@@ -499,28 +499,28 @@ |
499 | 499 |
/// |
500 | 500 |
/// \see ActiveIt |
501 | 501 |
bool processNextRound() { |
502 | 502 |
for (int i = 0; i < int(_process.size()); ++i) { |
503 |
|
|
503 |
_mask->set(_process[i], false); |
|
504 | 504 |
} |
505 | 505 |
std::vector<Node> nextProcess; |
506 | 506 |
std::vector<Value> values(_process.size()); |
507 | 507 |
for (int i = 0; i < int(_process.size()); ++i) { |
508 |
|
|
508 |
values[i] = (*_dist)[_process[i]]; |
|
509 | 509 |
} |
510 | 510 |
for (int i = 0; i < int(_process.size()); ++i) { |
511 |
for (OutArcIt it(*_gr, _process[i]); it != INVALID; ++it) { |
|
512 |
Node target = _gr->target(it); |
|
513 |
Value relaxed = OperationTraits::plus(values[i], (*_length)[it]); |
|
514 |
if (OperationTraits::less(relaxed, (*_dist)[target])) { |
|
515 |
_pred->set(target, it); |
|
516 |
_dist->set(target, relaxed); |
|
517 |
if (!(*_mask)[target]) { |
|
518 |
_mask->set(target, true); |
|
519 |
nextProcess.push_back(target); |
|
520 |
} |
|
521 |
} |
|
522 |
} |
|
511 |
for (OutArcIt it(*_gr, _process[i]); it != INVALID; ++it) { |
|
512 |
Node target = _gr->target(it); |
|
513 |
Value relaxed = OperationTraits::plus(values[i], (*_length)[it]); |
|
514 |
if (OperationTraits::less(relaxed, (*_dist)[target])) { |
|
515 |
_pred->set(target, it); |
|
516 |
_dist->set(target, relaxed); |
|
517 |
if (!(*_mask)[target]) { |
|
518 |
_mask->set(target, true); |
|
519 |
nextProcess.push_back(target); |
|
520 |
} |
|
521 |
} |
|
522 |
} |
|
523 | 523 |
} |
524 | 524 |
_process.swap(nextProcess); |
525 | 525 |
return _process.empty(); |
526 | 526 |
} |
... | ... |
@@ -540,25 +540,25 @@ |
540 | 540 |
/// |
541 | 541 |
/// \see ActiveIt |
542 | 542 |
bool processNextWeakRound() { |
543 | 543 |
for (int i = 0; i < int(_process.size()); ++i) { |
544 |
|
|
544 |
_mask->set(_process[i], false); |
|
545 | 545 |
} |
546 | 546 |
std::vector<Node> nextProcess; |
547 | 547 |
for (int i = 0; i < int(_process.size()); ++i) { |
548 |
for (OutArcIt it(*_gr, _process[i]); it != INVALID; ++it) { |
|
549 |
Node target = _gr->target(it); |
|
550 |
Value relaxed = |
|
551 |
OperationTraits::plus((*_dist)[_process[i]], (*_length)[it]); |
|
552 |
if (OperationTraits::less(relaxed, (*_dist)[target])) { |
|
553 |
_pred->set(target, it); |
|
554 |
_dist->set(target, relaxed); |
|
555 |
if (!(*_mask)[target]) { |
|
556 |
_mask->set(target, true); |
|
557 |
nextProcess.push_back(target); |
|
558 |
} |
|
559 |
} |
|
560 |
|
|
548 |
for (OutArcIt it(*_gr, _process[i]); it != INVALID; ++it) { |
|
549 |
Node target = _gr->target(it); |
|
550 |
Value relaxed = |
|
551 |
OperationTraits::plus((*_dist)[_process[i]], (*_length)[it]); |
|
552 |
if (OperationTraits::less(relaxed, (*_dist)[target])) { |
|
553 |
_pred->set(target, it); |
|
554 |
_dist->set(target, relaxed); |
|
555 |
if (!(*_mask)[target]) { |
|
556 |
_mask->set(target, true); |
|
557 |
nextProcess.push_back(target); |
|
558 |
} |
|
559 |
} |
|
560 |
} |
|
561 | 561 |
} |
562 | 562 |
_process.swap(nextProcess); |
563 | 563 |
return _process.empty(); |
564 | 564 |
} |
... | ... |
@@ -578,9 +578,9 @@ |
578 | 578 |
/// added with addSource() before using this function. |
579 | 579 |
void start() { |
580 | 580 |
int num = countNodes(*_gr) - 1; |
581 | 581 |
for (int i = 0; i < num; ++i) { |
582 |
|
|
582 |
if (processNextWeakRound()) break; |
|
583 | 583 |
} |
584 | 584 |
} |
585 | 585 |
|
586 | 586 |
/// \brief Executes the algorithm and checks the negative cycles. |
... | ... |
@@ -590,20 +590,20 @@ |
590 | 590 |
/// This method runs the Bellman-Ford algorithm from the root node(s) |
591 | 591 |
/// in order to compute the shortest path to each node and also checks |
592 | 592 |
/// if the digraph contains cycles with negative total length. |
593 | 593 |
/// |
594 |
/// The algorithm computes |
|
594 |
/// The algorithm computes |
|
595 | 595 |
/// - the shortest path tree (forest), |
596 | 596 |
/// - the distance of each node from the root(s). |
597 |
/// |
|
597 |
/// |
|
598 | 598 |
/// \return \c false if there is a negative cycle in the digraph. |
599 | 599 |
/// |
600 | 600 |
/// \pre init() must be called and at least one root node should be |
601 |
/// added with addSource() before using this function. |
|
601 |
/// added with addSource() before using this function. |
|
602 | 602 |
bool checkedStart() { |
603 | 603 |
int num = countNodes(*_gr); |
604 | 604 |
for (int i = 0; i < num; ++i) { |
605 |
|
|
605 |
if (processNextWeakRound()) return true; |
|
606 | 606 |
} |
607 | 607 |
return _process.empty(); |
608 | 608 |
} |
609 | 609 |
|
... | ... |
@@ -625,17 +625,17 @@ |
625 | 625 |
/// store the \ref predMap() "predecessor map" after each iteration |
626 | 626 |
/// and build the path manually. |
627 | 627 |
/// |
628 | 628 |
/// \pre init() must be called and at least one root node should be |
629 |
/// added with addSource() before using this function. |
|
629 |
/// added with addSource() before using this function. |
|
630 | 630 |
void limitedStart(int num) { |
631 | 631 |
for (int i = 0; i < num; ++i) { |
632 |
|
|
632 |
if (processNextRound()) break; |
|
633 | 633 |
} |
634 | 634 |
} |
635 |
|
|
635 |
|
|
636 | 636 |
/// \brief Runs the algorithm from the given root node. |
637 |
/// |
|
637 |
/// |
|
638 | 638 |
/// This method runs the Bellman-Ford algorithm from the given root |
639 | 639 |
/// node \c s in order to compute the shortest path to each node. |
640 | 640 |
/// |
641 | 641 |
/// The algorithm computes |
... | ... |
@@ -652,12 +652,12 @@ |
652 | 652 |
init(); |
653 | 653 |
addSource(s); |
654 | 654 |
start(); |
655 | 655 |
} |
656 |
|
|
656 |
|
|
657 | 657 |
/// \brief Runs the algorithm from the given root node with arc |
658 | 658 |
/// number limit. |
659 |
/// |
|
659 |
/// |
|
660 | 660 |
/// This method runs the Bellman-Ford algorithm from the given root |
661 | 661 |
/// node \c s in order to compute the shortest path distance for each |
662 | 662 |
/// node using only the paths consisting of at most \c num arcs. |
663 | 663 |
/// |
... | ... |
@@ -681,9 +681,9 @@ |
681 | 681 |
init(); |
682 | 682 |
addSource(s); |
683 | 683 |
limitedStart(num); |
684 | 684 |
} |
685 |
|
|
685 |
|
|
686 | 686 |
///@} |
687 | 687 |
|
688 | 688 |
/// \brief LEMON iterator for getting the active nodes. |
689 | 689 |
/// |
... | ... |
@@ -696,9 +696,9 @@ |
696 | 696 |
|
697 | 697 |
/// \brief Constructor. |
698 | 698 |
/// |
699 | 699 |
/// Constructor for getting the active nodes of the given BellmanFord |
700 |
/// instance. |
|
700 |
/// instance. |
|
701 | 701 |
ActiveIt(const BellmanFord& algorithm) : _algorithm(&algorithm) |
702 | 702 |
{ |
703 | 703 |
_index = _algorithm->_process.size() - 1; |
704 | 704 |
} |
... | ... |
@@ -710,44 +710,44 @@ |
710 | 710 |
|
711 | 711 |
/// \brief Conversion to \c Node. |
712 | 712 |
/// |
713 | 713 |
/// Conversion to \c Node. |
714 |
operator Node() const { |
|
714 |
operator Node() const { |
|
715 | 715 |
return _index >= 0 ? _algorithm->_process[_index] : INVALID; |
716 | 716 |
} |
717 | 717 |
|
718 | 718 |
/// \brief Increment operator. |
719 | 719 |
/// |
720 | 720 |
/// Increment operator. |
721 | 721 |
ActiveIt& operator++() { |
722 | 722 |
--_index; |
723 |
return *this; |
|
723 |
return *this; |
|
724 | 724 |
} |
725 | 725 |
|
726 |
bool operator==(const ActiveIt& it) const { |
|
727 |
return static_cast<Node>(*this) == static_cast<Node>(it); |
|
726 |
bool operator==(const ActiveIt& it) const { |
|
727 |
return static_cast<Node>(*this) == static_cast<Node>(it); |
|
728 | 728 |
} |
729 |
bool operator!=(const ActiveIt& it) const { |
|
730 |
return static_cast<Node>(*this) != static_cast<Node>(it); |
|
729 |
bool operator!=(const ActiveIt& it) const { |
|
730 |
return static_cast<Node>(*this) != static_cast<Node>(it); |
|
731 | 731 |
} |
732 |
bool operator<(const ActiveIt& it) const { |
|
733 |
return static_cast<Node>(*this) < static_cast<Node>(it); |
|
732 |
bool operator<(const ActiveIt& it) const { |
|
733 |
return static_cast<Node>(*this) < static_cast<Node>(it); |
|
734 | 734 |
} |
735 |
|
|
735 |
|
|
736 | 736 |
private: |
737 | 737 |
const BellmanFord* _algorithm; |
738 | 738 |
int _index; |
739 | 739 |
}; |
740 |
|
|
740 |
|
|
741 | 741 |
/// \name Query Functions |
742 | 742 |
/// The result of the Bellman-Ford algorithm can be obtained using these |
743 | 743 |
/// functions.\n |
744 | 744 |
/// Either \ref run() or \ref init() should be called before using them. |
745 |
|
|
745 |
|
|
746 | 746 |
///@{ |
747 | 747 |
|
748 | 748 |
/// \brief The shortest path to the given node. |
749 |
/// |
|
749 |
/// |
|
750 | 750 |
/// Gives back the shortest path to the given node from the root(s). |
751 | 751 |
/// |
752 | 752 |
/// \warning \c t should be reached from the root(s). |
753 | 753 |
/// |
... | ... |
@@ -756,9 +756,9 @@ |
756 | 756 |
Path path(Node t) const |
757 | 757 |
{ |
758 | 758 |
return Path(*_gr, *_pred, t); |
759 | 759 |
} |
760 |
|
|
760 |
|
|
761 | 761 |
/// \brief The distance of the given node from the root(s). |
762 | 762 |
/// |
763 | 763 |
/// Returns the distance of the given node from the root(s). |
764 | 764 |
/// |
... | ... |
@@ -796,12 +796,12 @@ |
796 | 796 |
/// tree used in \ref predArc() and \ref predMap(). |
797 | 797 |
/// |
798 | 798 |
/// \pre Either \ref run() or \ref init() must be called before |
799 | 799 |
/// using this function. |
800 |
Node predNode(Node v) const { |
|
801 |
return (*_pred)[v] == INVALID ? INVALID : _gr->source((*_pred)[v]); |
|
800 |
Node predNode(Node v) const { |
|
801 |
return (*_pred)[v] == INVALID ? INVALID : _gr->source((*_pred)[v]); |
|
802 | 802 |
} |
803 |
|
|
803 |
|
|
804 | 804 |
/// \brief Returns a const reference to the node map that stores the |
805 | 805 |
/// distances of the nodes. |
806 | 806 |
/// |
807 | 807 |
/// Returns a const reference to the node map that stores the distances |
... | ... |
@@ -809,9 +809,9 @@ |
809 | 809 |
/// |
810 | 810 |
/// \pre Either \ref run() or \ref init() must be called before |
811 | 811 |
/// using this function. |
812 | 812 |
const DistMap &distMap() const { return *_dist;} |
813 |
|
|
813 |
|
|
814 | 814 |
/// \brief Returns a const reference to the node map that stores the |
815 | 815 |
/// predecessor arcs. |
816 | 816 |
/// |
817 | 817 |
/// Returns a const reference to the node map that stores the predecessor |
... | ... |
@@ -819,9 +819,9 @@ |
819 | 819 |
/// |
820 | 820 |
/// \pre Either \ref run() or \ref init() must be called before |
821 | 821 |
/// using this function. |
822 | 822 |
const PredMap &predMap() const { return *_pred; } |
823 |
|
|
823 |
|
|
824 | 824 |
/// \brief Checks if a node is reached from the root(s). |
825 | 825 |
/// |
826 | 826 |
/// Returns \c true if \c v is reached from the root(s). |
827 | 827 |
/// |
... | ... |
@@ -831,9 +831,9 @@ |
831 | 831 |
return (*_dist)[v] != OperationTraits::infinity(); |
832 | 832 |
} |
833 | 833 |
|
834 | 834 |
/// \brief Gives back a negative cycle. |
835 |
/// |
|
835 |
/// |
|
836 | 836 |
/// This function gives back a directed cycle with negative total |
837 | 837 |
/// length if the algorithm has already found one. |
838 | 838 |
/// Otherwise it gives back an empty path. |
839 | 839 |
lemon::Path<Digraph> negativeCycle() const { |
... | ... |
@@ -858,20 +858,20 @@ |
858 | 858 |
} |
859 | 859 |
} |
860 | 860 |
return cycle; |
861 | 861 |
} |
862 |
|
|
862 |
|
|
863 | 863 |
///@} |
864 | 864 |
}; |
865 |
|
|
865 |
|
|
866 | 866 |
/// \brief Default traits class of bellmanFord() function. |
867 | 867 |
/// |
868 | 868 |
/// Default traits class of bellmanFord() function. |
869 | 869 |
/// \tparam GR The type of the digraph. |
870 | 870 |
/// \tparam LEN The type of the length map. |
871 | 871 |
template <typename GR, typename LEN> |
872 | 872 |
struct BellmanFordWizardDefaultTraits { |
873 |
/// The type of the digraph the algorithm runs on. |
|
873 |
/// The type of the digraph the algorithm runs on. |
|
874 | 874 |
typedef GR Digraph; |
875 | 875 |
|
876 | 876 |
/// \brief The type of the map that stores the arc lengths. |
877 | 877 |
/// |
... | ... |
@@ -891,15 +891,15 @@ |
891 | 891 |
typedef BellmanFordDefaultOperationTraits<Value> OperationTraits; |
892 | 892 |
|
893 | 893 |
/// \brief The type of the map that stores the last |
894 | 894 |
/// arcs of the shortest paths. |
895 |
/// |
|
895 |
/// |
|
896 | 896 |
/// The type of the map that stores the last arcs of the shortest paths. |
897 | 897 |
/// It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
898 | 898 |
typedef typename GR::template NodeMap<typename GR::Arc> PredMap; |
899 | 899 |
|
900 | 900 |
/// \brief Instantiates a \c PredMap. |
901 |
/// |
|
901 |
/// |
|
902 | 902 |
/// This function instantiates a \ref PredMap. |
903 | 903 |
/// \param g is the digraph to which we would like to define the |
904 | 904 |
/// \ref PredMap. |
905 | 905 |
static PredMap *createPredMap(const GR &g) { |
... | ... |
@@ -913,9 +913,9 @@ |
913 | 913 |
typedef typename GR::template NodeMap<Value> DistMap; |
914 | 914 |
|
915 | 915 |
/// \brief Instantiates a \c DistMap. |
916 | 916 |
/// |
917 |
/// This function instantiates a \ref DistMap. |
|
917 |
/// This function instantiates a \ref DistMap. |
|
918 | 918 |
/// \param g is the digraph to which we would like to define the |
919 | 919 |
/// \ref DistMap. |
920 | 920 |
static DistMap *createDistMap(const GR &g) { |
921 | 921 |
return new DistMap(g); |
... | ... |
@@ -926,16 +926,16 @@ |
926 | 926 |
///The type of the shortest paths. |
927 | 927 |
///It must meet the \ref concepts::Path "Path" concept. |
928 | 928 |
typedef lemon::Path<Digraph> Path; |
929 | 929 |
}; |
930 |
|
|
930 |
|
|
931 | 931 |
/// \brief Default traits class used by BellmanFordWizard. |
932 | 932 |
/// |
933 | 933 |
/// Default traits class used by BellmanFordWizard. |
934 | 934 |
/// \tparam GR The type of the digraph. |
935 | 935 |
/// \tparam LEN The type of the length map. |
936 | 936 |
template <typename GR, typename LEN> |
937 |
class BellmanFordWizardBase |
|
937 |
class BellmanFordWizardBase |
|
938 | 938 |
: public BellmanFordWizardDefaultTraits<GR, LEN> { |
939 | 939 |
|
940 | 940 |
typedef BellmanFordWizardDefaultTraits<GR, LEN> Base; |
941 | 941 |
protected: |
... | ... |
@@ -956,28 +956,28 @@ |
956 | 956 |
void *_di; |
957 | 957 |
|
958 | 958 |
public: |
959 | 959 |
/// Constructor. |
960 |
|
|
960 |
|
|
961 | 961 |
/// This constructor does not require parameters, it initiates |
962 | 962 |
/// all of the attributes to default values \c 0. |
963 | 963 |
BellmanFordWizardBase() : |
964 | 964 |
_graph(0), _length(0), _pred(0), _dist(0), _path(0), _di(0) {} |
965 | 965 |
|
966 | 966 |
/// Constructor. |
967 |
|
|
967 |
|
|
968 | 968 |
/// This constructor requires two parameters, |
969 | 969 |
/// others are initiated to \c 0. |
970 | 970 |
/// \param gr The digraph the algorithm runs on. |
971 | 971 |
/// \param len The length map. |
972 |
BellmanFordWizardBase(const GR& gr, |
|
973 |
const LEN& len) : |
|
974 |
_graph(reinterpret_cast<void*>(const_cast<GR*>(&gr))), |
|
975 |
_length(reinterpret_cast<void*>(const_cast<LEN*>(&len))), |
|
972 |
BellmanFordWizardBase(const GR& gr, |
|
973 |
const LEN& len) : |
|
974 |
_graph(reinterpret_cast<void*>(const_cast<GR*>(&gr))), |
|
975 |
_length(reinterpret_cast<void*>(const_cast<LEN*>(&len))), |
|
976 | 976 |
_pred(0), _dist(0), _path(0), _di(0) {} |
977 | 977 |
|
978 | 978 |
}; |
979 |
|
|
979 |
|
|
980 | 980 |
/// \brief Auxiliary class for the function-type interface of the |
981 | 981 |
/// \ref BellmanFord "Bellman-Ford" algorithm. |
982 | 982 |
/// |
983 | 983 |
/// This auxiliary class is created to implement the |
... | ... |
@@ -1000,9 +1000,9 @@ |
1000 | 1000 |
typedef typename Digraph::Node Node; |
1001 | 1001 |
typedef typename Digraph::NodeIt NodeIt; |
1002 | 1002 |
typedef typename Digraph::Arc Arc; |
1003 | 1003 |
typedef typename Digraph::OutArcIt ArcIt; |
1004 |
|
|
1004 |
|
|
1005 | 1005 |
typedef typename TR::LengthMap LengthMap; |
1006 | 1006 |
typedef typename LengthMap::Value Value; |
1007 | 1007 |
typedef typename TR::PredMap PredMap; |
1008 | 1008 |
typedef typename TR::DistMap DistMap; |
... | ... |
@@ -1017,23 +1017,23 @@ |
1017 | 1017 |
/// Constructor that requires parameters. |
1018 | 1018 |
/// These parameters will be the default values for the traits class. |
1019 | 1019 |
/// \param gr The digraph the algorithm runs on. |
1020 | 1020 |
/// \param len The length map. |
1021 |
BellmanFordWizard(const Digraph& gr, const LengthMap& len) |
|
1021 |
BellmanFordWizard(const Digraph& gr, const LengthMap& len) |
|
1022 | 1022 |
: TR(gr, len) {} |
1023 | 1023 |
|
1024 | 1024 |
/// \brief Copy constructor |
1025 | 1025 |
BellmanFordWizard(const TR &b) : TR(b) {} |
1026 | 1026 |
|
1027 | 1027 |
~BellmanFordWizard() {} |
1028 | 1028 |
|
1029 | 1029 |
/// \brief Runs the Bellman-Ford algorithm from the given source node. |
1030 |
/// |
|
1030 |
/// |
|
1031 | 1031 |
/// This method runs the Bellman-Ford algorithm from the given source |
1032 | 1032 |
/// node in order to compute the shortest path to each node. |
1033 | 1033 |
void run(Node s) { |
1034 |
BellmanFord<Digraph,LengthMap,TR> |
|
1035 |
bf(*reinterpret_cast<const Digraph*>(Base::_graph), |
|
1034 |
BellmanFord<Digraph,LengthMap,TR> |
|
1035 |
bf(*reinterpret_cast<const Digraph*>(Base::_graph), |
|
1036 | 1036 |
*reinterpret_cast<const LengthMap*>(Base::_length)); |
1037 | 1037 |
if (Base::_pred) bf.predMap(*reinterpret_cast<PredMap*>(Base::_pred)); |
1038 | 1038 |
if (Base::_dist) bf.distMap(*reinterpret_cast<DistMap*>(Base::_dist)); |
1039 | 1039 |
bf.run(s); |
... | ... |
@@ -1066,9 +1066,9 @@ |
1066 | 1066 |
typedef T PredMap; |
1067 | 1067 |
static PredMap *createPredMap(const Digraph &) { return 0; }; |
1068 | 1068 |
SetPredMapBase(const TR &b) : TR(b) {} |
1069 | 1069 |
}; |
1070 |
|
|
1070 |
|
|
1071 | 1071 |
/// \brief \ref named-templ-param "Named parameter" for setting |
1072 | 1072 |
/// the predecessor map. |
1073 | 1073 |
/// |
1074 | 1074 |
/// \ref named-templ-param "Named parameter" for setting |
... | ... |
@@ -1077,16 +1077,16 @@ |
1077 | 1077 |
BellmanFordWizard<SetPredMapBase<T> > predMap(const T &t) { |
1078 | 1078 |
Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t)); |
1079 | 1079 |
return BellmanFordWizard<SetPredMapBase<T> >(*this); |
1080 | 1080 |
} |
1081 |
|
|
1081 |
|
|
1082 | 1082 |
template<class T> |
1083 | 1083 |
struct SetDistMapBase : public Base { |
1084 | 1084 |
typedef T DistMap; |
1085 | 1085 |
static DistMap *createDistMap(const Digraph &) { return 0; }; |
1086 | 1086 |
SetDistMapBase(const TR &b) : TR(b) {} |
1087 | 1087 |
}; |
1088 |
|
|
1088 |
|
|
1089 | 1089 |
/// \brief \ref named-templ-param "Named parameter" for setting |
1090 | 1090 |
/// the distance map. |
1091 | 1091 |
/// |
1092 | 1092 |
/// \ref named-templ-param "Named parameter" for setting |
... | ... |
@@ -1125,20 +1125,20 @@ |
1125 | 1125 |
{ |
1126 | 1126 |
Base::_di=reinterpret_cast<void*>(const_cast<Value*>(&d)); |
1127 | 1127 |
return *this; |
1128 | 1128 |
} |
1129 |
|
|
1129 |
|
|
1130 | 1130 |
}; |
1131 |
|
|
1131 |
|
|
1132 | 1132 |
/// \brief Function type interface for the \ref BellmanFord "Bellman-Ford" |
1133 | 1133 |
/// algorithm. |
1134 | 1134 |
/// |
1135 | 1135 |
/// \ingroup shortest_path |
1136 | 1136 |
/// Function type interface for the \ref BellmanFord "Bellman-Ford" |
1137 | 1137 |
/// algorithm. |
1138 | 1138 |
/// |
1139 |
/// This function also has several \ref named-templ-func-param |
|
1140 |
/// "named parameters", they are declared as the members of class |
|
1139 |
/// This function also has several \ref named-templ-func-param |
|
1140 |
/// "named parameters", they are declared as the members of class |
|
1141 | 1141 |
/// \ref BellmanFordWizard. |
1142 | 1142 |
/// The following examples show how to use these parameters. |
1143 | 1143 |
/// \code |
1144 | 1144 |
/// // Compute shortest path from node s to each node |
... | ... |
@@ -1153,9 +1153,9 @@ |
1153 | 1153 |
/// \sa BellmanFord |
1154 | 1154 |
template<typename GR, typename LEN> |
1155 | 1155 |
BellmanFordWizard<BellmanFordWizardBase<GR,LEN> > |
1156 | 1156 |
bellmanFord(const GR& digraph, |
1157 |
|
|
1157 |
const LEN& length) |
|
1158 | 1158 |
{ |
1159 | 1159 |
return BellmanFordWizard<BellmanFordWizardBase<GR,LEN> >(digraph, length); |
1160 | 1160 |
} |
1161 | 1161 |
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-2010 |
|
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 |
... | ... |
@@ -81,9 +81,10 @@ |
81 | 81 |
|
82 | 82 |
///The type of the map that indicates which nodes are reached. |
83 | 83 |
|
84 | 84 |
///The type of the map that indicates which nodes are reached. |
85 |
///It must conform to |
|
85 |
///It must conform to |
|
86 |
///the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
86 | 87 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
87 | 88 |
///Instantiates a \c ReachedMap. |
88 | 89 |
|
89 | 90 |
///This function instantiates a \ref ReachedMap. |
... | ... |
@@ -270,9 +271,10 @@ |
270 | 271 |
///\c ReachedMap type. |
271 | 272 |
/// |
272 | 273 |
///\ref named-templ-param "Named parameter" for setting |
273 | 274 |
///\c ReachedMap type. |
274 |
///It must conform to |
|
275 |
///It must conform to |
|
276 |
///the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
275 | 277 |
template <class T> |
276 | 278 |
struct SetReachedMap : public Bfs< Digraph, SetReachedMapTraits<T> > { |
277 | 279 |
typedef Bfs< Digraph, SetReachedMapTraits<T> > Create; |
278 | 280 |
}; |
... | ... |
@@ -871,9 +873,10 @@ |
871 | 873 |
|
872 | 874 |
///The type of the map that indicates which nodes are reached. |
873 | 875 |
|
874 | 876 |
///The type of the map that indicates which nodes are reached. |
875 |
///It must conform to |
|
877 |
///It must conform to |
|
878 |
///the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
876 | 879 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
877 | 880 |
///Instantiates a ReachedMap. |
878 | 881 |
|
879 | 882 |
///This function instantiates a ReachedMap. |
... | ... |
@@ -1264,9 +1267,10 @@ |
1264 | 1267 |
|
1265 | 1268 |
/// \brief The type of the map that indicates which nodes are reached. |
1266 | 1269 |
/// |
1267 | 1270 |
/// The type of the map that indicates which nodes are reached. |
1268 |
/// It must conform to |
|
1271 |
/// It must conform to |
|
1272 |
///the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
1269 | 1273 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
1270 | 1274 |
|
1271 | 1275 |
/// \brief Instantiates a ReachedMap. |
1272 | 1276 |
/// |
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-2010 |
|
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 |
... | ... |
@@ -257,9 +257,9 @@ |
257 | 257 |
void decrease (Item item, const Prio& value) { |
258 | 258 |
int i=_iim[item]; |
259 | 259 |
int p=_data[i].parent; |
260 | 260 |
_data[i].prio=value; |
261 |
|
|
261 |
|
|
262 | 262 |
while( p!=-1 && _comp(value, _data[p].prio) ) { |
263 | 263 |
_data[i].name=_data[p].name; |
264 | 264 |
_data[i].prio=_data[p].prio; |
265 | 265 |
_data[p].name=item; |
... | ... |
@@ -321,9 +321,9 @@ |
321 | 321 |
} |
322 | 322 |
} |
323 | 323 |
|
324 | 324 |
private: |
325 |
|
|
325 |
|
|
326 | 326 |
// Find the minimum of the roots |
327 | 327 |
int findMin() { |
328 | 328 |
if( _head!=-1 ) { |
329 | 329 |
int min_loc=_head, min_val=_data[_head].prio; |
... | ... |
@@ -349,9 +349,9 @@ |
349 | 349 |
} else { |
350 | 350 |
interleave(a); |
351 | 351 |
} |
352 | 352 |
if( _data[_head].right_neighbor==-1 ) return; |
353 |
|
|
353 |
|
|
354 | 354 |
int x=_head; |
355 | 355 |
int x_prev=-1, x_next=_data[x].right_neighbor; |
356 | 356 |
while( x_next!=-1 ) { |
357 | 357 |
if( _data[x].degree!=_data[x_next].degree || |
... | ... |
@@ -383,9 +383,9 @@ |
383 | 383 |
void interleave(int a) { |
384 | 384 |
int p=_head, q=a; |
385 | 385 |
int curr=_data.size(); |
386 | 386 |
_data.push_back(Store()); |
387 |
|
|
387 |
|
|
388 | 388 |
while( p!=-1 || q!=-1 ) { |
389 | 389 |
if( q==-1 || ( p!=-1 && _data[p].degree<_data[q].degree ) ) { |
390 | 390 |
_data[curr].right_neighbor=p; |
391 | 391 |
curr=p; |
... | ... |
@@ -396,9 +396,9 @@ |
396 | 396 |
curr=q; |
397 | 397 |
q=_data[q].right_neighbor; |
398 | 398 |
} |
399 | 399 |
} |
400 |
|
|
400 |
|
|
401 | 401 |
_head=_data.back().right_neighbor; |
402 | 402 |
_data.pop_back(); |
403 | 403 |
} |
404 | 404 |
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-2010 |
|
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 |
... | ... |
@@ -69,9 +69,9 @@ |
69 | 69 |
// The notifier type. |
70 | 70 |
typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier Notifier; |
71 | 71 |
|
72 | 72 |
private: |
73 |
|
|
73 |
|
|
74 | 74 |
// The MapBase of the Map which imlements the core regisitry function. |
75 | 75 |
typedef typename Notifier::ObserverBase Parent; |
76 | 76 |
|
77 | 77 |
typedef std::allocator<Value> Allocator; |
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-2010 |
|
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 |
... | ... |
@@ -156,9 +156,9 @@ |
156 | 156 |
typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent; |
157 | 157 |
|
158 | 158 |
public: |
159 | 159 |
typedef DefaultMap<_Graph, _Item, _Value> Map; |
160 |
|
|
160 |
|
|
161 | 161 |
typedef typename Parent::GraphType GraphType; |
162 | 162 |
typedef typename Parent::Value Value; |
163 | 163 |
|
164 | 164 |
explicit DefaultMap(const GraphType& graph) : Parent(graph) {} |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 |
* Copyright (C) 2003- |
|
5 |
* Copyright (C) 2003-2010 |
|
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 |
... | ... |
@@ -62,13 +62,13 @@ |
62 | 62 |
} |
63 | 63 |
|
64 | 64 |
Node oppositeNode(const Node &n, const Arc &e) const { |
65 | 65 |
if (n == Parent::source(e)) |
66 |
|
|
66 |
return Parent::target(e); |
|
67 | 67 |
else if(n==Parent::target(e)) |
68 |
|
|
68 |
return Parent::source(e); |
|
69 | 69 |
else |
70 |
|
|
70 |
return INVALID; |
|
71 | 71 |
} |
72 | 72 |
|
73 | 73 |
|
74 | 74 |
// Alteration notifier extensions |
... | ... |
@@ -90,97 +90,97 @@ |
90 | 90 |
} |
91 | 91 |
|
92 | 92 |
// Iterable extensions |
93 | 93 |
|
94 |
class NodeIt : public Node { |
|
94 |
class NodeIt : public Node { |
|
95 | 95 |
const Digraph* digraph; |
96 | 96 |
public: |
97 | 97 |
|
98 | 98 |
NodeIt() {} |
99 | 99 |
|
100 | 100 |
NodeIt(Invalid i) : Node(i) { } |
101 | 101 |
|
102 | 102 |
explicit NodeIt(const Digraph& _graph) : digraph(&_graph) { |
103 |
|
|
103 |
_graph.first(static_cast<Node&>(*this)); |
|
104 | 104 |
} |
105 | 105 |
|
106 |
NodeIt(const Digraph& _graph, const Node& node) |
|
107 |
: Node(node), digraph(&_graph) {} |
|
106 |
NodeIt(const Digraph& _graph, const Node& node) |
|
107 |
: Node(node), digraph(&_graph) {} |
|
108 | 108 |
|
109 |
NodeIt& operator++() { |
|
110 |
digraph->next(*this); |
|
111 |
|
|
109 |
NodeIt& operator++() { |
|
110 |
digraph->next(*this); |
|
111 |
return *this; |
|
112 | 112 |
} |
113 | 113 |
|
114 | 114 |
}; |
115 | 115 |
|
116 | 116 |
|
117 |
class ArcIt : public Arc { |
|
117 |
class ArcIt : public Arc { |
|
118 | 118 |
const Digraph* digraph; |
119 | 119 |
public: |
120 | 120 |
|
121 | 121 |
ArcIt() { } |
122 | 122 |
|
123 | 123 |
ArcIt(Invalid i) : Arc(i) { } |
124 | 124 |
|
125 | 125 |
explicit ArcIt(const Digraph& _graph) : digraph(&_graph) { |
126 |
|
|
126 |
_graph.first(static_cast<Arc&>(*this)); |
|
127 | 127 |
} |
128 | 128 |
|
129 |
ArcIt(const Digraph& _graph, const Arc& e) : |
|
130 |
Arc(e), digraph(&_graph) { } |
|
129 |
ArcIt(const Digraph& _graph, const Arc& e) : |
|
130 |
Arc(e), digraph(&_graph) { } |
|
131 | 131 |
|
132 |
ArcIt& operator++() { |
|
133 |
digraph->next(*this); |
|
134 |
|
|
132 |
ArcIt& operator++() { |
|
133 |
digraph->next(*this); |
|
134 |
return *this; |
|
135 | 135 |
} |
136 | 136 |
|
137 | 137 |
}; |
138 | 138 |
|
139 | 139 |
|
140 |
class OutArcIt : public Arc { |
|
140 |
class OutArcIt : public Arc { |
|
141 | 141 |
const Digraph* digraph; |
142 | 142 |
public: |
143 | 143 |
|
144 | 144 |
OutArcIt() { } |
145 | 145 |
|
146 | 146 |
OutArcIt(Invalid i) : Arc(i) { } |
147 | 147 |
|
148 |
OutArcIt(const Digraph& _graph, const Node& node) |
|
149 |
: digraph(&_graph) { |
|
150 |
|
|
148 |
OutArcIt(const Digraph& _graph, const Node& node) |
|
149 |
: digraph(&_graph) { |
|
150 |
_graph.firstOut(*this, node); |
|
151 | 151 |
} |
152 | 152 |
|
153 |
OutArcIt(const Digraph& _graph, const Arc& arc) |
|
154 |
: Arc(arc), digraph(&_graph) {} |
|
153 |
OutArcIt(const Digraph& _graph, const Arc& arc) |
|
154 |
: Arc(arc), digraph(&_graph) {} |
|
155 | 155 |
|
156 |
OutArcIt& operator++() { |
|
157 |
digraph->nextOut(*this); |
|
158 |
|
|
156 |
OutArcIt& operator++() { |
|
157 |
digraph->nextOut(*this); |
|
158 |
return *this; |
|
159 | 159 |
} |
160 | 160 |
|
161 | 161 |
}; |
162 | 162 |
|
163 | 163 |
|
164 |
class InArcIt : public Arc { |
|
164 |
class InArcIt : public Arc { |
|
165 | 165 |
const Digraph* digraph; |
166 | 166 |
public: |
167 | 167 |
|
168 | 168 |
InArcIt() { } |
169 | 169 |
|
170 | 170 |
InArcIt(Invalid i) : Arc(i) { } |
171 | 171 |
|
172 |
InArcIt(const Digraph& _graph, const Node& node) |
|
173 |
: digraph(&_graph) { |
|
174 |
|
|
172 |
InArcIt(const Digraph& _graph, const Node& node) |
|
173 |
: digraph(&_graph) { |
|
174 |
_graph.firstIn(*this, node); |
|
175 | 175 |
} |
176 | 176 |
|
177 |
InArcIt(const Digraph& _graph, const Arc& arc) : |
|
178 |
Arc(arc), digraph(&_graph) {} |
|
177 |
InArcIt(const Digraph& _graph, const Arc& arc) : |
|
178 |
Arc(arc), digraph(&_graph) {} |
|
179 | 179 |
|
180 |
InArcIt& operator++() { |
|
181 |
digraph->nextIn(*this); |
|
182 |
|
|
180 |
InArcIt& operator++() { |
|
181 |
digraph->nextIn(*this); |
|
182 |
return *this; |
|
183 | 183 |
} |
184 | 184 |
|
185 | 185 |
}; |
186 | 186 |
|
... | ... |
@@ -214,28 +214,28 @@ |
214 | 214 |
|
215 | 215 |
using Parent::first; |
216 | 216 |
|
217 | 217 |
// Mappable extension |
218 |
|
|
218 |
|
|
219 | 219 |
template <typename _Value> |
220 |
class ArcMap |
|
220 |
class ArcMap |
|
221 | 221 |
: public MapExtender<DefaultMap<Digraph, Arc, _Value> > { |
222 | 222 |
typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent; |
223 | 223 |
|
224 | 224 |
public: |
225 |
explicit ArcMap(const Digraph& _g) |
|
226 |
: Parent(_g) {} |
|
227 |
ArcMap(const Digraph& _g, const _Value& _v) |
|
228 |
: Parent(_g, _v) {} |
|
225 |
explicit ArcMap(const Digraph& _g) |
|
226 |
: Parent(_g) {} |
|
227 |
ArcMap(const Digraph& _g, const _Value& _v) |
|
228 |
: Parent(_g, _v) {} |
|
229 | 229 |
|
230 | 230 |
ArcMap& operator=(const ArcMap& cmap) { |
231 |
|
|
231 |
return operator=<ArcMap>(cmap); |
|
232 | 232 |
} |
233 | 233 |
|
234 | 234 |
template <typename CMap> |
235 | 235 |
ArcMap& operator=(const CMap& cmap) { |
236 | 236 |
Parent::operator=(cmap); |
237 |
|
|
237 |
return *this; |
|
238 | 238 |
} |
239 | 239 |
|
240 | 240 |
}; |
241 | 241 |
|
... | ... |
@@ -246,9 +246,9 @@ |
246 | 246 |
Arc arc = Parent::addArc(from, to); |
247 | 247 |
notifier(Arc()).add(arc); |
248 | 248 |
return arc; |
249 | 249 |
} |
250 |
|
|
250 |
|
|
251 | 251 |
void clear() { |
252 | 252 |
notifier(Arc()).clear(); |
253 | 253 |
Parent::clear(); |
254 | 254 |
} |
... | ... |
@@ -309,13 +309,13 @@ |
309 | 309 |
} |
310 | 310 |
|
311 | 311 |
Node oppositeNode(const Node &n, const Edge &e) const { |
312 | 312 |
if( n == Parent::u(e)) |
313 |
|
|
313 |
return Parent::v(e); |
|
314 | 314 |
else if( n == Parent::v(e)) |
315 |
|
|
315 |
return Parent::u(e); |
|
316 | 316 |
else |
317 |
|
|
317 |
return INVALID; |
|
318 | 318 |
} |
319 | 319 |
|
320 | 320 |
Arc oppositeArc(const Arc &e) const { |
321 | 321 |
return Parent::direct(e, !Parent::direction(e)); |
... | ... |
@@ -337,9 +337,9 @@ |
337 | 337 |
|
338 | 338 |
public: |
339 | 339 |
|
340 | 340 |
using Parent::notifier; |
341 |
|
|
341 |
|
|
342 | 342 |
ArcNotifier& notifier(Arc) const { |
343 | 343 |
return arc_notifier; |
344 | 344 |
} |
345 | 345 |
|
... | ... |
@@ -347,120 +347,120 @@ |
347 | 347 |
return edge_notifier; |
348 | 348 |
} |
349 | 349 |
|
350 | 350 |
|
351 |
class NodeIt : public Node { |
|
351 |
class NodeIt : public Node { |
|
352 | 352 |
const Graph* graph; |
353 | 353 |
public: |
354 | 354 |
|
355 | 355 |
NodeIt() {} |
356 | 356 |
|
357 | 357 |
NodeIt(Invalid i) : Node(i) { } |
358 | 358 |
|
359 | 359 |
explicit NodeIt(const Graph& _graph) : graph(&_graph) { |
360 |
|
|
360 |
_graph.first(static_cast<Node&>(*this)); |
|
361 | 361 |
} |
362 | 362 |
|
363 |
NodeIt(const Graph& _graph, const Node& node) |
|
364 |
: Node(node), graph(&_graph) {} |
|
363 |
NodeIt(const Graph& _graph, const Node& node) |
|
364 |
: Node(node), graph(&_graph) {} |
|
365 | 365 |
|
366 |
NodeIt& operator++() { |
|
367 |
graph->next(*this); |
|
368 |
|
|
366 |
NodeIt& operator++() { |
|
367 |
graph->next(*this); |
|
368 |
return *this; |
|
369 | 369 |
} |
370 | 370 |
|
371 | 371 |
}; |
372 | 372 |
|
373 | 373 |
|
374 |
class ArcIt : public Arc { |
|
374 |
class ArcIt : public Arc { |
|
375 | 375 |
const Graph* graph; |
376 | 376 |
public: |
377 | 377 |
|
378 | 378 |
ArcIt() { } |
379 | 379 |
|
380 | 380 |
ArcIt(Invalid i) : Arc(i) { } |
381 | 381 |
|
382 | 382 |
explicit ArcIt(const Graph& _graph) : graph(&_graph) { |
383 |
|
|
383 |
_graph.first(static_cast<Arc&>(*this)); |
|
384 | 384 |
} |
385 | 385 |
|
386 |
ArcIt(const Graph& _graph, const Arc& e) : |
|
387 |
Arc(e), graph(&_graph) { } |
|
386 |
ArcIt(const Graph& _graph, const Arc& e) : |
|
387 |
Arc(e), graph(&_graph) { } |
|
388 | 388 |
|
389 |
ArcIt& operator++() { |
|
390 |
graph->next(*this); |
|
391 |
|
|
389 |
ArcIt& operator++() { |
|
390 |
graph->next(*this); |
|
391 |
return *this; |
|
392 | 392 |
} |
393 | 393 |
|
394 | 394 |
}; |
395 | 395 |
|
396 | 396 |
|
397 |
class OutArcIt : public Arc { |
|
397 |
class OutArcIt : public Arc { |
|
398 | 398 |
const Graph* graph; |
399 | 399 |
public: |
400 | 400 |
|
401 | 401 |
OutArcIt() { } |
402 | 402 |
|
403 | 403 |
OutArcIt(Invalid i) : Arc(i) { } |
404 | 404 |
|
405 |
OutArcIt(const Graph& _graph, const Node& node) |
|
406 |
: graph(&_graph) { |
|
407 |
|
|
405 |
OutArcIt(const Graph& _graph, const Node& node) |
|
406 |
: graph(&_graph) { |
|
407 |
_graph.firstOut(*this, node); |
|
408 | 408 |
} |
409 | 409 |
|
410 |
OutArcIt(const Graph& _graph, const Arc& arc) |
|
411 |
: Arc(arc), graph(&_graph) {} |
|
410 |
OutArcIt(const Graph& _graph, const Arc& arc) |
|
411 |
: Arc(arc), graph(&_graph) {} |
|
412 | 412 |
|
413 |
OutArcIt& operator++() { |
|
414 |
graph->nextOut(*this); |
|
415 |
|
|
413 |
OutArcIt& operator++() { |
|
414 |
graph->nextOut(*this); |
|
415 |
return *this; |
|
416 | 416 |
} |
417 | 417 |
|
418 | 418 |
}; |
419 | 419 |
|
420 | 420 |
|
421 |
class InArcIt : public Arc { |
|
421 |
class InArcIt : public Arc { |
|
422 | 422 |
const Graph* graph; |
423 | 423 |
public: |
424 | 424 |
|
425 | 425 |
InArcIt() { } |
426 | 426 |
|
427 | 427 |
InArcIt(Invalid i) : Arc(i) { } |
428 | 428 |
|
429 |
InArcIt(const Graph& _graph, const Node& node) |
|
430 |
: graph(&_graph) { |
|
431 |
|
|
429 |
InArcIt(const Graph& _graph, const Node& node) |
|
430 |
: graph(&_graph) { |
|
431 |
_graph.firstIn(*this, node); |
|
432 | 432 |
} |
433 | 433 |
|
434 |
InArcIt(const Graph& _graph, const Arc& arc) : |
|
435 |
Arc(arc), graph(&_graph) {} |
|
434 |
InArcIt(const Graph& _graph, const Arc& arc) : |
|
435 |
Arc(arc), graph(&_graph) {} |
|
436 | 436 |
|
437 |
InArcIt& operator++() { |
|
438 |
graph->nextIn(*this); |
|
439 |
|
|
437 |
InArcIt& operator++() { |
|
438 |
graph->nextIn(*this); |
|
439 |
return *this; |
|
440 | 440 |
} |
441 | 441 |
|
442 | 442 |
}; |
443 | 443 |
|
444 | 444 |
|
445 |
class EdgeIt : public Parent::Edge { |
|
445 |
class EdgeIt : public Parent::Edge { |
|
446 | 446 |
const Graph* graph; |
447 | 447 |
public: |
448 | 448 |
|
449 | 449 |
EdgeIt() { } |
450 | 450 |
|
451 | 451 |
EdgeIt(Invalid i) : Edge(i) { } |
452 | 452 |
|
453 | 453 |
explicit EdgeIt(const Graph& _graph) : graph(&_graph) { |
454 |
|
|
454 |
_graph.first(static_cast<Edge&>(*this)); |
|
455 | 455 |
} |
456 | 456 |
|
457 |
EdgeIt(const Graph& _graph, const Edge& e) : |
|
458 |
Edge(e), graph(&_graph) { } |
|
457 |
EdgeIt(const Graph& _graph, const Edge& e) : |
|
458 |
Edge(e), graph(&_graph) { } |
|
459 | 459 |
|
460 |
EdgeIt& operator++() { |
|
461 |
graph->next(*this); |
|
462 |
|
|
460 |
EdgeIt& operator++() { |
|
461 |
graph->next(*this); |
|
462 |
return *this; |
|
463 | 463 |
} |
464 | 464 |
|
465 | 465 |
}; |
466 | 466 |
|
... | ... |
@@ -474,19 +474,19 @@ |
474 | 474 |
|
475 | 475 |
IncEdgeIt(Invalid i) : Edge(i), direction(false) { } |
476 | 476 |
|
477 | 477 |
IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) { |
478 |
|
|
478 |
_graph.firstInc(*this, direction, n); |
|
479 | 479 |
} |
480 | 480 |
|
481 | 481 |
IncEdgeIt(const Graph& _graph, const Edge &ue, const Node &n) |
482 |
: graph(&_graph), Edge(ue) { |
|
483 |
direction = (_graph.source(ue) == n); |
|
482 |
: graph(&_graph), Edge(ue) { |
|
483 |
direction = (_graph.source(ue) == n); |
|
484 | 484 |
} |
485 | 485 |
|
486 | 486 |
IncEdgeIt& operator++() { |
487 |
graph->nextInc(*this, direction); |
|
488 |
return *this; |
|
487 |
graph->nextInc(*this, direction); |
|
488 |
return *this; |
|
489 | 489 |
} |
490 | 490 |
}; |
491 | 491 |
|
492 | 492 |
// \brief Base node of the iterator |
... | ... |
@@ -531,51 +531,51 @@ |
531 | 531 |
} |
532 | 532 |
|
533 | 533 |
|
534 | 534 |
template <typename _Value> |
535 |
class ArcMap |
|
535 |
class ArcMap |
|
536 | 536 |
: public MapExtender<DefaultMap<Graph, Arc, _Value> > { |
537 | 537 |
typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent; |
538 | 538 |
|
539 | 539 |
public: |
540 |
explicit ArcMap(const Graph& _g) |
|
541 |
: Parent(_g) {} |
|
542 |
ArcMap(const Graph& _g, const _Value& _v) |
|
543 |
: Parent(_g, _v) {} |
|
540 |
explicit ArcMap(const Graph& _g) |
|
541 |
: Parent(_g) {} |
|
542 |
ArcMap(const Graph& _g, const _Value& _v) |
|
543 |
: Parent(_g, _v) {} |
|
544 | 544 |
|
545 | 545 |
ArcMap& operator=(const ArcMap& cmap) { |
546 |
|
|
546 |
return operator=<ArcMap>(cmap); |
|
547 | 547 |
} |
548 | 548 |
|
549 | 549 |
template <typename CMap> |
550 | 550 |
ArcMap& operator=(const CMap& cmap) { |
551 | 551 |
Parent::operator=(cmap); |
552 |
|
|
552 |
return *this; |
|
553 | 553 |
} |
554 | 554 |
|
555 | 555 |
}; |
556 | 556 |
|
557 | 557 |
|
558 | 558 |
template <typename _Value> |
559 |
class EdgeMap |
|
559 |
class EdgeMap |
|
560 | 560 |
: public MapExtender<DefaultMap<Graph, Edge, _Value> > { |
561 | 561 |
typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent; |
562 | 562 |
|
563 | 563 |
public: |
564 |
explicit EdgeMap(const Graph& _g) |
|
565 |
: Parent(_g) {} |
|
564 |
explicit EdgeMap(const Graph& _g) |
|
565 |
: Parent(_g) {} |
|
566 | 566 |
|
567 |
EdgeMap(const Graph& _g, const _Value& _v) |
|
568 |
: Parent(_g, _v) {} |
|
567 |
EdgeMap(const Graph& _g, const _Value& _v) |
|
568 |
: Parent(_g, _v) {} |
|
569 | 569 |
|
570 | 570 |
EdgeMap& operator=(const EdgeMap& cmap) { |
571 |
|
|
571 |
return operator=<EdgeMap>(cmap); |
|
572 | 572 |
} |
573 | 573 |
|
574 | 574 |
template <typename CMap> |
575 | 575 |
EdgeMap& operator=(const CMap& cmap) { |
576 | 576 |
Parent::operator=(cmap); |
577 |
|
|
577 |
return *this; |
|
578 | 578 |
} |
579 | 579 |
|
580 | 580 |
}; |
581 | 581 |
|
... | ... |
@@ -590,9 +590,9 @@ |
590 | 590 |
arcs.push_back(Parent::direct(edge, false)); |
591 | 591 |
notifier(Arc()).add(arcs); |
592 | 592 |
return edge; |
593 | 593 |
} |
594 |
|
|
594 |
|
|
595 | 595 |
void clear() { |
596 | 596 |
notifier(Arc()).clear(); |
597 | 597 |
notifier(Edge()).clear(); |
598 | 598 |
Parent::clear(); |
... | ... |
@@ -616,9 +616,9 @@ |
616 | 616 |
~EdgeSetExtender() { |
617 | 617 |
edge_notifier.clear(); |
618 | 618 |
arc_notifier.clear(); |
619 | 619 |
} |
620 |
|
|
620 |
|
|
621 | 621 |
}; |
622 | 622 |
|
623 | 623 |
} |
624 | 624 |
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-2010 |
|
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 |
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-2010 |
|
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 |
... | ... |
@@ -95,9 +95,9 @@ |
95 | 95 |
#ifdef WIN32 |
96 | 96 |
SYSTEMTIME time; |
97 | 97 |
GetSystemTime(&time); |
98 | 98 |
char buf1[11], buf2[9], buf3[5]; |
99 |
|
|
99 |
if (GetDateFormat(MY_LOCALE, 0, &time, |
|
100 | 100 |
("ddd MMM dd"), buf1, 11) && |
101 | 101 |
GetTimeFormat(MY_LOCALE, 0, &time, |
102 | 102 |
("HH':'mm':'ss"), buf2, 9) && |
103 | 103 |
GetDateFormat(MY_LOCALE, 0, &time, |
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-2010 |
|
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 |
... | ... |
@@ -383,9 +383,9 @@ |
383 | 383 |
/// only for the item having minimum priority and it does not support |
384 | 384 |
/// key increasing and decreasing. |
385 | 385 |
/// |
386 | 386 |
/// Note that this implementation does not conform to the |
387 |
/// \ref concepts::Heap "heap concept" due to the lack of some |
|
387 |
/// \ref concepts::Heap "heap concept" due to the lack of some |
|
388 | 388 |
/// functionality. |
389 | 389 |
/// |
390 | 390 |
/// \tparam IM A read-writable item map with \c int values, used |
391 | 391 |
/// internally to handle the cross references. |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 |
* Copyright (C) 2003- |
|
5 |
* Copyright (C) 2003-2010 |
|
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 |
... | ... |
@@ -132,9 +132,9 @@ |
132 | 132 |
/// over the feasible flows, but this algroithm cannot handle |
133 | 133 |
/// these cases. |
134 | 134 |
UNBOUNDED |
135 | 135 |
}; |
136 |
|
|
136 |
|
|
137 | 137 |
private: |
138 | 138 |
|
139 | 139 |
TEMPLATE_DIGRAPH_TYPEDEFS(GR); |
140 | 140 |
|
... | ... |
@@ -183,9 +183,9 @@ |
183 | 183 |
int _factor; |
184 | 184 |
IntVector _pred; |
185 | 185 |
|
186 | 186 |
public: |
187 |
|
|
187 |
|
|
188 | 188 |
/// \brief Constant for infinite upper bounds (capacities). |
189 | 189 |
/// |
190 | 190 |
/// Constant for infinite upper bounds (capacities). |
191 | 191 |
/// It is \c std::numeric_limits<Value>::infinity() if available, |
... | ... |
@@ -210,12 +210,12 @@ |
210 | 210 |
const ValueVector &_res_cap; |
211 | 211 |
const ValueVector &_excess; |
212 | 212 |
CostVector &_pi; |
213 | 213 |
IntVector &_pred; |
214 |
|
|
214 |
|
|
215 | 215 |
IntVector _proc_nodes; |
216 | 216 |
CostVector _dist; |
217 |
|
|
217 |
|
|
218 | 218 |
public: |
219 | 219 |
|
220 | 220 |
ResidualDijkstra(CapacityScaling& cs) : |
221 | 221 |
_node_num(cs._node_num), _geq(cs._sum_supply < 0), |
... | ... |
@@ -438,9 +438,9 @@ |
438 | 438 |
_supply[_node_id[s]] = k; |
439 | 439 |
_supply[_node_id[t]] = -k; |
440 | 440 |
return *this; |
441 | 441 |
} |
442 |
|
|
442 |
|
|
443 | 443 |
/// @} |
444 | 444 |
|
445 | 445 |
/// \name Execution control |
446 | 446 |
/// The algorithm can be executed using \ref run(). |
... | ... |
@@ -574,9 +574,9 @@ |
574 | 574 |
_lower.resize(_res_arc_num); |
575 | 575 |
_upper.resize(_res_arc_num); |
576 | 576 |
_cost.resize(_res_arc_num); |
577 | 577 |
_supply.resize(_node_num); |
578 |
|
|
578 |
|
|
579 | 579 |
_res_cap.resize(_res_arc_num); |
580 | 580 |
_pi.resize(_node_num); |
581 | 581 |
_excess.resize(_node_num); |
582 | 582 |
_pred.resize(_node_num); |
... | ... |
@@ -618,9 +618,9 @@ |
618 | 618 |
int bi = _arc_idb[a]; |
619 | 619 |
_reverse[fi] = bi; |
620 | 620 |
_reverse[bi] = fi; |
621 | 621 |
} |
622 |
|
|
622 |
|
|
623 | 623 |
// Reset parameters |
624 | 624 |
resetParams(); |
625 | 625 |
return *this; |
626 | 626 |
} |
... | ... |
@@ -727,9 +727,9 @@ |
727 | 727 |
for (int i = 0; i != _root; ++i) { |
728 | 728 |
_sum_supply += _supply[i]; |
729 | 729 |
} |
730 | 730 |
if (_sum_supply > 0) return INFEASIBLE; |
731 |
|
|
731 |
|
|
732 | 732 |
// Initialize vectors |
733 | 733 |
for (int i = 0; i != _root; ++i) { |
734 | 734 |
_pi[i] = 0; |
735 | 735 |
_excess[i] = _supply[i]; |
... | ... |
@@ -775,9 +775,9 @@ |
775 | 775 |
_res_cap[_reverse[j]] += rc; |
776 | 776 |
} |
777 | 777 |
} |
778 | 778 |
} |
779 |
|
|
779 |
|
|
780 | 780 |
// Handle GEQ supply type |
781 | 781 |
if (_sum_supply < 0) { |
782 | 782 |
_pi[_root] = 0; |
783 | 783 |
_excess[_root] = -_sum_supply; |
... | ... |
@@ -843,11 +843,11 @@ |
843 | 843 |
Cost pr = _pi[_root]; |
844 | 844 |
if (_sum_supply < 0 || pr > 0) { |
845 | 845 |
for (int i = 0; i != _node_num; ++i) { |
846 | 846 |
_pi[i] -= pr; |
847 |
} |
|
847 |
} |
|
848 | 848 |
} |
849 |
|
|
849 |
|
|
850 | 850 |
return pt; |
851 | 851 |
} |
852 | 852 |
|
853 | 853 |
// Execute the capacity scaling algorithm |
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-2010 |
|
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 |
... | ... |
@@ -120,9 +120,9 @@ |
120 | 120 |
void _applyMessageLevel(); |
121 | 121 |
|
122 | 122 |
int _message_level; |
123 | 123 |
|
124 |
|
|
124 |
|
|
125 | 125 |
|
126 | 126 |
}; |
127 | 127 |
|
128 | 128 |
} |
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-2010 |
|
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 |
... | ... |
@@ -58,10 +58,10 @@ |
58 | 58 |
typedef UM UpperMap; |
59 | 59 |
|
60 | 60 |
/// \brief The type of supply map. |
61 | 61 |
/// |
62 |
/// The type of the map that stores the signed supply values of the |
|
63 |
/// nodes. |
|
62 |
/// The type of the map that stores the signed supply values of the |
|
63 |
/// nodes. |
|
64 | 64 |
/// It must conform to the \ref concepts::ReadMap "ReadMap" concept. |
65 | 65 |
typedef SM SupplyMap; |
66 | 66 |
|
67 | 67 |
/// \brief The type of the flow and supply values. |
... | ... |
@@ -140,9 +140,9 @@ |
140 | 140 |
|
141 | 141 |
\f[ \sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) |
142 | 142 |
\geq sup(u) \quad \forall u\in V, \f] |
143 | 143 |
\f[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A. \f] |
144 |
|
|
144 |
|
|
145 | 145 |
The sum of the supply values, i.e. \f$\sum_{u\in V} sup(u)\f$ must be |
146 | 146 |
zero or negative in order to have a feasible solution (since the sum |
147 | 147 |
of the expressions on the left-hand side of the inequalities is zero). |
148 | 148 |
It means that the total demand must be greater or equal to the total |
... | ... |
@@ -150,9 +150,9 @@ |
150 | 150 |
but there could be demands that are not satisfied. |
151 | 151 |
If \f$\sum_{u\in V} sup(u)\f$ is zero, then all the supply/demand |
152 | 152 |
constraints have to be satisfied with equality, i.e. all demands |
153 | 153 |
have to be satisfied and all supplies have to be used. |
154 |
|
|
154 |
|
|
155 | 155 |
If you need the opposite inequalities in the supply/demand constraints |
156 | 156 |
(i.e. the total demand is less than the total supply and all the demands |
157 | 157 |
have to be satisfied while there could be supplies that are not used), |
158 | 158 |
then you could easily transform the problem to the above form by reversing |
... | ... |
@@ -336,9 +336,9 @@ |
336 | 336 |
/// The constructor of the class. |
337 | 337 |
/// |
338 | 338 |
/// \param graph The digraph the algorithm runs on. |
339 | 339 |
/// \param lower The lower bounds for the flow values on the arcs. |
340 |
/// \param upper The upper bounds (capacities) for the flow values |
|
340 |
/// \param upper The upper bounds (capacities) for the flow values |
|
341 | 341 |
/// on the arcs. |
342 | 342 |
/// \param supply The signed supply values of the nodes. |
343 | 343 |
Circulation(const Digraph &graph, const LowerMap &lower, |
344 | 344 |
const UpperMap &upper, const SupplyMap &supply) |
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-2010 |
|
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 |
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-2010 |
|
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 |
... | ... |
@@ -137,9 +137,9 @@ |
137 | 137 |
|
138 | 138 |
virtual void _clear(); |
139 | 139 |
|
140 | 140 |
virtual void _messageLevel(MessageLevel); |
141 |
|
|
141 |
|
|
142 | 142 |
public: |
143 | 143 |
|
144 | 144 |
///Solves LP with primal simplex method. |
145 | 145 |
SolveExitStatus solvePrimal(); |
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-2010 |
|
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 |
... | ... |
@@ -433,9 +433,9 @@ |
433 | 433 |
NodeMap(const Digraph&, T) { } |
434 | 434 |
|
435 | 435 |
private: |
436 | 436 |
///Copy constructor |
437 |
NodeMap(const NodeMap& nm) : |
|
437 |
NodeMap(const NodeMap& nm) : |
|
438 | 438 |
ReferenceMap<Node, T, T&, const T&>(nm) { } |
439 | 439 |
///Assignment operator |
440 | 440 |
template <typename CMap> |
441 | 441 |
NodeMap& operator=(const CMap&) { |
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-2010 |
|
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 |
... | ... |
@@ -42,9 +42,9 @@ |
42 | 42 |
/// without any sensible implementation. So any general algorithm for |
43 | 43 |
/// undirected graphs should compile with this class, but it will not |
44 | 44 |
/// run properly, of course. |
45 | 45 |
/// An actual graph implementation like \ref ListGraph or |
46 |
/// \ref SmartGraph may have additional functionality. |
|
46 |
/// \ref SmartGraph may have additional functionality. |
|
47 | 47 |
/// |
48 | 48 |
/// The undirected graphs also fulfill the concept of \ref Digraph |
49 | 49 |
/// "directed graphs", since each edge can also be regarded as two |
50 | 50 |
/// oppositely directed arcs. |
... | ... |
@@ -84,9 +84,9 @@ |
84 | 84 |
|
85 | 85 |
/// \brief Undirected graphs should be tagged with \c UndirectedTag. |
86 | 86 |
/// |
87 | 87 |
/// Undirected graphs should be tagged with \c UndirectedTag. |
88 |
/// |
|
88 |
/// |
|
89 | 89 |
/// This tag helps the \c enable_if technics to make compile time |
90 | 90 |
/// specializations for undirected graphs. |
91 | 91 |
typedef True UndirectedTag; |
92 | 92 |
|
... | ... |
@@ -359,9 +359,9 @@ |
359 | 359 |
/// ordering of the arcs. |
360 | 360 |
bool operator<(Arc) const { return false; } |
361 | 361 |
|
362 | 362 |
/// Converison to \c Edge |
363 |
|
|
363 |
|
|
364 | 364 |
/// Converison to \c Edge. |
365 | 365 |
/// |
366 | 366 |
operator Edge() const { return Edge(); } |
367 | 367 |
}; |
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-2010 |
|
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 |
... | ... |
@@ -37,9 +37,9 @@ |
37 | 37 |
/// subtypes of digraph and graph types. |
38 | 38 |
/// |
39 | 39 |
/// \note This class is a template class so that we can use it to |
40 | 40 |
/// create graph skeleton classes. The reason for this is that \c Node |
41 |
/// and \c Arc (or \c Edge) types should \e not derive from the same |
|
41 |
/// and \c Arc (or \c Edge) types should \e not derive from the same |
|
42 | 42 |
/// base class. For \c Node you should instantiate it with character |
43 | 43 |
/// \c 'n', for \c Arc with \c 'a' and for \c Edge with \c 'e'. |
44 | 44 |
#ifndef DOXYGEN |
45 | 45 |
template <char sel = '0'> |
... | ... |
@@ -88,9 +88,9 @@ |
88 | 88 |
|
89 | 89 |
/// \brief Ordering operator. |
90 | 90 |
/// |
91 | 91 |
/// This operator defines an ordering of the items. |
92 |
/// It makes possible to use graph item types as key types in |
|
92 |
/// It makes possible to use graph item types as key types in |
|
93 | 93 |
/// associative containers (e.g. \c std::map). |
94 | 94 |
/// |
95 | 95 |
/// \note This operator only has to define some strict ordering of |
96 | 96 |
/// the items; this order has nothing to do with the iteration |
... | ... |
@@ -121,9 +121,9 @@ |
121 | 121 |
/// \brief Base skeleton class for directed graphs. |
122 | 122 |
/// |
123 | 123 |
/// This class describes the base interface of directed graph types. |
124 | 124 |
/// All digraph %concepts have to conform to this class. |
125 |
/// It just provides types for nodes and arcs and functions |
|
125 |
/// It just provides types for nodes and arcs and functions |
|
126 | 126 |
/// to get the source and the target nodes of arcs. |
127 | 127 |
class BaseDigraphComponent { |
128 | 128 |
public: |
129 | 129 |
|
... | ... |
@@ -425,9 +425,9 @@ |
425 | 425 |
}; |
426 | 426 |
|
427 | 427 |
/// \brief Concept class for \c NodeIt, \c ArcIt and \c EdgeIt types. |
428 | 428 |
/// |
429 |
/// This class describes the concept of \c NodeIt, \c ArcIt and |
|
429 |
/// This class describes the concept of \c NodeIt, \c ArcIt and |
|
430 | 430 |
/// \c EdgeIt subtypes of digraph and graph types. |
431 | 431 |
template <typename GR, typename Item> |
432 | 432 |
class GraphItemIt : public Item { |
433 | 433 |
public: |
... | ... |
@@ -465,9 +465,9 @@ |
465 | 465 |
/// |
466 | 466 |
/// This operator increments the iterator, i.e. assigns it to the |
467 | 467 |
/// next item. |
468 | 468 |
GraphItemIt& operator++() { return *this; } |
469 |
|
|
469 |
|
|
470 | 470 |
/// \brief Equality operator |
471 | 471 |
/// |
472 | 472 |
/// Equality operator. |
473 | 473 |
/// Two iterators are equal if and only if they point to the |
... | ... |
@@ -500,17 +500,17 @@ |
500 | 500 |
const GR& g; |
501 | 501 |
}; |
502 | 502 |
}; |
503 | 503 |
|
504 |
/// \brief Concept class for \c InArcIt, \c OutArcIt and |
|
504 |
/// \brief Concept class for \c InArcIt, \c OutArcIt and |
|
505 | 505 |
/// \c IncEdgeIt types. |
506 | 506 |
/// |
507 |
/// This class describes the concept of \c InArcIt, \c OutArcIt |
|
507 |
/// This class describes the concept of \c InArcIt, \c OutArcIt |
|
508 | 508 |
/// and \c IncEdgeIt subtypes of digraph and graph types. |
509 | 509 |
/// |
510 | 510 |
/// \note Since these iterator classes do not inherit from the same |
511 | 511 |
/// base class, there is an additional template parameter (selector) |
512 |
/// \c sel. For \c InArcIt you should instantiate it with character |
|
512 |
/// \c sel. For \c InArcIt you should instantiate it with character |
|
513 | 513 |
/// \c 'i', for \c OutArcIt with \c 'o' and for \c IncEdgeIt with \c 'e'. |
514 | 514 |
template <typename GR, |
515 | 515 |
typename Item = typename GR::Arc, |
516 | 516 |
typename Base = typename GR::Node, |
... | ... |
@@ -529,12 +529,12 @@ |
529 | 529 |
/// |
530 | 530 |
/// Copy constructor. |
531 | 531 |
GraphIncIt(const GraphIncIt& it) : Item(it) {} |
532 | 532 |
|
533 |
/// \brief Constructor that sets the iterator to the first |
|
533 |
/// \brief Constructor that sets the iterator to the first |
|
534 | 534 |
/// incoming or outgoing arc. |
535 | 535 |
/// |
536 |
/// Constructor that sets the iterator to the first arc |
|
536 |
/// Constructor that sets the iterator to the first arc |
|
537 | 537 |
/// incoming to or outgoing from the given node. |
538 | 538 |
explicit GraphIncIt(const GR&, const Base&) {} |
539 | 539 |
|
540 | 540 |
/// \brief Constructor for conversion from \c INVALID. |
... | ... |
@@ -803,18 +803,18 @@ |
803 | 803 |
void next(Edge&) const {} |
804 | 804 |
|
805 | 805 |
/// \brief Return the first edge incident to the given node. |
806 | 806 |
/// |
807 |
/// This function gives back the first edge incident to the given |
|
807 |
/// This function gives back the first edge incident to the given |
|
808 | 808 |
/// node. The bool parameter gives back the direction for which the |
809 |
/// source node of the directed arc representing the edge is the |
|
809 |
/// source node of the directed arc representing the edge is the |
|
810 | 810 |
/// given node. |
811 | 811 |
void firstInc(Edge&, bool&, const Node&) const {} |
812 | 812 |
|
813 | 813 |
/// \brief Gives back the next of the edges from the |
814 | 814 |
/// given node. |
815 | 815 |
/// |
816 |
/// This function gives back the next edge incident to the given |
|
816 |
/// This function gives back the next edge incident to the given |
|
817 | 817 |
/// node. The bool parameter should be used as \c firstInc() use it. |
818 | 818 |
void nextInc(Edge&, bool&) const {} |
819 | 819 |
|
820 | 820 |
using IterableDigraphComponent<Base>::baseNode; |
... | ... |
@@ -989,9 +989,9 @@ |
989 | 989 |
|
990 | 990 |
/// \brief Concept class for standard graph maps. |
991 | 991 |
/// |
992 | 992 |
/// This class describes the concept of standard graph maps, i.e. |
993 |
/// the \c NodeMap, \c ArcMap and \c EdgeMap subtypes of digraph and |
|
993 |
/// the \c NodeMap, \c ArcMap and \c EdgeMap subtypes of digraph and |
|
994 | 994 |
/// graph types, which can be used for associating data to graph items. |
995 | 995 |
/// The standard graph maps must conform to the ReferenceMap concept. |
996 | 996 |
template <typename GR, typename K, typename V> |
997 | 997 |
class GraphMap : public ReferenceMap<K, V, V&, const V&> { |
... | ... |
@@ -1044,9 +1044,9 @@ |
1044 | 1044 |
checkConcept |
1045 | 1045 |
<ReferenceMap<Key, Value, Value&, const Value&>, _Map>(); |
1046 | 1046 |
_Map m1(g); |
1047 | 1047 |
_Map m2(g,t); |
1048 |
|
|
1048 |
|
|
1049 | 1049 |
// Copy constructor |
1050 | 1050 |
// _Map m3(m); |
1051 | 1051 |
|
1052 | 1052 |
// Assignment operator |
... | ... |
@@ -1067,9 +1067,9 @@ |
1067 | 1067 |
|
1068 | 1068 |
/// \brief Skeleton class for mappable directed graphs. |
1069 | 1069 |
/// |
1070 | 1070 |
/// This class describes the interface of mappable directed graphs. |
1071 |
/// It extends \ref BaseDigraphComponent with the standard digraph |
|
1071 |
/// It extends \ref BaseDigraphComponent with the standard digraph |
|
1072 | 1072 |
/// map classes, namely \c NodeMap and \c ArcMap. |
1073 | 1073 |
/// This concept is part of the Digraph concept. |
1074 | 1074 |
template <typename BAS = BaseDigraphComponent> |
1075 | 1075 |
class MappableDigraphComponent : public BAS { |
... | ... |
@@ -1204,9 +1204,9 @@ |
1204 | 1204 |
|
1205 | 1205 |
/// \brief Skeleton class for mappable undirected graphs. |
1206 | 1206 |
/// |
1207 | 1207 |
/// This class describes the interface of mappable undirected graphs. |
1208 |
/// It extends \ref MappableDigraphComponent with the standard graph |
|
1208 |
/// It extends \ref MappableDigraphComponent with the standard graph |
|
1209 | 1209 |
/// map class for edges (\c EdgeMap). |
1210 | 1210 |
/// This concept is part of the Graph concept. |
1211 | 1211 |
template <typename BAS = BaseGraphComponent> |
1212 | 1212 |
class MappableGraphComponent : public MappableDigraphComponent<BAS> { |
... | ... |
@@ -1289,9 +1289,9 @@ |
1289 | 1289 |
|
1290 | 1290 |
/// \brief Skeleton class for extendable directed graphs. |
1291 | 1291 |
/// |
1292 | 1292 |
/// This class describes the interface of extendable directed graphs. |
1293 |
/// It extends \ref BaseDigraphComponent with functions for adding |
|
1293 |
/// It extends \ref BaseDigraphComponent with functions for adding |
|
1294 | 1294 |
/// nodes and arcs to the digraph. |
1295 | 1295 |
/// This concept requires \ref AlterableDigraphComponent. |
1296 | 1296 |
template <typename BAS = BaseDigraphComponent> |
1297 | 1297 |
class ExtendableDigraphComponent : public BAS { |
... | ... |
@@ -1333,9 +1333,9 @@ |
1333 | 1333 |
|
1334 | 1334 |
/// \brief Skeleton class for extendable undirected graphs. |
1335 | 1335 |
/// |
1336 | 1336 |
/// This class describes the interface of extendable undirected graphs. |
1337 |
/// It extends \ref BaseGraphComponent with functions for adding |
|
1337 |
/// It extends \ref BaseGraphComponent with functions for adding |
|
1338 | 1338 |
/// nodes and edges to the graph. |
1339 | 1339 |
/// This concept requires \ref AlterableGraphComponent. |
1340 | 1340 |
template <typename BAS = BaseGraphComponent> |
1341 | 1341 |
class ExtendableGraphComponent : public BAS { |
... | ... |
@@ -1377,9 +1377,9 @@ |
1377 | 1377 |
|
1378 | 1378 |
/// \brief Skeleton class for erasable directed graphs. |
1379 | 1379 |
/// |
1380 | 1380 |
/// This class describes the interface of erasable directed graphs. |
1381 |
/// It extends \ref BaseDigraphComponent with functions for removing |
|
1381 |
/// It extends \ref BaseDigraphComponent with functions for removing |
|
1382 | 1382 |
/// nodes and arcs from the digraph. |
1383 | 1383 |
/// This concept requires \ref AlterableDigraphComponent. |
1384 | 1384 |
template <typename BAS = BaseDigraphComponent> |
1385 | 1385 |
class ErasableDigraphComponent : public BAS { |
... | ... |
@@ -1390,9 +1390,9 @@ |
1390 | 1390 |
typedef typename Base::Arc Arc; |
1391 | 1391 |
|
1392 | 1392 |
/// \brief Erase a node from the digraph. |
1393 | 1393 |
/// |
1394 |
/// This function erases the given node from the digraph and all arcs |
|
1394 |
/// This function erases the given node from the digraph and all arcs |
|
1395 | 1395 |
/// connected to the node. |
1396 | 1396 |
void erase(const Node&) {} |
1397 | 1397 |
|
1398 | 1398 |
/// \brief Erase an arc from the digraph. |
... | ... |
@@ -1416,9 +1416,9 @@ |
1416 | 1416 |
|
1417 | 1417 |
/// \brief Skeleton class for erasable undirected graphs. |
1418 | 1418 |
/// |
1419 | 1419 |
/// This class describes the interface of erasable undirected graphs. |
1420 |
/// It extends \ref BaseGraphComponent with functions for removing |
|
1420 |
/// It extends \ref BaseGraphComponent with functions for removing |
|
1421 | 1421 |
/// nodes and edges from the graph. |
1422 | 1422 |
/// This concept requires \ref AlterableGraphComponent. |
1423 | 1423 |
template <typename BAS = BaseGraphComponent> |
1424 | 1424 |
class ErasableGraphComponent : public BAS { |
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-2010 |
|
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 |
... | ... |
@@ -91,9 +91,9 @@ |
91 | 91 |
#ifdef DOXYGEN |
92 | 92 |
explicit Heap(ItemIntMap &map) {} |
93 | 93 |
#else |
94 | 94 |
explicit Heap(ItemIntMap&) {} |
95 |
#endif |
|
95 |
#endif |
|
96 | 96 |
|
97 | 97 |
/// \brief Constructor. |
98 | 98 |
/// |
99 | 99 |
/// Constructor. |
... | ... |
@@ -105,9 +105,9 @@ |
105 | 105 |
#ifdef DOXYGEN |
106 | 106 |
explicit Heap(ItemIntMap &map, const CMP &comp) {} |
107 | 107 |
#else |
108 | 108 |
explicit Heap(ItemIntMap&, const CMP&) {} |
109 |
#endif |
|
109 |
#endif |
|
110 | 110 |
|
111 | 111 |
/// \brief The number of items stored in the heap. |
112 | 112 |
/// |
113 | 113 |
/// This function returns the number of items stored in the heap. |
... | ... |
@@ -137,9 +137,9 @@ |
137 | 137 |
#ifdef DOXYGEN |
138 | 138 |
void push(const Item &i, const Prio &p) {} |
139 | 139 |
#else |
140 | 140 |
void push(const Item&, const Prio&) {} |
141 |
#endif |
|
141 |
#endif |
|
142 | 142 |
|
143 | 143 |
/// \brief Return the item having minimum priority. |
144 | 144 |
/// |
145 | 145 |
/// This function returns the item having minimum priority. |
... | ... |
@@ -167,9 +167,9 @@ |
167 | 167 |
#ifdef DOXYGEN |
168 | 168 |
void erase(const Item &i) {} |
169 | 169 |
#else |
170 | 170 |
void erase(const Item&) {} |
171 |
#endif |
|
171 |
#endif |
|
172 | 172 |
|
173 | 173 |
/// \brief The priority of the given item. |
174 | 174 |
/// |
175 | 175 |
/// This function returns the priority of the given item. |
... | ... |
@@ -178,9 +178,9 @@ |
178 | 178 |
#ifdef DOXYGEN |
179 | 179 |
Prio operator[](const Item &i) const {} |
180 | 180 |
#else |
181 | 181 |
Prio operator[](const Item&) const { return Prio(); } |
182 |
#endif |
|
182 |
#endif |
|
183 | 183 |
|
184 | 184 |
/// \brief Set the priority of an item or insert it, if it is |
185 | 185 |
/// not stored in the heap. |
186 | 186 |
/// |
... | ... |
@@ -193,9 +193,9 @@ |
193 | 193 |
#ifdef DOXYGEN |
194 | 194 |
void set(const Item &i, const Prio &p) {} |
195 | 195 |
#else |
196 | 196 |
void set(const Item&, const Prio&) {} |
197 |
#endif |
|
197 |
#endif |
|
198 | 198 |
|
199 | 199 |
/// \brief Decrease the priority of an item to the given value. |
200 | 200 |
/// |
201 | 201 |
/// This function decreases the priority of an item to the given value. |
... | ... |
@@ -205,9 +205,9 @@ |
205 | 205 |
#ifdef DOXYGEN |
206 | 206 |
void decrease(const Item &i, const Prio &p) {} |
207 | 207 |
#else |
208 | 208 |
void decrease(const Item&, const Prio&) {} |
209 |
#endif |
|
209 |
#endif |
|
210 | 210 |
|
211 | 211 |
/// \brief Increase the priority of an item to the given value. |
212 | 212 |
/// |
213 | 213 |
/// This function increases the priority of an item to the given value. |
... | ... |
@@ -217,9 +217,9 @@ |
217 | 217 |
#ifdef DOXYGEN |
218 | 218 |
void increase(const Item &i, const Prio &p) {} |
219 | 219 |
#else |
220 | 220 |
void increase(const Item&, const Prio&) {} |
221 |
#endif |
|
221 |
#endif |
|
222 | 222 |
|
223 | 223 |
/// \brief Return the state of an item. |
224 | 224 |
/// |
225 | 225 |
/// This method returns \c PRE_HEAP if the given item has never |
... | ... |
@@ -231,9 +231,9 @@ |
231 | 231 |
#ifdef DOXYGEN |
232 | 232 |
State state(const Item &i) const {} |
233 | 233 |
#else |
234 | 234 |
State state(const Item&) const { return PRE_HEAP; } |
235 |
#endif |
|
235 |
#endif |
|
236 | 236 |
|
237 | 237 |
/// \brief Set the state of an item in the heap. |
238 | 238 |
/// |
239 | 239 |
/// This function sets the state of the given item in the heap. |
... | ... |
@@ -244,9 +244,9 @@ |
244 | 244 |
#ifdef DOXYGEN |
245 | 245 |
void state(const Item& i, State st) {} |
246 | 246 |
#else |
247 | 247 |
void state(const Item&, State) {} |
248 |
#endif |
|
248 |
#endif |
|
249 | 249 |
|
250 | 250 |
|
251 | 251 |
template <typename _Heap> |
252 | 252 |
struct Constraints { |
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-2010 |
|
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 |
... | ... |
@@ -257,9 +257,9 @@ |
257 | 257 |
/// connected with directed paths in both direction. |
258 | 258 |
/// |
259 | 259 |
/// \return \c true if the digraph is strongly connected. |
260 | 260 |
/// \note By definition, the empty digraph is strongly connected. |
261 |
/// |
|
261 |
/// |
|
262 | 262 |
/// \see countStronglyConnectedComponents(), stronglyConnectedComponents() |
263 | 263 |
/// \see connected() |
264 | 264 |
template <typename Digraph> |
265 | 265 |
bool stronglyConnected(const Digraph& digraph) { |
... | ... |
@@ -309,9 +309,9 @@ |
309 | 309 |
} |
310 | 310 |
|
311 | 311 |
/// \ingroup graph_properties |
312 | 312 |
/// |
313 |
/// \brief Count the number of strongly connected components of a |
|
313 |
/// \brief Count the number of strongly connected components of a |
|
314 | 314 |
/// directed graph |
315 | 315 |
/// |
316 | 316 |
/// This function counts the number of strongly connected components of |
317 | 317 |
/// the given directed graph. |
... | ... |
@@ -743,9 +743,9 @@ |
743 | 743 |
/// \ingroup graph_properties |
744 | 744 |
/// |
745 | 745 |
/// \brief Check whether an undirected graph is bi-node-connected. |
746 | 746 |
/// |
747 |
/// This function checks whether the given undirected graph is |
|
747 |
/// This function checks whether the given undirected graph is |
|
748 | 748 |
/// bi-node-connected, i.e. any two edges are on same circle. |
749 | 749 |
/// |
750 | 750 |
/// \return \c true if the graph bi-node-connected. |
751 | 751 |
/// \note By definition, the empty graph is bi-node-connected. |
... | ... |
@@ -757,9 +757,9 @@ |
757 | 757 |
} |
758 | 758 |
|
759 | 759 |
/// \ingroup graph_properties |
760 | 760 |
/// |
761 |
/// \brief Count the number of bi-node-connected components of an |
|
761 |
/// \brief Count the number of bi-node-connected components of an |
|
762 | 762 |
/// undirected graph. |
763 | 763 |
/// |
764 | 764 |
/// This function counts the number of bi-node-connected components of |
765 | 765 |
/// the given undirected graph. |
... | ... |
@@ -811,9 +811,9 @@ |
811 | 811 |
/// |
812 | 812 |
/// \param graph The undirected graph. |
813 | 813 |
/// \retval compMap A writable edge map. The values will be set from 0 |
814 | 814 |
/// to the number of the bi-node-connected components minus one. Each |
815 |
/// value of the map will be set exactly once, and the values of a |
|
815 |
/// value of the map will be set exactly once, and the values of a |
|
816 | 816 |
/// certain component will be set continuously. |
817 | 817 |
/// \return The number of bi-node-connected components. |
818 | 818 |
/// |
819 | 819 |
/// \see biNodeConnected(), countBiNodeConnectedComponents() |
... | ... |
@@ -857,9 +857,9 @@ |
857 | 857 |
/// The bi-node-connected components are separted by the cut nodes of |
858 | 858 |
/// the components. |
859 | 859 |
/// |
860 | 860 |
/// \param graph The undirected graph. |
861 |
/// \retval cutMap A writable node map. The values will be set to |
|
861 |
/// \retval cutMap A writable node map. The values will be set to |
|
862 | 862 |
/// \c true for the nodes that separate two or more components |
863 | 863 |
/// (exactly once for each cut node), and will not be changed for |
864 | 864 |
/// other nodes. |
865 | 865 |
/// \return The number of the cut nodes. |
... | ... |
@@ -1084,9 +1084,9 @@ |
1084 | 1084 |
/// \ingroup graph_properties |
1085 | 1085 |
/// |
1086 | 1086 |
/// \brief Check whether an undirected graph is bi-edge-connected. |
1087 | 1087 |
/// |
1088 |
/// This function checks whether the given undirected graph is |
|
1088 |
/// This function checks whether the given undirected graph is |
|
1089 | 1089 |
/// bi-edge-connected, i.e. any two nodes are connected with at least |
1090 | 1090 |
/// two edge-disjoint paths. |
1091 | 1091 |
/// |
1092 | 1092 |
/// \return \c true if the graph is bi-edge-connected. |
... | ... |
@@ -1191,9 +1191,9 @@ |
1191 | 1191 |
/// |
1192 | 1192 |
/// \brief Find the bi-edge-connected cut edges in an undirected graph. |
1193 | 1193 |
/// |
1194 | 1194 |
/// This function finds the bi-edge-connected cut edges in the given |
1195 |
/// undirected graph. |
|
1195 |
/// undirected graph. |
|
1196 | 1196 |
/// |
1197 | 1197 |
/// The bi-edge-connected components are the classes of an equivalence |
1198 | 1198 |
/// relation on the nodes of an undirected graph. Two nodes are in the |
1199 | 1199 |
/// same class if they are connected with at least two edge-disjoint |
... | ... |
@@ -1348,9 +1348,9 @@ |
1348 | 1348 |
/// is DAG. |
1349 | 1349 |
/// |
1350 | 1350 |
/// \param digraph The digraph. |
1351 | 1351 |
/// \retval order A readable and writable node map. The values will be |
1352 |
/// set from 0 to the number of the nodes in the digraph minus one. |
|
1352 |
/// set from 0 to the number of the nodes in the digraph minus one. |
|
1353 | 1353 |
/// Each value of the map will be set exactly once, and the values will |
1354 | 1354 |
/// be set descending order. |
1355 | 1355 |
/// \return \c false if the digraph is not DAG. |
1356 | 1356 |
/// |
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-2010 |
|
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 |
... | ... |
@@ -1238,9 +1238,10 @@ |
1238 | 1238 |
typedef GR Digraph; |
1239 | 1239 |
|
1240 | 1240 |
protected: |
1241 | 1241 |
|
1242 |
class AutoNodeMap : public ItemSetTraits<GR, Node>::template Map<Arc>::Type |
|
1242 |
class AutoNodeMap : public ItemSetTraits<GR, Node>::template Map<Arc>::Type |
|
1243 |
{ |
|
1243 | 1244 |
typedef typename ItemSetTraits<GR, Node>::template Map<Arc>::Type Parent; |
1244 | 1245 |
|
1245 | 1246 |
public: |
1246 | 1247 |
|
... | ... |
@@ -1277,9 +1278,9 @@ |
1277 | 1278 |
return g.target(a)<g.target(b); |
1278 | 1279 |
} |
1279 | 1280 |
}; |
1280 | 1281 |
|
1281 |
protected: |
|
1282 |
protected: |
|
1282 | 1283 |
|
1283 | 1284 |
const Digraph &_g; |
1284 | 1285 |
AutoNodeMap _head; |
1285 | 1286 |
typename Digraph::template ArcMap<Arc> _parent; |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 |
* Copyright (C) 2003- |
|
5 |
* Copyright (C) 2003-2010 |
|
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 |
... | ... |
@@ -91,9 +91,9 @@ |
91 | 91 |
/// |
92 | 92 |
/// \ref CostScaling implements a cost scaling algorithm that performs |
93 | 93 |
/// push/augment and relabel operations for finding a \ref min_cost_flow |
94 | 94 |
/// "minimum cost flow" \ref amo93networkflows, \ref goldberg90approximation, |
95 |
/// \ref goldberg97efficient, \ref bunnagel98efficient. |
|
95 |
/// \ref goldberg97efficient, \ref bunnagel98efficient. |
|
96 | 96 |
/// It is a highly efficient primal-dual solution method, which |
97 | 97 |
/// can be viewed as the generalization of the \ref Preflow |
98 | 98 |
/// "preflow push-relabel" algorithm for the maximum flow problem. |
99 | 99 |
/// |
... | ... |
@@ -188,9 +188,9 @@ |
188 | 188 |
PUSH, |
189 | 189 |
/// Augment operations are used, i.e. flow is moved on admissible |
190 | 190 |
/// paths from a node with excess to a node with deficit. |
191 | 191 |
AUGMENT, |
192 |
/// Partial augment operations are used, i.e. flow is moved on |
|
192 |
/// Partial augment operations are used, i.e. flow is moved on |
|
193 | 193 |
/// admissible paths started from a node with excess, but the |
194 | 194 |
/// lengths of these paths are limited. This method can be viewed |
195 | 195 |
/// as a combined version of the previous two operations. |
196 | 196 |
PARTIAL_AUGMENT |
... | ... |
@@ -207,25 +207,25 @@ |
207 | 207 |
typedef std::vector<char> BoolVector; |
208 | 208 |
// Note: vector<char> is used instead of vector<bool> for efficiency reasons |
209 | 209 |
|
210 | 210 |
private: |
211 |
|
|
211 |
|
|
212 | 212 |
template <typename KT, typename VT> |
213 | 213 |
class StaticVectorMap { |
214 | 214 |
public: |
215 | 215 |
typedef KT Key; |
216 | 216 |
typedef VT Value; |
217 |
|
|
217 |
|
|
218 | 218 |
StaticVectorMap(std::vector<Value>& v) : _v(v) {} |
219 |
|
|
219 |
|
|
220 | 220 |
const Value& operator[](const Key& key) const { |
221 | 221 |
return _v[StaticDigraph::id(key)]; |
222 | 222 |
} |
223 | 223 |
|
224 | 224 |
Value& operator[](const Key& key) { |
225 | 225 |
return _v[StaticDigraph::id(key)]; |
226 | 226 |
} |
227 |
|
|
227 |
|
|
228 | 228 |
void set(const Key& key, const Value& val) { |
229 | 229 |
_v[StaticDigraph::id(key)] = val; |
230 | 230 |
} |
231 | 231 |
|
... | ... |
@@ -282,19 +282,19 @@ |
282 | 282 |
IntVector _bucket_next; |
283 | 283 |
IntVector _bucket_prev; |
284 | 284 |
IntVector _rank; |
285 | 285 |
int _max_rank; |
286 |
|
|
286 |
|
|
287 | 287 |
// Data for a StaticDigraph structure |
288 | 288 |
typedef std::pair<int, int> IntPair; |
289 | 289 |
StaticDigraph _sgr; |
290 | 290 |
std::vector<IntPair> _arc_vec; |
291 | 291 |
std::vector<LargeCost> _cost_vec; |
292 | 292 |
LargeCostArcMap _cost_map; |
293 | 293 |
LargeCostNodeMap _pi_map; |
294 |
|
|
294 |
|
|
295 | 295 |
public: |
296 |
|
|
296 |
|
|
297 | 297 |
/// \brief Constant for infinite upper bounds (capacities). |
298 | 298 |
/// |
299 | 299 |
/// Constant for infinite upper bounds (capacities). |
300 | 300 |
/// It is \c std::numeric_limits<Value>::infinity() if available, |
... | ... |
@@ -347,9 +347,9 @@ |
347 | 347 |
LEMON_ASSERT(std::numeric_limits<Value>::is_signed, |
348 | 348 |
"The flow type of CostScaling must be signed"); |
349 | 349 |
LEMON_ASSERT(std::numeric_limits<Cost>::is_signed, |
350 | 350 |
"The cost type of CostScaling must be signed"); |
351 |
|
|
351 |
|
|
352 | 352 |
// Reset data structures |
353 | 353 |
reset(); |
354 | 354 |
} |
355 | 355 |
|
... | ... |
@@ -463,9 +463,9 @@ |
463 | 463 |
_supply[_node_id[s]] = k; |
464 | 464 |
_supply[_node_id[t]] = -k; |
465 | 465 |
return *this; |
466 | 466 |
} |
467 |
|
|
467 |
|
|
468 | 468 |
/// @} |
469 | 469 |
|
470 | 470 |
/// \name Execution control |
471 | 471 |
/// The algorithm can be executed using \ref run(). |
... | ... |
@@ -565,9 +565,9 @@ |
565 | 565 |
_lower[j] = 0; |
566 | 566 |
_upper[j] = INF; |
567 | 567 |
_scost[j] = 0; |
568 | 568 |
_scost[_reverse[j]] = 0; |
569 |
} |
|
569 |
} |
|
570 | 570 |
_have_lower = false; |
571 | 571 |
return *this; |
572 | 572 |
} |
573 | 573 |
|
... | ... |
@@ -600,9 +600,9 @@ |
600 | 600 |
_lower.resize(_res_arc_num); |
601 | 601 |
_upper.resize(_res_arc_num); |
602 | 602 |
_scost.resize(_res_arc_num); |
603 | 603 |
_supply.resize(_res_node_num); |
604 |
|
|
604 |
|
|
605 | 605 |
_res_cap.resize(_res_arc_num); |
606 | 606 |
_cost.resize(_res_arc_num); |
607 | 607 |
_pi.resize(_res_node_num); |
608 | 608 |
_excess.resize(_res_node_num); |
... | ... |
@@ -648,9 +648,9 @@ |
648 | 648 |
int bi = _arc_idb[a]; |
649 | 649 |
_reverse[fi] = bi; |
650 | 650 |
_reverse[bi] = fi; |
651 | 651 |
} |
652 |
|
|
652 |
|
|
653 | 653 |
// Reset parameters |
654 | 654 |
resetParams(); |
655 | 655 |
return *this; |
656 | 656 |
} |
... | ... |
@@ -757,16 +757,16 @@ |
757 | 757 |
for (int i = 0; i != _root; ++i) { |
758 | 758 |
_sum_supply += _supply[i]; |
759 | 759 |
} |
760 | 760 |
if (_sum_supply > 0) return INFEASIBLE; |
761 |
|
|
761 |
|
|
762 | 762 |
|
763 | 763 |
// Initialize vectors |
764 | 764 |
for (int i = 0; i != _res_node_num; ++i) { |
765 | 765 |
_pi[i] = 0; |
766 | 766 |
_excess[i] = _supply[i]; |
767 | 767 |
} |
768 |
|
|
768 |
|
|
769 | 769 |
// Remove infinite upper bounds and check negative arcs |
770 | 770 |
const Value MAX = std::numeric_limits<Value>::max(); |
771 | 771 |
int last_out; |
772 | 772 |
if (_have_lower) { |
... | ... |
@@ -884,24 +884,24 @@ |
884 | 884 |
_cost[a] = 0; |
885 | 885 |
_cost[ra] = 0; |
886 | 886 |
} |
887 | 887 |
} |
888 |
|
|
888 |
|
|
889 | 889 |
return OPTIMAL; |
890 | 890 |
} |
891 | 891 |
|
892 | 892 |
// Execute the algorithm and transform the results |
893 | 893 |
void start(Method method) { |
894 | 894 |
// Maximum path length for partial augment |
895 | 895 |
const int MAX_PATH_LENGTH = 4; |
896 | 896 |
|
897 |
// Initialize data structures for buckets |
|
897 |
// Initialize data structures for buckets |
|
898 | 898 |
_max_rank = _alpha * _res_node_num; |
899 | 899 |
_buckets.resize(_max_rank); |
900 | 900 |
_bucket_next.resize(_res_node_num + 1); |
901 | 901 |
_bucket_prev.resize(_res_node_num + 1); |
902 | 902 |
_rank.resize(_res_node_num + 1); |
903 |
|
|
903 |
|
|
904 | 904 |
// Execute the algorithm |
905 | 905 |
switch (method) { |
906 | 906 |
case PUSH: |
907 | 907 |
startPush(); |
... | ... |
@@ -938,9 +938,9 @@ |
938 | 938 |
if (!_forward[j]) _res_cap[j] += _lower[j]; |
939 | 939 |
} |
940 | 940 |
} |
941 | 941 |
} |
942 |
|
|
942 |
|
|
943 | 943 |
// Initialize a cost scaling phase |
944 | 944 |
void initPhase() { |
945 | 945 |
// Saturate arcs not satisfying the optimality condition |
946 | 946 |
for (int u = 0; u != _res_node_num; ++u) { |
... | ... |
@@ -956,9 +956,9 @@ |
956 | 956 |
_res_cap[_reverse[a]] += delta; |
957 | 957 |
} |
958 | 958 |
} |
959 | 959 |
} |
960 |
|
|
960 |
|
|
961 | 961 |
// Find active nodes (i.e. nodes with positive excess) |
962 | 962 |
for (int u = 0; u != _res_node_num; ++u) { |
963 | 963 |
if (_excess[u] > 0) _active_nodes.push_back(u); |
964 | 964 |
} |
... | ... |
@@ -967,9 +967,9 @@ |
967 | 967 |
for (int u = 0; u != _res_node_num; ++u) { |
968 | 968 |
_next_out[u] = _first_out[u]; |
969 | 969 |
} |
970 | 970 |
} |
971 |
|
|
971 |
|
|
972 | 972 |
// Early termination heuristic |
973 | 973 |
bool earlyTermination() { |
974 | 974 |
const double EARLY_TERM_FACTOR = 3.0; |
975 | 975 |
|
... | ... |
@@ -997,9 +997,9 @@ |
997 | 997 |
|
998 | 998 |
// Global potential update heuristic |
999 | 999 |
void globalUpdate() { |
1000 | 1000 |
int bucket_end = _root + 1; |
1001 |
|
|
1001 |
|
|
1002 | 1002 |
// Initialize buckets |
1003 | 1003 |
for (int r = 0; r != _max_rank; ++r) { |
1004 | 1004 |
_buckets[r] = bucket_end; |
1005 | 1005 |
} |
... | ... |
@@ -1023,9 +1023,9 @@ |
1023 | 1023 |
while (_buckets[r] != bucket_end) { |
1024 | 1024 |
// Remove the first node from the current bucket |
1025 | 1025 |
int u = _buckets[r]; |
1026 | 1026 |
_buckets[r] = _bucket_next[u]; |
1027 |
|
|
1027 |
|
|
1028 | 1028 |
// Search the incomming arcs of u |
1029 | 1029 |
LargeCost pi_u = _pi[u]; |
1030 | 1030 |
int last_out = _first_out[u+1]; |
1031 | 1031 |
for (int a = _first_out[u]; a != last_out; ++a) { |
... | ... |
@@ -1038,14 +1038,14 @@ |
1038 | 1038 |
LargeCost nrc = (_cost[ra] + _pi[v] - pi_u) / _epsilon; |
1039 | 1039 |
int new_rank_v = old_rank_v; |
1040 | 1040 |
if (nrc < LargeCost(_max_rank)) |
1041 | 1041 |
new_rank_v = r + 1 + int(nrc); |
1042 |
|
|
1042 |
|
|
1043 | 1043 |
// Change the rank of v |
1044 | 1044 |
if (new_rank_v < old_rank_v) { |
1045 | 1045 |
_rank[v] = new_rank_v; |
1046 | 1046 |
_next_out[v] = _first_out[v]; |
1047 |
|
|
1047 |
|
|
1048 | 1048 |
// Remove v from its old bucket |
1049 | 1049 |
if (old_rank_v < _max_rank) { |
1050 | 1050 |
if (_buckets[old_rank_v] == v) { |
1051 | 1051 |
_buckets[old_rank_v] = _bucket_next[v]; |
... | ... |
@@ -1053,9 +1053,9 @@ |
1053 | 1053 |
_bucket_next[_bucket_prev[v]] = _bucket_next[v]; |
1054 | 1054 |
_bucket_prev[_bucket_next[v]] = _bucket_prev[v]; |
1055 | 1055 |
} |
1056 | 1056 |
} |
1057 |
|
|
1057 |
|
|
1058 | 1058 |
// Insert v to its new bucket |
1059 | 1059 |
_bucket_next[v] = _buckets[new_rank_v]; |
1060 | 1060 |
_bucket_prev[_buckets[new_rank_v]] = v; |
1061 | 1061 |
_buckets[new_rank_v] = v; |
... | ... |
@@ -1071,9 +1071,9 @@ |
1071 | 1071 |
} |
1072 | 1072 |
} |
1073 | 1073 |
if (total_excess <= 0) break; |
1074 | 1074 |
} |
1075 |
|
|
1075 |
|
|
1076 | 1076 |
// Relabel nodes |
1077 | 1077 |
for (int u = 0; u != _res_node_num; ++u) { |
1078 | 1078 |
int k = std::min(_rank[u], r); |
1079 | 1079 |
if (k > 0) { |
... | ... |
@@ -1091,11 +1091,11 @@ |
1091 | 1091 |
|
1092 | 1092 |
const int global_update_freq = int(GLOBAL_UPDATE_FACTOR * |
1093 | 1093 |
(_res_node_num + _sup_node_num * _sup_node_num)); |
1094 | 1094 |
int next_update_limit = global_update_freq; |
1095 |
|
|
1095 |
|
|
1096 | 1096 |
int relabel_cnt = 0; |
1097 |
|
|
1097 |
|
|
1098 | 1098 |
// Perform cost scaling phases |
1099 | 1099 |
std::vector<int> path; |
1100 | 1100 |
for ( ; _epsilon >= 1; _epsilon = _epsilon < _alpha && _epsilon > 1 ? |
1101 | 1101 |
1 : _epsilon / _alpha ) |
... | ... |
@@ -1103,12 +1103,12 @@ |
1103 | 1103 |
// Early termination heuristic |
1104 | 1104 |
if (_epsilon <= EARLY_TERM_EPSILON_LIMIT) { |
1105 | 1105 |
if (earlyTermination()) break; |
1106 | 1106 |
} |
1107 |
|
|
1107 |
|
|
1108 | 1108 |
// Initialize current phase |
1109 | 1109 |
initPhase(); |
1110 |
|
|
1110 |
|
|
1111 | 1111 |
// Perform partial augment and relabel operations |
1112 | 1112 |
while (true) { |
1113 | 1113 |
// Select an active node (FIFO selection) |
1114 | 1114 |
while (_active_nodes.size() > 0 && |
... | ... |
@@ -1195,9 +1195,9 @@ |
1195 | 1195 |
(_res_node_num + _sup_node_num * _sup_node_num)); |
1196 | 1196 |
int next_update_limit = global_update_freq; |
1197 | 1197 |
|
1198 | 1198 |
int relabel_cnt = 0; |
1199 |
|
|
1199 |
|
|
1200 | 1200 |
// Perform cost scaling phases |
1201 | 1201 |
BoolVector hyper(_res_node_num, false); |
1202 | 1202 |
LargeCostVector hyper_cost(_res_node_num); |
1203 | 1203 |
for ( ; _epsilon >= 1; _epsilon = _epsilon < _alpha && _epsilon > 1 ? |
... | ... |
@@ -1206,9 +1206,9 @@ |
1206 | 1206 |
// Early termination heuristic |
1207 | 1207 |
if (_epsilon <= EARLY_TERM_EPSILON_LIMIT) { |
1208 | 1208 |
if (earlyTermination()) break; |
1209 | 1209 |
} |
1210 |
|
|
1210 |
|
|
1211 | 1211 |
// Initialize current phase |
1212 | 1212 |
initPhase(); |
1213 | 1213 |
|
1214 | 1214 |
// Perform push and relabel operations |
... | ... |
@@ -1221,9 +1221,9 @@ |
1221 | 1221 |
// Select an active node (FIFO selection) |
1222 | 1222 |
n = _active_nodes.front(); |
1223 | 1223 |
last_out = _first_out[n+1]; |
1224 | 1224 |
pi_n = _pi[n]; |
1225 |
|
|
1225 |
|
|
1226 | 1226 |
// Perform push operations if there are admissible arcs |
1227 | 1227 |
if (_excess[n] > 0) { |
1228 | 1228 |
for (a = _next_out[n]; a != last_out; ++a) { |
1229 | 1229 |
if (_res_cap[a] > 0 && |
... | ... |
@@ -1235,9 +1235,9 @@ |
1235 | 1235 |
Value ahead = -_excess[t]; |
1236 | 1236 |
int last_out_t = _first_out[t+1]; |
1237 | 1237 |
LargeCost pi_t = _pi[t]; |
1238 | 1238 |
for (int ta = _next_out[t]; ta != last_out_t; ++ta) { |
1239 |
if (_res_cap[ta] > 0 && |
|
1239 |
if (_res_cap[ta] > 0 && |
|
1240 | 1240 |
_cost[ta] + pi_t - _pi[_target[ta]] < 0) |
1241 | 1241 |
ahead += _res_cap[ta]; |
1242 | 1242 |
if (ahead >= delta) break; |
1243 | 1243 |
} |
... | ... |
@@ -1286,17 +1286,17 @@ |
1286 | 1286 |
_next_out[n] = _first_out[n]; |
1287 | 1287 |
hyper[n] = false; |
1288 | 1288 |
++relabel_cnt; |
1289 | 1289 |
} |
1290 |
|
|
1290 |
|
|
1291 | 1291 |
// Remove nodes that are not active nor hyper |
1292 | 1292 |
remove_nodes: |
1293 | 1293 |
while ( _active_nodes.size() > 0 && |
1294 | 1294 |
_excess[_active_nodes.front()] <= 0 && |
1295 | 1295 |
!hyper[_active_nodes.front()] ) { |
1296 | 1296 |
_active_nodes.pop_front(); |
1297 | 1297 |
} |
1298 |
|
|
1298 |
|
|
1299 | 1299 |
// Global update heuristic |
1300 | 1300 |
if (relabel_cnt >= next_update_limit) { |
1301 | 1301 |
globalUpdate(); |
1302 | 1302 |
for (int u = 0; u != _res_node_num; ++u) |
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-2010 |
|
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 |
... | ... |
@@ -110,9 +110,9 @@ |
110 | 110 |
CPXnewrows(cplexEnv(), _prob, 1, &ub, &s, 0, 0); |
111 | 111 |
return i; |
112 | 112 |
} |
113 | 113 |
|
114 |
int CplexBase::_addRow(Value lb, ExprIterator b, |
|
114 |
int CplexBase::_addRow(Value lb, ExprIterator b, |
|
115 | 115 |
ExprIterator e, Value ub) { |
116 | 116 |
int i = CPXgetnumrows(cplexEnv(), _prob); |
117 | 117 |
if (lb == -INF) { |
118 | 118 |
const char s = 'L'; |
... | ... |
@@ -488,9 +488,9 @@ |
488 | 488 |
} |
489 | 489 |
} |
490 | 490 |
|
491 | 491 |
void CplexBase::_applyMessageLevel() { |
492 |
CPXsetintparam(cplexEnv(), CPX_PARAM_SCRIND, |
|
492 |
CPXsetintparam(cplexEnv(), CPX_PARAM_SCRIND, |
|
493 | 493 |
_message_enabled ? CPX_ON : CPX_OFF); |
494 | 494 |
} |
495 | 495 |
|
496 | 496 |
// CplexLp members |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 |
* Copyright (C) 2003- |
|
5 |
* Copyright (C) 2003-2010 |
|
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 |
... | ... |
@@ -141,34 +141,34 @@ |
141 | 141 |
|
142 | 142 |
private: |
143 | 143 |
|
144 | 144 |
TEMPLATE_DIGRAPH_TYPEDEFS(GR); |
145 |
|
|
145 |
|
|
146 | 146 |
typedef std::vector<int> IntVector; |
147 | 147 |
typedef std::vector<double> DoubleVector; |
148 | 148 |
typedef std::vector<Value> ValueVector; |
149 | 149 |
typedef std::vector<Cost> CostVector; |
150 | 150 |
typedef std::vector<char> BoolVector; |
151 | 151 |
// Note: vector<char> is used instead of vector<bool> for efficiency reasons |
152 | 152 |
|
153 | 153 |
private: |
154 |
|
|
154 |
|
|
155 | 155 |
template <typename KT, typename VT> |
156 | 156 |
class StaticVectorMap { |
157 | 157 |
public: |
158 | 158 |
typedef KT Key; |
159 | 159 |
typedef VT Value; |
160 |
|
|
160 |
|
|
161 | 161 |
StaticVectorMap(std::vector<Value>& v) : _v(v) {} |
162 |
|
|
162 |
|
|
163 | 163 |
const Value& operator[](const Key& key) const { |
164 | 164 |
return _v[StaticDigraph::id(key)]; |
165 | 165 |
} |
166 | 166 |
|
167 | 167 |
Value& operator[](const Key& key) { |
168 | 168 |
return _v[StaticDigraph::id(key)]; |
169 | 169 |
} |
170 |
|
|
170 |
|
|
171 | 171 |
void set(const Key& key, const Value& val) { |
172 | 172 |
_v[StaticDigraph::id(key)] = val; |
173 | 173 |
} |
174 | 174 |
|
... | ... |
@@ -220,11 +220,11 @@ |
220 | 220 |
std::vector<Cost> _cost_vec; |
221 | 221 |
IntVector _id_vec; |
222 | 222 |
CostArcMap _cost_map; |
223 | 223 |
CostNodeMap _pi_map; |
224 |
|
|
224 |
|
|
225 | 225 |
public: |
226 |
|
|
226 |
|
|
227 | 227 |
/// \brief Constant for infinite upper bounds (capacities). |
228 | 228 |
/// |
229 | 229 |
/// Constant for infinite upper bounds (capacities). |
230 | 230 |
/// It is \c std::numeric_limits<Value>::infinity() if available, |
... | ... |
@@ -365,9 +365,9 @@ |
365 | 365 |
_supply[_node_id[s]] = k; |
366 | 366 |
_supply[_node_id[t]] = -k; |
367 | 367 |
return *this; |
368 | 368 |
} |
369 |
|
|
369 |
|
|
370 | 370 |
/// @} |
371 | 371 |
|
372 | 372 |
/// \name Execution control |
373 | 373 |
/// The algorithm can be executed using \ref run(). |
... | ... |
@@ -465,9 +465,9 @@ |
465 | 465 |
_lower[j] = 0; |
466 | 466 |
_upper[j] = INF; |
467 | 467 |
_cost[j] = 0; |
468 | 468 |
_cost[_reverse[j]] = 0; |
469 |
} |
|
469 |
} |
|
470 | 470 |
_have_lower = false; |
471 | 471 |
return *this; |
472 | 472 |
} |
473 | 473 |
|
... | ... |
@@ -507,9 +507,9 @@ |
507 | 507 |
_lower.resize(_res_arc_num); |
508 | 508 |
_upper.resize(_res_arc_num); |
509 | 509 |
_cost.resize(_res_arc_num); |
510 | 510 |
_supply.resize(_res_node_num); |
511 |
|
|
511 |
|
|
512 | 512 |
_res_cap.resize(_res_arc_num); |
513 | 513 |
_pi.resize(_res_node_num); |
514 | 514 |
|
515 | 515 |
_arc_vec.reserve(_res_arc_num); |
... | ... |
@@ -553,9 +553,9 @@ |
553 | 553 |
int bi = _arc_idb[a]; |
554 | 554 |
_reverse[fi] = bi; |
555 | 555 |
_reverse[bi] = fi; |
556 | 556 |
} |
557 |
|
|
557 |
|
|
558 | 558 |
// Reset parameters |
559 | 559 |
resetParams(); |
560 | 560 |
return *this; |
561 | 561 |
} |
... | ... |
@@ -662,16 +662,16 @@ |
662 | 662 |
for (int i = 0; i != _root; ++i) { |
663 | 663 |
_sum_supply += _supply[i]; |
664 | 664 |
} |
665 | 665 |
if (_sum_supply > 0) return INFEASIBLE; |
666 |
|
|
666 |
|
|
667 | 667 |
|
668 | 668 |
// Initialize vectors |
669 | 669 |
for (int i = 0; i != _res_node_num; ++i) { |
670 | 670 |
_pi[i] = 0; |
671 | 671 |
} |
672 | 672 |
ValueVector excess(_supply); |
673 |
|
|
673 |
|
|
674 | 674 |
// Remove infinite upper bounds and check negative arcs |
675 | 675 |
const Value MAX = std::numeric_limits<Value>::max(); |
676 | 676 |
int last_out; |
677 | 677 |
if (_have_lower) { |
... | ... |
@@ -769,12 +769,12 @@ |
769 | 769 |
_cost[a] = 0; |
770 | 770 |
_cost[ra] = 0; |
771 | 771 |
} |
772 | 772 |
} |
773 |
|
|
773 |
|
|
774 | 774 |
return OPTIMAL; |
775 | 775 |
} |
776 |
|
|
776 |
|
|
777 | 777 |
// Build a StaticDigraph structure containing the current |
778 | 778 |
// residual network |
779 | 779 |
void buildResidualNetwork() { |
780 | 780 |
_arc_vec.clear(); |
... | ... |
@@ -828,16 +828,16 @@ |
828 | 828 |
void startSimpleCycleCanceling() { |
829 | 829 |
// Constants for computing the iteration limits |
830 | 830 |
const int BF_FIRST_LIMIT = 2; |
831 | 831 |
const double BF_LIMIT_FACTOR = 1.5; |
832 |
|
|
832 |
|
|
833 | 833 |
typedef StaticVectorMap<StaticDigraph::Arc, Value> FilterMap; |
834 | 834 |
typedef FilterArcs<StaticDigraph, FilterMap> ResDigraph; |
835 | 835 |
typedef StaticVectorMap<StaticDigraph::Node, StaticDigraph::Arc> PredMap; |
836 | 836 |
typedef typename BellmanFord<ResDigraph, CostArcMap> |
837 | 837 |
::template SetDistMap<CostNodeMap> |
838 | 838 |
::template SetPredMap<PredMap>::Create BF; |
839 |
|
|
839 |
|
|
840 | 840 |
// Build the residual network |
841 | 841 |
_arc_vec.clear(); |
842 | 842 |
_cost_vec.clear(); |
843 | 843 |
for (int j = 0; j != _res_arc_num; ++j) { |
... | ... |
@@ -925,9 +925,9 @@ |
925 | 925 |
typedef SimplePath<StaticDigraph> SPath; |
926 | 926 |
typedef typename SPath::ArcIt SPathArcIt; |
927 | 927 |
typedef typename HowardMmc<StaticDigraph, CostArcMap> |
928 | 928 |
::template SetPath<SPath>::Create MMC; |
929 |
|
|
929 |
|
|
930 | 930 |
SPath cycle; |
931 | 931 |
MMC mmc(_sgr, _cost_map); |
932 | 932 |
mmc.cycle(cycle); |
933 | 933 |
buildResidualNetwork(); |
... | ... |
@@ -948,9 +948,9 @@ |
948 | 948 |
_res_cap[j] -= delta; |
949 | 949 |
_res_cap[_reverse[j]] += delta; |
950 | 950 |
} |
951 | 951 |
|
952 |
// Rebuild the residual network |
|
952 |
// Rebuild the residual network |
|
953 | 953 |
buildResidualNetwork(); |
954 | 954 |
} |
955 | 955 |
} |
956 | 956 |
|
... | ... |
@@ -1142,9 +1142,9 @@ |
1142 | 1142 |
mmc.findCycleMean(); |
1143 | 1143 |
epsilon = -mmc.cycleMean(); |
1144 | 1144 |
Cost cycle_cost = mmc.cycleCost(); |
1145 | 1145 |
int cycle_size = mmc.cycleSize(); |
1146 |
|
|
1146 |
|
|
1147 | 1147 |
// Compute feasible potentials for the current epsilon |
1148 | 1148 |
for (int i = 0; i != int(_cost_vec.size()); ++i) { |
1149 | 1149 |
_cost_vec[i] = cycle_size * _cost_vec[i] - cycle_cost; |
1150 | 1150 |
} |
... | ... |
@@ -1154,9 +1154,9 @@ |
1154 | 1154 |
bf.start(); |
1155 | 1155 |
for (int u = 0; u != _res_node_num; ++u) { |
1156 | 1156 |
pi[u] = static_cast<double>(_pi[u]) / cycle_size; |
1157 | 1157 |
} |
1158 |
|
|
1158 |
|
|
1159 | 1159 |
iter = limit; |
1160 | 1160 |
} |
1161 | 1161 |
} |
1162 | 1162 |
} |
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-2010 |
|
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 |
... | ... |
@@ -81,9 +81,10 @@ |
81 | 81 |
|
82 | 82 |
///The type of the map that indicates which nodes are reached. |
83 | 83 |
|
84 | 84 |
///The type of the map that indicates which nodes are reached. |
85 |
///It must conform to |
|
85 |
///It must conform to |
|
86 |
///the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
86 | 87 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
87 | 88 |
///Instantiates a \c ReachedMap. |
88 | 89 |
|
89 | 90 |
///This function instantiates a \ref ReachedMap. |
... | ... |
@@ -269,9 +270,10 @@ |
269 | 270 |
///\c ReachedMap type. |
270 | 271 |
/// |
271 | 272 |
///\ref named-templ-param "Named parameter" for setting |
272 | 273 |
///\c ReachedMap type. |
273 |
///It must conform to |
|
274 |
///It must conform to |
|
275 |
///the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
274 | 276 |
template <class T> |
275 | 277 |
struct SetReachedMap : public Dfs< Digraph, SetReachedMapTraits<T> > { |
276 | 278 |
typedef Dfs< Digraph, SetReachedMapTraits<T> > Create; |
277 | 279 |
}; |
... | ... |
@@ -801,9 +803,10 @@ |
801 | 803 |
|
802 | 804 |
///The type of the map that indicates which nodes are reached. |
803 | 805 |
|
804 | 806 |
///The type of the map that indicates which nodes are reached. |
805 |
///It must conform to |
|
807 |
///It must conform to |
|
808 |
///the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
806 | 809 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
807 | 810 |
///Instantiates a ReachedMap. |
808 | 811 |
|
809 | 812 |
///This function instantiates a ReachedMap. |
... | ... |
@@ -1206,9 +1209,10 @@ |
1206 | 1209 |
|
1207 | 1210 |
/// \brief The type of the map that indicates which nodes are reached. |
1208 | 1211 |
/// |
1209 | 1212 |
/// The type of the map that indicates which nodes are reached. |
1210 |
/// It must conform to the |
|
1213 |
/// It must conform to the |
|
1214 |
/// \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
1211 | 1215 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
1212 | 1216 |
|
1213 | 1217 |
/// \brief Instantiates a ReachedMap. |
1214 | 1218 |
/// |
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-2010 |
|
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 |
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-2010 |
|
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 |
... | ... |
@@ -60,9 +60,9 @@ |
60 | 60 |
|
61 | 61 |
///Discover the type of a DIMACS file |
62 | 62 |
|
63 | 63 |
///This function starts seeking the beginning of the given file for the |
64 |
///problem type and size info. |
|
64 |
///problem type and size info. |
|
65 | 65 |
///The found data is returned in a special struct that can be evaluated |
66 | 66 |
///and passed to the appropriate reader function. |
67 | 67 |
DimacsDescriptor dimacsType(std::istream& is) |
68 | 68 |
{ |
... | ... |
@@ -211,9 +211,9 @@ |
211 | 211 |
if(infty==0) |
212 | 212 |
infty = std::numeric_limits<Capacity>::has_infinity ? |
213 | 213 |
std::numeric_limits<Capacity>::infinity() : |
214 | 214 |
std::numeric_limits<Capacity>::max(); |
215 |
|
|
215 |
|
|
216 | 216 |
while (is >> c) { |
217 | 217 |
switch (c) { |
218 | 218 |
case 'c': // comment line |
219 | 219 |
getline(is, str); |
... | ... |
@@ -236,9 +236,9 @@ |
236 | 236 |
is >> i >> j >> _cap; |
237 | 237 |
getline(is, str); |
238 | 238 |
e = g.addArc(nodes[i], nodes[j]); |
239 | 239 |
capacity.set(e, _cap); |
240 |
} |
|
240 |
} |
|
241 | 241 |
else if (desc.type==DimacsDescriptor::MAX) { |
242 | 242 |
is >> i >> j >> _cap; |
243 | 243 |
getline(is, str); |
244 | 244 |
e = g.addArc(nodes[i], nodes[j]); |
... | ... |
@@ -361,13 +361,13 @@ |
361 | 361 |
dummy<1> = 1) |
362 | 362 |
{ |
363 | 363 |
g.addArc(s,t); |
364 | 364 |
} |
365 |
|
|
365 |
|
|
366 | 366 |
/// \brief DIMACS plain (di)graph reader function. |
367 | 367 |
/// |
368 | 368 |
/// This function reads a plain (di)graph without any designated nodes |
369 |
/// and maps (e.g. a matching instance) from DIMACS format, i.e. from |
|
369 |
/// and maps (e.g. a matching instance) from DIMACS format, i.e. from |
|
370 | 370 |
/// DIMACS files having a line starting with |
371 | 371 |
/// \code |
372 | 372 |
/// p mat |
373 | 373 |
/// \endcode |
... | ... |
@@ -391,9 +391,9 @@ |
391 | 391 |
nodes.resize(desc.nodeNum + 1); |
392 | 392 |
for (int k = 1; k <= desc.nodeNum; ++k) { |
393 | 393 |
nodes[k] = g.addNode(); |
394 | 394 |
} |
395 |
|
|
395 |
|
|
396 | 396 |
while (is >> c) { |
397 | 397 |
switch (c) { |
398 | 398 |
case 'c': // comment line |
399 | 399 |
getline(is, str); |
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-2010 |
|
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 |
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-2010 |
|
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 |
... | ... |
@@ -25,9 +25,9 @@ |
25 | 25 |
#include <list> |
26 | 26 |
|
27 | 27 |
/// \ingroup graph_properties |
28 | 28 |
/// \file |
29 |
/// \brief Euler tour iterators and a function for checking the \e Eulerian |
|
29 |
/// \brief Euler tour iterators and a function for checking the \e Eulerian |
|
30 | 30 |
/// property. |
31 | 31 |
/// |
32 | 32 |
///This file provides Euler tour iterators and a function to check |
33 | 33 |
///if a (di)graph is \e Eulerian. |
... | ... |
@@ -40,9 +40,9 @@ |
40 | 40 |
///This iterator provides an Euler tour (Eulerian circuit) of a \e directed |
41 | 41 |
///graph (if there exists) and it converts to the \c Arc type of the digraph. |
42 | 42 |
/// |
43 | 43 |
///For example, if the given digraph has an Euler tour (i.e it has only one |
44 |
///non-trivial component and the in-degree is equal to the out-degree |
|
44 |
///non-trivial component and the in-degree is equal to the out-degree |
|
45 | 45 |
///for all nodes), then the following code will put the arcs of \c g |
46 | 46 |
///to the vector \c et according to an Euler tour of \c g. |
47 | 47 |
///\code |
48 | 48 |
/// std::vector<ListDigraph::Arc> et; |
... | ... |
@@ -137,18 +137,18 @@ |
137 | 137 |
///This iterator provides an Euler tour (Eulerian circuit) of an |
138 | 138 |
///\e undirected graph (if there exists) and it converts to the \c Arc |
139 | 139 |
///and \c Edge types of the graph. |
140 | 140 |
/// |
141 |
///For example, if the given graph has an Euler tour (i.e it has only one |
|
141 |
///For example, if the given graph has an Euler tour (i.e it has only one |
|
142 | 142 |
///non-trivial component and the degree of each node is even), |
143 | 143 |
///the following code will print the arc IDs according to an |
144 | 144 |
///Euler tour of \c g. |
145 | 145 |
///\code |
146 | 146 |
/// for(EulerIt<ListGraph> e(g); e!=INVALID; ++e) { |
147 | 147 |
/// std::cout << g.id(Edge(e)) << std::eol; |
148 | 148 |
/// } |
149 | 149 |
///\endcode |
150 |
///Although this iterator is for undirected graphs, it still returns |
|
150 |
///Although this iterator is for undirected graphs, it still returns |
|
151 | 151 |
///arcs in order to indicate the direction of the tour. |
152 | 152 |
///(But arcs convert to edges, of course.) |
153 | 153 |
/// |
154 | 154 |
///If \c g has no Euler tour, then the resulted walk will not be closed |
... | ... |
@@ -232,9 +232,9 @@ |
232 | 232 |
///Postfix incrementation |
233 | 233 |
|
234 | 234 |
/// Postfix incrementation. |
235 | 235 |
/// |
236 |
///\warning This incrementation returns an \c Arc (which converts to |
|
236 |
///\warning This incrementation returns an \c Arc (which converts to |
|
237 | 237 |
///an \c Edge), not an \ref EulerIt, as one may expect. |
238 | 238 |
Arc operator++(int) |
239 | 239 |
{ |
240 | 240 |
Arc e=*this; |
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-2010 |
|
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 |
... | ... |
@@ -2008,9 +2008,9 @@ |
2008 | 2008 |
} |
2009 | 2009 |
|
2010 | 2010 |
/// \brief Run the algorithm. |
2011 | 2011 |
/// |
2012 |
/// This method runs the \c %MaxWeightedPerfectFractionalMatching |
|
2012 |
/// This method runs the \c %MaxWeightedPerfectFractionalMatching |
|
2013 | 2013 |
/// algorithm. |
2014 | 2014 |
/// |
2015 | 2015 |
/// \note mwfm.run() is just a shortcut of the following code. |
2016 | 2016 |
/// \code |
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-2010 |
|
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 |
... | ... |
@@ -202,18 +202,18 @@ |
202 | 202 |
} |
203 | 203 |
|
204 | 204 |
/// \brief Returns the node with the given index. |
205 | 205 |
/// |
206 |
/// Returns the node with the given index. Since this structure is |
|
206 |
/// Returns the node with the given index. Since this structure is |
|
207 | 207 |
/// completely static, the nodes can be indexed with integers from |
208 | 208 |
/// the range <tt>[0..nodeNum()-1]</tt>. |
209 | 209 |
/// The index of a node is the same as its ID. |
210 | 210 |
/// \sa index() |
211 | 211 |
Node operator()(int ix) const { return Parent::operator()(ix); } |
212 | 212 |
|
213 | 213 |
/// \brief Returns the index of the given node. |
214 | 214 |
/// |
215 |
/// Returns the index of the given node. Since this structure is |
|
215 |
/// Returns the index of the given node. Since this structure is |
|
216 | 216 |
/// completely static, the nodes can be indexed with integers from |
217 | 217 |
/// the range <tt>[0..nodeNum()-1]</tt>. |
218 | 218 |
/// The index of a node is the same as its ID. |
219 | 219 |
/// \sa operator()() |
... | ... |
@@ -581,18 +581,18 @@ |
581 | 581 |
} |
582 | 582 |
|
583 | 583 |
/// \brief Returns the node with the given index. |
584 | 584 |
/// |
585 |
/// Returns the node with the given index. Since this structure is |
|
585 |
/// Returns the node with the given index. Since this structure is |
|
586 | 586 |
/// completely static, the nodes can be indexed with integers from |
587 | 587 |
/// the range <tt>[0..nodeNum()-1]</tt>. |
588 | 588 |
/// The index of a node is the same as its ID. |
589 | 589 |
/// \sa index() |
590 | 590 |
Node operator()(int ix) const { return Parent::operator()(ix); } |
591 | 591 |
|
592 | 592 |
/// \brief Returns the index of the given node. |
593 | 593 |
/// |
594 |
/// Returns the index of the given node. Since this structure is |
|
594 |
/// Returns the index of the given node. Since this structure is |
|
595 | 595 |
/// completely static, the nodes can be indexed with integers from |
596 | 596 |
/// the range <tt>[0..nodeNum()-1]</tt>. |
597 | 597 |
/// The index of a node is the same as its ID. |
598 | 598 |
/// \sa operator()() |
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-2010 |
|
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 |
... | ... |
@@ -58,22 +58,22 @@ |
58 | 58 |
glp_set_row_bnds(lp, i, GLP_FR, 0.0, 0.0); |
59 | 59 |
return i; |
60 | 60 |
} |
61 | 61 |
|
62 |
int GlpkBase::_addRow(Value lo, ExprIterator b, |
|
62 |
int GlpkBase::_addRow(Value lo, ExprIterator b, |
|
63 | 63 |
ExprIterator e, Value up) { |
64 | 64 |
int i = glp_add_rows(lp, 1); |
65 | 65 |
|
66 | 66 |
if (lo == -INF) { |
67 | 67 |
if (up == INF) { |
68 | 68 |
glp_set_row_bnds(lp, i, GLP_FR, lo, up); |
69 | 69 |
} else { |
70 | 70 |
glp_set_row_bnds(lp, i, GLP_UP, lo, up); |
71 |
} |
|
71 |
} |
|
72 | 72 |
} else { |
73 | 73 |
if (up == INF) { |
74 | 74 |
glp_set_row_bnds(lp, i, GLP_LO, lo, up); |
75 |
} else if (lo != up) { |
|
75 |
} else if (lo != up) { |
|
76 | 76 |
glp_set_row_bnds(lp, i, GLP_DB, lo, up); |
77 | 77 |
} else { |
78 | 78 |
glp_set_row_bnds(lp, i, GLP_FX, lo, up); |
79 | 79 |
} |
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-2010 |
|
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 |
... | ... |
@@ -29,18 +29,18 @@ |
29 | 29 |
|
30 | 30 |
namespace _solver_bits { |
31 | 31 |
class VoidPtr { |
32 | 32 |
private: |
33 |
void *_ptr; |
|
33 |
void *_ptr; |
|
34 | 34 |
public: |
35 | 35 |
VoidPtr() : _ptr(0) {} |
36 | 36 |
|
37 | 37 |
template <typename T> |
38 | 38 |
VoidPtr(T* ptr) : _ptr(reinterpret_cast<void*>(ptr)) {} |
39 | 39 |
|
40 | 40 |
template <typename T> |
41 |
VoidPtr& operator=(T* ptr) { |
|
42 |
_ptr = reinterpret_cast<void*>(ptr); |
|
41 |
VoidPtr& operator=(T* ptr) { |
|
42 |
_ptr = reinterpret_cast<void*>(ptr); |
|
43 | 43 |
return *this; |
44 | 44 |
} |
45 | 45 |
|
46 | 46 |
template <typename T> |
... | ... |
@@ -123,15 +123,15 @@ |
123 | 123 |
~FreeEnvHelper() { |
124 | 124 |
freeEnv(); |
125 | 125 |
} |
126 | 126 |
}; |
127 |
|
|
127 |
|
|
128 | 128 |
static FreeEnvHelper freeEnvHelper; |
129 | 129 |
|
130 | 130 |
protected: |
131 |
|
|
131 |
|
|
132 | 132 |
int _message_level; |
133 |
|
|
133 |
|
|
134 | 134 |
public: |
135 | 135 |
|
136 | 136 |
///Pointer to the underlying GLPK data structure. |
137 | 137 |
_solver_bits::VoidPtr lpx() {return lp;} |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 |
* Copyright (C) 2003- |
|
5 |
* Copyright (C) 2003-2010 |
|
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 |
... | ... |
@@ -26,9 +26,9 @@ |
26 | 26 |
#include <lemon/concept_check.h> |
27 | 27 |
#include <lemon/concepts/maps.h> |
28 | 28 |
|
29 | 29 |
/// \ingroup min_cut |
30 |
/// \file |
|
30 |
/// \file |
|
31 | 31 |
/// \brief Gomory-Hu cut tree in graphs. |
32 | 32 |
|
33 | 33 |
namespace lemon { |
34 | 34 |
|
... | ... |
@@ -37,15 +37,15 @@ |
37 | 37 |
/// \brief Gomory-Hu cut tree algorithm |
38 | 38 |
/// |
39 | 39 |
/// The Gomory-Hu tree is a tree on the node set of a given graph, but it |
40 | 40 |
/// may contain edges which are not in the original graph. It has the |
41 |
/// property that the minimum capacity edge of the path between two nodes |
|
41 |
/// property that the minimum capacity edge of the path between two nodes |
|
42 | 42 |
/// in this tree has the same weight as the minimum cut in the graph |
43 | 43 |
/// between these nodes. Moreover the components obtained by removing |
44 | 44 |
/// this edge from the tree determine the corresponding minimum cut. |
45 | 45 |
/// Therefore once this tree is computed, the minimum cut between any pair |
46 | 46 |
/// of nodes can easily be obtained. |
47 |
/// |
|
47 |
/// |
|
48 | 48 |
/// The algorithm calculates \e n-1 distinct minimum cuts (currently with |
49 | 49 |
/// the \ref Preflow algorithm), thus it has \f$O(n^3\sqrt{e})\f$ overall |
50 | 50 |
/// time complexity. It calculates a rooted Gomory-Hu tree. |
51 | 51 |
/// The structure of the tree and the edge weights can be |
... | ... |
@@ -59,12 +59,12 @@ |
59 | 59 |
/// \tparam CAP The type of the edge map containing the capacities. |
60 | 60 |
/// The default map type is \ref concepts::Graph::EdgeMap "GR::EdgeMap<int>". |
61 | 61 |
#ifdef DOXYGEN |
62 | 62 |
template <typename GR, |
63 |
|
|
63 |
typename CAP> |
|
64 | 64 |
#else |
65 | 65 |
template <typename GR, |
66 |
|
|
66 |
typename CAP = typename GR::template EdgeMap<int> > |
|
67 | 67 |
#endif |
68 | 68 |
class GomoryHu { |
69 | 69 |
public: |
70 | 70 |
|
... | ... |
@@ -73,9 +73,9 @@ |
73 | 73 |
/// The capacity map type of the algorithm |
74 | 74 |
typedef CAP Capacity; |
75 | 75 |
/// The value type of capacities |
76 | 76 |
typedef typename Capacity::Value Value; |
77 |
|
|
77 |
|
|
78 | 78 |
private: |
79 | 79 |
|
80 | 80 |
TEMPLATE_GRAPH_TYPEDEFS(Graph); |
81 | 81 |
|
... | ... |
@@ -88,40 +88,40 @@ |
88 | 88 |
typename Graph::template NodeMap<int>* _order; |
89 | 89 |
|
90 | 90 |
void createStructures() { |
91 | 91 |
if (!_pred) { |
92 |
|
|
92 |
_pred = new typename Graph::template NodeMap<Node>(_graph); |
|
93 | 93 |
} |
94 | 94 |
if (!_weight) { |
95 |
|
|
95 |
_weight = new typename Graph::template NodeMap<Value>(_graph); |
|
96 | 96 |
} |
97 | 97 |
if (!_order) { |
98 |
|
|
98 |
_order = new typename Graph::template NodeMap<int>(_graph); |
|
99 | 99 |
} |
100 | 100 |
} |
101 | 101 |
|
102 | 102 |
void destroyStructures() { |
103 | 103 |
if (_pred) { |
104 |
|
|
104 |
delete _pred; |
|
105 | 105 |
} |
106 | 106 |
if (_weight) { |
107 |
|
|
107 |
delete _weight; |
|
108 | 108 |
} |
109 | 109 |
if (_order) { |
110 |
|
|
110 |
delete _order; |
|
111 | 111 |
} |
112 | 112 |
} |
113 |
|
|
113 |
|
|
114 | 114 |
public: |
115 | 115 |
|
116 | 116 |
/// \brief Constructor |
117 | 117 |
/// |
118 | 118 |
/// Constructor. |
119 | 119 |
/// \param graph The undirected graph the algorithm runs on. |
120 | 120 |
/// \param capacity The edge capacity map. |
121 |
GomoryHu(const Graph& graph, const Capacity& capacity) |
|
121 |
GomoryHu(const Graph& graph, const Capacity& capacity) |
|
122 | 122 |
: _graph(graph), _capacity(capacity), |
123 |
|
|
123 |
_pred(0), _weight(0), _order(0) |
|
124 | 124 |
{ |
125 | 125 |
checkConcept<concepts::ReadMap<Edge, Value>, Capacity>(); |
126 | 126 |
} |
127 | 127 |
|
... | ... |
@@ -133,9 +133,9 @@ |
133 | 133 |
destroyStructures(); |
134 | 134 |
} |
135 | 135 |
|
136 | 136 |
private: |
137 |
|
|
137 |
|
|
138 | 138 |
// Initialize the internal data structures |
139 | 139 |
void init() { |
140 | 140 |
createStructures(); |
141 | 141 |
|
... | ... |
@@ -144,61 +144,61 @@ |
144 | 144 |
(*_pred)[n] = _root; |
145 | 145 |
(*_order)[n] = -1; |
146 | 146 |
} |
147 | 147 |
(*_pred)[_root] = INVALID; |
148 |
(*_weight)[_root] = std::numeric_limits<Value>::max(); |
|
148 |
(*_weight)[_root] = std::numeric_limits<Value>::max(); |
|
149 | 149 |
} |
150 | 150 |
|
151 | 151 |
|
152 | 152 |
// Start the algorithm |
153 | 153 |
void start() { |
154 | 154 |
Preflow<Graph, Capacity> fa(_graph, _capacity, _root, INVALID); |
155 | 155 |
|
156 | 156 |
for (NodeIt n(_graph); n != INVALID; ++n) { |
157 |
|
|
157 |
if (n == _root) continue; |
|
158 | 158 |
|
159 |
Node pn = (*_pred)[n]; |
|
160 |
fa.source(n); |
|
161 |
|
|
159 |
Node pn = (*_pred)[n]; |
|
160 |
fa.source(n); |
|
161 |
fa.target(pn); |
|
162 | 162 |
|
163 |
|
|
163 |
fa.runMinCut(); |
|
164 | 164 |
|
165 |
|
|
165 |
(*_weight)[n] = fa.flowValue(); |
|
166 | 166 |
|
167 |
for (NodeIt nn(_graph); nn != INVALID; ++nn) { |
|
168 |
if (nn != n && fa.minCut(nn) && (*_pred)[nn] == pn) { |
|
169 |
(*_pred)[nn] = n; |
|
170 |
} |
|
171 |
} |
|
172 |
if ((*_pred)[pn] != INVALID && fa.minCut((*_pred)[pn])) { |
|
173 |
(*_pred)[n] = (*_pred)[pn]; |
|
174 |
(*_pred)[pn] = n; |
|
175 |
(*_weight)[n] = (*_weight)[pn]; |
|
176 |
(*_weight)[pn] = fa.flowValue(); |
|
177 |
|
|
167 |
for (NodeIt nn(_graph); nn != INVALID; ++nn) { |
|
168 |
if (nn != n && fa.minCut(nn) && (*_pred)[nn] == pn) { |
|
169 |
(*_pred)[nn] = n; |
|
170 |
} |
|
171 |
} |
|
172 |
if ((*_pred)[pn] != INVALID && fa.minCut((*_pred)[pn])) { |
|
173 |
(*_pred)[n] = (*_pred)[pn]; |
|
174 |
(*_pred)[pn] = n; |
|
175 |
(*_weight)[n] = (*_weight)[pn]; |
|
176 |
(*_weight)[pn] = fa.flowValue(); |
|
177 |
} |
|
178 | 178 |
} |
179 | 179 |
|
180 | 180 |
(*_order)[_root] = 0; |
181 | 181 |
int index = 1; |
182 | 182 |
|
183 | 183 |
for (NodeIt n(_graph); n != INVALID; ++n) { |
184 |
std::vector<Node> st; |
|
185 |
Node nn = n; |
|
186 |
while ((*_order)[nn] == -1) { |
|
187 |
st.push_back(nn); |
|
188 |
nn = (*_pred)[nn]; |
|
189 |
} |
|
190 |
while (!st.empty()) { |
|
191 |
(*_order)[st.back()] = index++; |
|
192 |
st.pop_back(); |
|
193 |
} |
|
184 |
std::vector<Node> st; |
|
185 |
Node nn = n; |
|
186 |
while ((*_order)[nn] == -1) { |
|
187 |
st.push_back(nn); |
|
188 |
nn = (*_pred)[nn]; |
|
189 |
} |
|
190 |
while (!st.empty()) { |
|
191 |
(*_order)[st.back()] = index++; |
|
192 |
st.pop_back(); |
|
193 |
} |
|
194 | 194 |
} |
195 | 195 |
} |
196 | 196 |
|
197 | 197 |
public: |
198 | 198 |
|
199 | 199 |
///\name Execution Control |
200 |
|
|
200 |
|
|
201 | 201 |
///@{ |
202 | 202 |
|
203 | 203 |
/// \brief Run the Gomory-Hu algorithm. |
204 | 204 |
/// |
... | ... |
@@ -206,9 +206,9 @@ |
206 | 206 |
void run() { |
207 | 207 |
init(); |
208 | 208 |
start(); |
209 | 209 |
} |
210 |
|
|
210 |
|
|
211 | 211 |
/// @} |
212 | 212 |
|
213 | 213 |
///\name Query Functions |
214 | 214 |
///The results of the algorithm can be obtained using these |
... | ... |
@@ -231,9 +231,9 @@ |
231 | 231 |
|
232 | 232 |
/// \brief Return the weight of the predecessor edge in the |
233 | 233 |
/// Gomory-Hu tree. |
234 | 234 |
/// |
235 |
/// This function returns the weight of the predecessor edge of the |
|
235 |
/// This function returns the weight of the predecessor edge of the |
|
236 | 236 |
/// given node in the Gomory-Hu tree. |
237 | 237 |
/// If \c node is the root of the tree, the result is undefined. |
238 | 238 |
/// |
239 | 239 |
/// \pre \ref run() must be called before using this function. |
... | ... |
@@ -253,26 +253,26 @@ |
253 | 253 |
|
254 | 254 |
/// \brief Return the minimum cut value between two nodes |
255 | 255 |
/// |
256 | 256 |
/// This function returns the minimum cut value between the nodes |
257 |
/// \c s and \c t. |
|
257 |
/// \c s and \c t. |
|
258 | 258 |
/// It finds the nearest common ancestor of the given nodes in the |
259 | 259 |
/// Gomory-Hu tree and calculates the minimum weight edge on the |
260 | 260 |
/// paths to the ancestor. |
261 | 261 |
/// |
262 | 262 |
/// \pre \ref run() must be called before using this function. |
263 | 263 |
Value minCutValue(const Node& s, const Node& t) const { |
264 | 264 |
Node sn = s, tn = t; |
265 | 265 |
Value value = std::numeric_limits<Value>::max(); |
266 |
|
|
266 |
|
|
267 | 267 |
while (sn != tn) { |
268 |
if ((*_order)[sn] < (*_order)[tn]) { |
|
269 |
if ((*_weight)[tn] <= value) value = (*_weight)[tn]; |
|
270 |
tn = (*_pred)[tn]; |
|
271 |
} else { |
|
272 |
if ((*_weight)[sn] <= value) value = (*_weight)[sn]; |
|
273 |
sn = (*_pred)[sn]; |
|
274 |
|
|
268 |
if ((*_order)[sn] < (*_order)[tn]) { |
|
269 |
if ((*_weight)[tn] <= value) value = (*_weight)[tn]; |
|
270 |
tn = (*_pred)[tn]; |
|
271 |
} else { |
|
272 |
if ((*_weight)[sn] <= value) value = (*_weight)[sn]; |
|
273 |
sn = (*_pred)[sn]; |
|
274 |
} |
|
275 | 275 |
} |
276 | 276 |
return value; |
277 | 277 |
} |
278 | 278 |
|
... | ... |
@@ -301,25 +301,25 @@ |
301 | 301 |
Node sn = s, tn = t; |
302 | 302 |
bool s_root=false; |
303 | 303 |
Node rn = INVALID; |
304 | 304 |
Value value = std::numeric_limits<Value>::max(); |
305 |
|
|
305 |
|
|
306 | 306 |
while (sn != tn) { |
307 |
if ((*_order)[sn] < (*_order)[tn]) { |
|
308 |
if ((*_weight)[tn] <= value) { |
|
309 |
|
|
307 |
if ((*_order)[sn] < (*_order)[tn]) { |
|
308 |
if ((*_weight)[tn] <= value) { |
|
309 |
rn = tn; |
|
310 | 310 |
s_root = false; |
311 |
value = (*_weight)[tn]; |
|
312 |
} |
|
313 |
tn = (*_pred)[tn]; |
|
314 |
} else { |
|
315 |
if ((*_weight)[sn] <= value) { |
|
316 |
rn = sn; |
|
311 |
value = (*_weight)[tn]; |
|
312 |
} |
|
313 |
tn = (*_pred)[tn]; |
|
314 |
} else { |
|
315 |
if ((*_weight)[sn] <= value) { |
|
316 |
rn = sn; |
|
317 | 317 |
s_root = true; |
318 |
value = (*_weight)[sn]; |
|
319 |
} |
|
320 |
sn = (*_pred)[sn]; |
|
321 |
} |
|
318 |
value = (*_weight)[sn]; |
|
319 |
} |
|
320 |
sn = (*_pred)[sn]; |
|
321 |
} |
|
322 | 322 |
} |
323 | 323 |
|
324 | 324 |
typename Graph::template NodeMap<bool> reached(_graph, false); |
325 | 325 |
reached[_root] = true; |
... | ... |
@@ -328,29 +328,29 @@ |
328 | 328 |
cutMap.set(rn, s_root); |
329 | 329 |
|
330 | 330 |
std::vector<Node> st; |
331 | 331 |
for (NodeIt n(_graph); n != INVALID; ++n) { |
332 |
|
|
332 |
st.clear(); |
|
333 | 333 |
Node nn = n; |
334 |
while (!reached[nn]) { |
|
335 |
st.push_back(nn); |
|
336 |
nn = (*_pred)[nn]; |
|
337 |
} |
|
338 |
while (!st.empty()) { |
|
339 |
cutMap.set(st.back(), cutMap[nn]); |
|
340 |
st.pop_back(); |
|
341 |
} |
|
334 |
while (!reached[nn]) { |
|
335 |
st.push_back(nn); |
|
336 |
nn = (*_pred)[nn]; |
|
337 |
} |
|
338 |
while (!st.empty()) { |
|
339 |
cutMap.set(st.back(), cutMap[nn]); |
|
340 |
st.pop_back(); |
|
341 |
} |
|
342 | 342 |
} |
343 |
|
|
343 |
|
|
344 | 344 |
return value; |
345 | 345 |
} |
346 | 346 |
|
347 | 347 |
///@} |
348 | 348 |
|
349 | 349 |
friend class MinCutNodeIt; |
350 | 350 |
|
351 | 351 |
/// Iterate on the nodes of a minimum cut |
352 |
|
|
352 |
|
|
353 | 353 |
/// This iterator class lists the nodes of a minimum cut found by |
354 | 354 |
/// GomoryHu. Before using it, you must allocate a GomoryHu class |
355 | 355 |
/// and call its \ref GomoryHu::run() "run()" method. |
356 | 356 |
/// |
... | ... |
@@ -441,13 +441,13 @@ |
441 | 441 |
++(*this); |
442 | 442 |
return n; |
443 | 443 |
} |
444 | 444 |
}; |
445 |
|
|
445 |
|
|
446 | 446 |
friend class MinCutEdgeIt; |
447 |
|
|
447 |
|
|
448 | 448 |
/// Iterate on the edges of a minimum cut |
449 |
|
|
449 |
|
|
450 | 450 |
/// This iterator class lists the edges of a minimum cut found by |
451 | 451 |
/// GomoryHu. Before using it, you must allocate a GomoryHu class |
452 | 452 |
/// and call its \ref GomoryHu::run() "run()" method. |
453 | 453 |
/// |
... | ... |
@@ -478,9 +478,9 @@ |
478 | 478 |
if(_node_it!=INVALID) |
479 | 479 |
_arc_it=typename Graph::OutArcIt(_graph,_node_it); |
480 | 480 |
} |
481 | 481 |
} |
482 |
|
|
482 |
|
|
483 | 483 |
public: |
484 | 484 |
/// Constructor |
485 | 485 |
|
486 | 486 |
/// Constructor. |
... | ... |
@@ -547,9 +547,9 @@ |
547 | 547 |
while(_arc_it!=INVALID && _cut[_graph.target(_arc_it)]) step(); |
548 | 548 |
return *this; |
549 | 549 |
} |
550 | 550 |
/// Postfix incrementation |
551 |
|
|
551 |
|
|
552 | 552 |
/// Postfix incrementation. |
553 | 553 |
/// |
554 | 554 |
/// \warning This incrementation |
555 | 555 |
/// returns an \c Arc, not a \c MinCutEdgeIt, as one may expect. |
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-2010 |
|
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 |
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-2010 |
|
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 |
... | ... |
@@ -30,9 +30,9 @@ |
30 | 30 |
/// \file |
31 | 31 |
/// \ingroup min_cut |
32 | 32 |
/// \brief Implementation of the Hao-Orlin algorithm. |
33 | 33 |
/// |
34 |
/// Implementation of the Hao-Orlin algorithm for finding a minimum cut |
|
34 |
/// Implementation of the Hao-Orlin algorithm for finding a minimum cut |
|
35 | 35 |
/// in a digraph. |
36 | 36 |
|
37 | 37 |
namespace lemon { |
38 | 38 |
|
... | ... |
@@ -40,9 +40,9 @@ |
40 | 40 |
/// |
41 | 41 |
/// \brief Hao-Orlin algorithm for finding a minimum cut in a digraph. |
42 | 42 |
/// |
43 | 43 |
/// This class implements the Hao-Orlin algorithm for finding a minimum |
44 |
/// value cut in a directed graph \f$D=(V,A)\f$. |
|
44 |
/// value cut in a directed graph \f$D=(V,A)\f$. |
|
45 | 45 |
/// It takes a fixed node \f$ source \in V \f$ and |
46 | 46 |
/// consists of two phases: in the first phase it determines a |
47 | 47 |
/// minimum cut with \f$ source \f$ on the source-side (i.e. a set |
48 | 48 |
/// \f$ X\subsetneq V \f$ with \f$ source \in X \f$ and minimal outgoing |
... | ... |
@@ -57,9 +57,9 @@ |
57 | 57 |
/// purpose of such algorithm is e.g. testing network reliability. |
58 | 58 |
/// |
59 | 59 |
/// For an undirected graph you can run just the first phase of the |
60 | 60 |
/// algorithm or you can use the algorithm of Nagamochi and Ibaraki, |
61 |
/// which solves the undirected problem in \f$ O(nm + n^2 \log n) \f$ |
|
61 |
/// which solves the undirected problem in \f$ O(nm + n^2 \log n) \f$ |
|
62 | 62 |
/// time. It is implemented in the NagamochiIbaraki algorithm class. |
63 | 63 |
/// |
64 | 64 |
/// \tparam GR The type of the digraph the algorithm runs on. |
65 | 65 |
/// \tparam CAP The type of the arc map containing the capacities, |
... | ... |
@@ -75,9 +75,9 @@ |
75 | 75 |
typename TOL = Tolerance<typename CAP::Value> > |
76 | 76 |
#endif |
77 | 77 |
class HaoOrlin { |
78 | 78 |
public: |
79 |
|
|
79 |
|
|
80 | 80 |
/// The digraph type of the algorithm |
81 | 81 |
typedef GR Digraph; |
82 | 82 |
/// The capacity map type of the algorithm |
83 | 83 |
typedef CAP CapacityMap; |
... | ... |
@@ -863,9 +863,9 @@ |
863 | 863 |
|
864 | 864 |
/// \brief Initialize the internal data structures. |
865 | 865 |
/// |
866 | 866 |
/// This function initializes the internal data structures. It creates |
867 |
/// the maps and some bucket structures for the algorithm. |
|
867 |
/// the maps and some bucket structures for the algorithm. |
|
868 | 868 |
/// The given node is used as the source node for the push-relabel |
869 | 869 |
/// algorithm. |
870 | 870 |
void init(const Node& source) { |
871 | 871 |
_source = source; |
... | ... |
@@ -943,9 +943,9 @@ |
943 | 943 |
} |
944 | 944 |
|
945 | 945 |
/// \brief Run the algorithm. |
946 | 946 |
/// |
947 |
/// This function runs the algorithm. It uses the given \c source node, |
|
947 |
/// This function runs the algorithm. It uses the given \c source node, |
|
948 | 948 |
/// finds a proper \c target node and then calls the \ref init(), |
949 | 949 |
/// \ref calculateOut() and \ref calculateIn(). |
950 | 950 |
void run(const Node& s) { |
951 | 951 |
init(s); |
... | ... |
@@ -957,18 +957,18 @@ |
957 | 957 |
|
958 | 958 |
/// \name Query Functions |
959 | 959 |
/// The result of the %HaoOrlin algorithm |
960 | 960 |
/// can be obtained using these functions.\n |
961 |
/// \ref run(), \ref calculateOut() or \ref calculateIn() |
|
961 |
/// \ref run(), \ref calculateOut() or \ref calculateIn() |
|
962 | 962 |
/// should be called before using them. |
963 | 963 |
|
964 | 964 |
/// @{ |
965 | 965 |
|
966 | 966 |
/// \brief Return the value of the minimum cut. |
967 | 967 |
/// |
968 | 968 |
/// This function returns the value of the minimum cut. |
969 | 969 |
/// |
970 |
/// \pre \ref run(), \ref calculateOut() or \ref calculateIn() |
|
970 |
/// \pre \ref run(), \ref calculateOut() or \ref calculateIn() |
|
971 | 971 |
/// must be called before using this function. |
972 | 972 |
Value minCutValue() const { |
973 | 973 |
return _min_cut; |
974 | 974 |
} |
... | ... |
@@ -985,9 +985,9 @@ |
985 | 985 |
/// \c bool (or convertible) value type. |
986 | 986 |
/// |
987 | 987 |
/// \return The value of the minimum cut. |
988 | 988 |
/// |
989 |
/// \pre \ref run(), \ref calculateOut() or \ref calculateIn() |
|
989 |
/// \pre \ref run(), \ref calculateOut() or \ref calculateIn() |
|
990 | 990 |
/// must be called before using this function. |
991 | 991 |
template <typename CutMap> |
992 | 992 |
Value minCutMap(CutMap& cutMap) const { |
993 | 993 |
for (NodeIt it(_graph); it != INVALID; ++it) { |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 |
* Copyright (C) 2003- |
|
5 |
* Copyright (C) 2003-2010 |
|
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 |
... | ... |
@@ -342,16 +342,16 @@ |
342 | 342 |
bool findCycleMean() { |
343 | 343 |
// Initialization and find strongly connected components |
344 | 344 |
init(); |
345 | 345 |
findComponents(); |
346 |
|
|
346 |
|
|
347 | 347 |
// Find the minimum cycle mean in the components |
348 | 348 |
for (int comp = 0; comp < _comp_num; ++comp) { |
349 | 349 |
if (!initComponent(comp)) continue; |
350 | 350 |
processRounds(); |
351 |
|
|
351 |
|
|
352 | 352 |
// Update the best cycle (global minimum mean cycle) |
353 |
if ( _curr_found && (!_best_found || |
|
353 |
if ( _curr_found && (!_best_found || |
|
354 | 354 |
_curr_cost * _best_size < _best_cost * _curr_size) ) { |
355 | 355 |
_best_found = true; |
356 | 356 |
_best_cost = _curr_cost; |
357 | 357 |
_best_size = _curr_size; |
... | ... |
@@ -502,9 +502,9 @@ |
502 | 502 |
_nodes = &(_comp_nodes[comp]); |
503 | 503 |
int n = _nodes->size(); |
504 | 504 |
if (n < 1 || (n == 1 && _out_arcs[(*_nodes)[0]].size() == 0)) { |
505 | 505 |
return false; |
506 |
} |
|
506 |
} |
|
507 | 507 |
for (int i = 0; i < n; ++i) { |
508 | 508 |
_data[(*_nodes)[i]].resize(n + 1, PathData(INF)); |
509 | 509 |
} |
510 | 510 |
return true; |
... | ... |
@@ -575,9 +575,9 @@ |
575 | 575 |
} |
576 | 576 |
} |
577 | 577 |
} |
578 | 578 |
} |
579 |
|
|
579 |
|
|
580 | 580 |
// Check early termination |
581 | 581 |
bool checkTermination(int k) { |
582 | 582 |
typedef std::pair<int, int> Pair; |
583 | 583 |
typename GR::template NodeMap<Pair> level(_gr, Pair(-1, 0)); |
... | ... |
@@ -585,9 +585,9 @@ |
585 | 585 |
int n = _nodes->size(); |
586 | 586 |
LargeCost cost; |
587 | 587 |
int size; |
588 | 588 |
Node u; |
589 |
|
|
589 |
|
|
590 | 590 |
// Search for cycles that are already found |
591 | 591 |
_curr_found = false; |
592 | 592 |
for (int i = 0; i < n; ++i) { |
593 | 593 |
u = (*_nodes)[i]; |
... | ... |
@@ -606,10 +606,10 @@ |
606 | 606 |
} |
607 | 607 |
} |
608 | 608 |
level[u] = Pair(i, j); |
609 | 609 |
if (j != 0) { |
610 |
u = _gr.source(_data[u][j].pred); |
|
611 |
} |
|
610 |
u = _gr.source(_data[u][j].pred); |
|
611 |
} |
|
612 | 612 |
} |
613 | 613 |
} |
614 | 614 |
|
615 | 615 |
// If at least one cycle is found, check the optimality condition |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 |
* Copyright (C) 2003- |
|
5 |
* Copyright (C) 2003-2010 |
|
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 |
... | ... |
@@ -120,9 +120,9 @@ |
120 | 120 |
#endif |
121 | 121 |
class HowardMmc |
122 | 122 |
{ |
123 | 123 |
public: |
124 |
|
|
124 |
|
|
125 | 125 |
/// The type of the digraph |
126 | 126 |
typedef typename TR::Digraph Digraph; |
127 | 127 |
/// The type of the cost map |
128 | 128 |
typedef typename TR::CostMap CostMap; |
... | ... |
@@ -151,9 +151,9 @@ |
151 | 151 |
|
152 | 152 |
private: |
153 | 153 |
|
154 | 154 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
155 |
|
|
155 |
|
|
156 | 156 |
// The digraph the algorithm runs on |
157 | 157 |
const Digraph &_gr; |
158 | 158 |
// The cost of the arcs |
159 | 159 |
const CostMap &_cost; |
... | ... |
@@ -178,20 +178,20 @@ |
178 | 178 |
typename Digraph::template NodeMap<int> _comp; |
179 | 179 |
std::vector<std::vector<Node> > _comp_nodes; |
180 | 180 |
std::vector<Node>* _nodes; |
181 | 181 |
typename Digraph::template NodeMap<std::vector<Arc> > _in_arcs; |
182 |
|
|
182 |
|
|
183 | 183 |
// Queue used for BFS search |
184 | 184 |
std::vector<Node> _queue; |
185 | 185 |
int _qfront, _qback; |
186 | 186 |
|
187 | 187 |
Tolerance _tolerance; |
188 |
|
|
188 |
|
|
189 | 189 |
// Infinite constant |
190 | 190 |
const LargeCost INF; |
191 | 191 |
|
192 | 192 |
public: |
193 |
|
|
193 |
|
|
194 | 194 |
/// \name Named Template Parameters |
195 | 195 |
/// @{ |
196 | 196 |
|
197 | 197 |
template <typename T> |
... | ... |
@@ -227,9 +227,9 @@ |
227 | 227 |
struct SetPath |
228 | 228 |
: public HowardMmc<GR, CM, SetPathTraits<T> > { |
229 | 229 |
typedef HowardMmc<GR, CM, SetPathTraits<T> > Create; |
230 | 230 |
}; |
231 |
|
|
231 |
|
|
232 | 232 |
/// @} |
233 | 233 |
|
234 | 234 |
protected: |
235 | 235 |
|
... | ... |
@@ -333,9 +333,9 @@ |
333 | 333 |
bool findCycleMean() { |
334 | 334 |
// Initialize and find strongly connected components |
335 | 335 |
init(); |
336 | 336 |
findComponents(); |
337 |
|
|
337 |
|
|
338 | 338 |
// Find the minimum cycle mean in the components |
339 | 339 |
for (int comp = 0; comp < _comp_num; ++comp) { |
340 | 340 |
// Find the minimum mean cycle in the current component |
341 | 341 |
if (!buildPolicyGraph(comp)) continue; |
... | ... |
@@ -444,9 +444,9 @@ |
444 | 444 |
_best_cost = 0; |
445 | 445 |
_best_size = 1; |
446 | 446 |
_cycle_path->clear(); |
447 | 447 |
} |
448 |
|
|
448 |
|
|
449 | 449 |
// Find strongly connected components and initialize _comp_nodes |
450 | 450 |
// and _in_arcs |
451 | 451 |
void findComponents() { |
452 | 452 |
_comp_num = stronglyConnectedComponents(_gr, _comp); |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 |
* Copyright (C) 2003- |
|
5 |
* Copyright (C) 2003-2010 |
|
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 |
... | ... |
@@ -190,9 +190,9 @@ |
190 | 190 |
// The processed nodes in the last round |
191 | 191 |
std::vector<Node> _process; |
192 | 192 |
|
193 | 193 |
Tolerance _tolerance; |
194 |
|
|
194 |
|
|
195 | 195 |
// Infinite constant |
196 | 196 |
const LargeCost INF; |
197 | 197 |
|
198 | 198 |
public: |
... | ... |
@@ -338,9 +338,9 @@ |
338 | 338 |
bool findCycleMean() { |
339 | 339 |
// Initialization and find strongly connected components |
340 | 340 |
init(); |
341 | 341 |
findComponents(); |
342 |
|
|
342 |
|
|
343 | 343 |
// Find the minimum cycle mean in the components |
344 | 344 |
for (int comp = 0; comp < _comp_num; ++comp) { |
345 | 345 |
if (!initComponent(comp)) continue; |
346 | 346 |
processRounds(); |
... | ... |
@@ -488,9 +488,9 @@ |
488 | 488 |
_nodes = &(_comp_nodes[comp]); |
489 | 489 |
int n = _nodes->size(); |
490 | 490 |
if (n < 1 || (n == 1 && _out_arcs[(*_nodes)[0]].size() == 0)) { |
491 | 491 |
return false; |
492 |
} |
|
492 |
} |
|
493 | 493 |
for (int i = 0; i < n; ++i) { |
494 | 494 |
_data[(*_nodes)[i]].resize(n + 1, PathData(INF)); |
495 | 495 |
} |
496 | 496 |
return true; |
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-2010 |
|
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 |
... | ... |
@@ -561,9 +561,9 @@ |
561 | 561 |
|
562 | 562 |
template <typename TDGR> |
563 | 563 |
friend DigraphReader<TDGR> digraphReader(TDGR& digraph, std::istream& is); |
564 | 564 |
template <typename TDGR> |
565 |
friend DigraphReader<TDGR> digraphReader(TDGR& digraph, |
|
565 |
friend DigraphReader<TDGR> digraphReader(TDGR& digraph, |
|
566 | 566 |
const std::string& fn); |
567 | 567 |
template <typename TDGR> |
568 | 568 |
friend DigraphReader<TDGR> digraphReader(TDGR& digraph, const char *fn); |
569 | 569 |
|
... | ... |
@@ -1186,16 +1186,16 @@ |
1186 | 1186 |
|
1187 | 1187 |
/// @} |
1188 | 1188 |
|
1189 | 1189 |
}; |
1190 |
|
|
1190 |
|
|
1191 | 1191 |
/// \ingroup lemon_io |
1192 | 1192 |
/// |
1193 | 1193 |
/// \brief Return a \ref DigraphReader class |
1194 | 1194 |
/// |
1195 | 1195 |
/// This function just returns a \ref DigraphReader class. |
1196 | 1196 |
/// |
1197 |
/// With this function a digraph can be read from an |
|
1197 |
/// With this function a digraph can be read from an |
|
1198 | 1198 |
/// \ref lgf-format "LGF" file or input stream with several maps and |
1199 | 1199 |
/// attributes. For example, there is network flow problem on a |
1200 | 1200 |
/// digraph, i.e. a digraph with a \e capacity map on the arcs and |
1201 | 1201 |
/// \e source and \e target nodes. This digraph can be read with the |
... | ... |
@@ -1248,9 +1248,9 @@ |
1248 | 1248 |
} |
1249 | 1249 |
|
1250 | 1250 |
template <typename GR> |
1251 | 1251 |
class GraphReader; |
1252 |
|
|
1252 |
|
|
1253 | 1253 |
template <typename TGR> |
1254 | 1254 |
GraphReader<TGR> graphReader(TGR& graph, std::istream& is = std::cin); |
1255 | 1255 |
template <typename TGR> |
1256 | 1256 |
GraphReader<TGR> graphReader(TGR& graph, const std::string& fn); |
... | ... |
@@ -1385,9 +1385,9 @@ |
1385 | 1385 |
private: |
1386 | 1386 |
template <typename TGR> |
1387 | 1387 |
friend GraphReader<TGR> graphReader(TGR& graph, std::istream& is); |
1388 | 1388 |
template <typename TGR> |
1389 |
friend GraphReader<TGR> graphReader(TGR& graph, const std::string& fn); |
|
1389 |
friend GraphReader<TGR> graphReader(TGR& graph, const std::string& fn); |
|
1390 | 1390 |
template <typename TGR> |
1391 | 1391 |
friend GraphReader<TGR> graphReader(TGR& graph, const char *fn); |
1392 | 1392 |
|
1393 | 1393 |
GraphReader(GraphReader& other) |
... | ... |
@@ -2062,11 +2062,11 @@ |
2062 | 2062 |
/// \ingroup lemon_io |
2063 | 2063 |
/// |
2064 | 2064 |
/// \brief Return a \ref GraphReader class |
2065 | 2065 |
/// |
2066 |
/// This function just returns a \ref GraphReader class. |
|
2066 |
/// This function just returns a \ref GraphReader class. |
|
2067 | 2067 |
/// |
2068 |
/// With this function a graph can be read from an |
|
2068 |
/// With this function a graph can be read from an |
|
2069 | 2069 |
/// \ref lgf-format "LGF" file or input stream with several maps and |
2070 | 2070 |
/// attributes. For example, there is weighted matching problem on a |
2071 | 2071 |
/// graph, i.e. a graph with a \e weight map on the edges. This |
2072 | 2072 |
/// graph can be read with the following code: |
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-2010 |
|
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 |
... | ... |
@@ -350,9 +350,9 @@ |
350 | 350 |
template <typename DGR> |
351 | 351 |
class DigraphWriter; |
352 | 352 |
|
353 | 353 |
template <typename TDGR> |
354 |
DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, |
|
354 |
DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, |
|
355 | 355 |
std::ostream& os = std::cout); |
356 | 356 |
template <typename TDGR> |
357 | 357 |
DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, const std::string& fn); |
358 | 358 |
|
... | ... |
@@ -503,9 +503,9 @@ |
503 | 503 |
|
504 | 504 |
private: |
505 | 505 |
|
506 | 506 |
template <typename TDGR> |
507 |
friend DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, |
|
507 |
friend DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, |
|
508 | 508 |
std::ostream& os); |
509 | 509 |
template <typename TDGR> |
510 | 510 |
friend DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, |
511 | 511 |
const std::string& fn); |
... | ... |
@@ -916,9 +916,9 @@ |
916 | 916 |
/// \ingroup lemon_io |
917 | 917 |
/// |
918 | 918 |
/// \brief Return a \ref DigraphWriter class |
919 | 919 |
/// |
920 |
/// This function just returns a \ref DigraphWriter class. |
|
920 |
/// This function just returns a \ref DigraphWriter class. |
|
921 | 921 |
/// |
922 | 922 |
/// With this function a digraph can be write to a file or output |
923 | 923 |
/// stream in \ref lgf-format "LGF" format with several maps and |
924 | 924 |
/// attributes. For example, with the following code a network flow |
... | ... |
@@ -956,9 +956,9 @@ |
956 | 956 |
/// This function just returns a \ref DigraphWriter class. |
957 | 957 |
/// \relates DigraphWriter |
958 | 958 |
/// \sa digraphWriter(const TDGR& digraph, std::ostream& os) |
959 | 959 |
template <typename TDGR> |
960 |
DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, |
|
960 |
DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, |
|
961 | 961 |
const std::string& fn) { |
962 | 962 |
DigraphWriter<TDGR> tmp(digraph, fn); |
963 | 963 |
return tmp; |
964 | 964 |
} |
... | ... |
@@ -1100,13 +1100,13 @@ |
1100 | 1100 |
|
1101 | 1101 |
template <typename TGR> |
1102 | 1102 |
friend GraphWriter<TGR> graphWriter(const TGR& graph, std::ostream& os); |
1103 | 1103 |
template <typename TGR> |
1104 |
friend GraphWriter<TGR> graphWriter(const TGR& graph, |
|
1104 |
friend GraphWriter<TGR> graphWriter(const TGR& graph, |
|
1105 | 1105 |
const std::string& fn); |
1106 | 1106 |
template <typename TGR> |
1107 | 1107 |
friend GraphWriter<TGR> graphWriter(const TGR& graph, const char *fn); |
1108 |
|
|
1108 |
|
|
1109 | 1109 |
GraphWriter(GraphWriter& other) |
1110 | 1110 |
: _os(other._os), local_os(other.local_os), _graph(other._graph), |
1111 | 1111 |
_skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) { |
1112 | 1112 |
|
... | ... |
@@ -1555,9 +1555,9 @@ |
1555 | 1555 |
/// \ingroup lemon_io |
1556 | 1556 |
/// |
1557 | 1557 |
/// \brief Return a \ref GraphWriter class |
1558 | 1558 |
/// |
1559 |
/// This function just returns a \ref GraphWriter class. |
|
1559 |
/// This function just returns a \ref GraphWriter class. |
|
1560 | 1560 |
/// |
1561 | 1561 |
/// With this function a graph can be write to a file or output |
1562 | 1562 |
/// stream in \ref lgf-format "LGF" format with several maps and |
1563 | 1563 |
/// attributes. For example, with the following code a weighted |
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-2010 |
|
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 |
... | ... |
@@ -445,9 +445,9 @@ |
445 | 445 |
///\note The moved arcs are joined to node \c u using changeSource() |
446 | 446 |
///or changeTarget(), thus \c ArcIt and \c OutArcIt iterators are |
447 | 447 |
///invalidated for the outgoing arcs of node \c v and \c InArcIt |
448 | 448 |
///iterators are invalidated for the incomming arcs of \c v. |
449 |
///Moreover all iterators referencing node \c v or the removed |
|
449 |
///Moreover all iterators referencing node \c v or the removed |
|
450 | 450 |
///loops are also invalidated. Other iterators remain valid. |
451 | 451 |
/// |
452 | 452 |
///\warning This functionality cannot be used together with the Snapshot |
453 | 453 |
///feature. |
... | ... |
@@ -551,9 +551,9 @@ |
551 | 551 |
/// |
552 | 552 |
/// The newly added nodes and arcs can be removed using the |
553 | 553 |
/// restore() function. |
554 | 554 |
/// |
555 |
/// \note After a state is restored, you cannot restore a later state, |
|
555 |
/// \note After a state is restored, you cannot restore a later state, |
|
556 | 556 |
/// i.e. you cannot add the removed nodes and arcs again using |
557 | 557 |
/// another Snapshot instance. |
558 | 558 |
/// |
559 | 559 |
/// \warning Node and arc deletions and other modifications (e.g. |
... | ... |
@@ -1306,9 +1306,9 @@ |
1306 | 1306 |
/// |
1307 | 1307 |
/// \note The moved edges are joined to node \c a using changeU() |
1308 | 1308 |
/// or changeV(), thus all edge and arc iterators whose base node is |
1309 | 1309 |
/// \c b are invalidated. |
1310 |
/// Moreover all iterators referencing node \c b or the removed |
|
1310 |
/// Moreover all iterators referencing node \c b or the removed |
|
1311 | 1311 |
/// loops are also invalidated. Other iterators remain valid. |
1312 | 1312 |
/// |
1313 | 1313 |
///\warning This functionality cannot be used together with the |
1314 | 1314 |
///Snapshot feature. |
... | ... |
@@ -1363,9 +1363,9 @@ |
1363 | 1363 |
/// |
1364 | 1364 |
/// The newly added nodes and edges can be removed |
1365 | 1365 |
/// using the restore() function. |
1366 | 1366 |
/// |
1367 |
/// \note After a state is restored, you cannot restore a later state, |
|
1367 |
/// \note After a state is restored, you cannot restore a later state, |
|
1368 | 1368 |
/// i.e. you cannot add the removed nodes and edges again using |
1369 | 1369 |
/// another Snapshot instance. |
1370 | 1370 |
/// |
1371 | 1371 |
/// \warning Node and edge deletions and other modifications |
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-2010 |
|
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 |
... | ... |
@@ -83,9 +83,9 @@ |
83 | 83 |
# define DEFAULT_LP SOPLEX |
84 | 84 |
typedef SoplexLp Lp; |
85 | 85 |
#elif LEMON_HAVE_CLP |
86 | 86 |
# define DEFAULT_LP CLP |
87 |
typedef ClpLp Lp; |
|
87 |
typedef ClpLp Lp; |
|
88 | 88 |
#endif |
89 | 89 |
#endif |
90 | 90 |
|
91 | 91 |
} //namespace lemon |
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-2010 |
|
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 |
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-2010 |
|
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 |
... | ... |
@@ -81,9 +81,9 @@ |
81 | 81 |
MESSAGE_NORMAL, |
82 | 82 |
/// Verbose output. |
83 | 83 |
MESSAGE_VERBOSE |
84 | 84 |
}; |
85 |
|
|
85 |
|
|
86 | 86 |
|
87 | 87 |
///The floating point type used by the solver |
88 | 88 |
typedef double Value; |
89 | 89 |
///The infinity constant |
... | ... |
@@ -113,16 +113,16 @@ |
113 | 113 |
public: |
114 | 114 |
typedef Value ExprValue; |
115 | 115 |
typedef True LpCol; |
116 | 116 |
/// Default constructor |
117 |
|
|
117 |
|
|
118 | 118 |
/// \warning The default constructor sets the Col to an |
119 | 119 |
/// undefined value. |
120 | 120 |
Col() {} |
121 | 121 |
/// Invalid constructor \& conversion. |
122 |
|
|
122 |
|
|
123 | 123 |
/// This constructor initializes the Col to be invalid. |
124 |
/// \sa Invalid for more details. |
|
124 |
/// \sa Invalid for more details. |
|
125 | 125 |
Col(const Invalid&) : _id(-1) {} |
126 | 126 |
/// Equality operator |
127 | 127 |
|
128 | 128 |
/// Two \ref Col "Col"s are equal if and only if they point to |
... | ... |
@@ -155,27 +155,27 @@ |
155 | 155 |
class ColIt : public Col { |
156 | 156 |
const LpBase *_solver; |
157 | 157 |
public: |
158 | 158 |
/// Default constructor |
159 |
|
|
159 |
|
|
160 | 160 |
/// \warning The default constructor sets the iterator |
161 | 161 |
/// to an undefined value. |
162 | 162 |
ColIt() {} |
163 | 163 |
/// Sets the iterator to the first Col |
164 |
|
|
164 |
|
|
165 | 165 |
/// Sets the iterator to the first Col. |
166 | 166 |
/// |
167 | 167 |
ColIt(const LpBase &solver) : _solver(&solver) |
168 | 168 |
{ |
169 | 169 |
_solver->cols.firstItem(_id); |
170 | 170 |
} |
171 | 171 |
/// Invalid constructor \& conversion |
172 |
|
|
172 |
|
|
173 | 173 |
/// Initialize the iterator to be invalid. |
174 | 174 |
/// \sa Invalid for more details. |
175 | 175 |
ColIt(const Invalid&) : Col(INVALID) {} |
176 | 176 |
/// Next column |
177 |
|
|
177 |
|
|
178 | 178 |
/// Assign the iterator to the next column. |
179 | 179 |
/// |
180 | 180 |
ColIt &operator++() |
181 | 181 |
{ |
... | ... |
@@ -208,24 +208,24 @@ |
208 | 208 |
public: |
209 | 209 |
typedef Value ExprValue; |
210 | 210 |
typedef True LpRow; |
211 | 211 |
/// Default constructor |
212 |
|
|
212 |
|
|
213 | 213 |
/// \warning The default constructor sets the Row to an |
214 | 214 |
/// undefined value. |
215 | 215 |
Row() {} |
216 | 216 |
/// Invalid constructor \& conversion. |
217 |
|
|
217 |
|
|
218 | 218 |
/// This constructor initializes the Row to be invalid. |
219 |
/// \sa Invalid for more details. |
|
219 |
/// \sa Invalid for more details. |
|
220 | 220 |
Row(const Invalid&) : _id(-1) {} |
221 | 221 |
/// Equality operator |
222 | 222 |
|
223 | 223 |
/// Two \ref Row "Row"s are equal if and only if they point to |
224 | 224 |
/// the same LP row or both are invalid. |
225 | 225 |
bool operator==(Row r) const {return _id == r._id;} |
226 | 226 |
/// Inequality operator |
227 |
|
|
227 |
|
|
228 | 228 |
/// \sa operator==(Row r) |
229 | 229 |
/// |
230 | 230 |
bool operator!=(Row r) const {return _id != r._id;} |
231 | 231 |
/// Artificial ordering operator. |
... | ... |
@@ -250,27 +250,27 @@ |
250 | 250 |
class RowIt : public Row { |
251 | 251 |
const LpBase *_solver; |
252 | 252 |
public: |
253 | 253 |
/// Default constructor |
254 |
|
|
254 |
|
|
255 | 255 |
/// \warning The default constructor sets the iterator |
256 | 256 |
/// to an undefined value. |
257 | 257 |
RowIt() {} |
258 | 258 |
/// Sets the iterator to the first Row |
259 |
|
|
259 |
|
|
260 | 260 |
/// Sets the iterator to the first Row. |
261 | 261 |
/// |
262 | 262 |
RowIt(const LpBase &solver) : _solver(&solver) |
263 | 263 |
{ |
264 | 264 |
_solver->rows.firstItem(_id); |
265 | 265 |
} |
266 | 266 |
/// Invalid constructor \& conversion |
267 |
|
|
267 |
|
|
268 | 268 |
/// Initialize the iterator to be invalid. |
269 | 269 |
/// \sa Invalid for more details. |
270 | 270 |
RowIt(const Invalid&) : Row(INVALID) {} |
271 | 271 |
/// Next row |
272 |
|
|
272 |
|
|
273 | 273 |
/// Assign the iterator to the next row. |
274 | 274 |
/// |
275 | 275 |
RowIt &operator++() |
276 | 276 |
{ |
... | ... |
@@ -346,9 +346,9 @@ |
346 | 346 |
|
347 | 347 |
public: |
348 | 348 |
typedef True SolverExpr; |
349 | 349 |
/// Default constructor |
350 |
|
|
350 |
|
|
351 | 351 |
/// Construct an empty expression, the coefficients and |
352 | 352 |
/// the constant component are initialized to zero. |
353 | 353 |
Expr() : const_comp(0) {} |
354 | 354 |
/// Construct an expression from a column |
... | ... |
@@ -447,11 +447,11 @@ |
447 | 447 |
return *this; |
448 | 448 |
} |
449 | 449 |
|
450 | 450 |
///Iterator over the expression |
451 |
|
|
452 |
///The iterator iterates over the terms of the expression. |
|
453 |
|
|
451 |
|
|
452 |
///The iterator iterates over the terms of the expression. |
|
453 |
/// |
|
454 | 454 |
///\code |
455 | 455 |
///double s=0; |
456 | 456 |
///for(LpBase::Expr::CoeffIt i(e);i!=INVALID;++i) |
457 | 457 |
/// s+= *i * primal(i); |
... | ... |
@@ -463,9 +463,9 @@ |
463 | 463 |
|
464 | 464 |
public: |
465 | 465 |
|
466 | 466 |
/// Sets the iterator to the first term |
467 |
|
|
467 |
|
|
468 | 468 |
/// Sets the iterator to the first term of the expression. |
469 | 469 |
/// |
470 | 470 |
CoeffIt(Expr& e) |
471 | 471 |
: _it(e.comps.begin()), _end(e.comps.end()){} |
... | ... |
@@ -480,9 +480,9 @@ |
480 | 480 |
|
481 | 481 |
/// Returns the coefficient of the term |
482 | 482 |
const Value& operator*() const { return _it->second; } |
483 | 483 |
/// Next term |
484 |
|
|
484 |
|
|
485 | 485 |
/// Assign the iterator to the next term. |
486 | 486 |
/// |
487 | 487 |
CoeffIt& operator++() { ++_it; return *this; } |
488 | 488 |
|
... | ... |
@@ -492,11 +492,11 @@ |
492 | 492 |
bool operator!=(Invalid) const { return _it != _end; } |
493 | 493 |
}; |
494 | 494 |
|
495 | 495 |
/// Const iterator over the expression |
496 |
|
|
497 |
///The iterator iterates over the terms of the expression. |
|
498 |
|
|
496 |
|
|
497 |
///The iterator iterates over the terms of the expression. |
|
498 |
/// |
|
499 | 499 |
///\code |
500 | 500 |
///double s=0; |
501 | 501 |
///for(LpBase::Expr::ConstCoeffIt i(e);i!=INVALID;++i) |
502 | 502 |
/// s+=*i * primal(i); |
... | ... |
@@ -508,9 +508,9 @@ |
508 | 508 |
|
509 | 509 |
public: |
510 | 510 |
|
511 | 511 |
/// Sets the iterator to the first term |
512 |
|
|
512 |
|
|
513 | 513 |
/// Sets the iterator to the first term of the expression. |
514 | 514 |
/// |
515 | 515 |
ConstCoeffIt(const Expr& e) |
516 | 516 |
: _it(e.comps.begin()), _end(e.comps.end()){} |
... | ... |
@@ -523,9 +523,9 @@ |
523 | 523 |
/// Returns the coefficient of the term |
524 | 524 |
const Value& operator*() const { return _it->second; } |
525 | 525 |
|
526 | 526 |
/// Next term |
527 |
|
|
527 |
|
|
528 | 528 |
/// Assign the iterator to the next term. |
529 | 529 |
/// |
530 | 530 |
ConstCoeffIt& operator++() { ++_it; return *this; } |
531 | 531 |
|
... | ... |
@@ -672,9 +672,9 @@ |
672 | 672 |
|
673 | 673 |
public: |
674 | 674 |
typedef True SolverExpr; |
675 | 675 |
/// Default constructor |
676 |
|
|
676 |
|
|
677 | 677 |
/// Construct an empty expression, the coefficients are |
678 | 678 |
/// initialized to zero. |
679 | 679 |
DualExpr() {} |
680 | 680 |
/// Construct an expression from a row |
... | ... |
@@ -707,9 +707,9 @@ |
707 | 707 |
comps.erase(id(r)); |
708 | 708 |
} |
709 | 709 |
} |
710 | 710 |
/// \brief Removes the coefficients which's absolute value does |
711 |
/// not exceed \c epsilon. |
|
711 |
/// not exceed \c epsilon. |
|
712 | 712 |
void simplify(Value epsilon = 0.0) { |
713 | 713 |
std::map<int, Value>::iterator it=comps.begin(); |
714 | 714 |
while (it != comps.end()) { |
715 | 715 |
std::map<int, Value>::iterator jt=it; |
... | ... |
@@ -756,11 +756,11 @@ |
756 | 756 |
return *this; |
757 | 757 |
} |
758 | 758 |
|
759 | 759 |
///Iterator over the expression |
760 |
|
|
761 |
///The iterator iterates over the terms of the expression. |
|
762 |
|
|
760 |
|
|
761 |
///The iterator iterates over the terms of the expression. |
|
762 |
/// |
|
763 | 763 |
///\code |
764 | 764 |
///double s=0; |
765 | 765 |
///for(LpBase::DualExpr::CoeffIt i(e);i!=INVALID;++i) |
766 | 766 |
/// s+= *i * dual(i); |
... | ... |
@@ -772,9 +772,9 @@ |
772 | 772 |
|
773 | 773 |
public: |
774 | 774 |
|
775 | 775 |
/// Sets the iterator to the first term |
776 |
|
|
776 |
|
|
777 | 777 |
/// Sets the iterator to the first term of the expression. |
778 | 778 |
/// |
779 | 779 |
CoeffIt(DualExpr& e) |
780 | 780 |
: _it(e.comps.begin()), _end(e.comps.end()){} |
... | ... |
@@ -790,9 +790,9 @@ |
790 | 790 |
/// Returns the coefficient of the term |
791 | 791 |
const Value& operator*() const { return _it->second; } |
792 | 792 |
|
793 | 793 |
/// Next term |
794 |
|
|
794 |
|
|
795 | 795 |
/// Assign the iterator to the next term. |
796 | 796 |
/// |
797 | 797 |
CoeffIt& operator++() { ++_it; return *this; } |
798 | 798 |
|
... | ... |
@@ -802,11 +802,11 @@ |
802 | 802 |
bool operator!=(Invalid) const { return _it != _end; } |
803 | 803 |
}; |
804 | 804 |
|
805 | 805 |
///Iterator over the expression |
806 |
|
|
807 |
///The iterator iterates over the terms of the expression. |
|
808 |
|
|
806 |
|
|
807 |
///The iterator iterates over the terms of the expression. |
|
808 |
/// |
|
809 | 809 |
///\code |
810 | 810 |
///double s=0; |
811 | 811 |
///for(LpBase::DualExpr::ConstCoeffIt i(e);i!=INVALID;++i) |
812 | 812 |
/// s+= *i * dual(i); |
... | ... |
@@ -818,9 +818,9 @@ |
818 | 818 |
|
819 | 819 |
public: |
820 | 820 |
|
821 | 821 |
/// Sets the iterator to the first term |
822 |
|
|
822 |
|
|
823 | 823 |
/// Sets the iterator to the first term of the expression. |
824 | 824 |
/// |
825 | 825 |
ConstCoeffIt(const DualExpr& e) |
826 | 826 |
: _it(e.comps.begin()), _end(e.comps.end()){} |
... | ... |
@@ -833,9 +833,9 @@ |
833 | 833 |
/// Returns the coefficient of the term |
834 | 834 |
const Value& operator*() const { return _it->second; } |
835 | 835 |
|
836 | 836 |
/// Next term |
837 |
|
|
837 |
|
|
838 | 838 |
/// Assign the iterator to the next term. |
839 | 839 |
/// |
840 | 840 |
ConstCoeffIt& operator++() { ++_it; return *this; } |
841 | 841 |
|
... | ... |
@@ -1228,9 +1228,9 @@ |
1228 | 1228 |
///\return The created row. |
1229 | 1229 |
Row addRow(const Constr &c) { |
1230 | 1230 |
Row r; |
1231 | 1231 |
c.expr().simplify(); |
1232 |
r._id = _addRowId(_addRow(c.lowerBounded()?c.lowerBound()-*c.expr():-INF, |
|
1232 |
r._id = _addRowId(_addRow(c.lowerBounded()?c.lowerBound()-*c.expr():-INF, |
|
1233 | 1233 |
ExprIterator(c.expr().comps.begin(), cols), |
1234 | 1234 |
ExprIterator(c.expr().comps.end(), cols), |
1235 | 1235 |
c.upperBounded()?c.upperBound()-*c.expr():INF)); |
1236 | 1236 |
return r; |
... | ... |
@@ -1816,12 +1816,12 @@ |
1816 | 1816 |
|
1817 | 1817 |
///The basis status of variables |
1818 | 1818 |
enum VarStatus { |
1819 | 1819 |
/// The variable is in the basis |
1820 |
BASIC, |
|
1820 |
BASIC, |
|
1821 | 1821 |
/// The variable is free, but not basic |
1822 | 1822 |
FREE, |
1823 |
/// The variable has active lower bound |
|
1823 |
/// The variable has active lower bound |
|
1824 | 1824 |
LOWER, |
1825 | 1825 |
/// The variable has active upper bound |
1826 | 1826 |
UPPER, |
1827 | 1827 |
/// The variable is non-basic and fixed |
... | ... |
@@ -1898,9 +1898,9 @@ |
1898 | 1898 |
} |
1899 | 1899 |
return res; |
1900 | 1900 |
} |
1901 | 1901 |
/// Returns a component of the primal ray |
1902 |
|
|
1902 |
|
|
1903 | 1903 |
/// The primal ray is solution of the modified primal problem, |
1904 | 1904 |
/// where we change each finite bound to 0, and we looking for a |
1905 | 1905 |
/// negative objective value in case of minimization, and positive |
1906 | 1906 |
/// objective value for maximization. If there is such solution, |
... | ... |
@@ -1932,9 +1932,9 @@ |
1932 | 1932 |
return res; |
1933 | 1933 |
} |
1934 | 1934 |
|
1935 | 1935 |
/// Returns a component of the dual ray |
1936 |
|
|
1936 |
|
|
1937 | 1937 |
/// The dual ray is solution of the modified primal problem, where |
1938 | 1938 |
/// we change each finite bound to 0 (i.e. the objective function |
1939 | 1939 |
/// coefficients in the primal problem), and we looking for a |
1940 | 1940 |
/// ositive objective value. If there is such solution, that |
... | ... |
@@ -2074,9 +2074,9 @@ |
2074 | 2074 |
} |
2075 | 2075 |
return res; |
2076 | 2076 |
} |
2077 | 2077 |
///The value of the objective function |
2078 |
|
|
2078 |
|
|
2079 | 2079 |
///\return |
2080 | 2080 |
///- \ref INF or -\ref INF means either infeasibility or unboundedness |
2081 | 2081 |
/// of the problem, depending on whether we minimize or maximize. |
2082 | 2082 |
///- \ref NaN if no primal solution is found. |
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-2010 |
|
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 |
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-2010 |
|
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 |
... | ... |
@@ -22,15 +22,15 @@ |
22 | 22 |
#include <lemon/lp_base.h> |
23 | 23 |
|
24 | 24 |
///\file |
25 | 25 |
///\brief Skeleton file to implement LP/MIP solver interfaces |
26 |
/// |
|
26 |
/// |
|
27 | 27 |
///The classes in this file do nothing, but they can serve as skeletons when |
28 | 28 |
///implementing an interface to new solvers. |
29 | 29 |
namespace lemon { |
30 | 30 |
|
31 | 31 |
///A skeleton class to implement LP/MIP solver base interface |
32 |
|
|
32 |
|
|
33 | 33 |
///This class does nothing, but it can serve as a skeleton when |
34 | 34 |
///implementing an interface to new solvers. |
35 | 35 |
class SkeletonSolverBase : public virtual LpBase { |
36 | 36 |
int col_num,row_num; |
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-2010 |
|
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 |
... | ... |
@@ -232,9 +232,9 @@ |
232 | 232 |
/// values to integer keys from the range <tt>[0..size-1]</tt>. |
233 | 233 |
/// It can be used together with some data structures, e.g. |
234 | 234 |
/// heap types and \c UnionFind, when the used items are small |
235 | 235 |
/// integers. This map conforms to the \ref concepts::ReferenceMap |
236 |
/// "ReferenceMap" concept. |
|
236 |
/// "ReferenceMap" concept. |
|
237 | 237 |
/// |
238 | 238 |
/// The simplest way of using this map is through the rangeMap() |
239 | 239 |
/// function. |
240 | 240 |
template <typename V> |
... | ... |
@@ -1915,13 +1915,13 @@ |
1915 | 1915 |
/// and if a key is set to a new value, then stores it in the inverse map. |
1916 | 1916 |
/// The graph items can be accessed by their values either using |
1917 | 1917 |
/// \c InverseMap or \c operator()(), and the values of the map can be |
1918 | 1918 |
/// accessed with an STL compatible forward iterator (\c ValueIt). |
1919 |
/// |
|
1919 |
/// |
|
1920 | 1920 |
/// This map is intended to be used when all associated values are |
1921 | 1921 |
/// different (the map is actually invertable) or there are only a few |
1922 | 1922 |
/// items with the same value. |
1923 |
/// Otherwise consider to use \c IterableValueMap, which is more |
|
1923 |
/// Otherwise consider to use \c IterableValueMap, which is more |
|
1924 | 1924 |
/// suitable and more efficient for such cases. It provides iterators |
1925 | 1925 |
/// to traverse the items with the same associated value, but |
1926 | 1926 |
/// it does not have \c InverseMap. |
1927 | 1927 |
/// |
... | ... |
@@ -2001,9 +2001,9 @@ |
2001 | 2001 |
|
2002 | 2002 |
private: |
2003 | 2003 |
typename Container::const_iterator it; |
2004 | 2004 |
}; |
2005 |
|
|
2005 |
|
|
2006 | 2006 |
/// Alias for \c ValueIt |
2007 | 2007 |
typedef ValueIt ValueIterator; |
2008 | 2008 |
|
2009 | 2009 |
/// \brief Returns an iterator to the first value. |
... | ... |
@@ -2060,9 +2060,9 @@ |
2060 | 2060 |
Key operator()(const Value& val) const { |
2061 | 2061 |
typename Container::const_iterator it = _inv_map.find(val); |
2062 | 2062 |
return it != _inv_map.end() ? it->second : INVALID; |
2063 | 2063 |
} |
2064 |
|
|
2064 |
|
|
2065 | 2065 |
/// \brief Returns the number of items with the given value. |
2066 | 2066 |
/// |
2067 | 2067 |
/// This function returns the number of items with the given value |
2068 | 2068 |
/// associated with it. |
... | ... |
@@ -2377,9 +2377,9 @@ |
2377 | 2377 |
template <typename K, typename GR> |
2378 | 2378 |
inline RangeIdMap<GR, K> rangeIdMap(const GR& graph) { |
2379 | 2379 |
return RangeIdMap<GR, K>(graph); |
2380 | 2380 |
} |
2381 |
|
|
2381 |
|
|
2382 | 2382 |
/// \brief Dynamic iterable \c bool map. |
2383 | 2383 |
/// |
2384 | 2384 |
/// This class provides a special graph map type which can store a |
2385 | 2385 |
/// \c bool value for graph items (\c Node, \c Arc or \c Edge). |
... | ... |
@@ -2637,9 +2637,9 @@ |
2637 | 2637 |
/// keys mapped to the given value. |
2638 | 2638 |
/// \param map The IterableBoolMap. |
2639 | 2639 |
/// \param value The value. |
2640 | 2640 |
ItemIt(const IterableBoolMap& map, bool value) |
2641 |
: Parent(value ? |
|
2641 |
: Parent(value ? |
|
2642 | 2642 |
(map._sep > 0 ? |
2643 | 2643 |
map._array[map._sep - 1] : INVALID) : |
2644 | 2644 |
(map._sep < int(map._array.size()) ? |
2645 | 2645 |
map._array.back() : INVALID)), _map(&map) {} |
... | ... |
@@ -3785,17 +3785,17 @@ |
3785 | 3785 |
template <typename GR, typename From, typename To> |
3786 | 3786 |
void mapCopy(const GR& gr, const From& from, To& to) { |
3787 | 3787 |
typedef typename To::Key Item; |
3788 | 3788 |
typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt; |
3789 |
|
|
3789 |
|
|
3790 | 3790 |
for (ItemIt it(gr); it != INVALID; ++it) { |
3791 | 3791 |
to.set(it, from[it]); |
3792 | 3792 |
} |
3793 | 3793 |
} |
3794 | 3794 |
|
3795 | 3795 |
/// \brief Compare two graph maps. |
3796 | 3796 |
/// |
3797 |
/// This function compares the values of two graph maps. It returns |
|
3797 |
/// This function compares the values of two graph maps. It returns |
|
3798 | 3798 |
/// \c true if the maps assign the same value for all items in the graph. |
3799 | 3799 |
/// The \c Key type of the maps (\c Node, \c Arc or \c Edge) must be equal |
3800 | 3800 |
/// and their \c Value types must be comparable using \c %operator==(). |
3801 | 3801 |
/// |
... | ... |
@@ -3805,9 +3805,9 @@ |
3805 | 3805 |
template <typename GR, typename Map1, typename Map2> |
3806 | 3806 |
bool mapCompare(const GR& gr, const Map1& map1, const Map2& map2) { |
3807 | 3807 |
typedef typename Map2::Key Item; |
3808 | 3808 |
typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt; |
3809 |
|
|
3809 |
|
|
3810 | 3810 |
for (ItemIt it(gr); it != INVALID; ++it) { |
3811 | 3811 |
if (!(map1[it] == map2[it])) return false; |
3812 | 3812 |
} |
3813 | 3813 |
return true; |
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-2010 |
|
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 |
... | ... |
@@ -1622,9 +1622,9 @@ |
1622 | 1622 |
for (int i = 0; i < _blossom_num; ++i) { |
1623 | 1623 |
(*_delta2_index)[i] = _delta2->PRE_HEAP; |
1624 | 1624 |
(*_delta4_index)[i] = _delta4->PRE_HEAP; |
1625 | 1625 |
} |
1626 |
|
|
1626 |
|
|
1627 | 1627 |
_unmatched = _node_num; |
1628 | 1628 |
|
1629 | 1629 |
_delta1->clear(); |
1630 | 1630 |
_delta2->clear(); |
... | ... |
@@ -1677,9 +1677,9 @@ |
1677 | 1677 |
createStructures(); |
1678 | 1678 |
|
1679 | 1679 |
_blossom_node_list.clear(); |
1680 | 1680 |
_blossom_potential.clear(); |
1681 |
|
|
1681 |
|
|
1682 | 1682 |
if (_fractional == 0) { |
1683 | 1683 |
_fractional = new FractionalMatching(_graph, _weight, false); |
1684 | 1684 |
} |
1685 | 1685 |
_fractional->run(); |
... | ... |
@@ -1749,19 +1749,19 @@ |
1749 | 1749 |
v = _graph.target(_fractional->matching(n)); |
1750 | 1750 |
while (n != v) { |
1751 | 1751 |
subblossoms[--num] = _blossom_set->find(v); |
1752 | 1752 |
_delta1->push(v, _fractional->nodeValue(v)); |
1753 |
v = _graph.target(_fractional->matching(v)); |
|
1753 |
v = _graph.target(_fractional->matching(v)); |
|
1754 | 1754 |
} |
1755 |
|
|
1756 |
int surface = |
|
1755 |
|
|
1756 |
int surface = |
|
1757 | 1757 |
_blossom_set->join(subblossoms.begin(), subblossoms.end()); |
1758 | 1758 |
(*_blossom_data)[surface].status = EVEN; |
1759 | 1759 |
(*_blossom_data)[surface].pred = INVALID; |
1760 | 1760 |
(*_blossom_data)[surface].next = INVALID; |
1761 | 1761 |
(*_blossom_data)[surface].pot = 0; |
1762 | 1762 |
(*_blossom_data)[surface].offset = 0; |
1763 |
|
|
1763 |
|
|
1764 | 1764 |
_tree_set->insert(surface); |
1765 | 1765 |
++_unmatched; |
1766 | 1766 |
} |
1767 | 1767 |
} |
... | ... |
@@ -1809,9 +1809,9 @@ |
1809 | 1809 |
(*_node_data)[ni].heap_index.insert(std::make_pair(vt, e)); |
1810 | 1810 |
} |
1811 | 1811 |
} |
1812 | 1812 |
} |
1813 |
|
|
1813 |
|
|
1814 | 1814 |
if (!(*_node_data)[ni].heap.empty()) { |
1815 | 1815 |
_blossom_set->decrease(n, (*_node_data)[ni].heap.prio()); |
1816 | 1816 |
_delta2->push(nb, _blossom_set->classPrio(nb)); |
1817 | 1817 |
} |
... | ... |
@@ -2268,9 +2268,9 @@ |
2268 | 2268 |
|
2269 | 2269 |
Value _delta_sum; |
2270 | 2270 |
int _unmatched; |
2271 | 2271 |
|
2272 |
typedef MaxWeightedPerfectFractionalMatching<Graph, WeightMap> |
|
2272 |
typedef MaxWeightedPerfectFractionalMatching<Graph, WeightMap> |
|
2273 | 2273 |
FractionalMatching; |
2274 | 2274 |
FractionalMatching *_fractional; |
2275 | 2275 |
|
2276 | 2276 |
void createStructures() { |
... | ... |
@@ -3094,9 +3094,9 @@ |
3094 | 3094 |
createStructures(); |
3095 | 3095 |
|
3096 | 3096 |
_blossom_node_list.clear(); |
3097 | 3097 |
_blossom_potential.clear(); |
3098 |
|
|
3098 |
|
|
3099 | 3099 |
if (_fractional == 0) { |
3100 | 3100 |
_fractional = new FractionalMatching(_graph, _weight, false); |
3101 | 3101 |
} |
3102 | 3102 |
if (!_fractional->run()) { |
... | ... |
@@ -3160,19 +3160,19 @@ |
3160 | 3160 |
subblossoms[--num] = _blossom_set->find(n); |
3161 | 3161 |
v = _graph.target(_fractional->matching(n)); |
3162 | 3162 |
while (n != v) { |
3163 | 3163 |
subblossoms[--num] = _blossom_set->find(v); |
3164 |
v = _graph.target(_fractional->matching(v)); |
|
3164 |
v = _graph.target(_fractional->matching(v)); |
|
3165 | 3165 |
} |
3166 |
|
|
3167 |
int surface = |
|
3166 |
|
|
3167 |
int surface = |
|
3168 | 3168 |
_blossom_set->join(subblossoms.begin(), subblossoms.end()); |
3169 | 3169 |
(*_blossom_data)[surface].status = EVEN; |
3170 | 3170 |
(*_blossom_data)[surface].pred = INVALID; |
3171 | 3171 |
(*_blossom_data)[surface].next = INVALID; |
3172 | 3172 |
(*_blossom_data)[surface].pot = 0; |
3173 | 3173 |
(*_blossom_data)[surface].offset = 0; |
3174 |
|
|
3174 |
|
|
3175 | 3175 |
_tree_set->insert(surface); |
3176 | 3176 |
++_unmatched; |
3177 | 3177 |
} |
3178 | 3178 |
} |
... | ... |
@@ -3220,9 +3220,9 @@ |
3220 | 3220 |
(*_node_data)[ni].heap_index.insert(std::make_pair(vt, e)); |
3221 | 3221 |
} |
3222 | 3222 |
} |
3223 | 3223 |
} |
3224 |
|
|
3224 |
|
|
3225 | 3225 |
if (!(*_node_data)[ni].heap.empty()) { |
3226 | 3226 |
_blossom_set->decrease(n, (*_node_data)[ni].heap.prio()); |
3227 | 3227 |
_delta2->push(nb, _blossom_set->classPrio(nb)); |
3228 | 3228 |
} |
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-2010 |
|
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 |
... | ... |
@@ -55,9 +55,9 @@ |
55 | 55 |
/// 1/sqrt(2) |
56 | 56 |
const long double SQRT1_2 = 0.7071067811865475244008443621048490L; |
57 | 57 |
|
58 | 58 |
///Check whether the parameter is NaN or not |
59 |
|
|
59 |
|
|
60 | 60 |
///This function checks whether the parameter is NaN or not. |
61 | 61 |
///Is should be equivalent with std::isnan(), but it is not |
62 | 62 |
///provided by all compilers. |
63 | 63 |
inline bool isNaN(double v) |
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-2010 |
|
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 |
... | ... |
@@ -127,10 +127,10 @@ |
127 | 127 |
#endif |
128 | 128 |
class MinCostArborescence { |
129 | 129 |
public: |
130 | 130 |
|
131 |
/// \brief The \ref MinCostArborescenceDefaultTraits "traits class" |
|
132 |
/// of the algorithm. |
|
131 |
/// \brief The \ref MinCostArborescenceDefaultTraits "traits class" |
|
132 |
/// of the algorithm. |
|
133 | 133 |
typedef TR Traits; |
134 | 134 |
/// The type of the underlying digraph. |
135 | 135 |
typedef typename Traits::Digraph Digraph; |
136 | 136 |
/// The type of the map that stores the arc costs. |
... | ... |
@@ -435,9 +435,9 @@ |
435 | 435 |
/// setting \c PredMap type |
436 | 436 |
/// |
437 | 437 |
/// \ref named-templ-param "Named parameter" for setting |
438 | 438 |
/// \c PredMap type. |
439 |
/// It must meet the \ref concepts::WriteMap "WriteMap" concept, |
|
439 |
/// It must meet the \ref concepts::WriteMap "WriteMap" concept, |
|
440 | 440 |
/// and its value type must be the \c Arc type of the digraph. |
441 | 441 |
template <class T> |
442 | 442 |
struct SetPredMap |
443 | 443 |
: public MinCostArborescence<Digraph, CostMap, SetPredMapTraits<T> > { |
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-2010 |
|
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 |
... | ... |
@@ -96,9 +96,9 @@ |
96 | 96 |
/// there is a directed cycle having negative total cost and |
97 | 97 |
/// infinite upper bound. |
98 | 98 |
UNBOUNDED |
99 | 99 |
}; |
100 |
|
|
100 |
|
|
101 | 101 |
/// \brief Constants for selecting the type of the supply constraints. |
102 | 102 |
/// |
103 | 103 |
/// Enum type containing constants for selecting the supply type, |
104 | 104 |
/// i.e. the direction of the inequalities in the supply/demand |
... | ... |
@@ -114,9 +114,9 @@ |
114 | 114 |
/// This option means that there are <em>"less or equal"</em> |
115 | 115 |
/// supply/demand constraints in the definition of the problem. |
116 | 116 |
LEQ |
117 | 117 |
}; |
118 |
|
|
118 |
|
|
119 | 119 |
/// \brief Constants for selecting the pivot rule. |
120 | 120 |
/// |
121 | 121 |
/// Enum type containing constants for selecting the pivot rule for |
122 | 122 |
/// the \ref run() function. |
... | ... |
@@ -157,9 +157,9 @@ |
157 | 157 |
/// It keeps only the several best eligible arcs from the former |
158 | 158 |
/// candidate list and extends this list in every iteration. |
159 | 159 |
ALTERING_LIST |
160 | 160 |
}; |
161 |
|
|
161 |
|
|
162 | 162 |
private: |
163 | 163 |
|
164 | 164 |
TEMPLATE_DIGRAPH_TYPEDEFS(GR); |
165 | 165 |
|
... | ... |
@@ -226,13 +226,13 @@ |
226 | 226 |
int in_arc, join, u_in, v_in, u_out, v_out; |
227 | 227 |
int first, second, right, last; |
228 | 228 |
int stem, par_stem, new_stem; |
229 | 229 |
Value delta; |
230 |
|
|
230 |
|
|
231 | 231 |
const Value MAX; |
232 | 232 |
|
233 | 233 |
public: |
234 |
|
|
234 |
|
|
235 | 235 |
/// \brief Constant for infinite upper bounds (capacities). |
236 | 236 |
/// |
237 | 237 |
/// Constant for infinite upper bounds (capacities). |
238 | 238 |
/// It is \c std::numeric_limits<Value>::infinity() if available, |
... | ... |
@@ -497,10 +497,10 @@ |
497 | 497 |
if (_curr_length == _list_length) goto search_end; |
498 | 498 |
} |
499 | 499 |
} |
500 | 500 |
if (_curr_length == 0) return false; |
501 |
|
|
502 |
search_end: |
|
501 |
|
|
502 |
search_end: |
|
503 | 503 |
_minor_count = 1; |
504 | 504 |
_next_arc = e; |
505 | 505 |
return true; |
506 | 506 |
} |
... | ... |
@@ -607,9 +607,9 @@ |
607 | 607 |
cnt = _block_size; |
608 | 608 |
} |
609 | 609 |
} |
610 | 610 |
if (_curr_length == 0) return false; |
611 |
|
|
611 |
|
|
612 | 612 |
search_end: |
613 | 613 |
|
614 | 614 |
// Make heap of the candidate list (approximating a partial sort) |
615 | 615 |
make_heap( _candidates.begin(), _candidates.begin() + _curr_length, |
... | ... |
@@ -633,9 +633,9 @@ |
633 | 633 |
/// The constructor of the class. |
634 | 634 |
/// |
635 | 635 |
/// \param graph The digraph the algorithm runs on. |
636 | 636 |
/// \param arc_mixing Indicate if the arcs have to be stored in a |
637 |
/// mixed order in the internal data structure. |
|
637 |
/// mixed order in the internal data structure. |
|
638 | 638 |
/// In special cases, it could lead to better overall performance, |
639 | 639 |
/// but it is usually slower. Therefore it is disabled by default. |
640 | 640 |
NetworkSimplex(const GR& graph, bool arc_mixing = false) : |
641 | 641 |
_graph(graph), _node_id(graph), _arc_id(graph), |
... | ... |
@@ -648,9 +648,9 @@ |
648 | 648 |
LEMON_ASSERT(std::numeric_limits<Value>::is_signed, |
649 | 649 |
"The flow type of NetworkSimplex must be signed"); |
650 | 650 |
LEMON_ASSERT(std::numeric_limits<Cost>::is_signed, |
651 | 651 |
"The cost type of NetworkSimplex must be signed"); |
652 |
|
|
652 |
|
|
653 | 653 |
// Reset data structures |
654 | 654 |
reset(); |
655 | 655 |
} |
656 | 656 |
|
... | ... |
@@ -762,9 +762,9 @@ |
762 | 762 |
_supply[_node_id[s]] = k; |
763 | 763 |
_supply[_node_id[t]] = -k; |
764 | 764 |
return *this; |
765 | 765 |
} |
766 |
|
|
766 |
|
|
767 | 767 |
/// \brief Set the type of the supply constraints. |
768 | 768 |
/// |
769 | 769 |
/// This function sets the type of the supply/demand constraints. |
770 | 770 |
/// If it is not used before calling \ref run(), the \ref GEQ supply |
... | ... |
@@ -788,9 +788,9 @@ |
788 | 788 |
/// \brief Run the algorithm. |
789 | 789 |
/// |
790 | 790 |
/// This function runs the algorithm. |
791 | 791 |
/// The paramters can be specified using functions \ref lowerMap(), |
792 |
/// \ref upperMap(), \ref costMap(), \ref supplyMap(), \ref stSupply(), |
|
792 |
/// \ref upperMap(), \ref costMap(), \ref supplyMap(), \ref stSupply(), |
|
793 | 793 |
/// \ref supplyType(). |
794 | 794 |
/// For example, |
795 | 795 |
/// \code |
796 | 796 |
/// NetworkSimplex<ListDigraph> ns(graph); |
... | ... |
@@ -943,14 +943,14 @@ |
943 | 943 |
_source[i] = _node_id[_graph.source(a)]; |
944 | 944 |
_target[i] = _node_id[_graph.target(a)]; |
945 | 945 |
} |
946 | 946 |
} |
947 |
|
|
947 |
|
|
948 | 948 |
// Reset parameters |
949 | 949 |
resetParams(); |
950 | 950 |
return *this; |
951 | 951 |
} |
952 |
|
|
952 |
|
|
953 | 953 |
/// @} |
954 | 954 |
|
955 | 955 |
/// \name Query Functions |
956 | 956 |
/// The results of the algorithm can be obtained using these |
... | ... |
@@ -1088,9 +1088,9 @@ |
1088 | 1088 |
for (int i = 0; i != _arc_num; ++i) { |
1089 | 1089 |
_flow[i] = 0; |
1090 | 1090 |
_state[i] = STATE_LOWER; |
1091 | 1091 |
} |
1092 |
|
|
1092 |
|
|
1093 | 1093 |
// Set data for the artificial root node |
1094 | 1094 |
_root = _node_num; |
1095 | 1095 |
_parent[_root] = -1; |
1096 | 1096 |
_pred[_root] = -1; |
... | ... |
@@ -1262,9 +1262,9 @@ |
1262 | 1262 |
} |
1263 | 1263 |
// Search the cycle along the path form the second node to the root |
1264 | 1264 |
for (int u = second; u != join; u = _parent[u]) { |
1265 | 1265 |
e = _pred[u]; |
1266 |
d = _forward[u] ? |
|
1266 |
d = _forward[u] ? |
|
1267 | 1267 |
(_cap[e] >= MAX ? INF : _cap[e] - _flow[e]) : _flow[e]; |
1268 | 1268 |
if (d <= delta) { |
1269 | 1269 |
delta = d; |
1270 | 1270 |
u_out = u; |
... | ... |
@@ -1566,9 +1566,9 @@ |
1566 | 1566 |
updateTreeStructure(); |
1567 | 1567 |
updatePotential(); |
1568 | 1568 |
} |
1569 | 1569 |
} |
1570 |
|
|
1570 |
|
|
1571 | 1571 |
// Check feasibility |
1572 | 1572 |
for (int e = _search_arc_num; e != _all_arc_num; ++e) { |
1573 | 1573 |
if (_flow[e] != 0) return INFEASIBLE; |
1574 | 1574 |
} |
... | ... |
@@ -1583,9 +1583,9 @@ |
1583 | 1583 |
_supply[_target[i]] -= c; |
1584 | 1584 |
} |
1585 | 1585 |
} |
1586 | 1586 |
} |
1587 |
|
|
1587 |
|
|
1588 | 1588 |
// Shift potentials to meet the requirements of the GEQ/LEQ type |
1589 | 1589 |
// optimality conditions |
1590 | 1590 |
if (_sum_supply == 0) { |
1591 | 1591 |
if (_stype == GEQ) { |
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-2010 |
|
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 |
... | ... |
@@ -965,22 +965,22 @@ |
965 | 965 |
to.buildRev(from); |
966 | 966 |
} |
967 | 967 |
}; |
968 | 968 |
|
969 |
|
|
969 |
|
|
970 | 970 |
template <typename From, typename To, |
971 | 971 |
bool revEnable = RevPathTagIndicator<From>::value> |
972 | 972 |
struct PathCopySelector { |
973 | 973 |
static void copy(const From& from, To& to) { |
974 | 974 |
PathCopySelectorForward<From, To>::copy(from, to); |
975 |
} |
|
975 |
} |
|
976 | 976 |
}; |
977 | 977 |
|
978 | 978 |
template <typename From, typename To> |
979 | 979 |
struct PathCopySelector<From, To, true> { |
980 | 980 |
static void copy(const From& from, To& to) { |
981 | 981 |
PathCopySelectorBackward<From, To>::copy(from, to); |
982 |
} |
|
982 |
} |
|
983 | 983 |
}; |
984 | 984 |
|
985 | 985 |
} |
986 | 986 |
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-2010 |
|
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 |
... | ... |
@@ -139,19 +139,19 @@ |
139 | 139 |
|
140 | 140 |
template <typename Graph> |
141 | 141 |
class PlanarityChecking { |
142 | 142 |
private: |
143 |
|
|
143 |
|
|
144 | 144 |
TEMPLATE_GRAPH_TYPEDEFS(Graph); |
145 | 145 |
|
146 | 146 |
const Graph& _graph; |
147 | 147 |
|
148 | 148 |
private: |
149 |
|
|
149 |
|
|
150 | 150 |
typedef typename Graph::template NodeMap<Arc> PredMap; |
151 |
|
|
151 |
|
|
152 | 152 |
typedef typename Graph::template EdgeMap<bool> TreeMap; |
153 |
|
|
153 |
|
|
154 | 154 |
typedef typename Graph::template NodeMap<int> OrderMap; |
155 | 155 |
typedef std::vector<Node> OrderList; |
156 | 156 |
|
157 | 157 |
typedef typename Graph::template NodeMap<int> LowMap; |
... | ... |
@@ -220,9 +220,9 @@ |
220 | 220 |
} |
221 | 221 |
} |
222 | 222 |
|
223 | 223 |
for (typename MergeRoots::Value::iterator it = |
224 |
merge_roots[node].begin(); |
|
224 |
merge_roots[node].begin(); |
|
225 | 225 |
it != merge_roots[node].end(); ++it) { |
226 | 226 |
int rn = *it; |
227 | 227 |
walkDown(rn, i, node_data, order_list, child_lists, |
228 | 228 |
ancestor_map, low_map, embed_arc, merge_roots); |
... | ... |
@@ -431,9 +431,9 @@ |
431 | 431 |
int yn = node_data[rn].prev; |
432 | 432 |
Node ynode = order_list[yn]; |
433 | 433 |
|
434 | 434 |
bool rd; |
435 |
if (!external(xnode, rorder, child_lists, |
|
435 |
if (!external(xnode, rorder, child_lists, |
|
436 | 436 |
ancestor_map, low_map)) { |
437 | 437 |
rd = true; |
438 | 438 |
} else if (!external(ynode, rorder, child_lists, |
439 | 439 |
ancestor_map, low_map)) { |
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-2010 |
|
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 |
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-2010 |
|
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 |
... | ... |
@@ -185,9 +185,9 @@ |
185 | 185 |
///\brief A smart directed graph class. |
186 | 186 |
/// |
187 | 187 |
///\ref SmartDigraph is a simple and fast digraph implementation. |
188 | 188 |
///It is also quite memory efficient but at the price |
189 |
///that it does not support node and arc deletion |
|
189 |
///that it does not support node and arc deletion |
|
190 | 190 |
///(except for the Snapshot feature). |
191 | 191 |
/// |
192 | 192 |
///This type fully conforms to the \ref concepts::Digraph "Digraph concept" |
193 | 193 |
///and it also provides some additional functionalities. |
... | ... |
@@ -334,9 +334,9 @@ |
334 | 334 |
///The newly added nodes and arcs can be removed using the |
335 | 335 |
///restore() function. This is the only way for deleting nodes and/or |
336 | 336 |
///arcs from a SmartDigraph structure. |
337 | 337 |
/// |
338 |
///\note After a state is restored, you cannot restore a later state, |
|
338 |
///\note After a state is restored, you cannot restore a later state, |
|
339 | 339 |
///i.e. you cannot add the removed nodes and arcs again using |
340 | 340 |
///another Snapshot instance. |
341 | 341 |
/// |
342 | 342 |
///\warning Node splitting cannot be restored. |
... | ... |
@@ -613,9 +613,9 @@ |
613 | 613 |
/// \brief A smart undirected graph class. |
614 | 614 |
/// |
615 | 615 |
/// \ref SmartGraph is a simple and fast graph implementation. |
616 | 616 |
/// It is also quite memory efficient but at the price |
617 |
/// that it does not support node and edge deletion |
|
617 |
/// that it does not support node and edge deletion |
|
618 | 618 |
/// (except for the Snapshot feature). |
619 | 619 |
/// |
620 | 620 |
/// This type fully conforms to the \ref concepts::Graph "Graph concept" |
621 | 621 |
/// and it also provides some additional functionalities. |
... | ... |
@@ -760,9 +760,9 @@ |
760 | 760 |
///The newly added nodes and edges can be removed using the |
761 | 761 |
///restore() function. This is the only way for deleting nodes and/or |
762 | 762 |
///edges from a SmartGraph structure. |
763 | 763 |
/// |
764 |
///\note After a state is restored, you cannot restore a later state, |
|
764 |
///\note After a state is restored, you cannot restore a later state, |
|
765 | 765 |
///i.e. you cannot add the removed nodes and edges again using |
766 | 766 |
///another Snapshot instance. |
767 | 767 |
/// |
768 | 768 |
///\warning The validity of the snapshot is not stored due to |
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-2010 |
|
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 |
... | ... |
@@ -286,9 +286,9 @@ |
286 | 286 |
|
287 | 287 |
SoplexLp::SolveExitStatus SoplexLp::_solve() { |
288 | 288 |
|
289 | 289 |
_clear_temporals(); |
290 |
|
|
290 |
|
|
291 | 291 |
_applyMessageLevel(); |
292 | 292 |
|
293 | 293 |
soplex::SPxSolver::Status status = soplex->solve(); |
294 | 294 |
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-2010 |
|
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 |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 |
* Copyright (C) 2003- |
|
5 |
* Copyright (C) 2003-2010 |
|
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 |
... | ... |
@@ -30,14 +30,14 @@ |
30 | 30 |
|
31 | 31 |
class StaticDigraphBase { |
32 | 32 |
public: |
33 | 33 |
|
34 |
StaticDigraphBase() |
|
35 |
: built(false), node_num(0), arc_num(0), |
|
34 |
StaticDigraphBase() |
|
35 |
: built(false), node_num(0), arc_num(0), |
|
36 | 36 |
node_first_out(NULL), node_first_in(NULL), |
37 |
arc_source(NULL), arc_target(NULL), |
|
37 |
arc_source(NULL), arc_target(NULL), |
|
38 | 38 |
arc_next_in(NULL), arc_next_out(NULL) {} |
39 |
|
|
39 |
|
|
40 | 40 |
~StaticDigraphBase() { |
41 | 41 |
if (built) { |
42 | 42 |
delete[] node_first_out; |
43 | 43 |
delete[] node_first_in; |
... | ... |
@@ -61,9 +61,9 @@ |
61 | 61 |
bool operator<(const Node& node) const { return id < node.id; } |
62 | 62 |
}; |
63 | 63 |
|
64 | 64 |
class Arc { |
65 |
friend class StaticDigraphBase; |
|
65 |
friend class StaticDigraphBase; |
|
66 | 66 |
protected: |
67 | 67 |
int id; |
68 | 68 |
Arc(int _id) : id(_id) {} |
69 | 69 |
public: |
... | ... |
@@ -82,10 +82,10 @@ |
82 | 82 |
|
83 | 83 |
void first(Arc& e) const { e.id = arc_num - 1; } |
84 | 84 |
static void next(Arc& e) { --e.id; } |
85 | 85 |
|
86 |
void firstOut(Arc& e, const Node& n) const { |
|
87 |
e.id = node_first_out[n.id] != node_first_out[n.id + 1] ? |
|
86 |
void firstOut(Arc& e, const Node& n) const { |
|
87 |
e.id = node_first_out[n.id] != node_first_out[n.id + 1] ? |
|
88 | 88 |
node_first_out[n.id] : -1; |
89 | 89 |
} |
90 | 90 |
void nextOut(Arc& e) const { e.id = arc_next_out[e.id]; } |
91 | 91 |
|
... | ... |
@@ -112,23 +112,23 @@ |
112 | 112 |
class ArcLess { |
113 | 113 |
public: |
114 | 114 |
typedef typename Digraph::Arc Arc; |
115 | 115 |
|
116 |
ArcLess(const Digraph &_graph, const NodeRefMap& _nodeRef) |
|
116 |
ArcLess(const Digraph &_graph, const NodeRefMap& _nodeRef) |
|
117 | 117 |
: digraph(_graph), nodeRef(_nodeRef) {} |
118 |
|
|
118 |
|
|
119 | 119 |
bool operator()(const Arc& left, const Arc& right) const { |
120 |
|
|
120 |
return nodeRef[digraph.target(left)] < nodeRef[digraph.target(right)]; |
|
121 | 121 |
} |
122 | 122 |
private: |
123 | 123 |
const Digraph& digraph; |
124 | 124 |
const NodeRefMap& nodeRef; |
125 | 125 |
}; |
126 |
|
|
126 |
|
|
127 | 127 |
public: |
128 | 128 |
|
129 | 129 |
typedef True BuildTag; |
130 |
|
|
130 |
|
|
131 | 131 |
void clear() { |
132 | 132 |
if (built) { |
133 | 133 |
delete[] node_first_out; |
134 | 134 |
delete[] node_first_in; |
... | ... |
@@ -140,9 +140,9 @@ |
140 | 140 |
built = false; |
141 | 141 |
node_num = 0; |
142 | 142 |
arc_num = 0; |
143 | 143 |
} |
144 |
|
|
144 |
|
|
145 | 145 |
template <typename Digraph, typename NodeRefMap, typename ArcRefMap> |
146 | 146 |
void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) { |
147 | 147 |
typedef typename Digraph::Node GNode; |
148 | 148 |
typedef typename Digraph::Arc GArc; |
... | ... |
@@ -182,9 +182,9 @@ |
182 | 182 |
for (typename std::vector<GArc>::iterator it = arcs.begin(); |
183 | 183 |
it != arcs.end(); ++it) { |
184 | 184 |
int target = nodeRef[digraph.target(*it)].id; |
185 | 185 |
arcRef[*it] = Arc(arc_index); |
186 |
arc_source[arc_index] = source; |
|
186 |
arc_source[arc_index] = source; |
|
187 | 187 |
arc_target[arc_index] = target; |
188 | 188 |
arc_next_in[arc_index] = node_first_in[target]; |
189 | 189 |
node_first_in[target] = arc_index; |
190 | 190 |
arc_next_out[arc_index] = arc_index + 1; |
... | ... |
@@ -196,9 +196,9 @@ |
196 | 196 |
} |
197 | 197 |
} |
198 | 198 |
node_first_out[node_num] = arc_num; |
199 | 199 |
} |
200 |
|
|
200 |
|
|
201 | 201 |
template <typename ArcListIterator> |
202 | 202 |
void build(int n, ArcListIterator first, ArcListIterator last) { |
203 | 203 |
built = true; |
204 | 204 |
|
... | ... |
@@ -211,13 +211,13 @@ |
211 | 211 |
arc_source = new int[arc_num]; |
212 | 212 |
arc_target = new int[arc_num]; |
213 | 213 |
arc_next_out = new int[arc_num]; |
214 | 214 |
arc_next_in = new int[arc_num]; |
215 |
|
|
215 |
|
|
216 | 216 |
for (int i = 0; i != node_num; ++i) { |
217 | 217 |
node_first_in[i] = -1; |
218 |
} |
|
219 |
|
|
218 |
} |
|
219 |
|
|
220 | 220 |
int arc_index = 0; |
221 | 221 |
for (int i = 0; i != node_num; ++i) { |
222 | 222 |
node_first_out[i] = arc_index; |
223 | 223 |
for ( ; first != last && (*first).first == i; ++first) { |
... | ... |
@@ -281,9 +281,9 @@ |
281 | 281 |
/// support any other modification of the digraph. |
282 | 282 |
/// |
283 | 283 |
/// Since this digraph structure is completely static, its nodes and arcs |
284 | 284 |
/// can be indexed with integers from the ranges <tt>[0..nodeNum()-1]</tt> |
285 |
/// and <tt>[0..arcNum()-1]</tt>, respectively. |
|
285 |
/// and <tt>[0..arcNum()-1]</tt>, respectively. |
|
286 | 286 |
/// The index of an item is the same as its ID, it can be obtained |
287 | 287 |
/// using the corresponding \ref index() or \ref concepts::Digraph::id() |
288 | 288 |
/// "id()" function. A node or arc with a certain index can be obtained |
289 | 289 |
/// using node() or arc(). |
... | ... |
@@ -298,11 +298,11 @@ |
298 | 298 |
class StaticDigraph : public ExtendedStaticDigraphBase { |
299 | 299 |
public: |
300 | 300 |
|
301 | 301 |
typedef ExtendedStaticDigraphBase Parent; |
302 |
|
|
302 |
|
|
303 | 303 |
public: |
304 |
|
|
304 |
|
|
305 | 305 |
/// \brief Constructor |
306 | 306 |
/// |
307 | 307 |
/// Default constructor. |
308 | 308 |
StaticDigraph() : Parent() {} |
... | ... |
@@ -348,9 +348,9 @@ |
348 | 348 |
/// structure and all maps will be cleared and rebuilt. |
349 | 349 |
/// |
350 | 350 |
/// This method also makes possible to copy a digraph to a StaticDigraph |
351 | 351 |
/// structure using \ref DigraphCopy. |
352 |
/// |
|
352 |
/// |
|
353 | 353 |
/// \param digraph An existing digraph to be copied. |
354 | 354 |
/// \param nodeRef The node references will be copied into this map. |
355 | 355 |
/// Its key type must be \c Digraph::Node and its value type must be |
356 | 356 |
/// \c StaticDigraph::Node. |
... | ... |
@@ -369,9 +369,9 @@ |
369 | 369 |
void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) { |
370 | 370 |
if (built) Parent::clear(); |
371 | 371 |
Parent::build(digraph, nodeRef, arcRef); |
372 | 372 |
} |
373 |
|
|
373 |
|
|
374 | 374 |
/// \brief Build the digraph from an arc list. |
375 | 375 |
/// |
376 | 376 |
/// This function builds the digraph from the given arc list. |
377 | 377 |
/// It can be called more than once, but in such case, the whole |
... | ... |
@@ -420,9 +420,9 @@ |
420 | 420 |
|
421 | 421 |
using Parent::fastFirstOut; |
422 | 422 |
using Parent::fastNextOut; |
423 | 423 |
using Parent::fastLastOut; |
424 |
|
|
424 |
|
|
425 | 425 |
public: |
426 | 426 |
|
427 | 427 |
class OutArcIt : public Arc { |
428 | 428 |
public: |
... | ... |
@@ -431,10 +431,10 @@ |
431 | 431 |
|
432 | 432 |
OutArcIt(Invalid i) : Arc(i) { } |
433 | 433 |
|
434 | 434 |
OutArcIt(const StaticDigraph& digraph, const Node& node) { |
435 |
digraph.fastFirstOut(*this, node); |
|
436 |
digraph.fastLastOut(last, node); |
|
435 |
digraph.fastFirstOut(*this, node); |
|
436 |
digraph.fastLastOut(last, node); |
|
437 | 437 |
if (last == *this) *this = INVALID; |
438 | 438 |
} |
439 | 439 |
|
440 | 440 |
OutArcIt(const StaticDigraph& digraph, const Arc& arc) : Arc(arc) { |
... | ... |
@@ -442,12 +442,12 @@ |
442 | 442 |
digraph.fastLastOut(last, digraph.source(arc)); |
443 | 443 |
} |
444 | 444 |
} |
445 | 445 |
|
446 |
OutArcIt& operator++() { |
|
446 |
OutArcIt& operator++() { |
|
447 | 447 |
StaticDigraph::fastNextOut(*this); |
448 | 448 |
if (last == *this) *this = INVALID; |
449 |
return *this; |
|
449 |
return *this; |
|
450 | 450 |
} |
451 | 451 |
|
452 | 452 |
private: |
453 | 453 |
Arc last; |
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-2010 |
|
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 |
... | ... |
@@ -64,9 +64,9 @@ |
64 | 64 |
/// The type used for storing the found arc-disjoint paths. |
65 | 65 |
/// It must conform to the \ref lemon::concepts::Path "Path" concept |
66 | 66 |
/// and it must have an \c addBack() function. |
67 | 67 |
typedef lemon::Path<Digraph> Path; |
68 |
|
|
68 |
|
|
69 | 69 |
/// The cross reference type used for the heap. |
70 | 70 |
typedef typename GR::template NodeMap<int> HeapCrossRef; |
71 | 71 |
|
72 | 72 |
/// \brief The heap type used for internal Dijkstra computations. |
... | ... |
@@ -157,28 +157,28 @@ |
157 | 157 |
PotentialMap &_pi; |
158 | 158 |
PredMap &_pred; |
159 | 159 |
Node _s; |
160 | 160 |
Node _t; |
161 |
|
|
161 |
|
|
162 | 162 |
PotentialMap _dist; |
163 | 163 |
std::vector<Node> _proc_nodes; |
164 | 164 |
|
165 | 165 |
public: |
166 | 166 |
|
167 | 167 |
// Constructor |
168 | 168 |
ResidualDijkstra(Suurballe &srb) : |
169 | 169 |
_graph(srb._graph), _length(srb._length), |
170 |
_flow(*srb._flow), _pi(*srb._potential), _pred(srb._pred), |
|
170 |
_flow(*srb._flow), _pi(*srb._potential), _pred(srb._pred), |
|
171 | 171 |
_s(srb._s), _t(srb._t), _dist(_graph) {} |
172 |
|
|
172 |
|
|
173 | 173 |
// Run the algorithm and return true if a path is found |
174 | 174 |
// from the source node to the target node. |
175 | 175 |
bool run(int cnt) { |
176 | 176 |
return cnt == 0 ? startFirst() : start(); |
177 | 177 |
} |
178 | 178 |
|
179 | 179 |
private: |
180 |
|
|
180 |
|
|
181 | 181 |
// Execute the algorithm for the first time (the flow and potential |
182 | 182 |
// functions have to be identically zero). |
183 | 183 |
bool startFirst() { |
184 | 184 |
HeapCrossRef heap_cross_ref(_graph, Heap::PRE_HEAP); |
... | ... |
@@ -347,9 +347,9 @@ |
347 | 347 |
struct SetPath |
348 | 348 |
: public Suurballe<GR, LEN, SetPathTraits<T> > { |
349 | 349 |
typedef Suurballe<GR, LEN, SetPathTraits<T> > Create; |
350 | 350 |
}; |
351 |
|
|
351 |
|
|
352 | 352 |
template <typename H, typename CR> |
353 | 353 |
struct SetHeapTraits : public Traits { |
354 | 354 |
typedef H Heap; |
355 | 355 |
typedef CR HeapCrossRef; |
... | ... |
@@ -358,9 +358,9 @@ |
358 | 358 |
/// \brief \ref named-templ-param "Named parameter" for setting |
359 | 359 |
/// \c Heap and \c HeapCrossRef types. |
360 | 360 |
/// |
361 | 361 |
/// \ref named-templ-param "Named parameter" for setting \c Heap |
362 |
/// and \c HeapCrossRef types with automatic allocation. |
|
362 |
/// and \c HeapCrossRef types with automatic allocation. |
|
363 | 363 |
/// They will be used for internal Dijkstra computations. |
364 | 364 |
/// The heap type must conform to the \ref lemon::concepts::Heap "Heap" |
365 | 365 |
/// concept and its priority type must be \c Length. |
366 | 366 |
template <typename H, |
... | ... |
@@ -396,9 +396,9 @@ |
396 | 396 |
int _path_num; |
397 | 397 |
|
398 | 398 |
// The pred arc map |
399 | 399 |
PredMap _pred; |
400 |
|
|
400 |
|
|
401 | 401 |
// Data for full init |
402 | 402 |
PotentialMap *_init_dist; |
403 | 403 |
PredMap *_init_pred; |
404 | 404 |
bool _full_init; |
... | ... |
@@ -554,9 +554,9 @@ |
554 | 554 |
::template SetPredMap<PredMap> |
555 | 555 |
::Create dijk(_graph, _length); |
556 | 556 |
dijk.distMap(*_init_dist).predMap(*_init_pred); |
557 | 557 |
dijk.run(s); |
558 |
|
|
558 |
|
|
559 | 559 |
_full_init = true; |
560 | 560 |
} |
561 | 561 |
|
562 | 562 |
/// \brief Execute the algorithm. |
... | ... |
@@ -598,9 +598,9 @@ |
598 | 598 |
/// \pre \ref init() must be called before using this function. |
599 | 599 |
int findFlow(const Node& t, int k = 2) { |
600 | 600 |
_t = t; |
601 | 601 |
ResidualDijkstra dijkstra(*this); |
602 |
|
|
602 |
|
|
603 | 603 |
// Initialization |
604 | 604 |
for (ArcIt e(_graph); e != INVALID; ++e) { |
605 | 605 |
(*_flow)[e] = 0; |
606 | 606 |
} |
... | ... |
@@ -612,9 +612,9 @@ |
612 | 612 |
Arc e; |
613 | 613 |
while ((e = (*_init_pred)[u]) != INVALID) { |
614 | 614 |
(*_flow)[e] = 1; |
615 | 615 |
u = _graph.source(e); |
616 |
} |
|
616 |
} |
|
617 | 617 |
_path_num = 1; |
618 | 618 |
} else { |
619 | 619 |
for (NodeIt n(_graph); n != INVALID; ++n) { |
620 | 620 |
(*_potential)[n] = 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-2010 |
|
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 |
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-2010 |
|
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 |
... | ... |
@@ -96,9 +96,9 @@ |
96 | 96 |
d = const_bf_test.distMap(); |
97 | 97 |
p = const_bf_test.predMap(); |
98 | 98 |
pp = const_bf_test.path(t); |
99 | 99 |
pp = const_bf_test.negativeCycle(); |
100 |
|
|
100 |
|
|
101 | 101 |
for (BF::ActiveIt it(const_bf_test); it != INVALID; ++it) {} |
102 | 102 |
} |
103 | 103 |
{ |
104 | 104 |
BF::SetPredMap<concepts::ReadWriteMap<Node,Arc> > |
... | ... |
@@ -109,9 +109,9 @@ |
109 | 109 |
|
110 | 110 |
LengthMap length_map; |
111 | 111 |
concepts::ReadWriteMap<Node,Arc> pred_map; |
112 | 112 |
concepts::ReadWriteMap<Node,Value> dist_map; |
113 |
|
|
113 |
|
|
114 | 114 |
bf_test |
115 | 115 |
.lengthMap(length_map) |
116 | 116 |
.predMap(pred_map) |
117 | 117 |
.distMap(dist_map); |
... | ... |
@@ -188,9 +188,9 @@ |
188 | 188 |
check(p.length() == 3, "path() found a wrong path."); |
189 | 189 |
check(checkPath(gr, p), "path() found a wrong path."); |
190 | 190 |
check(pathSource(gr, p) == s, "path() found a wrong path."); |
191 | 191 |
check(pathTarget(gr, p) == t, "path() found a wrong path."); |
192 |
|
|
192 |
|
|
193 | 193 |
ListPath<Digraph> path; |
194 | 194 |
Value dist; |
195 | 195 |
bool reached = bellmanFord(gr,length).path(path).dist(dist).run(s,t); |
196 | 196 |
|
... | ... |
@@ -227,42 +227,42 @@ |
227 | 227 |
DIGRAPH_TYPEDEFS(SmartDigraph); |
228 | 228 |
|
229 | 229 |
SmartDigraph gr; |
230 | 230 |
IntArcMap length(gr); |
231 |
|
|
231 |
|
|
232 | 232 |
Node n1 = gr.addNode(); |
233 | 233 |
Node n2 = gr.addNode(); |
234 | 234 |
Node n3 = gr.addNode(); |
235 | 235 |
Node n4 = gr.addNode(); |
236 |
|
|
236 |
|
|
237 | 237 |
Arc a1 = gr.addArc(n1, n2); |
238 | 238 |
Arc a2 = gr.addArc(n2, n2); |
239 |
|
|
239 |
|
|
240 | 240 |
length[a1] = 2; |
241 | 241 |
length[a2] = -1; |
242 |
|
|
242 |
|
|
243 | 243 |
{ |
244 | 244 |
BellmanFord<SmartDigraph, IntArcMap> bf(gr, length); |
245 | 245 |
bf.run(n1); |
246 | 246 |
StaticPath<SmartDigraph> p = bf.negativeCycle(); |
247 | 247 |
check(p.length() == 1 && p.front() == p.back() && p.front() == a2, |
248 | 248 |
"Wrong negative cycle."); |
249 | 249 |
} |
250 |
|
|
250 |
|
|
251 | 251 |
length[a2] = 0; |
252 |
|
|
252 |
|
|
253 | 253 |
{ |
254 | 254 |
BellmanFord<SmartDigraph, IntArcMap> bf(gr, length); |
255 | 255 |
bf.run(n1); |
256 | 256 |
check(bf.negativeCycle().empty(), |
257 | 257 |
"Negative cycle should not be found."); |
258 | 258 |
} |
259 |
|
|
259 |
|
|
260 | 260 |
length[gr.addArc(n1, n3)] = 5; |
261 | 261 |
length[gr.addArc(n4, n3)] = 1; |
262 | 262 |
length[gr.addArc(n2, n4)] = 2; |
263 | 263 |
length[gr.addArc(n3, n2)] = -4; |
264 |
|
|
264 |
|
|
265 | 265 |
{ |
266 | 266 |
BellmanFord<SmartDigraph, IntArcMap> bf(gr, length); |
267 | 267 |
bf.init(); |
268 | 268 |
bf.addSource(n1); |
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-2010 |
|
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 |
... | ... |
@@ -82,9 +82,9 @@ |
82 | 82 |
n = bfs_test.processNextNode(nm, n); |
83 | 83 |
n = const_bfs_test.nextNode(); |
84 | 84 |
b = const_bfs_test.emptyQueue(); |
85 | 85 |
i = const_bfs_test.queueSize(); |
86 |
|
|
86 |
|
|
87 | 87 |
bfs_test.start(); |
88 | 88 |
bfs_test.start(t); |
89 | 89 |
bfs_test.start(nm); |
90 | 90 |
|
... | ... |
@@ -103,14 +103,14 @@ |
103 | 103 |
::SetReachedMap<concepts::ReadWriteMap<Node,bool> > |
104 | 104 |
::SetStandardProcessedMap |
105 | 105 |
::SetProcessedMap<concepts::WriteMap<Node,bool> > |
106 | 106 |
::Create bfs_test(G); |
107 |
|
|
107 |
|
|
108 | 108 |
concepts::ReadWriteMap<Node,Arc> pred_map; |
109 | 109 |
concepts::ReadWriteMap<Node,int> dist_map; |
110 | 110 |
concepts::ReadWriteMap<Node,bool> reached_map; |
111 | 111 |
concepts::WriteMap<Node,bool> processed_map; |
112 |
|
|
112 |
|
|
113 | 113 |
bfs_test |
114 | 114 |
.predMap(pred_map) |
115 | 115 |
.distMap(dist_map) |
116 | 116 |
.reachedMap(reached_map) |
... | ... |
@@ -118,18 +118,18 @@ |
118 | 118 |
|
119 | 119 |
bfs_test.run(s); |
120 | 120 |
bfs_test.run(s,t); |
121 | 121 |
bfs_test.run(); |
122 |
|
|
122 |
|
|
123 | 123 |
bfs_test.init(); |
124 | 124 |
bfs_test.addSource(s); |
125 | 125 |
n = bfs_test.processNextNode(); |
126 | 126 |
n = bfs_test.processNextNode(t, b); |
127 | 127 |
n = bfs_test.processNextNode(nm, n); |
128 | 128 |
n = bfs_test.nextNode(); |
129 | 129 |
b = bfs_test.emptyQueue(); |
130 | 130 |
i = bfs_test.queueSize(); |
131 |
|
|
131 |
|
|
132 | 132 |
bfs_test.start(); |
133 | 133 |
bfs_test.start(t); |
134 | 134 |
bfs_test.start(nm); |
135 | 135 |
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-2010 |
|
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 |
... | ... |
@@ -80,15 +80,15 @@ |
80 | 80 |
::SetStandardElevator<LinkedElev> |
81 | 81 |
::Create CirculationType; |
82 | 82 |
CirculationType circ_test(g, lcap, ucap, supply); |
83 | 83 |
const CirculationType& const_circ_test = circ_test; |
84 |
|
|
84 |
|
|
85 | 85 |
circ_test |
86 | 86 |
.lowerMap(lcap) |
87 | 87 |
.upperMap(ucap) |
88 | 88 |
.supplyMap(supply) |
89 | 89 |
.flowMap(flow); |
90 |
|
|
90 |
|
|
91 | 91 |
const CirculationType::Elevator& elev = const_circ_test.elevator(); |
92 | 92 |
circ_test.elevator(const_cast<CirculationType::Elevator&>(elev)); |
93 | 93 |
CirculationType::Tolerance tol = const_circ_test.tolerance(); |
94 | 94 |
circ_test.tolerance(tol); |
... | ... |
@@ -101,9 +101,9 @@ |
101 | 101 |
v = const_circ_test.flow(a); |
102 | 102 |
const FlowMap& fm = const_circ_test.flowMap(); |
103 | 103 |
b = const_circ_test.barrier(n); |
104 | 104 |
const_circ_test.barrierMap(bar); |
105 |
|
|
105 |
|
|
106 | 106 |
ignore_unused_variable_warning(fm); |
107 | 107 |
} |
108 | 108 |
|
109 | 109 |
template <class G, class LM, class UM, class DM> |
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-2010 |
|
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 |
... | ... |
@@ -28,14 +28,14 @@ |
28 | 28 |
int main() |
29 | 29 |
{ |
30 | 30 |
typedef ListDigraph Digraph; |
31 | 31 |
typedef Undirector<Digraph> Graph; |
32 |
|
|
32 |
|
|
33 | 33 |
{ |
34 | 34 |
Digraph d; |
35 | 35 |
Digraph::NodeMap<int> order(d); |
36 | 36 |
Graph g(d); |
37 |
|
|
37 |
|
|
38 | 38 |
check(stronglyConnected(d), "The empty digraph is strongly connected"); |
39 | 39 |
check(countStronglyConnectedComponents(d) == 0, |
40 | 40 |
"The empty digraph has 0 strongly connected component"); |
41 | 41 |
check(connected(g), "The empty graph is connected"); |
... | ... |
@@ -47,9 +47,9 @@ |
47 | 47 |
"The empty graph has 0 bi-node-connected component"); |
48 | 48 |
check(biEdgeConnected(g), "The empty graph is bi-edge-connected"); |
49 | 49 |
check(countBiEdgeConnectedComponents(g) == 0, |
50 | 50 |
"The empty graph has 0 bi-edge-connected component"); |
51 |
|
|
51 |
|
|
52 | 52 |
check(dag(d), "The empty digraph is DAG."); |
53 | 53 |
check(checkedTopologicalSort(d, order), "The empty digraph is DAG."); |
54 | 54 |
check(loopFree(d), "The empty digraph is loop-free."); |
55 | 55 |
check(parallelFree(d), "The empty digraph is parallel-free."); |
... | ... |
@@ -81,9 +81,9 @@ |
81 | 81 |
"This graph has 0 bi-node-connected component"); |
82 | 82 |
check(biEdgeConnected(g), "This graph is bi-edge-connected"); |
83 | 83 |
check(countBiEdgeConnectedComponents(g) == 1, |
84 | 84 |
"This graph has 1 bi-edge-connected component"); |
85 |
|
|
85 |
|
|
86 | 86 |
check(dag(d), "This digraph is DAG."); |
87 | 87 |
check(checkedTopologicalSort(d, order), "This digraph is DAG."); |
88 | 88 |
check(loopFree(d), "This digraph is loop-free."); |
89 | 89 |
check(parallelFree(d), "This digraph is parallel-free."); |
... | ... |
@@ -100,16 +100,16 @@ |
100 | 100 |
{ |
101 | 101 |
Digraph d; |
102 | 102 |
Digraph::NodeMap<int> order(d); |
103 | 103 |
Graph g(d); |
104 |
|
|
104 |
|
|
105 | 105 |
Digraph::Node n1 = d.addNode(); |
106 | 106 |
Digraph::Node n2 = d.addNode(); |
107 | 107 |
Digraph::Node n3 = d.addNode(); |
108 | 108 |
Digraph::Node n4 = d.addNode(); |
109 | 109 |
Digraph::Node n5 = d.addNode(); |
110 | 110 |
Digraph::Node n6 = d.addNode(); |
111 |
|
|
111 |
|
|
112 | 112 |
d.addArc(n1, n3); |
113 | 113 |
d.addArc(n3, n2); |
114 | 114 |
d.addArc(n2, n1); |
115 | 115 |
d.addArc(n4, n2); |
... | ... |
@@ -135,25 +135,25 @@ |
135 | 135 |
check(!bipartite(g), "This graph is not bipartite."); |
136 | 136 |
check(loopFree(g), "This graph is loop-free."); |
137 | 137 |
check(!parallelFree(g), "This graph is not parallel-free."); |
138 | 138 |
check(!simpleGraph(g), "This graph is not simple."); |
139 |
|
|
139 |
|
|
140 | 140 |
d.addArc(n3, n3); |
141 |
|
|
141 |
|
|
142 | 142 |
check(!loopFree(d), "This digraph is not loop-free."); |
143 | 143 |
check(!loopFree(g), "This graph is not loop-free."); |
144 | 144 |
check(!simpleGraph(d), "This digraph is not simple."); |
145 |
|
|
145 |
|
|
146 | 146 |
d.addArc(n3, n2); |
147 |
|
|
147 |
|
|
148 | 148 |
check(!parallelFree(d), "This digraph is not parallel-free."); |
149 | 149 |
} |
150 |
|
|
150 |
|
|
151 | 151 |
{ |
152 | 152 |
Digraph d; |
153 | 153 |
Digraph::ArcMap<bool> cutarcs(d, false); |
154 | 154 |
Graph g(d); |
155 |
|
|
155 |
|
|
156 | 156 |
Digraph::Node n1 = d.addNode(); |
157 | 157 |
Digraph::Node n2 = d.addNode(); |
158 | 158 |
Digraph::Node n3 = d.addNode(); |
159 | 159 |
Digraph::Node n4 = d.addNode(); |
... | ... |
@@ -171,9 +171,9 @@ |
171 | 171 |
d.addArc(n2, n5); |
172 | 172 |
d.addArc(n1, n8); |
173 | 173 |
d.addArc(n6, n7); |
174 | 174 |
d.addArc(n7, n6); |
175 |
|
|
175 |
|
|
176 | 176 |
check(!stronglyConnected(d), "This digraph is not strongly connected"); |
177 | 177 |
check(countStronglyConnectedComponents(d) == 3, |
178 | 178 |
"This digraph has 3 strongly connected components"); |
179 | 179 |
Digraph::NodeMap<int> scomp1(d); |
... | ... |
@@ -234,9 +234,9 @@ |
234 | 234 |
// DAG example for topological sort from the book New Algorithms |
235 | 235 |
// (T. H. Cormen, C. E. Leiserson, R. L. Rivest, C. Stein) |
236 | 236 |
Digraph d; |
237 | 237 |
Digraph::NodeMap<int> order(d); |
238 |
|
|
238 |
|
|
239 | 239 |
Digraph::Node belt = d.addNode(); |
240 | 240 |
Digraph::Node trousers = d.addNode(); |
241 | 241 |
Digraph::Node necktie = d.addNode(); |
242 | 242 |
Digraph::Node coat = d.addNode(); |
... | ... |
@@ -254,9 +254,9 @@ |
254 | 254 |
d.addArc(belt, coat); |
255 | 255 |
d.addArc(shirt, belt); |
256 | 256 |
d.addArc(shirt, necktie); |
257 | 257 |
d.addArc(necktie, coat); |
258 |
|
|
258 |
|
|
259 | 259 |
check(dag(d), "This digraph is DAG."); |
260 | 260 |
topologicalSort(d, order); |
261 | 261 |
for (Digraph::ArcIt a(d); a != INVALID; ++a) { |
262 | 262 |
check(order[d.source(a)] < order[d.target(a)], |
... | ... |
@@ -266,9 +266,9 @@ |
266 | 266 |
|
267 | 267 |
{ |
268 | 268 |
ListGraph g; |
269 | 269 |
ListGraph::NodeMap<bool> map(g); |
270 |
|
|
270 |
|
|
271 | 271 |
ListGraph::Node n1 = g.addNode(); |
272 | 272 |
ListGraph::Node n2 = g.addNode(); |
273 | 273 |
ListGraph::Node n3 = g.addNode(); |
274 | 274 |
ListGraph::Node n4 = g.addNode(); |
... | ... |
@@ -282,12 +282,12 @@ |
282 | 282 |
g.addEdge(n3, n6); |
283 | 283 |
g.addEdge(n4, n6); |
284 | 284 |
g.addEdge(n4, n7); |
285 | 285 |
g.addEdge(n5, n7); |
286 |
|
|
286 |
|
|
287 | 287 |
check(bipartite(g), "This graph is bipartite"); |
288 | 288 |
check(bipartitePartitions(g, map), "This graph is bipartite"); |
289 |
|
|
289 |
|
|
290 | 290 |
check(map[n1] == map[n2] && map[n1] == map[n6] && map[n1] == map[n7], |
291 | 291 |
"Wrong bipartitePartitions()"); |
292 | 292 |
check(map[n3] == map[n4] && map[n3] == map[n5], |
293 | 293 |
"Wrong bipartitePartitions()"); |
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-2010 |
|
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 |
... | ... |
@@ -82,9 +82,9 @@ |
82 | 82 |
e = dfs_test.processNextArc(); |
83 | 83 |
e = const_dfs_test.nextArc(); |
84 | 84 |
b = const_dfs_test.emptyQueue(); |
85 | 85 |
i = const_dfs_test.queueSize(); |
86 |
|
|
86 |
|
|
87 | 87 |
dfs_test.start(); |
88 | 88 |
dfs_test.start(t); |
89 | 89 |
dfs_test.start(am); |
90 | 90 |
|
... | ... |
@@ -108,9 +108,9 @@ |
108 | 108 |
concepts::ReadWriteMap<Node,Arc> pred_map; |
109 | 109 |
concepts::ReadWriteMap<Node,int> dist_map; |
110 | 110 |
concepts::ReadWriteMap<Node,bool> reached_map; |
111 | 111 |
concepts::WriteMap<Node,bool> processed_map; |
112 |
|
|
112 |
|
|
113 | 113 |
dfs_test |
114 | 114 |
.predMap(pred_map) |
115 | 115 |
.distMap(dist_map) |
116 | 116 |
.reachedMap(reached_map) |
... | ... |
@@ -125,9 +125,9 @@ |
125 | 125 |
e = dfs_test.processNextArc(); |
126 | 126 |
e = dfs_test.nextArc(); |
127 | 127 |
b = dfs_test.emptyQueue(); |
128 | 128 |
i = dfs_test.queueSize(); |
129 |
|
|
129 |
|
|
130 | 130 |
dfs_test.start(); |
131 | 131 |
dfs_test.start(t); |
132 | 132 |
dfs_test.start(am); |
133 | 133 |
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-2010 |
|
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 |
... | ... |
@@ -391,11 +391,11 @@ |
391 | 391 |
void checkStaticDigraph() { |
392 | 392 |
SmartDigraph g; |
393 | 393 |
SmartDigraph::NodeMap<StaticDigraph::Node> nref(g); |
394 | 394 |
SmartDigraph::ArcMap<StaticDigraph::Arc> aref(g); |
395 |
|
|
395 |
|
|
396 | 396 |
StaticDigraph G; |
397 |
|
|
397 |
|
|
398 | 398 |
checkGraphNodeList(G, 0); |
399 | 399 |
checkGraphArcList(G, 0); |
400 | 400 |
|
401 | 401 |
G.build(g, nref, aref); |
... | ... |
@@ -463,9 +463,9 @@ |
463 | 463 |
arcs.push_back(std::make_pair(4,3)); |
464 | 464 |
arcs.push_back(std::make_pair(4,1)); |
465 | 465 |
|
466 | 466 |
G.build(6, arcs.begin(), arcs.end()); |
467 |
|
|
467 |
|
|
468 | 468 |
checkGraphNodeList(G, 6); |
469 | 469 |
checkGraphArcList(G, 9); |
470 | 470 |
|
471 | 471 |
checkGraphOutArcList(G, G.node(0), 2); |
... | ... |
@@ -487,9 +487,9 @@ |
487 | 487 |
checkNodeIds(G); |
488 | 488 |
checkArcIds(G); |
489 | 489 |
checkGraphNodeMap(G); |
490 | 490 |
checkGraphArcMap(G); |
491 |
|
|
491 |
|
|
492 | 492 |
int n = G.nodeNum(); |
493 | 493 |
int m = G.arcNum(); |
494 | 494 |
check(G.index(G.node(n-1)) == n-1, "Wrong index."); |
495 | 495 |
check(G.index(G.arc(m-1)) == m-1, "Wrong index."); |
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-2010 |
|
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 |
... | ... |
@@ -84,9 +84,9 @@ |
84 | 84 |
n = dijkstra_test.processNextNode(); |
85 | 85 |
n = const_dijkstra_test.nextNode(); |
86 | 86 |
b = const_dijkstra_test.emptyQueue(); |
87 | 87 |
i = const_dijkstra_test.queueSize(); |
88 |
|
|
88 |
|
|
89 | 89 |
dijkstra_test.start(); |
90 | 90 |
dijkstra_test.start(t); |
91 | 91 |
dijkstra_test.start(nm); |
92 | 92 |
|
... | ... |
@@ -108,9 +108,9 @@ |
108 | 108 |
::SetProcessedMap<concepts::WriteMap<Node,bool> > |
109 | 109 |
::SetOperationTraits<DijkstraDefaultOperationTraits<VType> > |
110 | 110 |
::SetHeap<BinHeap<VType, concepts::ReadWriteMap<Node,int> > > |
111 | 111 |
::SetStandardHeap<BinHeap<VType, concepts::ReadWriteMap<Node,int> > > |
112 |
::SetHeap<BinHeap<VType, concepts::ReadWriteMap<Node,int> >, |
|
112 |
::SetHeap<BinHeap<VType, concepts::ReadWriteMap<Node,int> >, |
|
113 | 113 |
concepts::ReadWriteMap<Node,int> > |
114 | 114 |
::Create dijkstra_test(G,length); |
115 | 115 |
|
116 | 116 |
LengthMap length_map; |
... | ... |
@@ -118,9 +118,9 @@ |
118 | 118 |
concepts::ReadWriteMap<Node,VType> dist_map; |
119 | 119 |
concepts::WriteMap<Node,bool> processed_map; |
120 | 120 |
concepts::ReadWriteMap<Node,int> heap_cross_ref; |
121 | 121 |
BinHeap<VType, concepts::ReadWriteMap<Node,int> > heap(heap_cross_ref); |
122 |
|
|
122 |
|
|
123 | 123 |
dijkstra_test |
124 | 124 |
.lengthMap(length_map) |
125 | 125 |
.predMap(pred_map) |
126 | 126 |
.distMap(dist_map) |
... | ... |
@@ -135,9 +135,9 @@ |
135 | 135 |
n = dijkstra_test.processNextNode(); |
136 | 136 |
n = dijkstra_test.nextNode(); |
137 | 137 |
b = dijkstra_test.emptyQueue(); |
138 | 138 |
i = dijkstra_test.queueSize(); |
139 |
|
|
139 |
|
|
140 | 140 |
dijkstra_test.start(); |
141 | 141 |
dijkstra_test.start(t); |
142 | 142 |
dijkstra_test.start(nm); |
143 | 143 |
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-2010 |
|
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 |
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-2010 |
|
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 |
... | ... |
@@ -84,13 +84,13 @@ |
84 | 84 |
int main() |
85 | 85 |
{ |
86 | 86 |
typedef ListDigraph Digraph; |
87 | 87 |
typedef Undirector<Digraph> Graph; |
88 |
|
|
88 |
|
|
89 | 89 |
{ |
90 | 90 |
Digraph d; |
91 | 91 |
Graph g(d); |
92 |
|
|
92 |
|
|
93 | 93 |
checkDiEulerIt(d); |
94 | 94 |
checkDiEulerIt(g); |
95 | 95 |
checkEulerIt(g); |
96 | 96 |
|
... | ... |
@@ -127,9 +127,9 @@ |
127 | 127 |
Graph g(d); |
128 | 128 |
Digraph::Node n1 = d.addNode(); |
129 | 129 |
Digraph::Node n2 = d.addNode(); |
130 | 130 |
Digraph::Node n3 = d.addNode(); |
131 |
|
|
131 |
|
|
132 | 132 |
d.addArc(n1, n2); |
133 | 133 |
d.addArc(n2, n1); |
134 | 134 |
d.addArc(n2, n3); |
135 | 135 |
d.addArc(n3, n2); |
... | ... |
@@ -152,9 +152,9 @@ |
152 | 152 |
Digraph::Node n3 = d.addNode(); |
153 | 153 |
Digraph::Node n4 = d.addNode(); |
154 | 154 |
Digraph::Node n5 = d.addNode(); |
155 | 155 |
Digraph::Node n6 = d.addNode(); |
156 |
|
|
156 |
|
|
157 | 157 |
d.addArc(n1, n2); |
158 | 158 |
d.addArc(n2, n4); |
159 | 159 |
d.addArc(n1, n3); |
160 | 160 |
d.addArc(n3, n4); |
... | ... |
@@ -188,9 +188,9 @@ |
188 | 188 |
Digraph::Node n2 = d.addNode(); |
189 | 189 |
Digraph::Node n3 = d.addNode(); |
190 | 190 |
Digraph::Node n4 = d.addNode(); |
191 | 191 |
Digraph::Node n5 = d.addNode(); |
192 |
|
|
192 |
|
|
193 | 193 |
d.addArc(n1, n2); |
194 | 194 |
d.addArc(n2, n3); |
195 | 195 |
d.addArc(n3, n1); |
196 | 196 |
|
... | ... |
@@ -210,9 +210,9 @@ |
210 | 210 |
Graph g(d); |
211 | 211 |
Digraph::Node n1 = d.addNode(); |
212 | 212 |
Digraph::Node n2 = d.addNode(); |
213 | 213 |
Digraph::Node n3 = d.addNode(); |
214 |
|
|
214 |
|
|
215 | 215 |
d.addArc(n1, n2); |
216 | 216 |
d.addArc(n2, n3); |
217 | 217 |
|
218 | 218 |
check(!eulerian(d), "This graph is not Eulerian"); |
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-2010 |
|
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 |
... | ... |
@@ -237,9 +237,9 @@ |
237 | 237 |
check(pv == mfm.matchingSize(), "Wrong matching size"); |
238 | 238 |
|
239 | 239 |
for (SmartGraph::EdgeIt e(graph); e != INVALID; ++e) { |
240 | 240 |
check((e == mfm.matching(graph.u(e)) ? 1 : 0) + |
241 |
(e == mfm.matching(graph.v(e)) ? 1 : 0) == |
|
241 |
(e == mfm.matching(graph.v(e)) ? 1 : 0) == |
|
242 | 242 |
mfm.matching(e), "Invalid matching"); |
243 | 243 |
} |
244 | 244 |
|
245 | 245 |
SmartGraph::NodeMap<bool> processed(graph, false); |
... | ... |
@@ -291,9 +291,9 @@ |
291 | 291 |
check(indeg == 1, "Invalid matching"); |
292 | 292 |
} |
293 | 293 |
for (SmartGraph::EdgeIt e(graph); e != INVALID; ++e) { |
294 | 294 |
check((e == mfm.matching(graph.u(e)) ? 1 : 0) + |
295 |
(e == mfm.matching(graph.v(e)) ? 1 : 0) == |
|
295 |
(e == mfm.matching(graph.v(e)) ? 1 : 0) == |
|
296 | 296 |
mfm.matching(e), "Invalid matching"); |
297 | 297 |
} |
298 | 298 |
} else { |
299 | 299 |
int anum = 0, bnum = 0; |
... | ... |
@@ -349,9 +349,9 @@ |
349 | 349 |
} |
350 | 350 |
|
351 | 351 |
for (SmartGraph::EdgeIt e(graph); e != INVALID; ++e) { |
352 | 352 |
check((e == mwfm.matching(graph.u(e)) ? 1 : 0) + |
353 |
(e == mwfm.matching(graph.v(e)) ? 1 : 0) == |
|
353 |
(e == mwfm.matching(graph.v(e)) ? 1 : 0) == |
|
354 | 354 |
mwfm.matching(e), "Invalid matching"); |
355 | 355 |
} |
356 | 356 |
|
357 | 357 |
int dv = 0; |
... | ... |
@@ -409,9 +409,9 @@ |
409 | 409 |
} |
410 | 410 |
|
411 | 411 |
for (SmartGraph::EdgeIt e(graph); e != INVALID; ++e) { |
412 | 412 |
check((e == mwpfm.matching(graph.u(e)) ? 1 : 0) + |
413 |
(e == mwpfm.matching(graph.v(e)) ? 1 : 0) == |
|
413 |
(e == mwpfm.matching(graph.v(e)) ? 1 : 0) == |
|
414 | 414 |
mwpfm.matching(e), "Invalid matching"); |
415 | 415 |
} |
416 | 416 |
|
417 | 417 |
int dv = 0; |
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-2010 |
|
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 |
|
|
1 | 19 |
#include <iostream> |
2 | 20 |
|
3 | 21 |
#include "test_tools.h" |
4 | 22 |
#include <lemon/smart_graph.h> |
... | ... |
@@ -32,9 +50,9 @@ |
32 | 50 |
"4 2 7 1\n" |
33 | 51 |
"@attributes\n" |
34 | 52 |
"source 0\n" |
35 | 53 |
"target 3\n"; |
36 |
|
|
54 |
|
|
37 | 55 |
void checkGomoryHuCompile() |
38 | 56 |
{ |
39 | 57 |
typedef int Value; |
40 | 58 |
typedef concepts::Graph Graph; |
... | ... |
@@ -68,9 +86,9 @@ |
68 | 86 |
typedef Graph::EdgeMap<int> IntEdgeMap; |
69 | 87 |
typedef Graph::NodeMap<bool> BoolNodeMap; |
70 | 88 |
|
71 | 89 |
int cutValue(const Graph& graph, const BoolNodeMap& cut, |
72 |
|
|
90 |
const IntEdgeMap& capacity) { |
|
73 | 91 |
|
74 | 92 |
int sum = 0; |
75 | 93 |
for (EdgeIt e(graph); e != INVALID; ++e) { |
76 | 94 |
Node s = graph.u(e); |
... | ... |
@@ -106,9 +124,9 @@ |
106 | 124 |
check(pf.flowValue() == cutValue(graph, cm, capacity), "Wrong cut 3"); |
107 | 125 |
|
108 | 126 |
int sum=0; |
109 | 127 |
for(GomoryHu<Graph>::MinCutEdgeIt a(ght, u, v);a!=INVALID;++a) |
110 |
sum+=capacity[a]; |
|
128 |
sum+=capacity[a]; |
|
111 | 129 |
check(sum == ght.minCutValue(u, v), "Problem with MinCutEdgeIt"); |
112 | 130 |
|
113 | 131 |
sum=0; |
114 | 132 |
for(GomoryHu<Graph>::MinCutNodeIt n(ght, u, v,true);n!=INVALID;++n) |
... | ... |
@@ -117,7 +135,7 @@ |
117 | 135 |
sum++; |
118 | 136 |
check(sum == countNodes(graph), "Problem with MinCutNodeIt"); |
119 | 137 |
} |
120 | 138 |
} |
121 |
|
|
139 |
|
|
122 | 140 |
return 0; |
123 | 141 |
} |
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-2010 |
|
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 |
... | ... |
@@ -263,9 +263,9 @@ |
263 | 263 |
|
264 | 264 |
checkGraphNodeList(G, 4); |
265 | 265 |
checkGraphEdgeList(G, 3); |
266 | 266 |
checkGraphArcList(G, 6); |
267 |
|
|
267 |
|
|
268 | 268 |
G.addEdge(G.addNode(), G.addNode()); |
269 | 269 |
|
270 | 270 |
snapshot.restore(); |
271 | 271 |
|
... | ... |
@@ -512,9 +512,9 @@ |
512 | 512 |
check(G.dimension() == dim, "Wrong dimension"); |
513 | 513 |
|
514 | 514 |
G.resize(dim); |
515 | 515 |
check(G.dimension() == dim, "Wrong dimension"); |
516 |
|
|
516 |
|
|
517 | 517 |
checkGraphNodeList(G, 1 << dim); |
518 | 518 |
checkGraphEdgeList(G, dim * (1 << (dim-1))); |
519 | 519 |
checkGraphArcList(G, dim * (1 << dim)); |
520 | 520 |
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-2010 |
|
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 |
... | ... |
@@ -82,9 +82,9 @@ |
82 | 82 |
v = const_ho_test.minCutMap(cut); |
83 | 83 |
} |
84 | 84 |
|
85 | 85 |
template <typename Graph, typename CapMap, typename CutMap> |
86 |
typename CapMap::Value |
|
86 |
typename CapMap::Value |
|
87 | 87 |
cutValue(const Graph& graph, const CapMap& cap, const CutMap& cut) |
88 | 88 |
{ |
89 | 89 |
typename CapMap::Value sum = 0; |
90 | 90 |
for (typename Graph::ArcIt a(graph); a != INVALID; ++a) { |
... | ... |
@@ -109,9 +109,9 @@ |
109 | 109 |
{ |
110 | 110 |
HaoOrlin<SmartDigraph> ho(graph, cap1); |
111 | 111 |
ho.run(); |
112 | 112 |
ho.minCutMap(cut); |
113 |
|
|
113 |
|
|
114 | 114 |
check(ho.minCutValue() == 1, "Wrong cut value"); |
115 | 115 |
check(ho.minCutValue() == cutValue(graph, cap1, cut), "Wrong cut value"); |
116 | 116 |
} |
117 | 117 |
{ |
... | ... |
@@ -125,37 +125,37 @@ |
125 | 125 |
{ |
126 | 126 |
HaoOrlin<SmartDigraph> ho(graph, cap3); |
127 | 127 |
ho.run(); |
128 | 128 |
ho.minCutMap(cut); |
129 |
|
|
129 |
|
|
130 | 130 |
check(ho.minCutValue() == 1, "Wrong cut value"); |
131 | 131 |
check(ho.minCutValue() == cutValue(graph, cap3, cut), "Wrong cut value"); |
132 | 132 |
} |
133 |
|
|
133 |
|
|
134 | 134 |
typedef Undirector<SmartDigraph> UGraph; |
135 | 135 |
UGraph ugraph(graph); |
136 |
|
|
136 |
|
|
137 | 137 |
{ |
138 | 138 |
HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap1); |
139 | 139 |
ho.run(); |
140 | 140 |
ho.minCutMap(cut); |
141 |
|
|
141 |
|
|
142 | 142 |
check(ho.minCutValue() == 2, "Wrong cut value"); |
143 | 143 |
check(ho.minCutValue() == cutValue(ugraph, cap1, cut), "Wrong cut value"); |
144 | 144 |
} |
145 | 145 |
{ |
146 | 146 |
HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap2); |
147 | 147 |
ho.run(); |
148 | 148 |
ho.minCutMap(cut); |
149 |
|
|
149 |
|
|
150 | 150 |
check(ho.minCutValue() == 5, "Wrong cut value"); |
151 | 151 |
check(ho.minCutValue() == cutValue(ugraph, cap2, cut), "Wrong cut value"); |
152 | 152 |
} |
153 | 153 |
{ |
154 | 154 |
HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap3); |
155 | 155 |
ho.run(); |
156 | 156 |
ho.minCutMap(cut); |
157 |
|
|
157 |
|
|
158 | 158 |
check(ho.minCutValue() == 5, "Wrong cut value"); |
159 | 159 |
check(ho.minCutValue() == cutValue(ugraph, cap3, cut), "Wrong cut value"); |
160 | 160 |
} |
161 | 161 |
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-2010 |
|
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 |
... | ... |
@@ -224,9 +224,10 @@ |
224 | 224 |
FunctorToMap<F> map2 = FunctorToMap<F>(F()); |
225 | 225 |
B b = functorToMap(F())[A()]; |
226 | 226 |
|
227 | 227 |
checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >(); |
228 |
MapToFunctor<ReadMap<A,B> > map = |
|
228 |
MapToFunctor<ReadMap<A,B> > map = |
|
229 |
MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>()); |
|
229 | 230 |
|
230 | 231 |
check(functorToMap(&func)[A()] == 3, |
231 | 232 |
"Something is wrong with FunctorToMap"); |
232 | 233 |
check(mapToFunctor(constMap<A,int>(2))(A()) == 2, |
... | ... |
@@ -376,24 +377,24 @@ |
376 | 377 |
int i = 0; |
377 | 378 |
for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin(); |
378 | 379 |
it != map2.end(); ++it ) |
379 | 380 |
check(v1[i++] == *it, "Something is wrong with LoggerBoolMap"); |
380 |
|
|
381 |
|
|
381 | 382 |
typedef ListDigraph Graph; |
382 | 383 |
DIGRAPH_TYPEDEFS(Graph); |
383 | 384 |
Graph gr; |
384 | 385 |
|
385 | 386 |
Node n0 = gr.addNode(); |
386 | 387 |
Node n1 = gr.addNode(); |
387 | 388 |
Node n2 = gr.addNode(); |
388 | 389 |
Node n3 = gr.addNode(); |
389 |
|
|
390 |
|
|
390 | 391 |
gr.addArc(n3, n0); |
391 | 392 |
gr.addArc(n3, n2); |
392 | 393 |
gr.addArc(n0, n2); |
393 | 394 |
gr.addArc(n2, n1); |
394 | 395 |
gr.addArc(n0, n1); |
395 |
|
|
396 |
|
|
396 | 397 |
{ |
397 | 398 |
std::vector<Node> v; |
398 | 399 |
dfs(gr).processedMap(loggerBoolMap(std::back_inserter(v))).run(); |
399 | 400 |
|
... | ... |
@@ -402,14 +403,14 @@ |
402 | 403 |
} |
403 | 404 |
{ |
404 | 405 |
std::vector<Node> v(countNodes(gr)); |
405 | 406 |
dfs(gr).processedMap(loggerBoolMap(v.begin())).run(); |
406 |
|
|
407 |
|
|
407 | 408 |
check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3, |
408 | 409 |
"Something is wrong with LoggerBoolMap"); |
409 | 410 |
} |
410 | 411 |
} |
411 |
|
|
412 |
|
|
412 | 413 |
// IdMap, RangeIdMap |
413 | 414 |
{ |
414 | 415 |
typedef ListDigraph Graph; |
415 | 416 |
DIGRAPH_TYPEDEFS(Graph); |
... | ... |
@@ -417,24 +418,24 @@ |
417 | 418 |
checkConcept<ReadMap<Node, int>, IdMap<Graph, Node> >(); |
418 | 419 |
checkConcept<ReadMap<Arc, int>, IdMap<Graph, Arc> >(); |
419 | 420 |
checkConcept<ReadMap<Node, int>, RangeIdMap<Graph, Node> >(); |
420 | 421 |
checkConcept<ReadMap<Arc, int>, RangeIdMap<Graph, Arc> >(); |
421 |
|
|
422 |
|
|
422 | 423 |
Graph gr; |
423 | 424 |
IdMap<Graph, Node> nmap(gr); |
424 | 425 |
IdMap<Graph, Arc> amap(gr); |
425 | 426 |
RangeIdMap<Graph, Node> nrmap(gr); |
426 | 427 |
RangeIdMap<Graph, Arc> armap(gr); |
427 |
|
|
428 |
|
|
428 | 429 |
Node n0 = gr.addNode(); |
429 | 430 |
Node n1 = gr.addNode(); |
430 | 431 |
Node n2 = gr.addNode(); |
431 |
|
|
432 |
|
|
432 | 433 |
Arc a0 = gr.addArc(n0, n1); |
433 | 434 |
Arc a1 = gr.addArc(n0, n2); |
434 | 435 |
Arc a2 = gr.addArc(n2, n1); |
435 | 436 |
Arc a3 = gr.addArc(n2, n0); |
436 |
|
|
437 |
|
|
437 | 438 |
check(nmap[n0] == gr.id(n0) && nmap(gr.id(n0)) == n0, "Wrong IdMap"); |
438 | 439 |
check(nmap[n1] == gr.id(n1) && nmap(gr.id(n1)) == n1, "Wrong IdMap"); |
439 | 440 |
check(nmap[n2] == gr.id(n2) && nmap(gr.id(n2)) == n2, "Wrong IdMap"); |
440 | 441 |
|
... | ... |
@@ -444,49 +445,49 @@ |
444 | 445 |
check(amap[a3] == gr.id(a3) && amap(gr.id(a3)) == a3, "Wrong IdMap"); |
445 | 446 |
|
446 | 447 |
check(nmap.inverse()[gr.id(n0)] == n0, "Wrong IdMap::InverseMap"); |
447 | 448 |
check(amap.inverse()[gr.id(a0)] == a0, "Wrong IdMap::InverseMap"); |
448 |
|
|
449 |
|
|
449 | 450 |
check(nrmap.size() == 3 && armap.size() == 4, |
450 | 451 |
"Wrong RangeIdMap::size()"); |
451 | 452 |
|
452 | 453 |
check(nrmap[n0] == 0 && nrmap(0) == n0, "Wrong RangeIdMap"); |
453 | 454 |
check(nrmap[n1] == 1 && nrmap(1) == n1, "Wrong RangeIdMap"); |
454 | 455 |
check(nrmap[n2] == 2 && nrmap(2) == n2, "Wrong RangeIdMap"); |
455 |
|
|
456 |
|
|
456 | 457 |
check(armap[a0] == 0 && armap(0) == a0, "Wrong RangeIdMap"); |
457 | 458 |
check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap"); |
458 | 459 |
check(armap[a2] == 2 && armap(2) == a2, "Wrong RangeIdMap"); |
459 | 460 |
check(armap[a3] == 3 && armap(3) == a3, "Wrong RangeIdMap"); |
460 | 461 |
|
461 | 462 |
check(nrmap.inverse()[0] == n0, "Wrong RangeIdMap::InverseMap"); |
462 | 463 |
check(armap.inverse()[0] == a0, "Wrong RangeIdMap::InverseMap"); |
463 |
|
|
464 |
|
|
464 | 465 |
gr.erase(n1); |
465 |
|
|
466 |
|
|
466 | 467 |
if (nrmap[n0] == 1) nrmap.swap(n0, n2); |
467 | 468 |
nrmap.swap(n2, n0); |
468 | 469 |
if (armap[a1] == 1) armap.swap(a1, a3); |
469 | 470 |
armap.swap(a3, a1); |
470 |
|
|
471 |
|
|
471 | 472 |
check(nrmap.size() == 2 && armap.size() == 2, |
472 | 473 |
"Wrong RangeIdMap::size()"); |
473 | 474 |
|
474 | 475 |
check(nrmap[n0] == 1 && nrmap(1) == n0, "Wrong RangeIdMap"); |
475 | 476 |
check(nrmap[n2] == 0 && nrmap(0) == n2, "Wrong RangeIdMap"); |
476 |
|
|
477 |
|
|
477 | 478 |
check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap"); |
478 | 479 |
check(armap[a3] == 0 && armap(0) == a3, "Wrong RangeIdMap"); |
479 | 480 |
|
480 | 481 |
check(nrmap.inverse()[0] == n2, "Wrong RangeIdMap::InverseMap"); |
481 | 482 |
check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap"); |
482 | 483 |
} |
483 |
|
|
484 |
|
|
484 | 485 |
// SourceMap, TargetMap, ForwardMap, BackwardMap, InDegMap, OutDegMap |
485 | 486 |
{ |
486 | 487 |
typedef ListGraph Graph; |
487 | 488 |
GRAPH_TYPEDEFS(Graph); |
488 |
|
|
489 |
|
|
489 | 490 |
checkConcept<ReadMap<Arc, Node>, SourceMap<Graph> >(); |
490 | 491 |
checkConcept<ReadMap<Arc, Node>, TargetMap<Graph> >(); |
491 | 492 |
checkConcept<ReadMap<Edge, Arc>, ForwardMap<Graph> >(); |
492 | 493 |
checkConcept<ReadMap<Edge, Arc>, BackwardMap<Graph> >(); |
... | ... |
@@ -496,21 +497,21 @@ |
496 | 497 |
Graph gr; |
497 | 498 |
Node n0 = gr.addNode(); |
498 | 499 |
Node n1 = gr.addNode(); |
499 | 500 |
Node n2 = gr.addNode(); |
500 |
|
|
501 |
|
|
501 | 502 |
gr.addEdge(n0,n1); |
502 | 503 |
gr.addEdge(n1,n2); |
503 | 504 |
gr.addEdge(n0,n2); |
504 | 505 |
gr.addEdge(n2,n1); |
505 | 506 |
gr.addEdge(n1,n2); |
506 | 507 |
gr.addEdge(n0,n1); |
507 |
|
|
508 |
|
|
508 | 509 |
for (EdgeIt e(gr); e != INVALID; ++e) { |
509 | 510 |
check(forwardMap(gr)[e] == gr.direct(e, true), "Wrong ForwardMap"); |
510 | 511 |
check(backwardMap(gr)[e] == gr.direct(e, false), "Wrong BackwardMap"); |
511 | 512 |
} |
512 |
|
|
513 |
|
|
513 | 514 |
check(mapCompare(gr, |
514 | 515 |
sourceMap(orienter(gr, constMap<Edge, bool>(true))), |
515 | 516 |
targetMap(orienter(gr, constMap<Edge, bool>(false)))), |
516 | 517 |
"Wrong SourceMap or TargetMap"); |
... | ... |
@@ -518,18 +519,18 @@ |
518 | 519 |
typedef Orienter<Graph, const ConstMap<Edge, bool> > Digraph; |
519 | 520 |
Digraph dgr(gr, constMap<Edge, bool>(true)); |
520 | 521 |
OutDegMap<Digraph> odm(dgr); |
521 | 522 |
InDegMap<Digraph> idm(dgr); |
522 |
|
|
523 |
|
|
523 | 524 |
check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 1, "Wrong OutDegMap"); |
524 | 525 |
check(idm[n0] == 0 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap"); |
525 |
|
|
526 |
|
|
526 | 527 |
gr.addEdge(n2, n0); |
527 | 528 |
|
528 | 529 |
check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 2, "Wrong OutDegMap"); |
529 | 530 |
check(idm[n0] == 1 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap"); |
530 | 531 |
} |
531 |
|
|
532 |
|
|
532 | 533 |
// CrossRefMap |
533 | 534 |
{ |
534 | 535 |
typedef ListDigraph Graph; |
535 | 536 |
DIGRAPH_TYPEDEFS(Graph); |
... | ... |
@@ -539,34 +540,34 @@ |
539 | 540 |
checkConcept<ReadWriteMap<Node, bool>, |
540 | 541 |
CrossRefMap<Graph, Node, bool> >(); |
541 | 542 |
checkConcept<ReadWriteMap<Node, double>, |
542 | 543 |
CrossRefMap<Graph, Node, double> >(); |
543 |
|
|
544 |
|
|
544 | 545 |
Graph gr; |
545 | 546 |
typedef CrossRefMap<Graph, Node, char> CRMap; |
546 | 547 |
CRMap map(gr); |
547 |
|
|
548 |
|
|
548 | 549 |
Node n0 = gr.addNode(); |
549 | 550 |
Node n1 = gr.addNode(); |
550 | 551 |
Node n2 = gr.addNode(); |
551 |
|
|
552 |
|
|
552 | 553 |
map.set(n0, 'A'); |
553 | 554 |
map.set(n1, 'B'); |
554 | 555 |
map.set(n2, 'C'); |
555 |
|
|
556 |
|
|
556 | 557 |
check(map[n0] == 'A' && map('A') == n0 && map.inverse()['A'] == n0, |
557 | 558 |
"Wrong CrossRefMap"); |
558 | 559 |
check(map[n1] == 'B' && map('B') == n1 && map.inverse()['B'] == n1, |
559 | 560 |
"Wrong CrossRefMap"); |
560 | 561 |
check(map[n2] == 'C' && map('C') == n2 && map.inverse()['C'] == n2, |
561 | 562 |
"Wrong CrossRefMap"); |
562 | 563 |
check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1, |
563 | 564 |
"Wrong CrossRefMap::count()"); |
564 |
|
|
565 |
|
|
565 | 566 |
CRMap::ValueIt it = map.beginValue(); |
566 | 567 |
check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' && |
567 | 568 |
it == map.endValue(), "Wrong value iterator"); |
568 |
|
|
569 |
|
|
569 | 570 |
map.set(n2, 'A'); |
570 | 571 |
|
571 | 572 |
check(map[n0] == 'A' && map[n1] == 'B' && map[n2] == 'A', |
572 | 573 |
"Wrong CrossRefMap"); |
... | ... |
@@ -602,18 +603,18 @@ |
602 | 603 |
DIGRAPH_TYPEDEFS(Graph); |
603 | 604 |
|
604 | 605 |
checkConcept<ReadWriteMap<Node, int>, |
605 | 606 |
CrossRefMap<Graph, Node, int> >(); |
606 |
|
|
607 |
|
|
607 | 608 |
Graph gr; |
608 | 609 |
typedef CrossRefMap<Graph, Node, char> CRMap; |
609 | 610 |
typedef CRMap::ValueIterator ValueIt; |
610 | 611 |
CRMap map(gr); |
611 |
|
|
612 |
|
|
612 | 613 |
Node n0 = gr.addNode(); |
613 | 614 |
Node n1 = gr.addNode(); |
614 | 615 |
Node n2 = gr.addNode(); |
615 |
|
|
616 |
|
|
616 | 617 |
map.set(n0, 'A'); |
617 | 618 |
map.set(n1, 'B'); |
618 | 619 |
map.set(n2, 'C'); |
619 | 620 |
map.set(n2, 'A'); |
... | ... |
@@ -628,9 +629,9 @@ |
628 | 629 |
ValueIt it = map.beginValue(); |
629 | 630 |
check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' && |
630 | 631 |
it == map.endValue(), "Wrong value iterator"); |
631 | 632 |
} |
632 |
|
|
633 |
|
|
633 | 634 |
// Iterable bool map |
634 | 635 |
{ |
635 | 636 |
typedef SmartGraph Graph; |
636 | 637 |
typedef SmartGraph::Node Item; |
... | ... |
@@ -816,9 +817,9 @@ |
816 | 817 |
} |
817 | 818 |
check(n == num, "Wrong number"); |
818 | 819 |
|
819 | 820 |
} |
820 |
|
|
821 |
|
|
821 | 822 |
// Graph map utilities: |
822 | 823 |
// mapMin(), mapMax(), mapMinValue(), mapMaxValue() |
823 | 824 |
// mapFind(), mapFindIf(), mapCount(), mapCountIf() |
824 | 825 |
// mapCopy(), mapCompare(), mapFill() |
... | ... |
@@ -828,18 +829,18 @@ |
828 | 829 |
SmartDigraph g; |
829 | 830 |
Node n1 = g.addNode(); |
830 | 831 |
Node n2 = g.addNode(); |
831 | 832 |
Node n3 = g.addNode(); |
832 |
|
|
833 |
|
|
833 | 834 |
SmartDigraph::NodeMap<int> map1(g); |
834 | 835 |
SmartDigraph::ArcMap<char> map2(g); |
835 | 836 |
ConstMap<Node, A> cmap1 = A(); |
836 | 837 |
ConstMap<Arc, C> cmap2 = C(0); |
837 |
|
|
838 |
|
|
838 | 839 |
map1[n1] = 10; |
839 | 840 |
map1[n2] = 5; |
840 | 841 |
map1[n3] = 12; |
841 |
|
|
842 |
|
|
842 | 843 |
// mapMin(), mapMax(), mapMinValue(), mapMaxValue() |
843 | 844 |
check(mapMin(g, map1) == n2, "Wrong mapMin()"); |
844 | 845 |
check(mapMax(g, map1) == n3, "Wrong mapMax()"); |
845 | 846 |
check(mapMin(g, map1, std::greater<int>()) == n3, "Wrong mapMin()"); |
... | ... |
@@ -856,9 +857,9 @@ |
856 | 857 |
Arc a1 = g.addArc(n1, n2); |
857 | 858 |
Arc a2 = g.addArc(n1, n3); |
858 | 859 |
Arc a3 = g.addArc(n2, n3); |
859 | 860 |
Arc a4 = g.addArc(n3, n1); |
860 |
|
|
861 |
|
|
861 | 862 |
map2[a1] = 'b'; |
862 | 863 |
map2[a2] = 'a'; |
863 | 864 |
map2[a3] = 'b'; |
864 | 865 |
map2[a4] = 'c'; |
... | ... |
@@ -923,9 +924,9 @@ |
923 | 924 |
check(mapCountIf(g, map2, Less<char>('c')) == 3, |
924 | 925 |
"Wrong mapCountIf()"); |
925 | 926 |
check(mapCountIf(g, map2, Less<char>('a')) == 0, |
926 | 927 |
"Wrong mapCountIf()"); |
927 |
|
|
928 |
|
|
928 | 929 |
// MapIt, ConstMapIt |
929 | 930 |
/* |
930 | 931 |
These tests can be used after applying bugfix #330 |
931 | 932 |
typedef SmartDigraph::NodeMap<int>::MapIt MapIt; |
... | ... |
@@ -933,9 +934,9 @@ |
933 | 934 |
check(*std::min_element(MapIt(map1), MapIt(INVALID)) == 5, |
934 | 935 |
"Wrong NodeMap<>::MapIt"); |
935 | 936 |
check(*std::max_element(ConstMapIt(map1), ConstMapIt(INVALID)) == 12, |
936 | 937 |
"Wrong NodeMap<>::MapIt"); |
937 |
|
|
938 |
|
|
938 | 939 |
int sum = 0; |
939 | 940 |
std::for_each(MapIt(map1), MapIt(INVALID), Sum<int>(sum)); |
940 | 941 |
check(sum == 27, "Wrong NodeMap<>::MapIt"); |
941 | 942 |
std::for_each(ConstMapIt(map1), ConstMapIt(INVALID), Sum<int>(sum)); |
... | ... |
@@ -950,50 +951,50 @@ |
950 | 951 |
check(!mapCompare(g, map1, shiftMap(map1, 1)), "Wrong mapCompare()"); |
951 | 952 |
|
952 | 953 |
SmartDigraph::NodeMap<int> map3(g, 0); |
953 | 954 |
SmartDigraph::ArcMap<char> map4(g, 'a'); |
954 |
|
|
955 |
|
|
955 | 956 |
check(!mapCompare(g, map1, map3), "Wrong mapCompare()"); |
956 |
check(!mapCompare(g, map2, map4), "Wrong mapCompare()"); |
|
957 |
|
|
957 |
check(!mapCompare(g, map2, map4), "Wrong mapCompare()"); |
|
958 |
|
|
958 | 959 |
mapCopy(g, map1, map3); |
959 | 960 |
mapCopy(g, map2, map4); |
960 | 961 |
|
961 | 962 |
check(mapCompare(g, map1, map3), "Wrong mapCompare() or mapCopy()"); |
962 |
check(mapCompare(g, map2, map4), "Wrong mapCompare() or mapCopy()"); |
|
963 |
|
|
963 |
check(mapCompare(g, map2, map4), "Wrong mapCompare() or mapCopy()"); |
|
964 |
|
|
964 | 965 |
Undirector<SmartDigraph> ug(g); |
965 | 966 |
Undirector<SmartDigraph>::EdgeMap<char> umap1(ug, 'x'); |
966 | 967 |
Undirector<SmartDigraph>::ArcMap<double> umap2(ug, 3.14); |
967 |
|
|
968 |
|
|
968 | 969 |
check(!mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()"); |
969 | 970 |
check(!mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()"); |
970 | 971 |
check(!mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()"); |
971 | 972 |
check(!mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()"); |
972 |
|
|
973 |
|
|
973 | 974 |
mapCopy(g, map2, umap1); |
974 | 975 |
|
975 | 976 |
check(mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()"); |
976 | 977 |
check(mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()"); |
977 | 978 |
check(mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()"); |
978 | 979 |
check(mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()"); |
979 |
|
|
980 |
|
|
980 | 981 |
mapCopy(g, map2, umap1); |
981 | 982 |
mapCopy(g, umap1, map2); |
982 | 983 |
mapCopy(ug, map2, umap1); |
983 | 984 |
mapCopy(ug, umap1, map2); |
984 |
|
|
985 |
|
|
985 | 986 |
check(!mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()"); |
986 | 987 |
mapCopy(ug, umap1, umap2); |
987 | 988 |
check(mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()"); |
988 |
|
|
989 |
|
|
989 | 990 |
check(!mapCompare(g, map1, constMap<Node>(2)), "Wrong mapCompare()"); |
990 | 991 |
mapFill(g, map1, 2); |
991 | 992 |
check(mapCompare(g, constMap<Node>(2), map1), "Wrong mapFill()"); |
992 | 993 |
|
993 | 994 |
check(!mapCompare(g, map2, constMap<Arc>('z')), "Wrong mapCompare()"); |
994 | 995 |
mapCopy(g, constMap<Arc>('z'), map2); |
995 | 996 |
check(mapCompare(g, constMap<Arc>('z'), map2), "Wrong mapCopy()"); |
996 | 997 |
} |
997 |
|
|
998 |
|
|
998 | 999 |
return 0; |
999 | 1000 |
} |
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-2010 |
|
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 |
... | ... |
@@ -133,18 +133,18 @@ |
133 | 133 |
mat_test.matchingInit(mat); |
134 | 134 |
mat_test.startSparse(); |
135 | 135 |
mat_test.startDense(); |
136 | 136 |
mat_test.run(); |
137 |
|
|
137 |
|
|
138 | 138 |
const_mat_test.matchingSize(); |
139 | 139 |
const_mat_test.matching(e); |
140 | 140 |
const_mat_test.matching(n); |
141 | 141 |
const MaxMatching<Graph>::MatchingMap& mmap = |
142 | 142 |
const_mat_test.matchingMap(); |
143 | 143 |
e = mmap[n]; |
144 | 144 |
const_mat_test.mate(n); |
145 | 145 |
|
146 |
MaxMatching<Graph>::Status stat = |
|
146 |
MaxMatching<Graph>::Status stat = |
|
147 | 147 |
const_mat_test.status(n); |
148 | 148 |
const MaxMatching<Graph>::StatusMap& smap = |
149 | 149 |
const_mat_test.statusMap(); |
150 | 150 |
stat = smap[n]; |
... | ... |
@@ -169,18 +169,18 @@ |
169 | 169 |
|
170 | 170 |
mat_test.init(); |
171 | 171 |
mat_test.start(); |
172 | 172 |
mat_test.run(); |
173 |
|
|
173 |
|
|
174 | 174 |
const_mat_test.matchingWeight(); |
175 | 175 |
const_mat_test.matchingSize(); |
176 | 176 |
const_mat_test.matching(e); |
177 | 177 |
const_mat_test.matching(n); |
178 | 178 |
const MaxWeightedMatching<Graph>::MatchingMap& mmap = |
179 | 179 |
const_mat_test.matchingMap(); |
180 | 180 |
e = mmap[n]; |
181 | 181 |
const_mat_test.mate(n); |
182 |
|
|
182 |
|
|
183 | 183 |
int k = 0; |
184 | 184 |
const_mat_test.dualValue(); |
185 | 185 |
const_mat_test.nodeValue(n); |
186 | 186 |
const_mat_test.blossomNum(); |
... | ... |
@@ -206,17 +206,17 @@ |
206 | 206 |
|
207 | 207 |
mat_test.init(); |
208 | 208 |
mat_test.start(); |
209 | 209 |
mat_test.run(); |
210 |
|
|
210 |
|
|
211 | 211 |
const_mat_test.matchingWeight(); |
212 | 212 |
const_mat_test.matching(e); |
213 | 213 |
const_mat_test.matching(n); |
214 | 214 |
const MaxWeightedPerfectMatching<Graph>::MatchingMap& mmap = |
215 | 215 |
const_mat_test.matchingMap(); |
216 | 216 |
e = mmap[n]; |
217 | 217 |
const_mat_test.mate(n); |
218 |
|
|
218 |
|
|
219 | 219 |
int k = 0; |
220 | 220 |
const_mat_test.dualValue(); |
221 | 221 |
const_mat_test.nodeValue(n); |
222 | 222 |
const_mat_test.blossomNum(); |
... | ... |
@@ -424,9 +424,9 @@ |
424 | 424 |
|
425 | 425 |
{ |
426 | 426 |
MaxWeightedPerfectMatching<SmartGraph> mwpm(graph, weight); |
427 | 427 |
bool result = mwpm.run(); |
428 |
|
|
428 |
|
|
429 | 429 |
check(result == perfect, "Perfect matching found"); |
430 | 430 |
if (perfect) { |
431 | 431 |
checkWeightedPerfectMatching(graph, weight, mwpm); |
432 | 432 |
} |
... | ... |
@@ -435,9 +435,9 @@ |
435 | 435 |
{ |
436 | 436 |
MaxWeightedPerfectMatching<SmartGraph> mwpm(graph, weight); |
437 | 437 |
mwpm.init(); |
438 | 438 |
bool result = mwpm.start(); |
439 |
|
|
439 |
|
|
440 | 440 |
check(result == perfect, "Perfect matching found"); |
441 | 441 |
if (perfect) { |
442 | 442 |
checkWeightedPerfectMatching(graph, weight, mwpm); |
443 | 443 |
} |
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-2010 |
|
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 |
... | ... |
@@ -109,9 +109,9 @@ |
109 | 109 |
mcarb_test.start(); |
110 | 110 |
n = mcarb_test.processNextNode(); |
111 | 111 |
b = const_mcarb_test.emptyQueue(); |
112 | 112 |
i = const_mcarb_test.queueSize(); |
113 |
|
|
113 |
|
|
114 | 114 |
c = const_mcarb_test.arborescenceCost(); |
115 | 115 |
b = const_mcarb_test.arborescence(e); |
116 | 116 |
e = const_mcarb_test.pred(n); |
117 | 117 |
const MinCostArbType::ArborescenceMap &am = |
... | ... |
@@ -119,14 +119,14 @@ |
119 | 119 |
const MinCostArbType::PredMap &pm = |
120 | 120 |
const_mcarb_test.predMap(); |
121 | 121 |
b = const_mcarb_test.reached(n); |
122 | 122 |
b = const_mcarb_test.processed(n); |
123 |
|
|
123 |
|
|
124 | 124 |
i = const_mcarb_test.dualNum(); |
125 | 125 |
c = const_mcarb_test.dualValue(); |
126 | 126 |
i = const_mcarb_test.dualSize(i); |
127 | 127 |
c = const_mcarb_test.dualValue(i); |
128 |
|
|
128 |
|
|
129 | 129 |
ignore_unused_variable_warning(am); |
130 | 130 |
ignore_unused_variable_warning(pm); |
131 | 131 |
} |
132 | 132 |
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-2010 |
|
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 |
... | ... |
@@ -51,9 +51,9 @@ |
51 | 51 |
" 9 3 0 0 0 0 0\n" |
52 | 52 |
" 10 -2 0 0 0 -7 -2\n" |
53 | 53 |
" 11 0 0 0 0 -10 0\n" |
54 | 54 |
" 12 -20 -27 0 -30 -30 -20\n" |
55 |
"\n" |
|
55 |
"\n" |
|
56 | 56 |
"@arcs\n" |
57 | 57 |
" cost cap low1 low2 low3\n" |
58 | 58 |
" 1 2 70 11 0 8 8\n" |
59 | 59 |
" 1 3 150 3 0 1 0\n" |
... | ... |
@@ -101,9 +101,9 @@ |
101 | 101 |
"5 3 10 0 0\n" |
102 | 102 |
"5 6 80 0 1000\n" |
103 | 103 |
"6 7 30 0 -1000\n" |
104 | 104 |
"7 5 -120 0 0\n"; |
105 |
|
|
105 |
|
|
106 | 106 |
char test_neg2_lgf[] = |
107 | 107 |
"@nodes\n" |
108 | 108 |
"label sup\n" |
109 | 109 |
" 1 100\n" |
... | ... |
@@ -150,9 +150,9 @@ |
150 | 150 |
template <typename MCF> |
151 | 151 |
struct Constraints { |
152 | 152 |
void constraints() { |
153 | 153 |
checkConcept<concepts::Digraph, GR>(); |
154 |
|
|
154 |
|
|
155 | 155 |
const Constraints& me = *this; |
156 | 156 |
|
157 | 157 |
MCF mcf(me.g); |
158 | 158 |
const MCF& const_mcf = mcf; |
... | ... |
@@ -179,9 +179,9 @@ |
179 | 179 |
typedef concepts::ReadMap<Arc, Value> VAM; |
180 | 180 |
typedef concepts::ReadMap<Arc, Cost> CAM; |
181 | 181 |
typedef concepts::WriteMap<Arc, Value> FlowMap; |
182 | 182 |
typedef concepts::WriteMap<Node, Cost> PotMap; |
183 |
|
|
183 |
|
|
184 | 184 |
GR g; |
185 | 185 |
VAM lower; |
186 | 186 |
VAM upper; |
187 | 187 |
CAM cost; |
... | ... |
@@ -233,9 +233,9 @@ |
233 | 233 |
// using the "Complementary Slackness" optimality condition |
234 | 234 |
template < typename GR, typename LM, typename UM, |
235 | 235 |
typename CM, typename SM, typename FM, typename PM > |
236 | 236 |
bool checkPotential( const GR& gr, const LM& lower, const UM& upper, |
237 |
const CM& cost, const SM& supply, const FM& flow, |
|
237 |
const CM& cost, const SM& supply, const FM& flow, |
|
238 | 238 |
const PM& pi, SupplyType type ) |
239 | 239 |
{ |
240 | 240 |
TEMPLATE_DIGRAPH_TYPEDEFS(GR); |
241 | 241 |
|
... | ... |
@@ -246,9 +246,9 @@ |
246 | 246 |
opt = red_cost == 0 || |
247 | 247 |
(red_cost > 0 && flow[e] == lower[e]) || |
248 | 248 |
(red_cost < 0 && flow[e] == upper[e]); |
249 | 249 |
} |
250 |
|
|
250 |
|
|
251 | 251 |
for (NodeIt n(gr); opt && n != INVALID; ++n) { |
252 | 252 |
typename SM::Value sum = 0; |
253 | 253 |
for (OutArcIt e(gr, n); e != INVALID; ++e) |
254 | 254 |
sum += flow[e]; |
... | ... |
@@ -259,9 +259,9 @@ |
259 | 259 |
} else { |
260 | 260 |
opt = (pi[n] >= 0) && (sum == supply[n] || pi[n] == 0); |
261 | 261 |
} |
262 | 262 |
} |
263 |
|
|
263 |
|
|
264 | 264 |
return opt; |
265 | 265 |
} |
266 | 266 |
|
267 | 267 |
// Check whether the dual cost is equal to the primal cost |
... | ... |
@@ -284,18 +284,18 @@ |
284 | 284 |
red_supply[gr.source(a)] -= lower[a]; |
285 | 285 |
red_supply[gr.target(a)] += lower[a]; |
286 | 286 |
} |
287 | 287 |
} |
288 |
|
|
288 |
|
|
289 | 289 |
for (NodeIt n(gr); n != INVALID; ++n) { |
290 | 290 |
dual_cost -= red_supply[n] * pi[n]; |
291 | 291 |
} |
292 | 292 |
for (ArcIt a(gr); a != INVALID; ++a) { |
293 | 293 |
typename CM::Value red_cost = |
294 | 294 |
cost[a] + pi[gr.source(a)] - pi[gr.target(a)]; |
295 | 295 |
dual_cost -= (upper[a] - lower[a]) * std::max(-red_cost, 0); |
296 | 296 |
} |
297 |
|
|
297 |
|
|
298 | 298 |
return dual_cost == total; |
299 | 299 |
} |
300 | 300 |
|
301 | 301 |
// Run a minimum cost flow algorithm and check the results |
... | ... |
@@ -331,9 +331,9 @@ |
331 | 331 |
const std::string &test_str = "", |
332 | 332 |
bool full_neg_cost_support = false ) |
333 | 333 |
{ |
334 | 334 |
MCF mcf1(gr), mcf2(neg1_gr), mcf3(neg2_gr); |
335 |
|
|
335 |
|
|
336 | 336 |
// Basic tests |
337 | 337 |
mcf1.upperMap(u).costMap(c).supplyMap(s1); |
338 | 338 |
checkMcf(mcf1, mcf1.run(param), gr, l1, u, c, s1, |
339 | 339 |
mcf1.OPTIMAL, true, 5240, test_str + "-1"); |
... | ... |
@@ -434,23 +434,23 @@ |
434 | 434 |
.nodeMap("sup6", s6) |
435 | 435 |
.node("source", v) |
436 | 436 |
.node("target", w) |
437 | 437 |
.run(); |
438 |
|
|
438 |
|
|
439 | 439 |
std::istringstream neg_inp1(test_neg1_lgf); |
440 | 440 |
DigraphReader<Digraph>(neg1_gr, neg_inp1) |
441 | 441 |
.arcMap("cost", neg1_c) |
442 | 442 |
.arcMap("low1", neg1_l1) |
443 | 443 |
.arcMap("low2", neg1_l2) |
444 | 444 |
.nodeMap("sup", neg1_s) |
445 | 445 |
.run(); |
446 |
|
|
446 |
|
|
447 | 447 |
std::istringstream neg_inp2(test_neg2_lgf); |
448 | 448 |
DigraphReader<Digraph>(neg2_gr, neg_inp2) |
449 | 449 |
.arcMap("cost", neg2_c) |
450 | 450 |
.nodeMap("sup", neg2_s) |
451 | 451 |
.run(); |
452 |
|
|
452 |
|
|
453 | 453 |
// Check the interface of NetworkSimplex |
454 | 454 |
{ |
455 | 455 |
typedef concepts::Digraph GR; |
456 | 456 |
checkConcept< McfClassConcept<GR, int, int>, |
... | ... |
@@ -500,9 +500,9 @@ |
500 | 500 |
CycleCanceling<GR, int, double> >(); |
501 | 501 |
} |
502 | 502 |
|
503 | 503 |
// Test NetworkSimplex |
504 |
{ |
|
504 |
{ |
|
505 | 505 |
typedef NetworkSimplex<Digraph> MCF; |
506 | 506 |
runMcfGeqTests<MCF>(MCF::FIRST_ELIGIBLE, "NS-FE", true); |
507 | 507 |
runMcfLeqTests<MCF>(MCF::FIRST_ELIGIBLE, "NS-FE"); |
508 | 508 |
runMcfGeqTests<MCF>(MCF::BEST_ELIGIBLE, "NS-BE", true); |
... | ... |
@@ -513,9 +513,9 @@ |
513 | 513 |
runMcfLeqTests<MCF>(MCF::CANDIDATE_LIST, "NS-CL"); |
514 | 514 |
runMcfGeqTests<MCF>(MCF::ALTERING_LIST, "NS-AL", true); |
515 | 515 |
runMcfLeqTests<MCF>(MCF::ALTERING_LIST, "NS-AL"); |
516 | 516 |
} |
517 |
|
|
517 |
|
|
518 | 518 |
// Test CapacityScaling |
519 | 519 |
{ |
520 | 520 |
typedef CapacityScaling<Digraph> MCF; |
521 | 521 |
runMcfGeqTests<MCF>(0, "SSP"); |
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-2010 |
|
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 |
... | ... |
@@ -60,9 +60,9 @@ |
60 | 60 |
"6 4 -1 -1 -1 -1 0 0 0 0\n" |
61 | 61 |
"6 7 1 1 1 1 0 0 0 0\n" |
62 | 62 |
"7 7 4 4 4 -1 0 0 0 1\n"; |
63 | 63 |
|
64 |
|
|
64 |
|
|
65 | 65 |
// Check the interface of an MMC algorithm |
66 | 66 |
template <typename GR, typename Cost> |
67 | 67 |
struct MmcClassConcept |
68 | 68 |
{ |
... | ... |
@@ -76,12 +76,12 @@ |
76 | 76 |
::template SetLargeCost<Cost> |
77 | 77 |
::Create MmcAlg; |
78 | 78 |
MmcAlg mmc(me.g, me.cost); |
79 | 79 |
const MmcAlg& const_mmc = mmc; |
80 |
|
|
80 |
|
|
81 | 81 |
typename MmcAlg::Tolerance tol = const_mmc.tolerance(); |
82 | 82 |
mmc.tolerance(tol); |
83 |
|
|
83 |
|
|
84 | 84 |
b = mmc.cycle(p).run(); |
85 | 85 |
b = mmc.findCycleMean(); |
86 | 86 |
b = mmc.findCycle(); |
87 | 87 |
|
... | ... |
@@ -91,9 +91,9 @@ |
91 | 91 |
p = const_mmc.cycle(); |
92 | 92 |
} |
93 | 93 |
|
94 | 94 |
typedef concepts::ReadMap<typename GR::Arc, Cost> CM; |
95 |
|
|
95 |
|
|
96 | 96 |
GR g; |
97 | 97 |
CM cost; |
98 | 98 |
ListPath<GR> p; |
99 | 99 |
Cost v; |
... | ... |
@@ -152,15 +152,15 @@ |
152 | 152 |
checkConcept< MmcClassConcept<GR, int>, |
153 | 153 |
KarpMmc<GR, concepts::ReadMap<GR::Arc, int> > >(); |
154 | 154 |
checkConcept< MmcClassConcept<GR, float>, |
155 | 155 |
KarpMmc<GR, concepts::ReadMap<GR::Arc, float> > >(); |
156 |
|
|
156 |
|
|
157 | 157 |
// HartmannOrlinMmc |
158 | 158 |
checkConcept< MmcClassConcept<GR, int>, |
159 | 159 |
HartmannOrlinMmc<GR, concepts::ReadMap<GR::Arc, int> > >(); |
160 | 160 |
checkConcept< MmcClassConcept<GR, float>, |
161 | 161 |
HartmannOrlinMmc<GR, concepts::ReadMap<GR::Arc, float> > >(); |
162 |
|
|
162 |
|
|
163 | 163 |
// HowardMmc |
164 | 164 |
checkConcept< MmcClassConcept<GR, int>, |
165 | 165 |
HowardMmc<GR, concepts::ReadMap<GR::Arc, int> > >(); |
166 | 166 |
checkConcept< MmcClassConcept<GR, float>, |
... | ... |
@@ -175,13 +175,13 @@ |
175 | 175 |
// Run various tests |
176 | 176 |
{ |
177 | 177 |
typedef SmartDigraph GR; |
178 | 178 |
DIGRAPH_TYPEDEFS(GR); |
179 |
|
|
179 |
|
|
180 | 180 |
GR gr; |
181 | 181 |
IntArcMap l1(gr), l2(gr), l3(gr), l4(gr); |
182 | 182 |
IntArcMap c1(gr), c2(gr), c3(gr), c4(gr); |
183 |
|
|
183 |
|
|
184 | 184 |
std::istringstream input(test_lgf); |
185 | 185 |
digraphReader(gr, input). |
186 | 186 |
arcMap("len1", l1). |
187 | 187 |
arcMap("len2", l2). |
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-2010 |
|
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 |
... | ... |
@@ -93,9 +93,9 @@ |
93 | 93 |
::SetStandardElevator<LinkedElev> |
94 | 94 |
::Create PreflowType; |
95 | 95 |
PreflowType preflow_test(g, cap, n, n); |
96 | 96 |
const PreflowType& const_preflow_test = preflow_test; |
97 |
|
|
97 |
|
|
98 | 98 |
const PreflowType::Elevator& elev = const_preflow_test.elevator(); |
99 | 99 |
preflow_test.elevator(const_cast<PreflowType::Elevator&>(elev)); |
100 | 100 |
PreflowType::Tolerance tol = const_preflow_test.tolerance(); |
101 | 101 |
preflow_test.tolerance(tol); |
... | ... |
@@ -117,9 +117,9 @@ |
117 | 117 |
v = const_preflow_test.flow(e); |
118 | 118 |
const FlowMap& fm = const_preflow_test.flowMap(); |
119 | 119 |
b = const_preflow_test.minCut(n); |
120 | 120 |
const_preflow_test.minCutMap(cut); |
121 |
|
|
121 |
|
|
122 | 122 |
ignore_unused_variable_warning(fm); |
123 | 123 |
} |
124 | 124 |
|
125 | 125 |
int cutValue (const SmartDigraph& g, |
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-2010 |
|
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 |
... | ... |
@@ -80,9 +80,9 @@ |
80 | 80 |
|
81 | 81 |
typedef Digraph::Node Node; |
82 | 82 |
typedef Digraph::Arc Arc; |
83 | 83 |
typedef concepts::ReadMap<Arc, VType> LengthMap; |
84 |
|
|
84 |
|
|
85 | 85 |
typedef Suurballe<Digraph, LengthMap> ST; |
86 | 86 |
typedef Suurballe<Digraph, LengthMap> |
87 | 87 |
::SetFlowMap<ST::FlowMap> |
88 | 88 |
::SetPotentialMap<ST::PotentialMap> |
... | ... |
@@ -113,9 +113,9 @@ |
113 | 113 |
suurb_test.start(n, k); |
114 | 114 |
k = suurb_test.findFlow(n); |
115 | 115 |
k = suurb_test.findFlow(n, k); |
116 | 116 |
suurb_test.findPaths(); |
117 |
|
|
117 |
|
|
118 | 118 |
int f; |
119 | 119 |
VType c; |
120 | 120 |
c = const_suurb_test.totalLength(); |
121 | 121 |
f = const_suurb_test.flow(e); |
... | ... |
@@ -125,9 +125,9 @@ |
125 | 125 |
const SuurballeType::PotentialMap& pm = |
126 | 126 |
const_suurb_test.potentialMap(); |
127 | 127 |
k = const_suurb_test.pathNum(); |
128 | 128 |
Path<Digraph> p = const_suurb_test.path(k); |
129 |
|
|
129 |
|
|
130 | 130 |
ignore_unused_variable_warning(fm); |
131 | 131 |
ignore_unused_variable_warning(pm); |
132 | 132 |
} |
133 | 133 |
|
... | ... |
@@ -207,9 +207,9 @@ |
207 | 207 |
|
208 | 208 |
// Check run() |
209 | 209 |
{ |
210 | 210 |
Suurballe<ListDigraph> suurballe(digraph, length); |
211 |
|
|
211 |
|
|
212 | 212 |
// Find 2 paths |
213 | 213 |
check(suurballe.run(s, t) == 2, "Wrong number of paths"); |
214 | 214 |
check(checkFlow(digraph, suurballe.flowMap(), s, t, 2), |
215 | 215 |
"The flow is not feasible"); |
... | ... |
@@ -218,9 +218,9 @@ |
218 | 218 |
suurballe.potentialMap()), |
219 | 219 |
"Wrong potentials"); |
220 | 220 |
for (int i = 0; i < suurballe.pathNum(); ++i) |
221 | 221 |
check(checkPath(digraph, suurballe.path(i), s, t), "Wrong path"); |
222 |
|
|
222 |
|
|
223 | 223 |
// Find 3 paths |
224 | 224 |
check(suurballe.run(s, t, 3) == 3, "Wrong number of paths"); |
225 | 225 |
check(checkFlow(digraph, suurballe.flowMap(), s, t, 3), |
226 | 226 |
"The flow is not feasible"); |
... | ... |
@@ -229,9 +229,9 @@ |
229 | 229 |
suurballe.potentialMap()), |
230 | 230 |
"Wrong potentials"); |
231 | 231 |
for (int i = 0; i < suurballe.pathNum(); ++i) |
232 | 232 |
check(checkPath(digraph, suurballe.path(i), s, t), "Wrong path"); |
233 |
|
|
233 |
|
|
234 | 234 |
// Find 5 paths (only 3 can be found) |
235 | 235 |
check(suurballe.run(s, t, 5) == 3, "Wrong number of paths"); |
236 | 236 |
check(checkFlow(digraph, suurballe.flowMap(), s, t, 3), |
237 | 237 |
"The flow is not feasible"); |
... | ... |
@@ -241,14 +241,14 @@ |
241 | 241 |
"Wrong potentials"); |
242 | 242 |
for (int i = 0; i < suurballe.pathNum(); ++i) |
243 | 243 |
check(checkPath(digraph, suurballe.path(i), s, t), "Wrong path"); |
244 | 244 |
} |
245 |
|
|
245 |
|
|
246 | 246 |
// Check fullInit() + start() |
247 | 247 |
{ |
248 | 248 |
Suurballe<ListDigraph> suurballe(digraph, length); |
249 | 249 |
suurballe.fullInit(s); |
250 |
|
|
250 |
|
|
251 | 251 |
// Find 2 paths |
252 | 252 |
check(suurballe.start(t) == 2, "Wrong number of paths"); |
253 | 253 |
check(suurballe.totalLength() == 510, "The flow is not optimal"); |
254 | 254 |
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-2010 |
|
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 |
... | ... |
@@ -44,7 +44,7 @@ |
44 | 44 |
<< msg << std::endl; \ |
45 | 45 |
abort(); \ |
46 | 46 |
} else { } \ |
47 | 47 |
} \ |
48 |
|
|
48 |
|
|
49 | 49 |
|
50 | 50 |
#endif |
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-2010 |
|
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 |
... | ... |
@@ -87,9 +87,9 @@ |
87 | 87 |
if(report) std::cerr << "Setup Preflow class: " << ti << '\n'; |
88 | 88 |
ti.restart(); |
89 | 89 |
pre.run(); |
90 | 90 |
if(report) std::cerr << "Run Preflow: " << ti << '\n'; |
91 |
if(report) std::cerr << "\nMax flow value: " << pre.flowValue() << '\n'; |
|
91 |
if(report) std::cerr << "\nMax flow value: " << pre.flowValue() << '\n'; |
|
92 | 92 |
} |
93 | 93 |
|
94 | 94 |
template<class Value, class LargeValue> |
95 | 95 |
void solve_min(ArgParser &ap, std::istream &is, std::ostream &, |
... | ... |
@@ -147,9 +147,9 @@ |
147 | 147 |
ti.restart(); |
148 | 148 |
mat.run(); |
149 | 149 |
if(report) std::cerr << "Run MaxMatching: " << ti << '\n'; |
150 | 150 |
if(report) std::cerr << "\nCardinality of max matching: " |
151 |
<< mat.matchingSize() << '\n'; |
|
151 |
<< mat.matchingSize() << '\n'; |
|
152 | 152 |
} |
153 | 153 |
|
154 | 154 |
|
155 | 155 |
template<class Value, class LargeValue> |
... | ... |
@@ -165,9 +165,9 @@ |
165 | 165 |
<< static_cast<std::string>(ap["infcap"]) << "' as infinite" |
166 | 166 |
<< std::endl; |
167 | 167 |
exit(1); |
168 | 168 |
} |
169 |
|
|
169 |
|
|
170 | 170 |
switch(desc.type) |
171 | 171 |
{ |
172 | 172 |
case DimacsDescriptor::MIN: |
173 | 173 |
solve_min<Value, LargeValue>(ap,is,os,infty,desc); |
... | ... |
@@ -237,9 +237,9 @@ |
237 | 237 |
std::istream& is = (ap.files().size()<1 ? std::cin : input); |
238 | 238 |
std::ostream& os = (ap.files().size()<2 ? std::cout : output); |
239 | 239 |
|
240 | 240 |
DimacsDescriptor desc = dimacsType(is); |
241 |
|
|
241 |
|
|
242 | 242 |
if(!ap.given("q")) |
243 | 243 |
{ |
244 | 244 |
std::cout << "Problem type: "; |
245 | 245 |
switch(desc.type) |
... | ... |
@@ -262,9 +262,9 @@ |
262 | 262 |
std::cout << "\nNum of nodes: " << desc.nodeNum; |
263 | 263 |
std::cout << "\nNum of arcs: " << desc.edgeNum; |
264 | 264 |
std::cout << "\n\n"; |
265 | 265 |
} |
266 |
|
|
266 |
|
|
267 | 267 |
if(ap.given("double")) |
268 | 268 |
solve<double, double>(ap,is,os,desc); |
269 | 269 |
else if(ap.given("ldouble")) |
270 | 270 |
solve<long double, long double>(ap,is,os,desc); |
0 comments (0 inline)