/* -*- mode: C++; indent-tabs-mode: nil; -*-
*
* This file is a part of LEMON, a generic C++ optimization library.
*
* Copyright (C) 2003-2009
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
* (Egervary Research Group on Combinatorial Optimization, EGRES).
*
* Permission to use, modify and distribute this software is granted
* provided that this copyright notice appears in all copies. For
* precise terms see the accompanying LICENSE file.
*
* This software is provided "AS IS" with no warranty of any kind,
* express or implied, and with no claim as to its suitability for any
* purpose.
*
*/
namespace lemon {
/**
@defgroup datas Data Structures
This group contains the several data structures implemented in LEMON.
*/
/**
@defgroup graphs Graph Structures
@ingroup datas
\brief Graph structures implemented in LEMON.
The implementation of combinatorial algorithms heavily relies on
efficient graph implementations. LEMON offers data structures which are
planned to be easily used in an experimental phase of implementation studies,
and thereafter the program code can be made efficient by small modifications.
The most efficient implementation of diverse applications require the
usage of different physical graph implementations. These differences
appear in the size of graph we require to handle, memory or time usage
limitations or in the set of operations through which the graph can be
accessed. LEMON provides several physical graph structures to meet
the diverging requirements of the possible users. In order to save on
running time or on memory usage, some structures may fail to provide
some graph features like arc/edge or node deletion.
Alteration of standard containers need a very limited number of
operations, these together satisfy the everyday requirements.
In the case of graph structures, different operations are needed which do
not alter the physical graph, but gives another view. If some nodes or
arcs have to be hidden or the reverse oriented graph have to be used, then
this is the case. It also may happen that in a flow implementation
the residual graph can be accessed by another algorithm, or a node-set
is to be shrunk for another algorithm.
LEMON also provides a variety of graphs for these requirements called
\ref graph_adaptors "graph adaptors". Adaptors cannot be used alone but only
in conjunction with other graph representations.
You are free to use the graph structure that fit your requirements
the best, most graph algorithms and auxiliary data structures can be used
with any graph structure.
**See also:** \ref graph_concepts "Graph Structure Concepts".
*/
/**
@defgroup graph_adaptors Adaptor Classes for Graphs
@ingroup graphs
\brief Adaptor classes for digraphs and graphs
This group contains several useful adaptor classes for digraphs and graphs.
The main parts of LEMON are the different graph structures, generic
graph algorithms, graph concepts, which couple them, and graph
adaptors. While the previous notions are more or less clear, the
latter one needs further explanation. Graph adaptors are graph classes
which serve for considering graph structures in different ways.
A short example makes this much clearer. Suppose that we have an
instance \c g of a directed graph type, say ListDigraph and an algorithm
\code
template
int algorithm(const Digraph&);
\endcode
is needed to run on the reverse oriented graph. It may be expensive
(in time or in memory usage) to copy \c g with the reversed
arcs. In this case, an adaptor class is used, which (according
to LEMON \ref concepts::Digraph "digraph concepts") works as a digraph.
The adaptor uses the original digraph structure and digraph operations when
methods of the reversed oriented graph are called. This means that the adaptor
have minor memory usage, and do not perform sophisticated algorithmic
actions. The purpose of it is to give a tool for the cases when a
graph have to be used in a specific alteration. If this alteration is
obtained by a usual construction like filtering the node or the arc set or
considering a new orientation, then an adaptor is worthwhile to use.
To come back to the reverse oriented graph, in this situation
\code
template class ReverseDigraph;
\endcode
template class can be used. The code looks as follows
\code
ListDigraph g;
ReverseDigraph rg(g);
int result = algorithm(rg);
\endcode
During running the algorithm, the original digraph \c g is untouched.
This techniques give rise to an elegant code, and based on stable
graph adaptors, complex algorithms can be implemented easily.
In flow, circulation and matching problems, the residual
graph is of particular importance. Combining an adaptor implementing
this with shortest path algorithms or minimum mean cycle algorithms,
a range of weighted and cardinality optimization algorithms can be
obtained. For other examples, the interested user is referred to the
detailed documentation of particular adaptors.
The behavior of graph adaptors can be very different. Some of them keep
capabilities of the original graph while in other cases this would be
meaningless. This means that the concepts that they meet depend
on the graph adaptor, and the wrapped graph.
For example, if an arc of a reversed digraph is deleted, this is carried
out by deleting the corresponding arc of the original digraph, thus the
adaptor modifies the original digraph.
However in case of a residual digraph, this operation has no sense.
Let us stand one more example here to simplify your work.
ReverseDigraph has constructor
\code
ReverseDigraph(Digraph& digraph);
\endcode
This means that in a situation, when a `const %ListDigraph&`
reference to a graph is given, then it have to be instantiated with
`Digraph=const %ListDigraph`.
\code
int algorithm1(const ListDigraph& g) {
ReverseDigraph rg(g);
return algorithm2(rg);
}
\endcode
*/
/**
@defgroup semi_adaptors Semi-Adaptor Classes for Graphs
@ingroup graphs
\brief Graph types between real graphs and graph adaptors.
This group contains some graph types between real graphs and graph adaptors.
These classes wrap graphs to give new functionality as the adaptors do it.
On the other hand they are not light-weight structures as the adaptors.
*/
/**
@defgroup maps Maps
@ingroup datas
\brief Map structures implemented in LEMON.
This group contains the map structures implemented in LEMON.
LEMON provides several special purpose maps and map adaptors that e.g. combine
new maps from existing ones.
**See also:** \ref map_concepts "Map Concepts".
*/
/**
@defgroup graph_maps Graph Maps
@ingroup maps
\brief Special graph-related maps.
This group contains maps that are specifically designed to assign
values to the nodes and arcs/edges of graphs.
If you are looking for the standard graph maps (\c NodeMap, \c ArcMap,
\c EdgeMap), see the \ref graph_concepts "Graph Structure Concepts".
*/
/**
\defgroup map_adaptors Map Adaptors
\ingroup maps
\brief Tools to create new maps from existing ones
This group contains map adaptors that are used to create "implicit"
maps from other maps.
Most of them are \ref concepts::ReadMap "read-only maps".
They can make arithmetic and logical operations between one or two maps
(negation, shifting, addition, multiplication, logical 'and', 'or',
'not' etc.) or e.g. convert a map to another one of different Value type.
The typical usage of this classes is passing implicit maps to
algorithms. If a function type algorithm is called then the function
type map adaptors can be used comfortable. For example let's see the
usage of map adaptors with the \c graphToEps() function.
\code
Color nodeColor(int deg) {
if (deg >= 2) {
return Color(0.5, 0.0, 0.5);
} else if (deg == 1) {
return Color(1.0, 0.5, 1.0);
} else {
return Color(0.0, 0.0, 0.0);
}
}
Digraph::NodeMap degree_map(graph);
graphToEps(graph, "graph.eps")
.coords(coords).scaleToA4().undirected()
.nodeColors(composeMap(functorToMap(nodeColor), degree_map))
.run();
\endcode
The \c functorToMap() function makes an \c int to \c Color map from the
\c nodeColor() function. The \c composeMap() compose the \c degree_map
and the previously created map. The composed map is a proper function to
get the color of each node.
The usage with class type algorithms is little bit harder. In this
case the function type map adaptors can not be used, because the
function map adaptors give back temporary objects.
\code
Digraph graph;
typedef Digraph::ArcMap DoubleArcMap;
DoubleArcMap length(graph);
DoubleArcMap speed(graph);
typedef DivMap TimeMap;
TimeMap time(length, speed);
Dijkstra dijkstra(graph, time);
dijkstra.run(source, target);
\endcode
We have a length map and a maximum speed map on the arcs of a digraph.
The minimum time to pass the arc can be calculated as the division of
the two maps which can be done implicitly with the \c DivMap template
class. We use the implicit minimum time map as the length map of the
\c Dijkstra algorithm.
*/
/**
@defgroup matrices Matrices
@ingroup datas
\brief Two dimensional data storages implemented in LEMON.
This group contains two dimensional data storages implemented in LEMON.
*/
/**
@defgroup paths Path Structures
@ingroup datas
\brief %Path structures implemented in LEMON.
This group contains the path structures implemented in LEMON.
LEMON provides flexible data structures to work with paths.
All of them have similar interfaces and they can be copied easily with
assignment operators and copy constructors. This makes it easy and
efficient to have e.g. the Dijkstra algorithm to store its result in
any kind of path structure.
\sa lemon::concepts::Path
*/
/**
@defgroup auxdat Auxiliary Data Structures
@ingroup datas
\brief Auxiliary data structures implemented in LEMON.
This group contains some data structures implemented in LEMON in
order to make it easier to implement combinatorial algorithms.
*/
/**
@defgroup algs Algorithms
\brief This group contains the several algorithms
implemented in LEMON.
This group contains the several algorithms
implemented in LEMON.
*/
/**
@defgroup search Graph Search
@ingroup algs
\brief Common graph search algorithms.
This group contains the common graph search algorithms, namely
\e breadth-first \e search (BFS) and \e depth-first \e search (DFS).
*/
/**
@defgroup shortest_path Shortest Path Algorithms
@ingroup algs
\brief Algorithms for finding shortest paths.
This group contains the algorithms for finding shortest paths in digraphs.
- \ref Dijkstra algorithm for finding shortest paths from a source node
when all arc lengths are non-negative.
- \ref BellmanFord "Bellman-Ford" algorithm for finding shortest paths
from a source node when arc lenghts can be either positive or negative,
but the digraph should not contain directed cycles with negative total
length.
- \ref FloydWarshall "Floyd-Warshall" and \ref Johnson "Johnson" algorithms
for solving the \e all-pairs \e shortest \e paths \e problem when arc
lenghts can be either positive or negative, but the digraph should
not contain directed cycles with negative total length.
- \ref Suurballe A successive shortest path algorithm for finding
arc-disjoint paths between two nodes having minimum total length.
*/
/**
@defgroup max_flow Maximum Flow Algorithms
@ingroup algs
\brief Algorithms for finding maximum flows.
This group contains the algorithms for finding maximum flows and
feasible circulations.
The \e maximum \e flow \e problem is to find a flow of maximum value between
a single source and a single target. Formally, there is a \f$G=(V,A)\f$
digraph, a \f$cap: A\rightarrow\mathbf{R}^+_0\f$ capacity function and
\f$s, t \in V\f$ source and target nodes.
A maximum flow is an \f$f: A\rightarrow\mathbf{R}^+_0\f$ solution of the
following optimization problem.
\f[ \max\sum_{sv\in A} f(sv) - \sum_{vs\in A} f(vs) \f]
\f[ \sum_{uv\in A} f(uv) = \sum_{vu\in A} f(vu)
\quad \forall u\in V\setminus\{s,t\} \f]
\f[ 0 \leq f(uv) \leq cap(uv) \quad \forall uv\in A \f]
LEMON contains several algorithms for solving maximum flow problems:
- \ref EdmondsKarp Edmonds-Karp algorithm.
- \ref Preflow Goldberg-Tarjan's preflow push-relabel algorithm.
- \ref DinitzSleatorTarjan Dinitz's blocking flow algorithm with dynamic trees.
- \ref GoldbergTarjan Preflow push-relabel algorithm with dynamic trees.
In most cases the \ref Preflow "Preflow" algorithm provides the
fastest method for computing a maximum flow. All implementations
also provide functions to query the minimum cut, which is the dual
problem of maximum flow.
\ref Circulation is a preflow push-relabel algorithm implemented directly
for finding feasible circulations, which is a somewhat different problem,
but it is strongly related to maximum flow.
For more information, see \ref Circulation.
*/
/**
@defgroup min_cost_flow Minimum Cost Flow Algorithms
@ingroup algs
\brief Algorithms for finding minimum cost flows and circulations.
This group contains the algorithms for finding minimum cost flows and
circulations.
The \e minimum \e cost \e flow \e problem is to find a feasible flow of
minimum total cost from a set of supply nodes to a set of demand nodes
in a network with capacity constraints (lower and upper bounds)
and arc costs.
Formally, let \f$G=(V,A)\f$ be a digraph, \f$lower: A\rightarrow\mathbf{Z}\f$,
\f$upper: A\rightarrow\mathbf{Z}\cup\{+\infty\}\f$ denote the lower and
upper bounds for the flow values on the arcs, for which
\f$lower(uv) \leq upper(uv)\f$ must hold for all \f$uv\in A\f$,
\f$cost: A\rightarrow\mathbf{Z}\f$ denotes the cost per unit flow
on the arcs and \f$sup: V\rightarrow\mathbf{Z}\f$ denotes the
signed supply values of the nodes.
If \f$sup(u)>0\f$, then \f$u\f$ is a supply node with \f$sup(u)\f$
supply, if \f$sup(u)<0\f$, then \f$u\f$ is a demand node with
\f$-sup(u)\f$ demand.
A minimum cost flow is an \f$f: A\rightarrow\mathbf{Z}\f$ solution
of the following optimization problem.
\f[ \min\sum_{uv\in A} f(uv) \cdot cost(uv) \f]
\f[ \sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \geq
sup(u) \quad \forall u\in V \f]
\f[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A \f]
The sum of the supply values, i.e. \f$\sum_{u\in V} sup(u)\f$ must be
zero or negative in order to have a feasible solution (since the sum
of the expressions on the left-hand side of the inequalities is zero).
It means that the total demand must be greater or equal to the total
supply and all the supplies have to be carried out from the supply nodes,
but there could be demands that are not satisfied.
If \f$\sum_{u\in V} sup(u)\f$ is zero, then all the supply/demand
constraints have to be satisfied with equality, i.e. all demands
have to be satisfied and all supplies have to be used.
If you need the opposite inequalities in the supply/demand constraints
(i.e. the total demand is less than the total supply and all the demands
have to be satisfied while there could be supplies that are not used),
then you could easily transform the problem to the above form by reversing
the direction of the arcs and taking the negative of the supply values
(e.g. using \ref ReverseDigraph and \ref NegMap adaptors).
However \ref NetworkSimplex algorithm also supports this form directly
for the sake of convenience.
A feasible solution for this problem can be found using \ref Circulation.
Note that the above formulation is actually more general than the usual
definition of the minimum cost flow problem, in which strict equalities
are required in the supply/demand contraints, i.e.
\f[ \sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) =
sup(u) \quad \forall u\in V. \f]
However if the sum of the supply values is zero, then these two problems
are equivalent. So if you need the equality form, you have to ensure this
additional contraint for the algorithms.
The dual solution of the minimum cost flow problem is represented by node
potentials \f$\pi: V\rightarrow\mathbf{Z}\f$.
An \f$f: A\rightarrow\mathbf{Z}\f$ feasible solution of the problem
is optimal if and only if for some \f$\pi: V\rightarrow\mathbf{Z}\f$
node potentials the following \e complementary \e slackness optimality
conditions hold.
- For all \f$uv\in A\f$ arcs:
- if \f$cost^\pi(uv)>0\f$, then \f$f(uv)=lower(uv)\f$;
- if \f$lower(uv)typedefs etc. an
implementation of the %concepts should provide, however completely
without implementations and real data structures behind the
interface. On the other hand they should provide nothing else. All
the algorithms working on a data structure meeting a certain concept
should compile with these classes. (Though it will not run properly,
of course.) In this way it is easily to check if an algorithm
doesn't use any extra feature of a certain implementation.
- The concept descriptor classes also provide a *checker class*
that makes it possible to check whether a certain implementation of a
concept indeed provides all the required features.
- Finally, They can serve as a skeleton of a new implementation of a concept.
*/
/**
@defgroup graph_concepts Graph Structure Concepts
@ingroup concept
\brief Skeleton and concept checking classes for graph structures
This group contains the skeletons and concept checking classes of LEMON's
graph structures and helper classes used to implement these.
*/
/**
@defgroup map_concepts Map Concepts
@ingroup concept
\brief Skeleton and concept checking classes for maps
This group contains the skeletons and concept checking classes of maps.
*/
/**
\anchor demoprograms
@defgroup demos Demo Programs
Some demo programs are listed here. Their full source codes can be found in
the \c demo subdirectory of the source tree.
In order to compile them, use the `make demo` or the
`make check` commands.
*/
/**
@defgroup tools Standalone Utility Applications
Some utility applications are listed here.
The standard compilation procedure (`./configure;make`) will compile
them, as well.
*/
}