0
3
0
| ... | ... |
@@ -152,7 +152,6 @@ |
| 152 | 152 |
{
|
| 153 |
bool found; |
|
| 154 | 153 |
LargeValue dist; |
| 155 | 154 |
Arc pred; |
| 156 |
PathData(bool f = false, LargeValue d = 0, Arc p = INVALID) : |
|
| 157 |
found(f), dist(d), pred(p) {}
|
|
| 155 |
PathData(LargeValue d, Arc p = INVALID) : |
|
| 156 |
dist(d), pred(p) {}
|
|
| 158 | 157 |
}; |
| ... | ... |
@@ -193,2 +192,5 @@ |
| 193 | 192 |
|
| 193 |
// Infinite constant |
|
| 194 |
const LargeValue INF; |
|
| 195 |
|
|
| 194 | 196 |
public: |
| ... | ... |
@@ -247,3 +249,6 @@ |
| 247 | 249 |
_best_found(false), _best_length(0), _best_size(1), |
| 248 |
_cycle_path(NULL), _local_path(false), _data(digraph) |
|
| 250 |
_cycle_path(NULL), _local_path(false), _data(digraph), |
|
| 251 |
INF(std::numeric_limits<LargeValue>::has_infinity ? |
|
| 252 |
std::numeric_limits<LargeValue>::infinity() : |
|
| 253 |
std::numeric_limits<LargeValue>::max()) |
|
| 249 | 254 |
{}
|
| ... | ... |
@@ -474,3 +479,3 @@ |
| 474 | 479 |
for (int i = 0; i < n; ++i) {
|
| 475 |
_data[(*_nodes)[i]].resize(n + 1); |
|
| 480 |
_data[(*_nodes)[i]].resize(n + 1, PathData(INF)); |
|
| 476 | 481 |
} |
| ... | ... |
@@ -484,3 +489,3 @@ |
| 484 | 489 |
Node start = (*_nodes)[0]; |
| 485 |
_data[start][0] = PathData( |
|
| 490 |
_data[start][0] = PathData(0); |
|
| 486 | 491 |
_process.clear(); |
| ... | ... |
@@ -519,8 +524,5 @@ |
| 519 | 524 |
d = _data[u][k-1].dist + _length[e]; |
| 520 |
if (!_data[v][k].found) {
|
|
| 521 |
next.push_back(v); |
|
| 522 |
_data[v][k] = PathData(true, _data[u][k-1].dist + _length[e], e); |
|
| 523 |
} |
|
| 524 |
else if (_tolerance.less(d, _data[v][k].dist)) {
|
|
| 525 |
_data[v][k] = PathData(true, d, e); |
|
| 525 |
if (_tolerance.less(d, _data[v][k].dist)) {
|
|
| 526 |
if (_data[v][k].dist == INF) next.push_back(v); |
|
| 527 |
_data[v][k] = PathData(d, e); |
|
| 526 | 528 |
} |
| ... | ... |
@@ -542,4 +544,4 @@ |
| 542 | 544 |
d = _data[u][k-1].dist + _length[e]; |
| 543 |
if (!_data[v][k].found || _tolerance.less(d, _data[v][k].dist)) {
|
|
| 544 |
_data[v][k] = PathData(true, d, e); |
|
| 545 |
if (_tolerance.less(d, _data[v][k].dist)) {
|
|
| 546 |
_data[v][k] = PathData(d, e); |
|
| 545 | 547 |
} |
| ... | ... |
@@ -563,3 +565,3 @@ |
| 563 | 565 |
u = (*_nodes)[i]; |
| 564 |
if ( |
|
| 566 |
if (_data[u][k].dist == INF) continue; |
|
| 565 | 567 |
for (int j = k; j >= 0; --j) {
|
| ... | ... |
@@ -588,7 +590,7 @@ |
| 588 | 590 |
u = (*_nodes)[i]; |
| 589 |
pi[u] = |
|
| 591 |
pi[u] = INF; |
|
| 590 | 592 |
for (int j = 0; j <= k; ++j) {
|
| 591 |
d = _data[u][j].dist * _curr_size - j * _curr_length; |
|
| 592 |
if (_data[u][j].found && _tolerance.less(d, pi[u])) {
|
|
| 593 |
|
|
| 593 |
if (_data[u][j].dist < INF) {
|
|
| 594 |
d = _data[u][j].dist * _curr_size - j * _curr_length; |
|
| 595 |
if (_tolerance.less(d, pi[u])) pi[u] = d; |
|
| 594 | 596 |
} |
| ... | ... |
@@ -180,2 +180,5 @@ |
| 180 | 180 |
|
| 181 |
// Infinite constant |
|
| 182 |
const LargeValue INF; |
|
| 183 |
|
|
| 181 | 184 |
public: |
| ... | ... |
@@ -232,5 +235,9 @@ |
| 232 | 235 |
const LengthMap &length ) : |
| 233 |
_gr(digraph), _length(length), |
|
| 236 |
_gr(digraph), _length(length), _best_found(false), |
|
| 237 |
_best_length(0), _best_size(1), _cycle_path(NULL), _local_path(false), |
|
| 234 | 238 |
_policy(digraph), _reached(digraph), _level(digraph), _dist(digraph), |
| 235 |
_comp(digraph), _in_arcs(digraph) |
|
| 239 |
_comp(digraph), _in_arcs(digraph), |
|
| 240 |
INF(std::numeric_limits<LargeValue>::has_infinity ? |
|
| 241 |
std::numeric_limits<LargeValue>::infinity() : |
|
| 242 |
std::numeric_limits<LargeValue>::max()) |
|
| 236 | 243 |
{}
|
| ... | ... |
@@ -309,3 +316,3 @@ |
| 309 | 316 |
// Update the best cycle (global minimum mean cycle) |
| 310 |
if ( !_best_found || |
|
| 317 |
if ( _curr_found && (!_best_found || |
|
| 311 | 318 |
_curr_length * _best_size < _best_length * _curr_size) ) {
|
| ... | ... |
@@ -448,3 +455,3 @@ |
| 448 | 455 |
for (int i = 0; i < int(_nodes->size()); ++i) {
|
| 449 |
_dist[(*_nodes)[i]] = |
|
| 456 |
_dist[(*_nodes)[i]] = INF; |
|
| 450 | 457 |
} |
| ... | ... |
@@ -150,7 +150,6 @@ |
| 150 | 150 |
{
|
| 151 |
bool found; |
|
| 152 | 151 |
LargeValue dist; |
| 153 | 152 |
Arc pred; |
| 154 |
PathData(bool f = false, LargeValue d = 0, Arc p = INVALID) : |
|
| 155 |
found(f), dist(d), pred(p) {}
|
|
| 153 |
PathData(LargeValue d, Arc p = INVALID) : |
|
| 154 |
dist(d), pred(p) {}
|
|
| 156 | 155 |
}; |
| ... | ... |
@@ -188,2 +187,5 @@ |
| 188 | 187 |
Tolerance _tolerance; |
| 188 |
|
|
| 189 |
// Infinite constant |
|
| 190 |
const LargeValue INF; |
|
| 189 | 191 |
|
| ... | ... |
@@ -243,3 +245,6 @@ |
| 243 | 245 |
_cycle_length(0), _cycle_size(1), _cycle_node(INVALID), |
| 244 |
_cycle_path(NULL), _local_path(false), _data(digraph) |
|
| 246 |
_cycle_path(NULL), _local_path(false), _data(digraph), |
|
| 247 |
INF(std::numeric_limits<LargeValue>::has_infinity ? |
|
| 248 |
std::numeric_limits<LargeValue>::infinity() : |
|
| 249 |
std::numeric_limits<LargeValue>::max()) |
|
| 245 | 250 |
{}
|
| ... | ... |
@@ -460,3 +465,3 @@ |
| 460 | 465 |
for (int i = 0; i < n; ++i) {
|
| 461 |
_data[(*_nodes)[i]].resize(n + 1); |
|
| 466 |
_data[(*_nodes)[i]].resize(n + 1, PathData(INF)); |
|
| 462 | 467 |
} |
| ... | ... |
@@ -470,3 +475,3 @@ |
| 470 | 475 |
Node start = (*_nodes)[0]; |
| 471 |
_data[start][0] = PathData( |
|
| 476 |
_data[start][0] = PathData(0); |
|
| 472 | 477 |
_process.clear(); |
| ... | ... |
@@ -495,8 +500,5 @@ |
| 495 | 500 |
d = _data[u][k-1].dist + _length[e]; |
| 496 |
if (!_data[v][k].found) {
|
|
| 497 |
next.push_back(v); |
|
| 498 |
_data[v][k] = PathData(true, _data[u][k-1].dist + _length[e], e); |
|
| 499 |
} |
|
| 500 |
else if (_tolerance.less(d, _data[v][k].dist)) {
|
|
| 501 |
_data[v][k] = PathData(true, d, e); |
|
| 501 |
if (_tolerance.less(d, _data[v][k].dist)) {
|
|
| 502 |
if (_data[v][k].dist == INF) next.push_back(v); |
|
| 503 |
_data[v][k] = PathData(d, e); |
|
| 502 | 504 |
} |
| ... | ... |
@@ -518,4 +520,4 @@ |
| 518 | 520 |
d = _data[u][k-1].dist + _length[e]; |
| 519 |
if (!_data[v][k].found || _tolerance.less(d, _data[v][k].dist)) {
|
|
| 520 |
_data[v][k] = PathData(true, d, e); |
|
| 521 |
if (_tolerance.less(d, _data[v][k].dist)) {
|
|
| 522 |
_data[v][k] = PathData(d, e); |
|
| 521 | 523 |
} |
| ... | ... |
@@ -530,3 +532,3 @@ |
| 530 | 532 |
Node u = (*_nodes)[i]; |
| 531 |
if ( |
|
| 533 |
if (_data[u][n].dist == INF) continue; |
|
| 532 | 534 |
LargeValue length, max_length = 0; |
| ... | ... |
@@ -535,3 +537,3 @@ |
| 535 | 537 |
for (int k = 0; k < n; ++k) {
|
| 536 |
if ( |
|
| 538 |
if (_data[u][k].dist == INF) continue; |
|
| 537 | 539 |
length = _data[u][n].dist - _data[u][k].dist; |
0 comments (0 inline)