0
7
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 | 5 |
* Copyright (C) 2003-2009 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#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 |
#include <lemon/bits/map_extender.h> |
|
| 33 | 34 |
#include <lemon/tolerance.h> |
| 34 | 35 |
|
| 35 | 36 |
#include <algorithm> |
| 36 | 37 |
|
| 37 | 38 |
namespace lemon {
|
| 38 | 39 |
|
| 39 | 40 |
#ifdef _MSC_VER |
| 40 | 41 |
#define LEMON_SCOPE_FIX(OUTER, NESTED) OUTER::NESTED |
| 41 | 42 |
#else |
| 42 | 43 |
#define LEMON_SCOPE_FIX(OUTER, NESTED) typename OUTER::template NESTED |
| 43 | 44 |
#endif |
| 44 | 45 |
|
| 45 | 46 |
template<typename DGR> |
| 46 | 47 |
class DigraphAdaptorBase {
|
| 47 | 48 |
public: |
| 48 | 49 |
typedef DGR Digraph; |
| 49 | 50 |
typedef DigraphAdaptorBase Adaptor; |
| 50 | 51 |
|
| 51 | 52 |
protected: |
| 52 | 53 |
DGR* _digraph; |
| 53 | 54 |
DigraphAdaptorBase() : _digraph(0) { }
|
| 54 | 55 |
void initialize(DGR& digraph) { _digraph = &digraph; }
|
| 55 | 56 |
|
| 56 | 57 |
public: |
| 57 | 58 |
DigraphAdaptorBase(DGR& digraph) : _digraph(&digraph) { }
|
| 58 | 59 |
|
| 59 | 60 |
typedef typename DGR::Node Node; |
| 60 | 61 |
typedef typename DGR::Arc Arc; |
| 61 | 62 |
|
| 62 | 63 |
void first(Node& i) const { _digraph->first(i); }
|
| 63 | 64 |
void first(Arc& i) const { _digraph->first(i); }
|
| 64 | 65 |
void firstIn(Arc& i, const Node& n) const { _digraph->firstIn(i, n); }
|
| 65 | 66 |
void firstOut(Arc& i, const Node& n ) const { _digraph->firstOut(i, n); }
|
| 66 | 67 |
|
| 67 | 68 |
void next(Node& i) const { _digraph->next(i); }
|
| 68 | 69 |
void next(Arc& i) const { _digraph->next(i); }
|
| 69 | 70 |
void nextIn(Arc& i) const { _digraph->nextIn(i); }
|
| 70 | 71 |
void nextOut(Arc& i) const { _digraph->nextOut(i); }
|
| 71 | 72 |
|
| 72 | 73 |
Node source(const Arc& a) const { return _digraph->source(a); }
|
| 73 | 74 |
Node target(const Arc& a) const { return _digraph->target(a); }
|
| 74 | 75 |
|
| 75 | 76 |
typedef NodeNumTagIndicator<DGR> NodeNumTag; |
| 76 | 77 |
int nodeNum() const { return _digraph->nodeNum(); }
|
| 77 | 78 |
|
| 78 | 79 |
typedef ArcNumTagIndicator<DGR> ArcNumTag; |
| 79 | 80 |
int arcNum() const { return _digraph->arcNum(); }
|
| 80 | 81 |
| 1 | 1 |
/* -*- C++ -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2008 |
| 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 |
#include <lemon/core.h> |
|
| 22 | 23 |
#include <lemon/error.h> |
| 23 | 24 |
#include <lemon/bits/default_map.h> |
| 25 |
#include <lemon/bits/map_extender.h> |
|
| 24 | 26 |
|
| 25 | 27 |
///\ingroup digraphbits |
| 26 | 28 |
///\file |
| 27 | 29 |
///\brief Extenders for the arc set types |
| 28 | 30 |
namespace lemon {
|
| 29 | 31 |
|
| 30 | 32 |
/// \ingroup digraphbits |
| 31 | 33 |
/// |
| 32 | 34 |
/// \brief Extender for the ArcSets |
| 33 | 35 |
template <typename Base> |
| 34 | 36 |
class ArcSetExtender : public Base {
|
| 35 | 37 |
public: |
| 36 | 38 |
|
| 37 | 39 |
typedef Base Parent; |
| 38 | 40 |
typedef ArcSetExtender Digraph; |
| 39 | 41 |
|
| 40 | 42 |
// Base extensions |
| 41 | 43 |
|
| 42 | 44 |
typedef typename Parent::Node Node; |
| 43 | 45 |
typedef typename Parent::Arc Arc; |
| 44 | 46 |
|
| 45 | 47 |
int maxId(Node) const {
|
| 46 | 48 |
return Parent::maxNodeId(); |
| 47 | 49 |
} |
| 48 | 50 |
|
| 49 | 51 |
int maxId(Arc) const {
|
| 50 | 52 |
return Parent::maxArcId(); |
| 51 | 53 |
} |
| 52 | 54 |
|
| 53 | 55 |
Node fromId(int id, Node) const {
|
| 54 | 56 |
return Parent::nodeFromId(id); |
| 55 | 57 |
} |
| 56 | 58 |
|
| 57 | 59 |
Arc fromId(int id, Arc) const {
|
| 58 | 60 |
return Parent::arcFromId(id); |
| 59 | 61 |
} |
| 60 | 62 |
|
| 61 | 63 |
Node oppositeNode(const Node &n, const Arc &e) const {
|
| 62 | 64 |
if (n == Parent::source(e)) |
| 63 | 65 |
return Parent::target(e); |
| 64 | 66 |
else if(n==Parent::target(e)) |
| 65 | 67 |
return Parent::source(e); |
| 66 | 68 |
else |
| 67 | 69 |
return INVALID; |
| 68 | 70 |
} |
| 69 | 71 |
|
| 70 | 72 |
|
| 71 | 73 |
// Alteration notifier extensions |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2009 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_BITS_PRED_MAP_PATH_H |
| 20 | 20 |
#define LEMON_BITS_PRED_MAP_PATH_H |
| 21 | 21 |
|
| 22 |
#include <lemon/core.h> |
|
| 23 |
#include <lemon/concept_check.h> |
|
| 24 |
|
|
| 22 | 25 |
namespace lemon {
|
| 23 | 26 |
|
| 24 | 27 |
template <typename _Digraph, typename _PredMap> |
| 25 | 28 |
class PredMapPath {
|
| 26 | 29 |
public: |
| 27 | 30 |
typedef True RevPathTag; |
| 28 | 31 |
|
| 29 | 32 |
typedef _Digraph Digraph; |
| 30 | 33 |
typedef typename Digraph::Arc Arc; |
| 31 | 34 |
typedef _PredMap PredMap; |
| 32 | 35 |
|
| 33 | 36 |
PredMapPath(const Digraph& _digraph, const PredMap& _predMap, |
| 34 | 37 |
typename Digraph::Node _target) |
| 35 | 38 |
: digraph(_digraph), predMap(_predMap), target(_target) {}
|
| 36 | 39 |
|
| 37 | 40 |
int length() const {
|
| 38 | 41 |
int len = 0; |
| 39 | 42 |
typename Digraph::Node node = target; |
| 40 | 43 |
typename Digraph::Arc arc; |
| 41 | 44 |
while ((arc = predMap[node]) != INVALID) {
|
| 42 | 45 |
node = digraph.source(arc); |
| 43 | 46 |
++len; |
| 44 | 47 |
} |
| 45 | 48 |
return len; |
| 46 | 49 |
} |
| 47 | 50 |
|
| 48 | 51 |
bool empty() const {
|
| 49 | 52 |
return predMap[target] != INVALID; |
| 50 | 53 |
} |
| 51 | 54 |
|
| 52 | 55 |
class RevArcIt {
|
| 53 | 56 |
public: |
| 54 | 57 |
RevArcIt() {}
|
| 55 | 58 |
RevArcIt(Invalid) : path(0), current(INVALID) {}
|
| 56 | 59 |
RevArcIt(const PredMapPath& _path) |
| 57 | 60 |
: path(&_path), current(_path.target) {
|
| 58 | 61 |
if (path->predMap[current] == INVALID) current = INVALID; |
| 59 | 62 |
} |
| 60 | 63 |
|
| 61 | 64 |
operator const typename Digraph::Arc() const {
|
| 62 | 65 |
return path->predMap[current]; |
| 63 | 66 |
} |
| 64 | 67 |
|
| 65 | 68 |
RevArcIt& operator++() {
|
| 66 | 69 |
current = path->digraph.source(path->predMap[current]); |
| 67 | 70 |
if (path->predMap[current] == INVALID) current = INVALID; |
| 68 | 71 |
return *this; |
| 69 | 72 |
} |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2008 |
| 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 |
#include <vector> |
|
| 23 |
|
|
| 22 | 24 |
namespace lemon {
|
| 23 | 25 |
|
| 24 | 26 |
namespace _solver_bits {
|
| 25 | 27 |
|
| 26 | 28 |
class VarIndex {
|
| 27 | 29 |
private: |
| 28 | 30 |
struct ItemT {
|
| 29 | 31 |
int prev, next; |
| 30 | 32 |
int index; |
| 31 | 33 |
}; |
| 32 | 34 |
std::vector<ItemT> items; |
| 33 | 35 |
int first_item, last_item, first_free_item; |
| 34 | 36 |
|
| 35 | 37 |
std::vector<int> cross; |
| 36 | 38 |
|
| 37 | 39 |
public: |
| 38 | 40 |
|
| 39 | 41 |
VarIndex() |
| 40 | 42 |
: first_item(-1), last_item(-1), first_free_item(-1) {
|
| 41 | 43 |
} |
| 42 | 44 |
|
| 43 | 45 |
void clear() {
|
| 44 | 46 |
first_item = -1; |
| 45 | 47 |
first_free_item = -1; |
| 46 | 48 |
items.clear(); |
| 47 | 49 |
cross.clear(); |
| 48 | 50 |
} |
| 49 | 51 |
|
| 50 | 52 |
int addIndex(int idx) {
|
| 51 | 53 |
int n; |
| 52 | 54 |
if (first_free_item == -1) {
|
| 53 | 55 |
n = items.size(); |
| 54 | 56 |
items.push_back(ItemT()); |
| 55 | 57 |
} else {
|
| 56 | 58 |
n = first_free_item; |
| 57 | 59 |
first_free_item = items[n].next; |
| 58 | 60 |
if (first_free_item != -1) {
|
| 59 | 61 |
items[first_free_item].prev = -1; |
| 60 | 62 |
} |
| 61 | 63 |
} |
| 62 | 64 |
items[n].index = idx; |
| 63 | 65 |
if (static_cast<int>(cross.size()) <= idx) {
|
| 64 | 66 |
cross.resize(idx + 1, -1); |
| 65 | 67 |
} |
| 66 | 68 |
cross[idx] = n; |
| 67 | 69 |
|
| 68 | 70 |
items[n].prev = last_item; |
| 69 | 71 |
items[n].next = -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 | 5 |
* Copyright (C) 2003-2009 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
///\ingroup concept |
| 20 | 20 |
///\file |
| 21 | 21 |
///\brief The concept of heaps. |
| 22 | 22 |
|
| 23 | 23 |
#ifndef LEMON_CONCEPT_HEAP_H |
| 24 | 24 |
#define LEMON_CONCEPT_HEAP_H |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/core.h> |
| 27 |
#include <lemon/concept_check.h> |
|
| 27 | 28 |
|
| 28 | 29 |
namespace lemon {
|
| 29 | 30 |
|
| 30 | 31 |
namespace concepts {
|
| 31 | 32 |
|
| 32 | 33 |
/// \addtogroup concept |
| 33 | 34 |
/// @{
|
| 34 | 35 |
|
| 35 | 36 |
/// \brief The heap concept. |
| 36 | 37 |
/// |
| 37 | 38 |
/// Concept class describing the main interface of heaps. |
| 38 | 39 |
template <typename Priority, typename ItemIntMap> |
| 39 | 40 |
class Heap {
|
| 40 | 41 |
public: |
| 41 | 42 |
|
| 42 | 43 |
/// Type of the items stored in the heap. |
| 43 | 44 |
typedef typename ItemIntMap::Key Item; |
| 44 | 45 |
|
| 45 | 46 |
/// Type of the priorities. |
| 46 | 47 |
typedef Priority Prio; |
| 47 | 48 |
|
| 48 | 49 |
/// \brief Type to represent the states of the items. |
| 49 | 50 |
/// |
| 50 | 51 |
/// Each item has a state associated to it. It can be "in heap", |
| 51 | 52 |
/// "pre heap" or "post heap". The later two are indifferent |
| 52 | 53 |
/// from the point of view of the heap, but may be useful for |
| 53 | 54 |
/// the user. |
| 54 | 55 |
/// |
| 55 | 56 |
/// The \c ItemIntMap must be initialized in such a way, that it |
| 56 | 57 |
/// assigns \c PRE_HEAP (<tt>-1</tt>) to every item. |
| 57 | 58 |
enum State {
|
| 58 | 59 |
IN_HEAP = 0, |
| 59 | 60 |
PRE_HEAP = -1, |
| 60 | 61 |
POST_HEAP = -2 |
| 61 | 62 |
}; |
| 62 | 63 |
|
| 63 | 64 |
/// \brief The constructor. |
| 64 | 65 |
/// |
| 65 | 66 |
/// The constructor. |
| 66 | 67 |
/// \param map A map that assigns \c int values to keys of type |
| 67 | 68 |
/// \c Item. It is used internally by the heap implementations to |
| 68 | 69 |
/// handle the cross references. The assigned value must be |
| 69 | 70 |
/// \c PRE_HEAP (<tt>-1</tt>) for every item. |
| 70 | 71 |
explicit Heap(ItemIntMap &map) {}
|
| 71 | 72 |
|
| 72 | 73 |
/// \brief The number of items stored in the heap. |
| 73 | 74 |
/// |
| 74 | 75 |
/// Returns the number of items stored in the heap. |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2009 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_ELEVATOR_H |
| 20 | 20 |
#define LEMON_ELEVATOR_H |
| 21 | 21 |
|
| 22 | 22 |
///\ingroup auxdat |
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief Elevator class |
| 25 | 25 |
/// |
| 26 | 26 |
///Elevator class implements an efficient data structure |
| 27 | 27 |
///for labeling items in push-relabel type algorithms. |
| 28 | 28 |
/// |
| 29 | 29 |
|
| 30 |
#include <lemon/core.h> |
|
| 30 | 31 |
#include <lemon/bits/traits.h> |
| 31 | 32 |
|
| 32 | 33 |
namespace lemon {
|
| 33 | 34 |
|
| 34 | 35 |
///Class for handling "labels" in push-relabel type algorithms. |
| 35 | 36 |
|
| 36 | 37 |
///A class for handling "labels" in push-relabel type algorithms. |
| 37 | 38 |
/// |
| 38 | 39 |
///\ingroup auxdat |
| 39 | 40 |
///Using this class you can assign "labels" (nonnegative integer numbers) |
| 40 | 41 |
///to the edges or nodes of a graph, manipulate and query them through |
| 41 | 42 |
///operations typically arising in "push-relabel" type algorithms. |
| 42 | 43 |
/// |
| 43 | 44 |
///Each item is either \em active or not, and you can also choose a |
| 44 | 45 |
///highest level active item. |
| 45 | 46 |
/// |
| 46 | 47 |
///\sa LinkedElevator |
| 47 | 48 |
/// |
| 48 | 49 |
///\param Graph Type of the underlying graph. |
| 49 | 50 |
///\param Item Type of the items the data is assigned to (Graph::Node, |
| 50 | 51 |
///Graph::Arc, Graph::Edge). |
| 51 | 52 |
template<class Graph, class Item> |
| 52 | 53 |
class Elevator |
| 53 | 54 |
{
|
| 54 | 55 |
public: |
| 55 | 56 |
|
| 56 | 57 |
typedef Item Key; |
| 57 | 58 |
typedef int Value; |
| 58 | 59 |
|
| 59 | 60 |
private: |
| 60 | 61 |
|
| 61 | 62 |
typedef Item *Vit; |
| 62 | 63 |
typedef typename ItemSetTraits<Graph,Item>::template Map<Vit>::Type VitMap; |
| 63 | 64 |
typedef typename ItemSetTraits<Graph,Item>::template Map<int>::Type IntMap; |
| 64 | 65 |
|
| 65 | 66 |
const Graph &_g; |
| 66 | 67 |
int _max_level; |
| 67 | 68 |
int _item_num; |
| 68 | 69 |
VitMap _where; |
| 69 | 70 |
IntMap _level; |
| 70 | 71 |
std::vector<Item> _items; |
| 71 | 72 |
std::vector<Vit> _first; |
| 72 | 73 |
std::vector<Vit> _last_active; |
| 73 | 74 |
|
| 74 | 75 |
int _highest_active; |
| 75 | 76 |
|
| 76 | 77 |
void copy(Item i, Vit p) |
| 77 | 78 |
{
|
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2009 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#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 <lemon/bin_heap.h> |
| 29 | 29 |
#include <lemon/path.h> |
| 30 |
#include <lemon/list_graph.h> |
|
| 31 |
#include <lemon/maps.h> |
|
| 30 | 32 |
|
| 31 | 33 |
namespace lemon {
|
| 32 | 34 |
|
| 33 | 35 |
/// \addtogroup shortest_path |
| 34 | 36 |
/// @{
|
| 35 | 37 |
|
| 36 | 38 |
/// \brief Algorithm for finding arc-disjoint paths between two nodes |
| 37 | 39 |
/// having minimum total length. |
| 38 | 40 |
/// |
| 39 | 41 |
/// \ref lemon::Suurballe "Suurballe" implements an algorithm for |
| 40 | 42 |
/// finding arc-disjoint paths having minimum total length (cost) |
| 41 | 43 |
/// from a given source node to a given target node in a digraph. |
| 42 | 44 |
/// |
| 43 | 45 |
/// In fact, this implementation is the specialization of the |
| 44 | 46 |
/// \ref CapacityScaling "successive shortest path" algorithm. |
| 45 | 47 |
/// |
| 46 | 48 |
/// \tparam Digraph The digraph type the algorithm runs on. |
| 47 | 49 |
/// The default value is \c ListDigraph. |
| 48 | 50 |
/// \tparam LengthMap The type of the length (cost) map. |
| 49 | 51 |
/// The default value is <tt>Digraph::ArcMap<int></tt>. |
| 50 | 52 |
/// |
| 51 | 53 |
/// \warning Length values should be \e non-negative \e integers. |
| 52 | 54 |
/// |
| 53 | 55 |
/// \note For finding node-disjoint paths this algorithm can be used |
| 54 | 56 |
/// with \ref SplitNodes. |
| 55 | 57 |
#ifdef DOXYGEN |
| 56 | 58 |
template <typename Digraph, typename LengthMap> |
| 57 | 59 |
#else |
| 58 | 60 |
template < typename Digraph = ListDigraph, |
| 59 | 61 |
typename LengthMap = typename Digraph::template ArcMap<int> > |
| 60 | 62 |
#endif |
| 61 | 63 |
class Suurballe |
| 62 | 64 |
{
|
| 63 | 65 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
| 64 | 66 |
|
| 65 | 67 |
typedef typename LengthMap::Value Length; |
| 66 | 68 |
typedef ConstMap<Arc, int> ConstArcMap; |
| 67 | 69 |
typedef typename Digraph::template NodeMap<Arc> PredMap; |
| 68 | 70 |
|
| 69 | 71 |
public: |
| 70 | 72 |
|
| 71 | 73 |
/// The type of the flow map. |
| 72 | 74 |
typedef typename Digraph::template ArcMap<int> FlowMap; |
| 73 | 75 |
/// The type of the potential map. |
| 74 | 76 |
typedef typename Digraph::template NodeMap<Length> PotentialMap; |
| 75 | 77 |
/// The type of the path structures. |
| 76 | 78 |
typedef SimplePath<Digraph> Path; |
| 77 | 79 |
|
0 comments (0 inline)