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_PRED_MAP_PATH_H |
20 | 20 |
#define LEMON_BITS_PRED_MAP_PATH_H |
21 | 21 |
|
22 | 22 |
namespace lemon { |
23 | 23 |
|
24 | 24 |
template <typename _Digraph, typename _PredMap> |
25 | 25 |
class PredMapPath { |
26 | 26 |
public: |
27 | 27 |
typedef True RevPathTag; |
28 | 28 |
|
29 | 29 |
typedef _Digraph Digraph; |
30 | 30 |
typedef typename Digraph::Arc Arc; |
31 | 31 |
typedef _PredMap PredMap; |
32 | 32 |
|
33 | 33 |
PredMapPath(const Digraph& _digraph, const PredMap& _predMap, |
34 | 34 |
typename Digraph::Node _target) |
35 | 35 |
: digraph(_digraph), predMap(_predMap), target(_target) {} |
36 | 36 |
|
37 | 37 |
int length() const { |
38 | 38 |
int len = 0; |
39 | 39 |
typename Digraph::Node node = target; |
40 | 40 |
typename Digraph::Arc arc; |
41 | 41 |
while ((arc = predMap[node]) != INVALID) { |
42 | 42 |
node = digraph.source(arc); |
43 | 43 |
++len; |
44 | 44 |
} |
45 | 45 |
return len; |
46 | 46 |
} |
47 | 47 |
|
48 | 48 |
bool empty() const { |
49 |
return predMap[target] |
|
49 |
return predMap[target] == INVALID; |
|
50 | 50 |
} |
51 | 51 |
|
52 | 52 |
class RevArcIt { |
53 | 53 |
public: |
54 | 54 |
RevArcIt() {} |
55 | 55 |
RevArcIt(Invalid) : path(0), current(INVALID) {} |
56 | 56 |
RevArcIt(const PredMapPath& _path) |
57 | 57 |
: path(&_path), current(_path.target) { |
58 | 58 |
if (path->predMap[current] == INVALID) current = INVALID; |
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
operator const typename Digraph::Arc() const { |
62 | 62 |
return path->predMap[current]; |
63 | 63 |
} |
64 | 64 |
|
65 | 65 |
RevArcIt& operator++() { |
66 | 66 |
current = path->digraph.source(path->predMap[current]); |
67 | 67 |
if (path->predMap[current] == INVALID) current = INVALID; |
68 | 68 |
return *this; |
69 | 69 |
} |
70 | 70 |
|
71 | 71 |
bool operator==(const RevArcIt& e) const { |
72 | 72 |
return current == e.current; |
73 | 73 |
} |
74 | 74 |
|
75 | 75 |
bool operator!=(const RevArcIt& e) const { |
76 | 76 |
return current != e.current; |
77 | 77 |
} |
78 | 78 |
|
79 | 79 |
bool operator<(const RevArcIt& e) const { |
80 | 80 |
return current < e.current; |
81 | 81 |
} |
82 | 82 |
|
83 | 83 |
private: |
84 | 84 |
const PredMapPath* path; |
85 | 85 |
typename Digraph::Node current; |
86 | 86 |
}; |
87 | 87 |
|
88 | 88 |
private: |
89 | 89 |
const Digraph& digraph; |
90 | 90 |
const PredMap& predMap; |
91 | 91 |
typename Digraph::Node target; |
92 | 92 |
}; |
93 | 93 |
|
94 | 94 |
|
95 | 95 |
template <typename _Digraph, typename _PredMatrixMap> |
96 | 96 |
class PredMatrixMapPath { |
97 | 97 |
public: |
0 comments (0 inline)