1.1 --- a/lemon/hartmann_orlin.h Tue Aug 11 21:53:39 2009 +0200
1.2 +++ b/lemon/hartmann_orlin.h Tue Aug 11 22:52:35 2009 +0200
1.3 @@ -150,11 +150,10 @@
1.4 // Data sturcture for path data
1.5 struct PathData
1.6 {
1.7 - bool found;
1.8 LargeValue dist;
1.9 Arc pred;
1.10 - PathData(bool f = false, LargeValue d = 0, Arc p = INVALID) :
1.11 - found(f), dist(d), pred(p) {}
1.12 + PathData(LargeValue d, Arc p = INVALID) :
1.13 + dist(d), pred(p) {}
1.14 };
1.15
1.16 typedef typename Digraph::template NodeMap<std::vector<PathData> >
1.17 @@ -191,6 +190,9 @@
1.18
1.19 Tolerance _tolerance;
1.20
1.21 + // Infinite constant
1.22 + const LargeValue INF;
1.23 +
1.24 public:
1.25
1.26 /// \name Named Template Parameters
1.27 @@ -245,7 +247,10 @@
1.28 const LengthMap &length ) :
1.29 _gr(digraph), _length(length), _comp(digraph), _out_arcs(digraph),
1.30 _best_found(false), _best_length(0), _best_size(1),
1.31 - _cycle_path(NULL), _local_path(false), _data(digraph)
1.32 + _cycle_path(NULL), _local_path(false), _data(digraph),
1.33 + INF(std::numeric_limits<LargeValue>::has_infinity ?
1.34 + std::numeric_limits<LargeValue>::infinity() :
1.35 + std::numeric_limits<LargeValue>::max())
1.36 {}
1.37
1.38 /// Destructor.
1.39 @@ -472,7 +477,7 @@
1.40 return false;
1.41 }
1.42 for (int i = 0; i < n; ++i) {
1.43 - _data[(*_nodes)[i]].resize(n + 1);
1.44 + _data[(*_nodes)[i]].resize(n + 1, PathData(INF));
1.45 }
1.46 return true;
1.47 }
1.48 @@ -482,7 +487,7 @@
1.49 // node to node v containing exactly k arcs.
1.50 void processRounds() {
1.51 Node start = (*_nodes)[0];
1.52 - _data[start][0] = PathData(true, 0);
1.53 + _data[start][0] = PathData(0);
1.54 _process.clear();
1.55 _process.push_back(start);
1.56
1.57 @@ -517,12 +522,9 @@
1.58 e = _out_arcs[u][j];
1.59 v = _gr.target(e);
1.60 d = _data[u][k-1].dist + _length[e];
1.61 - if (!_data[v][k].found) {
1.62 - next.push_back(v);
1.63 - _data[v][k] = PathData(true, _data[u][k-1].dist + _length[e], e);
1.64 - }
1.65 - else if (_tolerance.less(d, _data[v][k].dist)) {
1.66 - _data[v][k] = PathData(true, d, e);
1.67 + if (_tolerance.less(d, _data[v][k].dist)) {
1.68 + if (_data[v][k].dist == INF) next.push_back(v);
1.69 + _data[v][k] = PathData(d, e);
1.70 }
1.71 }
1.72 }
1.73 @@ -540,8 +542,8 @@
1.74 e = _out_arcs[u][j];
1.75 v = _gr.target(e);
1.76 d = _data[u][k-1].dist + _length[e];
1.77 - if (!_data[v][k].found || _tolerance.less(d, _data[v][k].dist)) {
1.78 - _data[v][k] = PathData(true, d, e);
1.79 + if (_tolerance.less(d, _data[v][k].dist)) {
1.80 + _data[v][k] = PathData(d, e);
1.81 }
1.82 }
1.83 }
1.84 @@ -561,7 +563,7 @@
1.85 _curr_found = false;
1.86 for (int i = 0; i < n; ++i) {
1.87 u = (*_nodes)[i];
1.88 - if (!_data[u][k].found) continue;
1.89 + if (_data[u][k].dist == INF) continue;
1.90 for (int j = k; j >= 0; --j) {
1.91 if (level[u].first == i && level[u].second > 0) {
1.92 // A cycle is found
1.93 @@ -586,11 +588,11 @@
1.94 // Find node potentials
1.95 for (int i = 0; i < n; ++i) {
1.96 u = (*_nodes)[i];
1.97 - pi[u] = std::numeric_limits<LargeValue>::max();
1.98 + pi[u] = INF;
1.99 for (int j = 0; j <= k; ++j) {
1.100 - d = _data[u][j].dist * _curr_size - j * _curr_length;
1.101 - if (_data[u][j].found && _tolerance.less(d, pi[u])) {
1.102 - pi[u] = d;
1.103 + if (_data[u][j].dist < INF) {
1.104 + d = _data[u][j].dist * _curr_size - j * _curr_length;
1.105 + if (_tolerance.less(d, pi[u])) pi[u] = d;
1.106 }
1.107 }
1.108 }