0
13
0
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2011 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
namespace lemon {
|
| 20 | 20 |
/*! |
| 21 | 21 |
|
| 22 | 22 |
|
| 23 | 23 |
|
| 24 | 24 |
\page lgf-format LEMON Graph Format (LGF) |
| 25 | 25 |
|
| 26 | 26 |
The \e LGF is a <em>column oriented</em> |
| 27 | 27 |
file format for storing graphs and associated data like |
| 28 | 28 |
node and edge maps. |
| 29 | 29 |
|
| 30 | 30 |
Each line with \c '#' first non-whitespace |
| 31 | 31 |
character is considered as a comment line. |
| 32 | 32 |
|
| 33 | 33 |
Otherwise the file consists of sections starting with |
| 34 | 34 |
a header line. The header lines starts with an \c '@' character followed by the |
| 35 | 35 |
type of section. The standard section types are \c \@nodes, \c |
| 36 | 36 |
\@arcs and \c \@edges |
| 37 | 37 |
and \@attributes. Each header line may also have an optional |
| 38 | 38 |
\e name, which can be use to distinguish the sections of the same |
| 39 | 39 |
type. |
| 40 | 40 |
|
| 41 | 41 |
The standard sections are column oriented, each line consists of |
| 42 | 42 |
<em>token</em>s separated by whitespaces. A token can be \e plain or |
| 43 | 43 |
\e quoted. A plain token is just a sequence of non-whitespace characters, |
| 44 | 44 |
while a quoted token is a |
| 45 | 45 |
character sequence surrounded by double quotes, and it can also |
| 46 | 46 |
contain whitespaces and escape sequences. |
| 47 | 47 |
|
| 48 | 48 |
The \c \@nodes section describes a set of nodes and associated |
| 49 | 49 |
maps. The first is a header line, its columns are the names of the |
| 50 | 50 |
maps appearing in the following lines. |
| 51 | 51 |
One of the maps must be called \c |
| 52 | 52 |
"label", which plays special role in the file. |
| 53 | 53 |
The following |
| 54 | 54 |
non-empty lines until the next section describes nodes of the |
| 55 | 55 |
graph. Each line contains the values of the node maps |
| 56 | 56 |
associated to the current node. |
| 57 | 57 |
|
| 58 | 58 |
\code |
| 59 | 59 |
@nodes |
| 60 | 60 |
label coordinates size title |
| 61 | 61 |
1 (10,20) 10 "First node" |
| 62 | 62 |
2 (80,80) 8 "Second node" |
| 63 | 63 |
3 (40,10) 10 "Third node" |
| 64 | 64 |
\endcode |
| 65 | 65 |
|
| 66 | 66 |
The \c \@arcs section is very similar to the \c \@nodes section, it |
| 67 | 67 |
again starts with a header line describing the names of the maps, but |
| 68 | 68 |
the \c "label" map is not obligatory here. The following lines |
| 69 | 69 |
describe the arcs. The first two tokens of each line are the source |
| 70 | 70 |
and the target node of the arc, respectively, then come the map |
| 71 | 71 |
values. The source and target tokens must be node labels. |
| 72 | 72 |
|
| 73 | 73 |
\code |
| 74 | 74 |
@arcs |
| 75 | 75 |
capacity |
| 76 | 76 |
1 2 16 |
| 77 | 77 |
1 3 12 |
| 78 | 78 |
2 3 18 |
| 79 | 79 |
\endcode |
| 80 | 80 |
|
| 81 | 81 |
If there is no map in the \c \@arcs section at all, then it must be |
| 82 | 82 |
indicated by a sole '-' sign in the first line. |
| 83 | 83 |
|
| 84 | 84 |
\code |
| 85 | 85 |
@arcs |
| 86 | 86 |
- |
| 87 | 87 |
1 2 |
| 88 | 88 |
1 3 |
| 89 | 89 |
2 3 |
| 90 | 90 |
\endcode |
| 91 | 91 |
|
| 92 | 92 |
The \c \@edges is just a synonym of \c \@arcs. The \@arcs section can |
| 93 | 93 |
also store the edge set of an undirected graph. In such case there is |
| 94 | 94 |
a conventional method for store arc maps in the file, if two columns |
| 95 | 95 |
have the same caption with \c '+' and \c '-' prefix, then these columns |
| 96 | 96 |
can be regarded as the values of an arc map. |
| 97 | 97 |
|
| 98 | 98 |
The \c \@attributes section contains key-value pairs, each line |
| 99 | 99 |
consists of two tokens, an attribute name, and then an attribute |
| 100 | 100 |
value. The value of the attribute could be also a label value of a |
| 101 | 101 |
node or an edge, or even an edge label prefixed with \c '+' or \c '-', |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2011 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_BITS_GRAPH_ADAPTOR_EXTENDER_H |
| 20 | 20 |
#define LEMON_BITS_GRAPH_ADAPTOR_EXTENDER_H |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/core.h> |
| 23 | 23 |
#include <lemon/error.h> |
| 24 | 24 |
|
| 25 | 25 |
namespace lemon {
|
| 26 | 26 |
|
| 27 | 27 |
template <typename _Digraph> |
| 28 | 28 |
class DigraphAdaptorExtender : public _Digraph {
|
| 29 | 29 |
typedef _Digraph Parent; |
| 30 | 30 |
|
| 31 | 31 |
public: |
| 32 | 32 |
|
| 33 | 33 |
typedef _Digraph Digraph; |
| 34 | 34 |
typedef DigraphAdaptorExtender Adaptor; |
| 35 | 35 |
|
| 36 | 36 |
// Base extensions |
| 37 | 37 |
|
| 38 | 38 |
typedef typename Parent::Node Node; |
| 39 | 39 |
typedef typename Parent::Arc Arc; |
| 40 | 40 |
|
| 41 | 41 |
int maxId(Node) const {
|
| 42 | 42 |
return Parent::maxNodeId(); |
| 43 | 43 |
} |
| 44 | 44 |
|
| 45 | 45 |
int maxId(Arc) const {
|
| 46 | 46 |
return Parent::maxArcId(); |
| 47 | 47 |
} |
| 48 | 48 |
|
| 49 | 49 |
Node fromId(int id, Node) const {
|
| 50 | 50 |
return Parent::nodeFromId(id); |
| 51 | 51 |
} |
| 52 | 52 |
|
| 53 | 53 |
Arc fromId(int id, Arc) const {
|
| 54 | 54 |
return Parent::arcFromId(id); |
| 55 | 55 |
} |
| 56 | 56 |
|
| 57 | 57 |
Node oppositeNode(const Node &n, const Arc &e) const {
|
| 58 | 58 |
if (n == Parent::source(e)) |
| 59 | 59 |
return Parent::target(e); |
| 60 | 60 |
else if(n==Parent::target(e)) |
| 61 | 61 |
return Parent::source(e); |
| 62 | 62 |
else |
| 63 | 63 |
return INVALID; |
| 64 | 64 |
} |
| 65 | 65 |
|
| 66 | 66 |
class NodeIt : public Node {
|
| 67 | 67 |
const Adaptor* _adaptor; |
| 68 | 68 |
public: |
| 69 | 69 |
|
| 70 | 70 |
NodeIt() {}
|
| 71 | 71 |
|
| 72 | 72 |
NodeIt(Invalid i) : Node(i) { }
|
| 73 | 73 |
|
| 74 | 74 |
explicit NodeIt(const Adaptor& adaptor) : _adaptor(&adaptor) {
|
| 75 | 75 |
_adaptor->first(static_cast<Node&>(*this)); |
| 76 | 76 |
} |
| 77 | 77 |
|
| 78 | 78 |
NodeIt(const Adaptor& adaptor, const Node& node) |
| 79 | 79 |
: Node(node), _adaptor(&adaptor) {}
|
| 80 | 80 |
|
| 81 | 81 |
NodeIt& operator++() {
|
| 82 | 82 |
_adaptor->next(*this); |
| 83 | 83 |
return *this; |
| 84 | 84 |
} |
| 85 | 85 |
|
| 86 | 86 |
}; |
| 87 | 87 |
|
| 88 | 88 |
|
| 89 | 89 |
class ArcIt : public Arc {
|
| 90 | 90 |
const Adaptor* _adaptor; |
| 91 | 91 |
public: |
| 92 | 92 |
|
| 93 | 93 |
ArcIt() { }
|
| 94 | 94 |
|
| 95 | 95 |
ArcIt(Invalid i) : Arc(i) { }
|
| 96 | 96 |
|
| 97 | 97 |
explicit ArcIt(const Adaptor& adaptor) : _adaptor(&adaptor) {
|
| 98 | 98 |
_adaptor->first(static_cast<Arc&>(*this)); |
| 99 | 99 |
} |
| 100 | 100 |
|
| 101 | 101 |
ArcIt(const Adaptor& adaptor, const Arc& e) : |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2011 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_BITS_PATH_DUMP_H |
| 20 | 20 |
#define LEMON_BITS_PATH_DUMP_H |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/core.h> |
| 23 | 23 |
#include <lemon/concept_check.h> |
| 24 | 24 |
|
| 25 | 25 |
namespace lemon {
|
| 26 | 26 |
|
| 27 | 27 |
template <typename _Digraph, typename _PredMap> |
| 28 | 28 |
class PredMapPath {
|
| 29 | 29 |
public: |
| 30 | 30 |
typedef True RevPathTag; |
| 31 | 31 |
|
| 32 | 32 |
typedef _Digraph Digraph; |
| 33 | 33 |
typedef typename Digraph::Arc Arc; |
| 34 | 34 |
typedef _PredMap PredMap; |
| 35 | 35 |
|
| 36 | 36 |
PredMapPath(const Digraph& _digraph, const PredMap& _predMap, |
| 37 | 37 |
typename Digraph::Node _target) |
| 38 | 38 |
: digraph(_digraph), predMap(_predMap), target(_target) {}
|
| 39 | 39 |
|
| 40 | 40 |
int length() const {
|
| 41 | 41 |
int len = 0; |
| 42 | 42 |
typename Digraph::Node node = target; |
| 43 | 43 |
typename Digraph::Arc arc; |
| 44 | 44 |
while ((arc = predMap[node]) != INVALID) {
|
| 45 | 45 |
node = digraph.source(arc); |
| 46 | 46 |
++len; |
| 47 | 47 |
} |
| 48 | 48 |
return len; |
| 49 | 49 |
} |
| 50 | 50 |
|
| 51 | 51 |
bool empty() const {
|
| 52 | 52 |
return predMap[target] == INVALID; |
| 53 | 53 |
} |
| 54 | 54 |
|
| 55 | 55 |
class RevArcIt {
|
| 56 | 56 |
public: |
| 57 | 57 |
RevArcIt() {}
|
| 58 | 58 |
RevArcIt(Invalid) : path(0), current(INVALID) {}
|
| 59 | 59 |
RevArcIt(const PredMapPath& _path) |
| 60 | 60 |
: path(&_path), current(_path.target) {
|
| 61 | 61 |
if (path->predMap[current] == INVALID) current = INVALID; |
| 62 | 62 |
} |
| 63 | 63 |
|
| 64 | 64 |
operator const typename Digraph::Arc() const {
|
| 65 | 65 |
return path->predMap[current]; |
| 66 | 66 |
} |
| 67 | 67 |
|
| 68 | 68 |
RevArcIt& operator++() {
|
| 69 | 69 |
current = path->digraph.source(path->predMap[current]); |
| 70 | 70 |
if (path->predMap[current] == INVALID) current = INVALID; |
| 71 | 71 |
return *this; |
| 72 | 72 |
} |
| 73 | 73 |
|
| 74 | 74 |
bool operator==(const RevArcIt& e) const {
|
| 75 | 75 |
return current == e.current; |
| 76 | 76 |
} |
| 77 | 77 |
|
| 78 | 78 |
bool operator!=(const RevArcIt& e) const {
|
| 79 | 79 |
return current != e.current; |
| 80 | 80 |
} |
| 81 | 81 |
|
| 82 | 82 |
bool operator<(const RevArcIt& e) const {
|
| 83 | 83 |
return current < e.current; |
| 84 | 84 |
} |
| 85 | 85 |
|
| 86 | 86 |
private: |
| 87 | 87 |
const PredMapPath* path; |
| 88 | 88 |
typename Digraph::Node current; |
| 89 | 89 |
}; |
| 90 | 90 |
|
| 91 | 91 |
private: |
| 92 | 92 |
const Digraph& digraph; |
| 93 | 93 |
const PredMap& predMap; |
| 94 | 94 |
typename Digraph::Node target; |
| 95 | 95 |
}; |
| 96 | 96 |
|
| 97 | 97 |
|
| 98 | 98 |
template <typename _Digraph, typename _PredMatrixMap> |
| 99 | 99 |
class PredMatrixMapPath {
|
| 100 | 100 |
public: |
| 101 | 101 |
typedef True RevPathTag; |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2011 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 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 |
#ifndef WIN32 |
| 44 | 44 |
#include <sys/times.h> |
| 45 | 45 |
#endif |
| 46 | 46 |
#include <sys/time.h> |
| 47 | 47 |
#endif |
| 48 | 48 |
|
| 49 | 49 |
#include <cmath> |
| 50 | 50 |
#include <sstream> |
| 51 | 51 |
|
| 52 | 52 |
namespace lemon {
|
| 53 | 53 |
namespace bits {
|
| 54 | 54 |
void getWinProcTimes(double &rtime, |
| 55 | 55 |
double &utime, double &stime, |
| 56 | 56 |
double &cutime, double &cstime) |
| 57 | 57 |
{
|
| 58 | 58 |
#ifdef WIN32 |
| 59 | 59 |
static const double ch = 4294967296.0e-7; |
| 60 | 60 |
static const double cl = 1.0e-7; |
| 61 | 61 |
|
| 62 | 62 |
FILETIME system; |
| 63 | 63 |
GetSystemTimeAsFileTime(&system); |
| 64 | 64 |
rtime = ch * system.dwHighDateTime + cl * system.dwLowDateTime; |
| 65 | 65 |
|
| 66 | 66 |
FILETIME create, exit, kernel, user; |
| 67 | 67 |
if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
|
| 68 | 68 |
utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime; |
| 69 | 69 |
stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime; |
| 70 | 70 |
cutime = 0; |
| 71 | 71 |
cstime = 0; |
| 72 | 72 |
} else {
|
| 73 | 73 |
rtime = 0; |
| 74 | 74 |
utime = 0; |
| 75 | 75 |
stime = 0; |
| 76 | 76 |
cutime = 0; |
| 77 | 77 |
cstime = 0; |
| 78 | 78 |
} |
| 79 | 79 |
#else |
| 80 | 80 |
timeval tv; |
| 81 | 81 |
gettimeofday(&tv, 0); |
| 82 | 82 |
rtime=tv.tv_sec+double(tv.tv_usec)/1e6; |
| 83 | 83 |
|
| 84 | 84 |
tms ts; |
| 85 | 85 |
double tck=sysconf(_SC_CLK_TCK); |
| 86 | 86 |
times(&ts); |
| 87 | 87 |
utime=ts.tms_utime/tck; |
| 88 | 88 |
stime=ts.tms_stime/tck; |
| 89 | 89 |
cutime=ts.tms_cutime/tck; |
| 90 | 90 |
cstime=ts.tms_cstime/tck; |
| 91 | 91 |
#endif |
| 92 | 92 |
} |
| 93 | 93 |
|
| 94 | 94 |
std::string getWinFormattedDate() |
| 95 | 95 |
{
|
| 96 | 96 |
std::ostringstream os; |
| 97 | 97 |
#ifdef WIN32 |
| 98 | 98 |
SYSTEMTIME time; |
| 99 | 99 |
GetSystemTime(&time); |
| 100 | 100 |
char buf1[11], buf2[9], buf3[5]; |
| 101 | 101 |
if (GetDateFormat(MY_LOCALE, 0, &time, |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2011 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 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 |
| 54 | 54 |
{
|
| 55 | 55 |
/// The type of the digraph |
| 56 | 56 |
typedef GR Digraph; |
| 57 | 57 |
/// The type of the flow amounts, capacity bounds and supply values |
| 58 | 58 |
typedef V Value; |
| 59 | 59 |
/// The type of the arc costs |
| 60 | 60 |
typedef C Cost; |
| 61 | 61 |
|
| 62 | 62 |
/// \brief The large cost type used for internal computations |
| 63 | 63 |
/// |
| 64 | 64 |
/// The large cost type used for internal computations. |
| 65 | 65 |
/// It is \c long \c long if the \c Cost type is integer, |
| 66 | 66 |
/// otherwise it is \c double. |
| 67 | 67 |
/// \c Cost must be convertible to \c LargeCost. |
| 68 | 68 |
typedef double LargeCost; |
| 69 | 69 |
}; |
| 70 | 70 |
|
| 71 | 71 |
// Default traits class for integer cost types |
| 72 | 72 |
template <typename GR, typename V, typename C> |
| 73 | 73 |
struct CostScalingDefaultTraits<GR, V, C, true> |
| 74 | 74 |
{
|
| 75 | 75 |
typedef GR Digraph; |
| 76 | 76 |
typedef V Value; |
| 77 | 77 |
typedef C Cost; |
| 78 | 78 |
#ifdef LEMON_HAVE_LONG_LONG |
| 79 | 79 |
typedef long long LargeCost; |
| 80 | 80 |
#else |
| 81 | 81 |
typedef long LargeCost; |
| 82 | 82 |
#endif |
| 83 | 83 |
}; |
| 84 | 84 |
|
| 85 | 85 |
|
| 86 | 86 |
/// \addtogroup min_cost_flow_algs |
| 87 | 87 |
/// @{
|
| 88 | 88 |
|
| 89 | 89 |
/// \brief Implementation of the Cost Scaling algorithm for |
| 90 | 90 |
/// finding a \ref min_cost_flow "minimum cost flow". |
| 91 | 91 |
/// |
| 92 | 92 |
/// \ref CostScaling implements a cost scaling algorithm that performs |
| 93 | 93 |
/// push/augment and relabel operations for finding a \ref min_cost_flow |
| 94 | 94 |
/// "minimum cost flow" \ref amo93networkflows, \ref goldberg90approximation, |
| 95 | 95 |
/// \ref goldberg97efficient, \ref bunnagel98efficient. |
| 96 | 96 |
/// It is a highly efficient primal-dual solution method, which |
| 97 | 97 |
/// can be viewed as the generalization of the \ref Preflow |
| 98 | 98 |
/// "preflow push-relabel" algorithm for the maximum flow problem. |
| 99 | 99 |
/// |
| 100 | 100 |
/// Most of the parameters of the problem (except for the digraph) |
| 101 | 101 |
/// can be given using separate functions, and the algorithm 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-2011 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 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) |
| 54 | 54 |
|
| 55 | 55 |
/// This map can be used if you have to provide a map only for |
| 56 | 56 |
/// its type definitions, or if you have to provide a writable map, |
| 57 | 57 |
/// but data written to it is not required (i.e. it will be sent to |
| 58 | 58 |
/// <tt>/dev/null</tt>). |
| 59 | 59 |
/// It conforms to the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
| 60 | 60 |
/// |
| 61 | 61 |
/// \sa ConstMap |
| 62 | 62 |
template<typename K, typename V> |
| 63 | 63 |
class NullMap : public MapBase<K, V> {
|
| 64 | 64 |
public: |
| 65 | 65 |
///\e |
| 66 | 66 |
typedef K Key; |
| 67 | 67 |
///\e |
| 68 | 68 |
typedef V Value; |
| 69 | 69 |
|
| 70 | 70 |
/// Gives back a default constructed element. |
| 71 | 71 |
Value operator[](const Key&) const { return Value(); }
|
| 72 | 72 |
/// Absorbs the value. |
| 73 | 73 |
void set(const Key&, const Value&) {}
|
| 74 | 74 |
}; |
| 75 | 75 |
|
| 76 | 76 |
/// Returns a \c NullMap class |
| 77 | 77 |
|
| 78 | 78 |
/// This function just returns a \c NullMap class. |
| 79 | 79 |
/// \relates NullMap |
| 80 | 80 |
template <typename K, typename V> |
| 81 | 81 |
NullMap<K, V> nullMap() {
|
| 82 | 82 |
return NullMap<K, V>(); |
| 83 | 83 |
} |
| 84 | 84 |
|
| 85 | 85 |
|
| 86 | 86 |
/// Constant map. |
| 87 | 87 |
|
| 88 | 88 |
/// This \ref concepts::ReadMap "readable map" assigns a specified |
| 89 | 89 |
/// value to each key. |
| 90 | 90 |
/// |
| 91 | 91 |
/// In other aspects it is equivalent to \c NullMap. |
| 92 | 92 |
/// So it conforms to the \ref concepts::ReadWriteMap "ReadWriteMap" |
| 93 | 93 |
/// concept, but it absorbs the data written to it. |
| 94 | 94 |
/// |
| 95 | 95 |
/// The simplest way of using this map is through the constMap() |
| 96 | 96 |
/// function. |
| 97 | 97 |
/// |
| 98 | 98 |
/// \sa NullMap |
| 99 | 99 |
/// \sa IdentityMap |
| 100 | 100 |
template<typename K, typename V> |
| 101 | 101 |
class ConstMap : public MapBase<K, V> {
|
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2011 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 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. |
| 54 | 54 |
/// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
| 55 | 55 |
#ifdef DOXYGEN |
| 56 | 56 |
typedef GR::ArcMap<Value> FlowMap; |
| 57 | 57 |
#else |
| 58 | 58 |
typedef typename Digraph::template ArcMap<Value> FlowMap; |
| 59 | 59 |
#endif |
| 60 | 60 |
|
| 61 | 61 |
/// \brief Instantiates a FlowMap. |
| 62 | 62 |
/// |
| 63 | 63 |
/// This function instantiates a \ref FlowMap. |
| 64 | 64 |
/// \param digraph The digraph for which we would like to define |
| 65 | 65 |
/// the flow map. |
| 66 | 66 |
static FlowMap* createFlowMap(const Digraph& digraph) {
|
| 67 | 67 |
return new FlowMap(digraph); |
| 68 | 68 |
} |
| 69 | 69 |
|
| 70 | 70 |
/// \brief The elevator type used by Preflow algorithm. |
| 71 | 71 |
/// |
| 72 | 72 |
/// The elevator type used by Preflow algorithm. |
| 73 | 73 |
/// |
| 74 | 74 |
/// \sa Elevator, LinkedElevator |
| 75 | 75 |
#ifdef DOXYGEN |
| 76 | 76 |
typedef lemon::Elevator<GR, GR::Node> Elevator; |
| 77 | 77 |
#else |
| 78 | 78 |
typedef lemon::Elevator<Digraph, typename Digraph::Node> Elevator; |
| 79 | 79 |
#endif |
| 80 | 80 |
|
| 81 | 81 |
/// \brief Instantiates an Elevator. |
| 82 | 82 |
/// |
| 83 | 83 |
/// This function instantiates an \ref Elevator. |
| 84 | 84 |
/// \param digraph The digraph for which we would like to define |
| 85 | 85 |
/// the elevator. |
| 86 | 86 |
/// \param max_level The maximum level of the elevator. |
| 87 | 87 |
static Elevator* createElevator(const Digraph& digraph, int max_level) {
|
| 88 | 88 |
return new Elevator(digraph, max_level); |
| 89 | 89 |
} |
| 90 | 90 |
|
| 91 | 91 |
/// \brief The tolerance used by the algorithm |
| 92 | 92 |
/// |
| 93 | 93 |
/// The tolerance used by the algorithm to handle inexact computation. |
| 94 | 94 |
typedef lemon::Tolerance<Value> Tolerance; |
| 95 | 95 |
|
| 96 | 96 |
}; |
| 97 | 97 |
|
| 98 | 98 |
|
| 99 | 99 |
/// \ingroup max_flow |
| 100 | 100 |
/// |
| 101 | 101 |
/// \brief %Preflow algorithm class. |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2011 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 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" |
| 54 | 54 |
"source1 6\n" |
| 55 | 55 |
"target1 3\n"; |
| 56 | 56 |
|
| 57 | 57 |
|
| 58 | 58 |
void checkDfsCompile() |
| 59 | 59 |
{
|
| 60 | 60 |
typedef concepts::Digraph Digraph; |
| 61 | 61 |
typedef Dfs<Digraph> DType; |
| 62 | 62 |
typedef Digraph::Node Node; |
| 63 | 63 |
typedef Digraph::Arc Arc; |
| 64 | 64 |
|
| 65 | 65 |
Digraph G; |
| 66 | 66 |
Node s, t; |
| 67 | 67 |
Arc e; |
| 68 | 68 |
int l, i; |
| 69 | 69 |
bool b; |
| 70 | 70 |
DType::DistMap d(G); |
| 71 | 71 |
DType::PredMap p(G); |
| 72 | 72 |
Path<Digraph> pp; |
| 73 | 73 |
concepts::ReadMap<Arc,bool> am; |
| 74 | 74 |
|
| 75 | 75 |
{
|
| 76 | 76 |
DType dfs_test(G); |
| 77 | 77 |
const DType& const_dfs_test = dfs_test; |
| 78 | 78 |
|
| 79 | 79 |
dfs_test.run(s); |
| 80 | 80 |
dfs_test.run(s,t); |
| 81 | 81 |
dfs_test.run(); |
| 82 | 82 |
|
| 83 | 83 |
dfs_test.init(); |
| 84 | 84 |
dfs_test.addSource(s); |
| 85 | 85 |
e = dfs_test.processNextArc(); |
| 86 | 86 |
e = const_dfs_test.nextArc(); |
| 87 | 87 |
b = const_dfs_test.emptyQueue(); |
| 88 | 88 |
i = const_dfs_test.queueSize(); |
| 89 | 89 |
|
| 90 | 90 |
dfs_test.start(); |
| 91 | 91 |
dfs_test.start(t); |
| 92 | 92 |
dfs_test.start(am); |
| 93 | 93 |
|
| 94 | 94 |
l = const_dfs_test.dist(t); |
| 95 | 95 |
e = const_dfs_test.predArc(t); |
| 96 | 96 |
s = const_dfs_test.predNode(t); |
| 97 | 97 |
b = const_dfs_test.reached(t); |
| 98 | 98 |
d = const_dfs_test.distMap(); |
| 99 | 99 |
p = const_dfs_test.predMap(); |
| 100 | 100 |
pp = const_dfs_test.path(t); |
| 101 | 101 |
} |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2011 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#include <lemon/smart_graph.h> |
| 20 | 20 |
#include <lemon/list_graph.h> |
| 21 | 21 |
#include <lemon/lgf_reader.h> |
| 22 | 22 |
#include <lemon/error.h> |
| 23 | 23 |
|
| 24 | 24 |
#include "test_tools.h" |
| 25 | 25 |
|
| 26 | 26 |
using namespace std; |
| 27 | 27 |
using namespace lemon; |
| 28 | 28 |
|
| 29 | 29 |
void digraph_copy_test() {
|
| 30 | 30 |
const int nn = 10; |
| 31 | 31 |
|
| 32 | 32 |
// Build a digraph |
| 33 | 33 |
SmartDigraph from; |
| 34 | 34 |
SmartDigraph::NodeMap<int> fnm(from); |
| 35 | 35 |
SmartDigraph::ArcMap<int> fam(from); |
| 36 | 36 |
SmartDigraph::Node fn = INVALID; |
| 37 | 37 |
SmartDigraph::Arc fa = INVALID; |
| 38 | 38 |
|
| 39 | 39 |
std::vector<SmartDigraph::Node> fnv; |
| 40 | 40 |
for (int i = 0; i < nn; ++i) {
|
| 41 | 41 |
SmartDigraph::Node node = from.addNode(); |
| 42 | 42 |
fnv.push_back(node); |
| 43 | 43 |
fnm[node] = i * i; |
| 44 | 44 |
if (i == 0) fn = node; |
| 45 | 45 |
} |
| 46 | 46 |
|
| 47 | 47 |
for (int i = 0; i < nn; ++i) {
|
| 48 | 48 |
for (int j = 0; j < nn; ++j) {
|
| 49 | 49 |
SmartDigraph::Arc arc = from.addArc(fnv[i], fnv[j]); |
| 50 | 50 |
fam[arc] = i + j * j; |
| 51 | 51 |
if (i == 0 && j == 0) fa = arc; |
| 52 | 52 |
} |
| 53 | 53 |
} |
| 54 | 54 |
|
| 55 | 55 |
// Test digraph copy |
| 56 | 56 |
ListDigraph to; |
| 57 | 57 |
ListDigraph::NodeMap<int> tnm(to); |
| 58 | 58 |
ListDigraph::ArcMap<int> tam(to); |
| 59 | 59 |
ListDigraph::Node tn; |
| 60 | 60 |
ListDigraph::Arc ta; |
| 61 | 61 |
|
| 62 | 62 |
SmartDigraph::NodeMap<ListDigraph::Node> nr(from); |
| 63 | 63 |
SmartDigraph::ArcMap<ListDigraph::Arc> er(from); |
| 64 | 64 |
|
| 65 | 65 |
ListDigraph::NodeMap<SmartDigraph::Node> ncr(to); |
| 66 | 66 |
ListDigraph::ArcMap<SmartDigraph::Arc> ecr(to); |
| 67 | 67 |
|
| 68 | 68 |
digraphCopy(from, to). |
| 69 | 69 |
nodeMap(fnm, tnm).arcMap(fam, tam). |
| 70 | 70 |
nodeRef(nr).arcRef(er). |
| 71 | 71 |
nodeCrossRef(ncr).arcCrossRef(ecr). |
| 72 | 72 |
node(fn, tn).arc(fa, ta).run(); |
| 73 | 73 |
|
| 74 | 74 |
check(countNodes(from) == countNodes(to), "Wrong copy."); |
| 75 | 75 |
check(countArcs(from) == countArcs(to), "Wrong copy."); |
| 76 | 76 |
|
| 77 | 77 |
for (SmartDigraph::NodeIt it(from); it != INVALID; ++it) {
|
| 78 | 78 |
check(ncr[nr[it]] == it, "Wrong copy."); |
| 79 | 79 |
check(fnm[it] == tnm[nr[it]], "Wrong copy."); |
| 80 | 80 |
} |
| 81 | 81 |
|
| 82 | 82 |
for (SmartDigraph::ArcIt it(from); it != INVALID; ++it) {
|
| 83 | 83 |
check(ecr[er[it]] == it, "Wrong copy."); |
| 84 | 84 |
check(fam[it] == tam[er[it]], "Wrong copy."); |
| 85 | 85 |
check(nr[from.source(it)] == to.source(er[it]), "Wrong copy."); |
| 86 | 86 |
check(nr[from.target(it)] == to.target(er[it]), "Wrong copy."); |
| 87 | 87 |
} |
| 88 | 88 |
|
| 89 | 89 |
for (ListDigraph::NodeIt it(to); it != INVALID; ++it) {
|
| 90 | 90 |
check(nr[ncr[it]] == it, "Wrong copy."); |
| 91 | 91 |
} |
| 92 | 92 |
|
| 93 | 93 |
for (ListDigraph::ArcIt it(to); it != INVALID; ++it) {
|
| 94 | 94 |
check(er[ecr[it]] == it, "Wrong copy."); |
| 95 | 95 |
} |
| 96 | 96 |
check(tn == nr[fn], "Wrong copy."); |
| 97 | 97 |
check(ta == er[fa], "Wrong copy."); |
| 98 | 98 |
|
| 99 | 99 |
// Test repeated copy |
| 100 | 100 |
digraphCopy(from, to).run(); |
| 101 | 101 |
|
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2011 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#include <iostream> |
| 20 | 20 |
#include <fstream> |
| 21 | 21 |
#include <string> |
| 22 | 22 |
#include <vector> |
| 23 | 23 |
|
| 24 | 24 |
#include <lemon/concept_check.h> |
| 25 | 25 |
#include <lemon/concepts/heap.h> |
| 26 | 26 |
|
| 27 | 27 |
#include <lemon/smart_graph.h> |
| 28 | 28 |
#include <lemon/lgf_reader.h> |
| 29 | 29 |
#include <lemon/dijkstra.h> |
| 30 | 30 |
#include <lemon/maps.h> |
| 31 | 31 |
|
| 32 | 32 |
#include <lemon/bin_heap.h> |
| 33 | 33 |
#include <lemon/quad_heap.h> |
| 34 | 34 |
#include <lemon/dheap.h> |
| 35 | 35 |
#include <lemon/fib_heap.h> |
| 36 | 36 |
#include <lemon/pairing_heap.h> |
| 37 | 37 |
#include <lemon/radix_heap.h> |
| 38 | 38 |
#include <lemon/binomial_heap.h> |
| 39 | 39 |
#include <lemon/bucket_heap.h> |
| 40 | 40 |
|
| 41 | 41 |
#include "test_tools.h" |
| 42 | 42 |
|
| 43 | 43 |
using namespace lemon; |
| 44 | 44 |
using namespace lemon::concepts; |
| 45 | 45 |
|
| 46 | 46 |
typedef ListDigraph Digraph; |
| 47 | 47 |
DIGRAPH_TYPEDEFS(Digraph); |
| 48 | 48 |
|
| 49 | 49 |
char test_lgf[] = |
| 50 | 50 |
"@nodes\n" |
| 51 | 51 |
"label\n" |
| 52 | 52 |
"0\n" |
| 53 | 53 |
"1\n" |
| 54 | 54 |
"2\n" |
| 55 | 55 |
"3\n" |
| 56 | 56 |
"4\n" |
| 57 | 57 |
"5\n" |
| 58 | 58 |
"6\n" |
| 59 | 59 |
"7\n" |
| 60 | 60 |
"8\n" |
| 61 | 61 |
"9\n" |
| 62 | 62 |
"@arcs\n" |
| 63 | 63 |
" label capacity\n" |
| 64 | 64 |
"0 5 0 94\n" |
| 65 | 65 |
"3 9 1 11\n" |
| 66 | 66 |
"8 7 2 83\n" |
| 67 | 67 |
"1 2 3 94\n" |
| 68 | 68 |
"5 7 4 35\n" |
| 69 | 69 |
"7 4 5 84\n" |
| 70 | 70 |
"9 5 6 38\n" |
| 71 | 71 |
"0 4 7 96\n" |
| 72 | 72 |
"6 7 8 6\n" |
| 73 | 73 |
"3 1 9 27\n" |
| 74 | 74 |
"5 2 10 77\n" |
| 75 | 75 |
"5 6 11 69\n" |
| 76 | 76 |
"6 5 12 41\n" |
| 77 | 77 |
"4 6 13 70\n" |
| 78 | 78 |
"3 2 14 45\n" |
| 79 | 79 |
"7 9 15 93\n" |
| 80 | 80 |
"5 9 16 50\n" |
| 81 | 81 |
"9 0 17 94\n" |
| 82 | 82 |
"9 6 18 67\n" |
| 83 | 83 |
"0 9 19 86\n" |
| 84 | 84 |
"@attributes\n" |
| 85 | 85 |
"source 3\n"; |
| 86 | 86 |
|
| 87 | 87 |
int test_seq[] = { 2, 28, 19, 27, 33, 25, 13, 41, 10, 26, 1, 9, 4, 34};
|
| 88 | 88 |
int test_inc[] = {20, 28, 34, 16, 0, 46, 44, 0, 42, 32, 14, 8, 6, 37};
|
| 89 | 89 |
|
| 90 | 90 |
int test_len = sizeof(test_seq) / sizeof(test_seq[0]); |
| 91 | 91 |
|
| 92 | 92 |
template <typename Heap> |
| 93 | 93 |
void heapSortTest() {
|
| 94 | 94 |
RangeMap<int> map(test_len, -1); |
| 95 | 95 |
Heap heap(map); |
| 96 | 96 |
|
| 97 | 97 |
std::vector<int> v(test_len); |
| 98 | 98 |
for (int i = 0; i < test_len; ++i) {
|
| 99 | 99 |
v[i] = test_seq[i]; |
| 100 | 100 |
heap.push(i, v[i]); |
| 101 | 101 |
} |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2011 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 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; |
| 54 | 54 |
public: |
| 55 | 55 |
Less(T t): _t(t) {}
|
| 56 | 56 |
bool operator()(const T& t) const { return t < _t; }
|
| 57 | 57 |
}; |
| 58 | 58 |
|
| 59 | 59 |
class F {
|
| 60 | 60 |
public: |
| 61 | 61 |
typedef A argument_type; |
| 62 | 62 |
typedef B result_type; |
| 63 | 63 |
|
| 64 | 64 |
B operator()(const A&) const { return B(); }
|
| 65 | 65 |
private: |
| 66 | 66 |
F& operator=(const F&); |
| 67 | 67 |
}; |
| 68 | 68 |
|
| 69 | 69 |
int func(A) { return 3; }
|
| 70 | 70 |
|
| 71 | 71 |
int binc(int a, B) { return a+1; }
|
| 72 | 72 |
|
| 73 | 73 |
template <typename T> |
| 74 | 74 |
class Sum {
|
| 75 | 75 |
T& _sum; |
| 76 | 76 |
public: |
| 77 | 77 |
Sum(T& sum) : _sum(sum) {}
|
| 78 | 78 |
void operator()(const T& t) { _sum += t; }
|
| 79 | 79 |
}; |
| 80 | 80 |
|
| 81 | 81 |
typedef ReadMap<A, double> DoubleMap; |
| 82 | 82 |
typedef ReadWriteMap<A, double> DoubleWriteMap; |
| 83 | 83 |
typedef ReferenceMap<A, double, double&, const double&> DoubleRefMap; |
| 84 | 84 |
|
| 85 | 85 |
typedef ReadMap<A, bool> BoolMap; |
| 86 | 86 |
typedef ReadWriteMap<A, bool> BoolWriteMap; |
| 87 | 87 |
typedef ReferenceMap<A, bool, bool&, const bool&> BoolRefMap; |
| 88 | 88 |
|
| 89 | 89 |
int main() |
| 90 | 90 |
{
|
| 91 | 91 |
// Map concepts |
| 92 | 92 |
checkConcept<ReadMap<A,B>, ReadMap<A,B> >(); |
| 93 | 93 |
checkConcept<ReadMap<A,C>, ReadMap<A,C> >(); |
| 94 | 94 |
checkConcept<WriteMap<A,B>, WriteMap<A,B> >(); |
| 95 | 95 |
checkConcept<WriteMap<A,C>, WriteMap<A,C> >(); |
| 96 | 96 |
checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >(); |
| 97 | 97 |
checkConcept<ReadWriteMap<A,C>, ReadWriteMap<A,C> >(); |
| 98 | 98 |
checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >(); |
| 99 | 99 |
checkConcept<ReferenceMap<A,C,C&,const C&>, ReferenceMap<A,C,C&,const C&> >(); |
| 100 | 100 |
|
| 101 | 101 |
// NullMap |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2011 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 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" |
| 54 | 54 |
"3 6 8 5\n" |
| 55 | 55 |
"4 3 9 3\n" |
| 56 | 56 |
"5 7 10 3\n" |
| 57 | 57 |
"5 6 11 10\n" |
| 58 | 58 |
"5 8 12 10\n" |
| 59 | 59 |
"6 8 13 8\n" |
| 60 | 60 |
"8 9 14 20\n" |
| 61 | 61 |
"8 1 15 5\n" |
| 62 | 62 |
"9 5 16 5\n" |
| 63 | 63 |
"@attributes\n" |
| 64 | 64 |
"source 1\n" |
| 65 | 65 |
"target 8\n"; |
| 66 | 66 |
|
| 67 | 67 |
void checkPreflowCompile() |
| 68 | 68 |
{
|
| 69 | 69 |
typedef int VType; |
| 70 | 70 |
typedef concepts::Digraph Digraph; |
| 71 | 71 |
|
| 72 | 72 |
typedef Digraph::Node Node; |
| 73 | 73 |
typedef Digraph::Arc Arc; |
| 74 | 74 |
typedef concepts::ReadMap<Arc,VType> CapMap; |
| 75 | 75 |
typedef concepts::ReadWriteMap<Arc,VType> FlowMap; |
| 76 | 76 |
typedef concepts::WriteMap<Node,bool> CutMap; |
| 77 | 77 |
|
| 78 | 78 |
typedef Elevator<Digraph, Digraph::Node> Elev; |
| 79 | 79 |
typedef LinkedElevator<Digraph, Digraph::Node> LinkedElev; |
| 80 | 80 |
|
| 81 | 81 |
Digraph g; |
| 82 | 82 |
Node n; |
| 83 | 83 |
Arc e; |
| 84 | 84 |
CapMap cap; |
| 85 | 85 |
FlowMap flow; |
| 86 | 86 |
CutMap cut; |
| 87 | 87 |
VType v; |
| 88 | 88 |
bool b; |
| 89 | 89 |
|
| 90 | 90 |
typedef Preflow<Digraph, CapMap> |
| 91 | 91 |
::SetFlowMap<FlowMap> |
| 92 | 92 |
::SetElevator<Elev> |
| 93 | 93 |
::SetStandardElevator<LinkedElev> |
| 94 | 94 |
::Create PreflowType; |
| 95 | 95 |
PreflowType preflow_test(g, cap, n, n); |
| 96 | 96 |
const PreflowType& const_preflow_test = preflow_test; |
| 97 | 97 |
|
| 98 | 98 |
const PreflowType::Elevator& elev = const_preflow_test.elevator(); |
| 99 | 99 |
preflow_test.elevator(const_cast<PreflowType::Elevator&>(elev)); |
| 100 | 100 |
PreflowType::Tolerance tol = const_preflow_test.tolerance(); |
| 101 | 101 |
preflow_test.tolerance(tol); |
0 comments (0 inline)