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); } |
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 |
} |
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: |
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(); |
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, |
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; |
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 |
0 comments (0 inline)