lemon/cycle_canceling.h
changeset 1162 259e3a90ad97
parent 1081 9d1616d708ee
child 1111 a78e5b779b69
equal deleted inserted replaced
19:b88b63da6f28 20:1c34cb46888e
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     2  *
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library.
     3  * This file is a part of LEMON, a generic C++ optimization library.
     4  *
     4  *
     5  * Copyright (C) 2003-2010
     5  * Copyright (C) 2003-2013
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     8  *
     9  * Permission to use, modify and distribute this software is granted
     9  * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
    10  * provided that this copyright notice appears in all copies. For
   781         }
   781         }
   782       }
   782       }
   783 
   783 
   784       return OPTIMAL;
   784       return OPTIMAL;
   785     }
   785     }
   786     
   786 
   787     // Check if the upper bound is greater or equal to the lower bound
   787     // Check if the upper bound is greater or equal to the lower bound
   788     // on each arc.
   788     // on each arc.
   789     bool checkBoundMaps() {
   789     bool checkBoundMaps() {
   790       for (int j = 0; j != _res_arc_num; ++j) {
   790       for (int j = 0; j != _res_arc_num; ++j) {
   791         if (_upper[j] < _lower[j]) return false;
   791         if (_upper[j] < _lower[j]) return false;
   958       SPath cycle;
   958       SPath cycle;
   959       HwMmc hw_mmc(_sgr, _cost_map);
   959       HwMmc hw_mmc(_sgr, _cost_map);
   960       hw_mmc.cycle(cycle);
   960       hw_mmc.cycle(cycle);
   961       buildResidualNetwork();
   961       buildResidualNetwork();
   962       while (true) {
   962       while (true) {
   963         
   963 
   964         typename HwMmc::TerminationCause hw_tc =
   964         typename HwMmc::TerminationCause hw_tc =
   965             hw_mmc.findCycleMean(hw_iter_limit);
   965             hw_mmc.findCycleMean(hw_iter_limit);
   966         if (hw_tc == HwMmc::ITERATION_LIMIT) {
   966         if (hw_tc == HwMmc::ITERATION_LIMIT) {
   967           // Howard's algorithm reached the iteration limit, start a
   967           // Howard's algorithm reached the iteration limit, start a
   968           // strongly polynomial algorithm instead
   968           // strongly polynomial algorithm instead
   974         } else {
   974         } else {
   975           // Find a minimum mean cycle (Howard algorithm)
   975           // Find a minimum mean cycle (Howard algorithm)
   976           if (!(hw_tc == HwMmc::OPTIMAL && hw_mmc.cycleCost() < 0)) break;
   976           if (!(hw_tc == HwMmc::OPTIMAL && hw_mmc.cycleCost() < 0)) break;
   977           hw_mmc.findCycle();
   977           hw_mmc.findCycle();
   978         }
   978         }
   979         
   979 
   980         // Compute delta value
   980         // Compute delta value
   981         Value delta = INF;
   981         Value delta = INF;
   982         for (SPathArcIt a(cycle); a != INVALID; ++a) {
   982         for (SPathArcIt a(cycle); a != INVALID; ++a) {
   983           Value d = _res_cap[_id_vec[_sgr.id(a)]];
   983           Value d = _res_cap[_id_vec[_sgr.id(a)]];
   984           if (d < delta) delta = d;
   984           if (d < delta) delta = d;