!
!
!
9
5
1
1
1
1
1
1
3
2
9
5
1
1
1
1
1
1
1
1
1
1
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 demos |
| 20 | 20 |
///\file |
| 21 | 21 |
///\brief Argument parser demo |
| 22 | 22 |
/// |
| 23 | 23 |
/// This example shows how the argument parser can be used. |
| 24 | 24 |
/// |
| 25 | 25 |
/// \include arg_parser_demo.cc |
| 26 | 26 |
|
| 27 | 27 |
#include <lemon/arg_parser.h> |
| 28 | 28 |
|
| 29 | 29 |
using namespace lemon; |
| 30 | 30 |
int main(int argc, char **argv) |
| 31 | 31 |
{
|
| 32 | 32 |
// Initialize the argument parser |
| 33 | 33 |
ArgParser ap(argc, argv); |
| 34 | 34 |
int i; |
| 35 | 35 |
std::string s; |
| 36 | 36 |
double d = 1.0; |
| 37 | 37 |
bool b, nh; |
| 38 | 38 |
bool g1, g2, g3; |
| 39 | 39 |
|
| 40 | 40 |
// Add a mandatory integer option with storage reference |
| 41 | 41 |
ap.refOption("n", "An integer input.", i, true);
|
| 42 | 42 |
// Add a double option with storage reference (the default value is 1.0) |
| 43 | 43 |
ap.refOption("val", "A double input.", d);
|
| 44 | 44 |
// Add a double option without storage reference (the default value is 3.14) |
| 45 | 45 |
ap.doubleOption("val2", "A double input.", 3.14);
|
| 46 | 46 |
// Set synonym for -val option |
| 47 | 47 |
ap.synonym("vals", "val");
|
| 48 | 48 |
// Add a string option |
| 49 | 49 |
ap.refOption("name", "A string input.", s);
|
| 50 | 50 |
// Add bool options |
| 51 | 51 |
ap.refOption("f", "A switch.", b)
|
| 52 | 52 |
.refOption("nohelp", "", nh)
|
| 53 | 53 |
.refOption("gra", "Choice A", g1)
|
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
namespace lemon {
|
| 20 | 20 |
|
| 21 | 21 |
/** |
| 22 | 22 |
@defgroup datas Data Structures |
| 23 | 23 |
This group contains the several data structures implemented in LEMON. |
| 24 | 24 |
*/ |
| 25 | 25 |
|
| 26 | 26 |
/** |
| 27 | 27 |
@defgroup graphs Graph Structures |
| 28 | 28 |
@ingroup datas |
| 29 | 29 |
\brief Graph structures implemented in LEMON. |
| 30 | 30 |
|
| 31 | 31 |
The implementation of combinatorial algorithms heavily relies on |
| 32 | 32 |
efficient graph implementations. LEMON offers data structures which are |
| 33 | 33 |
planned to be easily used in an experimental phase of implementation studies, |
| 34 | 34 |
and thereafter the program code can be made efficient by small modifications. |
| 35 | 35 |
|
| 36 | 36 |
The most efficient implementation of diverse applications require the |
| 37 | 37 |
usage of different physical graph implementations. These differences |
| 38 | 38 |
appear in the size of graph we require to handle, memory or time usage |
| 39 | 39 |
limitations or in the set of operations through which the graph can be |
| 40 | 40 |
accessed. LEMON provides several physical graph structures to meet |
| 41 | 41 |
the diverging requirements of the possible users. In order to save on |
| 42 | 42 |
running time or on memory usage, some structures may fail to provide |
| 43 | 43 |
some graph features like arc/edge or node deletion. |
| 44 | 44 |
|
| 45 | 45 |
Alteration of standard containers need a very limited number of |
| 46 | 46 |
operations, these together satisfy the everyday requirements. |
| 47 | 47 |
In the case of graph structures, different operations are needed which do |
| 48 | 48 |
not alter the physical graph, but gives another view. If some nodes or |
| 49 | 49 |
arcs have to be hidden or the reverse oriented graph have to be used, then |
| 50 | 50 |
this is the case. It also may happen that in a flow implementation |
| 51 | 51 |
the residual graph can be accessed by another algorithm, or a node-set |
| 52 | 52 |
is to be shrunk for another algorithm. |
| 53 | 53 |
LEMON also provides a variety of graphs for these requirements called |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
/** |
| 20 | 20 |
\mainpage LEMON Documentation |
| 21 | 21 |
|
| 22 | 22 |
\section intro Introduction |
| 23 | 23 |
|
| 24 | 24 |
<b>LEMON</b> stands for <i><b>L</b>ibrary for <b>E</b>fficient <b>M</b>odeling |
| 25 | 25 |
and <b>O</b>ptimization in <b>N</b>etworks</i>. |
| 26 | 26 |
It is a C++ template library providing efficient implementations of common |
| 27 | 27 |
data structures and algorithms with focus on combinatorial optimization |
| 28 | 28 |
tasks connected mainly with graphs and networks. |
| 29 | 29 |
|
| 30 | 30 |
<b> |
| 31 | 31 |
LEMON is an <a class="el" href="http://opensource.org/">open source</a> |
| 32 | 32 |
project. |
| 33 | 33 |
You are free to use it in your commercial or |
| 34 | 34 |
non-commercial applications under very permissive |
| 35 | 35 |
\ref license "license terms". |
| 36 | 36 |
</b> |
| 37 | 37 |
|
| 38 | 38 |
The project is maintained by the |
| 39 | 39 |
<a href="http://www.cs.elte.hu/egres/">Egerváry Research Group on |
| 40 | 40 |
Combinatorial Optimization</a> \ref egres |
| 41 | 41 |
at the Operations Research Department of the |
| 42 | 42 |
<a href="http://www.elte.hu/en/">Eötvös Loránd University</a>, |
| 43 | 43 |
Budapest, Hungary. |
| 44 | 44 |
LEMON is also a member of the <a href="http://www.coin-or.org/">COIN-OR</a> |
| 45 | 45 |
initiative \ref coinor. |
| 46 | 46 |
|
| 47 | 47 |
\section howtoread How to Read the Documentation |
| 48 | 48 |
|
| 49 | 49 |
If you would like to get to know the library, see |
| 50 | 50 |
<a class="el" href="http://lemon.cs.elte.hu/pub/tutorial/">LEMON Tutorial</a>. |
| 51 | 51 |
|
| 52 | 52 |
If you are interested in starting to use the library, see the <a class="el" |
| 53 | 53 |
href="http://lemon.cs.elte.hu/trac/lemon/wiki/InstallGuide/">Installation |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
namespace lemon {
|
| 20 | 20 |
|
| 21 | 21 |
/** |
| 22 | 22 |
\page min_cost_flow Minimum Cost Flow Problem |
| 23 | 23 |
|
| 24 | 24 |
\section mcf_def Definition (GEQ form) |
| 25 | 25 |
|
| 26 | 26 |
The \e minimum \e cost \e flow \e problem is to find a feasible flow of |
| 27 | 27 |
minimum total cost from a set of supply nodes to a set of demand nodes |
| 28 | 28 |
in a network with capacity constraints (lower and upper bounds) |
| 29 | 29 |
and arc costs \ref amo93networkflows. |
| 30 | 30 |
|
| 31 | 31 |
Formally, let \f$G=(V,A)\f$ be a digraph, \f$lower: A\rightarrow\mathbf{R}\f$,
|
| 32 | 32 |
\f$upper: A\rightarrow\mathbf{R}\cup\{+\infty\}\f$ denote the lower and
|
| 33 | 33 |
upper bounds for the flow values on the arcs, for which |
| 34 | 34 |
\f$lower(uv) \leq upper(uv)\f$ must hold for all \f$uv\in A\f$, |
| 35 | 35 |
\f$cost: A\rightarrow\mathbf{R}\f$ denotes the cost per unit flow
|
| 36 | 36 |
on the arcs and \f$sup: V\rightarrow\mathbf{R}\f$ denotes the
|
| 37 | 37 |
signed supply values of the nodes. |
| 38 | 38 |
If \f$sup(u)>0\f$, then \f$u\f$ is a supply node with \f$sup(u)\f$ |
| 39 | 39 |
supply, if \f$sup(u)<0\f$, then \f$u\f$ is a demand node with |
| 40 | 40 |
\f$-sup(u)\f$ demand. |
| 41 | 41 |
A minimum cost flow is an \f$f: A\rightarrow\mathbf{R}\f$ solution
|
| 42 | 42 |
of the following optimization problem. |
| 43 | 43 |
|
| 44 | 44 |
\f[ \min\sum_{uv\in A} f(uv) \cdot cost(uv) \f]
|
| 45 | 45 |
\f[ \sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \geq
|
| 46 | 46 |
sup(u) \quad \forall u\in V \f] |
| 47 | 47 |
\f[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A \f] |
| 48 | 48 |
|
| 49 | 49 |
The sum of the supply values, i.e. \f$\sum_{u\in V} sup(u)\f$ must be
|
| 50 | 50 |
zero or negative in order to have a feasible solution (since the sum |
| 51 | 51 |
of the expressions on the left-hand side of the inequalities is zero). |
| 52 | 52 |
It means that the total demand must be greater or equal to the total |
| 53 | 53 |
supply and all the supplies have to be carried out from the supply nodes, |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_ADAPTORS_H |
| 20 | 20 |
#define LEMON_ADAPTORS_H |
| 21 | 21 |
|
| 22 | 22 |
/// \ingroup graph_adaptors |
| 23 | 23 |
/// \file |
| 24 | 24 |
/// \brief Adaptor classes for digraphs and graphs |
| 25 | 25 |
/// |
| 26 | 26 |
/// This file contains several useful adaptors for digraphs and graphs. |
| 27 | 27 |
|
| 28 | 28 |
#include <lemon/core.h> |
| 29 | 29 |
#include <lemon/maps.h> |
| 30 | 30 |
#include <lemon/bits/variant.h> |
| 31 | 31 |
|
| 32 | 32 |
#include <lemon/bits/graph_adaptor_extender.h> |
| 33 | 33 |
#include <lemon/bits/map_extender.h> |
| 34 | 34 |
#include <lemon/tolerance.h> |
| 35 | 35 |
|
| 36 | 36 |
#include <algorithm> |
| 37 | 37 |
|
| 38 | 38 |
namespace lemon {
|
| 39 | 39 |
|
| 40 | 40 |
#ifdef _MSC_VER |
| 41 | 41 |
#define LEMON_SCOPE_FIX(OUTER, NESTED) OUTER::NESTED |
| 42 | 42 |
#else |
| 43 | 43 |
#define LEMON_SCOPE_FIX(OUTER, NESTED) typename OUTER::template NESTED |
| 44 | 44 |
#endif |
| 45 | 45 |
|
| 46 | 46 |
template<typename DGR> |
| 47 | 47 |
class DigraphAdaptorBase {
|
| 48 | 48 |
public: |
| 49 | 49 |
typedef DGR Digraph; |
| 50 | 50 |
typedef DigraphAdaptorBase Adaptor; |
| 51 | 51 |
|
| 52 | 52 |
protected: |
| 53 | 53 |
DGR* _digraph; |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <lemon/arg_parser.h> |
| 20 | 20 |
|
| 21 | 21 |
namespace lemon {
|
| 22 | 22 |
|
| 23 | 23 |
void ArgParser::_terminate(ArgParserException::Reason reason) const |
| 24 | 24 |
{
|
| 25 | 25 |
if(_exit_on_problems) |
| 26 | 26 |
exit(1); |
| 27 | 27 |
else throw(ArgParserException(reason)); |
| 28 | 28 |
} |
| 29 | 29 |
|
| 30 | 30 |
|
| 31 | 31 |
void ArgParser::_showHelp(void *p) |
| 32 | 32 |
{
|
| 33 | 33 |
(static_cast<ArgParser*>(p))->showHelp(); |
| 34 | 34 |
(static_cast<ArgParser*>(p))->_terminate(ArgParserException::HELP); |
| 35 | 35 |
} |
| 36 | 36 |
|
| 37 | 37 |
ArgParser::ArgParser(int argc, const char * const *argv) |
| 38 | 38 |
:_argc(argc), _argv(argv), _command_name(argv[0]), |
| 39 | 39 |
_exit_on_problems(true) {
|
| 40 | 40 |
funcOption("-help","Print a short help message",_showHelp,this);
|
| 41 | 41 |
synonym("help","-help");
|
| 42 | 42 |
synonym("h","-help");
|
| 43 | 43 |
} |
| 44 | 44 |
|
| 45 | 45 |
ArgParser::~ArgParser() |
| 46 | 46 |
{
|
| 47 | 47 |
for(Opts::iterator i=_opts.begin();i!=_opts.end();++i) |
| 48 | 48 |
if(i->second.self_delete) |
| 49 | 49 |
switch(i->second.type) {
|
| 50 | 50 |
case BOOL: |
| 51 | 51 |
delete i->second.bool_p; |
| 52 | 52 |
break; |
| 53 | 53 |
case STRING: |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_ARG_PARSER_H |
| 20 | 20 |
#define LEMON_ARG_PARSER_H |
| 21 | 21 |
|
| 22 | 22 |
#include <vector> |
| 23 | 23 |
#include <map> |
| 24 | 24 |
#include <list> |
| 25 | 25 |
#include <string> |
| 26 | 26 |
#include <iostream> |
| 27 | 27 |
#include <sstream> |
| 28 | 28 |
#include <algorithm> |
| 29 | 29 |
#include <lemon/assert.h> |
| 30 | 30 |
|
| 31 | 31 |
///\ingroup misc |
| 32 | 32 |
///\file |
| 33 | 33 |
///\brief A tool to parse command line arguments. |
| 34 | 34 |
|
| 35 | 35 |
namespace lemon {
|
| 36 | 36 |
|
| 37 | 37 |
///Exception used by ArgParser |
| 38 | 38 |
class ArgParserException : public Exception {
|
| 39 | 39 |
public: |
| 40 | 40 |
enum Reason {
|
| 41 | 41 |
HELP, /// <tt>--help</tt> option was given |
| 42 | 42 |
UNKNOWN_OPT, /// Unknown option was given |
| 43 | 43 |
INVALID_OPT /// Invalid combination of options |
| 44 | 44 |
}; |
| 45 | 45 |
|
| 46 | 46 |
private: |
| 47 | 47 |
Reason _reason; |
| 48 | 48 |
|
| 49 | 49 |
public: |
| 50 | 50 |
///Constructor |
| 51 | 51 |
ArgParserException(Reason r) throw() : _reason(r) {}
|
| 52 | 52 |
///Virtual destructor |
| 53 | 53 |
virtual ~ArgParserException() throw() {}
|
| 1 |
/* -*- C++ -*- |
|
| 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
| 2 | 2 |
* |
| 3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
| 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_BELLMAN_FORD_H |
| 20 | 20 |
#define LEMON_BELLMAN_FORD_H |
| 21 | 21 |
|
| 22 | 22 |
/// \ingroup shortest_path |
| 23 | 23 |
/// \file |
| 24 | 24 |
/// \brief Bellman-Ford algorithm. |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/list_graph.h> |
| 27 | 27 |
#include <lemon/bits/path_dump.h> |
| 28 | 28 |
#include <lemon/core.h> |
| 29 | 29 |
#include <lemon/error.h> |
| 30 | 30 |
#include <lemon/maps.h> |
| 31 | 31 |
#include <lemon/tolerance.h> |
| 32 | 32 |
#include <lemon/path.h> |
| 33 | 33 |
|
| 34 | 34 |
#include <limits> |
| 35 | 35 |
|
| 36 | 36 |
namespace lemon {
|
| 37 | 37 |
|
| 38 | 38 |
/// \brief Default operation traits for the BellmanFord algorithm class. |
| 39 | 39 |
/// |
| 40 | 40 |
/// This operation traits class defines all computational operations |
| 41 | 41 |
/// and constants that are used in the Bellman-Ford algorithm. |
| 42 | 42 |
/// The default implementation is based on the \c numeric_limits class. |
| 43 | 43 |
/// If the numeric type does not have infinity value, then the maximum |
| 44 | 44 |
/// value is used as extremal infinity value. |
| 45 | 45 |
/// |
| 46 | 46 |
/// \see BellmanFordToleranceOperationTraits |
| 47 | 47 |
template < |
| 48 | 48 |
typename V, |
| 49 | 49 |
bool has_inf = std::numeric_limits<V>::has_infinity> |
| 50 | 50 |
struct BellmanFordDefaultOperationTraits {
|
| 51 | 51 |
/// \brief Value type for the algorithm. |
| 52 | 52 |
typedef V Value; |
| 53 | 53 |
/// \brief Gives back the zero value of the type. |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_BFS_H |
| 20 | 20 |
#define LEMON_BFS_H |
| 21 | 21 |
|
| 22 | 22 |
///\ingroup search |
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief BFS algorithm. |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/list_graph.h> |
| 27 | 27 |
#include <lemon/bits/path_dump.h> |
| 28 | 28 |
#include <lemon/core.h> |
| 29 | 29 |
#include <lemon/error.h> |
| 30 | 30 |
#include <lemon/maps.h> |
| 31 | 31 |
#include <lemon/path.h> |
| 32 | 32 |
|
| 33 | 33 |
namespace lemon {
|
| 34 | 34 |
|
| 35 | 35 |
///Default traits class of Bfs class. |
| 36 | 36 |
|
| 37 | 37 |
///Default traits class of Bfs class. |
| 38 | 38 |
///\tparam GR Digraph type. |
| 39 | 39 |
template<class GR> |
| 40 | 40 |
struct BfsDefaultTraits |
| 41 | 41 |
{
|
| 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 | 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 |
///It must conform to |
|
| 85 |
///It must conform to |
|
| 86 |
///the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
| 86 | 87 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
| 87 | 88 |
///Instantiates a \c ReachedMap. |
| 88 | 89 |
|
| 89 | 90 |
///This function instantiates a \ref ReachedMap. |
| 90 | 91 |
///\param g is the digraph, to which |
| 91 | 92 |
///we would like to define the \ref ReachedMap. |
| 92 | 93 |
static ReachedMap *createReachedMap(const Digraph &g) |
| 93 | 94 |
{
|
| 94 | 95 |
return new ReachedMap(g); |
| 95 | 96 |
} |
| 96 | 97 |
|
| 97 | 98 |
///The type of the map that stores the distances of the nodes. |
| 98 | 99 |
|
| 99 | 100 |
///The type of the map that stores the distances of the nodes. |
| 100 | 101 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 101 | 102 |
typedef typename Digraph::template NodeMap<int> DistMap; |
| 102 | 103 |
///Instantiates a \c DistMap. |
| 103 | 104 |
|
| 104 | 105 |
///This function instantiates a \ref DistMap. |
| 105 | 106 |
///\param g is the digraph, to which we would like to define the |
| 106 | 107 |
///\ref DistMap. |
| 107 | 108 |
static DistMap *createDistMap(const Digraph &g) |
| 108 | 109 |
{
|
| 109 | 110 |
return new DistMap(g); |
| 110 | 111 |
} |
| 111 | 112 |
}; |
| 112 | 113 |
|
| 113 | 114 |
///%BFS algorithm class. |
| 114 | 115 |
|
| 115 | 116 |
///\ingroup search |
| 116 | 117 |
///This class provides an efficient implementation of the %BFS algorithm. |
| 117 | 118 |
/// |
| 118 | 119 |
///There is also a \ref bfs() "function-type interface" for the BFS |
| 119 | 120 |
///algorithm, which is convenient in the simplier cases and it can be |
| 120 | 121 |
///used easier. |
| 121 | 122 |
/// |
| 122 | 123 |
///\tparam GR The type of the digraph the algorithm runs on. |
| 123 | 124 |
///The default type is \ref ListDigraph. |
| 124 | 125 |
///\tparam TR The traits class that defines various types used by the |
| 125 | 126 |
///algorithm. By default, it is \ref BfsDefaultTraits |
| 126 | 127 |
///"BfsDefaultTraits<GR>". |
| 127 | 128 |
///In most cases, this parameter should not be set directly, |
| 128 | 129 |
///consider to use the named template parameters instead. |
| 129 | 130 |
#ifdef DOXYGEN |
| 130 | 131 |
template <typename GR, |
| 131 | 132 |
typename TR> |
| 132 | 133 |
#else |
| 133 | 134 |
template <typename GR=ListDigraph, |
| ... | ... |
@@ -226,97 +227,98 @@ |
| 226 | 227 |
return 0; // ignore warnings |
| 227 | 228 |
} |
| 228 | 229 |
}; |
| 229 | 230 |
///\brief \ref named-templ-param "Named parameter" for setting |
| 230 | 231 |
///\c PredMap type. |
| 231 | 232 |
/// |
| 232 | 233 |
///\ref named-templ-param "Named parameter" for setting |
| 233 | 234 |
///\c PredMap type. |
| 234 | 235 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 235 | 236 |
template <class T> |
| 236 | 237 |
struct SetPredMap : public Bfs< Digraph, SetPredMapTraits<T> > {
|
| 237 | 238 |
typedef Bfs< Digraph, SetPredMapTraits<T> > Create; |
| 238 | 239 |
}; |
| 239 | 240 |
|
| 240 | 241 |
template <class T> |
| 241 | 242 |
struct SetDistMapTraits : public Traits {
|
| 242 | 243 |
typedef T DistMap; |
| 243 | 244 |
static DistMap *createDistMap(const Digraph &) |
| 244 | 245 |
{
|
| 245 | 246 |
LEMON_ASSERT(false, "DistMap is not initialized"); |
| 246 | 247 |
return 0; // ignore warnings |
| 247 | 248 |
} |
| 248 | 249 |
}; |
| 249 | 250 |
///\brief \ref named-templ-param "Named parameter" for setting |
| 250 | 251 |
///\c DistMap type. |
| 251 | 252 |
/// |
| 252 | 253 |
///\ref named-templ-param "Named parameter" for setting |
| 253 | 254 |
///\c DistMap type. |
| 254 | 255 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 255 | 256 |
template <class T> |
| 256 | 257 |
struct SetDistMap : public Bfs< Digraph, SetDistMapTraits<T> > {
|
| 257 | 258 |
typedef Bfs< Digraph, SetDistMapTraits<T> > Create; |
| 258 | 259 |
}; |
| 259 | 260 |
|
| 260 | 261 |
template <class T> |
| 261 | 262 |
struct SetReachedMapTraits : public Traits {
|
| 262 | 263 |
typedef T ReachedMap; |
| 263 | 264 |
static ReachedMap *createReachedMap(const Digraph &) |
| 264 | 265 |
{
|
| 265 | 266 |
LEMON_ASSERT(false, "ReachedMap is not initialized"); |
| 266 | 267 |
return 0; // ignore warnings |
| 267 | 268 |
} |
| 268 | 269 |
}; |
| 269 | 270 |
///\brief \ref named-templ-param "Named parameter" for setting |
| 270 | 271 |
///\c ReachedMap type. |
| 271 | 272 |
/// |
| 272 | 273 |
///\ref named-templ-param "Named parameter" for setting |
| 273 | 274 |
///\c ReachedMap type. |
| 274 |
///It must conform to |
|
| 275 |
///It must conform to |
|
| 276 |
///the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
| 275 | 277 |
template <class T> |
| 276 | 278 |
struct SetReachedMap : public Bfs< Digraph, SetReachedMapTraits<T> > {
|
| 277 | 279 |
typedef Bfs< Digraph, SetReachedMapTraits<T> > Create; |
| 278 | 280 |
}; |
| 279 | 281 |
|
| 280 | 282 |
template <class T> |
| 281 | 283 |
struct SetProcessedMapTraits : public Traits {
|
| 282 | 284 |
typedef T ProcessedMap; |
| 283 | 285 |
static ProcessedMap *createProcessedMap(const Digraph &) |
| 284 | 286 |
{
|
| 285 | 287 |
LEMON_ASSERT(false, "ProcessedMap is not initialized"); |
| 286 | 288 |
return 0; // ignore warnings |
| 287 | 289 |
} |
| 288 | 290 |
}; |
| 289 | 291 |
///\brief \ref named-templ-param "Named parameter" for setting |
| 290 | 292 |
///\c ProcessedMap type. |
| 291 | 293 |
/// |
| 292 | 294 |
///\ref named-templ-param "Named parameter" for setting |
| 293 | 295 |
///\c ProcessedMap type. |
| 294 | 296 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 295 | 297 |
template <class T> |
| 296 | 298 |
struct SetProcessedMap : public Bfs< Digraph, SetProcessedMapTraits<T> > {
|
| 297 | 299 |
typedef Bfs< Digraph, SetProcessedMapTraits<T> > Create; |
| 298 | 300 |
}; |
| 299 | 301 |
|
| 300 | 302 |
struct SetStandardProcessedMapTraits : public Traits {
|
| 301 | 303 |
typedef typename Digraph::template NodeMap<bool> ProcessedMap; |
| 302 | 304 |
static ProcessedMap *createProcessedMap(const Digraph &g) |
| 303 | 305 |
{
|
| 304 | 306 |
return new ProcessedMap(g); |
| 305 | 307 |
return 0; // ignore warnings |
| 306 | 308 |
} |
| 307 | 309 |
}; |
| 308 | 310 |
///\brief \ref named-templ-param "Named parameter" for setting |
| 309 | 311 |
///\c ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>. |
| 310 | 312 |
/// |
| 311 | 313 |
///\ref named-templ-param "Named parameter" for setting |
| 312 | 314 |
///\c ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>. |
| 313 | 315 |
///If you don't set it explicitly, it will be automatically allocated. |
| 314 | 316 |
struct SetStandardProcessedMap : |
| 315 | 317 |
public Bfs< Digraph, SetStandardProcessedMapTraits > {
|
| 316 | 318 |
typedef Bfs< Digraph, SetStandardProcessedMapTraits > Create; |
| 317 | 319 |
}; |
| 318 | 320 |
|
| 319 | 321 |
///@} |
| 320 | 322 |
|
| 321 | 323 |
public: |
| 322 | 324 |
|
| ... | ... |
@@ -827,97 +829,98 @@ |
| 827 | 829 |
///Default traits class of bfs() function. |
| 828 | 830 |
///\tparam GR Digraph type. |
| 829 | 831 |
template<class GR> |
| 830 | 832 |
struct BfsWizardDefaultTraits |
| 831 | 833 |
{
|
| 832 | 834 |
///The type of the digraph the algorithm runs on. |
| 833 | 835 |
typedef GR Digraph; |
| 834 | 836 |
|
| 835 | 837 |
///\brief The type of the map that stores the predecessor |
| 836 | 838 |
///arcs of the shortest paths. |
| 837 | 839 |
/// |
| 838 | 840 |
///The type of the map that stores the predecessor |
| 839 | 841 |
///arcs of the shortest paths. |
| 840 | 842 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 841 | 843 |
typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; |
| 842 | 844 |
///Instantiates a PredMap. |
| 843 | 845 |
|
| 844 | 846 |
///This function instantiates a PredMap. |
| 845 | 847 |
///\param g is the digraph, to which we would like to define the |
| 846 | 848 |
///PredMap. |
| 847 | 849 |
static PredMap *createPredMap(const Digraph &g) |
| 848 | 850 |
{
|
| 849 | 851 |
return new PredMap(g); |
| 850 | 852 |
} |
| 851 | 853 |
|
| 852 | 854 |
///The type of the map that indicates which nodes are processed. |
| 853 | 855 |
|
| 854 | 856 |
///The type of the map that indicates which nodes are processed. |
| 855 | 857 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 856 | 858 |
///By default, it is a NullMap. |
| 857 | 859 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
| 858 | 860 |
///Instantiates a ProcessedMap. |
| 859 | 861 |
|
| 860 | 862 |
///This function instantiates a ProcessedMap. |
| 861 | 863 |
///\param g is the digraph, to which |
| 862 | 864 |
///we would like to define the ProcessedMap. |
| 863 | 865 |
#ifdef DOXYGEN |
| 864 | 866 |
static ProcessedMap *createProcessedMap(const Digraph &g) |
| 865 | 867 |
#else |
| 866 | 868 |
static ProcessedMap *createProcessedMap(const Digraph &) |
| 867 | 869 |
#endif |
| 868 | 870 |
{
|
| 869 | 871 |
return new ProcessedMap(); |
| 870 | 872 |
} |
| 871 | 873 |
|
| 872 | 874 |
///The type of the map that indicates which nodes are reached. |
| 873 | 875 |
|
| 874 | 876 |
///The type of the map that indicates which nodes are reached. |
| 875 |
///It must conform to |
|
| 877 |
///It must conform to |
|
| 878 |
///the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
| 876 | 879 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
| 877 | 880 |
///Instantiates a ReachedMap. |
| 878 | 881 |
|
| 879 | 882 |
///This function instantiates a ReachedMap. |
| 880 | 883 |
///\param g is the digraph, to which |
| 881 | 884 |
///we would like to define the ReachedMap. |
| 882 | 885 |
static ReachedMap *createReachedMap(const Digraph &g) |
| 883 | 886 |
{
|
| 884 | 887 |
return new ReachedMap(g); |
| 885 | 888 |
} |
| 886 | 889 |
|
| 887 | 890 |
///The type of the map that stores the distances of the nodes. |
| 888 | 891 |
|
| 889 | 892 |
///The type of the map that stores the distances of the nodes. |
| 890 | 893 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 891 | 894 |
typedef typename Digraph::template NodeMap<int> DistMap; |
| 892 | 895 |
///Instantiates a DistMap. |
| 893 | 896 |
|
| 894 | 897 |
///This function instantiates a DistMap. |
| 895 | 898 |
///\param g is the digraph, to which we would like to define |
| 896 | 899 |
///the DistMap |
| 897 | 900 |
static DistMap *createDistMap(const Digraph &g) |
| 898 | 901 |
{
|
| 899 | 902 |
return new DistMap(g); |
| 900 | 903 |
} |
| 901 | 904 |
|
| 902 | 905 |
///The type of the shortest paths. |
| 903 | 906 |
|
| 904 | 907 |
///The type of the shortest paths. |
| 905 | 908 |
///It must conform to the \ref concepts::Path "Path" concept. |
| 906 | 909 |
typedef lemon::Path<Digraph> Path; |
| 907 | 910 |
}; |
| 908 | 911 |
|
| 909 | 912 |
/// Default traits class used by BfsWizard |
| 910 | 913 |
|
| 911 | 914 |
/// Default traits class used by BfsWizard. |
| 912 | 915 |
/// \tparam GR The type of the digraph. |
| 913 | 916 |
template<class GR> |
| 914 | 917 |
class BfsWizardBase : public BfsWizardDefaultTraits<GR> |
| 915 | 918 |
{
|
| 916 | 919 |
|
| 917 | 920 |
typedef BfsWizardDefaultTraits<GR> Base; |
| 918 | 921 |
protected: |
| 919 | 922 |
//The type of the nodes in the digraph. |
| 920 | 923 |
typedef typename Base::Digraph::Node Node; |
| 921 | 924 |
|
| 922 | 925 |
//Pointer to the digraph the algorithm runs on. |
| 923 | 926 |
void *_g; |
| ... | ... |
@@ -1220,97 +1223,98 @@ |
| 1220 | 1223 |
/// \brief Called when an arc is examined but its target node is |
| 1221 | 1224 |
/// already discovered. |
| 1222 | 1225 |
/// |
| 1223 | 1226 |
/// This function is called when an arc is examined but its target node is |
| 1224 | 1227 |
/// already discovered. |
| 1225 | 1228 |
void examine(const Arc& arc) {}
|
| 1226 | 1229 |
}; |
| 1227 | 1230 |
#else |
| 1228 | 1231 |
template <typename GR> |
| 1229 | 1232 |
struct BfsVisitor {
|
| 1230 | 1233 |
typedef GR Digraph; |
| 1231 | 1234 |
typedef typename Digraph::Arc Arc; |
| 1232 | 1235 |
typedef typename Digraph::Node Node; |
| 1233 | 1236 |
void start(const Node&) {}
|
| 1234 | 1237 |
void reach(const Node&) {}
|
| 1235 | 1238 |
void process(const Node&) {}
|
| 1236 | 1239 |
void discover(const Arc&) {}
|
| 1237 | 1240 |
void examine(const Arc&) {}
|
| 1238 | 1241 |
|
| 1239 | 1242 |
template <typename _Visitor> |
| 1240 | 1243 |
struct Constraints {
|
| 1241 | 1244 |
void constraints() {
|
| 1242 | 1245 |
Arc arc; |
| 1243 | 1246 |
Node node; |
| 1244 | 1247 |
visitor.start(node); |
| 1245 | 1248 |
visitor.reach(node); |
| 1246 | 1249 |
visitor.process(node); |
| 1247 | 1250 |
visitor.discover(arc); |
| 1248 | 1251 |
visitor.examine(arc); |
| 1249 | 1252 |
} |
| 1250 | 1253 |
_Visitor& visitor; |
| 1251 | 1254 |
}; |
| 1252 | 1255 |
}; |
| 1253 | 1256 |
#endif |
| 1254 | 1257 |
|
| 1255 | 1258 |
/// \brief Default traits class of BfsVisit class. |
| 1256 | 1259 |
/// |
| 1257 | 1260 |
/// Default traits class of BfsVisit class. |
| 1258 | 1261 |
/// \tparam GR The type of the digraph the algorithm runs on. |
| 1259 | 1262 |
template<class GR> |
| 1260 | 1263 |
struct BfsVisitDefaultTraits {
|
| 1261 | 1264 |
|
| 1262 | 1265 |
/// \brief The type of the digraph the algorithm runs on. |
| 1263 | 1266 |
typedef GR Digraph; |
| 1264 | 1267 |
|
| 1265 | 1268 |
/// \brief The type of the map that indicates which nodes are reached. |
| 1266 | 1269 |
/// |
| 1267 | 1270 |
/// The type of the map that indicates which nodes are reached. |
| 1268 |
/// It must conform to |
|
| 1271 |
/// It must conform to |
|
| 1272 |
///the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
| 1269 | 1273 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
| 1270 | 1274 |
|
| 1271 | 1275 |
/// \brief Instantiates a ReachedMap. |
| 1272 | 1276 |
/// |
| 1273 | 1277 |
/// This function instantiates a ReachedMap. |
| 1274 | 1278 |
/// \param digraph is the digraph, to which |
| 1275 | 1279 |
/// we would like to define the ReachedMap. |
| 1276 | 1280 |
static ReachedMap *createReachedMap(const Digraph &digraph) {
|
| 1277 | 1281 |
return new ReachedMap(digraph); |
| 1278 | 1282 |
} |
| 1279 | 1283 |
|
| 1280 | 1284 |
}; |
| 1281 | 1285 |
|
| 1282 | 1286 |
/// \ingroup search |
| 1283 | 1287 |
/// |
| 1284 | 1288 |
/// \brief BFS algorithm class with visitor interface. |
| 1285 | 1289 |
/// |
| 1286 | 1290 |
/// This class provides an efficient implementation of the BFS algorithm |
| 1287 | 1291 |
/// with visitor interface. |
| 1288 | 1292 |
/// |
| 1289 | 1293 |
/// The BfsVisit class provides an alternative interface to the Bfs |
| 1290 | 1294 |
/// class. It works with callback mechanism, the BfsVisit object calls |
| 1291 | 1295 |
/// the member functions of the \c Visitor class on every BFS event. |
| 1292 | 1296 |
/// |
| 1293 | 1297 |
/// This interface of the BFS algorithm should be used in special cases |
| 1294 | 1298 |
/// when extra actions have to be performed in connection with certain |
| 1295 | 1299 |
/// events of the BFS algorithm. Otherwise consider to use Bfs or bfs() |
| 1296 | 1300 |
/// instead. |
| 1297 | 1301 |
/// |
| 1298 | 1302 |
/// \tparam GR The type of the digraph the algorithm runs on. |
| 1299 | 1303 |
/// The default type is \ref ListDigraph. |
| 1300 | 1304 |
/// The value of GR is not used directly by \ref BfsVisit, |
| 1301 | 1305 |
/// it is only passed to \ref BfsVisitDefaultTraits. |
| 1302 | 1306 |
/// \tparam VS The Visitor type that is used by the algorithm. |
| 1303 | 1307 |
/// \ref BfsVisitor "BfsVisitor<GR>" is an empty visitor, which |
| 1304 | 1308 |
/// does not observe the BFS events. If you want to observe the BFS |
| 1305 | 1309 |
/// events, you should implement your own visitor class. |
| 1306 | 1310 |
/// \tparam TR The traits class that defines various types used by the |
| 1307 | 1311 |
/// algorithm. By default, it is \ref BfsVisitDefaultTraits |
| 1308 | 1312 |
/// "BfsVisitDefaultTraits<GR>". |
| 1309 | 1313 |
/// In most cases, this parameter should not be set directly, |
| 1310 | 1314 |
/// consider to use the named template parameters instead. |
| 1311 | 1315 |
#ifdef DOXYGEN |
| 1312 | 1316 |
template <typename GR, typename VS, typename TR> |
| 1313 | 1317 |
#else |
| 1314 | 1318 |
template <typename GR = ListDigraph, |
| 1315 | 1319 |
typename VS = BfsVisitor<GR>, |
| 1316 | 1320 |
typename TR = BfsVisitDefaultTraits<GR> > |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_BINOMIAL_HEAP_H |
| 20 | 20 |
#define LEMON_BINOMIAL_HEAP_H |
| 21 | 21 |
|
| 22 | 22 |
///\file |
| 23 | 23 |
///\ingroup heaps |
| 24 | 24 |
///\brief Binomial Heap implementation. |
| 25 | 25 |
|
| 26 | 26 |
#include <vector> |
| 27 | 27 |
#include <utility> |
| 28 | 28 |
#include <functional> |
| 29 | 29 |
#include <lemon/math.h> |
| 30 | 30 |
#include <lemon/counter.h> |
| 31 | 31 |
|
| 32 | 32 |
namespace lemon {
|
| 33 | 33 |
|
| 34 | 34 |
/// \ingroup heaps |
| 35 | 35 |
/// |
| 36 | 36 |
///\brief Binomial heap data structure. |
| 37 | 37 |
/// |
| 38 | 38 |
/// This class implements the \e binomial \e heap data structure. |
| 39 | 39 |
/// It fully conforms to the \ref concepts::Heap "heap concept". |
| 40 | 40 |
/// |
| 41 | 41 |
/// The methods \ref increase() and \ref erase() are not efficient |
| 42 | 42 |
/// in a binomial heap. In case of many calls of these operations, |
| 43 | 43 |
/// it is better to use other heap structure, e.g. \ref BinHeap |
| 44 | 44 |
/// "binary heap". |
| 45 | 45 |
/// |
| 46 | 46 |
/// \tparam PR Type of the priorities of the items. |
| 47 | 47 |
/// \tparam IM A read-writable item map with \c int values, used |
| 48 | 48 |
/// internally to handle the cross references. |
| 49 | 49 |
/// \tparam CMP A functor class for comparing the priorities. |
| 50 | 50 |
/// The default is \c std::less<PR>. |
| 51 | 51 |
#ifdef DOXYGEN |
| 52 | 52 |
template <typename PR, typename IM, typename CMP> |
| 53 | 53 |
#else |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_BITS_ARRAY_MAP_H |
| 20 | 20 |
#define LEMON_BITS_ARRAY_MAP_H |
| 21 | 21 |
|
| 22 | 22 |
#include <memory> |
| 23 | 23 |
|
| 24 | 24 |
#include <lemon/bits/traits.h> |
| 25 | 25 |
#include <lemon/bits/alteration_notifier.h> |
| 26 | 26 |
#include <lemon/concept_check.h> |
| 27 | 27 |
#include <lemon/concepts/maps.h> |
| 28 | 28 |
|
| 29 | 29 |
// \ingroup graphbits |
| 30 | 30 |
// \file |
| 31 | 31 |
// \brief Graph map based on the array storage. |
| 32 | 32 |
|
| 33 | 33 |
namespace lemon {
|
| 34 | 34 |
|
| 35 | 35 |
// \ingroup graphbits |
| 36 | 36 |
// |
| 37 | 37 |
// \brief Graph map based on the array storage. |
| 38 | 38 |
// |
| 39 | 39 |
// The ArrayMap template class is graph map structure that automatically |
| 40 | 40 |
// updates the map when a key is added to or erased from the graph. |
| 41 | 41 |
// This map uses the allocators to implement the container functionality. |
| 42 | 42 |
// |
| 43 | 43 |
// The template parameters are the Graph, the current Item type and |
| 44 | 44 |
// the Value type of the map. |
| 45 | 45 |
template <typename _Graph, typename _Item, typename _Value> |
| 46 | 46 |
class ArrayMap |
| 47 | 47 |
: public ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase {
|
| 48 | 48 |
public: |
| 49 | 49 |
// The graph type. |
| 50 | 50 |
typedef _Graph GraphType; |
| 51 | 51 |
// The item type. |
| 52 | 52 |
typedef _Item Item; |
| 53 | 53 |
// The reference map tag. |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_BITS_DEFAULT_MAP_H |
| 20 | 20 |
#define LEMON_BITS_DEFAULT_MAP_H |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/config.h> |
| 23 | 23 |
#include <lemon/bits/array_map.h> |
| 24 | 24 |
#include <lemon/bits/vector_map.h> |
| 25 | 25 |
//#include <lemon/bits/debug_map.h> |
| 26 | 26 |
|
| 27 | 27 |
//\ingroup graphbits |
| 28 | 28 |
//\file |
| 29 | 29 |
//\brief Graph maps that construct and destruct their elements dynamically. |
| 30 | 30 |
|
| 31 | 31 |
namespace lemon {
|
| 32 | 32 |
|
| 33 | 33 |
|
| 34 | 34 |
//#ifndef LEMON_USE_DEBUG_MAP |
| 35 | 35 |
|
| 36 | 36 |
template <typename _Graph, typename _Item, typename _Value> |
| 37 | 37 |
struct DefaultMapSelector {
|
| 38 | 38 |
typedef ArrayMap<_Graph, _Item, _Value> Map; |
| 39 | 39 |
}; |
| 40 | 40 |
|
| 41 | 41 |
// bool |
| 42 | 42 |
template <typename _Graph, typename _Item> |
| 43 | 43 |
struct DefaultMapSelector<_Graph, _Item, bool> {
|
| 44 | 44 |
typedef VectorMap<_Graph, _Item, bool> Map; |
| 45 | 45 |
}; |
| 46 | 46 |
|
| 47 | 47 |
// char |
| 48 | 48 |
template <typename _Graph, typename _Item> |
| 49 | 49 |
struct DefaultMapSelector<_Graph, _Item, char> {
|
| 50 | 50 |
typedef VectorMap<_Graph, _Item, char> Map; |
| 51 | 51 |
}; |
| 52 | 52 |
|
| 53 | 53 |
template <typename _Graph, typename _Item> |
| 1 |
/* -*- C++ -*- |
|
| 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
| 2 | 2 |
* |
| 3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
| 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_BITS_EDGE_SET_EXTENDER_H |
| 20 | 20 |
#define LEMON_BITS_EDGE_SET_EXTENDER_H |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/core.h> |
| 23 | 23 |
#include <lemon/error.h> |
| 24 | 24 |
#include <lemon/bits/default_map.h> |
| 25 | 25 |
#include <lemon/bits/map_extender.h> |
| 26 | 26 |
|
| 27 | 27 |
//\ingroup digraphbits |
| 28 | 28 |
//\file |
| 29 | 29 |
//\brief Extenders for the arc set types |
| 30 | 30 |
namespace lemon {
|
| 31 | 31 |
|
| 32 | 32 |
// \ingroup digraphbits |
| 33 | 33 |
// |
| 34 | 34 |
// \brief Extender for the ArcSets |
| 35 | 35 |
template <typename Base> |
| 36 | 36 |
class ArcSetExtender : public Base {
|
| 37 | 37 |
typedef Base Parent; |
| 38 | 38 |
|
| 39 | 39 |
public: |
| 40 | 40 |
|
| 41 | 41 |
typedef ArcSetExtender Digraph; |
| 42 | 42 |
|
| 43 | 43 |
// Base extensions |
| 44 | 44 |
|
| 45 | 45 |
typedef typename Parent::Node Node; |
| 46 | 46 |
typedef typename Parent::Arc Arc; |
| 47 | 47 |
|
| 48 | 48 |
int maxId(Node) const {
|
| 49 | 49 |
return Parent::maxNodeId(); |
| 50 | 50 |
} |
| 51 | 51 |
|
| 52 | 52 |
int maxId(Arc) const {
|
| 53 | 53 |
return Parent::maxArcId(); |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_BITS_SOLVER_BITS_H |
| 20 | 20 |
#define LEMON_BITS_SOLVER_BITS_H |
| 21 | 21 |
|
| 22 | 22 |
#include <vector> |
| 23 | 23 |
|
| 24 | 24 |
namespace lemon {
|
| 25 | 25 |
|
| 26 | 26 |
namespace _solver_bits {
|
| 27 | 27 |
|
| 28 | 28 |
class VarIndex {
|
| 29 | 29 |
private: |
| 30 | 30 |
struct ItemT {
|
| 31 | 31 |
int prev, next; |
| 32 | 32 |
int index; |
| 33 | 33 |
}; |
| 34 | 34 |
std::vector<ItemT> items; |
| 35 | 35 |
int first_item, last_item, first_free_item; |
| 36 | 36 |
|
| 37 | 37 |
std::vector<int> cross; |
| 38 | 38 |
|
| 39 | 39 |
public: |
| 40 | 40 |
|
| 41 | 41 |
VarIndex() |
| 42 | 42 |
: first_item(-1), last_item(-1), first_free_item(-1) {
|
| 43 | 43 |
} |
| 44 | 44 |
|
| 45 | 45 |
void clear() {
|
| 46 | 46 |
first_item = -1; |
| 47 | 47 |
first_free_item = -1; |
| 48 | 48 |
items.clear(); |
| 49 | 49 |
cross.clear(); |
| 50 | 50 |
} |
| 51 | 51 |
|
| 52 | 52 |
int addIndex(int idx) {
|
| 53 | 53 |
int n; |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
///\file |
| 20 | 20 |
///\brief Some basic non-inline functions and static global data. |
| 21 | 21 |
|
| 22 | 22 |
#include<lemon/bits/windows.h> |
| 23 | 23 |
|
| 24 | 24 |
#ifdef WIN32 |
| 25 | 25 |
#ifndef WIN32_LEAN_AND_MEAN |
| 26 | 26 |
#define WIN32_LEAN_AND_MEAN |
| 27 | 27 |
#endif |
| 28 | 28 |
#ifndef NOMINMAX |
| 29 | 29 |
#define NOMINMAX |
| 30 | 30 |
#endif |
| 31 | 31 |
#ifdef UNICODE |
| 32 | 32 |
#undef UNICODE |
| 33 | 33 |
#endif |
| 34 | 34 |
#include <windows.h> |
| 35 | 35 |
#ifdef LOCALE_INVARIANT |
| 36 | 36 |
#define MY_LOCALE LOCALE_INVARIANT |
| 37 | 37 |
#else |
| 38 | 38 |
#define MY_LOCALE LOCALE_NEUTRAL |
| 39 | 39 |
#endif |
| 40 | 40 |
#else |
| 41 | 41 |
#include <unistd.h> |
| 42 | 42 |
#include <ctime> |
| 43 | 43 |
#include <sys/times.h> |
| 44 | 44 |
#include <sys/time.h> |
| 45 | 45 |
#endif |
| 46 | 46 |
|
| 47 | 47 |
#include <cmath> |
| 48 | 48 |
#include <sstream> |
| 49 | 49 |
|
| 50 | 50 |
namespace lemon {
|
| 51 | 51 |
namespace bits {
|
| 52 | 52 |
void getWinProcTimes(double &rtime, |
| 53 | 53 |
double &utime, double &stime, |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_BUCKET_HEAP_H |
| 20 | 20 |
#define LEMON_BUCKET_HEAP_H |
| 21 | 21 |
|
| 22 | 22 |
///\ingroup heaps |
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief Bucket heap implementation. |
| 25 | 25 |
|
| 26 | 26 |
#include <vector> |
| 27 | 27 |
#include <utility> |
| 28 | 28 |
#include <functional> |
| 29 | 29 |
|
| 30 | 30 |
namespace lemon {
|
| 31 | 31 |
|
| 32 | 32 |
namespace _bucket_heap_bits {
|
| 33 | 33 |
|
| 34 | 34 |
template <bool MIN> |
| 35 | 35 |
struct DirectionTraits {
|
| 36 | 36 |
static bool less(int left, int right) {
|
| 37 | 37 |
return left < right; |
| 38 | 38 |
} |
| 39 | 39 |
static void increase(int& value) {
|
| 40 | 40 |
++value; |
| 41 | 41 |
} |
| 42 | 42 |
}; |
| 43 | 43 |
|
| 44 | 44 |
template <> |
| 45 | 45 |
struct DirectionTraits<false> {
|
| 46 | 46 |
static bool less(int left, int right) {
|
| 47 | 47 |
return left > right; |
| 48 | 48 |
} |
| 49 | 49 |
static void increase(int& value) {
|
| 50 | 50 |
--value; |
| 51 | 51 |
} |
| 52 | 52 |
}; |
| 53 | 53 |
| 1 |
/* -*- C++ -*- |
|
| 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
| 2 | 2 |
* |
| 3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
| 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_CAPACITY_SCALING_H |
| 20 | 20 |
#define LEMON_CAPACITY_SCALING_H |
| 21 | 21 |
|
| 22 | 22 |
/// \ingroup min_cost_flow_algs |
| 23 | 23 |
/// |
| 24 | 24 |
/// \file |
| 25 | 25 |
/// \brief Capacity Scaling algorithm for finding a minimum cost flow. |
| 26 | 26 |
|
| 27 | 27 |
#include <vector> |
| 28 | 28 |
#include <limits> |
| 29 | 29 |
#include <lemon/core.h> |
| 30 | 30 |
#include <lemon/bin_heap.h> |
| 31 | 31 |
|
| 32 | 32 |
namespace lemon {
|
| 33 | 33 |
|
| 34 | 34 |
/// \brief Default traits class of CapacityScaling algorithm. |
| 35 | 35 |
/// |
| 36 | 36 |
/// Default traits class of CapacityScaling algorithm. |
| 37 | 37 |
/// \tparam GR Digraph type. |
| 38 | 38 |
/// \tparam V The number type used for flow amounts, capacity bounds |
| 39 | 39 |
/// and supply values. By default it is \c int. |
| 40 | 40 |
/// \tparam C The number type used for costs and potentials. |
| 41 | 41 |
/// By default it is the same as \c V. |
| 42 | 42 |
template <typename GR, typename V = int, typename C = V> |
| 43 | 43 |
struct CapacityScalingDefaultTraits |
| 44 | 44 |
{
|
| 45 | 45 |
/// The type of the digraph |
| 46 | 46 |
typedef GR Digraph; |
| 47 | 47 |
/// The type of the flow amounts, capacity bounds and supply values |
| 48 | 48 |
typedef V Value; |
| 49 | 49 |
/// The type of the arc costs |
| 50 | 50 |
typedef C Cost; |
| 51 | 51 |
|
| 52 | 52 |
/// \brief The type of the heap used for internal Dijkstra computations. |
| 53 | 53 |
/// |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
// -*- C++ -*- |
| 20 | 20 |
#ifndef LEMON_CBC_H |
| 21 | 21 |
#define LEMON_CBC_H |
| 22 | 22 |
|
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief Header of the LEMON-CBC mip solver interface. |
| 25 | 25 |
///\ingroup lp_group |
| 26 | 26 |
|
| 27 | 27 |
#include <lemon/lp_base.h> |
| 28 | 28 |
|
| 29 | 29 |
class CoinModel; |
| 30 | 30 |
class OsiSolverInterface; |
| 31 | 31 |
class CbcModel; |
| 32 | 32 |
|
| 33 | 33 |
namespace lemon {
|
| 34 | 34 |
|
| 35 | 35 |
/// \brief Interface for the CBC MIP solver |
| 36 | 36 |
/// |
| 37 | 37 |
/// This class implements an interface for the CBC MIP solver. |
| 38 | 38 |
///\ingroup lp_group |
| 39 | 39 |
class CbcMip : public MipSolver {
|
| 40 | 40 |
protected: |
| 41 | 41 |
|
| 42 | 42 |
CoinModel *_prob; |
| 43 | 43 |
OsiSolverInterface *_osi_solver; |
| 44 | 44 |
CbcModel *_cbc_model; |
| 45 | 45 |
|
| 46 | 46 |
public: |
| 47 | 47 |
|
| 48 | 48 |
/// \e |
| 49 | 49 |
CbcMip(); |
| 50 | 50 |
/// \e |
| 51 | 51 |
CbcMip(const CbcMip&); |
| 52 | 52 |
/// \e |
| 53 | 53 |
~CbcMip(); |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_CIRCULATION_H |
| 20 | 20 |
#define LEMON_CIRCULATION_H |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/tolerance.h> |
| 23 | 23 |
#include <lemon/elevator.h> |
| 24 | 24 |
#include <limits> |
| 25 | 25 |
|
| 26 | 26 |
///\ingroup max_flow |
| 27 | 27 |
///\file |
| 28 | 28 |
///\brief Push-relabel algorithm for finding a feasible circulation. |
| 29 | 29 |
/// |
| 30 | 30 |
namespace lemon {
|
| 31 | 31 |
|
| 32 | 32 |
/// \brief Default traits class of Circulation class. |
| 33 | 33 |
/// |
| 34 | 34 |
/// Default traits class of Circulation class. |
| 35 | 35 |
/// |
| 36 | 36 |
/// \tparam GR Type of the digraph the algorithm runs on. |
| 37 | 37 |
/// \tparam LM The type of the lower bound map. |
| 38 | 38 |
/// \tparam UM The type of the upper bound (capacity) map. |
| 39 | 39 |
/// \tparam SM The type of the supply map. |
| 40 | 40 |
template <typename GR, typename LM, |
| 41 | 41 |
typename UM, typename SM> |
| 42 | 42 |
struct CirculationDefaultTraits {
|
| 43 | 43 |
|
| 44 | 44 |
/// \brief The type of the digraph the algorithm runs on. |
| 45 | 45 |
typedef GR Digraph; |
| 46 | 46 |
|
| 47 | 47 |
/// \brief The type of the lower bound map. |
| 48 | 48 |
/// |
| 49 | 49 |
/// The type of the map that stores the lower bounds on the arcs. |
| 50 | 50 |
/// It must conform to the \ref concepts::ReadMap "ReadMap" concept. |
| 51 | 51 |
typedef LM LowerMap; |
| 52 | 52 |
|
| 53 | 53 |
/// \brief The type of the upper bound (capacity) map. |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <lemon/clp.h> |
| 20 | 20 |
#include <coin/ClpSimplex.hpp> |
| 21 | 21 |
|
| 22 | 22 |
namespace lemon {
|
| 23 | 23 |
|
| 24 | 24 |
ClpLp::ClpLp() {
|
| 25 | 25 |
_prob = new ClpSimplex(); |
| 26 | 26 |
_init_temporals(); |
| 27 | 27 |
messageLevel(MESSAGE_NOTHING); |
| 28 | 28 |
} |
| 29 | 29 |
|
| 30 | 30 |
ClpLp::ClpLp(const ClpLp& other) {
|
| 31 | 31 |
_prob = new ClpSimplex(*other._prob); |
| 32 | 32 |
rows = other.rows; |
| 33 | 33 |
cols = other.cols; |
| 34 | 34 |
_init_temporals(); |
| 35 | 35 |
messageLevel(MESSAGE_NOTHING); |
| 36 | 36 |
} |
| 37 | 37 |
|
| 38 | 38 |
ClpLp::~ClpLp() {
|
| 39 | 39 |
delete _prob; |
| 40 | 40 |
_clear_temporals(); |
| 41 | 41 |
} |
| 42 | 42 |
|
| 43 | 43 |
void ClpLp::_init_temporals() {
|
| 44 | 44 |
_primal_ray = 0; |
| 45 | 45 |
_dual_ray = 0; |
| 46 | 46 |
} |
| 47 | 47 |
|
| 48 | 48 |
void ClpLp::_clear_temporals() {
|
| 49 | 49 |
if (_primal_ray) {
|
| 50 | 50 |
delete[] _primal_ray; |
| 51 | 51 |
_primal_ray = 0; |
| 52 | 52 |
} |
| 53 | 53 |
if (_dual_ray) {
|
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_CLP_H |
| 20 | 20 |
#define LEMON_CLP_H |
| 21 | 21 |
|
| 22 | 22 |
///\file |
| 23 | 23 |
///\brief Header of the LEMON-CLP lp solver interface. |
| 24 | 24 |
|
| 25 | 25 |
#include <vector> |
| 26 | 26 |
#include <string> |
| 27 | 27 |
|
| 28 | 28 |
#include <lemon/lp_base.h> |
| 29 | 29 |
|
| 30 | 30 |
class ClpSimplex; |
| 31 | 31 |
|
| 32 | 32 |
namespace lemon {
|
| 33 | 33 |
|
| 34 | 34 |
/// \ingroup lp_group |
| 35 | 35 |
/// |
| 36 | 36 |
/// \brief Interface for the CLP solver |
| 37 | 37 |
/// |
| 38 | 38 |
/// This class implements an interface for the Clp LP solver. The |
| 39 | 39 |
/// Clp library is an object oriented lp solver library developed at |
| 40 | 40 |
/// the IBM. The CLP is part of the COIN-OR package and it can be |
| 41 | 41 |
/// used with Common Public License. |
| 42 | 42 |
class ClpLp : public LpSolver {
|
| 43 | 43 |
protected: |
| 44 | 44 |
|
| 45 | 45 |
ClpSimplex* _prob; |
| 46 | 46 |
|
| 47 | 47 |
std::map<std::string, int> _col_names_ref; |
| 48 | 48 |
std::map<std::string, int> _row_names_ref; |
| 49 | 49 |
|
| 50 | 50 |
public: |
| 51 | 51 |
|
| 52 | 52 |
/// \e |
| 53 | 53 |
ClpLp(); |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_CONCEPTS_DIGRAPH_H |
| 20 | 20 |
#define LEMON_CONCEPTS_DIGRAPH_H |
| 21 | 21 |
|
| 22 | 22 |
///\ingroup graph_concepts |
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief The concept of directed graphs. |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/core.h> |
| 27 | 27 |
#include <lemon/concepts/maps.h> |
| 28 | 28 |
#include <lemon/concept_check.h> |
| 29 | 29 |
#include <lemon/concepts/graph_components.h> |
| 30 | 30 |
|
| 31 | 31 |
namespace lemon {
|
| 32 | 32 |
namespace concepts {
|
| 33 | 33 |
|
| 34 | 34 |
/// \ingroup graph_concepts |
| 35 | 35 |
/// |
| 36 | 36 |
/// \brief Class describing the concept of directed graphs. |
| 37 | 37 |
/// |
| 38 | 38 |
/// This class describes the common interface of all directed |
| 39 | 39 |
/// graphs (digraphs). |
| 40 | 40 |
/// |
| 41 | 41 |
/// Like all concept classes, it only provides an interface |
| 42 | 42 |
/// without any sensible implementation. So any general algorithm for |
| 43 | 43 |
/// directed graphs should compile with this class, but it will not |
| 44 | 44 |
/// run properly, of course. |
| 45 | 45 |
/// An actual digraph implementation like \ref ListDigraph or |
| 46 | 46 |
/// \ref SmartDigraph may have additional functionality. |
| 47 | 47 |
/// |
| 48 | 48 |
/// \sa Graph |
| 49 | 49 |
class Digraph {
|
| 50 | 50 |
private: |
| 51 | 51 |
/// Diraphs are \e not copy constructible. Use DigraphCopy instead. |
| 52 | 52 |
Digraph(const Digraph &) {}
|
| 53 | 53 |
/// \brief Assignment of a digraph to another one is \e not allowed. |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 | 21 |
///\brief The concept of undirected graphs. |
| 22 | 22 |
|
| 23 | 23 |
#ifndef LEMON_CONCEPTS_GRAPH_H |
| 24 | 24 |
#define LEMON_CONCEPTS_GRAPH_H |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/concepts/graph_components.h> |
| 27 | 27 |
#include <lemon/concepts/maps.h> |
| 28 | 28 |
#include <lemon/concept_check.h> |
| 29 | 29 |
#include <lemon/core.h> |
| 30 | 30 |
|
| 31 | 31 |
namespace lemon {
|
| 32 | 32 |
namespace concepts {
|
| 33 | 33 |
|
| 34 | 34 |
/// \ingroup graph_concepts |
| 35 | 35 |
/// |
| 36 | 36 |
/// \brief Class describing the concept of undirected graphs. |
| 37 | 37 |
/// |
| 38 | 38 |
/// This class describes the common interface of all undirected |
| 39 | 39 |
/// graphs. |
| 40 | 40 |
/// |
| 41 | 41 |
/// Like all concept classes, it only provides an interface |
| 42 | 42 |
/// without any sensible implementation. So any general algorithm for |
| 43 | 43 |
/// undirected graphs should compile with this class, but it will not |
| 44 | 44 |
/// run properly, of course. |
| 45 | 45 |
/// An actual graph implementation like \ref ListGraph or |
| 46 | 46 |
/// \ref SmartGraph may have additional functionality. |
| 47 | 47 |
/// |
| 48 | 48 |
/// The undirected graphs also fulfill the concept of \ref Digraph |
| 49 | 49 |
/// "directed graphs", since each edge can also be regarded as two |
| 50 | 50 |
/// oppositely directed arcs. |
| 51 | 51 |
/// Undirected graphs provide an Edge type for the undirected edges and |
| 52 | 52 |
/// an Arc type for the directed arcs. The Arc type is convertible to |
| 53 | 53 |
/// Edge or inherited from it, i.e. the corresponding edge can be |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 | 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'> |
| 46 | 46 |
#endif |
| 47 | 47 |
class GraphItem {
|
| 48 | 48 |
public: |
| 49 | 49 |
/// \brief Default constructor. |
| 50 | 50 |
/// |
| 51 | 51 |
/// Default constructor. |
| 52 | 52 |
/// \warning The default constructor is not required to set |
| 53 | 53 |
/// the item to some well-defined value. So you should consider it |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_CONCEPTS_HEAP_H |
| 20 | 20 |
#define LEMON_CONCEPTS_HEAP_H |
| 21 | 21 |
|
| 22 | 22 |
///\ingroup concept |
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief The concept of heaps. |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/core.h> |
| 27 | 27 |
#include <lemon/concept_check.h> |
| 28 | 28 |
|
| 29 | 29 |
namespace lemon {
|
| 30 | 30 |
|
| 31 | 31 |
namespace concepts {
|
| 32 | 32 |
|
| 33 | 33 |
/// \addtogroup concept |
| 34 | 34 |
/// @{
|
| 35 | 35 |
|
| 36 | 36 |
/// \brief The heap concept. |
| 37 | 37 |
/// |
| 38 | 38 |
/// This concept class describes the main interface of heaps. |
| 39 | 39 |
/// The various \ref heaps "heap structures" are efficient |
| 40 | 40 |
/// implementations of the abstract data type \e priority \e queue. |
| 41 | 41 |
/// They store items with specified values called \e priorities |
| 42 | 42 |
/// in such a way that finding and removing the item with minimum |
| 43 | 43 |
/// priority are efficient. The basic operations are adding and |
| 44 | 44 |
/// erasing items, changing the priority of an item, etc. |
| 45 | 45 |
/// |
| 46 | 46 |
/// Heaps are crucial in several algorithms, such as Dijkstra and Prim. |
| 47 | 47 |
/// Any class that conforms to this concept can be used easily in such |
| 48 | 48 |
/// algorithms. |
| 49 | 49 |
/// |
| 50 | 50 |
/// \tparam PR Type of the priorities of the items. |
| 51 | 51 |
/// \tparam IM A read-writable item map with \c int values, used |
| 52 | 52 |
/// internally to handle the cross references. |
| 53 | 53 |
/// \tparam CMP A functor class for comparing the priorities. |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_CONNECTIVITY_H |
| 20 | 20 |
#define LEMON_CONNECTIVITY_H |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/dfs.h> |
| 23 | 23 |
#include <lemon/bfs.h> |
| 24 | 24 |
#include <lemon/core.h> |
| 25 | 25 |
#include <lemon/maps.h> |
| 26 | 26 |
#include <lemon/adaptors.h> |
| 27 | 27 |
|
| 28 | 28 |
#include <lemon/concepts/digraph.h> |
| 29 | 29 |
#include <lemon/concepts/graph.h> |
| 30 | 30 |
#include <lemon/concept_check.h> |
| 31 | 31 |
|
| 32 | 32 |
#include <stack> |
| 33 | 33 |
#include <functional> |
| 34 | 34 |
|
| 35 | 35 |
/// \ingroup graph_properties |
| 36 | 36 |
/// \file |
| 37 | 37 |
/// \brief Connectivity algorithms |
| 38 | 38 |
/// |
| 39 | 39 |
/// Connectivity algorithms |
| 40 | 40 |
|
| 41 | 41 |
namespace lemon {
|
| 42 | 42 |
|
| 43 | 43 |
/// \ingroup graph_properties |
| 44 | 44 |
/// |
| 45 | 45 |
/// \brief Check whether an undirected graph is connected. |
| 46 | 46 |
/// |
| 47 | 47 |
/// This function checks whether the given undirected graph is connected, |
| 48 | 48 |
/// i.e. there is a path between any two nodes in the graph. |
| 49 | 49 |
/// |
| 50 | 50 |
/// \return \c true if the graph is connected. |
| 51 | 51 |
/// \note By definition, the empty graph is connected. |
| 52 | 52 |
/// |
| 53 | 53 |
/// \see countConnectedComponents(), connectedComponents() |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_CORE_H |
| 20 | 20 |
#define LEMON_CORE_H |
| 21 | 21 |
|
| 22 | 22 |
#include <vector> |
| 23 | 23 |
#include <algorithm> |
| 24 | 24 |
|
| 25 | 25 |
#include <lemon/config.h> |
| 26 | 26 |
#include <lemon/bits/enable_if.h> |
| 27 | 27 |
#include <lemon/bits/traits.h> |
| 28 | 28 |
#include <lemon/assert.h> |
| 29 | 29 |
|
| 30 | 30 |
// Disable the following warnings when compiling with MSVC: |
| 31 | 31 |
// C4250: 'class1' : inherits 'class2::member' via dominance |
| 32 | 32 |
// C4355: 'this' : used in base member initializer list |
| 33 | 33 |
// C4503: 'function' : decorated name length exceeded, name was truncated |
| 34 | 34 |
// C4800: 'type' : forcing value to bool 'true' or 'false' (performance warning) |
| 35 | 35 |
// C4996: 'function': was declared deprecated |
| 36 | 36 |
#ifdef _MSC_VER |
| 37 | 37 |
#pragma warning( disable : 4250 4355 4503 4800 4996 ) |
| 38 | 38 |
#endif |
| 39 | 39 |
|
| 40 | 40 |
///\file |
| 41 | 41 |
///\brief LEMON core utilities. |
| 42 | 42 |
/// |
| 43 | 43 |
///This header file contains core utilities for LEMON. |
| 44 | 44 |
///It is automatically included by all graph types, therefore it usually |
| 45 | 45 |
///do not have to be included directly. |
| 46 | 46 |
|
| 47 | 47 |
namespace lemon {
|
| 48 | 48 |
|
| 49 | 49 |
/// \brief Dummy type to make it easier to create invalid iterators. |
| 50 | 50 |
/// |
| 51 | 51 |
/// Dummy type to make it easier to create invalid iterators. |
| 52 | 52 |
/// See \ref INVALID for the usage. |
| 53 | 53 |
struct Invalid {
|
| ... | ... |
@@ -1194,97 +1194,98 @@ |
| 1194 | 1194 |
ConEdgeIt& operator++() {
|
| 1195 | 1195 |
Parent::operator=(findEdge(_graph, _u, _v, *this)); |
| 1196 | 1196 |
return *this; |
| 1197 | 1197 |
} |
| 1198 | 1198 |
private: |
| 1199 | 1199 |
const GR& _graph; |
| 1200 | 1200 |
Node _u, _v; |
| 1201 | 1201 |
}; |
| 1202 | 1202 |
|
| 1203 | 1203 |
|
| 1204 | 1204 |
///Dynamic arc look-up between given endpoints. |
| 1205 | 1205 |
|
| 1206 | 1206 |
///Using this class, you can find an arc in a digraph from a given |
| 1207 | 1207 |
///source to a given target in amortized time <em>O</em>(log<em>d</em>), |
| 1208 | 1208 |
///where <em>d</em> is the out-degree of the source node. |
| 1209 | 1209 |
/// |
| 1210 | 1210 |
///It is possible to find \e all parallel arcs between two nodes with |
| 1211 | 1211 |
///the \c operator() member. |
| 1212 | 1212 |
/// |
| 1213 | 1213 |
///This is a dynamic data structure. Consider to use \ref ArcLookUp or |
| 1214 | 1214 |
///\ref AllArcLookUp if your digraph is not changed so frequently. |
| 1215 | 1215 |
/// |
| 1216 | 1216 |
///This class uses a self-adjusting binary search tree, the Splay tree |
| 1217 | 1217 |
///of Sleator and Tarjan to guarantee the logarithmic amortized |
| 1218 | 1218 |
///time bound for arc look-ups. This class also guarantees the |
| 1219 | 1219 |
///optimal time bound in a constant factor for any distribution of |
| 1220 | 1220 |
///queries. |
| 1221 | 1221 |
/// |
| 1222 | 1222 |
///\tparam GR The type of the underlying digraph. |
| 1223 | 1223 |
/// |
| 1224 | 1224 |
///\sa ArcLookUp |
| 1225 | 1225 |
///\sa AllArcLookUp |
| 1226 | 1226 |
template <typename GR> |
| 1227 | 1227 |
class DynArcLookUp |
| 1228 | 1228 |
: protected ItemSetTraits<GR, typename GR::Arc>::ItemNotifier::ObserverBase |
| 1229 | 1229 |
{
|
| 1230 | 1230 |
typedef typename ItemSetTraits<GR, typename GR::Arc> |
| 1231 | 1231 |
::ItemNotifier::ObserverBase Parent; |
| 1232 | 1232 |
|
| 1233 | 1233 |
TEMPLATE_DIGRAPH_TYPEDEFS(GR); |
| 1234 | 1234 |
|
| 1235 | 1235 |
public: |
| 1236 | 1236 |
|
| 1237 | 1237 |
/// The Digraph type |
| 1238 | 1238 |
typedef GR Digraph; |
| 1239 | 1239 |
|
| 1240 | 1240 |
protected: |
| 1241 | 1241 |
|
| 1242 |
class AutoNodeMap : public ItemSetTraits<GR, Node>::template Map<Arc>::Type |
|
| 1242 |
class AutoNodeMap : public ItemSetTraits<GR, Node>::template Map<Arc>::Type |
|
| 1243 |
{
|
|
| 1243 | 1244 |
typedef typename ItemSetTraits<GR, Node>::template Map<Arc>::Type Parent; |
| 1244 | 1245 |
|
| 1245 | 1246 |
public: |
| 1246 | 1247 |
|
| 1247 | 1248 |
AutoNodeMap(const GR& digraph) : Parent(digraph, INVALID) {}
|
| 1248 | 1249 |
|
| 1249 | 1250 |
virtual void add(const Node& node) {
|
| 1250 | 1251 |
Parent::add(node); |
| 1251 | 1252 |
Parent::set(node, INVALID); |
| 1252 | 1253 |
} |
| 1253 | 1254 |
|
| 1254 | 1255 |
virtual void add(const std::vector<Node>& nodes) {
|
| 1255 | 1256 |
Parent::add(nodes); |
| 1256 | 1257 |
for (int i = 0; i < int(nodes.size()); ++i) {
|
| 1257 | 1258 |
Parent::set(nodes[i], INVALID); |
| 1258 | 1259 |
} |
| 1259 | 1260 |
} |
| 1260 | 1261 |
|
| 1261 | 1262 |
virtual void build() {
|
| 1262 | 1263 |
Parent::build(); |
| 1263 | 1264 |
Node it; |
| 1264 | 1265 |
typename Parent::Notifier* nf = Parent::notifier(); |
| 1265 | 1266 |
for (nf->first(it); it != INVALID; nf->next(it)) {
|
| 1266 | 1267 |
Parent::set(it, INVALID); |
| 1267 | 1268 |
} |
| 1268 | 1269 |
} |
| 1269 | 1270 |
}; |
| 1270 | 1271 |
|
| 1271 | 1272 |
class ArcLess {
|
| 1272 | 1273 |
const Digraph &g; |
| 1273 | 1274 |
public: |
| 1274 | 1275 |
ArcLess(const Digraph &_g) : g(_g) {}
|
| 1275 | 1276 |
bool operator()(Arc a,Arc b) const |
| 1276 | 1277 |
{
|
| 1277 | 1278 |
return g.target(a)<g.target(b); |
| 1278 | 1279 |
} |
| 1279 | 1280 |
}; |
| 1280 | 1281 |
|
| 1281 | 1282 |
protected: |
| 1282 | 1283 |
|
| 1283 | 1284 |
const Digraph &_g; |
| 1284 | 1285 |
AutoNodeMap _head; |
| 1285 | 1286 |
typename Digraph::template ArcMap<Arc> _parent; |
| 1286 | 1287 |
typename Digraph::template ArcMap<Arc> _left; |
| 1287 | 1288 |
typename Digraph::template ArcMap<Arc> _right; |
| 1288 | 1289 |
|
| 1289 | 1290 |
public: |
| 1290 | 1291 |
| 1 |
/* -*- C++ -*- |
|
| 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
| 2 | 2 |
* |
| 3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
| 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_COST_SCALING_H |
| 20 | 20 |
#define LEMON_COST_SCALING_H |
| 21 | 21 |
|
| 22 | 22 |
/// \ingroup min_cost_flow_algs |
| 23 | 23 |
/// \file |
| 24 | 24 |
/// \brief Cost scaling algorithm for finding a minimum cost flow. |
| 25 | 25 |
|
| 26 | 26 |
#include <vector> |
| 27 | 27 |
#include <deque> |
| 28 | 28 |
#include <limits> |
| 29 | 29 |
|
| 30 | 30 |
#include <lemon/core.h> |
| 31 | 31 |
#include <lemon/maps.h> |
| 32 | 32 |
#include <lemon/math.h> |
| 33 | 33 |
#include <lemon/static_graph.h> |
| 34 | 34 |
#include <lemon/circulation.h> |
| 35 | 35 |
#include <lemon/bellman_ford.h> |
| 36 | 36 |
|
| 37 | 37 |
namespace lemon {
|
| 38 | 38 |
|
| 39 | 39 |
/// \brief Default traits class of CostScaling algorithm. |
| 40 | 40 |
/// |
| 41 | 41 |
/// Default traits class of CostScaling algorithm. |
| 42 | 42 |
/// \tparam GR Digraph type. |
| 43 | 43 |
/// \tparam V The number type used for flow amounts, capacity bounds |
| 44 | 44 |
/// and supply values. By default it is \c int. |
| 45 | 45 |
/// \tparam C The number type used for costs and potentials. |
| 46 | 46 |
/// By default it is the same as \c V. |
| 47 | 47 |
#ifdef DOXYGEN |
| 48 | 48 |
template <typename GR, typename V = int, typename C = V> |
| 49 | 49 |
#else |
| 50 | 50 |
template < typename GR, typename V = int, typename C = V, |
| 51 | 51 |
bool integer = std::numeric_limits<C>::is_integer > |
| 52 | 52 |
#endif |
| 53 | 53 |
struct CostScalingDefaultTraits |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <iostream> |
| 20 | 20 |
#include <vector> |
| 21 | 21 |
#include <cstring> |
| 22 | 22 |
|
| 23 | 23 |
#include <lemon/cplex.h> |
| 24 | 24 |
|
| 25 | 25 |
extern "C" {
|
| 26 | 26 |
#include <ilcplex/cplex.h> |
| 27 | 27 |
} |
| 28 | 28 |
|
| 29 | 29 |
|
| 30 | 30 |
///\file |
| 31 | 31 |
///\brief Implementation of the LEMON-CPLEX lp solver interface. |
| 32 | 32 |
namespace lemon {
|
| 33 | 33 |
|
| 34 | 34 |
CplexEnv::LicenseError::LicenseError(int status) {
|
| 35 | 35 |
if (!CPXgeterrorstring(0, status, _message)) {
|
| 36 | 36 |
std::strcpy(_message, "Cplex unknown error"); |
| 37 | 37 |
} |
| 38 | 38 |
} |
| 39 | 39 |
|
| 40 | 40 |
CplexEnv::CplexEnv() {
|
| 41 | 41 |
int status; |
| 42 | 42 |
_cnt = new int; |
| 43 | 43 |
_env = CPXopenCPLEX(&status); |
| 44 | 44 |
if (_env == 0) {
|
| 45 | 45 |
delete _cnt; |
| 46 | 46 |
_cnt = 0; |
| 47 | 47 |
throw LicenseError(status); |
| 48 | 48 |
} |
| 49 | 49 |
} |
| 50 | 50 |
|
| 51 | 51 |
CplexEnv::CplexEnv(const CplexEnv& other) {
|
| 52 | 52 |
_env = other._env; |
| 53 | 53 |
_cnt = other._cnt; |
| 1 |
/* -*- C++ -*- |
|
| 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
| 2 | 2 |
* |
| 3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
| 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_CYCLE_CANCELING_H |
| 20 | 20 |
#define LEMON_CYCLE_CANCELING_H |
| 21 | 21 |
|
| 22 | 22 |
/// \ingroup min_cost_flow_algs |
| 23 | 23 |
/// \file |
| 24 | 24 |
/// \brief Cycle-canceling algorithms for finding a minimum cost flow. |
| 25 | 25 |
|
| 26 | 26 |
#include <vector> |
| 27 | 27 |
#include <limits> |
| 28 | 28 |
|
| 29 | 29 |
#include <lemon/core.h> |
| 30 | 30 |
#include <lemon/maps.h> |
| 31 | 31 |
#include <lemon/path.h> |
| 32 | 32 |
#include <lemon/math.h> |
| 33 | 33 |
#include <lemon/static_graph.h> |
| 34 | 34 |
#include <lemon/adaptors.h> |
| 35 | 35 |
#include <lemon/circulation.h> |
| 36 | 36 |
#include <lemon/bellman_ford.h> |
| 37 | 37 |
#include <lemon/howard_mmc.h> |
| 38 | 38 |
|
| 39 | 39 |
namespace lemon {
|
| 40 | 40 |
|
| 41 | 41 |
/// \addtogroup min_cost_flow_algs |
| 42 | 42 |
/// @{
|
| 43 | 43 |
|
| 44 | 44 |
/// \brief Implementation of cycle-canceling algorithms for |
| 45 | 45 |
/// finding a \ref min_cost_flow "minimum cost flow". |
| 46 | 46 |
/// |
| 47 | 47 |
/// \ref CycleCanceling implements three different cycle-canceling |
| 48 | 48 |
/// algorithms for finding a \ref min_cost_flow "minimum cost flow" |
| 49 | 49 |
/// \ref amo93networkflows, \ref klein67primal, |
| 50 | 50 |
/// \ref goldberg89cyclecanceling. |
| 51 | 51 |
/// The most efficent one (both theoretically and practically) |
| 52 | 52 |
/// is the \ref CANCEL_AND_TIGHTEN "Cancel and Tighten" algorithm, |
| 53 | 53 |
/// thus it is the default method. |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_DFS_H |
| 20 | 20 |
#define LEMON_DFS_H |
| 21 | 21 |
|
| 22 | 22 |
///\ingroup search |
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief DFS algorithm. |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/list_graph.h> |
| 27 | 27 |
#include <lemon/bits/path_dump.h> |
| 28 | 28 |
#include <lemon/core.h> |
| 29 | 29 |
#include <lemon/error.h> |
| 30 | 30 |
#include <lemon/maps.h> |
| 31 | 31 |
#include <lemon/path.h> |
| 32 | 32 |
|
| 33 | 33 |
namespace lemon {
|
| 34 | 34 |
|
| 35 | 35 |
///Default traits class of Dfs class. |
| 36 | 36 |
|
| 37 | 37 |
///Default traits class of Dfs class. |
| 38 | 38 |
///\tparam GR Digraph type. |
| 39 | 39 |
template<class GR> |
| 40 | 40 |
struct DfsDefaultTraits |
| 41 | 41 |
{
|
| 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 | 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 |
///It must conform to |
|
| 85 |
///It must conform to |
|
| 86 |
///the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
| 86 | 87 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
| 87 | 88 |
///Instantiates a \c ReachedMap. |
| 88 | 89 |
|
| 89 | 90 |
///This function instantiates a \ref ReachedMap. |
| 90 | 91 |
///\param g is the digraph, to which |
| 91 | 92 |
///we would like to define the \ref ReachedMap. |
| 92 | 93 |
static ReachedMap *createReachedMap(const Digraph &g) |
| 93 | 94 |
{
|
| 94 | 95 |
return new ReachedMap(g); |
| 95 | 96 |
} |
| 96 | 97 |
|
| 97 | 98 |
///The type of the map that stores the distances of the nodes. |
| 98 | 99 |
|
| 99 | 100 |
///The type of the map that stores the distances of the nodes. |
| 100 | 101 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 101 | 102 |
typedef typename Digraph::template NodeMap<int> DistMap; |
| 102 | 103 |
///Instantiates a \c DistMap. |
| 103 | 104 |
|
| 104 | 105 |
///This function instantiates a \ref DistMap. |
| 105 | 106 |
///\param g is the digraph, to which we would like to define the |
| 106 | 107 |
///\ref DistMap. |
| 107 | 108 |
static DistMap *createDistMap(const Digraph &g) |
| 108 | 109 |
{
|
| 109 | 110 |
return new DistMap(g); |
| 110 | 111 |
} |
| 111 | 112 |
}; |
| 112 | 113 |
|
| 113 | 114 |
///%DFS algorithm class. |
| 114 | 115 |
|
| 115 | 116 |
///\ingroup search |
| 116 | 117 |
///This class provides an efficient implementation of the %DFS algorithm. |
| 117 | 118 |
/// |
| 118 | 119 |
///There is also a \ref dfs() "function-type interface" for the DFS |
| 119 | 120 |
///algorithm, which is convenient in the simplier cases and it can be |
| 120 | 121 |
///used easier. |
| 121 | 122 |
/// |
| 122 | 123 |
///\tparam GR The type of the digraph the algorithm runs on. |
| 123 | 124 |
///The default type is \ref ListDigraph. |
| 124 | 125 |
///\tparam TR The traits class that defines various types used by the |
| 125 | 126 |
///algorithm. By default, it is \ref DfsDefaultTraits |
| 126 | 127 |
///"DfsDefaultTraits<GR>". |
| 127 | 128 |
///In most cases, this parameter should not be set directly, |
| 128 | 129 |
///consider to use the named template parameters instead. |
| 129 | 130 |
#ifdef DOXYGEN |
| 130 | 131 |
template <typename GR, |
| 131 | 132 |
typename TR> |
| 132 | 133 |
#else |
| 133 | 134 |
template <typename GR=ListDigraph, |
| ... | ... |
@@ -225,97 +226,98 @@ |
| 225 | 226 |
return 0; // ignore warnings |
| 226 | 227 |
} |
| 227 | 228 |
}; |
| 228 | 229 |
///\brief \ref named-templ-param "Named parameter" for setting |
| 229 | 230 |
///\c PredMap type. |
| 230 | 231 |
/// |
| 231 | 232 |
///\ref named-templ-param "Named parameter" for setting |
| 232 | 233 |
///\c PredMap type. |
| 233 | 234 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 234 | 235 |
template <class T> |
| 235 | 236 |
struct SetPredMap : public Dfs<Digraph, SetPredMapTraits<T> > {
|
| 236 | 237 |
typedef Dfs<Digraph, SetPredMapTraits<T> > Create; |
| 237 | 238 |
}; |
| 238 | 239 |
|
| 239 | 240 |
template <class T> |
| 240 | 241 |
struct SetDistMapTraits : public Traits {
|
| 241 | 242 |
typedef T DistMap; |
| 242 | 243 |
static DistMap *createDistMap(const Digraph &) |
| 243 | 244 |
{
|
| 244 | 245 |
LEMON_ASSERT(false, "DistMap is not initialized"); |
| 245 | 246 |
return 0; // ignore warnings |
| 246 | 247 |
} |
| 247 | 248 |
}; |
| 248 | 249 |
///\brief \ref named-templ-param "Named parameter" for setting |
| 249 | 250 |
///\c DistMap type. |
| 250 | 251 |
/// |
| 251 | 252 |
///\ref named-templ-param "Named parameter" for setting |
| 252 | 253 |
///\c DistMap type. |
| 253 | 254 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 254 | 255 |
template <class T> |
| 255 | 256 |
struct SetDistMap : public Dfs< Digraph, SetDistMapTraits<T> > {
|
| 256 | 257 |
typedef Dfs<Digraph, SetDistMapTraits<T> > Create; |
| 257 | 258 |
}; |
| 258 | 259 |
|
| 259 | 260 |
template <class T> |
| 260 | 261 |
struct SetReachedMapTraits : public Traits {
|
| 261 | 262 |
typedef T ReachedMap; |
| 262 | 263 |
static ReachedMap *createReachedMap(const Digraph &) |
| 263 | 264 |
{
|
| 264 | 265 |
LEMON_ASSERT(false, "ReachedMap is not initialized"); |
| 265 | 266 |
return 0; // ignore warnings |
| 266 | 267 |
} |
| 267 | 268 |
}; |
| 268 | 269 |
///\brief \ref named-templ-param "Named parameter" for setting |
| 269 | 270 |
///\c ReachedMap type. |
| 270 | 271 |
/// |
| 271 | 272 |
///\ref named-templ-param "Named parameter" for setting |
| 272 | 273 |
///\c ReachedMap type. |
| 273 |
///It must conform to |
|
| 274 |
///It must conform to |
|
| 275 |
///the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
| 274 | 276 |
template <class T> |
| 275 | 277 |
struct SetReachedMap : public Dfs< Digraph, SetReachedMapTraits<T> > {
|
| 276 | 278 |
typedef Dfs< Digraph, SetReachedMapTraits<T> > Create; |
| 277 | 279 |
}; |
| 278 | 280 |
|
| 279 | 281 |
template <class T> |
| 280 | 282 |
struct SetProcessedMapTraits : public Traits {
|
| 281 | 283 |
typedef T ProcessedMap; |
| 282 | 284 |
static ProcessedMap *createProcessedMap(const Digraph &) |
| 283 | 285 |
{
|
| 284 | 286 |
LEMON_ASSERT(false, "ProcessedMap is not initialized"); |
| 285 | 287 |
return 0; // ignore warnings |
| 286 | 288 |
} |
| 287 | 289 |
}; |
| 288 | 290 |
///\brief \ref named-templ-param "Named parameter" for setting |
| 289 | 291 |
///\c ProcessedMap type. |
| 290 | 292 |
/// |
| 291 | 293 |
///\ref named-templ-param "Named parameter" for setting |
| 292 | 294 |
///\c ProcessedMap type. |
| 293 | 295 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 294 | 296 |
template <class T> |
| 295 | 297 |
struct SetProcessedMap : public Dfs< Digraph, SetProcessedMapTraits<T> > {
|
| 296 | 298 |
typedef Dfs< Digraph, SetProcessedMapTraits<T> > Create; |
| 297 | 299 |
}; |
| 298 | 300 |
|
| 299 | 301 |
struct SetStandardProcessedMapTraits : public Traits {
|
| 300 | 302 |
typedef typename Digraph::template NodeMap<bool> ProcessedMap; |
| 301 | 303 |
static ProcessedMap *createProcessedMap(const Digraph &g) |
| 302 | 304 |
{
|
| 303 | 305 |
return new ProcessedMap(g); |
| 304 | 306 |
} |
| 305 | 307 |
}; |
| 306 | 308 |
///\brief \ref named-templ-param "Named parameter" for setting |
| 307 | 309 |
///\c ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>. |
| 308 | 310 |
/// |
| 309 | 311 |
///\ref named-templ-param "Named parameter" for setting |
| 310 | 312 |
///\c ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>. |
| 311 | 313 |
///If you don't set it explicitly, it will be automatically allocated. |
| 312 | 314 |
struct SetStandardProcessedMap : |
| 313 | 315 |
public Dfs< Digraph, SetStandardProcessedMapTraits > {
|
| 314 | 316 |
typedef Dfs< Digraph, SetStandardProcessedMapTraits > Create; |
| 315 | 317 |
}; |
| 316 | 318 |
|
| 317 | 319 |
///@} |
| 318 | 320 |
|
| 319 | 321 |
public: |
| 320 | 322 |
|
| 321 | 323 |
///Constructor. |
| ... | ... |
@@ -757,97 +759,98 @@ |
| 757 | 759 |
///Default traits class of dfs() function. |
| 758 | 760 |
///\tparam GR Digraph type. |
| 759 | 761 |
template<class GR> |
| 760 | 762 |
struct DfsWizardDefaultTraits |
| 761 | 763 |
{
|
| 762 | 764 |
///The type of the digraph the algorithm runs on. |
| 763 | 765 |
typedef GR Digraph; |
| 764 | 766 |
|
| 765 | 767 |
///\brief The type of the map that stores the predecessor |
| 766 | 768 |
///arcs of the %DFS paths. |
| 767 | 769 |
/// |
| 768 | 770 |
///The type of the map that stores the predecessor |
| 769 | 771 |
///arcs of the %DFS paths. |
| 770 | 772 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 771 | 773 |
typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; |
| 772 | 774 |
///Instantiates a PredMap. |
| 773 | 775 |
|
| 774 | 776 |
///This function instantiates a PredMap. |
| 775 | 777 |
///\param g is the digraph, to which we would like to define the |
| 776 | 778 |
///PredMap. |
| 777 | 779 |
static PredMap *createPredMap(const Digraph &g) |
| 778 | 780 |
{
|
| 779 | 781 |
return new PredMap(g); |
| 780 | 782 |
} |
| 781 | 783 |
|
| 782 | 784 |
///The type of the map that indicates which nodes are processed. |
| 783 | 785 |
|
| 784 | 786 |
///The type of the map that indicates which nodes are processed. |
| 785 | 787 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 786 | 788 |
///By default, it is a NullMap. |
| 787 | 789 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
| 788 | 790 |
///Instantiates a ProcessedMap. |
| 789 | 791 |
|
| 790 | 792 |
///This function instantiates a ProcessedMap. |
| 791 | 793 |
///\param g is the digraph, to which |
| 792 | 794 |
///we would like to define the ProcessedMap. |
| 793 | 795 |
#ifdef DOXYGEN |
| 794 | 796 |
static ProcessedMap *createProcessedMap(const Digraph &g) |
| 795 | 797 |
#else |
| 796 | 798 |
static ProcessedMap *createProcessedMap(const Digraph &) |
| 797 | 799 |
#endif |
| 798 | 800 |
{
|
| 799 | 801 |
return new ProcessedMap(); |
| 800 | 802 |
} |
| 801 | 803 |
|
| 802 | 804 |
///The type of the map that indicates which nodes are reached. |
| 803 | 805 |
|
| 804 | 806 |
///The type of the map that indicates which nodes are reached. |
| 805 |
///It must conform to |
|
| 807 |
///It must conform to |
|
| 808 |
///the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
| 806 | 809 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
| 807 | 810 |
///Instantiates a ReachedMap. |
| 808 | 811 |
|
| 809 | 812 |
///This function instantiates a ReachedMap. |
| 810 | 813 |
///\param g is the digraph, to which |
| 811 | 814 |
///we would like to define the ReachedMap. |
| 812 | 815 |
static ReachedMap *createReachedMap(const Digraph &g) |
| 813 | 816 |
{
|
| 814 | 817 |
return new ReachedMap(g); |
| 815 | 818 |
} |
| 816 | 819 |
|
| 817 | 820 |
///The type of the map that stores the distances of the nodes. |
| 818 | 821 |
|
| 819 | 822 |
///The type of the map that stores the distances of the nodes. |
| 820 | 823 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
| 821 | 824 |
typedef typename Digraph::template NodeMap<int> DistMap; |
| 822 | 825 |
///Instantiates a DistMap. |
| 823 | 826 |
|
| 824 | 827 |
///This function instantiates a DistMap. |
| 825 | 828 |
///\param g is the digraph, to which we would like to define |
| 826 | 829 |
///the DistMap |
| 827 | 830 |
static DistMap *createDistMap(const Digraph &g) |
| 828 | 831 |
{
|
| 829 | 832 |
return new DistMap(g); |
| 830 | 833 |
} |
| 831 | 834 |
|
| 832 | 835 |
///The type of the DFS paths. |
| 833 | 836 |
|
| 834 | 837 |
///The type of the DFS paths. |
| 835 | 838 |
///It must conform to the \ref concepts::Path "Path" concept. |
| 836 | 839 |
typedef lemon::Path<Digraph> Path; |
| 837 | 840 |
}; |
| 838 | 841 |
|
| 839 | 842 |
/// Default traits class used by DfsWizard |
| 840 | 843 |
|
| 841 | 844 |
/// Default traits class used by DfsWizard. |
| 842 | 845 |
/// \tparam GR The type of the digraph. |
| 843 | 846 |
template<class GR> |
| 844 | 847 |
class DfsWizardBase : public DfsWizardDefaultTraits<GR> |
| 845 | 848 |
{
|
| 846 | 849 |
|
| 847 | 850 |
typedef DfsWizardDefaultTraits<GR> Base; |
| 848 | 851 |
protected: |
| 849 | 852 |
//The type of the nodes in the digraph. |
| 850 | 853 |
typedef typename Base::Digraph::Node Node; |
| 851 | 854 |
|
| 852 | 855 |
//Pointer to the digraph the algorithm runs on. |
| 853 | 856 |
void *_g; |
| ... | ... |
@@ -1162,97 +1165,98 @@ |
| 1162 | 1165 |
/// This function is called when the DFS steps back on an arc. |
| 1163 | 1166 |
void backtrack(const Arc& arc) {}
|
| 1164 | 1167 |
}; |
| 1165 | 1168 |
#else |
| 1166 | 1169 |
template <typename GR> |
| 1167 | 1170 |
struct DfsVisitor {
|
| 1168 | 1171 |
typedef GR Digraph; |
| 1169 | 1172 |
typedef typename Digraph::Arc Arc; |
| 1170 | 1173 |
typedef typename Digraph::Node Node; |
| 1171 | 1174 |
void start(const Node&) {}
|
| 1172 | 1175 |
void stop(const Node&) {}
|
| 1173 | 1176 |
void reach(const Node&) {}
|
| 1174 | 1177 |
void discover(const Arc&) {}
|
| 1175 | 1178 |
void examine(const Arc&) {}
|
| 1176 | 1179 |
void leave(const Node&) {}
|
| 1177 | 1180 |
void backtrack(const Arc&) {}
|
| 1178 | 1181 |
|
| 1179 | 1182 |
template <typename _Visitor> |
| 1180 | 1183 |
struct Constraints {
|
| 1181 | 1184 |
void constraints() {
|
| 1182 | 1185 |
Arc arc; |
| 1183 | 1186 |
Node node; |
| 1184 | 1187 |
visitor.start(node); |
| 1185 | 1188 |
visitor.stop(arc); |
| 1186 | 1189 |
visitor.reach(node); |
| 1187 | 1190 |
visitor.discover(arc); |
| 1188 | 1191 |
visitor.examine(arc); |
| 1189 | 1192 |
visitor.leave(node); |
| 1190 | 1193 |
visitor.backtrack(arc); |
| 1191 | 1194 |
} |
| 1192 | 1195 |
_Visitor& visitor; |
| 1193 | 1196 |
}; |
| 1194 | 1197 |
}; |
| 1195 | 1198 |
#endif |
| 1196 | 1199 |
|
| 1197 | 1200 |
/// \brief Default traits class of DfsVisit class. |
| 1198 | 1201 |
/// |
| 1199 | 1202 |
/// Default traits class of DfsVisit class. |
| 1200 | 1203 |
/// \tparam _Digraph The type of the digraph the algorithm runs on. |
| 1201 | 1204 |
template<class GR> |
| 1202 | 1205 |
struct DfsVisitDefaultTraits {
|
| 1203 | 1206 |
|
| 1204 | 1207 |
/// \brief The type of the digraph the algorithm runs on. |
| 1205 | 1208 |
typedef GR Digraph; |
| 1206 | 1209 |
|
| 1207 | 1210 |
/// \brief The type of the map that indicates which nodes are reached. |
| 1208 | 1211 |
/// |
| 1209 | 1212 |
/// The type of the map that indicates which nodes are reached. |
| 1210 |
/// It must conform to the |
|
| 1213 |
/// It must conform to the |
|
| 1214 |
/// \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
| 1211 | 1215 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
| 1212 | 1216 |
|
| 1213 | 1217 |
/// \brief Instantiates a ReachedMap. |
| 1214 | 1218 |
/// |
| 1215 | 1219 |
/// This function instantiates a ReachedMap. |
| 1216 | 1220 |
/// \param digraph is the digraph, to which |
| 1217 | 1221 |
/// we would like to define the ReachedMap. |
| 1218 | 1222 |
static ReachedMap *createReachedMap(const Digraph &digraph) {
|
| 1219 | 1223 |
return new ReachedMap(digraph); |
| 1220 | 1224 |
} |
| 1221 | 1225 |
|
| 1222 | 1226 |
}; |
| 1223 | 1227 |
|
| 1224 | 1228 |
/// \ingroup search |
| 1225 | 1229 |
/// |
| 1226 | 1230 |
/// \brief DFS algorithm class with visitor interface. |
| 1227 | 1231 |
/// |
| 1228 | 1232 |
/// This class provides an efficient implementation of the DFS algorithm |
| 1229 | 1233 |
/// with visitor interface. |
| 1230 | 1234 |
/// |
| 1231 | 1235 |
/// The DfsVisit class provides an alternative interface to the Dfs |
| 1232 | 1236 |
/// class. It works with callback mechanism, the DfsVisit object calls |
| 1233 | 1237 |
/// the member functions of the \c Visitor class on every DFS event. |
| 1234 | 1238 |
/// |
| 1235 | 1239 |
/// This interface of the DFS algorithm should be used in special cases |
| 1236 | 1240 |
/// when extra actions have to be performed in connection with certain |
| 1237 | 1241 |
/// events of the DFS algorithm. Otherwise consider to use Dfs or dfs() |
| 1238 | 1242 |
/// instead. |
| 1239 | 1243 |
/// |
| 1240 | 1244 |
/// \tparam GR The type of the digraph the algorithm runs on. |
| 1241 | 1245 |
/// The default type is \ref ListDigraph. |
| 1242 | 1246 |
/// The value of GR is not used directly by \ref DfsVisit, |
| 1243 | 1247 |
/// it is only passed to \ref DfsVisitDefaultTraits. |
| 1244 | 1248 |
/// \tparam VS The Visitor type that is used by the algorithm. |
| 1245 | 1249 |
/// \ref DfsVisitor "DfsVisitor<GR>" is an empty visitor, which |
| 1246 | 1250 |
/// does not observe the DFS events. If you want to observe the DFS |
| 1247 | 1251 |
/// events, you should implement your own visitor class. |
| 1248 | 1252 |
/// \tparam TR The traits class that defines various types used by the |
| 1249 | 1253 |
/// algorithm. By default, it is \ref DfsVisitDefaultTraits |
| 1250 | 1254 |
/// "DfsVisitDefaultTraits<GR>". |
| 1251 | 1255 |
/// In most cases, this parameter should not be set directly, |
| 1252 | 1256 |
/// consider to use the named template parameters instead. |
| 1253 | 1257 |
#ifdef DOXYGEN |
| 1254 | 1258 |
template <typename GR, typename VS, typename TR> |
| 1255 | 1259 |
#else |
| 1256 | 1260 |
template <typename GR = ListDigraph, |
| 1257 | 1261 |
typename VS = DfsVisitor<GR>, |
| 1258 | 1262 |
typename TR = DfsVisitDefaultTraits<GR> > |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_DIJKSTRA_H |
| 20 | 20 |
#define LEMON_DIJKSTRA_H |
| 21 | 21 |
|
| 22 | 22 |
///\ingroup shortest_path |
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief Dijkstra algorithm. |
| 25 | 25 |
|
| 26 | 26 |
#include <limits> |
| 27 | 27 |
#include <lemon/list_graph.h> |
| 28 | 28 |
#include <lemon/bin_heap.h> |
| 29 | 29 |
#include <lemon/bits/path_dump.h> |
| 30 | 30 |
#include <lemon/core.h> |
| 31 | 31 |
#include <lemon/error.h> |
| 32 | 32 |
#include <lemon/maps.h> |
| 33 | 33 |
#include <lemon/path.h> |
| 34 | 34 |
|
| 35 | 35 |
namespace lemon {
|
| 36 | 36 |
|
| 37 | 37 |
/// \brief Default operation traits for the Dijkstra algorithm class. |
| 38 | 38 |
/// |
| 39 | 39 |
/// This operation traits class defines all computational operations and |
| 40 | 40 |
/// constants which are used in the Dijkstra algorithm. |
| 41 | 41 |
template <typename V> |
| 42 | 42 |
struct DijkstraDefaultOperationTraits {
|
| 43 | 43 |
/// \e |
| 44 | 44 |
typedef V Value; |
| 45 | 45 |
/// \brief Gives back the zero value of the type. |
| 46 | 46 |
static Value zero() {
|
| 47 | 47 |
return static_cast<Value>(0); |
| 48 | 48 |
} |
| 49 | 49 |
/// \brief Gives back the sum of the given two elements. |
| 50 | 50 |
static Value plus(const Value& left, const Value& right) {
|
| 51 | 51 |
return left + right; |
| 52 | 52 |
} |
| 53 | 53 |
/// \brief Gives back true only if the first value is less than the second. |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_DIMACS_H |
| 20 | 20 |
#define LEMON_DIMACS_H |
| 21 | 21 |
|
| 22 | 22 |
#include <iostream> |
| 23 | 23 |
#include <string> |
| 24 | 24 |
#include <vector> |
| 25 | 25 |
#include <limits> |
| 26 | 26 |
#include <lemon/maps.h> |
| 27 | 27 |
#include <lemon/error.h> |
| 28 | 28 |
/// \ingroup dimacs_group |
| 29 | 29 |
/// \file |
| 30 | 30 |
/// \brief DIMACS file format reader. |
| 31 | 31 |
|
| 32 | 32 |
namespace lemon {
|
| 33 | 33 |
|
| 34 | 34 |
/// \addtogroup dimacs_group |
| 35 | 35 |
/// @{
|
| 36 | 36 |
|
| 37 | 37 |
/// DIMACS file type descriptor. |
| 38 | 38 |
struct DimacsDescriptor |
| 39 | 39 |
{
|
| 40 | 40 |
///\brief DIMACS file type enum |
| 41 | 41 |
/// |
| 42 | 42 |
///DIMACS file type enum. |
| 43 | 43 |
enum Type {
|
| 44 | 44 |
NONE, ///< Undefined type. |
| 45 | 45 |
MIN, ///< DIMACS file type for minimum cost flow problems. |
| 46 | 46 |
MAX, ///< DIMACS file type for maximum flow problems. |
| 47 | 47 |
SP, ///< DIMACS file type for shostest path problems. |
| 48 | 48 |
MAT ///< DIMACS file type for plain graphs and matching problems. |
| 49 | 49 |
}; |
| 50 | 50 |
///The file type |
| 51 | 51 |
Type type; |
| 52 | 52 |
///The number of nodes in the graph |
| 53 | 53 |
int nodeNum; |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_EDGE_SET_H |
| 20 | 20 |
#define LEMON_EDGE_SET_H |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/core.h> |
| 23 | 23 |
#include <lemon/bits/edge_set_extender.h> |
| 24 | 24 |
|
| 25 | 25 |
/// \ingroup graphs |
| 26 | 26 |
/// \file |
| 27 | 27 |
/// \brief ArcSet and EdgeSet classes. |
| 28 | 28 |
/// |
| 29 | 29 |
/// Graphs which use another graph's node-set as own. |
| 30 | 30 |
namespace lemon {
|
| 31 | 31 |
|
| 32 | 32 |
template <typename GR> |
| 33 | 33 |
class ListArcSetBase {
|
| 34 | 34 |
public: |
| 35 | 35 |
|
| 36 | 36 |
typedef typename GR::Node Node; |
| 37 | 37 |
typedef typename GR::NodeIt NodeIt; |
| 38 | 38 |
|
| 39 | 39 |
protected: |
| 40 | 40 |
|
| 41 | 41 |
struct NodeT {
|
| 42 | 42 |
int first_out, first_in; |
| 43 | 43 |
NodeT() : first_out(-1), first_in(-1) {}
|
| 44 | 44 |
}; |
| 45 | 45 |
|
| 46 | 46 |
typedef typename ItemSetTraits<GR, Node>:: |
| 47 | 47 |
template Map<NodeT>::Type NodesImplBase; |
| 48 | 48 |
|
| 49 | 49 |
NodesImplBase* _nodes; |
| 50 | 50 |
|
| 51 | 51 |
struct ArcT {
|
| 52 | 52 |
Node source, target; |
| 53 | 53 |
int next_out, next_in; |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_EULER_H |
| 20 | 20 |
#define LEMON_EULER_H |
| 21 | 21 |
|
| 22 | 22 |
#include<lemon/core.h> |
| 23 | 23 |
#include<lemon/adaptors.h> |
| 24 | 24 |
#include<lemon/connectivity.h> |
| 25 | 25 |
#include <list> |
| 26 | 26 |
|
| 27 | 27 |
/// \ingroup graph_properties |
| 28 | 28 |
/// \file |
| 29 | 29 |
/// \brief Euler tour iterators and a function for checking the \e Eulerian |
| 30 | 30 |
/// property. |
| 31 | 31 |
/// |
| 32 | 32 |
///This file provides Euler tour iterators and a function to check |
| 33 | 33 |
///if a (di)graph is \e Eulerian. |
| 34 | 34 |
|
| 35 | 35 |
namespace lemon {
|
| 36 | 36 |
|
| 37 | 37 |
///Euler tour iterator for digraphs. |
| 38 | 38 |
|
| 39 | 39 |
/// \ingroup graph_prop |
| 40 | 40 |
///This iterator provides an Euler tour (Eulerian circuit) of a \e directed |
| 41 | 41 |
///graph (if there exists) and it converts to the \c Arc type of the digraph. |
| 42 | 42 |
/// |
| 43 | 43 |
///For example, if the given digraph has an Euler tour (i.e it has only one |
| 44 | 44 |
///non-trivial component and the in-degree is equal to the out-degree |
| 45 | 45 |
///for all nodes), then the following code will put the arcs of \c g |
| 46 | 46 |
///to the vector \c et according to an Euler tour of \c g. |
| 47 | 47 |
///\code |
| 48 | 48 |
/// std::vector<ListDigraph::Arc> et; |
| 49 | 49 |
/// for(DiEulerIt<ListDigraph> e(g); e!=INVALID; ++e) |
| 50 | 50 |
/// et.push_back(e); |
| 51 | 51 |
///\endcode |
| 52 | 52 |
///If \c g has no Euler tour, then the resulted walk will not be closed |
| 53 | 53 |
///or not contain all arcs. |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_FRACTIONAL_MATCHING_H |
| 20 | 20 |
#define LEMON_FRACTIONAL_MATCHING_H |
| 21 | 21 |
|
| 22 | 22 |
#include <vector> |
| 23 | 23 |
#include <queue> |
| 24 | 24 |
#include <set> |
| 25 | 25 |
#include <limits> |
| 26 | 26 |
|
| 27 | 27 |
#include <lemon/core.h> |
| 28 | 28 |
#include <lemon/unionfind.h> |
| 29 | 29 |
#include <lemon/bin_heap.h> |
| 30 | 30 |
#include <lemon/maps.h> |
| 31 | 31 |
#include <lemon/assert.h> |
| 32 | 32 |
#include <lemon/elevator.h> |
| 33 | 33 |
|
| 34 | 34 |
///\ingroup matching |
| 35 | 35 |
///\file |
| 36 | 36 |
///\brief Fractional matching algorithms in general graphs. |
| 37 | 37 |
|
| 38 | 38 |
namespace lemon {
|
| 39 | 39 |
|
| 40 | 40 |
/// \brief Default traits class of MaxFractionalMatching class. |
| 41 | 41 |
/// |
| 42 | 42 |
/// Default traits class of MaxFractionalMatching class. |
| 43 | 43 |
/// \tparam GR Graph type. |
| 44 | 44 |
template <typename GR> |
| 45 | 45 |
struct MaxFractionalMatchingDefaultTraits {
|
| 46 | 46 |
|
| 47 | 47 |
/// \brief The type of the graph the algorithm runs on. |
| 48 | 48 |
typedef GR Graph; |
| 49 | 49 |
|
| 50 | 50 |
/// \brief The type of the map that stores the matching. |
| 51 | 51 |
/// |
| 52 | 52 |
/// The type of the map that stores the matching arcs. |
| 53 | 53 |
/// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_FULL_GRAPH_H |
| 20 | 20 |
#define LEMON_FULL_GRAPH_H |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/core.h> |
| 23 | 23 |
#include <lemon/bits/graph_extender.h> |
| 24 | 24 |
|
| 25 | 25 |
///\ingroup graphs |
| 26 | 26 |
///\file |
| 27 | 27 |
///\brief FullDigraph and FullGraph classes. |
| 28 | 28 |
|
| 29 | 29 |
namespace lemon {
|
| 30 | 30 |
|
| 31 | 31 |
class FullDigraphBase {
|
| 32 | 32 |
public: |
| 33 | 33 |
|
| 34 | 34 |
typedef FullDigraphBase Digraph; |
| 35 | 35 |
|
| 36 | 36 |
class Node; |
| 37 | 37 |
class Arc; |
| 38 | 38 |
|
| 39 | 39 |
protected: |
| 40 | 40 |
|
| 41 | 41 |
int _node_num; |
| 42 | 42 |
int _arc_num; |
| 43 | 43 |
|
| 44 | 44 |
FullDigraphBase() {}
|
| 45 | 45 |
|
| 46 | 46 |
void construct(int n) { _node_num = n; _arc_num = n * n; }
|
| 47 | 47 |
|
| 48 | 48 |
public: |
| 49 | 49 |
|
| 50 | 50 |
typedef True NodeNumTag; |
| 51 | 51 |
typedef True ArcNumTag; |
| 52 | 52 |
|
| 53 | 53 |
Node operator()(int ix) const { return Node(ix); }
|
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
///\file |
| 20 | 20 |
///\brief Implementation of the LEMON GLPK LP and MIP solver interface. |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/glpk.h> |
| 23 | 23 |
#include <glpk.h> |
| 24 | 24 |
|
| 25 | 25 |
#include <lemon/assert.h> |
| 26 | 26 |
|
| 27 | 27 |
namespace lemon {
|
| 28 | 28 |
|
| 29 | 29 |
// GlpkBase members |
| 30 | 30 |
|
| 31 | 31 |
GlpkBase::GlpkBase() : LpBase() {
|
| 32 | 32 |
lp = glp_create_prob(); |
| 33 | 33 |
glp_create_index(lp); |
| 34 | 34 |
messageLevel(MESSAGE_NOTHING); |
| 35 | 35 |
} |
| 36 | 36 |
|
| 37 | 37 |
GlpkBase::GlpkBase(const GlpkBase &other) : LpBase() {
|
| 38 | 38 |
lp = glp_create_prob(); |
| 39 | 39 |
glp_copy_prob(lp, other.lp, GLP_ON); |
| 40 | 40 |
glp_create_index(lp); |
| 41 | 41 |
rows = other.rows; |
| 42 | 42 |
cols = other.cols; |
| 43 | 43 |
messageLevel(MESSAGE_NOTHING); |
| 44 | 44 |
} |
| 45 | 45 |
|
| 46 | 46 |
GlpkBase::~GlpkBase() {
|
| 47 | 47 |
glp_delete_prob(lp); |
| 48 | 48 |
} |
| 49 | 49 |
|
| 50 | 50 |
int GlpkBase::_addCol() {
|
| 51 | 51 |
int i = glp_add_cols(lp, 1); |
| 52 | 52 |
glp_set_col_bnds(lp, i, GLP_FR, 0.0, 0.0); |
| 53 | 53 |
return i; |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_GLPK_H |
| 20 | 20 |
#define LEMON_GLPK_H |
| 21 | 21 |
|
| 22 | 22 |
///\file |
| 23 | 23 |
///\brief Header of the LEMON-GLPK lp solver interface. |
| 24 | 24 |
///\ingroup lp_group |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/lp_base.h> |
| 27 | 27 |
|
| 28 | 28 |
namespace lemon {
|
| 29 | 29 |
|
| 30 | 30 |
namespace _solver_bits {
|
| 31 | 31 |
class VoidPtr {
|
| 32 | 32 |
private: |
| 33 | 33 |
void *_ptr; |
| 34 | 34 |
public: |
| 35 | 35 |
VoidPtr() : _ptr(0) {}
|
| 36 | 36 |
|
| 37 | 37 |
template <typename T> |
| 38 | 38 |
VoidPtr(T* ptr) : _ptr(reinterpret_cast<void*>(ptr)) {}
|
| 39 | 39 |
|
| 40 | 40 |
template <typename T> |
| 41 | 41 |
VoidPtr& operator=(T* ptr) {
|
| 42 | 42 |
_ptr = reinterpret_cast<void*>(ptr); |
| 43 | 43 |
return *this; |
| 44 | 44 |
} |
| 45 | 45 |
|
| 46 | 46 |
template <typename T> |
| 47 | 47 |
operator T*() const { return reinterpret_cast<T*>(_ptr); }
|
| 48 | 48 |
}; |
| 49 | 49 |
} |
| 50 | 50 |
|
| 51 | 51 |
/// \brief Base interface for the GLPK LP and MIP solver |
| 52 | 52 |
/// |
| 53 | 53 |
/// This class implements the common interface of the GLPK LP and MIP solver. |
| 1 |
/* -*- C++ -*- |
|
| 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
| 2 | 2 |
* |
| 3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
| 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_GOMORY_HU_TREE_H |
| 20 | 20 |
#define LEMON_GOMORY_HU_TREE_H |
| 21 | 21 |
|
| 22 | 22 |
#include <limits> |
| 23 | 23 |
|
| 24 | 24 |
#include <lemon/core.h> |
| 25 | 25 |
#include <lemon/preflow.h> |
| 26 | 26 |
#include <lemon/concept_check.h> |
| 27 | 27 |
#include <lemon/concepts/maps.h> |
| 28 | 28 |
|
| 29 | 29 |
/// \ingroup min_cut |
| 30 | 30 |
/// \file |
| 31 | 31 |
/// \brief Gomory-Hu cut tree in graphs. |
| 32 | 32 |
|
| 33 | 33 |
namespace lemon {
|
| 34 | 34 |
|
| 35 | 35 |
/// \ingroup min_cut |
| 36 | 36 |
/// |
| 37 | 37 |
/// \brief Gomory-Hu cut tree algorithm |
| 38 | 38 |
/// |
| 39 | 39 |
/// The Gomory-Hu tree is a tree on the node set of a given graph, but it |
| 40 | 40 |
/// may contain edges which are not in the original graph. It has the |
| 41 | 41 |
/// property that the minimum capacity edge of the path between two nodes |
| 42 | 42 |
/// in this tree has the same weight as the minimum cut in the graph |
| 43 | 43 |
/// between these nodes. Moreover the components obtained by removing |
| 44 | 44 |
/// this edge from the tree determine the corresponding minimum cut. |
| 45 | 45 |
/// Therefore once this tree is computed, the minimum cut between any pair |
| 46 | 46 |
/// of nodes can easily be obtained. |
| 47 | 47 |
/// |
| 48 | 48 |
/// The algorithm calculates \e n-1 distinct minimum cuts (currently with |
| 49 | 49 |
/// the \ref Preflow algorithm), thus it has \f$O(n^3\sqrt{e})\f$ overall
|
| 50 | 50 |
/// time complexity. It calculates a rooted Gomory-Hu tree. |
| 51 | 51 |
/// The structure of the tree and the edge weights can be |
| 52 | 52 |
/// obtained using \c predNode(), \c predValue() and \c rootDist(). |
| 53 | 53 |
/// The functions \c minCutMap() and \c minCutValue() calculate |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_GRAPH_TO_EPS_H |
| 20 | 20 |
#define LEMON_GRAPH_TO_EPS_H |
| 21 | 21 |
|
| 22 | 22 |
#include<iostream> |
| 23 | 23 |
#include<fstream> |
| 24 | 24 |
#include<sstream> |
| 25 | 25 |
#include<algorithm> |
| 26 | 26 |
#include<vector> |
| 27 | 27 |
|
| 28 | 28 |
#ifndef WIN32 |
| 29 | 29 |
#include<sys/time.h> |
| 30 | 30 |
#include<ctime> |
| 31 | 31 |
#else |
| 32 | 32 |
#include<lemon/bits/windows.h> |
| 33 | 33 |
#endif |
| 34 | 34 |
|
| 35 | 35 |
#include<lemon/math.h> |
| 36 | 36 |
#include<lemon/core.h> |
| 37 | 37 |
#include<lemon/dim2.h> |
| 38 | 38 |
#include<lemon/maps.h> |
| 39 | 39 |
#include<lemon/color.h> |
| 40 | 40 |
#include<lemon/bits/bezier.h> |
| 41 | 41 |
#include<lemon/error.h> |
| 42 | 42 |
|
| 43 | 43 |
|
| 44 | 44 |
///\ingroup eps_io |
| 45 | 45 |
///\file |
| 46 | 46 |
///\brief A well configurable tool for visualizing graphs |
| 47 | 47 |
|
| 48 | 48 |
namespace lemon {
|
| 49 | 49 |
|
| 50 | 50 |
namespace _graph_to_eps_bits {
|
| 51 | 51 |
template<class MT> |
| 52 | 52 |
class _NegY {
|
| 53 | 53 |
public: |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_HAO_ORLIN_H |
| 20 | 20 |
#define LEMON_HAO_ORLIN_H |
| 21 | 21 |
|
| 22 | 22 |
#include <vector> |
| 23 | 23 |
#include <list> |
| 24 | 24 |
#include <limits> |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/maps.h> |
| 27 | 27 |
#include <lemon/core.h> |
| 28 | 28 |
#include <lemon/tolerance.h> |
| 29 | 29 |
|
| 30 | 30 |
/// \file |
| 31 | 31 |
/// \ingroup min_cut |
| 32 | 32 |
/// \brief Implementation of the Hao-Orlin algorithm. |
| 33 | 33 |
/// |
| 34 | 34 |
/// Implementation of the Hao-Orlin algorithm for finding a minimum cut |
| 35 | 35 |
/// in a digraph. |
| 36 | 36 |
|
| 37 | 37 |
namespace lemon {
|
| 38 | 38 |
|
| 39 | 39 |
/// \ingroup min_cut |
| 40 | 40 |
/// |
| 41 | 41 |
/// \brief Hao-Orlin algorithm for finding a minimum cut in a digraph. |
| 42 | 42 |
/// |
| 43 | 43 |
/// This class implements the Hao-Orlin algorithm for finding a minimum |
| 44 | 44 |
/// value cut in a directed graph \f$D=(V,A)\f$. |
| 45 | 45 |
/// It takes a fixed node \f$ source \in V \f$ and |
| 46 | 46 |
/// consists of two phases: in the first phase it determines a |
| 47 | 47 |
/// minimum cut with \f$ source \f$ on the source-side (i.e. a set |
| 48 | 48 |
/// \f$ X\subsetneq V \f$ with \f$ source \in X \f$ and minimal outgoing |
| 49 | 49 |
/// capacity) and in the second phase it determines a minimum cut |
| 50 | 50 |
/// with \f$ source \f$ on the sink-side (i.e. a set |
| 51 | 51 |
/// \f$ X\subsetneq V \f$ with \f$ source \notin X \f$ and minimal outgoing |
| 52 | 52 |
/// capacity). Obviously, the smaller of these two cuts will be a |
| 53 | 53 |
/// minimum cut of \f$ D \f$. The algorithm is a modified |
| 1 |
/* -*- C++ -*- |
|
| 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
| 2 | 2 |
* |
| 3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
| 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_HARTMANN_ORLIN_MMC_H |
| 20 | 20 |
#define LEMON_HARTMANN_ORLIN_MMC_H |
| 21 | 21 |
|
| 22 | 22 |
/// \ingroup min_mean_cycle |
| 23 | 23 |
/// |
| 24 | 24 |
/// \file |
| 25 | 25 |
/// \brief Hartmann-Orlin's algorithm for finding a minimum mean cycle. |
| 26 | 26 |
|
| 27 | 27 |
#include <vector> |
| 28 | 28 |
#include <limits> |
| 29 | 29 |
#include <lemon/core.h> |
| 30 | 30 |
#include <lemon/path.h> |
| 31 | 31 |
#include <lemon/tolerance.h> |
| 32 | 32 |
#include <lemon/connectivity.h> |
| 33 | 33 |
|
| 34 | 34 |
namespace lemon {
|
| 35 | 35 |
|
| 36 | 36 |
/// \brief Default traits class of HartmannOrlinMmc class. |
| 37 | 37 |
/// |
| 38 | 38 |
/// Default traits class of HartmannOrlinMmc class. |
| 39 | 39 |
/// \tparam GR The type of the digraph. |
| 40 | 40 |
/// \tparam CM The type of the cost map. |
| 41 | 41 |
/// It must conform to the \ref concepts::Rea_data "Rea_data" concept. |
| 42 | 42 |
#ifdef DOXYGEN |
| 43 | 43 |
template <typename GR, typename CM> |
| 44 | 44 |
#else |
| 45 | 45 |
template <typename GR, typename CM, |
| 46 | 46 |
bool integer = std::numeric_limits<typename CM::Value>::is_integer> |
| 47 | 47 |
#endif |
| 48 | 48 |
struct HartmannOrlinMmcDefaultTraits |
| 49 | 49 |
{
|
| 50 | 50 |
/// The type of the digraph |
| 51 | 51 |
typedef GR Digraph; |
| 52 | 52 |
/// The type of the cost map |
| 53 | 53 |
typedef CM CostMap; |
| 1 |
/* -*- C++ -*- |
|
| 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
| 2 | 2 |
* |
| 3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
| 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_HOWARD_MMC_H |
| 20 | 20 |
#define LEMON_HOWARD_MMC_H |
| 21 | 21 |
|
| 22 | 22 |
/// \ingroup min_mean_cycle |
| 23 | 23 |
/// |
| 24 | 24 |
/// \file |
| 25 | 25 |
/// \brief Howard's algorithm for finding a minimum mean cycle. |
| 26 | 26 |
|
| 27 | 27 |
#include <vector> |
| 28 | 28 |
#include <limits> |
| 29 | 29 |
#include <lemon/core.h> |
| 30 | 30 |
#include <lemon/path.h> |
| 31 | 31 |
#include <lemon/tolerance.h> |
| 32 | 32 |
#include <lemon/connectivity.h> |
| 33 | 33 |
|
| 34 | 34 |
namespace lemon {
|
| 35 | 35 |
|
| 36 | 36 |
/// \brief Default traits class of HowardMmc class. |
| 37 | 37 |
/// |
| 38 | 38 |
/// Default traits class of HowardMmc class. |
| 39 | 39 |
/// \tparam GR The type of the digraph. |
| 40 | 40 |
/// \tparam CM The type of the cost map. |
| 41 | 41 |
/// It must conform to the \ref concepts::ReadMap "ReadMap" concept. |
| 42 | 42 |
#ifdef DOXYGEN |
| 43 | 43 |
template <typename GR, typename CM> |
| 44 | 44 |
#else |
| 45 | 45 |
template <typename GR, typename CM, |
| 46 | 46 |
bool integer = std::numeric_limits<typename CM::Value>::is_integer> |
| 47 | 47 |
#endif |
| 48 | 48 |
struct HowardMmcDefaultTraits |
| 49 | 49 |
{
|
| 50 | 50 |
/// The type of the digraph |
| 51 | 51 |
typedef GR Digraph; |
| 52 | 52 |
/// The type of the cost map |
| 53 | 53 |
typedef CM CostMap; |
| 1 |
/* -*- C++ -*- |
|
| 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
| 2 | 2 |
* |
| 3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
| 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_KARP_MMC_H |
| 20 | 20 |
#define LEMON_KARP_MMC_H |
| 21 | 21 |
|
| 22 | 22 |
/// \ingroup min_mean_cycle |
| 23 | 23 |
/// |
| 24 | 24 |
/// \file |
| 25 | 25 |
/// \brief Karp's algorithm for finding a minimum mean cycle. |
| 26 | 26 |
|
| 27 | 27 |
#include <vector> |
| 28 | 28 |
#include <limits> |
| 29 | 29 |
#include <lemon/core.h> |
| 30 | 30 |
#include <lemon/path.h> |
| 31 | 31 |
#include <lemon/tolerance.h> |
| 32 | 32 |
#include <lemon/connectivity.h> |
| 33 | 33 |
|
| 34 | 34 |
namespace lemon {
|
| 35 | 35 |
|
| 36 | 36 |
/// \brief Default traits class of KarpMmc class. |
| 37 | 37 |
/// |
| 38 | 38 |
/// Default traits class of KarpMmc class. |
| 39 | 39 |
/// \tparam GR The type of the digraph. |
| 40 | 40 |
/// \tparam CM The type of the cost map. |
| 41 | 41 |
/// It must conform to the \ref concepts::ReadMap "ReadMap" concept. |
| 42 | 42 |
#ifdef DOXYGEN |
| 43 | 43 |
template <typename GR, typename CM> |
| 44 | 44 |
#else |
| 45 | 45 |
template <typename GR, typename CM, |
| 46 | 46 |
bool integer = std::numeric_limits<typename CM::Value>::is_integer> |
| 47 | 47 |
#endif |
| 48 | 48 |
struct KarpMmcDefaultTraits |
| 49 | 49 |
{
|
| 50 | 50 |
/// The type of the digraph |
| 51 | 51 |
typedef GR Digraph; |
| 52 | 52 |
/// The type of the cost map |
| 53 | 53 |
typedef CM CostMap; |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 lemon_io |
| 20 | 20 |
///\file |
| 21 | 21 |
///\brief \ref lgf-format "LEMON Graph Format" reader. |
| 22 | 22 |
|
| 23 | 23 |
|
| 24 | 24 |
#ifndef LEMON_LGF_READER_H |
| 25 | 25 |
#define LEMON_LGF_READER_H |
| 26 | 26 |
|
| 27 | 27 |
#include <iostream> |
| 28 | 28 |
#include <fstream> |
| 29 | 29 |
#include <sstream> |
| 30 | 30 |
|
| 31 | 31 |
#include <set> |
| 32 | 32 |
#include <map> |
| 33 | 33 |
|
| 34 | 34 |
#include <lemon/core.h> |
| 35 | 35 |
|
| 36 | 36 |
#include <lemon/lgf_writer.h> |
| 37 | 37 |
|
| 38 | 38 |
#include <lemon/concept_check.h> |
| 39 | 39 |
#include <lemon/concepts/maps.h> |
| 40 | 40 |
|
| 41 | 41 |
namespace lemon {
|
| 42 | 42 |
|
| 43 | 43 |
namespace _reader_bits {
|
| 44 | 44 |
|
| 45 | 45 |
template <typename Value> |
| 46 | 46 |
struct DefaultConverter {
|
| 47 | 47 |
Value operator()(const std::string& str) {
|
| 48 | 48 |
std::istringstream is(str); |
| 49 | 49 |
Value value; |
| 50 | 50 |
if (!(is >> value)) {
|
| 51 | 51 |
throw FormatError("Cannot read token");
|
| 52 | 52 |
} |
| 53 | 53 |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 lemon_io |
| 20 | 20 |
///\file |
| 21 | 21 |
///\brief \ref lgf-format "LEMON Graph Format" writer. |
| 22 | 22 |
|
| 23 | 23 |
|
| 24 | 24 |
#ifndef LEMON_LGF_WRITER_H |
| 25 | 25 |
#define LEMON_LGF_WRITER_H |
| 26 | 26 |
|
| 27 | 27 |
#include <iostream> |
| 28 | 28 |
#include <fstream> |
| 29 | 29 |
#include <sstream> |
| 30 | 30 |
|
| 31 | 31 |
#include <algorithm> |
| 32 | 32 |
|
| 33 | 33 |
#include <vector> |
| 34 | 34 |
#include <functional> |
| 35 | 35 |
|
| 36 | 36 |
#include <lemon/core.h> |
| 37 | 37 |
#include <lemon/maps.h> |
| 38 | 38 |
|
| 39 | 39 |
#include <lemon/concept_check.h> |
| 40 | 40 |
#include <lemon/concepts/maps.h> |
| 41 | 41 |
|
| 42 | 42 |
namespace lemon {
|
| 43 | 43 |
|
| 44 | 44 |
namespace _writer_bits {
|
| 45 | 45 |
|
| 46 | 46 |
template <typename Value> |
| 47 | 47 |
struct DefaultConverter {
|
| 48 | 48 |
std::string operator()(const Value& value) {
|
| 49 | 49 |
std::ostringstream os; |
| 50 | 50 |
os << value; |
| 51 | 51 |
return os.str(); |
| 52 | 52 |
} |
| 53 | 53 |
}; |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_LIST_GRAPH_H |
| 20 | 20 |
#define LEMON_LIST_GRAPH_H |
| 21 | 21 |
|
| 22 | 22 |
///\ingroup graphs |
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief ListDigraph and ListGraph classes. |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/core.h> |
| 27 | 27 |
#include <lemon/error.h> |
| 28 | 28 |
#include <lemon/bits/graph_extender.h> |
| 29 | 29 |
|
| 30 | 30 |
#include <vector> |
| 31 | 31 |
#include <list> |
| 32 | 32 |
|
| 33 | 33 |
namespace lemon {
|
| 34 | 34 |
|
| 35 | 35 |
class ListDigraph; |
| 36 | 36 |
|
| 37 | 37 |
class ListDigraphBase {
|
| 38 | 38 |
|
| 39 | 39 |
protected: |
| 40 | 40 |
struct NodeT {
|
| 41 | 41 |
int first_in, first_out; |
| 42 | 42 |
int prev, next; |
| 43 | 43 |
}; |
| 44 | 44 |
|
| 45 | 45 |
struct ArcT {
|
| 46 | 46 |
int target, source; |
| 47 | 47 |
int prev_in, prev_out; |
| 48 | 48 |
int next_in, next_out; |
| 49 | 49 |
}; |
| 50 | 50 |
|
| 51 | 51 |
std::vector<NodeT> nodes; |
| 52 | 52 |
|
| 53 | 53 |
int first_node; |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_LP_H |
| 20 | 20 |
#define LEMON_LP_H |
| 21 | 21 |
|
| 22 | 22 |
#include<lemon/config.h> |
| 23 | 23 |
|
| 24 | 24 |
|
| 25 | 25 |
#ifdef LEMON_HAVE_GLPK |
| 26 | 26 |
#include <lemon/glpk.h> |
| 27 | 27 |
#elif LEMON_HAVE_CPLEX |
| 28 | 28 |
#include <lemon/cplex.h> |
| 29 | 29 |
#elif LEMON_HAVE_SOPLEX |
| 30 | 30 |
#include <lemon/soplex.h> |
| 31 | 31 |
#elif LEMON_HAVE_CLP |
| 32 | 32 |
#include <lemon/clp.h> |
| 33 | 33 |
#endif |
| 34 | 34 |
|
| 35 | 35 |
///\file |
| 36 | 36 |
///\brief Defines a default LP solver |
| 37 | 37 |
///\ingroup lp_group |
| 38 | 38 |
namespace lemon {
|
| 39 | 39 |
|
| 40 | 40 |
#ifdef DOXYGEN |
| 41 | 41 |
///The default LP solver identifier |
| 42 | 42 |
|
| 43 | 43 |
///The default LP solver identifier. |
| 44 | 44 |
///\ingroup lp_group |
| 45 | 45 |
/// |
| 46 | 46 |
///Currently, the possible values are \c GLPK, \c CPLEX, |
| 47 | 47 |
///\c SOPLEX or \c CLP |
| 48 | 48 |
#define LEMON_DEFAULT_LP SOLVER |
| 49 | 49 |
///The default LP solver |
| 50 | 50 |
|
| 51 | 51 |
///The default LP solver. |
| 52 | 52 |
///\ingroup lp_group |
| 53 | 53 |
/// |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
///\file |
| 20 | 20 |
///\brief The implementation of the LP solver interface. |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/lp_base.h> |
| 23 | 23 |
namespace lemon {
|
| 24 | 24 |
|
| 25 | 25 |
const LpBase::Value LpBase::INF = |
| 26 | 26 |
std::numeric_limits<LpBase::Value>::infinity(); |
| 27 | 27 |
const LpBase::Value LpBase::NaN = |
| 28 | 28 |
std::numeric_limits<LpBase::Value>::quiet_NaN(); |
| 29 | 29 |
|
| 30 | 30 |
} //namespace lemon |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_LP_BASE_H |
| 20 | 20 |
#define LEMON_LP_BASE_H |
| 21 | 21 |
|
| 22 | 22 |
#include<iostream> |
| 23 | 23 |
#include<vector> |
| 24 | 24 |
#include<map> |
| 25 | 25 |
#include<limits> |
| 26 | 26 |
#include<lemon/math.h> |
| 27 | 27 |
|
| 28 | 28 |
#include<lemon/error.h> |
| 29 | 29 |
#include<lemon/assert.h> |
| 30 | 30 |
|
| 31 | 31 |
#include<lemon/core.h> |
| 32 | 32 |
#include<lemon/bits/solver_bits.h> |
| 33 | 33 |
|
| 34 | 34 |
///\file |
| 35 | 35 |
///\brief The interface of the LP solver interface. |
| 36 | 36 |
///\ingroup lp_group |
| 37 | 37 |
namespace lemon {
|
| 38 | 38 |
|
| 39 | 39 |
///Common base class for LP and MIP solvers |
| 40 | 40 |
|
| 41 | 41 |
///Usually this class is not used directly, please use one of the concrete |
| 42 | 42 |
///implementations of the solver interface. |
| 43 | 43 |
///\ingroup lp_group |
| 44 | 44 |
class LpBase {
|
| 45 | 45 |
|
| 46 | 46 |
protected: |
| 47 | 47 |
|
| 48 | 48 |
_solver_bits::VarIndex rows; |
| 49 | 49 |
_solver_bits::VarIndex cols; |
| 50 | 50 |
|
| 51 | 51 |
public: |
| 52 | 52 |
|
| 53 | 53 |
///Possible outcomes of an LP solving procedure |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <lemon/lp_skeleton.h> |
| 20 | 20 |
|
| 21 | 21 |
///\file |
| 22 | 22 |
///\brief A skeleton file to implement LP solver interfaces |
| 23 | 23 |
namespace lemon {
|
| 24 | 24 |
|
| 25 | 25 |
int SkeletonSolverBase::_addCol() |
| 26 | 26 |
{
|
| 27 | 27 |
return ++col_num; |
| 28 | 28 |
} |
| 29 | 29 |
|
| 30 | 30 |
int SkeletonSolverBase::_addRow() |
| 31 | 31 |
{
|
| 32 | 32 |
return ++row_num; |
| 33 | 33 |
} |
| 34 | 34 |
|
| 35 | 35 |
int SkeletonSolverBase::_addRow(Value, ExprIterator, ExprIterator, Value) |
| 36 | 36 |
{
|
| 37 | 37 |
return ++row_num; |
| 38 | 38 |
} |
| 39 | 39 |
|
| 40 | 40 |
void SkeletonSolverBase::_eraseCol(int) {}
|
| 41 | 41 |
void SkeletonSolverBase::_eraseRow(int) {}
|
| 42 | 42 |
|
| 43 | 43 |
void SkeletonSolverBase::_getColName(int, std::string &) const {}
|
| 44 | 44 |
void SkeletonSolverBase::_setColName(int, const std::string &) {}
|
| 45 | 45 |
int SkeletonSolverBase::_colByName(const std::string&) const { return -1; }
|
| 46 | 46 |
|
| 47 | 47 |
void SkeletonSolverBase::_getRowName(int, std::string &) const {}
|
| 48 | 48 |
void SkeletonSolverBase::_setRowName(int, const std::string &) {}
|
| 49 | 49 |
int SkeletonSolverBase::_rowByName(const std::string&) const { return -1; }
|
| 50 | 50 |
|
| 51 | 51 |
void SkeletonSolverBase::_setRowCoeffs(int, ExprIterator, ExprIterator) {}
|
| 52 | 52 |
void SkeletonSolverBase::_getRowCoeffs(int, InsertIterator) const {}
|
| 53 | 53 |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_LP_SKELETON_H |
| 20 | 20 |
#define LEMON_LP_SKELETON_H |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/lp_base.h> |
| 23 | 23 |
|
| 24 | 24 |
///\file |
| 25 | 25 |
///\brief Skeleton file to implement LP/MIP solver interfaces |
| 26 | 26 |
/// |
| 27 | 27 |
///The classes in this file do nothing, but they can serve as skeletons when |
| 28 | 28 |
///implementing an interface to new solvers. |
| 29 | 29 |
namespace lemon {
|
| 30 | 30 |
|
| 31 | 31 |
///A skeleton class to implement LP/MIP solver base interface |
| 32 | 32 |
|
| 33 | 33 |
///This class does nothing, but it can serve as a skeleton when |
| 34 | 34 |
///implementing an interface to new solvers. |
| 35 | 35 |
class SkeletonSolverBase : public virtual LpBase {
|
| 36 | 36 |
int col_num,row_num; |
| 37 | 37 |
|
| 38 | 38 |
protected: |
| 39 | 39 |
|
| 40 | 40 |
SkeletonSolverBase() |
| 41 | 41 |
: col_num(-1), row_num(-1) {}
|
| 42 | 42 |
|
| 43 | 43 |
/// \e |
| 44 | 44 |
virtual int _addCol(); |
| 45 | 45 |
/// \e |
| 46 | 46 |
virtual int _addRow(); |
| 47 | 47 |
/// \e |
| 48 | 48 |
virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u); |
| 49 | 49 |
/// \e |
| 50 | 50 |
virtual void _eraseCol(int i); |
| 51 | 51 |
/// \e |
| 52 | 52 |
virtual void _eraseRow(int i); |
| 53 | 53 |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_MAPS_H |
| 20 | 20 |
#define LEMON_MAPS_H |
| 21 | 21 |
|
| 22 | 22 |
#include <iterator> |
| 23 | 23 |
#include <functional> |
| 24 | 24 |
#include <vector> |
| 25 | 25 |
#include <map> |
| 26 | 26 |
|
| 27 | 27 |
#include <lemon/core.h> |
| 28 | 28 |
|
| 29 | 29 |
///\file |
| 30 | 30 |
///\ingroup maps |
| 31 | 31 |
///\brief Miscellaneous property maps |
| 32 | 32 |
|
| 33 | 33 |
namespace lemon {
|
| 34 | 34 |
|
| 35 | 35 |
/// \addtogroup maps |
| 36 | 36 |
/// @{
|
| 37 | 37 |
|
| 38 | 38 |
/// Base class of maps. |
| 39 | 39 |
|
| 40 | 40 |
/// Base class of maps. It provides the necessary type definitions |
| 41 | 41 |
/// required by the map %concepts. |
| 42 | 42 |
template<typename K, typename V> |
| 43 | 43 |
class MapBase {
|
| 44 | 44 |
public: |
| 45 | 45 |
/// \brief The key type of the map. |
| 46 | 46 |
typedef K Key; |
| 47 | 47 |
/// \brief The value type of the map. |
| 48 | 48 |
/// (The type of objects associated with the keys). |
| 49 | 49 |
typedef V Value; |
| 50 | 50 |
}; |
| 51 | 51 |
|
| 52 | 52 |
|
| 53 | 53 |
/// Null map. (a.k.a. DoNothingMap) |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_MATCHING_H |
| 20 | 20 |
#define LEMON_MATCHING_H |
| 21 | 21 |
|
| 22 | 22 |
#include <vector> |
| 23 | 23 |
#include <queue> |
| 24 | 24 |
#include <set> |
| 25 | 25 |
#include <limits> |
| 26 | 26 |
|
| 27 | 27 |
#include <lemon/core.h> |
| 28 | 28 |
#include <lemon/unionfind.h> |
| 29 | 29 |
#include <lemon/bin_heap.h> |
| 30 | 30 |
#include <lemon/maps.h> |
| 31 | 31 |
#include <lemon/fractional_matching.h> |
| 32 | 32 |
|
| 33 | 33 |
///\ingroup matching |
| 34 | 34 |
///\file |
| 35 | 35 |
///\brief Maximum matching algorithms in general graphs. |
| 36 | 36 |
|
| 37 | 37 |
namespace lemon {
|
| 38 | 38 |
|
| 39 | 39 |
/// \ingroup matching |
| 40 | 40 |
/// |
| 41 | 41 |
/// \brief Maximum cardinality matching in general graphs |
| 42 | 42 |
/// |
| 43 | 43 |
/// This class implements Edmonds' alternating forest matching algorithm |
| 44 | 44 |
/// for finding a maximum cardinality matching in a general undirected graph. |
| 45 | 45 |
/// It can be started from an arbitrary initial matching |
| 46 | 46 |
/// (the default is the empty one). |
| 47 | 47 |
/// |
| 48 | 48 |
/// The dual solution of the problem is a map of the nodes to |
| 49 | 49 |
/// \ref MaxMatching::Status "Status", having values \c EVEN (or \c D), |
| 50 | 50 |
/// \c ODD (or \c A) and \c MATCHED (or \c C) defining the Gallai-Edmonds |
| 51 | 51 |
/// decomposition of the graph. The nodes in \c EVEN/D induce a subgraph |
| 52 | 52 |
/// with factor-critical components, the nodes in \c ODD/A form the |
| 53 | 53 |
/// canonical barrier, and the nodes in \c MATCHED/C induce a graph having |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_MATH_H |
| 20 | 20 |
#define LEMON_MATH_H |
| 21 | 21 |
|
| 22 | 22 |
///\ingroup misc |
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief Some extensions to the standard \c cmath library. |
| 25 | 25 |
/// |
| 26 | 26 |
///Some extensions to the standard \c cmath library. |
| 27 | 27 |
/// |
| 28 | 28 |
///This file includes the standard math library (cmath). |
| 29 | 29 |
|
| 30 | 30 |
#include<cmath> |
| 31 | 31 |
|
| 32 | 32 |
namespace lemon {
|
| 33 | 33 |
|
| 34 | 34 |
/// \addtogroup misc |
| 35 | 35 |
/// @{
|
| 36 | 36 |
|
| 37 | 37 |
/// The Euler constant |
| 38 | 38 |
const long double E = 2.7182818284590452353602874713526625L; |
| 39 | 39 |
/// log_2(e) |
| 40 | 40 |
const long double LOG2E = 1.4426950408889634073599246810018921L; |
| 41 | 41 |
/// log_10(e) |
| 42 | 42 |
const long double LOG10E = 0.4342944819032518276511289189166051L; |
| 43 | 43 |
/// ln(2) |
| 44 | 44 |
const long double LN2 = 0.6931471805599453094172321214581766L; |
| 45 | 45 |
/// ln(10) |
| 46 | 46 |
const long double LN10 = 2.3025850929940456840179914546843642L; |
| 47 | 47 |
/// pi |
| 48 | 48 |
const long double PI = 3.1415926535897932384626433832795029L; |
| 49 | 49 |
/// pi/2 |
| 50 | 50 |
const long double PI_2 = 1.5707963267948966192313216916397514L; |
| 51 | 51 |
/// pi/4 |
| 52 | 52 |
const long double PI_4 = 0.7853981633974483096156608458198757L; |
| 53 | 53 |
/// sqrt(2) |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_MIN_COST_ARBORESCENCE_H |
| 20 | 20 |
#define LEMON_MIN_COST_ARBORESCENCE_H |
| 21 | 21 |
|
| 22 | 22 |
///\ingroup spantree |
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief Minimum Cost Arborescence algorithm. |
| 25 | 25 |
|
| 26 | 26 |
#include <vector> |
| 27 | 27 |
|
| 28 | 28 |
#include <lemon/list_graph.h> |
| 29 | 29 |
#include <lemon/bin_heap.h> |
| 30 | 30 |
#include <lemon/assert.h> |
| 31 | 31 |
|
| 32 | 32 |
namespace lemon {
|
| 33 | 33 |
|
| 34 | 34 |
|
| 35 | 35 |
/// \brief Default traits class for MinCostArborescence class. |
| 36 | 36 |
/// |
| 37 | 37 |
/// Default traits class for MinCostArborescence class. |
| 38 | 38 |
/// \param GR Digraph type. |
| 39 | 39 |
/// \param CM Type of the cost map. |
| 40 | 40 |
template <class GR, class CM> |
| 41 | 41 |
struct MinCostArborescenceDefaultTraits{
|
| 42 | 42 |
|
| 43 | 43 |
/// \brief The digraph type the algorithm runs on. |
| 44 | 44 |
typedef GR Digraph; |
| 45 | 45 |
|
| 46 | 46 |
/// \brief The type of the map that stores the arc costs. |
| 47 | 47 |
/// |
| 48 | 48 |
/// The type of the map that stores the arc costs. |
| 49 | 49 |
/// It must conform to the \ref concepts::ReadMap "ReadMap" concept. |
| 50 | 50 |
typedef CM CostMap; |
| 51 | 51 |
|
| 52 | 52 |
/// \brief The value type of the costs. |
| 53 | 53 |
/// |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_NETWORK_SIMPLEX_H |
| 20 | 20 |
#define LEMON_NETWORK_SIMPLEX_H |
| 21 | 21 |
|
| 22 | 22 |
/// \ingroup min_cost_flow_algs |
| 23 | 23 |
/// |
| 24 | 24 |
/// \file |
| 25 | 25 |
/// \brief Network Simplex algorithm for finding a minimum cost flow. |
| 26 | 26 |
|
| 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 |
/// \ref amo93networkflows, \ref dantzig63linearprog, |
| 45 | 45 |
/// \ref kellyoneill91netsimplex. |
| 46 | 46 |
/// This algorithm is a highly efficient specialized version of the |
| 47 | 47 |
/// linear programming simplex method directly for the minimum cost |
| 48 | 48 |
/// flow problem. |
| 49 | 49 |
/// |
| 50 | 50 |
/// In general, %NetworkSimplex is the fastest implementation available |
| 51 | 51 |
/// in LEMON for this problem. |
| 52 | 52 |
/// Moreover, it supports both directions of the supply/demand inequality |
| 53 | 53 |
/// constraints. For more information, see \ref SupplyType. |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 paths |
| 20 | 20 |
///\file |
| 21 | 21 |
///\brief Classes for representing paths in digraphs. |
| 22 | 22 |
/// |
| 23 | 23 |
|
| 24 | 24 |
#ifndef LEMON_PATH_H |
| 25 | 25 |
#define LEMON_PATH_H |
| 26 | 26 |
|
| 27 | 27 |
#include <vector> |
| 28 | 28 |
#include <algorithm> |
| 29 | 29 |
|
| 30 | 30 |
#include <lemon/error.h> |
| 31 | 31 |
#include <lemon/core.h> |
| 32 | 32 |
#include <lemon/concepts/path.h> |
| 33 | 33 |
|
| 34 | 34 |
namespace lemon {
|
| 35 | 35 |
|
| 36 | 36 |
/// \addtogroup paths |
| 37 | 37 |
/// @{
|
| 38 | 38 |
|
| 39 | 39 |
|
| 40 | 40 |
/// \brief A structure for representing directed paths in a digraph. |
| 41 | 41 |
/// |
| 42 | 42 |
/// A structure for representing directed path in a digraph. |
| 43 | 43 |
/// \tparam GR The digraph type in which the path is. |
| 44 | 44 |
/// |
| 45 | 45 |
/// In a sense, the path can be treated as a list of arcs. The |
| 46 | 46 |
/// lemon path type stores just this list. As a consequence, it |
| 47 | 47 |
/// cannot enumerate the nodes of the path and the source node of |
| 48 | 48 |
/// a zero length path is undefined. |
| 49 | 49 |
/// |
| 50 | 50 |
/// This implementation is a back and front insertable and erasable |
| 51 | 51 |
/// path type. It can be indexed in O(1) time. The front and back |
| 52 | 52 |
/// insertion and erase is done in O(1) (amortized) time. The |
| 53 | 53 |
/// implementation uses two vectors for storing the front and back |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_PLANARITY_H |
| 20 | 20 |
#define LEMON_PLANARITY_H |
| 21 | 21 |
|
| 22 | 22 |
/// \ingroup planar |
| 23 | 23 |
/// \file |
| 24 | 24 |
/// \brief Planarity checking, embedding, drawing and coloring |
| 25 | 25 |
|
| 26 | 26 |
#include <vector> |
| 27 | 27 |
#include <list> |
| 28 | 28 |
|
| 29 | 29 |
#include <lemon/dfs.h> |
| 30 | 30 |
#include <lemon/bfs.h> |
| 31 | 31 |
#include <lemon/radix_sort.h> |
| 32 | 32 |
#include <lemon/maps.h> |
| 33 | 33 |
#include <lemon/path.h> |
| 34 | 34 |
#include <lemon/bucket_heap.h> |
| 35 | 35 |
#include <lemon/adaptors.h> |
| 36 | 36 |
#include <lemon/edge_set.h> |
| 37 | 37 |
#include <lemon/color.h> |
| 38 | 38 |
#include <lemon/dim2.h> |
| 39 | 39 |
|
| 40 | 40 |
namespace lemon {
|
| 41 | 41 |
|
| 42 | 42 |
namespace _planarity_bits {
|
| 43 | 43 |
|
| 44 | 44 |
template <typename Graph> |
| 45 | 45 |
struct PlanarityVisitor : DfsVisitor<Graph> {
|
| 46 | 46 |
|
| 47 | 47 |
TEMPLATE_GRAPH_TYPEDEFS(Graph); |
| 48 | 48 |
|
| 49 | 49 |
typedef typename Graph::template NodeMap<Arc> PredMap; |
| 50 | 50 |
|
| 51 | 51 |
typedef typename Graph::template EdgeMap<bool> TreeMap; |
| 52 | 52 |
|
| 53 | 53 |
typedef typename Graph::template NodeMap<int> OrderMap; |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_PREFLOW_H |
| 20 | 20 |
#define LEMON_PREFLOW_H |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/tolerance.h> |
| 23 | 23 |
#include <lemon/elevator.h> |
| 24 | 24 |
|
| 25 | 25 |
/// \file |
| 26 | 26 |
/// \ingroup max_flow |
| 27 | 27 |
/// \brief Implementation of the preflow algorithm. |
| 28 | 28 |
|
| 29 | 29 |
namespace lemon {
|
| 30 | 30 |
|
| 31 | 31 |
/// \brief Default traits class of Preflow class. |
| 32 | 32 |
/// |
| 33 | 33 |
/// Default traits class of Preflow class. |
| 34 | 34 |
/// \tparam GR Digraph type. |
| 35 | 35 |
/// \tparam CAP Capacity map type. |
| 36 | 36 |
template <typename GR, typename CAP> |
| 37 | 37 |
struct PreflowDefaultTraits {
|
| 38 | 38 |
|
| 39 | 39 |
/// \brief The type of the digraph the algorithm runs on. |
| 40 | 40 |
typedef GR Digraph; |
| 41 | 41 |
|
| 42 | 42 |
/// \brief The type of the map that stores the arc capacities. |
| 43 | 43 |
/// |
| 44 | 44 |
/// The type of the map that stores the arc capacities. |
| 45 | 45 |
/// It must meet the \ref concepts::ReadMap "ReadMap" concept. |
| 46 | 46 |
typedef CAP CapacityMap; |
| 47 | 47 |
|
| 48 | 48 |
/// \brief The type of the flow values. |
| 49 | 49 |
typedef typename CapacityMap::Value Value; |
| 50 | 50 |
|
| 51 | 51 |
/// \brief The type of the map that stores the flow values. |
| 52 | 52 |
/// |
| 53 | 53 |
/// The type of the map that stores the flow values. |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_SMART_GRAPH_H |
| 20 | 20 |
#define LEMON_SMART_GRAPH_H |
| 21 | 21 |
|
| 22 | 22 |
///\ingroup graphs |
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief SmartDigraph and SmartGraph classes. |
| 25 | 25 |
|
| 26 | 26 |
#include <vector> |
| 27 | 27 |
|
| 28 | 28 |
#include <lemon/core.h> |
| 29 | 29 |
#include <lemon/error.h> |
| 30 | 30 |
#include <lemon/bits/graph_extender.h> |
| 31 | 31 |
|
| 32 | 32 |
namespace lemon {
|
| 33 | 33 |
|
| 34 | 34 |
class SmartDigraph; |
| 35 | 35 |
|
| 36 | 36 |
class SmartDigraphBase {
|
| 37 | 37 |
protected: |
| 38 | 38 |
|
| 39 | 39 |
struct NodeT |
| 40 | 40 |
{
|
| 41 | 41 |
int first_in, first_out; |
| 42 | 42 |
NodeT() {}
|
| 43 | 43 |
}; |
| 44 | 44 |
struct ArcT |
| 45 | 45 |
{
|
| 46 | 46 |
int target, source, next_in, next_out; |
| 47 | 47 |
ArcT() {}
|
| 48 | 48 |
}; |
| 49 | 49 |
|
| 50 | 50 |
std::vector<NodeT> nodes; |
| 51 | 51 |
std::vector<ArcT> arcs; |
| 52 | 52 |
|
| 53 | 53 |
public: |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <iostream> |
| 20 | 20 |
#include <lemon/soplex.h> |
| 21 | 21 |
|
| 22 | 22 |
#include <soplex.h> |
| 23 | 23 |
#include <spxout.h> |
| 24 | 24 |
|
| 25 | 25 |
|
| 26 | 26 |
///\file |
| 27 | 27 |
///\brief Implementation of the LEMON-SOPLEX lp solver interface. |
| 28 | 28 |
namespace lemon {
|
| 29 | 29 |
|
| 30 | 30 |
SoplexLp::SoplexLp() {
|
| 31 | 31 |
soplex = new soplex::SoPlex; |
| 32 | 32 |
messageLevel(MESSAGE_NOTHING); |
| 33 | 33 |
} |
| 34 | 34 |
|
| 35 | 35 |
SoplexLp::~SoplexLp() {
|
| 36 | 36 |
delete soplex; |
| 37 | 37 |
} |
| 38 | 38 |
|
| 39 | 39 |
SoplexLp::SoplexLp(const SoplexLp& lp) {
|
| 40 | 40 |
rows = lp.rows; |
| 41 | 41 |
cols = lp.cols; |
| 42 | 42 |
|
| 43 | 43 |
soplex = new soplex::SoPlex; |
| 44 | 44 |
(*static_cast<soplex::SPxLP*>(soplex)) = *(lp.soplex); |
| 45 | 45 |
|
| 46 | 46 |
_col_names = lp._col_names; |
| 47 | 47 |
_col_names_ref = lp._col_names_ref; |
| 48 | 48 |
|
| 49 | 49 |
_row_names = lp._row_names; |
| 50 | 50 |
_row_names_ref = lp._row_names_ref; |
| 51 | 51 |
|
| 52 | 52 |
messageLevel(MESSAGE_NOTHING); |
| 53 | 53 |
} |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_SOPLEX_H |
| 20 | 20 |
#define LEMON_SOPLEX_H |
| 21 | 21 |
|
| 22 | 22 |
///\file |
| 23 | 23 |
///\brief Header of the LEMON-SOPLEX lp solver interface. |
| 24 | 24 |
|
| 25 | 25 |
#include <vector> |
| 26 | 26 |
#include <string> |
| 27 | 27 |
|
| 28 | 28 |
#include <lemon/lp_base.h> |
| 29 | 29 |
|
| 30 | 30 |
// Forward declaration |
| 31 | 31 |
namespace soplex {
|
| 32 | 32 |
class SoPlex; |
| 33 | 33 |
} |
| 34 | 34 |
|
| 35 | 35 |
namespace lemon {
|
| 36 | 36 |
|
| 37 | 37 |
/// \ingroup lp_group |
| 38 | 38 |
/// |
| 39 | 39 |
/// \brief Interface for the SOPLEX solver |
| 40 | 40 |
/// |
| 41 | 41 |
/// This class implements an interface for the SoPlex LP solver. |
| 42 | 42 |
/// The SoPlex library is an object oriented lp solver library |
| 43 | 43 |
/// developed at the Konrad-Zuse-Zentrum f�r Informationstechnik |
| 44 | 44 |
/// Berlin (ZIB). You can find detailed information about it at the |
| 45 | 45 |
/// <tt>http://soplex.zib.de</tt> address. |
| 46 | 46 |
class SoplexLp : public LpSolver {
|
| 47 | 47 |
private: |
| 48 | 48 |
|
| 49 | 49 |
soplex::SoPlex* soplex; |
| 50 | 50 |
|
| 51 | 51 |
std::vector<std::string> _col_names; |
| 52 | 52 |
std::map<std::string, int> _col_names_ref; |
| 53 | 53 |
| 1 |
/* -*- C++ -*- |
|
| 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
| 2 | 2 |
* |
| 3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
| 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_STATIC_GRAPH_H |
| 20 | 20 |
#define LEMON_STATIC_GRAPH_H |
| 21 | 21 |
|
| 22 | 22 |
///\ingroup graphs |
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief StaticDigraph class. |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/core.h> |
| 27 | 27 |
#include <lemon/bits/graph_extender.h> |
| 28 | 28 |
|
| 29 | 29 |
namespace lemon {
|
| 30 | 30 |
|
| 31 | 31 |
class StaticDigraphBase {
|
| 32 | 32 |
public: |
| 33 | 33 |
|
| 34 | 34 |
StaticDigraphBase() |
| 35 | 35 |
: built(false), node_num(0), arc_num(0), |
| 36 | 36 |
node_first_out(NULL), node_first_in(NULL), |
| 37 | 37 |
arc_source(NULL), arc_target(NULL), |
| 38 | 38 |
arc_next_in(NULL), arc_next_out(NULL) {}
|
| 39 | 39 |
|
| 40 | 40 |
~StaticDigraphBase() {
|
| 41 | 41 |
if (built) {
|
| 42 | 42 |
delete[] node_first_out; |
| 43 | 43 |
delete[] node_first_in; |
| 44 | 44 |
delete[] arc_source; |
| 45 | 45 |
delete[] arc_target; |
| 46 | 46 |
delete[] arc_next_out; |
| 47 | 47 |
delete[] arc_next_in; |
| 48 | 48 |
} |
| 49 | 49 |
} |
| 50 | 50 |
|
| 51 | 51 |
class Node {
|
| 52 | 52 |
friend class StaticDigraphBase; |
| 53 | 53 |
protected: |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_SUURBALLE_H |
| 20 | 20 |
#define LEMON_SUURBALLE_H |
| 21 | 21 |
|
| 22 | 22 |
///\ingroup shortest_path |
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief An algorithm for finding arc-disjoint paths between two |
| 25 | 25 |
/// nodes having minimum total length. |
| 26 | 26 |
|
| 27 | 27 |
#include <vector> |
| 28 | 28 |
#include <limits> |
| 29 | 29 |
#include <lemon/bin_heap.h> |
| 30 | 30 |
#include <lemon/path.h> |
| 31 | 31 |
#include <lemon/list_graph.h> |
| 32 | 32 |
#include <lemon/dijkstra.h> |
| 33 | 33 |
#include <lemon/maps.h> |
| 34 | 34 |
|
| 35 | 35 |
namespace lemon {
|
| 36 | 36 |
|
| 37 | 37 |
/// \brief Default traits class of Suurballe algorithm. |
| 38 | 38 |
/// |
| 39 | 39 |
/// Default traits class of Suurballe algorithm. |
| 40 | 40 |
/// \tparam GR The digraph type the algorithm runs on. |
| 41 | 41 |
/// \tparam LEN The type of the length map. |
| 42 | 42 |
/// The default value is <tt>GR::ArcMap<int></tt>. |
| 43 | 43 |
#ifdef DOXYGEN |
| 44 | 44 |
template <typename GR, typename LEN> |
| 45 | 45 |
#else |
| 46 | 46 |
template < typename GR, |
| 47 | 47 |
typename LEN = typename GR::template ArcMap<int> > |
| 48 | 48 |
#endif |
| 49 | 49 |
struct SuurballeDefaultTraits |
| 50 | 50 |
{
|
| 51 | 51 |
/// The type of the digraph. |
| 52 | 52 |
typedef GR Digraph; |
| 53 | 53 |
/// The type of the length map. |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_UNION_FIND_H |
| 20 | 20 |
#define LEMON_UNION_FIND_H |
| 21 | 21 |
|
| 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 | 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. |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <lemon/concepts/digraph.h> |
| 20 | 20 |
#include <lemon/smart_graph.h> |
| 21 | 21 |
#include <lemon/list_graph.h> |
| 22 | 22 |
#include <lemon/lgf_reader.h> |
| 23 | 23 |
#include <lemon/bellman_ford.h> |
| 24 | 24 |
#include <lemon/path.h> |
| 25 | 25 |
|
| 26 | 26 |
#include "graph_test.h" |
| 27 | 27 |
#include "test_tools.h" |
| 28 | 28 |
|
| 29 | 29 |
using namespace lemon; |
| 30 | 30 |
|
| 31 | 31 |
char test_lgf[] = |
| 32 | 32 |
"@nodes\n" |
| 33 | 33 |
"label\n" |
| 34 | 34 |
"0\n" |
| 35 | 35 |
"1\n" |
| 36 | 36 |
"2\n" |
| 37 | 37 |
"3\n" |
| 38 | 38 |
"4\n" |
| 39 | 39 |
"@arcs\n" |
| 40 | 40 |
" length\n" |
| 41 | 41 |
"0 1 3\n" |
| 42 | 42 |
"1 2 -3\n" |
| 43 | 43 |
"1 2 -5\n" |
| 44 | 44 |
"1 3 -2\n" |
| 45 | 45 |
"0 2 -1\n" |
| 46 | 46 |
"1 2 -4\n" |
| 47 | 47 |
"0 3 2\n" |
| 48 | 48 |
"4 2 -5\n" |
| 49 | 49 |
"2 3 1\n" |
| 50 | 50 |
"@attributes\n" |
| 51 | 51 |
"source 0\n" |
| 52 | 52 |
"target 3\n"; |
| 53 | 53 |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <lemon/concepts/digraph.h> |
| 20 | 20 |
#include <lemon/smart_graph.h> |
| 21 | 21 |
#include <lemon/list_graph.h> |
| 22 | 22 |
#include <lemon/lgf_reader.h> |
| 23 | 23 |
#include <lemon/bfs.h> |
| 24 | 24 |
#include <lemon/path.h> |
| 25 | 25 |
|
| 26 | 26 |
#include "graph_test.h" |
| 27 | 27 |
#include "test_tools.h" |
| 28 | 28 |
|
| 29 | 29 |
using namespace lemon; |
| 30 | 30 |
|
| 31 | 31 |
char test_lgf[] = |
| 32 | 32 |
"@nodes\n" |
| 33 | 33 |
"label\n" |
| 34 | 34 |
"0\n" |
| 35 | 35 |
"1\n" |
| 36 | 36 |
"2\n" |
| 37 | 37 |
"3\n" |
| 38 | 38 |
"4\n" |
| 39 | 39 |
"5\n" |
| 40 | 40 |
"@arcs\n" |
| 41 | 41 |
" label\n" |
| 42 | 42 |
"0 1 0\n" |
| 43 | 43 |
"1 2 1\n" |
| 44 | 44 |
"2 3 2\n" |
| 45 | 45 |
"3 4 3\n" |
| 46 | 46 |
"0 3 4\n" |
| 47 | 47 |
"0 3 5\n" |
| 48 | 48 |
"5 2 6\n" |
| 49 | 49 |
"@attributes\n" |
| 50 | 50 |
"source 0\n" |
| 51 | 51 |
"target 4\n"; |
| 52 | 52 |
|
| 53 | 53 |
void checkBfsCompile() |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <iostream> |
| 20 | 20 |
|
| 21 | 21 |
#include "test_tools.h" |
| 22 | 22 |
#include <lemon/list_graph.h> |
| 23 | 23 |
#include <lemon/circulation.h> |
| 24 | 24 |
#include <lemon/lgf_reader.h> |
| 25 | 25 |
#include <lemon/concepts/digraph.h> |
| 26 | 26 |
#include <lemon/concepts/maps.h> |
| 27 | 27 |
|
| 28 | 28 |
using namespace lemon; |
| 29 | 29 |
|
| 30 | 30 |
char test_lgf[] = |
| 31 | 31 |
"@nodes\n" |
| 32 | 32 |
"label\n" |
| 33 | 33 |
"0\n" |
| 34 | 34 |
"1\n" |
| 35 | 35 |
"2\n" |
| 36 | 36 |
"3\n" |
| 37 | 37 |
"4\n" |
| 38 | 38 |
"5\n" |
| 39 | 39 |
"@arcs\n" |
| 40 | 40 |
" lcap ucap\n" |
| 41 | 41 |
"0 1 2 10\n" |
| 42 | 42 |
"0 2 2 6\n" |
| 43 | 43 |
"1 3 4 7\n" |
| 44 | 44 |
"1 4 0 5\n" |
| 45 | 45 |
"2 4 1 3\n" |
| 46 | 46 |
"3 5 3 8\n" |
| 47 | 47 |
"4 5 3 7\n" |
| 48 | 48 |
"@attributes\n" |
| 49 | 49 |
"source 0\n" |
| 50 | 50 |
"sink 5\n"; |
| 51 | 51 |
|
| 52 | 52 |
void checkCirculationCompile() |
| 53 | 53 |
{
|
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <lemon/connectivity.h> |
| 20 | 20 |
#include <lemon/list_graph.h> |
| 21 | 21 |
#include <lemon/adaptors.h> |
| 22 | 22 |
|
| 23 | 23 |
#include "test_tools.h" |
| 24 | 24 |
|
| 25 | 25 |
using namespace lemon; |
| 26 | 26 |
|
| 27 | 27 |
|
| 28 | 28 |
int main() |
| 29 | 29 |
{
|
| 30 | 30 |
typedef ListDigraph Digraph; |
| 31 | 31 |
typedef Undirector<Digraph> Graph; |
| 32 | 32 |
|
| 33 | 33 |
{
|
| 34 | 34 |
Digraph d; |
| 35 | 35 |
Digraph::NodeMap<int> order(d); |
| 36 | 36 |
Graph g(d); |
| 37 | 37 |
|
| 38 | 38 |
check(stronglyConnected(d), "The empty digraph is strongly connected"); |
| 39 | 39 |
check(countStronglyConnectedComponents(d) == 0, |
| 40 | 40 |
"The empty digraph has 0 strongly connected component"); |
| 41 | 41 |
check(connected(g), "The empty graph is connected"); |
| 42 | 42 |
check(countConnectedComponents(g) == 0, |
| 43 | 43 |
"The empty graph has 0 connected component"); |
| 44 | 44 |
|
| 45 | 45 |
check(biNodeConnected(g), "The empty graph is bi-node-connected"); |
| 46 | 46 |
check(countBiNodeConnectedComponents(g) == 0, |
| 47 | 47 |
"The empty graph has 0 bi-node-connected component"); |
| 48 | 48 |
check(biEdgeConnected(g), "The empty graph is bi-edge-connected"); |
| 49 | 49 |
check(countBiEdgeConnectedComponents(g) == 0, |
| 50 | 50 |
"The empty graph has 0 bi-edge-connected component"); |
| 51 | 51 |
|
| 52 | 52 |
check(dag(d), "The empty digraph is DAG."); |
| 53 | 53 |
check(checkedTopologicalSort(d, order), "The empty digraph is DAG."); |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <lemon/concepts/digraph.h> |
| 20 | 20 |
#include <lemon/smart_graph.h> |
| 21 | 21 |
#include <lemon/list_graph.h> |
| 22 | 22 |
#include <lemon/lgf_reader.h> |
| 23 | 23 |
#include <lemon/dfs.h> |
| 24 | 24 |
#include <lemon/path.h> |
| 25 | 25 |
|
| 26 | 26 |
#include "graph_test.h" |
| 27 | 27 |
#include "test_tools.h" |
| 28 | 28 |
|
| 29 | 29 |
using namespace lemon; |
| 30 | 30 |
|
| 31 | 31 |
char test_lgf[] = |
| 32 | 32 |
"@nodes\n" |
| 33 | 33 |
"label\n" |
| 34 | 34 |
"0\n" |
| 35 | 35 |
"1\n" |
| 36 | 36 |
"2\n" |
| 37 | 37 |
"3\n" |
| 38 | 38 |
"4\n" |
| 39 | 39 |
"5\n" |
| 40 | 40 |
"6\n" |
| 41 | 41 |
"@arcs\n" |
| 42 | 42 |
" label\n" |
| 43 | 43 |
"0 1 0\n" |
| 44 | 44 |
"1 2 1\n" |
| 45 | 45 |
"2 3 2\n" |
| 46 | 46 |
"1 4 3\n" |
| 47 | 47 |
"4 2 4\n" |
| 48 | 48 |
"4 5 5\n" |
| 49 | 49 |
"5 0 6\n" |
| 50 | 50 |
"6 3 7\n" |
| 51 | 51 |
"@attributes\n" |
| 52 | 52 |
"source 0\n" |
| 53 | 53 |
"target 5\n"; |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <lemon/concepts/digraph.h> |
| 20 | 20 |
#include <lemon/list_graph.h> |
| 21 | 21 |
#include <lemon/smart_graph.h> |
| 22 | 22 |
#include <lemon/static_graph.h> |
| 23 | 23 |
#include <lemon/full_graph.h> |
| 24 | 24 |
|
| 25 | 25 |
#include "test_tools.h" |
| 26 | 26 |
#include "graph_test.h" |
| 27 | 27 |
|
| 28 | 28 |
using namespace lemon; |
| 29 | 29 |
using namespace lemon::concepts; |
| 30 | 30 |
|
| 31 | 31 |
template <class Digraph> |
| 32 | 32 |
void checkDigraphBuild() {
|
| 33 | 33 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
| 34 | 34 |
Digraph G; |
| 35 | 35 |
|
| 36 | 36 |
checkGraphNodeList(G, 0); |
| 37 | 37 |
checkGraphArcList(G, 0); |
| 38 | 38 |
|
| 39 | 39 |
G.reserveNode(3); |
| 40 | 40 |
G.reserveArc(4); |
| 41 | 41 |
|
| 42 | 42 |
Node |
| 43 | 43 |
n1 = G.addNode(), |
| 44 | 44 |
n2 = G.addNode(), |
| 45 | 45 |
n3 = G.addNode(); |
| 46 | 46 |
checkGraphNodeList(G, 3); |
| 47 | 47 |
checkGraphArcList(G, 0); |
| 48 | 48 |
|
| 49 | 49 |
Arc a1 = G.addArc(n1, n2); |
| 50 | 50 |
check(G.source(a1) == n1 && G.target(a1) == n2, "Wrong arc"); |
| 51 | 51 |
checkGraphNodeList(G, 3); |
| 52 | 52 |
checkGraphArcList(G, 1); |
| 53 | 53 |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <lemon/concepts/digraph.h> |
| 20 | 20 |
#include <lemon/smart_graph.h> |
| 21 | 21 |
#include <lemon/list_graph.h> |
| 22 | 22 |
#include <lemon/lgf_reader.h> |
| 23 | 23 |
#include <lemon/dijkstra.h> |
| 24 | 24 |
#include <lemon/path.h> |
| 25 | 25 |
#include <lemon/bin_heap.h> |
| 26 | 26 |
|
| 27 | 27 |
#include "graph_test.h" |
| 28 | 28 |
#include "test_tools.h" |
| 29 | 29 |
|
| 30 | 30 |
using namespace lemon; |
| 31 | 31 |
|
| 32 | 32 |
char test_lgf[] = |
| 33 | 33 |
"@nodes\n" |
| 34 | 34 |
"label\n" |
| 35 | 35 |
"0\n" |
| 36 | 36 |
"1\n" |
| 37 | 37 |
"2\n" |
| 38 | 38 |
"3\n" |
| 39 | 39 |
"4\n" |
| 40 | 40 |
"@arcs\n" |
| 41 | 41 |
" label length\n" |
| 42 | 42 |
"0 1 0 1\n" |
| 43 | 43 |
"1 2 1 1\n" |
| 44 | 44 |
"2 3 2 1\n" |
| 45 | 45 |
"0 3 4 5\n" |
| 46 | 46 |
"0 3 5 10\n" |
| 47 | 47 |
"0 3 6 7\n" |
| 48 | 48 |
"4 2 7 1\n" |
| 49 | 49 |
"@attributes\n" |
| 50 | 50 |
"source 0\n" |
| 51 | 51 |
"target 3\n"; |
| 52 | 52 |
|
| 53 | 53 |
void checkDijkstraCompile() |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <iostream> |
| 20 | 20 |
#include <vector> |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/concepts/digraph.h> |
| 23 | 23 |
#include <lemon/concepts/graph.h> |
| 24 | 24 |
#include <lemon/concept_check.h> |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/list_graph.h> |
| 27 | 27 |
|
| 28 | 28 |
#include <lemon/edge_set.h> |
| 29 | 29 |
|
| 30 | 30 |
#include "graph_test.h" |
| 31 | 31 |
#include "test_tools.h" |
| 32 | 32 |
|
| 33 | 33 |
using namespace lemon; |
| 34 | 34 |
|
| 35 | 35 |
void checkSmartArcSet() {
|
| 36 | 36 |
checkConcept<concepts::Digraph, SmartArcSet<ListDigraph> >(); |
| 37 | 37 |
|
| 38 | 38 |
typedef ListDigraph Digraph; |
| 39 | 39 |
typedef SmartArcSet<Digraph> ArcSet; |
| 40 | 40 |
|
| 41 | 41 |
Digraph digraph; |
| 42 | 42 |
Digraph::Node |
| 43 | 43 |
n1 = digraph.addNode(), |
| 44 | 44 |
n2 = digraph.addNode(); |
| 45 | 45 |
|
| 46 | 46 |
Digraph::Arc ga1 = digraph.addArc(n1, n2); |
| 47 | 47 |
|
| 48 | 48 |
ArcSet arc_set(digraph); |
| 49 | 49 |
|
| 50 | 50 |
Digraph::Arc ga2 = digraph.addArc(n2, n1); |
| 51 | 51 |
|
| 52 | 52 |
checkGraphNodeList(arc_set, 2); |
| 53 | 53 |
checkGraphArcList(arc_set, 0); |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <lemon/euler.h> |
| 20 | 20 |
#include <lemon/list_graph.h> |
| 21 | 21 |
#include <lemon/adaptors.h> |
| 22 | 22 |
#include "test_tools.h" |
| 23 | 23 |
|
| 24 | 24 |
using namespace lemon; |
| 25 | 25 |
|
| 26 | 26 |
template <typename Digraph> |
| 27 | 27 |
void checkDiEulerIt(const Digraph& g, |
| 28 | 28 |
const typename Digraph::Node& start = INVALID) |
| 29 | 29 |
{
|
| 30 | 30 |
typename Digraph::template ArcMap<int> visitationNumber(g, 0); |
| 31 | 31 |
|
| 32 | 32 |
DiEulerIt<Digraph> e(g, start); |
| 33 | 33 |
if (e == INVALID) return; |
| 34 | 34 |
typename Digraph::Node firstNode = g.source(e); |
| 35 | 35 |
typename Digraph::Node lastNode = g.target(e); |
| 36 | 36 |
if (start != INVALID) {
|
| 37 | 37 |
check(firstNode == start, "checkDiEulerIt: Wrong first node"); |
| 38 | 38 |
} |
| 39 | 39 |
|
| 40 | 40 |
for (; e != INVALID; ++e) {
|
| 41 | 41 |
if (e != INVALID) lastNode = g.target(e); |
| 42 | 42 |
++visitationNumber[e]; |
| 43 | 43 |
} |
| 44 | 44 |
|
| 45 | 45 |
check(firstNode == lastNode, |
| 46 | 46 |
"checkDiEulerIt: First and last nodes are not the same"); |
| 47 | 47 |
|
| 48 | 48 |
for (typename Digraph::ArcIt a(g); a != INVALID; ++a) |
| 49 | 49 |
{
|
| 50 | 50 |
check(visitationNumber[a] == 1, |
| 51 | 51 |
"checkDiEulerIt: Not visited or multiple times visited arc found"); |
| 52 | 52 |
} |
| 53 | 53 |
} |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <iostream> |
| 20 | 20 |
#include <sstream> |
| 21 | 21 |
#include <vector> |
| 22 | 22 |
#include <queue> |
| 23 | 23 |
#include <cstdlib> |
| 24 | 24 |
|
| 25 | 25 |
#include <lemon/fractional_matching.h> |
| 26 | 26 |
#include <lemon/smart_graph.h> |
| 27 | 27 |
#include <lemon/concepts/graph.h> |
| 28 | 28 |
#include <lemon/concepts/maps.h> |
| 29 | 29 |
#include <lemon/lgf_reader.h> |
| 30 | 30 |
#include <lemon/math.h> |
| 31 | 31 |
|
| 32 | 32 |
#include "test_tools.h" |
| 33 | 33 |
|
| 34 | 34 |
using namespace std; |
| 35 | 35 |
using namespace lemon; |
| 36 | 36 |
|
| 37 | 37 |
GRAPH_TYPEDEFS(SmartGraph); |
| 38 | 38 |
|
| 39 | 39 |
|
| 40 | 40 |
const int lgfn = 4; |
| 41 | 41 |
const std::string lgf[lgfn] = {
|
| 42 | 42 |
"@nodes\n" |
| 43 | 43 |
"label\n" |
| 44 | 44 |
"0\n" |
| 45 | 45 |
"1\n" |
| 46 | 46 |
"2\n" |
| 47 | 47 |
"3\n" |
| 48 | 48 |
"4\n" |
| 49 | 49 |
"5\n" |
| 50 | 50 |
"6\n" |
| 51 | 51 |
"7\n" |
| 52 | 52 |
"@edges\n" |
| 53 | 53 |
" label weight\n" |
| 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
| 2 |
* |
|
| 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
| 4 |
* |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
|
| 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
|
| 8 |
* |
|
| 9 |
* Permission to use, modify and distribute this software is granted |
|
| 10 |
* provided that this copyright notice appears in all copies. For |
|
| 11 |
* precise terms see the accompanying LICENSE file. |
|
| 12 |
* |
|
| 13 |
* This software is provided "AS IS" with no warranty of any kind, |
|
| 14 |
* express or implied, and with no claim as to its suitability for any |
|
| 15 |
* purpose. |
|
| 16 |
* |
|
| 17 |
*/ |
|
| 18 |
|
|
| 1 | 19 |
#include <iostream> |
| 2 | 20 |
|
| 3 | 21 |
#include "test_tools.h" |
| 4 | 22 |
#include <lemon/smart_graph.h> |
| 5 | 23 |
#include <lemon/concepts/graph.h> |
| 6 | 24 |
#include <lemon/concepts/maps.h> |
| 7 | 25 |
#include <lemon/lgf_reader.h> |
| 8 | 26 |
#include <lemon/gomory_hu.h> |
| 9 | 27 |
#include <cstdlib> |
| 10 | 28 |
|
| 11 | 29 |
using namespace std; |
| 12 | 30 |
using namespace lemon; |
| 13 | 31 |
|
| 14 | 32 |
typedef SmartGraph Graph; |
| 15 | 33 |
|
| 16 | 34 |
char test_lgf[] = |
| 17 | 35 |
"@nodes\n" |
| 18 | 36 |
"label\n" |
| 19 | 37 |
"0\n" |
| 20 | 38 |
"1\n" |
| 21 | 39 |
"2\n" |
| 22 | 40 |
"3\n" |
| 23 | 41 |
"4\n" |
| 24 | 42 |
"@arcs\n" |
| 25 | 43 |
" label capacity\n" |
| 26 | 44 |
"0 1 0 1\n" |
| 27 | 45 |
"1 2 1 1\n" |
| 28 | 46 |
"2 3 2 1\n" |
| 29 | 47 |
"0 3 4 5\n" |
| 30 | 48 |
"0 3 5 10\n" |
| 31 | 49 |
"0 3 6 7\n" |
| 32 | 50 |
"4 2 7 1\n" |
| 33 | 51 |
"@attributes\n" |
| 34 | 52 |
"source 0\n" |
| 35 | 53 |
"target 3\n"; |
| 36 | 54 |
|
| 37 | 55 |
void checkGomoryHuCompile() |
| 38 | 56 |
{
|
| 39 | 57 |
typedef int Value; |
| 40 | 58 |
typedef concepts::Graph Graph; |
| 41 | 59 |
|
| 42 | 60 |
typedef Graph::Node Node; |
| 43 | 61 |
typedef Graph::Edge Edge; |
| 44 | 62 |
typedef concepts::ReadMap<Edge, Value> CapMap; |
| 45 | 63 |
typedef concepts::ReadWriteMap<Node, bool> CutMap; |
| 46 | 64 |
|
| 47 | 65 |
Graph g; |
| 48 | 66 |
Node n; |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <lemon/concepts/graph.h> |
| 20 | 20 |
#include <lemon/list_graph.h> |
| 21 | 21 |
#include <lemon/smart_graph.h> |
| 22 | 22 |
#include <lemon/full_graph.h> |
| 23 | 23 |
#include <lemon/grid_graph.h> |
| 24 | 24 |
#include <lemon/hypercube_graph.h> |
| 25 | 25 |
|
| 26 | 26 |
#include "test_tools.h" |
| 27 | 27 |
#include "graph_test.h" |
| 28 | 28 |
|
| 29 | 29 |
using namespace lemon; |
| 30 | 30 |
using namespace lemon::concepts; |
| 31 | 31 |
|
| 32 | 32 |
template <class Graph> |
| 33 | 33 |
void checkGraphBuild() {
|
| 34 | 34 |
TEMPLATE_GRAPH_TYPEDEFS(Graph); |
| 35 | 35 |
|
| 36 | 36 |
Graph G; |
| 37 | 37 |
checkGraphNodeList(G, 0); |
| 38 | 38 |
checkGraphEdgeList(G, 0); |
| 39 | 39 |
checkGraphArcList(G, 0); |
| 40 | 40 |
|
| 41 | 41 |
G.reserveNode(3); |
| 42 | 42 |
G.reserveEdge(3); |
| 43 | 43 |
|
| 44 | 44 |
Node |
| 45 | 45 |
n1 = G.addNode(), |
| 46 | 46 |
n2 = G.addNode(), |
| 47 | 47 |
n3 = G.addNode(); |
| 48 | 48 |
checkGraphNodeList(G, 3); |
| 49 | 49 |
checkGraphEdgeList(G, 0); |
| 50 | 50 |
checkGraphArcList(G, 0); |
| 51 | 51 |
|
| 52 | 52 |
Edge e1 = G.addEdge(n1, n2); |
| 53 | 53 |
check((G.u(e1) == n1 && G.v(e1) == n2) || (G.u(e1) == n2 && G.v(e1) == n1), |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <sstream> |
| 20 | 20 |
|
| 21 | 21 |
#include <lemon/smart_graph.h> |
| 22 | 22 |
#include <lemon/adaptors.h> |
| 23 | 23 |
#include <lemon/concepts/digraph.h> |
| 24 | 24 |
#include <lemon/concepts/maps.h> |
| 25 | 25 |
#include <lemon/lgf_reader.h> |
| 26 | 26 |
#include <lemon/hao_orlin.h> |
| 27 | 27 |
|
| 28 | 28 |
#include "test_tools.h" |
| 29 | 29 |
|
| 30 | 30 |
using namespace lemon; |
| 31 | 31 |
using namespace std; |
| 32 | 32 |
|
| 33 | 33 |
const std::string lgf = |
| 34 | 34 |
"@nodes\n" |
| 35 | 35 |
"label\n" |
| 36 | 36 |
"0\n" |
| 37 | 37 |
"1\n" |
| 38 | 38 |
"2\n" |
| 39 | 39 |
"3\n" |
| 40 | 40 |
"4\n" |
| 41 | 41 |
"5\n" |
| 42 | 42 |
"@edges\n" |
| 43 | 43 |
" cap1 cap2 cap3\n" |
| 44 | 44 |
"0 1 1 1 1 \n" |
| 45 | 45 |
"0 2 2 2 4 \n" |
| 46 | 46 |
"1 2 4 4 4 \n" |
| 47 | 47 |
"3 4 1 1 1 \n" |
| 48 | 48 |
"3 5 2 2 4 \n" |
| 49 | 49 |
"4 5 4 4 4 \n" |
| 50 | 50 |
"5 4 4 4 4 \n" |
| 51 | 51 |
"2 3 1 6 6 \n" |
| 52 | 52 |
"4 0 1 6 6 \n"; |
| 53 | 53 |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <deque> |
| 20 | 20 |
#include <set> |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/concept_check.h> |
| 23 | 23 |
#include <lemon/concepts/maps.h> |
| 24 | 24 |
#include <lemon/maps.h> |
| 25 | 25 |
#include <lemon/list_graph.h> |
| 26 | 26 |
#include <lemon/smart_graph.h> |
| 27 | 27 |
#include <lemon/adaptors.h> |
| 28 | 28 |
#include <lemon/dfs.h> |
| 29 | 29 |
#include <algorithm> |
| 30 | 30 |
|
| 31 | 31 |
#include "test_tools.h" |
| 32 | 32 |
|
| 33 | 33 |
using namespace lemon; |
| 34 | 34 |
using namespace lemon::concepts; |
| 35 | 35 |
|
| 36 | 36 |
struct A {};
|
| 37 | 37 |
inline bool operator<(A, A) { return true; }
|
| 38 | 38 |
struct B {};
|
| 39 | 39 |
|
| 40 | 40 |
class C {
|
| 41 | 41 |
int _x; |
| 42 | 42 |
public: |
| 43 | 43 |
C(int x) : _x(x) {}
|
| 44 | 44 |
int get() const { return _x; }
|
| 45 | 45 |
}; |
| 46 | 46 |
inline bool operator<(C c1, C c2) { return c1.get() < c2.get(); }
|
| 47 | 47 |
inline bool operator==(C c1, C c2) { return c1.get() == c2.get(); }
|
| 48 | 48 |
|
| 49 | 49 |
C createC(int x) { return C(x); }
|
| 50 | 50 |
|
| 51 | 51 |
template <typename T> |
| 52 | 52 |
class Less {
|
| 53 | 53 |
T _t; |
| ... | ... |
@@ -180,97 +180,98 @@ |
| 180 | 180 |
std::map<double, int> m; |
| 181 | 181 |
SparseMap<double, int> map5(m); |
| 182 | 182 |
SparseMap<double, int> map6(m,10); |
| 183 | 183 |
SparseMap<double, int> map7 = sparseMap(m); |
| 184 | 184 |
SparseMap<double, int> map8 = sparseMap(m,10); |
| 185 | 185 |
|
| 186 | 186 |
check(map5[1.0] == 0 && map5[3.14] == 0 && |
| 187 | 187 |
map6[1.0] == 10 && map6[3.14] == 10, |
| 188 | 188 |
"Something is wrong with SparseMap"); |
| 189 | 189 |
map5[1.0] = map6[3.14] = 100; |
| 190 | 190 |
check(map5[1.0] == 100 && map5[3.14] == 0 && |
| 191 | 191 |
map6[1.0] == 10 && map6[3.14] == 100, |
| 192 | 192 |
"Something is wrong with SparseMap"); |
| 193 | 193 |
} |
| 194 | 194 |
|
| 195 | 195 |
// ComposeMap |
| 196 | 196 |
{
|
| 197 | 197 |
typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap; |
| 198 | 198 |
checkConcept<ReadMap<B,double>, CompMap>(); |
| 199 | 199 |
CompMap map1 = CompMap(DoubleMap(),ReadMap<B,A>()); |
| 200 | 200 |
CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>()); |
| 201 | 201 |
|
| 202 | 202 |
SparseMap<double, bool> m1(false); m1[3.14] = true; |
| 203 | 203 |
RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14; |
| 204 | 204 |
check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1], |
| 205 | 205 |
"Something is wrong with ComposeMap") |
| 206 | 206 |
} |
| 207 | 207 |
|
| 208 | 208 |
// CombineMap |
| 209 | 209 |
{
|
| 210 | 210 |
typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap; |
| 211 | 211 |
checkConcept<ReadMap<A,double>, CombMap>(); |
| 212 | 212 |
CombMap map1 = CombMap(DoubleMap(), DoubleMap()); |
| 213 | 213 |
CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>()); |
| 214 | 214 |
|
| 215 | 215 |
check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3, |
| 216 | 216 |
"Something is wrong with CombineMap"); |
| 217 | 217 |
} |
| 218 | 218 |
|
| 219 | 219 |
// FunctorToMap, MapToFunctor |
| 220 | 220 |
{
|
| 221 | 221 |
checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >(); |
| 222 | 222 |
checkConcept<ReadMap<A,B>, FunctorToMap<F> >(); |
| 223 | 223 |
FunctorToMap<F> map1; |
| 224 | 224 |
FunctorToMap<F> map2 = FunctorToMap<F>(F()); |
| 225 | 225 |
B b = functorToMap(F())[A()]; |
| 226 | 226 |
|
| 227 | 227 |
checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >(); |
| 228 |
MapToFunctor<ReadMap<A,B> > map = |
|
| 228 |
MapToFunctor<ReadMap<A,B> > map = |
|
| 229 |
MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>()); |
|
| 229 | 230 |
|
| 230 | 231 |
check(functorToMap(&func)[A()] == 3, |
| 231 | 232 |
"Something is wrong with FunctorToMap"); |
| 232 | 233 |
check(mapToFunctor(constMap<A,int>(2))(A()) == 2, |
| 233 | 234 |
"Something is wrong with MapToFunctor"); |
| 234 | 235 |
check(mapToFunctor(functorToMap(&func))(A()) == 3 && |
| 235 | 236 |
mapToFunctor(functorToMap(&func))[A()] == 3, |
| 236 | 237 |
"Something is wrong with FunctorToMap or MapToFunctor"); |
| 237 | 238 |
check(functorToMap(mapToFunctor(constMap<A,int>(2)))[A()] == 2, |
| 238 | 239 |
"Something is wrong with FunctorToMap or MapToFunctor"); |
| 239 | 240 |
} |
| 240 | 241 |
|
| 241 | 242 |
// ConvertMap |
| 242 | 243 |
{
|
| 243 | 244 |
checkConcept<ReadMap<double,double>, |
| 244 | 245 |
ConvertMap<ReadMap<double, int>, double> >(); |
| 245 | 246 |
ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true)); |
| 246 | 247 |
ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false)); |
| 247 | 248 |
} |
| 248 | 249 |
|
| 249 | 250 |
// ForkMap |
| 250 | 251 |
{
|
| 251 | 252 |
checkConcept<DoubleWriteMap, ForkMap<DoubleWriteMap, DoubleWriteMap> >(); |
| 252 | 253 |
|
| 253 | 254 |
typedef RangeMap<double> RM; |
| 254 | 255 |
typedef SparseMap<int, double> SM; |
| 255 | 256 |
RM m1(10, -1); |
| 256 | 257 |
SM m2(-1); |
| 257 | 258 |
checkConcept<ReadWriteMap<int, double>, ForkMap<RM, SM> >(); |
| 258 | 259 |
checkConcept<ReadWriteMap<int, double>, ForkMap<SM, RM> >(); |
| 259 | 260 |
ForkMap<RM, SM> map1(m1,m2); |
| 260 | 261 |
ForkMap<SM, RM> map2 = forkMap(m2,m1); |
| 261 | 262 |
map2.set(5, 10); |
| 262 | 263 |
check(m1[1] == -1 && m1[5] == 10 && m2[1] == -1 && |
| 263 | 264 |
m2[5] == 10 && map2[1] == -1 && map2[5] == 10, |
| 264 | 265 |
"Something is wrong with ForkMap"); |
| 265 | 266 |
} |
| 266 | 267 |
|
| 267 | 268 |
// Arithmetic maps: |
| 268 | 269 |
// - AddMap, SubMap, MulMap, DivMap |
| 269 | 270 |
// - ShiftMap, ShiftWriteMap, ScaleMap, ScaleWriteMap |
| 270 | 271 |
// - NegMap, NegWriteMap, AbsMap |
| 271 | 272 |
{
|
| 272 | 273 |
checkConcept<DoubleMap, AddMap<DoubleMap,DoubleMap> >(); |
| 273 | 274 |
checkConcept<DoubleMap, SubMap<DoubleMap,DoubleMap> >(); |
| 274 | 275 |
checkConcept<DoubleMap, MulMap<DoubleMap,DoubleMap> >(); |
| 275 | 276 |
checkConcept<DoubleMap, DivMap<DoubleMap,DoubleMap> >(); |
| 276 | 277 |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <iostream> |
| 20 | 20 |
#include <sstream> |
| 21 | 21 |
#include <vector> |
| 22 | 22 |
#include <queue> |
| 23 | 23 |
#include <cstdlib> |
| 24 | 24 |
|
| 25 | 25 |
#include <lemon/matching.h> |
| 26 | 26 |
#include <lemon/smart_graph.h> |
| 27 | 27 |
#include <lemon/concepts/graph.h> |
| 28 | 28 |
#include <lemon/concepts/maps.h> |
| 29 | 29 |
#include <lemon/lgf_reader.h> |
| 30 | 30 |
#include <lemon/math.h> |
| 31 | 31 |
|
| 32 | 32 |
#include "test_tools.h" |
| 33 | 33 |
|
| 34 | 34 |
using namespace std; |
| 35 | 35 |
using namespace lemon; |
| 36 | 36 |
|
| 37 | 37 |
GRAPH_TYPEDEFS(SmartGraph); |
| 38 | 38 |
|
| 39 | 39 |
|
| 40 | 40 |
const int lgfn = 3; |
| 41 | 41 |
const std::string lgf[lgfn] = {
|
| 42 | 42 |
"@nodes\n" |
| 43 | 43 |
"label\n" |
| 44 | 44 |
"0\n" |
| 45 | 45 |
"1\n" |
| 46 | 46 |
"2\n" |
| 47 | 47 |
"3\n" |
| 48 | 48 |
"4\n" |
| 49 | 49 |
"5\n" |
| 50 | 50 |
"6\n" |
| 51 | 51 |
"7\n" |
| 52 | 52 |
"@edges\n" |
| 53 | 53 |
" label weight\n" |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <iostream> |
| 20 | 20 |
#include <set> |
| 21 | 21 |
#include <vector> |
| 22 | 22 |
#include <iterator> |
| 23 | 23 |
|
| 24 | 24 |
#include <lemon/smart_graph.h> |
| 25 | 25 |
#include <lemon/min_cost_arborescence.h> |
| 26 | 26 |
#include <lemon/lgf_reader.h> |
| 27 | 27 |
#include <lemon/concepts/digraph.h> |
| 28 | 28 |
|
| 29 | 29 |
#include "test_tools.h" |
| 30 | 30 |
|
| 31 | 31 |
using namespace lemon; |
| 32 | 32 |
using namespace std; |
| 33 | 33 |
|
| 34 | 34 |
const char test_lgf[] = |
| 35 | 35 |
"@nodes\n" |
| 36 | 36 |
"label\n" |
| 37 | 37 |
"0\n" |
| 38 | 38 |
"1\n" |
| 39 | 39 |
"2\n" |
| 40 | 40 |
"3\n" |
| 41 | 41 |
"4\n" |
| 42 | 42 |
"5\n" |
| 43 | 43 |
"6\n" |
| 44 | 44 |
"7\n" |
| 45 | 45 |
"8\n" |
| 46 | 46 |
"9\n" |
| 47 | 47 |
"@arcs\n" |
| 48 | 48 |
" label cost\n" |
| 49 | 49 |
"1 8 0 107\n" |
| 50 | 50 |
"0 3 1 70\n" |
| 51 | 51 |
"2 1 2 46\n" |
| 52 | 52 |
"4 1 3 28\n" |
| 53 | 53 |
"4 4 4 91\n" |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <iostream> |
| 20 | 20 |
#include <fstream> |
| 21 | 21 |
#include <limits> |
| 22 | 22 |
|
| 23 | 23 |
#include <lemon/list_graph.h> |
| 24 | 24 |
#include <lemon/lgf_reader.h> |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/network_simplex.h> |
| 27 | 27 |
#include <lemon/capacity_scaling.h> |
| 28 | 28 |
#include <lemon/cost_scaling.h> |
| 29 | 29 |
#include <lemon/cycle_canceling.h> |
| 30 | 30 |
|
| 31 | 31 |
#include <lemon/concepts/digraph.h> |
| 32 | 32 |
#include <lemon/concepts/heap.h> |
| 33 | 33 |
#include <lemon/concept_check.h> |
| 34 | 34 |
|
| 35 | 35 |
#include "test_tools.h" |
| 36 | 36 |
|
| 37 | 37 |
using namespace lemon; |
| 38 | 38 |
|
| 39 | 39 |
// Test networks |
| 40 | 40 |
char test_lgf[] = |
| 41 | 41 |
"@nodes\n" |
| 42 | 42 |
"label sup1 sup2 sup3 sup4 sup5 sup6\n" |
| 43 | 43 |
" 1 20 27 0 30 20 30\n" |
| 44 | 44 |
" 2 -4 0 0 0 -8 -3\n" |
| 45 | 45 |
" 3 0 0 0 0 0 0\n" |
| 46 | 46 |
" 4 0 0 0 0 0 0\n" |
| 47 | 47 |
" 5 9 0 0 0 6 11\n" |
| 48 | 48 |
" 6 -6 0 0 0 -5 -6\n" |
| 49 | 49 |
" 7 0 0 0 0 0 0\n" |
| 50 | 50 |
" 8 0 0 0 0 0 3\n" |
| 51 | 51 |
" 9 3 0 0 0 0 0\n" |
| 52 | 52 |
" 10 -2 0 0 0 -7 -2\n" |
| 53 | 53 |
" 11 0 0 0 0 -10 0\n" |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <iostream> |
| 20 | 20 |
#include <sstream> |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/smart_graph.h> |
| 23 | 23 |
#include <lemon/lgf_reader.h> |
| 24 | 24 |
#include <lemon/path.h> |
| 25 | 25 |
#include <lemon/concepts/digraph.h> |
| 26 | 26 |
#include <lemon/concept_check.h> |
| 27 | 27 |
|
| 28 | 28 |
#include <lemon/karp_mmc.h> |
| 29 | 29 |
#include <lemon/hartmann_orlin_mmc.h> |
| 30 | 30 |
#include <lemon/howard_mmc.h> |
| 31 | 31 |
|
| 32 | 32 |
#include "test_tools.h" |
| 33 | 33 |
|
| 34 | 34 |
using namespace lemon; |
| 35 | 35 |
|
| 36 | 36 |
char test_lgf[] = |
| 37 | 37 |
"@nodes\n" |
| 38 | 38 |
"label\n" |
| 39 | 39 |
"1\n" |
| 40 | 40 |
"2\n" |
| 41 | 41 |
"3\n" |
| 42 | 42 |
"4\n" |
| 43 | 43 |
"5\n" |
| 44 | 44 |
"6\n" |
| 45 | 45 |
"7\n" |
| 46 | 46 |
"@arcs\n" |
| 47 | 47 |
" len1 len2 len3 len4 c1 c2 c3 c4\n" |
| 48 | 48 |
"1 2 1 1 1 1 0 0 0 0\n" |
| 49 | 49 |
"2 4 5 5 5 5 1 0 0 0\n" |
| 50 | 50 |
"2 3 8 8 8 8 0 0 0 0\n" |
| 51 | 51 |
"3 2 -2 0 0 0 1 0 0 0\n" |
| 52 | 52 |
"3 4 4 4 4 4 0 0 0 0\n" |
| 53 | 53 |
"3 7 -4 -4 -4 -4 0 0 0 0\n" |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <iostream> |
| 20 | 20 |
|
| 21 | 21 |
#include "test_tools.h" |
| 22 | 22 |
#include <lemon/smart_graph.h> |
| 23 | 23 |
#include <lemon/preflow.h> |
| 24 | 24 |
#include <lemon/concepts/digraph.h> |
| 25 | 25 |
#include <lemon/concepts/maps.h> |
| 26 | 26 |
#include <lemon/lgf_reader.h> |
| 27 | 27 |
#include <lemon/elevator.h> |
| 28 | 28 |
|
| 29 | 29 |
using namespace lemon; |
| 30 | 30 |
|
| 31 | 31 |
char test_lgf[] = |
| 32 | 32 |
"@nodes\n" |
| 33 | 33 |
"label\n" |
| 34 | 34 |
"0\n" |
| 35 | 35 |
"1\n" |
| 36 | 36 |
"2\n" |
| 37 | 37 |
"3\n" |
| 38 | 38 |
"4\n" |
| 39 | 39 |
"5\n" |
| 40 | 40 |
"6\n" |
| 41 | 41 |
"7\n" |
| 42 | 42 |
"8\n" |
| 43 | 43 |
"9\n" |
| 44 | 44 |
"@arcs\n" |
| 45 | 45 |
" label capacity\n" |
| 46 | 46 |
"0 1 0 20\n" |
| 47 | 47 |
"0 2 1 0\n" |
| 48 | 48 |
"1 1 2 3\n" |
| 49 | 49 |
"1 2 3 8\n" |
| 50 | 50 |
"1 3 4 8\n" |
| 51 | 51 |
"2 5 5 5\n" |
| 52 | 52 |
"3 2 6 5\n" |
| 53 | 53 |
"3 5 7 5\n" |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#include <iostream> |
| 20 | 20 |
|
| 21 | 21 |
#include <lemon/list_graph.h> |
| 22 | 22 |
#include <lemon/lgf_reader.h> |
| 23 | 23 |
#include <lemon/path.h> |
| 24 | 24 |
#include <lemon/suurballe.h> |
| 25 | 25 |
#include <lemon/concepts/digraph.h> |
| 26 | 26 |
#include <lemon/concepts/heap.h> |
| 27 | 27 |
|
| 28 | 28 |
#include "test_tools.h" |
| 29 | 29 |
|
| 30 | 30 |
using namespace lemon; |
| 31 | 31 |
|
| 32 | 32 |
char test_lgf[] = |
| 33 | 33 |
"@nodes\n" |
| 34 | 34 |
"label\n" |
| 35 | 35 |
"1\n" |
| 36 | 36 |
"2\n" |
| 37 | 37 |
"3\n" |
| 38 | 38 |
"4\n" |
| 39 | 39 |
"5\n" |
| 40 | 40 |
"6\n" |
| 41 | 41 |
"7\n" |
| 42 | 42 |
"8\n" |
| 43 | 43 |
"9\n" |
| 44 | 44 |
"10\n" |
| 45 | 45 |
"11\n" |
| 46 | 46 |
"12\n" |
| 47 | 47 |
"@arcs\n" |
| 48 | 48 |
" length\n" |
| 49 | 49 |
" 1 2 70\n" |
| 50 | 50 |
" 1 3 150\n" |
| 51 | 51 |
" 1 4 80\n" |
| 52 | 52 |
" 2 8 80\n" |
| 53 | 53 |
" 3 5 140\n" |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 |
#ifndef LEMON_TEST_TEST_TOOLS_H |
| 20 | 20 |
#define LEMON_TEST_TEST_TOOLS_H |
| 21 | 21 |
|
| 22 | 22 |
///\ingroup misc |
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief Some utilities to write test programs. |
| 25 | 25 |
|
| 26 | 26 |
#include <iostream> |
| 27 | 27 |
#include <stdlib.h> |
| 28 | 28 |
|
| 29 | 29 |
///If \c rc is fail, writes an error message and exits. |
| 30 | 30 |
|
| 31 | 31 |
///If \c rc is fail, writes an error message and exits. |
| 32 | 32 |
///The error message contains the file name and the line number of the |
| 33 | 33 |
///source code in a standard from, which makes it possible to go there |
| 34 | 34 |
///using good source browsers like e.g. \c emacs. |
| 35 | 35 |
/// |
| 36 | 36 |
///For example |
| 37 | 37 |
///\code check(0==1,"This is obviously false.");\endcode will |
| 38 | 38 |
///print something like this (and then exits). |
| 39 | 39 |
///\verbatim file_name.cc:123: error: This is obviously false. \endverbatim |
| 40 | 40 |
#define check(rc, msg) \ |
| 41 | 41 |
{ \
|
| 42 | 42 |
if(!(rc)) { \
|
| 43 | 43 |
std::cerr << __FILE__ ":" << __LINE__ << ": error: " \ |
| 44 | 44 |
<< msg << std::endl; \ |
| 45 | 45 |
abort(); \ |
| 46 | 46 |
} else { } \
|
| 47 | 47 |
} \ |
| 48 | 48 |
|
| 49 | 49 |
|
| 50 | 50 |
#endif |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2010 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 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 tools |
| 20 | 20 |
///\file |
| 21 | 21 |
///\brief DIMACS problem solver. |
| 22 | 22 |
/// |
| 23 | 23 |
/// This program solves various problems given in DIMACS format. |
| 24 | 24 |
/// |
| 25 | 25 |
/// See |
| 26 | 26 |
/// \code |
| 27 | 27 |
/// dimacs-solver --help |
| 28 | 28 |
/// \endcode |
| 29 | 29 |
/// for more info on usage. |
| 30 | 30 |
|
| 31 | 31 |
#include <iostream> |
| 32 | 32 |
#include <fstream> |
| 33 | 33 |
#include <cstring> |
| 34 | 34 |
|
| 35 | 35 |
#include <lemon/smart_graph.h> |
| 36 | 36 |
#include <lemon/dimacs.h> |
| 37 | 37 |
#include <lemon/lgf_writer.h> |
| 38 | 38 |
#include <lemon/time_measure.h> |
| 39 | 39 |
|
| 40 | 40 |
#include <lemon/arg_parser.h> |
| 41 | 41 |
#include <lemon/error.h> |
| 42 | 42 |
|
| 43 | 43 |
#include <lemon/dijkstra.h> |
| 44 | 44 |
#include <lemon/preflow.h> |
| 45 | 45 |
#include <lemon/matching.h> |
| 46 | 46 |
#include <lemon/network_simplex.h> |
| 47 | 47 |
|
| 48 | 48 |
using namespace lemon; |
| 49 | 49 |
typedef SmartDigraph Digraph; |
| 50 | 50 |
DIGRAPH_TYPEDEFS(Digraph); |
| 51 | 51 |
typedef SmartGraph Graph; |
| 52 | 52 |
|
| 53 | 53 |
template<class Value> |
0 comments (0 inline)