| ... | ... |
@@ -442,111 +442,112 @@ |
| 442 | 442 |
/// |
| 443 | 443 |
/// Using this function has the same effect as using \ref supplyMap() |
| 444 | 444 |
/// with a map in which \c k is assigned to \c s, \c -k is |
| 445 | 445 |
/// assigned to \c t and all other nodes have zero supply value. |
| 446 | 446 |
/// |
| 447 | 447 |
/// \param s The source node. |
| 448 | 448 |
/// \param t The target node. |
| 449 | 449 |
/// \param k The required amount of flow from node \c s to node \c t |
| 450 | 450 |
/// (i.e. the supply of \c s and the demand of \c t). |
| 451 | 451 |
/// |
| 452 | 452 |
/// \return <tt>(*this)</tt> |
| 453 | 453 |
CostScaling& stSupply(const Node& s, const Node& t, Value k) {
|
| 454 | 454 |
for (int i = 0; i != _res_node_num; ++i) {
|
| 455 | 455 |
_supply[i] = 0; |
| 456 | 456 |
} |
| 457 | 457 |
_supply[_node_id[s]] = k; |
| 458 | 458 |
_supply[_node_id[t]] = -k; |
| 459 | 459 |
return *this; |
| 460 | 460 |
} |
| 461 | 461 |
|
| 462 | 462 |
/// @} |
| 463 | 463 |
|
| 464 | 464 |
/// \name Execution control |
| 465 | 465 |
/// The algorithm can be executed using \ref run(). |
| 466 | 466 |
|
| 467 | 467 |
/// @{
|
| 468 | 468 |
|
| 469 | 469 |
/// \brief Run the algorithm. |
| 470 | 470 |
/// |
| 471 | 471 |
/// This function runs the algorithm. |
| 472 | 472 |
/// The paramters can be specified using functions \ref lowerMap(), |
| 473 | 473 |
/// \ref upperMap(), \ref costMap(), \ref supplyMap(), \ref stSupply(). |
| 474 | 474 |
/// For example, |
| 475 | 475 |
/// \code |
| 476 | 476 |
/// CostScaling<ListDigraph> cs(graph); |
| 477 | 477 |
/// cs.lowerMap(lower).upperMap(upper).costMap(cost) |
| 478 | 478 |
/// .supplyMap(sup).run(); |
| 479 | 479 |
/// \endcode |
| 480 | 480 |
/// |
| 481 | 481 |
/// This function can be called more than once. All the given parameters |
| 482 | 482 |
/// are kept for the next call, unless \ref resetParams() or \ref reset() |
| 483 | 483 |
/// is used, thus only the modified parameters have to be set again. |
| 484 | 484 |
/// If the underlying digraph was also modified after the construction |
| 485 | 485 |
/// of the class (or the last \ref reset() call), then the \ref reset() |
| 486 | 486 |
/// function must be called. |
| 487 | 487 |
/// |
| 488 | 488 |
/// \param method The internal method that will be used in the |
| 489 | 489 |
/// algorithm. For more information, see \ref Method. |
| 490 |
/// \param factor The cost scaling factor. It must be |
|
| 490 |
/// \param factor The cost scaling factor. It must be at least two. |
|
| 491 | 491 |
/// |
| 492 | 492 |
/// \return \c INFEASIBLE if no feasible flow exists, |
| 493 | 493 |
/// \n \c OPTIMAL if the problem has optimal solution |
| 494 | 494 |
/// (i.e. it is feasible and bounded), and the algorithm has found |
| 495 | 495 |
/// optimal flow and node potentials (primal and dual solutions), |
| 496 | 496 |
/// \n \c UNBOUNDED if the digraph contains an arc of negative cost |
| 497 | 497 |
/// and infinite upper bound. It means that the objective function |
| 498 | 498 |
/// is unbounded on that arc, however, note that it could actually be |
| 499 | 499 |
/// bounded over the feasible flows, but this algroithm cannot handle |
| 500 | 500 |
/// these cases. |
| 501 | 501 |
/// |
| 502 | 502 |
/// \see ProblemType, Method |
| 503 | 503 |
/// \see resetParams(), reset() |
| 504 |
ProblemType run(Method method = PARTIAL_AUGMENT, int factor = |
|
| 504 |
ProblemType run(Method method = PARTIAL_AUGMENT, int factor = 16) {
|
|
| 505 |
LEMON_ASSERT(factor >= 2, "The scaling factor must be at least 2"); |
|
| 505 | 506 |
_alpha = factor; |
| 506 | 507 |
ProblemType pt = init(); |
| 507 | 508 |
if (pt != OPTIMAL) return pt; |
| 508 | 509 |
start(method); |
| 509 | 510 |
return OPTIMAL; |
| 510 | 511 |
} |
| 511 | 512 |
|
| 512 | 513 |
/// \brief Reset all the parameters that have been given before. |
| 513 | 514 |
/// |
| 514 | 515 |
/// This function resets all the paramaters that have been given |
| 515 | 516 |
/// before using functions \ref lowerMap(), \ref upperMap(), |
| 516 | 517 |
/// \ref costMap(), \ref supplyMap(), \ref stSupply(). |
| 517 | 518 |
/// |
| 518 | 519 |
/// It is useful for multiple \ref run() calls. Basically, all the given |
| 519 | 520 |
/// parameters are kept for the next \ref run() call, unless |
| 520 | 521 |
/// \ref resetParams() or \ref reset() is used. |
| 521 | 522 |
/// If the underlying digraph was also modified after the construction |
| 522 | 523 |
/// of the class or the last \ref reset() call, then the \ref reset() |
| 523 | 524 |
/// function must be used, otherwise \ref resetParams() is sufficient. |
| 524 | 525 |
/// |
| 525 | 526 |
/// For example, |
| 526 | 527 |
/// \code |
| 527 | 528 |
/// CostScaling<ListDigraph> cs(graph); |
| 528 | 529 |
/// |
| 529 | 530 |
/// // First run |
| 530 | 531 |
/// cs.lowerMap(lower).upperMap(upper).costMap(cost) |
| 531 | 532 |
/// .supplyMap(sup).run(); |
| 532 | 533 |
/// |
| 533 | 534 |
/// // Run again with modified cost map (resetParams() is not called, |
| 534 | 535 |
/// // so only the cost map have to be set again) |
| 535 | 536 |
/// cost[e] += 100; |
| 536 | 537 |
/// cs.costMap(cost).run(); |
| 537 | 538 |
/// |
| 538 | 539 |
/// // Run again from scratch using resetParams() |
| 539 | 540 |
/// // (the lower bounds will be set to zero on all arcs) |
| 540 | 541 |
/// cs.resetParams(); |
| 541 | 542 |
/// cs.upperMap(capacity).costMap(cost) |
| 542 | 543 |
/// .supplyMap(sup).run(); |
| 543 | 544 |
/// \endcode |
| 544 | 545 |
/// |
| 545 | 546 |
/// \return <tt>(*this)</tt> |
| 546 | 547 |
/// |
| 547 | 548 |
/// \see reset(), run() |
| 548 | 549 |
CostScaling& resetParams() {
|
| 549 | 550 |
for (int i = 0; i != _res_node_num; ++i) {
|
| 550 | 551 |
_supply[i] = 0; |
| 551 | 552 |
} |
| 552 | 553 |
int limit = _first_out[_root]; |
0 comments (0 inline)