0
21
0
2
2
2
2
10
10
| ... | ... |
@@ -57,49 +57,49 @@ |
| 57 | 57 |
have to be satisfied and all supplies have to be used. |
| 58 | 58 |
|
| 59 | 59 |
|
| 60 | 60 |
\section mcf_algs Algorithms |
| 61 | 61 |
|
| 62 | 62 |
LEMON contains several algorithms for solving this problem, for more |
| 63 | 63 |
information see \ref min_cost_flow_algs "Minimum Cost Flow Algorithms". |
| 64 | 64 |
|
| 65 | 65 |
A feasible solution for this problem can be found using \ref Circulation. |
| 66 | 66 |
|
| 67 | 67 |
|
| 68 | 68 |
\section mcf_dual Dual Solution |
| 69 | 69 |
|
| 70 | 70 |
The dual solution of the minimum cost flow problem is represented by |
| 71 | 71 |
node potentials \f$\pi: V\rightarrow\mathbf{R}\f$.
|
| 72 | 72 |
An \f$f: A\rightarrow\mathbf{R}\f$ primal feasible solution is optimal
|
| 73 | 73 |
if and only if for some \f$\pi: V\rightarrow\mathbf{R}\f$ node potentials
|
| 74 | 74 |
the following \e complementary \e slackness optimality conditions hold. |
| 75 | 75 |
|
| 76 | 76 |
- For all \f$uv\in A\f$ arcs: |
| 77 | 77 |
- if \f$cost^\pi(uv)>0\f$, then \f$f(uv)=lower(uv)\f$; |
| 78 | 78 |
- if \f$lower(uv)<f(uv)<upper(uv)\f$, then \f$cost^\pi(uv)=0\f$; |
| 79 | 79 |
- if \f$cost^\pi(uv)<0\f$, then \f$f(uv)=upper(uv)\f$. |
| 80 | 80 |
- For all \f$u\in V\f$ nodes: |
| 81 |
- \f$\pi(u) |
|
| 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 |
|
| 89 | 89 |
All algorithms provide dual solution (node potentials), as well, |
| 90 | 90 |
if an optimal flow is found. |
| 91 | 91 |
|
| 92 | 92 |
|
| 93 | 93 |
\section mcf_eq Equality Form |
| 94 | 94 |
|
| 95 | 95 |
The above \ref mcf_def "definition" is actually more general than the |
| 96 | 96 |
usual formulation of the minimum cost flow problem, in which strict |
| 97 | 97 |
equalities are required in the supply/demand contraints. |
| 98 | 98 |
|
| 99 | 99 |
\f[ \min\sum_{uv\in A} f(uv) \cdot cost(uv) \f]
|
| 100 | 100 |
\f[ \sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) =
|
| 101 | 101 |
sup(u) \quad \forall u\in V \f] |
| 102 | 102 |
\f[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A \f] |
| 103 | 103 |
|
| 104 | 104 |
However if the sum of the supply values is zero, then these two problems |
| 105 | 105 |
are equivalent. |
| ... | ... |
@@ -124,30 +124,30 @@ |
| 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. |
| 127 | 127 |
The equality form is also a special case of this form, of course. |
| 128 | 128 |
|
| 129 | 129 |
You could easily transform this case to the \ref mcf_def "GEQ form" |
| 130 | 130 |
of the problem by reversing the direction of the arcs and taking the |
| 131 | 131 |
negative of the supply values (e.g. using \ref ReverseDigraph and |
| 132 | 132 |
\ref NegMap adaptors). |
| 133 | 133 |
However \ref NetworkSimplex algorithm also supports this form directly |
| 134 | 134 |
for the sake of convenience. |
| 135 | 135 |
|
| 136 | 136 |
Note that the optimality conditions for this supply constraint type are |
| 137 | 137 |
slightly differ from the conditions that are discussed for the GEQ form, |
| 138 | 138 |
namely the potentials have to be non-negative instead of non-positive. |
| 139 | 139 |
An \f$f: A\rightarrow\mathbf{R}\f$ feasible solution of this problem
|
| 140 | 140 |
is optimal if and only if for some \f$\pi: V\rightarrow\mathbf{R}\f$
|
| 141 | 141 |
node potentials the following conditions hold. |
| 142 | 142 |
|
| 143 | 143 |
- For all \f$uv\in A\f$ arcs: |
| 144 | 144 |
- if \f$cost^\pi(uv)>0\f$, then \f$f(uv)=lower(uv)\f$; |
| 145 | 145 |
- if \f$lower(uv)<f(uv)<upper(uv)\f$, then \f$cost^\pi(uv)=0\f$; |
| 146 | 146 |
- if \f$cost^\pi(uv)<0\f$, then \f$f(uv)=upper(uv)\f$. |
| 147 | 147 |
- For all \f$u\in V\f$ nodes: |
| 148 |
- \f$\pi(u) |
|
| 148 |
- \f$\pi(u)\geq 0\f$; |
|
| 149 | 149 |
- if \f$\sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \neq sup(u)\f$,
|
| 150 | 150 |
then \f$\pi(u)=0\f$. |
| 151 | 151 |
|
| 152 | 152 |
*/ |
| 153 | 153 |
} |
| ... | ... |
@@ -278,49 +278,49 @@ |
| 278 | 278 |
}; |
| 279 | 279 |
|
| 280 | 280 |
/// \brief \ref named-templ-param "Named parameter" for setting |
| 281 | 281 |
/// \c DistMap type. |
| 282 | 282 |
/// |
| 283 | 283 |
/// \ref named-templ-param "Named parameter" for setting |
| 284 | 284 |
/// \c DistMap type. |
| 285 | 285 |
/// It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 286 | 286 |
template <class T> |
| 287 | 287 |
struct SetDistMap |
| 288 | 288 |
: public BellmanFord< Digraph, LengthMap, SetDistMapTraits<T> > {
|
| 289 | 289 |
typedef BellmanFord< Digraph, LengthMap, SetDistMapTraits<T> > Create; |
| 290 | 290 |
}; |
| 291 | 291 |
|
| 292 | 292 |
template <class T> |
| 293 | 293 |
struct SetOperationTraitsTraits : public Traits {
|
| 294 | 294 |
typedef T OperationTraits; |
| 295 | 295 |
}; |
| 296 | 296 |
|
| 297 | 297 |
/// \brief \ref named-templ-param "Named parameter" for setting |
| 298 | 298 |
/// \c OperationTraits type. |
| 299 | 299 |
/// |
| 300 | 300 |
/// \ref named-templ-param "Named parameter" for setting |
| 301 | 301 |
/// \c OperationTraits type. |
| 302 |
/// For more information see \ref BellmanFordDefaultOperationTraits. |
|
| 302 |
/// For more information, see \ref BellmanFordDefaultOperationTraits. |
|
| 303 | 303 |
template <class T> |
| 304 | 304 |
struct SetOperationTraits |
| 305 | 305 |
: public BellmanFord< Digraph, LengthMap, SetOperationTraitsTraits<T> > {
|
| 306 | 306 |
typedef BellmanFord< Digraph, LengthMap, SetOperationTraitsTraits<T> > |
| 307 | 307 |
Create; |
| 308 | 308 |
}; |
| 309 | 309 |
|
| 310 | 310 |
///@} |
| 311 | 311 |
|
| 312 | 312 |
protected: |
| 313 | 313 |
|
| 314 | 314 |
BellmanFord() {}
|
| 315 | 315 |
|
| 316 | 316 |
public: |
| 317 | 317 |
|
| 318 | 318 |
/// \brief Constructor. |
| 319 | 319 |
/// |
| 320 | 320 |
/// Constructor. |
| 321 | 321 |
/// \param g The digraph the algorithm runs on. |
| 322 | 322 |
/// \param length The length map used by the algorithm. |
| 323 | 323 |
BellmanFord(const Digraph& g, const LengthMap& length) : |
| 324 | 324 |
_gr(&g), _length(&length), |
| 325 | 325 |
_pred(0), _local_pred(false), |
| 326 | 326 |
_dist(0), _local_dist(false), _mask(0) {}
|
| ... | ... |
@@ -696,64 +696,64 @@ |
| 696 | 696 |
{
|
| 697 | 697 |
return Path(*_gr, *_pred, t); |
| 698 | 698 |
} |
| 699 | 699 |
|
| 700 | 700 |
/// \brief The distance of the given node from the root(s). |
| 701 | 701 |
/// |
| 702 | 702 |
/// Returns the distance of the given node from the root(s). |
| 703 | 703 |
/// |
| 704 | 704 |
/// \warning If node \c v is not reached from the root(s), then |
| 705 | 705 |
/// the return value of this function is undefined. |
| 706 | 706 |
/// |
| 707 | 707 |
/// \pre Either \ref run() or \ref init() must be called before |
| 708 | 708 |
/// using this function. |
| 709 | 709 |
Value dist(Node v) const { return (*_dist)[v]; }
|
| 710 | 710 |
|
| 711 | 711 |
/// \brief Returns the 'previous arc' of the shortest path tree for |
| 712 | 712 |
/// the given node. |
| 713 | 713 |
/// |
| 714 | 714 |
/// This function returns the 'previous arc' of the shortest path |
| 715 | 715 |
/// tree for node \c v, i.e. it returns the last arc of a |
| 716 | 716 |
/// shortest path from a root to \c v. It is \c INVALID if \c v |
| 717 | 717 |
/// is not reached from the root(s) or if \c v is a root. |
| 718 | 718 |
/// |
| 719 | 719 |
/// The shortest path tree used here is equal to the shortest path |
| 720 |
/// tree used in \ref predNode() and \predMap(). |
|
| 720 |
/// tree used in \ref predNode() and \ref predMap(). |
|
| 721 | 721 |
/// |
| 722 | 722 |
/// \pre Either \ref run() or \ref init() must be called before |
| 723 | 723 |
/// using this function. |
| 724 | 724 |
Arc predArc(Node v) const { return (*_pred)[v]; }
|
| 725 | 725 |
|
| 726 | 726 |
/// \brief Returns the 'previous node' of the shortest path tree for |
| 727 | 727 |
/// the given node. |
| 728 | 728 |
/// |
| 729 | 729 |
/// This function returns the 'previous node' of the shortest path |
| 730 | 730 |
/// tree for node \c v, i.e. it returns the last but one node of |
| 731 | 731 |
/// a shortest path from a root to \c v. It is \c INVALID if \c v |
| 732 | 732 |
/// is not reached from the root(s) or if \c v is a root. |
| 733 | 733 |
/// |
| 734 | 734 |
/// The shortest path tree used here is equal to the shortest path |
| 735 |
/// tree used in \ref predArc() and \predMap(). |
|
| 735 |
/// tree used in \ref predArc() and \ref predMap(). |
|
| 736 | 736 |
/// |
| 737 | 737 |
/// \pre Either \ref run() or \ref init() must be called before |
| 738 | 738 |
/// using this function. |
| 739 | 739 |
Node predNode(Node v) const {
|
| 740 | 740 |
return (*_pred)[v] == INVALID ? INVALID : _gr->source((*_pred)[v]); |
| 741 | 741 |
} |
| 742 | 742 |
|
| 743 | 743 |
/// \brief Returns a const reference to the node map that stores the |
| 744 | 744 |
/// distances of the nodes. |
| 745 | 745 |
/// |
| 746 | 746 |
/// Returns a const reference to the node map that stores the distances |
| 747 | 747 |
/// of the nodes calculated by the algorithm. |
| 748 | 748 |
/// |
| 749 | 749 |
/// \pre Either \ref run() or \ref init() must be called before |
| 750 | 750 |
/// using this function. |
| 751 | 751 |
const DistMap &distMap() const { return *_dist;}
|
| 752 | 752 |
|
| 753 | 753 |
/// \brief Returns a const reference to the node map that stores the |
| 754 | 754 |
/// predecessor arcs. |
| 755 | 755 |
/// |
| 756 | 756 |
/// Returns a const reference to the node map that stores the predecessor |
| 757 | 757 |
/// arcs, which form the shortest path tree (forest). |
| 758 | 758 |
/// |
| 759 | 759 |
/// \pre Either \ref run() or \ref init() must be called before |
| ... | ... |
@@ -42,49 +42,49 @@ |
| 42 | 42 |
///The type of the digraph the algorithm runs on. |
| 43 | 43 |
typedef GR Digraph; |
| 44 | 44 |
|
| 45 | 45 |
///\brief The type of the map that stores the predecessor |
| 46 | 46 |
///arcs of the shortest paths. |
| 47 | 47 |
/// |
| 48 | 48 |
///The type of the map that stores the predecessor |
| 49 | 49 |
///arcs of the shortest paths. |
| 50 | 50 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 51 | 51 |
typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; |
| 52 | 52 |
///Instantiates a \c PredMap. |
| 53 | 53 |
|
| 54 | 54 |
///This function instantiates a \ref PredMap. |
| 55 | 55 |
///\param g is the digraph, to which we would like to define the |
| 56 | 56 |
///\ref PredMap. |
| 57 | 57 |
static PredMap *createPredMap(const Digraph &g) |
| 58 | 58 |
{
|
| 59 | 59 |
return new PredMap(g); |
| 60 | 60 |
} |
| 61 | 61 |
|
| 62 | 62 |
///The type of the map that indicates which nodes are processed. |
| 63 | 63 |
|
| 64 | 64 |
///The type of the map that indicates which nodes are processed. |
| 65 | 65 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 66 |
///By default it is a NullMap. |
|
| 66 |
///By default, it is a NullMap. |
|
| 67 | 67 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
| 68 | 68 |
///Instantiates a \c ProcessedMap. |
| 69 | 69 |
|
| 70 | 70 |
///This function instantiates a \ref ProcessedMap. |
| 71 | 71 |
///\param g is the digraph, to which |
| 72 | 72 |
///we would like to define the \ref ProcessedMap |
| 73 | 73 |
#ifdef DOXYGEN |
| 74 | 74 |
static ProcessedMap *createProcessedMap(const Digraph &g) |
| 75 | 75 |
#else |
| 76 | 76 |
static ProcessedMap *createProcessedMap(const Digraph &) |
| 77 | 77 |
#endif |
| 78 | 78 |
{
|
| 79 | 79 |
return new ProcessedMap(); |
| 80 | 80 |
} |
| 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 | 85 |
///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
| 86 | 86 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
| 87 | 87 |
///Instantiates a \c ReachedMap. |
| 88 | 88 |
|
| 89 | 89 |
///This function instantiates a \ref ReachedMap. |
| 90 | 90 |
///\param g is the digraph, to which |
| ... | ... |
@@ -831,49 +831,49 @@ |
| 831 | 831 |
///The type of the digraph the algorithm runs on. |
| 832 | 832 |
typedef GR Digraph; |
| 833 | 833 |
|
| 834 | 834 |
///\brief The type of the map that stores the predecessor |
| 835 | 835 |
///arcs of the shortest paths. |
| 836 | 836 |
/// |
| 837 | 837 |
///The type of the map that stores the predecessor |
| 838 | 838 |
///arcs of the shortest paths. |
| 839 | 839 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 840 | 840 |
typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; |
| 841 | 841 |
///Instantiates a PredMap. |
| 842 | 842 |
|
| 843 | 843 |
///This function instantiates a PredMap. |
| 844 | 844 |
///\param g is the digraph, to which we would like to define the |
| 845 | 845 |
///PredMap. |
| 846 | 846 |
static PredMap *createPredMap(const Digraph &g) |
| 847 | 847 |
{
|
| 848 | 848 |
return new PredMap(g); |
| 849 | 849 |
} |
| 850 | 850 |
|
| 851 | 851 |
///The type of the map that indicates which nodes are processed. |
| 852 | 852 |
|
| 853 | 853 |
///The type of the map that indicates which nodes are processed. |
| 854 | 854 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 855 |
///By default it is a NullMap. |
|
| 855 |
///By default, it is a NullMap. |
|
| 856 | 856 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
| 857 | 857 |
///Instantiates a ProcessedMap. |
| 858 | 858 |
|
| 859 | 859 |
///This function instantiates a ProcessedMap. |
| 860 | 860 |
///\param g is the digraph, to which |
| 861 | 861 |
///we would like to define the ProcessedMap. |
| 862 | 862 |
#ifdef DOXYGEN |
| 863 | 863 |
static ProcessedMap *createProcessedMap(const Digraph &g) |
| 864 | 864 |
#else |
| 865 | 865 |
static ProcessedMap *createProcessedMap(const Digraph &) |
| 866 | 866 |
#endif |
| 867 | 867 |
{
|
| 868 | 868 |
return new ProcessedMap(); |
| 869 | 869 |
} |
| 870 | 870 |
|
| 871 | 871 |
///The type of the map that indicates which nodes are reached. |
| 872 | 872 |
|
| 873 | 873 |
///The type of the map that indicates which nodes are reached. |
| 874 | 874 |
///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
| 875 | 875 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
| 876 | 876 |
///Instantiates a ReachedMap. |
| 877 | 877 |
|
| 878 | 878 |
///This function instantiates a ReachedMap. |
| 879 | 879 |
///\param g is the digraph, to which |
| ... | ... |
@@ -285,49 +285,49 @@ |
| 285 | 285 |
template <typename T> |
| 286 | 286 |
struct SetElevator |
| 287 | 287 |
: public Circulation<Digraph, LowerMap, UpperMap, SupplyMap, |
| 288 | 288 |
SetElevatorTraits<T> > {
|
| 289 | 289 |
typedef Circulation<Digraph, LowerMap, UpperMap, SupplyMap, |
| 290 | 290 |
SetElevatorTraits<T> > Create; |
| 291 | 291 |
}; |
| 292 | 292 |
|
| 293 | 293 |
template <typename T> |
| 294 | 294 |
struct SetStandardElevatorTraits : public Traits {
|
| 295 | 295 |
typedef T Elevator; |
| 296 | 296 |
static Elevator *createElevator(const Digraph& digraph, int max_level) {
|
| 297 | 297 |
return new Elevator(digraph, max_level); |
| 298 | 298 |
} |
| 299 | 299 |
}; |
| 300 | 300 |
|
| 301 | 301 |
/// \brief \ref named-templ-param "Named parameter" for setting |
| 302 | 302 |
/// Elevator type with automatic allocation |
| 303 | 303 |
/// |
| 304 | 304 |
/// \ref named-templ-param "Named parameter" for setting Elevator |
| 305 | 305 |
/// type with automatic allocation. |
| 306 | 306 |
/// The Elevator should have standard constructor interface to be |
| 307 | 307 |
/// able to automatically created by the algorithm (i.e. the |
| 308 | 308 |
/// digraph and the maximum level should be passed to it). |
| 309 |
/// However an external elevator object could also be passed to the |
|
| 309 |
/// However, an external elevator object could also be passed to the |
|
| 310 | 310 |
/// algorithm with the \ref elevator(Elevator&) "elevator()" function |
| 311 | 311 |
/// before calling \ref run() or \ref init(). |
| 312 | 312 |
/// \sa SetElevator |
| 313 | 313 |
template <typename T> |
| 314 | 314 |
struct SetStandardElevator |
| 315 | 315 |
: public Circulation<Digraph, LowerMap, UpperMap, SupplyMap, |
| 316 | 316 |
SetStandardElevatorTraits<T> > {
|
| 317 | 317 |
typedef Circulation<Digraph, LowerMap, UpperMap, SupplyMap, |
| 318 | 318 |
SetStandardElevatorTraits<T> > Create; |
| 319 | 319 |
}; |
| 320 | 320 |
|
| 321 | 321 |
/// @} |
| 322 | 322 |
|
| 323 | 323 |
protected: |
| 324 | 324 |
|
| 325 | 325 |
Circulation() {}
|
| 326 | 326 |
|
| 327 | 327 |
public: |
| 328 | 328 |
|
| 329 | 329 |
/// Constructor. |
| 330 | 330 |
|
| 331 | 331 |
/// The constructor of the class. |
| 332 | 332 |
/// |
| 333 | 333 |
/// \param graph The digraph the algorithm runs on. |
| ... | ... |
@@ -86,49 +86,49 @@ |
| 86 | 86 |
/// Equality operator. |
| 87 | 87 |
/// |
| 88 | 88 |
/// Two iterators are equal if and only if they point to the |
| 89 | 89 |
/// same object or both are \c INVALID. |
| 90 | 90 |
bool operator==(Node) const { return true; }
|
| 91 | 91 |
|
| 92 | 92 |
/// Inequality operator |
| 93 | 93 |
|
| 94 | 94 |
/// Inequality operator. |
| 95 | 95 |
bool operator!=(Node) const { return true; }
|
| 96 | 96 |
|
| 97 | 97 |
/// Artificial ordering operator. |
| 98 | 98 |
|
| 99 | 99 |
/// Artificial ordering operator. |
| 100 | 100 |
/// |
| 101 | 101 |
/// \note This operator only has to define some strict ordering of |
| 102 | 102 |
/// the nodes; this order has nothing to do with the iteration |
| 103 | 103 |
/// ordering of the nodes. |
| 104 | 104 |
bool operator<(Node) const { return false; }
|
| 105 | 105 |
}; |
| 106 | 106 |
|
| 107 | 107 |
/// Iterator class for the nodes. |
| 108 | 108 |
|
| 109 | 109 |
/// This iterator goes through each node of the digraph. |
| 110 |
/// Its usage is quite simple, for example you can count the number |
|
| 110 |
/// Its usage is quite simple, for example, you can count the number |
|
| 111 | 111 |
/// of nodes in a digraph \c g of type \c %Digraph like this: |
| 112 | 112 |
///\code |
| 113 | 113 |
/// int count=0; |
| 114 | 114 |
/// for (Digraph::NodeIt n(g); n!=INVALID; ++n) ++count; |
| 115 | 115 |
///\endcode |
| 116 | 116 |
class NodeIt : public Node {
|
| 117 | 117 |
public: |
| 118 | 118 |
/// Default constructor |
| 119 | 119 |
|
| 120 | 120 |
/// Default constructor. |
| 121 | 121 |
/// \warning It sets the iterator to an undefined value. |
| 122 | 122 |
NodeIt() { }
|
| 123 | 123 |
/// Copy constructor. |
| 124 | 124 |
|
| 125 | 125 |
/// Copy constructor. |
| 126 | 126 |
/// |
| 127 | 127 |
NodeIt(const NodeIt& n) : Node(n) { }
|
| 128 | 128 |
/// %Invalid constructor \& conversion. |
| 129 | 129 |
|
| 130 | 130 |
/// Initializes the iterator to be invalid. |
| 131 | 131 |
/// \sa Invalid for more details. |
| 132 | 132 |
NodeIt(Invalid) { }
|
| 133 | 133 |
/// Sets the iterator to the first node. |
| 134 | 134 |
|
| ... | ... |
@@ -175,138 +175,138 @@ |
| 175 | 175 |
/// Equality operator. |
| 176 | 176 |
/// |
| 177 | 177 |
/// Two iterators are equal if and only if they point to the |
| 178 | 178 |
/// same object or both are \c INVALID. |
| 179 | 179 |
bool operator==(Arc) const { return true; }
|
| 180 | 180 |
/// Inequality operator |
| 181 | 181 |
|
| 182 | 182 |
/// Inequality operator. |
| 183 | 183 |
bool operator!=(Arc) const { return true; }
|
| 184 | 184 |
|
| 185 | 185 |
/// Artificial ordering operator. |
| 186 | 186 |
|
| 187 | 187 |
/// Artificial ordering operator. |
| 188 | 188 |
/// |
| 189 | 189 |
/// \note This operator only has to define some strict ordering of |
| 190 | 190 |
/// the arcs; this order has nothing to do with the iteration |
| 191 | 191 |
/// ordering of the arcs. |
| 192 | 192 |
bool operator<(Arc) const { return false; }
|
| 193 | 193 |
}; |
| 194 | 194 |
|
| 195 | 195 |
/// Iterator class for the outgoing arcs of a node. |
| 196 | 196 |
|
| 197 | 197 |
/// This iterator goes trough the \e outgoing arcs of a certain node |
| 198 | 198 |
/// of a digraph. |
| 199 |
/// Its usage is quite simple, for example you can count the number |
|
| 199 |
/// Its usage is quite simple, for example, you can count the number |
|
| 200 | 200 |
/// of outgoing arcs of a node \c n |
| 201 | 201 |
/// in a digraph \c g of type \c %Digraph as follows. |
| 202 | 202 |
///\code |
| 203 | 203 |
/// int count=0; |
| 204 | 204 |
/// for (Digraph::OutArcIt a(g, n); a!=INVALID; ++a) ++count; |
| 205 | 205 |
///\endcode |
| 206 | 206 |
class OutArcIt : public Arc {
|
| 207 | 207 |
public: |
| 208 | 208 |
/// Default constructor |
| 209 | 209 |
|
| 210 | 210 |
/// Default constructor. |
| 211 | 211 |
/// \warning It sets the iterator to an undefined value. |
| 212 | 212 |
OutArcIt() { }
|
| 213 | 213 |
/// Copy constructor. |
| 214 | 214 |
|
| 215 | 215 |
/// Copy constructor. |
| 216 | 216 |
/// |
| 217 | 217 |
OutArcIt(const OutArcIt& e) : Arc(e) { }
|
| 218 | 218 |
/// %Invalid constructor \& conversion. |
| 219 | 219 |
|
| 220 | 220 |
/// Initializes the iterator to be invalid. |
| 221 | 221 |
/// \sa Invalid for more details. |
| 222 | 222 |
OutArcIt(Invalid) { }
|
| 223 | 223 |
/// Sets the iterator to the first outgoing arc. |
| 224 | 224 |
|
| 225 | 225 |
/// Sets the iterator to the first outgoing arc of the given node. |
| 226 | 226 |
/// |
| 227 | 227 |
OutArcIt(const Digraph&, const Node&) { }
|
| 228 | 228 |
/// Sets the iterator to the given arc. |
| 229 | 229 |
|
| 230 | 230 |
/// Sets the iterator to the given arc of the given digraph. |
| 231 | 231 |
/// |
| 232 | 232 |
OutArcIt(const Digraph&, const Arc&) { }
|
| 233 | 233 |
/// Next outgoing arc |
| 234 | 234 |
|
| 235 | 235 |
/// Assign the iterator to the next |
| 236 | 236 |
/// outgoing arc of the corresponding node. |
| 237 | 237 |
OutArcIt& operator++() { return *this; }
|
| 238 | 238 |
}; |
| 239 | 239 |
|
| 240 | 240 |
/// Iterator class for the incoming arcs of a node. |
| 241 | 241 |
|
| 242 | 242 |
/// This iterator goes trough the \e incoming arcs of a certain node |
| 243 | 243 |
/// of a digraph. |
| 244 |
/// Its usage is quite simple, for example you can count the number |
|
| 244 |
/// Its usage is quite simple, for example, you can count the number |
|
| 245 | 245 |
/// of incoming arcs of a node \c n |
| 246 | 246 |
/// in a digraph \c g of type \c %Digraph as follows. |
| 247 | 247 |
///\code |
| 248 | 248 |
/// int count=0; |
| 249 | 249 |
/// for(Digraph::InArcIt a(g, n); a!=INVALID; ++a) ++count; |
| 250 | 250 |
///\endcode |
| 251 | 251 |
class InArcIt : public Arc {
|
| 252 | 252 |
public: |
| 253 | 253 |
/// Default constructor |
| 254 | 254 |
|
| 255 | 255 |
/// Default constructor. |
| 256 | 256 |
/// \warning It sets the iterator to an undefined value. |
| 257 | 257 |
InArcIt() { }
|
| 258 | 258 |
/// Copy constructor. |
| 259 | 259 |
|
| 260 | 260 |
/// Copy constructor. |
| 261 | 261 |
/// |
| 262 | 262 |
InArcIt(const InArcIt& e) : Arc(e) { }
|
| 263 | 263 |
/// %Invalid constructor \& conversion. |
| 264 | 264 |
|
| 265 | 265 |
/// Initializes the iterator to be invalid. |
| 266 | 266 |
/// \sa Invalid for more details. |
| 267 | 267 |
InArcIt(Invalid) { }
|
| 268 | 268 |
/// Sets the iterator to the first incoming arc. |
| 269 | 269 |
|
| 270 | 270 |
/// Sets the iterator to the first incoming arc of the given node. |
| 271 | 271 |
/// |
| 272 | 272 |
InArcIt(const Digraph&, const Node&) { }
|
| 273 | 273 |
/// Sets the iterator to the given arc. |
| 274 | 274 |
|
| 275 | 275 |
/// Sets the iterator to the given arc of the given digraph. |
| 276 | 276 |
/// |
| 277 | 277 |
InArcIt(const Digraph&, const Arc&) { }
|
| 278 | 278 |
/// Next incoming arc |
| 279 | 279 |
|
| 280 | 280 |
/// Assign the iterator to the next |
| 281 | 281 |
/// incoming arc of the corresponding node. |
| 282 | 282 |
InArcIt& operator++() { return *this; }
|
| 283 | 283 |
}; |
| 284 | 284 |
|
| 285 | 285 |
/// Iterator class for the arcs. |
| 286 | 286 |
|
| 287 | 287 |
/// This iterator goes through each arc of the digraph. |
| 288 |
/// Its usage is quite simple, for example you can count the number |
|
| 288 |
/// Its usage is quite simple, for example, you can count the number |
|
| 289 | 289 |
/// of arcs in a digraph \c g of type \c %Digraph as follows: |
| 290 | 290 |
///\code |
| 291 | 291 |
/// int count=0; |
| 292 | 292 |
/// for(Digraph::ArcIt a(g); a!=INVALID; ++a) ++count; |
| 293 | 293 |
///\endcode |
| 294 | 294 |
class ArcIt : public Arc {
|
| 295 | 295 |
public: |
| 296 | 296 |
/// Default constructor |
| 297 | 297 |
|
| 298 | 298 |
/// Default constructor. |
| 299 | 299 |
/// \warning It sets the iterator to an undefined value. |
| 300 | 300 |
ArcIt() { }
|
| 301 | 301 |
/// Copy constructor. |
| 302 | 302 |
|
| 303 | 303 |
/// Copy constructor. |
| 304 | 304 |
/// |
| 305 | 305 |
ArcIt(const ArcIt& e) : Arc(e) { }
|
| 306 | 306 |
/// %Invalid constructor \& conversion. |
| 307 | 307 |
|
| 308 | 308 |
/// Initializes the iterator to be invalid. |
| 309 | 309 |
/// \sa Invalid for more details. |
| 310 | 310 |
ArcIt(Invalid) { }
|
| 311 | 311 |
/// Sets the iterator to the first arc. |
| 312 | 312 |
| ... | ... |
@@ -119,49 +119,49 @@ |
| 119 | 119 |
/// |
| 120 | 120 |
/// Two iterators are equal if and only if they point to the |
| 121 | 121 |
/// same object or both are \c INVALID. |
| 122 | 122 |
bool operator==(Node) const { return true; }
|
| 123 | 123 |
|
| 124 | 124 |
/// Inequality operator |
| 125 | 125 |
|
| 126 | 126 |
/// Inequality operator. |
| 127 | 127 |
bool operator!=(Node) const { return true; }
|
| 128 | 128 |
|
| 129 | 129 |
/// Artificial ordering operator. |
| 130 | 130 |
|
| 131 | 131 |
/// Artificial ordering operator. |
| 132 | 132 |
/// |
| 133 | 133 |
/// \note This operator only has to define some strict ordering of |
| 134 | 134 |
/// the items; this order has nothing to do with the iteration |
| 135 | 135 |
/// ordering of the items. |
| 136 | 136 |
bool operator<(Node) const { return false; }
|
| 137 | 137 |
|
| 138 | 138 |
}; |
| 139 | 139 |
|
| 140 | 140 |
/// Iterator class for the nodes. |
| 141 | 141 |
|
| 142 | 142 |
/// This iterator goes through each node of the graph. |
| 143 |
/// Its usage is quite simple, for example you can count the number |
|
| 143 |
/// Its usage is quite simple, for example, you can count the number |
|
| 144 | 144 |
/// of nodes in a graph \c g of type \c %Graph like this: |
| 145 | 145 |
///\code |
| 146 | 146 |
/// int count=0; |
| 147 | 147 |
/// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count; |
| 148 | 148 |
///\endcode |
| 149 | 149 |
class NodeIt : public Node {
|
| 150 | 150 |
public: |
| 151 | 151 |
/// Default constructor |
| 152 | 152 |
|
| 153 | 153 |
/// Default constructor. |
| 154 | 154 |
/// \warning It sets the iterator to an undefined value. |
| 155 | 155 |
NodeIt() { }
|
| 156 | 156 |
/// Copy constructor. |
| 157 | 157 |
|
| 158 | 158 |
/// Copy constructor. |
| 159 | 159 |
/// |
| 160 | 160 |
NodeIt(const NodeIt& n) : Node(n) { }
|
| 161 | 161 |
/// %Invalid constructor \& conversion. |
| 162 | 162 |
|
| 163 | 163 |
/// Initializes the iterator to be invalid. |
| 164 | 164 |
/// \sa Invalid for more details. |
| 165 | 165 |
NodeIt(Invalid) { }
|
| 166 | 166 |
/// Sets the iterator to the first node. |
| 167 | 167 |
|
| ... | ... |
@@ -207,93 +207,93 @@ |
| 207 | 207 |
|
| 208 | 208 |
/// Equality operator. |
| 209 | 209 |
/// |
| 210 | 210 |
/// Two iterators are equal if and only if they point to the |
| 211 | 211 |
/// same object or both are \c INVALID. |
| 212 | 212 |
bool operator==(Edge) const { return true; }
|
| 213 | 213 |
/// Inequality operator |
| 214 | 214 |
|
| 215 | 215 |
/// Inequality operator. |
| 216 | 216 |
bool operator!=(Edge) const { return true; }
|
| 217 | 217 |
|
| 218 | 218 |
/// Artificial ordering operator. |
| 219 | 219 |
|
| 220 | 220 |
/// Artificial ordering operator. |
| 221 | 221 |
/// |
| 222 | 222 |
/// \note This operator only has to define some strict ordering of |
| 223 | 223 |
/// the edges; this order has nothing to do with the iteration |
| 224 | 224 |
/// ordering of the edges. |
| 225 | 225 |
bool operator<(Edge) const { return false; }
|
| 226 | 226 |
}; |
| 227 | 227 |
|
| 228 | 228 |
/// Iterator class for the edges. |
| 229 | 229 |
|
| 230 | 230 |
/// This iterator goes through each edge of the graph. |
| 231 |
/// Its usage is quite simple, for example you can count the number |
|
| 231 |
/// Its usage is quite simple, for example, you can count the number |
|
| 232 | 232 |
/// of edges in a graph \c g of type \c %Graph as follows: |
| 233 | 233 |
///\code |
| 234 | 234 |
/// int count=0; |
| 235 | 235 |
/// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count; |
| 236 | 236 |
///\endcode |
| 237 | 237 |
class EdgeIt : public Edge {
|
| 238 | 238 |
public: |
| 239 | 239 |
/// Default constructor |
| 240 | 240 |
|
| 241 | 241 |
/// Default constructor. |
| 242 | 242 |
/// \warning It sets the iterator to an undefined value. |
| 243 | 243 |
EdgeIt() { }
|
| 244 | 244 |
/// Copy constructor. |
| 245 | 245 |
|
| 246 | 246 |
/// Copy constructor. |
| 247 | 247 |
/// |
| 248 | 248 |
EdgeIt(const EdgeIt& e) : Edge(e) { }
|
| 249 | 249 |
/// %Invalid constructor \& conversion. |
| 250 | 250 |
|
| 251 | 251 |
/// Initializes the iterator to be invalid. |
| 252 | 252 |
/// \sa Invalid for more details. |
| 253 | 253 |
EdgeIt(Invalid) { }
|
| 254 | 254 |
/// Sets the iterator to the first edge. |
| 255 | 255 |
|
| 256 | 256 |
/// Sets the iterator to the first edge of the given graph. |
| 257 | 257 |
/// |
| 258 | 258 |
explicit EdgeIt(const Graph&) { }
|
| 259 | 259 |
/// Sets the iterator to the given edge. |
| 260 | 260 |
|
| 261 | 261 |
/// Sets the iterator to the given edge of the given graph. |
| 262 | 262 |
/// |
| 263 | 263 |
EdgeIt(const Graph&, const Edge&) { }
|
| 264 | 264 |
/// Next edge |
| 265 | 265 |
|
| 266 | 266 |
/// Assign the iterator to the next edge. |
| 267 | 267 |
/// |
| 268 | 268 |
EdgeIt& operator++() { return *this; }
|
| 269 | 269 |
}; |
| 270 | 270 |
|
| 271 | 271 |
/// Iterator class for the incident edges of a node. |
| 272 | 272 |
|
| 273 | 273 |
/// This iterator goes trough the incident undirected edges |
| 274 | 274 |
/// of a certain node of a graph. |
| 275 |
/// Its usage is quite simple, for example you can compute the |
|
| 275 |
/// Its usage is quite simple, for example, you can compute the |
|
| 276 | 276 |
/// degree (i.e. the number of incident edges) of a node \c n |
| 277 | 277 |
/// in a graph \c g of type \c %Graph as follows. |
| 278 | 278 |
/// |
| 279 | 279 |
///\code |
| 280 | 280 |
/// int count=0; |
| 281 | 281 |
/// for(Graph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count; |
| 282 | 282 |
///\endcode |
| 283 | 283 |
/// |
| 284 | 284 |
/// \warning Loop edges will be iterated twice. |
| 285 | 285 |
class IncEdgeIt : public Edge {
|
| 286 | 286 |
public: |
| 287 | 287 |
/// Default constructor |
| 288 | 288 |
|
| 289 | 289 |
/// Default constructor. |
| 290 | 290 |
/// \warning It sets the iterator to an undefined value. |
| 291 | 291 |
IncEdgeIt() { }
|
| 292 | 292 |
/// Copy constructor. |
| 293 | 293 |
|
| 294 | 294 |
/// Copy constructor. |
| 295 | 295 |
/// |
| 296 | 296 |
IncEdgeIt(const IncEdgeIt& e) : Edge(e) { }
|
| 297 | 297 |
/// %Invalid constructor \& conversion. |
| 298 | 298 |
|
| 299 | 299 |
/// Initializes the iterator to be invalid. |
| ... | ... |
@@ -348,141 +348,141 @@ |
| 348 | 348 |
/// Inequality operator |
| 349 | 349 |
|
| 350 | 350 |
/// Inequality operator. |
| 351 | 351 |
bool operator!=(Arc) const { return true; }
|
| 352 | 352 |
|
| 353 | 353 |
/// Artificial ordering operator. |
| 354 | 354 |
|
| 355 | 355 |
/// Artificial ordering operator. |
| 356 | 356 |
/// |
| 357 | 357 |
/// \note This operator only has to define some strict ordering of |
| 358 | 358 |
/// the arcs; this order has nothing to do with the iteration |
| 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 |
}; |
| 368 | 368 |
|
| 369 | 369 |
/// Iterator class for the arcs. |
| 370 | 370 |
|
| 371 | 371 |
/// This iterator goes through each directed arc of the graph. |
| 372 |
/// Its usage is quite simple, for example you can count the number |
|
| 372 |
/// Its usage is quite simple, for example, you can count the number |
|
| 373 | 373 |
/// of arcs in a graph \c g of type \c %Graph as follows: |
| 374 | 374 |
///\code |
| 375 | 375 |
/// int count=0; |
| 376 | 376 |
/// for(Graph::ArcIt a(g); a!=INVALID; ++a) ++count; |
| 377 | 377 |
///\endcode |
| 378 | 378 |
class ArcIt : public Arc {
|
| 379 | 379 |
public: |
| 380 | 380 |
/// Default constructor |
| 381 | 381 |
|
| 382 | 382 |
/// Default constructor. |
| 383 | 383 |
/// \warning It sets the iterator to an undefined value. |
| 384 | 384 |
ArcIt() { }
|
| 385 | 385 |
/// Copy constructor. |
| 386 | 386 |
|
| 387 | 387 |
/// Copy constructor. |
| 388 | 388 |
/// |
| 389 | 389 |
ArcIt(const ArcIt& e) : Arc(e) { }
|
| 390 | 390 |
/// %Invalid constructor \& conversion. |
| 391 | 391 |
|
| 392 | 392 |
/// Initializes the iterator to be invalid. |
| 393 | 393 |
/// \sa Invalid for more details. |
| 394 | 394 |
ArcIt(Invalid) { }
|
| 395 | 395 |
/// Sets the iterator to the first arc. |
| 396 | 396 |
|
| 397 | 397 |
/// Sets the iterator to the first arc of the given graph. |
| 398 | 398 |
/// |
| 399 | 399 |
explicit ArcIt(const Graph &g) { ignore_unused_variable_warning(g); }
|
| 400 | 400 |
/// Sets the iterator to the given arc. |
| 401 | 401 |
|
| 402 | 402 |
/// Sets the iterator to the given arc of the given graph. |
| 403 | 403 |
/// |
| 404 | 404 |
ArcIt(const Graph&, const Arc&) { }
|
| 405 | 405 |
/// Next arc |
| 406 | 406 |
|
| 407 | 407 |
/// Assign the iterator to the next arc. |
| 408 | 408 |
/// |
| 409 | 409 |
ArcIt& operator++() { return *this; }
|
| 410 | 410 |
}; |
| 411 | 411 |
|
| 412 | 412 |
/// Iterator class for the outgoing arcs of a node. |
| 413 | 413 |
|
| 414 | 414 |
/// This iterator goes trough the \e outgoing directed arcs of a |
| 415 | 415 |
/// certain node of a graph. |
| 416 |
/// Its usage is quite simple, for example you can count the number |
|
| 416 |
/// Its usage is quite simple, for example, you can count the number |
|
| 417 | 417 |
/// of outgoing arcs of a node \c n |
| 418 | 418 |
/// in a graph \c g of type \c %Graph as follows. |
| 419 | 419 |
///\code |
| 420 | 420 |
/// int count=0; |
| 421 | 421 |
/// for (Digraph::OutArcIt a(g, n); a!=INVALID; ++a) ++count; |
| 422 | 422 |
///\endcode |
| 423 | 423 |
class OutArcIt : public Arc {
|
| 424 | 424 |
public: |
| 425 | 425 |
/// Default constructor |
| 426 | 426 |
|
| 427 | 427 |
/// Default constructor. |
| 428 | 428 |
/// \warning It sets the iterator to an undefined value. |
| 429 | 429 |
OutArcIt() { }
|
| 430 | 430 |
/// Copy constructor. |
| 431 | 431 |
|
| 432 | 432 |
/// Copy constructor. |
| 433 | 433 |
/// |
| 434 | 434 |
OutArcIt(const OutArcIt& e) : Arc(e) { }
|
| 435 | 435 |
/// %Invalid constructor \& conversion. |
| 436 | 436 |
|
| 437 | 437 |
/// Initializes the iterator to be invalid. |
| 438 | 438 |
/// \sa Invalid for more details. |
| 439 | 439 |
OutArcIt(Invalid) { }
|
| 440 | 440 |
/// Sets the iterator to the first outgoing arc. |
| 441 | 441 |
|
| 442 | 442 |
/// Sets the iterator to the first outgoing arc of the given node. |
| 443 | 443 |
/// |
| 444 | 444 |
OutArcIt(const Graph& n, const Node& g) {
|
| 445 | 445 |
ignore_unused_variable_warning(n); |
| 446 | 446 |
ignore_unused_variable_warning(g); |
| 447 | 447 |
} |
| 448 | 448 |
/// Sets the iterator to the given arc. |
| 449 | 449 |
|
| 450 | 450 |
/// Sets the iterator to the given arc of the given graph. |
| 451 | 451 |
/// |
| 452 | 452 |
OutArcIt(const Graph&, const Arc&) { }
|
| 453 | 453 |
/// Next outgoing arc |
| 454 | 454 |
|
| 455 | 455 |
/// Assign the iterator to the next |
| 456 | 456 |
/// outgoing arc of the corresponding node. |
| 457 | 457 |
OutArcIt& operator++() { return *this; }
|
| 458 | 458 |
}; |
| 459 | 459 |
|
| 460 | 460 |
/// Iterator class for the incoming arcs of a node. |
| 461 | 461 |
|
| 462 | 462 |
/// This iterator goes trough the \e incoming directed arcs of a |
| 463 | 463 |
/// certain node of a graph. |
| 464 |
/// Its usage is quite simple, for example you can count the number |
|
| 464 |
/// Its usage is quite simple, for example, you can count the number |
|
| 465 | 465 |
/// of incoming arcs of a node \c n |
| 466 | 466 |
/// in a graph \c g of type \c %Graph as follows. |
| 467 | 467 |
///\code |
| 468 | 468 |
/// int count=0; |
| 469 | 469 |
/// for (Digraph::InArcIt a(g, n); a!=INVALID; ++a) ++count; |
| 470 | 470 |
///\endcode |
| 471 | 471 |
class InArcIt : public Arc {
|
| 472 | 472 |
public: |
| 473 | 473 |
/// Default constructor |
| 474 | 474 |
|
| 475 | 475 |
/// Default constructor. |
| 476 | 476 |
/// \warning It sets the iterator to an undefined value. |
| 477 | 477 |
InArcIt() { }
|
| 478 | 478 |
/// Copy constructor. |
| 479 | 479 |
|
| 480 | 480 |
/// Copy constructor. |
| 481 | 481 |
/// |
| 482 | 482 |
InArcIt(const InArcIt& e) : Arc(e) { }
|
| 483 | 483 |
/// %Invalid constructor \& conversion. |
| 484 | 484 |
|
| 485 | 485 |
/// Initializes the iterator to be invalid. |
| 486 | 486 |
/// \sa Invalid for more details. |
| 487 | 487 |
InArcIt(Invalid) { }
|
| 488 | 488 |
/// Sets the iterator to the first incoming arc. |
| ... | ... |
@@ -566,62 +566,62 @@ |
| 566 | 566 |
{
|
| 567 | 567 |
public: |
| 568 | 568 |
|
| 569 | 569 |
/// Constructor |
| 570 | 570 |
explicit EdgeMap(const Graph&) { }
|
| 571 | 571 |
/// Constructor with given initial value |
| 572 | 572 |
EdgeMap(const Graph&, T) { }
|
| 573 | 573 |
|
| 574 | 574 |
private: |
| 575 | 575 |
///Copy constructor |
| 576 | 576 |
EdgeMap(const EdgeMap& em) : |
| 577 | 577 |
ReferenceMap<Edge, T, T&, const T&>(em) {}
|
| 578 | 578 |
///Assignment operator |
| 579 | 579 |
template <typename CMap> |
| 580 | 580 |
EdgeMap& operator=(const CMap&) {
|
| 581 | 581 |
checkConcept<ReadMap<Edge, T>, CMap>(); |
| 582 | 582 |
return *this; |
| 583 | 583 |
} |
| 584 | 584 |
}; |
| 585 | 585 |
|
| 586 | 586 |
/// \brief The first node of the edge. |
| 587 | 587 |
/// |
| 588 | 588 |
/// Returns the first node of the given edge. |
| 589 | 589 |
/// |
| 590 |
/// Edges don't have source and target nodes, however methods |
|
| 590 |
/// Edges don't have source and target nodes, however, methods |
|
| 591 | 591 |
/// u() and v() are used to query the two end-nodes of an edge. |
| 592 | 592 |
/// The orientation of an edge that arises this way is called |
| 593 | 593 |
/// the inherent direction, it is used to define the default |
| 594 | 594 |
/// direction for the corresponding arcs. |
| 595 | 595 |
/// \sa v() |
| 596 | 596 |
/// \sa direction() |
| 597 | 597 |
Node u(Edge) const { return INVALID; }
|
| 598 | 598 |
|
| 599 | 599 |
/// \brief The second node of the edge. |
| 600 | 600 |
/// |
| 601 | 601 |
/// Returns the second node of the given edge. |
| 602 | 602 |
/// |
| 603 |
/// Edges don't have source and target nodes, however methods |
|
| 603 |
/// Edges don't have source and target nodes, however, methods |
|
| 604 | 604 |
/// u() and v() are used to query the two end-nodes of an edge. |
| 605 | 605 |
/// The orientation of an edge that arises this way is called |
| 606 | 606 |
/// the inherent direction, it is used to define the default |
| 607 | 607 |
/// direction for the corresponding arcs. |
| 608 | 608 |
/// \sa u() |
| 609 | 609 |
/// \sa direction() |
| 610 | 610 |
Node v(Edge) const { return INVALID; }
|
| 611 | 611 |
|
| 612 | 612 |
/// \brief The source node of the arc. |
| 613 | 613 |
/// |
| 614 | 614 |
/// Returns the source node of the given arc. |
| 615 | 615 |
Node source(Arc) const { return INVALID; }
|
| 616 | 616 |
|
| 617 | 617 |
/// \brief The target node of the arc. |
| 618 | 618 |
/// |
| 619 | 619 |
/// Returns the target node of the given arc. |
| 620 | 620 |
Node target(Arc) const { return INVALID; }
|
| 621 | 621 |
|
| 622 | 622 |
/// \brief The ID of the node. |
| 623 | 623 |
/// |
| 624 | 624 |
/// Returns the ID of the given node. |
| 625 | 625 |
int id(Node) const { return -1; }
|
| 626 | 626 |
|
| 627 | 627 |
/// \brief The ID of the edge. |
| 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 | 5 |
* Copyright (C) 2003-2009 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
///\ingroup graph_concepts |
| 20 | 20 |
///\file |
| 21 |
///\brief The |
|
| 21 |
///\brief The concepts of graph components. |
|
| 22 | 22 |
|
| 23 | 23 |
#ifndef LEMON_CONCEPTS_GRAPH_COMPONENTS_H |
| 24 | 24 |
#define LEMON_CONCEPTS_GRAPH_COMPONENTS_H |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/core.h> |
| 27 | 27 |
#include <lemon/concepts/maps.h> |
| 28 | 28 |
|
| 29 | 29 |
#include <lemon/bits/alteration_notifier.h> |
| 30 | 30 |
|
| 31 | 31 |
namespace lemon {
|
| 32 | 32 |
namespace concepts {
|
| 33 | 33 |
|
| 34 | 34 |
/// \brief Concept class for \c Node, \c Arc and \c Edge types. |
| 35 | 35 |
/// |
| 36 | 36 |
/// This class describes the concept of \c Node, \c Arc and \c Edge |
| 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 | 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'> |
| ... | ... |
@@ -191,49 +191,49 @@ |
| 191 | 191 |
Counter &operator++() { count++; return *this;}
|
| 192 | 192 |
///\e |
| 193 | 193 |
int operator++(int) { return count++;}
|
| 194 | 194 |
///\e |
| 195 | 195 |
Counter &operator--() { count--; return *this;}
|
| 196 | 196 |
///\e |
| 197 | 197 |
int operator--(int) { return count--;}
|
| 198 | 198 |
///\e |
| 199 | 199 |
Counter &operator+=(int c) { count+=c; return *this;}
|
| 200 | 200 |
///\e |
| 201 | 201 |
Counter &operator-=(int c) { count-=c; return *this;}
|
| 202 | 202 |
/// Resets the counter to the given value. |
| 203 | 203 |
|
| 204 | 204 |
/// Resets the counter to the given value. |
| 205 | 205 |
/// \note This function does not reset the values of |
| 206 | 206 |
/// \ref SubCounter "SubCounter"s but it resets \ref NoSubCounter |
| 207 | 207 |
/// "NoSubCounter"s along with the main counter. |
| 208 | 208 |
void reset(int c=0) {count=c;}
|
| 209 | 209 |
/// Returns the value of the counter. |
| 210 | 210 |
operator int() {return count;}
|
| 211 | 211 |
}; |
| 212 | 212 |
|
| 213 | 213 |
/// 'Do nothing' version of Counter. |
| 214 | 214 |
|
| 215 |
/// This class can be used in the same way as \ref Counter |
|
| 215 |
/// This class can be used in the same way as \ref Counter, but it |
|
| 216 | 216 |
/// does not count at all and does not print report on destruction. |
| 217 | 217 |
/// |
| 218 | 218 |
/// Replacing a \ref Counter with a \ref NoCounter makes it possible |
| 219 | 219 |
/// to turn off all counting and reporting (SubCounters should also |
| 220 | 220 |
/// be replaced with NoSubCounters), so it does not affect the |
| 221 | 221 |
/// efficiency of the program at all. |
| 222 | 222 |
/// |
| 223 | 223 |
/// \sa Counter |
| 224 | 224 |
class NoCounter |
| 225 | 225 |
{
|
| 226 | 226 |
public: |
| 227 | 227 |
typedef _NoSubCounter<NoCounter> SubCounter; |
| 228 | 228 |
typedef _NoSubCounter<NoCounter> NoSubCounter; |
| 229 | 229 |
|
| 230 | 230 |
NoCounter() {}
|
| 231 | 231 |
NoCounter(std::string,std::ostream &) {}
|
| 232 | 232 |
NoCounter(const char *,std::ostream &) {}
|
| 233 | 233 |
NoCounter(std::string) {}
|
| 234 | 234 |
NoCounter(const char *) {}
|
| 235 | 235 |
NoCounter &operator++() { return *this; }
|
| 236 | 236 |
int operator++(int) { return 0; }
|
| 237 | 237 |
NoCounter &operator--() { return *this; }
|
| 238 | 238 |
int operator--(int) { return 0; }
|
| 239 | 239 |
NoCounter &operator+=(int) { return *this;}
|
| ... | ... |
@@ -42,49 +42,49 @@ |
| 42 | 42 |
///The type of the digraph the algorithm runs on. |
| 43 | 43 |
typedef GR Digraph; |
| 44 | 44 |
|
| 45 | 45 |
///\brief The type of the map that stores the predecessor |
| 46 | 46 |
///arcs of the %DFS paths. |
| 47 | 47 |
/// |
| 48 | 48 |
///The type of the map that stores the predecessor |
| 49 | 49 |
///arcs of the %DFS paths. |
| 50 | 50 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 51 | 51 |
typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; |
| 52 | 52 |
///Instantiates a \c PredMap. |
| 53 | 53 |
|
| 54 | 54 |
///This function instantiates a \ref PredMap. |
| 55 | 55 |
///\param g is the digraph, to which we would like to define the |
| 56 | 56 |
///\ref PredMap. |
| 57 | 57 |
static PredMap *createPredMap(const Digraph &g) |
| 58 | 58 |
{
|
| 59 | 59 |
return new PredMap(g); |
| 60 | 60 |
} |
| 61 | 61 |
|
| 62 | 62 |
///The type of the map that indicates which nodes are processed. |
| 63 | 63 |
|
| 64 | 64 |
///The type of the map that indicates which nodes are processed. |
| 65 | 65 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 66 |
///By default it is a NullMap. |
|
| 66 |
///By default, it is a NullMap. |
|
| 67 | 67 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
| 68 | 68 |
///Instantiates a \c ProcessedMap. |
| 69 | 69 |
|
| 70 | 70 |
///This function instantiates a \ref ProcessedMap. |
| 71 | 71 |
///\param g is the digraph, to which |
| 72 | 72 |
///we would like to define the \ref ProcessedMap. |
| 73 | 73 |
#ifdef DOXYGEN |
| 74 | 74 |
static ProcessedMap *createProcessedMap(const Digraph &g) |
| 75 | 75 |
#else |
| 76 | 76 |
static ProcessedMap *createProcessedMap(const Digraph &) |
| 77 | 77 |
#endif |
| 78 | 78 |
{
|
| 79 | 79 |
return new ProcessedMap(); |
| 80 | 80 |
} |
| 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 | 85 |
///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
| 86 | 86 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
| 87 | 87 |
///Instantiates a \c ReachedMap. |
| 88 | 88 |
|
| 89 | 89 |
///This function instantiates a \ref ReachedMap. |
| 90 | 90 |
///\param g is the digraph, to which |
| ... | ... |
@@ -761,49 +761,49 @@ |
| 761 | 761 |
///The type of the digraph the algorithm runs on. |
| 762 | 762 |
typedef GR Digraph; |
| 763 | 763 |
|
| 764 | 764 |
///\brief The type of the map that stores the predecessor |
| 765 | 765 |
///arcs of the %DFS paths. |
| 766 | 766 |
/// |
| 767 | 767 |
///The type of the map that stores the predecessor |
| 768 | 768 |
///arcs of the %DFS paths. |
| 769 | 769 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 770 | 770 |
typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; |
| 771 | 771 |
///Instantiates a PredMap. |
| 772 | 772 |
|
| 773 | 773 |
///This function instantiates a PredMap. |
| 774 | 774 |
///\param g is the digraph, to which we would like to define the |
| 775 | 775 |
///PredMap. |
| 776 | 776 |
static PredMap *createPredMap(const Digraph &g) |
| 777 | 777 |
{
|
| 778 | 778 |
return new PredMap(g); |
| 779 | 779 |
} |
| 780 | 780 |
|
| 781 | 781 |
///The type of the map that indicates which nodes are processed. |
| 782 | 782 |
|
| 783 | 783 |
///The type of the map that indicates which nodes are processed. |
| 784 | 784 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 785 |
///By default it is a NullMap. |
|
| 785 |
///By default, it is a NullMap. |
|
| 786 | 786 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
| 787 | 787 |
///Instantiates a ProcessedMap. |
| 788 | 788 |
|
| 789 | 789 |
///This function instantiates a ProcessedMap. |
| 790 | 790 |
///\param g is the digraph, to which |
| 791 | 791 |
///we would like to define the ProcessedMap. |
| 792 | 792 |
#ifdef DOXYGEN |
| 793 | 793 |
static ProcessedMap *createProcessedMap(const Digraph &g) |
| 794 | 794 |
#else |
| 795 | 795 |
static ProcessedMap *createProcessedMap(const Digraph &) |
| 796 | 796 |
#endif |
| 797 | 797 |
{
|
| 798 | 798 |
return new ProcessedMap(); |
| 799 | 799 |
} |
| 800 | 800 |
|
| 801 | 801 |
///The type of the map that indicates which nodes are reached. |
| 802 | 802 |
|
| 803 | 803 |
///The type of the map that indicates which nodes are reached. |
| 804 | 804 |
///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
| 805 | 805 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
| 806 | 806 |
///Instantiates a ReachedMap. |
| 807 | 807 |
|
| 808 | 808 |
///This function instantiates a ReachedMap. |
| 809 | 809 |
///\param g is the digraph, to which |
| ... | ... |
@@ -111,49 +111,49 @@ |
| 111 | 111 |
return new Heap(r); |
| 112 | 112 |
} |
| 113 | 113 |
|
| 114 | 114 |
///\brief The type of the map that stores the predecessor |
| 115 | 115 |
///arcs of the shortest paths. |
| 116 | 116 |
/// |
| 117 | 117 |
///The type of the map that stores the predecessor |
| 118 | 118 |
///arcs of the shortest paths. |
| 119 | 119 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 120 | 120 |
typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; |
| 121 | 121 |
///Instantiates a \c PredMap. |
| 122 | 122 |
|
| 123 | 123 |
///This function instantiates a \ref PredMap. |
| 124 | 124 |
///\param g is the digraph, to which we would like to define the |
| 125 | 125 |
///\ref PredMap. |
| 126 | 126 |
static PredMap *createPredMap(const Digraph &g) |
| 127 | 127 |
{
|
| 128 | 128 |
return new PredMap(g); |
| 129 | 129 |
} |
| 130 | 130 |
|
| 131 | 131 |
///The type of the map that indicates which nodes are processed. |
| 132 | 132 |
|
| 133 | 133 |
///The type of the map that indicates which nodes are processed. |
| 134 | 134 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 135 |
///By default it is a NullMap. |
|
| 135 |
///By default, it is a NullMap. |
|
| 136 | 136 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
| 137 | 137 |
///Instantiates a \c ProcessedMap. |
| 138 | 138 |
|
| 139 | 139 |
///This function instantiates a \ref ProcessedMap. |
| 140 | 140 |
///\param g is the digraph, to which |
| 141 | 141 |
///we would like to define the \ref ProcessedMap. |
| 142 | 142 |
#ifdef DOXYGEN |
| 143 | 143 |
static ProcessedMap *createProcessedMap(const Digraph &g) |
| 144 | 144 |
#else |
| 145 | 145 |
static ProcessedMap *createProcessedMap(const Digraph &) |
| 146 | 146 |
#endif |
| 147 | 147 |
{
|
| 148 | 148 |
return new ProcessedMap(); |
| 149 | 149 |
} |
| 150 | 150 |
|
| 151 | 151 |
///The type of the map that stores the distances of the nodes. |
| 152 | 152 |
|
| 153 | 153 |
///The type of the map that stores the distances of the nodes. |
| 154 | 154 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 155 | 155 |
typedef typename Digraph::template NodeMap<typename LEN::Value> DistMap; |
| 156 | 156 |
///Instantiates a \c DistMap. |
| 157 | 157 |
|
| 158 | 158 |
///This function instantiates a \ref DistMap. |
| 159 | 159 |
///\param g is the digraph, to which we would like to define |
| ... | ... |
@@ -405,70 +405,70 @@ |
| 405 | 405 |
typedef Dijkstra< Digraph, LengthMap, SetHeapTraits<H, CR> > Create; |
| 406 | 406 |
}; |
| 407 | 407 |
|
| 408 | 408 |
template <class H, class CR> |
| 409 | 409 |
struct SetStandardHeapTraits : public Traits {
|
| 410 | 410 |
typedef CR HeapCrossRef; |
| 411 | 411 |
typedef H Heap; |
| 412 | 412 |
static HeapCrossRef *createHeapCrossRef(const Digraph &G) {
|
| 413 | 413 |
return new HeapCrossRef(G); |
| 414 | 414 |
} |
| 415 | 415 |
static Heap *createHeap(HeapCrossRef &R) |
| 416 | 416 |
{
|
| 417 | 417 |
return new Heap(R); |
| 418 | 418 |
} |
| 419 | 419 |
}; |
| 420 | 420 |
///\brief \ref named-templ-param "Named parameter" for setting |
| 421 | 421 |
///heap and cross reference types with automatic allocation |
| 422 | 422 |
/// |
| 423 | 423 |
///\ref named-templ-param "Named parameter" for setting heap and cross |
| 424 | 424 |
///reference types with automatic allocation. |
| 425 | 425 |
///They should have standard constructor interfaces to be able to |
| 426 | 426 |
///automatically created by the algorithm (i.e. the digraph should be |
| 427 | 427 |
///passed to the constructor of the cross reference and the cross |
| 428 | 428 |
///reference should be passed to the constructor of the heap). |
| 429 |
///However external heap and cross reference objects could also be |
|
| 429 |
///However, external heap and cross reference objects could also be |
|
| 430 | 430 |
///passed to the algorithm using the \ref heap() function before |
| 431 | 431 |
///calling \ref run(Node) "run()" or \ref init(). |
| 432 | 432 |
///\sa SetHeap |
| 433 | 433 |
template <class H, class CR = typename Digraph::template NodeMap<int> > |
| 434 | 434 |
struct SetStandardHeap |
| 435 | 435 |
: public Dijkstra< Digraph, LengthMap, SetStandardHeapTraits<H, CR> > {
|
| 436 | 436 |
typedef Dijkstra< Digraph, LengthMap, SetStandardHeapTraits<H, CR> > |
| 437 | 437 |
Create; |
| 438 | 438 |
}; |
| 439 | 439 |
|
| 440 | 440 |
template <class T> |
| 441 | 441 |
struct SetOperationTraitsTraits : public Traits {
|
| 442 | 442 |
typedef T OperationTraits; |
| 443 | 443 |
}; |
| 444 | 444 |
|
| 445 | 445 |
/// \brief \ref named-templ-param "Named parameter" for setting |
| 446 | 446 |
///\c OperationTraits type |
| 447 | 447 |
/// |
| 448 | 448 |
///\ref named-templ-param "Named parameter" for setting |
| 449 | 449 |
///\c OperationTraits type. |
| 450 |
/// For more information see \ref DijkstraDefaultOperationTraits. |
|
| 450 |
/// For more information, see \ref DijkstraDefaultOperationTraits. |
|
| 451 | 451 |
template <class T> |
| 452 | 452 |
struct SetOperationTraits |
| 453 | 453 |
: public Dijkstra<Digraph, LengthMap, SetOperationTraitsTraits<T> > {
|
| 454 | 454 |
typedef Dijkstra<Digraph, LengthMap, SetOperationTraitsTraits<T> > |
| 455 | 455 |
Create; |
| 456 | 456 |
}; |
| 457 | 457 |
|
| 458 | 458 |
///@} |
| 459 | 459 |
|
| 460 | 460 |
protected: |
| 461 | 461 |
|
| 462 | 462 |
Dijkstra() {}
|
| 463 | 463 |
|
| 464 | 464 |
public: |
| 465 | 465 |
|
| 466 | 466 |
///Constructor. |
| 467 | 467 |
|
| 468 | 468 |
///Constructor. |
| 469 | 469 |
///\param g The digraph the algorithm runs on. |
| 470 | 470 |
///\param length The length map used by the algorithm. |
| 471 | 471 |
Dijkstra(const Digraph& g, const LengthMap& length) : |
| 472 | 472 |
G(&g), _length(&length), |
| 473 | 473 |
_pred(NULL), local_pred(false), |
| 474 | 474 |
_dist(NULL), local_dist(false), |
| ... | ... |
@@ -975,49 +975,49 @@ |
| 975 | 975 |
return new Heap(r); |
| 976 | 976 |
} |
| 977 | 977 |
|
| 978 | 978 |
///\brief The type of the map that stores the predecessor |
| 979 | 979 |
///arcs of the shortest paths. |
| 980 | 980 |
/// |
| 981 | 981 |
///The type of the map that stores the predecessor |
| 982 | 982 |
///arcs of the shortest paths. |
| 983 | 983 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 984 | 984 |
typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; |
| 985 | 985 |
///Instantiates a PredMap. |
| 986 | 986 |
|
| 987 | 987 |
///This function instantiates a PredMap. |
| 988 | 988 |
///\param g is the digraph, to which we would like to define the |
| 989 | 989 |
///PredMap. |
| 990 | 990 |
static PredMap *createPredMap(const Digraph &g) |
| 991 | 991 |
{
|
| 992 | 992 |
return new PredMap(g); |
| 993 | 993 |
} |
| 994 | 994 |
|
| 995 | 995 |
///The type of the map that indicates which nodes are processed. |
| 996 | 996 |
|
| 997 | 997 |
///The type of the map that indicates which nodes are processed. |
| 998 | 998 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 999 |
///By default it is a NullMap. |
|
| 999 |
///By default, it is a NullMap. |
|
| 1000 | 1000 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
| 1001 | 1001 |
///Instantiates a ProcessedMap. |
| 1002 | 1002 |
|
| 1003 | 1003 |
///This function instantiates a ProcessedMap. |
| 1004 | 1004 |
///\param g is the digraph, to which |
| 1005 | 1005 |
///we would like to define the ProcessedMap. |
| 1006 | 1006 |
#ifdef DOXYGEN |
| 1007 | 1007 |
static ProcessedMap *createProcessedMap(const Digraph &g) |
| 1008 | 1008 |
#else |
| 1009 | 1009 |
static ProcessedMap *createProcessedMap(const Digraph &) |
| 1010 | 1010 |
#endif |
| 1011 | 1011 |
{
|
| 1012 | 1012 |
return new ProcessedMap(); |
| 1013 | 1013 |
} |
| 1014 | 1014 |
|
| 1015 | 1015 |
///The type of the map that stores the distances of the nodes. |
| 1016 | 1016 |
|
| 1017 | 1017 |
///The type of the map that stores the distances of the nodes. |
| 1018 | 1018 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 1019 | 1019 |
typedef typename Digraph::template NodeMap<typename LEN::Value> DistMap; |
| 1020 | 1020 |
///Instantiates a DistMap. |
| 1021 | 1021 |
|
| 1022 | 1022 |
///This function instantiates a DistMap. |
| 1023 | 1023 |
///\param g is the digraph, to which we would like to define |
| ... | ... |
@@ -273,53 +273,51 @@ |
| 273 | 273 |
sn = (*_pred)[sn]; |
| 274 | 274 |
} |
| 275 | 275 |
} |
| 276 | 276 |
return value; |
| 277 | 277 |
} |
| 278 | 278 |
|
| 279 | 279 |
/// \brief Return the minimum cut between two nodes |
| 280 | 280 |
/// |
| 281 | 281 |
/// This function returns the minimum cut between the nodes \c s and \c t |
| 282 | 282 |
/// in the \c cutMap parameter by setting the nodes in the component of |
| 283 | 283 |
/// \c s to \c true and the other nodes to \c false. |
| 284 | 284 |
/// |
| 285 | 285 |
/// For higher level interfaces see MinCutNodeIt and MinCutEdgeIt. |
| 286 | 286 |
/// |
| 287 | 287 |
/// \param s The base node. |
| 288 | 288 |
/// \param t The node you want to separate from node \c s. |
| 289 | 289 |
/// \param cutMap The cut will be returned in this map. |
| 290 | 290 |
/// It must be a \c bool (or convertible) \ref concepts::ReadWriteMap |
| 291 | 291 |
/// "ReadWriteMap" on the graph nodes. |
| 292 | 292 |
/// |
| 293 | 293 |
/// \return The value of the minimum cut between \c s and \c t. |
| 294 | 294 |
/// |
| 295 | 295 |
/// \pre \ref run() must be called before using this function. |
| 296 | 296 |
template <typename CutMap> |
| 297 |
Value minCutMap(const Node& s, |
|
| 297 |
Value minCutMap(const Node& s, |
|
| 298 | 298 |
const Node& t, |
| 299 |
///< |
|
| 300 | 299 |
CutMap& cutMap |
| 301 |
///< |
|
| 302 | 300 |
) const {
|
| 303 | 301 |
Node sn = s, tn = t; |
| 304 | 302 |
bool s_root=false; |
| 305 | 303 |
Node rn = INVALID; |
| 306 | 304 |
Value value = std::numeric_limits<Value>::max(); |
| 307 | 305 |
|
| 308 | 306 |
while (sn != tn) {
|
| 309 | 307 |
if ((*_order)[sn] < (*_order)[tn]) {
|
| 310 | 308 |
if ((*_weight)[tn] <= value) {
|
| 311 | 309 |
rn = tn; |
| 312 | 310 |
s_root = false; |
| 313 | 311 |
value = (*_weight)[tn]; |
| 314 | 312 |
} |
| 315 | 313 |
tn = (*_pred)[tn]; |
| 316 | 314 |
} else {
|
| 317 | 315 |
if ((*_weight)[sn] <= value) {
|
| 318 | 316 |
rn = sn; |
| 319 | 317 |
s_root = true; |
| 320 | 318 |
value = (*_weight)[sn]; |
| 321 | 319 |
} |
| 322 | 320 |
sn = (*_pred)[sn]; |
| 323 | 321 |
} |
| 324 | 322 |
} |
| 325 | 323 |
|
| ... | ... |
@@ -373,49 +371,49 @@ |
| 373 | 371 |
/// Constructor |
| 374 | 372 |
|
| 375 | 373 |
/// Constructor. |
| 376 | 374 |
/// |
| 377 | 375 |
MinCutNodeIt(GomoryHu const &gomory, |
| 378 | 376 |
///< The GomoryHu class. You must call its |
| 379 | 377 |
/// run() method |
| 380 | 378 |
/// before initializing this iterator. |
| 381 | 379 |
const Node& s, ///< The base node. |
| 382 | 380 |
const Node& t, |
| 383 | 381 |
///< The node you want to separate from node \c s. |
| 384 | 382 |
bool side=true |
| 385 | 383 |
///< If it is \c true (default) then the iterator lists |
| 386 | 384 |
/// the nodes of the component containing \c s, |
| 387 | 385 |
/// otherwise it lists the other component. |
| 388 | 386 |
/// \note As the minimum cut is not always unique, |
| 389 | 387 |
/// \code |
| 390 | 388 |
/// MinCutNodeIt(gomory, s, t, true); |
| 391 | 389 |
/// \endcode |
| 392 | 390 |
/// and |
| 393 | 391 |
/// \code |
| 394 | 392 |
/// MinCutNodeIt(gomory, t, s, false); |
| 395 | 393 |
/// \endcode |
| 396 | 394 |
/// does not necessarily give the same set of nodes. |
| 397 |
/// However it is ensured that |
|
| 395 |
/// However, it is ensured that |
|
| 398 | 396 |
/// \code |
| 399 | 397 |
/// MinCutNodeIt(gomory, s, t, true); |
| 400 | 398 |
/// \endcode |
| 401 | 399 |
/// and |
| 402 | 400 |
/// \code |
| 403 | 401 |
/// MinCutNodeIt(gomory, s, t, false); |
| 404 | 402 |
/// \endcode |
| 405 | 403 |
/// together list each node exactly once. |
| 406 | 404 |
) |
| 407 | 405 |
: _side(side), _cut(gomory._graph) |
| 408 | 406 |
{
|
| 409 | 407 |
gomory.minCutMap(s,t,_cut); |
| 410 | 408 |
for(_node_it=typename Graph::NodeIt(gomory._graph); |
| 411 | 409 |
_node_it!=INVALID && _cut[_node_it]!=_side; |
| 412 | 410 |
++_node_it) {}
|
| 413 | 411 |
} |
| 414 | 412 |
/// Conversion to \c Node |
| 415 | 413 |
|
| 416 | 414 |
/// Conversion to \c Node. |
| 417 | 415 |
/// |
| 418 | 416 |
operator typename Graph::Node() const |
| 419 | 417 |
{
|
| 420 | 418 |
return _node_it; |
| 421 | 419 |
} |
| ... | ... |
@@ -121,49 +121,49 @@ |
| 121 | 121 |
|
| 122 | 122 |
bool _scaleToA4; |
| 123 | 123 |
|
| 124 | 124 |
std::string _title; |
| 125 | 125 |
std::string _copyright; |
| 126 | 126 |
|
| 127 | 127 |
enum NodeTextColorType |
| 128 | 128 |
{ DIST_COL=0, DIST_BW=1, CUST_COL=2, SAME_COL=3 } _nodeTextColorType;
|
| 129 | 129 |
ConstMap<typename Graph::Node,Color > _nodeTextColors; |
| 130 | 130 |
|
| 131 | 131 |
bool _autoNodeScale; |
| 132 | 132 |
bool _autoArcWidthScale; |
| 133 | 133 |
|
| 134 | 134 |
bool _absoluteNodeSizes; |
| 135 | 135 |
bool _absoluteArcWidths; |
| 136 | 136 |
|
| 137 | 137 |
bool _negY; |
| 138 | 138 |
|
| 139 | 139 |
bool _preScale; |
| 140 | 140 |
///Constructor |
| 141 | 141 |
|
| 142 | 142 |
///Constructor |
| 143 | 143 |
///\param gr Reference to the graph to be printed. |
| 144 | 144 |
///\param ost Reference to the output stream. |
| 145 |
///By default it is <tt>std::cout</tt>. |
|
| 145 |
///By default, it is <tt>std::cout</tt>. |
|
| 146 | 146 |
///\param pros If it is \c true, then the \c ostream referenced by \c os |
| 147 | 147 |
///will be explicitly deallocated by the destructor. |
| 148 | 148 |
DefaultGraphToEpsTraits(const GR &gr, std::ostream& ost = std::cout, |
| 149 | 149 |
bool pros = false) : |
| 150 | 150 |
g(gr), os(ost), |
| 151 | 151 |
_coords(dim2::Point<double>(1,1)), _nodeSizes(1), _nodeShapes(0), |
| 152 | 152 |
_nodeColors(WHITE), _arcColors(BLACK), |
| 153 | 153 |
_arcWidths(1.0), _arcWidthScale(0.003), |
| 154 | 154 |
_nodeScale(.01), _xBorder(10), _yBorder(10), _scale(1.0), |
| 155 | 155 |
_nodeBorderQuotient(.1), |
| 156 | 156 |
_drawArrows(false), _arrowLength(1), _arrowWidth(0.3), |
| 157 | 157 |
_showNodes(true), _showArcs(true), |
| 158 | 158 |
_enableParallel(false), _parArcDist(1), |
| 159 | 159 |
_showNodeText(false), _nodeTexts(false), _nodeTextSize(1), |
| 160 | 160 |
_showNodePsText(false), _nodePsTexts(false), _nodePsTextsPreamble(0), |
| 161 | 161 |
_undirected(lemon::UndirectedTagIndicator<GR>::value), |
| 162 | 162 |
_pleaseRemoveOsStream(pros), _scaleToA4(false), |
| 163 | 163 |
_nodeTextColorType(SAME_COL), _nodeTextColors(BLACK), |
| 164 | 164 |
_autoNodeScale(false), |
| 165 | 165 |
_autoArcWidthScale(false), |
| 166 | 166 |
_absoluteNodeSizes(false), |
| 167 | 167 |
_absoluteArcWidths(false), |
| 168 | 168 |
_negY(false), |
| 169 | 169 |
_preScale(true) |
| ... | ... |
@@ -491,49 +491,49 @@ |
| 491 | 491 |
/// |
| 492 | 492 |
///\sa nodeScale() |
| 493 | 493 |
/// |
| 494 | 494 |
GraphToEps<T> &autoNodeScale(bool b=true) {
|
| 495 | 495 |
_autoNodeScale=b;return *this; |
| 496 | 496 |
} |
| 497 | 497 |
|
| 498 | 498 |
///Turns on/off the absolutematic node size scaling. |
| 499 | 499 |
|
| 500 | 500 |
///Turns on/off the absolutematic node size scaling. |
| 501 | 501 |
/// |
| 502 | 502 |
///\sa nodeScale() |
| 503 | 503 |
/// |
| 504 | 504 |
GraphToEps<T> &absoluteNodeSizes(bool b=true) {
|
| 505 | 505 |
_absoluteNodeSizes=b;return *this; |
| 506 | 506 |
} |
| 507 | 507 |
|
| 508 | 508 |
///Negates the Y coordinates. |
| 509 | 509 |
GraphToEps<T> &negateY(bool b=true) {
|
| 510 | 510 |
_negY=b;return *this; |
| 511 | 511 |
} |
| 512 | 512 |
|
| 513 | 513 |
///Turn on/off pre-scaling |
| 514 | 514 |
|
| 515 |
///By default graphToEps() rescales the whole image in order to avoid |
|
| 515 |
///By default, graphToEps() rescales the whole image in order to avoid |
|
| 516 | 516 |
///very big or very small bounding boxes. |
| 517 | 517 |
/// |
| 518 | 518 |
///This (p)rescaling can be turned off with this function. |
| 519 | 519 |
/// |
| 520 | 520 |
GraphToEps<T> &preScale(bool b=true) {
|
| 521 | 521 |
_preScale=b;return *this; |
| 522 | 522 |
} |
| 523 | 523 |
|
| 524 | 524 |
///Sets a global scale factor for arc widths |
| 525 | 525 |
|
| 526 | 526 |
/// Sets a global scale factor for arc widths. |
| 527 | 527 |
/// |
| 528 | 528 |
/// If arcWidths() is not given, this function simply sets the arc |
| 529 | 529 |
/// widths to \c d. If arcWidths() is given, but |
| 530 | 530 |
/// autoArcWidthScale() is not, then the arc withs given by |
| 531 | 531 |
/// arcWidths() will be multiplied by the value \c d. |
| 532 | 532 |
/// If both arcWidths() and autoArcWidthScale() are used, then the |
| 533 | 533 |
/// arc withs will be scaled in such a way that the greatest width will be |
| 534 | 534 |
/// equal to \c d. |
| 535 | 535 |
GraphToEps<T> &arcWidthScale(double d=.003) {_arcWidthScale=d;return *this;}
|
| 536 | 536 |
///Turns on/off the automatic arc width scaling. |
| 537 | 537 |
|
| 538 | 538 |
///Turns on/off the automatic arc width scaling. |
| 539 | 539 |
/// |
| ... | ... |
@@ -1093,61 +1093,61 @@ |
| 1093 | 1093 |
GraphToEps<T> &parEdgeDist(double d) {return parArcDist(d);}
|
| 1094 | 1094 |
|
| 1095 | 1095 |
///An alias for hideArcs() |
| 1096 | 1096 |
GraphToEps<T> &hideEdges(bool b=true) {return hideArcs(b);}
|
| 1097 | 1097 |
|
| 1098 | 1098 |
///@} |
| 1099 | 1099 |
}; |
| 1100 | 1100 |
|
| 1101 | 1101 |
template<class T> |
| 1102 | 1102 |
const int GraphToEps<T>::INTERPOL_PREC = 20; |
| 1103 | 1103 |
template<class T> |
| 1104 | 1104 |
const double GraphToEps<T>::A4HEIGHT = 841.8897637795276; |
| 1105 | 1105 |
template<class T> |
| 1106 | 1106 |
const double GraphToEps<T>::A4WIDTH = 595.275590551181; |
| 1107 | 1107 |
template<class T> |
| 1108 | 1108 |
const double GraphToEps<T>::A4BORDER = 15; |
| 1109 | 1109 |
|
| 1110 | 1110 |
|
| 1111 | 1111 |
///Generates an EPS file from a graph |
| 1112 | 1112 |
|
| 1113 | 1113 |
///\ingroup eps_io |
| 1114 | 1114 |
///Generates an EPS file from a graph. |
| 1115 | 1115 |
///\param g Reference to the graph to be printed. |
| 1116 | 1116 |
///\param os Reference to the output stream. |
| 1117 |
///By default it is <tt>std::cout</tt>. |
|
| 1117 |
///By default, it is <tt>std::cout</tt>. |
|
| 1118 | 1118 |
/// |
| 1119 | 1119 |
///This function also has a lot of |
| 1120 | 1120 |
///\ref named-templ-func-param "named parameters", |
| 1121 | 1121 |
///they are declared as the members of class \ref GraphToEps. The following |
| 1122 | 1122 |
///example shows how to use these parameters. |
| 1123 | 1123 |
///\code |
| 1124 | 1124 |
/// graphToEps(g,os).scale(10).coords(coords) |
| 1125 | 1125 |
/// .nodeScale(2).nodeSizes(sizes) |
| 1126 | 1126 |
/// .arcWidthScale(.4).run(); |
| 1127 | 1127 |
///\endcode |
| 1128 | 1128 |
/// |
| 1129 |
///For more detailed examples see the \ref graph_to_eps_demo.cc demo file. |
|
| 1129 |
///For more detailed examples, see the \ref graph_to_eps_demo.cc demo file. |
|
| 1130 | 1130 |
/// |
| 1131 | 1131 |
///\warning Don't forget to put the \ref GraphToEps::run() "run()" |
| 1132 | 1132 |
///to the end of the parameter list. |
| 1133 | 1133 |
///\sa GraphToEps |
| 1134 | 1134 |
///\sa graphToEps(GR &g, const char *file_name) |
| 1135 | 1135 |
template<class GR> |
| 1136 | 1136 |
GraphToEps<DefaultGraphToEpsTraits<GR> > |
| 1137 | 1137 |
graphToEps(GR &g, std::ostream& os=std::cout) |
| 1138 | 1138 |
{
|
| 1139 | 1139 |
return |
| 1140 | 1140 |
GraphToEps<DefaultGraphToEpsTraits<GR> >(DefaultGraphToEpsTraits<GR>(g,os)); |
| 1141 | 1141 |
} |
| 1142 | 1142 |
|
| 1143 | 1143 |
///Generates an EPS file from a graph |
| 1144 | 1144 |
|
| 1145 | 1145 |
///\ingroup eps_io |
| 1146 | 1146 |
///This function does the same as |
| 1147 | 1147 |
///\ref graphToEps(GR &g,std::ostream& os) |
| 1148 | 1148 |
///but it writes its output into the file \c file_name |
| 1149 | 1149 |
///instead of a stream. |
| 1150 | 1150 |
///\sa graphToEps(GR &g, std::ostream& os) |
| 1151 | 1151 |
template<class GR> |
| 1152 | 1152 |
GraphToEps<DefaultGraphToEpsTraits<GR> > |
| 1153 | 1153 |
graphToEps(GR &g,const char *file_name) |
| ... | ... |
@@ -266,49 +266,49 @@ |
| 266 | 266 |
return node._id; |
| 267 | 267 |
} |
| 268 | 268 |
|
| 269 | 269 |
Node operator()(int ix) const {
|
| 270 | 270 |
return Node(ix); |
| 271 | 271 |
} |
| 272 | 272 |
|
| 273 | 273 |
private: |
| 274 | 274 |
int _dim; |
| 275 | 275 |
int _node_num, _edge_num; |
| 276 | 276 |
}; |
| 277 | 277 |
|
| 278 | 278 |
|
| 279 | 279 |
typedef GraphExtender<HypercubeGraphBase> ExtendedHypercubeGraphBase; |
| 280 | 280 |
|
| 281 | 281 |
/// \ingroup graphs |
| 282 | 282 |
/// |
| 283 | 283 |
/// \brief Hypercube graph class |
| 284 | 284 |
/// |
| 285 | 285 |
/// HypercubeGraph implements a special graph type. The nodes of the |
| 286 | 286 |
/// graph are indexed with integers having at most \c dim binary digits. |
| 287 | 287 |
/// Two nodes are connected in the graph if and only if their indices |
| 288 | 288 |
/// differ only on one position in the binary form. |
| 289 | 289 |
/// This class is completely static and it needs constant memory space. |
| 290 |
/// Thus you can neither add nor delete nodes or edges, however |
|
| 290 |
/// Thus you can neither add nor delete nodes or edges, however, |
|
| 291 | 291 |
/// the structure can be resized using resize(). |
| 292 | 292 |
/// |
| 293 | 293 |
/// This type fully conforms to the \ref concepts::Graph "Graph concept". |
| 294 | 294 |
/// Most of its member functions and nested classes are documented |
| 295 | 295 |
/// only in the concept class. |
| 296 | 296 |
/// |
| 297 | 297 |
/// \note The type of the indices is chosen to \c int for efficiency |
| 298 | 298 |
/// reasons. Thus the maximum dimension of this implementation is 26 |
| 299 | 299 |
/// (assuming that the size of \c int is 32 bit). |
| 300 | 300 |
class HypercubeGraph : public ExtendedHypercubeGraphBase {
|
| 301 | 301 |
typedef ExtendedHypercubeGraphBase Parent; |
| 302 | 302 |
|
| 303 | 303 |
public: |
| 304 | 304 |
|
| 305 | 305 |
/// \brief Constructs a hypercube graph with \c dim dimensions. |
| 306 | 306 |
/// |
| 307 | 307 |
/// Constructs a hypercube graph with \c dim dimensions. |
| 308 | 308 |
HypercubeGraph(int dim) { construct(dim); }
|
| 309 | 309 |
|
| 310 | 310 |
/// \brief Resizes the graph |
| 311 | 311 |
/// |
| 312 | 312 |
/// This function resizes the graph. It fully destroys and |
| 313 | 313 |
/// rebuilds the structure, therefore the maps of the graph will be |
| 314 | 314 |
/// reallocated automatically and the previous values will be lost. |
| ... | ... |
@@ -406,49 +406,49 @@ |
| 406 | 406 |
/// The reading method does a batch processing. The user creates a |
| 407 | 407 |
/// reader object, then various reading rules can be added to the |
| 408 | 408 |
/// reader, and eventually the reading is executed with the \c run() |
| 409 | 409 |
/// member function. A map reading rule can be added to the reader |
| 410 | 410 |
/// with the \c nodeMap() or \c arcMap() members. An optional |
| 411 | 411 |
/// converter parameter can also be added as a standard functor |
| 412 | 412 |
/// converting from \c std::string to the value type of the map. If it |
| 413 | 413 |
/// is set, it will determine how the tokens in the file should be |
| 414 | 414 |
/// converted to the value type of the map. If the functor is not set, |
| 415 | 415 |
/// then a default conversion will be used. One map can be read into |
| 416 | 416 |
/// multiple map objects at the same time. The \c attribute(), \c |
| 417 | 417 |
/// node() and \c arc() functions are used to add attribute reading |
| 418 | 418 |
/// rules. |
| 419 | 419 |
/// |
| 420 | 420 |
///\code |
| 421 | 421 |
/// DigraphReader<DGR>(digraph, std::cin). |
| 422 | 422 |
/// nodeMap("coordinates", coord_map).
|
| 423 | 423 |
/// arcMap("capacity", cap_map).
|
| 424 | 424 |
/// node("source", src).
|
| 425 | 425 |
/// node("target", trg).
|
| 426 | 426 |
/// attribute("caption", caption).
|
| 427 | 427 |
/// run(); |
| 428 | 428 |
///\endcode |
| 429 | 429 |
/// |
| 430 |
/// By default the reader uses the first section in the file of the |
|
| 430 |
/// By default, the reader uses the first section in the file of the |
|
| 431 | 431 |
/// proper type. If a section has an optional name, then it can be |
| 432 | 432 |
/// selected for reading by giving an optional name parameter to the |
| 433 | 433 |
/// \c nodes(), \c arcs() or \c attributes() functions. |
| 434 | 434 |
/// |
| 435 | 435 |
/// The \c useNodes() and \c useArcs() functions are used to tell the reader |
| 436 | 436 |
/// that the nodes or arcs should not be constructed (added to the |
| 437 | 437 |
/// graph) during the reading, but instead the label map of the items |
| 438 | 438 |
/// are given as a parameter of these functions. An |
| 439 | 439 |
/// application of these functions is multipass reading, which is |
| 440 | 440 |
/// important if two \c \@arcs sections must be read from the |
| 441 | 441 |
/// file. In this case the first phase would read the node set and one |
| 442 | 442 |
/// of the arc sets, while the second phase would read the second arc |
| 443 | 443 |
/// set into an \e ArcSet class (\c SmartArcSet or \c ListArcSet). |
| 444 | 444 |
/// The previously read label node map should be passed to the \c |
| 445 | 445 |
/// useNodes() functions. Another application of multipass reading when |
| 446 | 446 |
/// paths are given as a node map or an arc map. |
| 447 | 447 |
/// It is impossible to read this in |
| 448 | 448 |
/// a single pass, because the arcs are not constructed when the node |
| 449 | 449 |
/// maps are read. |
| 450 | 450 |
template <typename DGR> |
| 451 | 451 |
class DigraphReader {
|
| 452 | 452 |
public: |
| 453 | 453 |
|
| 454 | 454 |
typedef DGR Digraph; |
| ... | ... |
@@ -2200,49 +2200,49 @@ |
| 2200 | 2200 |
: _is(other._is), local_is(other.local_is) {
|
| 2201 | 2201 |
|
| 2202 | 2202 |
other._is = 0; |
| 2203 | 2203 |
other.local_is = false; |
| 2204 | 2204 |
|
| 2205 | 2205 |
_sections.swap(other._sections); |
| 2206 | 2206 |
} |
| 2207 | 2207 |
|
| 2208 | 2208 |
SectionReader& operator=(const SectionReader&); |
| 2209 | 2209 |
|
| 2210 | 2210 |
public: |
| 2211 | 2211 |
|
| 2212 | 2212 |
/// \name Section Readers |
| 2213 | 2213 |
/// @{
|
| 2214 | 2214 |
|
| 2215 | 2215 |
/// \brief Add a section processor with line oriented reading |
| 2216 | 2216 |
/// |
| 2217 | 2217 |
/// The first parameter is the type descriptor of the section, the |
| 2218 | 2218 |
/// second is a functor, which takes just one \c std::string |
| 2219 | 2219 |
/// parameter. At the reading process, each line of the section |
| 2220 | 2220 |
/// will be given to the functor object. However, the empty lines |
| 2221 | 2221 |
/// and the comment lines are filtered out, and the leading |
| 2222 | 2222 |
/// whitespaces are trimmed from each processed string. |
| 2223 | 2223 |
/// |
| 2224 |
/// For example let's see a section, which contain several |
|
| 2224 |
/// For example, let's see a section, which contain several |
|
| 2225 | 2225 |
/// integers, which should be inserted into a vector. |
| 2226 | 2226 |
///\code |
| 2227 | 2227 |
/// @numbers |
| 2228 | 2228 |
/// 12 45 23 |
| 2229 | 2229 |
/// 4 |
| 2230 | 2230 |
/// 23 6 |
| 2231 | 2231 |
///\endcode |
| 2232 | 2232 |
/// |
| 2233 | 2233 |
/// The functor is implemented as a struct: |
| 2234 | 2234 |
///\code |
| 2235 | 2235 |
/// struct NumberSection {
|
| 2236 | 2236 |
/// std::vector<int>& _data; |
| 2237 | 2237 |
/// NumberSection(std::vector<int>& data) : _data(data) {}
|
| 2238 | 2238 |
/// void operator()(const std::string& line) {
|
| 2239 | 2239 |
/// std::istringstream ls(line); |
| 2240 | 2240 |
/// int value; |
| 2241 | 2241 |
/// while (ls >> value) _data.push_back(value); |
| 2242 | 2242 |
/// } |
| 2243 | 2243 |
/// }; |
| 2244 | 2244 |
/// |
| 2245 | 2245 |
/// // ... |
| 2246 | 2246 |
/// |
| 2247 | 2247 |
/// reader.sectionLines("numbers", NumberSection(vec));
|
| 2248 | 2248 |
///\endcode |
| ... | ... |
@@ -370,61 +370,61 @@ |
| 370 | 370 |
|
| 371 | 371 |
/// Node validity check |
| 372 | 372 |
|
| 373 | 373 |
/// This function gives back \c true if the given node is valid, |
| 374 | 374 |
/// i.e. it is a real node of the digraph. |
| 375 | 375 |
/// |
| 376 | 376 |
/// \warning A removed node could become valid again if new nodes are |
| 377 | 377 |
/// added to the digraph. |
| 378 | 378 |
bool valid(Node n) const { return Parent::valid(n); }
|
| 379 | 379 |
|
| 380 | 380 |
/// Arc validity check |
| 381 | 381 |
|
| 382 | 382 |
/// This function gives back \c true if the given arc is valid, |
| 383 | 383 |
/// i.e. it is a real arc of the digraph. |
| 384 | 384 |
/// |
| 385 | 385 |
/// \warning A removed arc could become valid again if new arcs are |
| 386 | 386 |
/// added to the digraph. |
| 387 | 387 |
bool valid(Arc a) const { return Parent::valid(a); }
|
| 388 | 388 |
|
| 389 | 389 |
/// Change the target node of an arc |
| 390 | 390 |
|
| 391 | 391 |
/// This function changes the target node of the given arc \c a to \c n. |
| 392 | 392 |
/// |
| 393 | 393 |
///\note \c ArcIt and \c OutArcIt iterators referencing the changed |
| 394 |
///arc remain valid, |
|
| 394 |
///arc remain valid, but \c InArcIt iterators are invalidated. |
|
| 395 | 395 |
/// |
| 396 | 396 |
///\warning This functionality cannot be used together with the Snapshot |
| 397 | 397 |
///feature. |
| 398 | 398 |
void changeTarget(Arc a, Node n) {
|
| 399 | 399 |
Parent::changeTarget(a,n); |
| 400 | 400 |
} |
| 401 | 401 |
/// Change the source node of an arc |
| 402 | 402 |
|
| 403 | 403 |
/// This function changes the source node of the given arc \c a to \c n. |
| 404 | 404 |
/// |
| 405 | 405 |
///\note \c InArcIt iterators referencing the changed arc remain |
| 406 |
///valid, |
|
| 406 |
///valid, but \c ArcIt and \c OutArcIt iterators are invalidated. |
|
| 407 | 407 |
/// |
| 408 | 408 |
///\warning This functionality cannot be used together with the Snapshot |
| 409 | 409 |
///feature. |
| 410 | 410 |
void changeSource(Arc a, Node n) {
|
| 411 | 411 |
Parent::changeSource(a,n); |
| 412 | 412 |
} |
| 413 | 413 |
|
| 414 | 414 |
/// Reverse the direction of an arc. |
| 415 | 415 |
|
| 416 | 416 |
/// This function reverses the direction of the given arc. |
| 417 | 417 |
///\note \c ArcIt, \c OutArcIt and \c InArcIt iterators referencing |
| 418 | 418 |
///the changed arc are invalidated. |
| 419 | 419 |
/// |
| 420 | 420 |
///\warning This functionality cannot be used together with the Snapshot |
| 421 | 421 |
///feature. |
| 422 | 422 |
void reverseArc(Arc a) {
|
| 423 | 423 |
Node t=target(a); |
| 424 | 424 |
changeTarget(a,source(a)); |
| 425 | 425 |
changeSource(a,t); |
| 426 | 426 |
} |
| 427 | 427 |
|
| 428 | 428 |
///Contract two nodes. |
| 429 | 429 |
|
| 430 | 430 |
///This function contracts the given two nodes. |
| ... | ... |
@@ -528,49 +528,49 @@ |
| 528 | 528 |
|
| 529 | 529 |
/// Using this function, it is possible to avoid superfluous memory |
| 530 | 530 |
/// allocation: if you know that the digraph you want to build will |
| 531 | 531 |
/// be large (e.g. it will contain millions of nodes and/or arcs), |
| 532 | 532 |
/// then it is worth reserving space for this amount before starting |
| 533 | 533 |
/// to build the digraph. |
| 534 | 534 |
/// \sa reserveNode() |
| 535 | 535 |
void reserveArc(int m) { arcs.reserve(m); };
|
| 536 | 536 |
|
| 537 | 537 |
/// \brief Class to make a snapshot of the digraph and restore |
| 538 | 538 |
/// it later. |
| 539 | 539 |
/// |
| 540 | 540 |
/// Class to make a snapshot of the digraph and restore it later. |
| 541 | 541 |
/// |
| 542 | 542 |
/// The newly added nodes and arcs can be removed using the |
| 543 | 543 |
/// restore() function. |
| 544 | 544 |
/// |
| 545 | 545 |
/// \note After a state is restored, you cannot restore a later state, |
| 546 | 546 |
/// i.e. you cannot add the removed nodes and arcs again using |
| 547 | 547 |
/// another Snapshot instance. |
| 548 | 548 |
/// |
| 549 | 549 |
/// \warning Node and arc deletions and other modifications (e.g. |
| 550 | 550 |
/// reversing, contracting, splitting arcs or nodes) cannot be |
| 551 | 551 |
/// restored. These events invalidate the snapshot. |
| 552 |
/// However the arcs and nodes that were added to the digraph after |
|
| 552 |
/// However, the arcs and nodes that were added to the digraph after |
|
| 553 | 553 |
/// making the current snapshot can be removed without invalidating it. |
| 554 | 554 |
class Snapshot {
|
| 555 | 555 |
protected: |
| 556 | 556 |
|
| 557 | 557 |
typedef Parent::NodeNotifier NodeNotifier; |
| 558 | 558 |
|
| 559 | 559 |
class NodeObserverProxy : public NodeNotifier::ObserverBase {
|
| 560 | 560 |
public: |
| 561 | 561 |
|
| 562 | 562 |
NodeObserverProxy(Snapshot& _snapshot) |
| 563 | 563 |
: snapshot(_snapshot) {}
|
| 564 | 564 |
|
| 565 | 565 |
using NodeNotifier::ObserverBase::attach; |
| 566 | 566 |
using NodeNotifier::ObserverBase::detach; |
| 567 | 567 |
using NodeNotifier::ObserverBase::attached; |
| 568 | 568 |
|
| 569 | 569 |
protected: |
| 570 | 570 |
|
| 571 | 571 |
virtual void add(const Node& node) {
|
| 572 | 572 |
snapshot.addNode(node); |
| 573 | 573 |
} |
| 574 | 574 |
virtual void add(const std::vector<Node>& nodes) {
|
| 575 | 575 |
for (int i = nodes.size() - 1; i >= 0; ++i) {
|
| 576 | 576 |
snapshot.addNode(nodes[i]); |
| ... | ... |
@@ -1246,49 +1246,49 @@ |
| 1246 | 1246 |
/// i.e. it is a real arc of the graph. |
| 1247 | 1247 |
/// |
| 1248 | 1248 |
/// \warning A removed arc could become valid again if new edges are |
| 1249 | 1249 |
/// added to the graph. |
| 1250 | 1250 |
bool valid(Arc a) const { return Parent::valid(a); }
|
| 1251 | 1251 |
|
| 1252 | 1252 |
/// \brief Change the first node of an edge. |
| 1253 | 1253 |
/// |
| 1254 | 1254 |
/// This function changes the first node of the given edge \c e to \c n. |
| 1255 | 1255 |
/// |
| 1256 | 1256 |
///\note \c EdgeIt and \c ArcIt iterators referencing the |
| 1257 | 1257 |
///changed edge are invalidated and all other iterators whose |
| 1258 | 1258 |
///base node is the changed node are also invalidated. |
| 1259 | 1259 |
/// |
| 1260 | 1260 |
///\warning This functionality cannot be used together with the |
| 1261 | 1261 |
///Snapshot feature. |
| 1262 | 1262 |
void changeU(Edge e, Node n) {
|
| 1263 | 1263 |
Parent::changeU(e,n); |
| 1264 | 1264 |
} |
| 1265 | 1265 |
/// \brief Change the second node of an edge. |
| 1266 | 1266 |
/// |
| 1267 | 1267 |
/// This function changes the second node of the given edge \c e to \c n. |
| 1268 | 1268 |
/// |
| 1269 | 1269 |
///\note \c EdgeIt iterators referencing the changed edge remain |
| 1270 |
///valid, |
|
| 1270 |
///valid, but \c ArcIt iterators referencing the changed edge and |
|
| 1271 | 1271 |
///all other iterators whose base node is the changed node are also |
| 1272 | 1272 |
///invalidated. |
| 1273 | 1273 |
/// |
| 1274 | 1274 |
///\warning This functionality cannot be used together with the |
| 1275 | 1275 |
///Snapshot feature. |
| 1276 | 1276 |
void changeV(Edge e, Node n) {
|
| 1277 | 1277 |
Parent::changeV(e,n); |
| 1278 | 1278 |
} |
| 1279 | 1279 |
|
| 1280 | 1280 |
/// \brief Contract two nodes. |
| 1281 | 1281 |
/// |
| 1282 | 1282 |
/// This function contracts the given two nodes. |
| 1283 | 1283 |
/// Node \c b is removed, but instead of deleting |
| 1284 | 1284 |
/// its incident edges, they are joined to node \c a. |
| 1285 | 1285 |
/// If the last parameter \c r is \c true (this is the default value), |
| 1286 | 1286 |
/// then the newly created loops are removed. |
| 1287 | 1287 |
/// |
| 1288 | 1288 |
/// \note The moved edges are joined to node \c a using changeU() |
| 1289 | 1289 |
/// or changeV(), thus all edge and arc iterators whose base node is |
| 1290 | 1290 |
/// \c b are invalidated. |
| 1291 | 1291 |
/// Moreover all iterators referencing node \c b or the removed |
| 1292 | 1292 |
/// loops are also invalidated. Other iterators remain valid. |
| 1293 | 1293 |
/// |
| 1294 | 1294 |
///\warning This functionality cannot be used together with the |
| ... | ... |
@@ -1330,49 +1330,49 @@ |
| 1330 | 1330 |
|
| 1331 | 1331 |
/// Using this function, it is possible to avoid superfluous memory |
| 1332 | 1332 |
/// allocation: if you know that the graph you want to build will |
| 1333 | 1333 |
/// be large (e.g. it will contain millions of nodes and/or edges), |
| 1334 | 1334 |
/// then it is worth reserving space for this amount before starting |
| 1335 | 1335 |
/// to build the graph. |
| 1336 | 1336 |
/// \sa reserveNode() |
| 1337 | 1337 |
void reserveEdge(int m) { arcs.reserve(2 * m); };
|
| 1338 | 1338 |
|
| 1339 | 1339 |
/// \brief Class to make a snapshot of the graph and restore |
| 1340 | 1340 |
/// it later. |
| 1341 | 1341 |
/// |
| 1342 | 1342 |
/// Class to make a snapshot of the graph and restore it later. |
| 1343 | 1343 |
/// |
| 1344 | 1344 |
/// The newly added nodes and edges can be removed |
| 1345 | 1345 |
/// using the restore() function. |
| 1346 | 1346 |
/// |
| 1347 | 1347 |
/// \note After a state is restored, you cannot restore a later state, |
| 1348 | 1348 |
/// i.e. you cannot add the removed nodes and edges again using |
| 1349 | 1349 |
/// another Snapshot instance. |
| 1350 | 1350 |
/// |
| 1351 | 1351 |
/// \warning Node and edge deletions and other modifications |
| 1352 | 1352 |
/// (e.g. changing the end-nodes of edges or contracting nodes) |
| 1353 | 1353 |
/// cannot be restored. These events invalidate the snapshot. |
| 1354 |
/// However the edges and nodes that were added to the graph after |
|
| 1354 |
/// However, the edges and nodes that were added to the graph after |
|
| 1355 | 1355 |
/// making the current snapshot can be removed without invalidating it. |
| 1356 | 1356 |
class Snapshot {
|
| 1357 | 1357 |
protected: |
| 1358 | 1358 |
|
| 1359 | 1359 |
typedef Parent::NodeNotifier NodeNotifier; |
| 1360 | 1360 |
|
| 1361 | 1361 |
class NodeObserverProxy : public NodeNotifier::ObserverBase {
|
| 1362 | 1362 |
public: |
| 1363 | 1363 |
|
| 1364 | 1364 |
NodeObserverProxy(Snapshot& _snapshot) |
| 1365 | 1365 |
: snapshot(_snapshot) {}
|
| 1366 | 1366 |
|
| 1367 | 1367 |
using NodeNotifier::ObserverBase::attach; |
| 1368 | 1368 |
using NodeNotifier::ObserverBase::detach; |
| 1369 | 1369 |
using NodeNotifier::ObserverBase::attached; |
| 1370 | 1370 |
|
| 1371 | 1371 |
protected: |
| 1372 | 1372 |
|
| 1373 | 1373 |
virtual void add(const Node& node) {
|
| 1374 | 1374 |
snapshot.addNode(node); |
| 1375 | 1375 |
} |
| 1376 | 1376 |
virtual void add(const std::vector<Node>& nodes) {
|
| 1377 | 1377 |
for (int i = nodes.size() - 1; i >= 0; ++i) {
|
| 1378 | 1378 |
snapshot.addNode(nodes[i]); |
| ... | ... |
@@ -125,49 +125,49 @@ |
| 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 |
| 129 | 129 |
/// the same LP column or both are invalid. |
| 130 | 130 |
bool operator==(Col c) const {return _id == c._id;}
|
| 131 | 131 |
/// Inequality operator |
| 132 | 132 |
|
| 133 | 133 |
/// \sa operator==(Col c) |
| 134 | 134 |
/// |
| 135 | 135 |
bool operator!=(Col c) const {return _id != c._id;}
|
| 136 | 136 |
/// Artificial ordering operator. |
| 137 | 137 |
|
| 138 | 138 |
/// To allow the use of this object in std::map or similar |
| 139 | 139 |
/// associative container we require this. |
| 140 | 140 |
/// |
| 141 | 141 |
/// \note This operator only have to define some strict ordering of |
| 142 | 142 |
/// the items; this order has nothing to do with the iteration |
| 143 | 143 |
/// ordering of the items. |
| 144 | 144 |
bool operator<(Col c) const {return _id < c._id;}
|
| 145 | 145 |
}; |
| 146 | 146 |
|
| 147 | 147 |
///Iterator for iterate over the columns of an LP problem |
| 148 | 148 |
|
| 149 |
/// Its usage is quite simple, for example you can count the number |
|
| 149 |
/// Its usage is quite simple, for example, you can count the number |
|
| 150 | 150 |
/// of columns in an LP \c lp: |
| 151 | 151 |
///\code |
| 152 | 152 |
/// int count=0; |
| 153 | 153 |
/// for (LpBase::ColIt c(lp); c!=INVALID; ++c) ++count; |
| 154 | 154 |
///\endcode |
| 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. |
| ... | ... |
@@ -220,49 +220,49 @@ |
| 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. |
| 232 | 232 |
|
| 233 | 233 |
/// To allow the use of this object in std::map or similar |
| 234 | 234 |
/// associative container we require this. |
| 235 | 235 |
/// |
| 236 | 236 |
/// \note This operator only have to define some strict ordering of |
| 237 | 237 |
/// the items; this order has nothing to do with the iteration |
| 238 | 238 |
/// ordering of the items. |
| 239 | 239 |
bool operator<(Row r) const {return _id < r._id;}
|
| 240 | 240 |
}; |
| 241 | 241 |
|
| 242 | 242 |
///Iterator for iterate over the rows of an LP problem |
| 243 | 243 |
|
| 244 |
/// Its usage is quite simple, for example you can count the number |
|
| 244 |
/// Its usage is quite simple, for example, you can count the number |
|
| 245 | 245 |
/// of rows in an LP \c lp: |
| 246 | 246 |
///\code |
| 247 | 247 |
/// int count=0; |
| 248 | 248 |
/// for (LpBase::RowIt c(lp); c!=INVALID; ++c) ++count; |
| 249 | 249 |
///\endcode |
| 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. |
| ... | ... |
@@ -209,52 +209,52 @@ |
| 209 | 209 |
///\e |
| 210 | 210 |
typedef T Value; |
| 211 | 211 |
|
| 212 | 212 |
/// Gives back the given value without any modification. |
| 213 | 213 |
Value operator[](const Key &k) const {
|
| 214 | 214 |
return k; |
| 215 | 215 |
} |
| 216 | 216 |
}; |
| 217 | 217 |
|
| 218 | 218 |
/// Returns an \c IdentityMap class |
| 219 | 219 |
|
| 220 | 220 |
/// This function just returns an \c IdentityMap class. |
| 221 | 221 |
/// \relates IdentityMap |
| 222 | 222 |
template<typename T> |
| 223 | 223 |
inline IdentityMap<T> identityMap() {
|
| 224 | 224 |
return IdentityMap<T>(); |
| 225 | 225 |
} |
| 226 | 226 |
|
| 227 | 227 |
|
| 228 | 228 |
/// \brief Map for storing values for integer keys from the range |
| 229 | 229 |
/// <tt>[0..size-1]</tt>. |
| 230 | 230 |
/// |
| 231 | 231 |
/// This map is essentially a wrapper for \c std::vector. It assigns |
| 232 | 232 |
/// values to integer keys from the range <tt>[0..size-1]</tt>. |
| 233 |
/// It can be used with some data structures, for example |
|
| 234 |
/// \c UnionFind, \c BinHeap, when the used items are small |
|
| 233 |
/// It can be used together with some data structures, e.g. |
|
| 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> |
| 241 | 241 |
class RangeMap : public MapBase<int, V> {
|
| 242 | 242 |
template <typename V1> |
| 243 | 243 |
friend class RangeMap; |
| 244 | 244 |
private: |
| 245 | 245 |
|
| 246 | 246 |
typedef std::vector<V> Vector; |
| 247 | 247 |
Vector _vector; |
| 248 | 248 |
|
| 249 | 249 |
public: |
| 250 | 250 |
|
| 251 | 251 |
/// Key type |
| 252 | 252 |
typedef int Key; |
| 253 | 253 |
/// Value type |
| 254 | 254 |
typedef V Value; |
| 255 | 255 |
/// Reference type |
| 256 | 256 |
typedef typename Vector::reference Reference; |
| 257 | 257 |
/// Const reference type |
| 258 | 258 |
typedef typename Vector::const_reference ConstReference; |
| 259 | 259 |
|
| 260 | 260 |
typedef True ReferenceMapTag; |
| ... | ... |
@@ -327,51 +327,51 @@ |
| 327 | 327 |
|
| 328 | 328 |
/// This function just returns a \c RangeMap class created from an |
| 329 | 329 |
/// appropriate \c std::vector. |
| 330 | 330 |
/// \relates RangeMap |
| 331 | 331 |
template<typename V> |
| 332 | 332 |
inline RangeMap<V> rangeMap(const std::vector<V> &vector) {
|
| 333 | 333 |
return RangeMap<V>(vector); |
| 334 | 334 |
} |
| 335 | 335 |
|
| 336 | 336 |
|
| 337 | 337 |
/// Map type based on \c std::map |
| 338 | 338 |
|
| 339 | 339 |
/// This map is essentially a wrapper for \c std::map with addition |
| 340 | 340 |
/// that you can specify a default value for the keys that are not |
| 341 | 341 |
/// stored actually. This value can be different from the default |
| 342 | 342 |
/// contructed value (i.e. \c %Value()). |
| 343 | 343 |
/// This type conforms to the \ref concepts::ReferenceMap "ReferenceMap" |
| 344 | 344 |
/// concept. |
| 345 | 345 |
/// |
| 346 | 346 |
/// This map is useful if a default value should be assigned to most of |
| 347 | 347 |
/// the keys and different values should be assigned only to a few |
| 348 | 348 |
/// keys (i.e. the map is "sparse"). |
| 349 | 349 |
/// The name of this type also refers to this important usage. |
| 350 | 350 |
/// |
| 351 |
/// Apart form that this map can be used in many other cases since it |
|
| 351 |
/// Apart form that, this map can be used in many other cases since it |
|
| 352 | 352 |
/// is based on \c std::map, which is a general associative container. |
| 353 |
/// However keep in mind that it is usually not as efficient as other |
|
| 353 |
/// However, keep in mind that it is usually not as efficient as other |
|
| 354 | 354 |
/// maps. |
| 355 | 355 |
/// |
| 356 | 356 |
/// The simplest way of using this map is through the sparseMap() |
| 357 | 357 |
/// function. |
| 358 | 358 |
template <typename K, typename V, typename Comp = std::less<K> > |
| 359 | 359 |
class SparseMap : public MapBase<K, V> {
|
| 360 | 360 |
template <typename K1, typename V1, typename C1> |
| 361 | 361 |
friend class SparseMap; |
| 362 | 362 |
public: |
| 363 | 363 |
|
| 364 | 364 |
/// Key type |
| 365 | 365 |
typedef K Key; |
| 366 | 366 |
/// Value type |
| 367 | 367 |
typedef V Value; |
| 368 | 368 |
/// Reference type |
| 369 | 369 |
typedef Value& Reference; |
| 370 | 370 |
/// Const reference type |
| 371 | 371 |
typedef const Value& ConstReference; |
| 372 | 372 |
|
| 373 | 373 |
typedef True ReferenceMapTag; |
| 374 | 374 |
|
| 375 | 375 |
private: |
| 376 | 376 |
|
| 377 | 377 |
typedef std::map<K, V, Comp> Map; |
| ... | ... |
@@ -1764,64 +1764,64 @@ |
| 1764 | 1764 |
|
| 1765 | 1765 |
/// Gives back the the 'after the last' iterator |
| 1766 | 1766 |
Iterator end() const {
|
| 1767 | 1767 |
return _end; |
| 1768 | 1768 |
} |
| 1769 | 1769 |
|
| 1770 | 1770 |
/// The set function of the map |
| 1771 | 1771 |
void set(const Key& key, Value value) {
|
| 1772 | 1772 |
if (value) {
|
| 1773 | 1773 |
*_end++ = key; |
| 1774 | 1774 |
} |
| 1775 | 1775 |
} |
| 1776 | 1776 |
|
| 1777 | 1777 |
private: |
| 1778 | 1778 |
Iterator _begin; |
| 1779 | 1779 |
Iterator _end; |
| 1780 | 1780 |
}; |
| 1781 | 1781 |
|
| 1782 | 1782 |
/// Returns a \c LoggerBoolMap class |
| 1783 | 1783 |
|
| 1784 | 1784 |
/// This function just returns a \c LoggerBoolMap class. |
| 1785 | 1785 |
/// |
| 1786 | 1786 |
/// The most important usage of it is storing certain nodes or arcs |
| 1787 | 1787 |
/// that were marked \c true by an algorithm. |
| 1788 |
/// For example it makes easier to store the nodes in the processing |
|
| 1788 |
/// For example, it makes easier to store the nodes in the processing |
|
| 1789 | 1789 |
/// order of Dfs algorithm, as the following examples show. |
| 1790 | 1790 |
/// \code |
| 1791 | 1791 |
/// std::vector<Node> v; |
| 1792 | 1792 |
/// dfs(g).processedMap(loggerBoolMap(std::back_inserter(v))).run(s); |
| 1793 | 1793 |
/// \endcode |
| 1794 | 1794 |
/// \code |
| 1795 | 1795 |
/// std::vector<Node> v(countNodes(g)); |
| 1796 | 1796 |
/// dfs(g).processedMap(loggerBoolMap(v.begin())).run(s); |
| 1797 | 1797 |
/// \endcode |
| 1798 | 1798 |
/// |
| 1799 | 1799 |
/// \note The container of the iterator must contain enough space |
| 1800 | 1800 |
/// for the elements or the iterator should be an inserter iterator. |
| 1801 | 1801 |
/// |
| 1802 | 1802 |
/// \note LoggerBoolMap is just \ref concepts::WriteMap "writable", so |
| 1803 |
/// it cannot be used when a readable map is needed, for example as |
|
| 1803 |
/// it cannot be used when a readable map is needed, for example, as |
|
| 1804 | 1804 |
/// \c ReachedMap for \c Bfs, \c Dfs and \c Dijkstra algorithms. |
| 1805 | 1805 |
/// |
| 1806 | 1806 |
/// \relates LoggerBoolMap |
| 1807 | 1807 |
template<typename Iterator> |
| 1808 | 1808 |
inline LoggerBoolMap<Iterator> loggerBoolMap(Iterator it) {
|
| 1809 | 1809 |
return LoggerBoolMap<Iterator>(it); |
| 1810 | 1810 |
} |
| 1811 | 1811 |
|
| 1812 | 1812 |
/// @} |
| 1813 | 1813 |
|
| 1814 | 1814 |
/// \addtogroup graph_maps |
| 1815 | 1815 |
/// @{
|
| 1816 | 1816 |
|
| 1817 | 1817 |
/// \brief Provides an immutable and unique id for each item in a graph. |
| 1818 | 1818 |
/// |
| 1819 | 1819 |
/// IdMap provides a unique and immutable id for each item of the |
| 1820 | 1820 |
/// same type (\c Node, \c Arc or \c Edge) in a graph. This id is |
| 1821 | 1821 |
/// - \b unique: different items get different ids, |
| 1822 | 1822 |
/// - \b immutable: the id of an item does not change (even if you |
| 1823 | 1823 |
/// delete other nodes). |
| 1824 | 1824 |
/// |
| 1825 | 1825 |
/// Using this map you get access (i.e. can read) the inner id values of |
| 1826 | 1826 |
/// the items stored in the graph, which is returned by the \c id() |
| 1827 | 1827 |
/// function of the graph. This map can be inverted with its member |
| ... | ... |
@@ -1901,49 +1901,49 @@ |
| 1901 | 1901 |
|
| 1902 | 1902 |
/// \brief Returns an \c IdMap class. |
| 1903 | 1903 |
/// |
| 1904 | 1904 |
/// This function just returns an \c IdMap class. |
| 1905 | 1905 |
/// \relates IdMap |
| 1906 | 1906 |
template <typename K, typename GR> |
| 1907 | 1907 |
inline IdMap<GR, K> idMap(const GR& graph) {
|
| 1908 | 1908 |
return IdMap<GR, K>(graph); |
| 1909 | 1909 |
} |
| 1910 | 1910 |
|
| 1911 | 1911 |
/// \brief General cross reference graph map type. |
| 1912 | 1912 |
|
| 1913 | 1913 |
/// This class provides simple invertable graph maps. |
| 1914 | 1914 |
/// It wraps a standard graph map (\c NodeMap, \c ArcMap or \c EdgeMap) |
| 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 | 1923 |
/// Otherwise consider to use \c IterableValueMap, which is more |
| 1924 | 1924 |
/// suitable and more efficient for such cases. It provides iterators |
| 1925 |
/// to traverse the items with the same associated value, |
|
| 1925 |
/// to traverse the items with the same associated value, but |
|
| 1926 | 1926 |
/// it does not have \c InverseMap. |
| 1927 | 1927 |
/// |
| 1928 | 1928 |
/// This type is not reference map, so it cannot be modified with |
| 1929 | 1929 |
/// the subscript operator. |
| 1930 | 1930 |
/// |
| 1931 | 1931 |
/// \tparam GR The graph type. |
| 1932 | 1932 |
/// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or |
| 1933 | 1933 |
/// \c GR::Edge). |
| 1934 | 1934 |
/// \tparam V The value type of the map. |
| 1935 | 1935 |
/// |
| 1936 | 1936 |
/// \see IterableValueMap |
| 1937 | 1937 |
template <typename GR, typename K, typename V> |
| 1938 | 1938 |
class CrossRefMap |
| 1939 | 1939 |
: protected ItemSetTraits<GR, K>::template Map<V>::Type {
|
| 1940 | 1940 |
private: |
| 1941 | 1941 |
|
| 1942 | 1942 |
typedef typename ItemSetTraits<GR, K>:: |
| 1943 | 1943 |
template Map<V>::Type Map; |
| 1944 | 1944 |
|
| 1945 | 1945 |
typedef std::multimap<V, K> Container; |
| 1946 | 1946 |
Container _inv_map; |
| 1947 | 1947 |
|
| 1948 | 1948 |
public: |
| 1949 | 1949 |
|
| ... | ... |
@@ -3445,49 +3445,49 @@ |
| 3445 | 3445 |
|
| 3446 | 3446 |
private: |
| 3447 | 3447 |
const GR& _graph; |
| 3448 | 3448 |
}; |
| 3449 | 3449 |
|
| 3450 | 3450 |
/// \brief Returns a \c BackwardMap class |
| 3451 | 3451 |
|
| 3452 | 3452 |
/// This function just returns a \c BackwardMap class. |
| 3453 | 3453 |
/// \relates BackwardMap |
| 3454 | 3454 |
template <typename GR> |
| 3455 | 3455 |
inline BackwardMap<GR> backwardMap(const GR& graph) {
|
| 3456 | 3456 |
return BackwardMap<GR>(graph); |
| 3457 | 3457 |
} |
| 3458 | 3458 |
|
| 3459 | 3459 |
/// \brief Map of the in-degrees of nodes in a digraph. |
| 3460 | 3460 |
/// |
| 3461 | 3461 |
/// This map returns the in-degree of a node. Once it is constructed, |
| 3462 | 3462 |
/// the degrees are stored in a standard \c NodeMap, so each query is done |
| 3463 | 3463 |
/// in constant time. On the other hand, the values are updated automatically |
| 3464 | 3464 |
/// whenever the digraph changes. |
| 3465 | 3465 |
/// |
| 3466 | 3466 |
/// \warning Besides \c addNode() and \c addArc(), a digraph structure |
| 3467 | 3467 |
/// may provide alternative ways to modify the digraph. |
| 3468 | 3468 |
/// The correct behavior of InDegMap is not guarantied if these additional |
| 3469 |
/// features are used. For example the functions |
|
| 3469 |
/// features are used. For example, the functions |
|
| 3470 | 3470 |
/// \ref ListDigraph::changeSource() "changeSource()", |
| 3471 | 3471 |
/// \ref ListDigraph::changeTarget() "changeTarget()" and |
| 3472 | 3472 |
/// \ref ListDigraph::reverseArc() "reverseArc()" |
| 3473 | 3473 |
/// of \ref ListDigraph will \e not update the degree values correctly. |
| 3474 | 3474 |
/// |
| 3475 | 3475 |
/// \sa OutDegMap |
| 3476 | 3476 |
template <typename GR> |
| 3477 | 3477 |
class InDegMap |
| 3478 | 3478 |
: protected ItemSetTraits<GR, typename GR::Arc> |
| 3479 | 3479 |
::ItemNotifier::ObserverBase {
|
| 3480 | 3480 |
|
| 3481 | 3481 |
public: |
| 3482 | 3482 |
|
| 3483 | 3483 |
/// The graph type of InDegMap |
| 3484 | 3484 |
typedef GR Graph; |
| 3485 | 3485 |
typedef GR Digraph; |
| 3486 | 3486 |
/// The key type |
| 3487 | 3487 |
typedef typename Digraph::Node Key; |
| 3488 | 3488 |
/// The value type |
| 3489 | 3489 |
typedef int Value; |
| 3490 | 3490 |
|
| 3491 | 3491 |
typedef typename ItemSetTraits<Digraph, typename Digraph::Arc> |
| 3492 | 3492 |
::ItemNotifier::ObserverBase Parent; |
| 3493 | 3493 |
|
| ... | ... |
@@ -3575,49 +3575,49 @@ |
| 3575 | 3575 |
} |
| 3576 | 3576 |
} |
| 3577 | 3577 |
|
| 3578 | 3578 |
virtual void clear() {
|
| 3579 | 3579 |
for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {
|
| 3580 | 3580 |
_deg[it] = 0; |
| 3581 | 3581 |
} |
| 3582 | 3582 |
} |
| 3583 | 3583 |
private: |
| 3584 | 3584 |
|
| 3585 | 3585 |
const Digraph& _digraph; |
| 3586 | 3586 |
AutoNodeMap _deg; |
| 3587 | 3587 |
}; |
| 3588 | 3588 |
|
| 3589 | 3589 |
/// \brief Map of the out-degrees of nodes in a digraph. |
| 3590 | 3590 |
/// |
| 3591 | 3591 |
/// This map returns the out-degree of a node. Once it is constructed, |
| 3592 | 3592 |
/// the degrees are stored in a standard \c NodeMap, so each query is done |
| 3593 | 3593 |
/// in constant time. On the other hand, the values are updated automatically |
| 3594 | 3594 |
/// whenever the digraph changes. |
| 3595 | 3595 |
/// |
| 3596 | 3596 |
/// \warning Besides \c addNode() and \c addArc(), a digraph structure |
| 3597 | 3597 |
/// may provide alternative ways to modify the digraph. |
| 3598 | 3598 |
/// The correct behavior of OutDegMap is not guarantied if these additional |
| 3599 |
/// features are used. For example the functions |
|
| 3599 |
/// features are used. For example, the functions |
|
| 3600 | 3600 |
/// \ref ListDigraph::changeSource() "changeSource()", |
| 3601 | 3601 |
/// \ref ListDigraph::changeTarget() "changeTarget()" and |
| 3602 | 3602 |
/// \ref ListDigraph::reverseArc() "reverseArc()" |
| 3603 | 3603 |
/// of \ref ListDigraph will \e not update the degree values correctly. |
| 3604 | 3604 |
/// |
| 3605 | 3605 |
/// \sa InDegMap |
| 3606 | 3606 |
template <typename GR> |
| 3607 | 3607 |
class OutDegMap |
| 3608 | 3608 |
: protected ItemSetTraits<GR, typename GR::Arc> |
| 3609 | 3609 |
::ItemNotifier::ObserverBase {
|
| 3610 | 3610 |
|
| 3611 | 3611 |
public: |
| 3612 | 3612 |
|
| 3613 | 3613 |
/// The graph type of OutDegMap |
| 3614 | 3614 |
typedef GR Graph; |
| 3615 | 3615 |
typedef GR Digraph; |
| 3616 | 3616 |
/// The key type |
| 3617 | 3617 |
typedef typename Digraph::Node Key; |
| 3618 | 3618 |
/// The value type |
| 3619 | 3619 |
typedef int Value; |
| 3620 | 3620 |
|
| 3621 | 3621 |
typedef typename ItemSetTraits<Digraph, typename Digraph::Arc> |
| 3622 | 3622 |
::ItemNotifier::ObserverBase Parent; |
| 3623 | 3623 |
| ... | ... |
@@ -27,67 +27,67 @@ |
| 27 | 27 |
#include <vector> |
| 28 | 28 |
#include <limits> |
| 29 | 29 |
#include <algorithm> |
| 30 | 30 |
|
| 31 | 31 |
#include <lemon/core.h> |
| 32 | 32 |
#include <lemon/math.h> |
| 33 | 33 |
|
| 34 | 34 |
namespace lemon {
|
| 35 | 35 |
|
| 36 | 36 |
/// \addtogroup min_cost_flow_algs |
| 37 | 37 |
/// @{
|
| 38 | 38 |
|
| 39 | 39 |
/// \brief Implementation of the primal Network Simplex algorithm |
| 40 | 40 |
/// for finding a \ref min_cost_flow "minimum cost flow". |
| 41 | 41 |
/// |
| 42 | 42 |
/// \ref NetworkSimplex implements the primal Network Simplex algorithm |
| 43 | 43 |
/// for finding a \ref min_cost_flow "minimum cost flow". |
| 44 | 44 |
/// This algorithm is a specialized version of the linear programming |
| 45 | 45 |
/// simplex method directly for the minimum cost flow problem. |
| 46 | 46 |
/// It is one of the most efficient solution methods. |
| 47 | 47 |
/// |
| 48 | 48 |
/// In general this class is the fastest implementation available |
| 49 | 49 |
/// in LEMON for the minimum cost flow problem. |
| 50 | 50 |
/// Moreover it supports both directions of the supply/demand inequality |
| 51 |
/// constraints. For more information see \ref SupplyType. |
|
| 51 |
/// constraints. For more information, see \ref SupplyType. |
|
| 52 | 52 |
/// |
| 53 | 53 |
/// Most of the parameters of the problem (except for the digraph) |
| 54 | 54 |
/// can be given using separate functions, and the algorithm can be |
| 55 | 55 |
/// executed using the \ref run() function. If some parameters are not |
| 56 | 56 |
/// specified, then default values will be used. |
| 57 | 57 |
/// |
| 58 | 58 |
/// \tparam GR The digraph type the algorithm runs on. |
| 59 | 59 |
/// \tparam V The value type used for flow amounts, capacity bounds |
| 60 |
/// and supply values in the algorithm. By default it is \c int. |
|
| 60 |
/// and supply values in the algorithm. By default, it is \c int. |
|
| 61 | 61 |
/// \tparam C The value type used for costs and potentials in the |
| 62 |
/// algorithm. By default it is the same as \c V. |
|
| 62 |
/// algorithm. By default, it is the same as \c V. |
|
| 63 | 63 |
/// |
| 64 | 64 |
/// \warning Both value types must be signed and all input data must |
| 65 | 65 |
/// be integer. |
| 66 | 66 |
/// |
| 67 | 67 |
/// \note %NetworkSimplex provides five different pivot rule |
| 68 | 68 |
/// implementations, from which the most efficient one is used |
| 69 |
/// by default. For more information see \ref PivotRule. |
|
| 69 |
/// by default. For more information, see \ref PivotRule. |
|
| 70 | 70 |
template <typename GR, typename V = int, typename C = V> |
| 71 | 71 |
class NetworkSimplex |
| 72 | 72 |
{
|
| 73 | 73 |
public: |
| 74 | 74 |
|
| 75 | 75 |
/// The type of the flow amounts, capacity bounds and supply values |
| 76 | 76 |
typedef V Value; |
| 77 | 77 |
/// The type of the arc costs |
| 78 | 78 |
typedef C Cost; |
| 79 | 79 |
|
| 80 | 80 |
public: |
| 81 | 81 |
|
| 82 | 82 |
/// \brief Problem type constants for the \c run() function. |
| 83 | 83 |
/// |
| 84 | 84 |
/// Enum type containing the problem type constants that can be |
| 85 | 85 |
/// returned by the \ref run() function of the algorithm. |
| 86 | 86 |
enum ProblemType {
|
| 87 | 87 |
/// The problem has no feasible solution (flow). |
| 88 | 88 |
INFEASIBLE, |
| 89 | 89 |
/// The problem has optimal solution (i.e. it is feasible and |
| 90 | 90 |
/// bounded), and the algorithm has found optimal flow and node |
| 91 | 91 |
/// potentials (primal and dual solutions). |
| 92 | 92 |
OPTIMAL, |
| 93 | 93 |
/// The objective function of the problem is unbounded, i.e. |
| ... | ... |
@@ -101,77 +101,77 @@ |
| 101 | 101 |
/// Enum type containing constants for selecting the supply type, |
| 102 | 102 |
/// i.e. the direction of the inequalities in the supply/demand |
| 103 | 103 |
/// constraints of the \ref min_cost_flow "minimum cost flow problem". |
| 104 | 104 |
/// |
| 105 | 105 |
/// The default supply type is \c GEQ, the \c LEQ type can be |
| 106 | 106 |
/// selected using \ref supplyType(). |
| 107 | 107 |
/// The equality form is a special case of both supply types. |
| 108 | 108 |
enum SupplyType {
|
| 109 | 109 |
/// This option means that there are <em>"greater or equal"</em> |
| 110 | 110 |
/// supply/demand constraints in the definition of the problem. |
| 111 | 111 |
GEQ, |
| 112 | 112 |
/// This option means that there are <em>"less or equal"</em> |
| 113 | 113 |
/// supply/demand constraints in the definition of the problem. |
| 114 | 114 |
LEQ |
| 115 | 115 |
}; |
| 116 | 116 |
|
| 117 | 117 |
/// \brief Constants for selecting the pivot rule. |
| 118 | 118 |
/// |
| 119 | 119 |
/// Enum type containing constants for selecting the pivot rule for |
| 120 | 120 |
/// the \ref run() function. |
| 121 | 121 |
/// |
| 122 | 122 |
/// \ref NetworkSimplex provides five different pivot rule |
| 123 | 123 |
/// implementations that significantly affect the running time |
| 124 | 124 |
/// of the algorithm. |
| 125 |
/// By default \ref BLOCK_SEARCH "Block Search" is used, which |
|
| 125 |
/// By default, \ref BLOCK_SEARCH "Block Search" is used, which |
|
| 126 | 126 |
/// proved to be the most efficient and the most robust on various |
| 127 | 127 |
/// test inputs according to our benchmark tests. |
| 128 |
/// However another pivot rule can be selected using the \ref run() |
|
| 128 |
/// However, another pivot rule can be selected using the \ref run() |
|
| 129 | 129 |
/// function with the proper parameter. |
| 130 | 130 |
enum PivotRule {
|
| 131 | 131 |
|
| 132 |
/// The First Eligible pivot rule. |
|
| 132 |
/// The \e First \e Eligible pivot rule. |
|
| 133 | 133 |
/// The next eligible arc is selected in a wraparound fashion |
| 134 | 134 |
/// in every iteration. |
| 135 | 135 |
FIRST_ELIGIBLE, |
| 136 | 136 |
|
| 137 |
/// The Best Eligible pivot rule. |
|
| 137 |
/// The \e Best \e Eligible pivot rule. |
|
| 138 | 138 |
/// The best eligible arc is selected in every iteration. |
| 139 | 139 |
BEST_ELIGIBLE, |
| 140 | 140 |
|
| 141 |
/// The Block Search pivot rule. |
|
| 141 |
/// The \e Block \e Search pivot rule. |
|
| 142 | 142 |
/// A specified number of arcs are examined in every iteration |
| 143 | 143 |
/// in a wraparound fashion and the best eligible arc is selected |
| 144 | 144 |
/// from this block. |
| 145 | 145 |
BLOCK_SEARCH, |
| 146 | 146 |
|
| 147 |
/// The Candidate List pivot rule. |
|
| 147 |
/// The \e Candidate \e List pivot rule. |
|
| 148 | 148 |
/// In a major iteration a candidate list is built from eligible arcs |
| 149 | 149 |
/// in a wraparound fashion and in the following minor iterations |
| 150 | 150 |
/// the best eligible arc is selected from this list. |
| 151 | 151 |
CANDIDATE_LIST, |
| 152 | 152 |
|
| 153 |
/// The Altering Candidate List pivot rule. |
|
| 153 |
/// The \e Altering \e Candidate \e List pivot rule. |
|
| 154 | 154 |
/// It is a modified version of the Candidate List method. |
| 155 | 155 |
/// It keeps only the several best eligible arcs from the former |
| 156 | 156 |
/// candidate list and extends this list in every iteration. |
| 157 | 157 |
ALTERING_LIST |
| 158 | 158 |
}; |
| 159 | 159 |
|
| 160 | 160 |
private: |
| 161 | 161 |
|
| 162 | 162 |
TEMPLATE_DIGRAPH_TYPEDEFS(GR); |
| 163 | 163 |
|
| 164 | 164 |
typedef std::vector<int> IntVector; |
| 165 | 165 |
typedef std::vector<bool> BoolVector; |
| 166 | 166 |
typedef std::vector<Value> ValueVector; |
| 167 | 167 |
typedef std::vector<Cost> CostVector; |
| 168 | 168 |
|
| 169 | 169 |
// State constants for arcs |
| 170 | 170 |
enum ArcStateEnum {
|
| 171 | 171 |
STATE_UPPER = -1, |
| 172 | 172 |
STATE_TREE = 0, |
| 173 | 173 |
STATE_LOWER = 1 |
| 174 | 174 |
}; |
| 175 | 175 |
|
| 176 | 176 |
private: |
| 177 | 177 |
|
| ... | ... |
@@ -789,110 +789,110 @@ |
| 789 | 789 |
/// with such a map in which \c k is assigned to \c s, \c -k is |
| 790 | 790 |
/// assigned to \c t and all other nodes have zero supply value. |
| 791 | 791 |
/// |
| 792 | 792 |
/// \param s The source node. |
| 793 | 793 |
/// \param t The target node. |
| 794 | 794 |
/// \param k The required amount of flow from node \c s to node \c t |
| 795 | 795 |
/// (i.e. the supply of \c s and the demand of \c t). |
| 796 | 796 |
/// |
| 797 | 797 |
/// \return <tt>(*this)</tt> |
| 798 | 798 |
NetworkSimplex& stSupply(const Node& s, const Node& t, Value k) {
|
| 799 | 799 |
for (int i = 0; i != _node_num; ++i) {
|
| 800 | 800 |
_supply[i] = 0; |
| 801 | 801 |
} |
| 802 | 802 |
_supply[_node_id[s]] = k; |
| 803 | 803 |
_supply[_node_id[t]] = -k; |
| 804 | 804 |
return *this; |
| 805 | 805 |
} |
| 806 | 806 |
|
| 807 | 807 |
/// \brief Set the type of the supply constraints. |
| 808 | 808 |
/// |
| 809 | 809 |
/// This function sets the type of the supply/demand constraints. |
| 810 | 810 |
/// If it is not used before calling \ref run(), the \ref GEQ supply |
| 811 | 811 |
/// type will be used. |
| 812 | 812 |
/// |
| 813 |
/// For more information see \ref SupplyType. |
|
| 813 |
/// For more information, see \ref SupplyType. |
|
| 814 | 814 |
/// |
| 815 | 815 |
/// \return <tt>(*this)</tt> |
| 816 | 816 |
NetworkSimplex& supplyType(SupplyType supply_type) {
|
| 817 | 817 |
_stype = supply_type; |
| 818 | 818 |
return *this; |
| 819 | 819 |
} |
| 820 | 820 |
|
| 821 | 821 |
/// @} |
| 822 | 822 |
|
| 823 | 823 |
/// \name Execution Control |
| 824 | 824 |
/// The algorithm can be executed using \ref run(). |
| 825 | 825 |
|
| 826 | 826 |
/// @{
|
| 827 | 827 |
|
| 828 | 828 |
/// \brief Run the algorithm. |
| 829 | 829 |
/// |
| 830 | 830 |
/// This function runs the algorithm. |
| 831 | 831 |
/// The paramters can be specified using functions \ref lowerMap(), |
| 832 | 832 |
/// \ref upperMap(), \ref costMap(), \ref supplyMap(), \ref stSupply(), |
| 833 | 833 |
/// \ref supplyType(). |
| 834 | 834 |
/// For example, |
| 835 | 835 |
/// \code |
| 836 | 836 |
/// NetworkSimplex<ListDigraph> ns(graph); |
| 837 | 837 |
/// ns.lowerMap(lower).upperMap(upper).costMap(cost) |
| 838 | 838 |
/// .supplyMap(sup).run(); |
| 839 | 839 |
/// \endcode |
| 840 | 840 |
/// |
| 841 | 841 |
/// This function can be called more than once. All the parameters |
| 842 | 842 |
/// that have been given are kept for the next call, unless |
| 843 | 843 |
/// \ref reset() is called, thus only the modified parameters |
| 844 | 844 |
/// have to be set again. See \ref reset() for examples. |
| 845 |
/// However the underlying digraph must not be modified after this |
|
| 845 |
/// However, the underlying digraph must not be modified after this |
|
| 846 | 846 |
/// class have been constructed, since it copies and extends the graph. |
| 847 | 847 |
/// |
| 848 | 848 |
/// \param pivot_rule The pivot rule that will be used during the |
| 849 |
/// algorithm. For more information see \ref PivotRule. |
|
| 849 |
/// algorithm. For more information, see \ref PivotRule. |
|
| 850 | 850 |
/// |
| 851 | 851 |
/// \return \c INFEASIBLE if no feasible flow exists, |
| 852 | 852 |
/// \n \c OPTIMAL if the problem has optimal solution |
| 853 | 853 |
/// (i.e. it is feasible and bounded), and the algorithm has found |
| 854 | 854 |
/// optimal flow and node potentials (primal and dual solutions), |
| 855 | 855 |
/// \n \c UNBOUNDED if the objective function of the problem is |
| 856 | 856 |
/// unbounded, i.e. there is a directed cycle having negative total |
| 857 | 857 |
/// cost and infinite upper bound. |
| 858 | 858 |
/// |
| 859 | 859 |
/// \see ProblemType, PivotRule |
| 860 | 860 |
ProblemType run(PivotRule pivot_rule = BLOCK_SEARCH) {
|
| 861 | 861 |
if (!init()) return INFEASIBLE; |
| 862 | 862 |
return start(pivot_rule); |
| 863 | 863 |
} |
| 864 | 864 |
|
| 865 | 865 |
/// \brief Reset all the parameters that have been given before. |
| 866 | 866 |
/// |
| 867 | 867 |
/// This function resets all the paramaters that have been given |
| 868 | 868 |
/// before using functions \ref lowerMap(), \ref upperMap(), |
| 869 | 869 |
/// \ref costMap(), \ref supplyMap(), \ref stSupply(), \ref supplyType(). |
| 870 | 870 |
/// |
| 871 | 871 |
/// It is useful for multiple run() calls. If this function is not |
| 872 | 872 |
/// used, all the parameters given before are kept for the next |
| 873 | 873 |
/// \ref run() call. |
| 874 |
/// However the underlying digraph must not be modified after this |
|
| 874 |
/// However, the underlying digraph must not be modified after this |
|
| 875 | 875 |
/// class have been constructed, since it copies and extends the graph. |
| 876 | 876 |
/// |
| 877 | 877 |
/// For example, |
| 878 | 878 |
/// \code |
| 879 | 879 |
/// NetworkSimplex<ListDigraph> ns(graph); |
| 880 | 880 |
/// |
| 881 | 881 |
/// // First run |
| 882 | 882 |
/// ns.lowerMap(lower).upperMap(upper).costMap(cost) |
| 883 | 883 |
/// .supplyMap(sup).run(); |
| 884 | 884 |
/// |
| 885 | 885 |
/// // Run again with modified cost map (reset() is not called, |
| 886 | 886 |
/// // so only the cost map have to be set again) |
| 887 | 887 |
/// cost[e] += 100; |
| 888 | 888 |
/// ns.costMap(cost).run(); |
| 889 | 889 |
/// |
| 890 | 890 |
/// // Run again from scratch using reset() |
| 891 | 891 |
/// // (the lower bounds will be set to zero on all arcs) |
| 892 | 892 |
/// ns.reset(); |
| 893 | 893 |
/// ns.upperMap(capacity).costMap(cost) |
| 894 | 894 |
/// .supplyMap(sup).run(); |
| 895 | 895 |
/// \endcode |
| 896 | 896 |
/// |
| 897 | 897 |
/// \return <tt>(*this)</tt> |
| 898 | 898 |
NetworkSimplex& reset() {
|
| ... | ... |
@@ -243,49 +243,49 @@ |
| 243 | 243 |
/// \sa SetStandardElevator |
| 244 | 244 |
template <typename T> |
| 245 | 245 |
struct SetElevator |
| 246 | 246 |
: public Preflow<Digraph, CapacityMap, SetElevatorTraits<T> > {
|
| 247 | 247 |
typedef Preflow<Digraph, CapacityMap, |
| 248 | 248 |
SetElevatorTraits<T> > Create; |
| 249 | 249 |
}; |
| 250 | 250 |
|
| 251 | 251 |
template <typename T> |
| 252 | 252 |
struct SetStandardElevatorTraits : public Traits {
|
| 253 | 253 |
typedef T Elevator; |
| 254 | 254 |
static Elevator *createElevator(const Digraph& digraph, int max_level) {
|
| 255 | 255 |
return new Elevator(digraph, max_level); |
| 256 | 256 |
} |
| 257 | 257 |
}; |
| 258 | 258 |
|
| 259 | 259 |
/// \brief \ref named-templ-param "Named parameter" for setting |
| 260 | 260 |
/// Elevator type with automatic allocation |
| 261 | 261 |
/// |
| 262 | 262 |
/// \ref named-templ-param "Named parameter" for setting Elevator |
| 263 | 263 |
/// type with automatic allocation. |
| 264 | 264 |
/// The Elevator should have standard constructor interface to be |
| 265 | 265 |
/// able to automatically created by the algorithm (i.e. the |
| 266 | 266 |
/// digraph and the maximum level should be passed to it). |
| 267 |
/// However an external elevator object could also be passed to the |
|
| 267 |
/// However, an external elevator object could also be passed to the |
|
| 268 | 268 |
/// algorithm with the \ref elevator(Elevator&) "elevator()" function |
| 269 | 269 |
/// before calling \ref run() or \ref init(). |
| 270 | 270 |
/// \sa SetElevator |
| 271 | 271 |
template <typename T> |
| 272 | 272 |
struct SetStandardElevator |
| 273 | 273 |
: public Preflow<Digraph, CapacityMap, |
| 274 | 274 |
SetStandardElevatorTraits<T> > {
|
| 275 | 275 |
typedef Preflow<Digraph, CapacityMap, |
| 276 | 276 |
SetStandardElevatorTraits<T> > Create; |
| 277 | 277 |
}; |
| 278 | 278 |
|
| 279 | 279 |
/// @} |
| 280 | 280 |
|
| 281 | 281 |
protected: |
| 282 | 282 |
|
| 283 | 283 |
Preflow() {}
|
| 284 | 284 |
|
| 285 | 285 |
public: |
| 286 | 286 |
|
| 287 | 287 |
|
| 288 | 288 |
/// \brief The constructor of the class. |
| 289 | 289 |
/// |
| 290 | 290 |
/// The constructor of the class. |
| 291 | 291 |
/// \param digraph The digraph the algorithm runs on. |
| ... | ... |
@@ -354,49 +354,49 @@ |
| 354 | 354 |
///equivalent of the following. |
| 355 | 355 |
///\code |
| 356 | 356 |
/// while(t.running()) t.stop() |
| 357 | 357 |
///\endcode |
| 358 | 358 |
/// |
| 359 | 359 |
/// |
| 360 | 360 |
///\sa stop() |
| 361 | 361 |
///\sa restart() |
| 362 | 362 |
///\sa reset() |
| 363 | 363 |
|
| 364 | 364 |
void halt() |
| 365 | 365 |
{
|
| 366 | 366 |
if(_running) {
|
| 367 | 367 |
_running=0; |
| 368 | 368 |
TimeStamp t; |
| 369 | 369 |
t.stamp(); |
| 370 | 370 |
start_time=t-start_time; |
| 371 | 371 |
} |
| 372 | 372 |
} |
| 373 | 373 |
|
| 374 | 374 |
///Returns the running state of the timer |
| 375 | 375 |
|
| 376 | 376 |
///This function returns the number of stop() exections that is |
| 377 | 377 |
///necessary to really stop the timer. |
| 378 |
///For example the timer |
|
| 378 |
///For example, the timer |
|
| 379 | 379 |
///is running if and only if the return value is \c true |
| 380 | 380 |
///(i.e. greater than |
| 381 | 381 |
///zero). |
| 382 | 382 |
int running() { return _running; }
|
| 383 | 383 |
|
| 384 | 384 |
|
| 385 | 385 |
///Restart the time counters |
| 386 | 386 |
|
| 387 | 387 |
///This function is a shorthand for |
| 388 | 388 |
///a reset() and a start() calls. |
| 389 | 389 |
/// |
| 390 | 390 |
void restart() |
| 391 | 391 |
{
|
| 392 | 392 |
reset(); |
| 393 | 393 |
start(); |
| 394 | 394 |
} |
| 395 | 395 |
|
| 396 | 396 |
///@} |
| 397 | 397 |
|
| 398 | 398 |
///\name Query Functions for the Ellapsed Time |
| 399 | 399 |
|
| 400 | 400 |
///@{
|
| 401 | 401 |
|
| 402 | 402 |
///Gives back the ellapsed user time of the process |
| ... | ... |
@@ -22,49 +22,49 @@ |
| 22 | 22 |
//!\ingroup auxdat |
| 23 | 23 |
//!\file |
| 24 | 24 |
//!\brief Union-Find data structures. |
| 25 | 25 |
//! |
| 26 | 26 |
|
| 27 | 27 |
#include <vector> |
| 28 | 28 |
#include <list> |
| 29 | 29 |
#include <utility> |
| 30 | 30 |
#include <algorithm> |
| 31 | 31 |
#include <functional> |
| 32 | 32 |
|
| 33 | 33 |
#include <lemon/core.h> |
| 34 | 34 |
|
| 35 | 35 |
namespace lemon {
|
| 36 | 36 |
|
| 37 | 37 |
/// \ingroup auxdat |
| 38 | 38 |
/// |
| 39 | 39 |
/// \brief A \e Union-Find data structure implementation |
| 40 | 40 |
/// |
| 41 | 41 |
/// The class implements the \e Union-Find data structure. |
| 42 | 42 |
/// The union operation uses rank heuristic, while |
| 43 | 43 |
/// the find operation uses path compression. |
| 44 | 44 |
/// This is a very simple but efficient implementation, providing |
| 45 | 45 |
/// only four methods: join (union), find, insert and size. |
| 46 |
/// For more features see the \ref UnionFindEnum class. |
|
| 46 |
/// For more features, see the \ref UnionFindEnum class. |
|
| 47 | 47 |
/// |
| 48 | 48 |
/// It is primarily used in Kruskal algorithm for finding minimal |
| 49 | 49 |
/// cost spanning tree in a graph. |
| 50 | 50 |
/// \sa kruskal() |
| 51 | 51 |
/// |
| 52 | 52 |
/// \pre You need to add all the elements by the \ref insert() |
| 53 | 53 |
/// method. |
| 54 | 54 |
template <typename IM> |
| 55 | 55 |
class UnionFind {
|
| 56 | 56 |
public: |
| 57 | 57 |
|
| 58 | 58 |
///\e |
| 59 | 59 |
typedef IM ItemIntMap; |
| 60 | 60 |
///\e |
| 61 | 61 |
typedef typename ItemIntMap::Key Item; |
| 62 | 62 |
|
| 63 | 63 |
private: |
| 64 | 64 |
// If the items vector stores negative value for an item then |
| 65 | 65 |
// that item is root item and it has -items[it] component size. |
| 66 | 66 |
// Else the items[it] contains the index of the parent. |
| 67 | 67 |
std::vector<int> items; |
| 68 | 68 |
ItemIntMap& index; |
| 69 | 69 |
|
| 70 | 70 |
bool rep(int idx) const {
|
0 comments (0 inline)