diff --git a/lemon/Makefile.am b/lemon/Makefile.am --- a/lemon/Makefile.am +++ b/lemon/Makefile.am @@ -89,10 +89,10 @@ lemon/gomory_hu.h \ lemon/graph_to_eps.h \ lemon/grid_graph.h \ - lemon/hartmann_orlin.h \ - lemon/howard.h \ + lemon/hartmann_orlin_mmc.h \ + lemon/howard_mmc.h \ lemon/hypercube_graph.h \ - lemon/karp.h \ + lemon/karp_mmc.h \ lemon/kruskal.h \ lemon/hao_orlin.h \ lemon/lgf_reader.h \ diff --git a/lemon/cycle_canceling.h b/lemon/cycle_canceling.h --- a/lemon/cycle_canceling.h +++ b/lemon/cycle_canceling.h @@ -34,7 +34,7 @@ #include #include #include -#include +#include namespace lemon { @@ -924,14 +924,14 @@ void startMinMeanCycleCanceling() { typedef SimplePath SPath; typedef typename SPath::ArcIt SPathArcIt; - typedef typename Howard + typedef typename HowardMmc ::template SetPath::Create MMC; SPath cycle; MMC mmc(_sgr, _cost_map); mmc.cycle(cycle); buildResidualNetwork(); - while (mmc.findMinMean() && mmc.cycleLength() < 0) { + while (mmc.findCycleMean() && mmc.cycleCost() < 0) { // Find the cycle mmc.findCycle(); @@ -1132,17 +1132,17 @@ } } } else { - typedef Howard MMC; + typedef HowardMmc MMC; typedef typename BellmanFord ::template SetDistMap::Create BF; // Set epsilon to the minimum cycle mean buildResidualNetwork(); MMC mmc(_sgr, _cost_map); - mmc.findMinMean(); + mmc.findCycleMean(); epsilon = -mmc.cycleMean(); - Cost cycle_cost = mmc.cycleLength(); - int cycle_size = mmc.cycleArcNum(); + Cost cycle_cost = mmc.cycleCost(); + int cycle_size = mmc.cycleSize(); // Compute feasible potentials for the current epsilon for (int i = 0; i != int(_cost_vec.size()); ++i) { diff --git a/lemon/hartmann_orlin.h b/lemon/hartmann_orlin_mmc.h rename from lemon/hartmann_orlin.h rename to lemon/hartmann_orlin_mmc.h --- a/lemon/hartmann_orlin.h +++ b/lemon/hartmann_orlin_mmc.h @@ -16,8 +16,8 @@ * */ -#ifndef LEMON_HARTMANN_ORLIN_H -#define LEMON_HARTMANN_ORLIN_H +#ifndef LEMON_HARTMANN_ORLIN_MMC_H +#define LEMON_HARTMANN_ORLIN_MMC_H /// \ingroup min_mean_cycle /// @@ -33,37 +33,37 @@ namespace lemon { - /// \brief Default traits class of HartmannOrlin algorithm. + /// \brief Default traits class of HartmannOrlinMmc class. /// - /// Default traits class of HartmannOrlin algorithm. + /// Default traits class of HartmannOrlinMmc class. /// \tparam GR The type of the digraph. - /// \tparam LEN The type of the length map. + /// \tparam CM The type of the cost map. /// It must conform to the \ref concepts::Rea_data "Rea_data" concept. #ifdef DOXYGEN - template + template #else - template ::is_integer> + template ::is_integer> #endif - struct HartmannOrlinDefaultTraits + struct HartmannOrlinMmcDefaultTraits { /// The type of the digraph typedef GR Digraph; - /// The type of the length map - typedef LEN LengthMap; - /// The type of the arc lengths - typedef typename LengthMap::Value Value; + /// The type of the cost map + typedef CM CostMap; + /// The type of the arc costs + typedef typename CostMap::Value Cost; - /// \brief The large value type used for internal computations + /// \brief The large cost type used for internal computations /// - /// The large value type used for internal computations. - /// It is \c long \c long if the \c Value type is integer, + /// The large cost type used for internal computations. + /// It is \c long \c long if the \c Cost type is integer, /// otherwise it is \c double. - /// \c Value must be convertible to \c LargeValue. - typedef double LargeValue; + /// \c Cost must be convertible to \c LargeCost. + typedef double LargeCost; /// The tolerance type used for internal computations - typedef lemon::Tolerance Tolerance; + typedef lemon::Tolerance Tolerance; /// \brief The path type of the found cycles /// @@ -73,19 +73,19 @@ typedef lemon::Path Path; }; - // Default traits class for integer value types - template - struct HartmannOrlinDefaultTraits + // Default traits class for integer cost types + template + struct HartmannOrlinMmcDefaultTraits { typedef GR Digraph; - typedef LEN LengthMap; - typedef typename LengthMap::Value Value; + typedef CM CostMap; + typedef typename CostMap::Value Cost; #ifdef LEMON_HAVE_LONG_LONG - typedef long long LargeValue; + typedef long long LargeCost; #else - typedef long LargeValue; + typedef long LargeCost; #endif - typedef lemon::Tolerance Tolerance; + typedef lemon::Tolerance Tolerance; typedef lemon::Path Path; }; @@ -97,44 +97,44 @@ /// a minimum mean cycle. /// /// This class implements the Hartmann-Orlin algorithm for finding - /// a directed cycle of minimum mean length (cost) in a digraph + /// a directed cycle of minimum mean cost in a digraph /// \ref amo93networkflows, \ref dasdan98minmeancycle. /// It is an improved version of \ref Karp "Karp"'s original algorithm, /// it applies an efficient early termination scheme. /// It runs in time O(ne) and uses space O(n2+e). /// /// \tparam GR The type of the digraph the algorithm runs on. - /// \tparam LEN The type of the length map. The default + /// \tparam CM The type of the cost map. The default /// map type is \ref concepts::Digraph::ArcMap "GR::ArcMap". /// \tparam TR The traits class that defines various types used by the - /// algorithm. By default, it is \ref HartmannOrlinDefaultTraits - /// "HartmannOrlinDefaultTraits". + /// algorithm. By default, it is \ref HartmannOrlinMmcDefaultTraits + /// "HartmannOrlinMmcDefaultTraits". /// In most cases, this parameter should not be set directly, /// consider to use the named template parameters instead. #ifdef DOXYGEN - template + template #else template < typename GR, - typename LEN = typename GR::template ArcMap, - typename TR = HartmannOrlinDefaultTraits > + typename CM = typename GR::template ArcMap, + typename TR = HartmannOrlinMmcDefaultTraits > #endif - class HartmannOrlin + class HartmannOrlinMmc { public: /// The type of the digraph typedef typename TR::Digraph Digraph; - /// The type of the length map - typedef typename TR::LengthMap LengthMap; - /// The type of the arc lengths - typedef typename TR::Value Value; + /// The type of the cost map + typedef typename TR::CostMap CostMap; + /// The type of the arc costs + typedef typename TR::Cost Cost; - /// \brief The large value type + /// \brief The large cost type /// - /// The large value type used for internal computations. - /// By default, it is \c long \c long if the \c Value type is integer, + /// The large cost type used for internal computations. + /// By default, it is \c long \c long if the \c Cost type is integer, /// otherwise it is \c double. - typedef typename TR::LargeValue LargeValue; + typedef typename TR::LargeCost LargeCost; /// The tolerance type typedef typename TR::Tolerance Tolerance; @@ -142,11 +142,11 @@ /// \brief The path type of the found cycles /// /// The path type of the found cycles. - /// Using the \ref HartmannOrlinDefaultTraits "default traits class", + /// Using the \ref HartmannOrlinMmcDefaultTraits "default traits class", /// it is \ref lemon::Path "Path". typedef typename TR::Path Path; - /// The \ref HartmannOrlinDefaultTraits "traits class" of the algorithm + /// The \ref HartmannOrlinMmcDefaultTraits "traits class" of the algorithm typedef TR Traits; private: @@ -156,9 +156,9 @@ // Data sturcture for path data struct PathData { - LargeValue dist; + LargeCost dist; Arc pred; - PathData(LargeValue d, Arc p = INVALID) : + PathData(LargeCost d, Arc p = INVALID) : dist(d), pred(p) {} }; @@ -169,8 +169,8 @@ // The digraph the algorithm runs on const Digraph &_gr; - // The length of the arcs - const LengthMap &_length; + // The cost of the arcs + const CostMap &_cost; // Data for storing the strongly connected components int _comp_num; @@ -181,7 +181,7 @@ // Data for the found cycles bool _curr_found, _best_found; - LargeValue _curr_length, _best_length; + LargeCost _curr_cost, _best_cost; int _curr_size, _best_size; Node _curr_node, _best_node; int _curr_level, _best_level; @@ -197,7 +197,7 @@ Tolerance _tolerance; // Infinite constant - const LargeValue INF; + const LargeCost INF; public: @@ -205,20 +205,20 @@ /// @{ template - struct SetLargeValueTraits : public Traits { - typedef T LargeValue; + struct SetLargeCostTraits : public Traits { + typedef T LargeCost; typedef lemon::Tolerance Tolerance; }; /// \brief \ref named-templ-param "Named parameter" for setting - /// \c LargeValue type. + /// \c LargeCost type. /// - /// \ref named-templ-param "Named parameter" for setting \c LargeValue + /// \ref named-templ-param "Named parameter" for setting \c LargeCost /// type. It is used for internal computations in the algorithm. template - struct SetLargeValue - : public HartmannOrlin > { - typedef HartmannOrlin > Create; + struct SetLargeCost + : public HartmannOrlinMmc > { + typedef HartmannOrlinMmc > Create; }; template @@ -235,15 +235,15 @@ /// and it must have an \c addFront() function. template struct SetPath - : public HartmannOrlin > { - typedef HartmannOrlin > Create; + : public HartmannOrlinMmc > { + typedef HartmannOrlinMmc > Create; }; /// @} protected: - HartmannOrlin() {} + HartmannOrlinMmc() {} public: @@ -252,19 +252,19 @@ /// The constructor of the class. /// /// \param digraph The digraph the algorithm runs on. - /// \param length The lengths (costs) of the arcs. - HartmannOrlin( const Digraph &digraph, - const LengthMap &length ) : - _gr(digraph), _length(length), _comp(digraph), _out_arcs(digraph), - _best_found(false), _best_length(0), _best_size(1), + /// \param cost The costs of the arcs. + HartmannOrlinMmc( const Digraph &digraph, + const CostMap &cost ) : + _gr(digraph), _cost(cost), _comp(digraph), _out_arcs(digraph), + _best_found(false), _best_cost(0), _best_size(1), _cycle_path(NULL), _local_path(false), _data(digraph), - INF(std::numeric_limits::has_infinity ? - std::numeric_limits::infinity() : - std::numeric_limits::max()) + INF(std::numeric_limits::has_infinity ? + std::numeric_limits::infinity() : + std::numeric_limits::max()) {} /// Destructor. - ~HartmannOrlin() { + ~HartmannOrlinMmc() { if (_local_path) delete _cycle_path; } @@ -274,7 +274,7 @@ /// found cycle. /// /// If you don't call this function before calling \ref run() or - /// \ref findMinMean(), it will allocate a local \ref Path "path" + /// \ref findCycleMean(), it will allocate a local \ref Path "path" /// structure. The destuctor deallocates this automatically /// allocated object, of course. /// @@ -282,7 +282,7 @@ /// "addFront()" function of the given path structure. /// /// \return (*this) - HartmannOrlin& cycle(Path &path) { + HartmannOrlinMmc& cycle(Path &path) { if (_local_path) { delete _cycle_path; _local_path = false; @@ -296,7 +296,7 @@ /// This function sets the tolerance object used by the algorithm. /// /// \return (*this) - HartmannOrlin& tolerance(const Tolerance& tolerance) { + HartmannOrlinMmc& tolerance(const Tolerance& tolerance) { _tolerance = tolerance; return *this; } @@ -312,8 +312,8 @@ /// \name Execution control /// The simplest way to execute the algorithm is to call the \ref run() /// function.\n - /// If you only need the minimum mean length, you may call - /// \ref findMinMean(). + /// If you only need the minimum mean cost, you may call + /// \ref findCycleMean(). /// @{ @@ -321,25 +321,25 @@ /// /// This function runs the algorithm. /// It can be called more than once (e.g. if the underlying digraph - /// and/or the arc lengths have been modified). + /// and/or the arc costs have been modified). /// /// \return \c true if a directed cycle exists in the digraph. /// /// \note mmc.run() is just a shortcut of the following code. /// \code - /// return mmc.findMinMean() && mmc.findCycle(); + /// return mmc.findCycleMean() && mmc.findCycle(); /// \endcode bool run() { - return findMinMean() && findCycle(); + return findCycleMean() && findCycle(); } /// \brief Find the minimum cycle mean. /// - /// This function finds the minimum mean length of the directed + /// This function finds the minimum mean cost of the directed /// cycles in the digraph. /// /// \return \c true if a directed cycle exists in the digraph. - bool findMinMean() { + bool findCycleMean() { // Initialization and find strongly connected components init(); findComponents(); @@ -351,9 +351,9 @@ // Update the best cycle (global minimum mean cycle) if ( _curr_found && (!_best_found || - _curr_length * _best_size < _best_length * _curr_size) ) { + _curr_cost * _best_size < _best_cost * _curr_size) ) { _best_found = true; - _best_length = _curr_length; + _best_cost = _curr_cost; _best_size = _curr_size; _best_node = _curr_node; _best_level = _curr_level; @@ -364,12 +364,12 @@ /// \brief Find a minimum mean directed cycle. /// - /// This function finds a directed cycle of minimum mean length - /// in the digraph using the data computed by findMinMean(). + /// This function finds a directed cycle of minimum mean cost + /// in the digraph using the data computed by findCycleMean(). /// /// \return \c true if a directed cycle exists in the digraph. /// - /// \pre \ref findMinMean() must be called before using this function. + /// \pre \ref findCycleMean() must be called before using this function. bool findCycle() { if (!_best_found) return false; IntNodeMap reached(_gr, -1); @@ -382,13 +382,13 @@ r = reached[u]; Arc e = _data[u][r].pred; _cycle_path->addFront(e); - _best_length = _length[e]; + _best_cost = _cost[e]; _best_size = 1; Node v; while ((v = _gr.source(e)) != u) { e = _data[v][--r].pred; _cycle_path->addFront(e); - _best_length += _length[e]; + _best_cost += _cost[e]; ++_best_size; } return true; @@ -403,40 +403,40 @@ /// @{ - /// \brief Return the total length of the found cycle. + /// \brief Return the total cost of the found cycle. /// - /// This function returns the total length of the found cycle. + /// This function returns the total cost of the found cycle. /// - /// \pre \ref run() or \ref findMinMean() must be called before + /// \pre \ref run() or \ref findCycleMean() must be called before /// using this function. - Value cycleLength() const { - return static_cast(_best_length); + Cost cycleCost() const { + return static_cast(_best_cost); } /// \brief Return the number of arcs on the found cycle. /// /// This function returns the number of arcs on the found cycle. /// - /// \pre \ref run() or \ref findMinMean() must be called before + /// \pre \ref run() or \ref findCycleMean() must be called before /// using this function. - int cycleArcNum() const { + int cycleSize() const { return _best_size; } - /// \brief Return the mean length of the found cycle. + /// \brief Return the mean cost of the found cycle. /// - /// This function returns the mean length of the found cycle. + /// This function returns the mean cost of the found cycle. /// /// \note alg.cycleMean() is just a shortcut of the /// following code. /// \code - /// return static_cast(alg.cycleLength()) / alg.cycleArcNum(); + /// return static_cast(alg.cycleCost()) / alg.cycleSize(); /// \endcode /// - /// \pre \ref run() or \ref findMinMean() must be called before + /// \pre \ref run() or \ref findCycleMean() must be called before /// using this function. double cycleMean() const { - return static_cast(_best_length) / _best_size; + return static_cast(_best_cost) / _best_size; } /// \brief Return the found cycle. @@ -462,7 +462,7 @@ } _cycle_path->clear(); _best_found = false; - _best_length = 0; + _best_cost = 0; _best_size = 1; _cycle_path->clear(); for (NodeIt u(_gr); u != INVALID; ++u) @@ -511,7 +511,7 @@ } // Process all rounds of computing path data for the current component. - // _data[v][k] is the length of a shortest directed walk from the root + // _data[v][k] is the cost of a shortest directed walk from the root // node to node v containing exactly k arcs. void processRounds() { Node start = (*_nodes)[0]; @@ -543,13 +543,13 @@ std::vector next; Node u, v; Arc e; - LargeValue d; + LargeCost d; for (int i = 0; i < int(_process.size()); ++i) { u = _process[i]; for (int j = 0; j < int(_out_arcs[u].size()); ++j) { e = _out_arcs[u][j]; v = _gr.target(e); - d = _data[u][k-1].dist + _length[e]; + d = _data[u][k-1].dist + _cost[e]; if (_tolerance.less(d, _data[v][k].dist)) { if (_data[v][k].dist == INF) next.push_back(v); _data[v][k] = PathData(d, e); @@ -563,13 +563,13 @@ void processNextFullRound(int k) { Node u, v; Arc e; - LargeValue d; + LargeCost d; for (int i = 0; i < int(_nodes->size()); ++i) { u = (*_nodes)[i]; for (int j = 0; j < int(_out_arcs[u].size()); ++j) { e = _out_arcs[u][j]; v = _gr.target(e); - d = _data[u][k-1].dist + _length[e]; + d = _data[u][k-1].dist + _cost[e]; if (_tolerance.less(d, _data[v][k].dist)) { _data[v][k] = PathData(d, e); } @@ -581,9 +581,9 @@ bool checkTermination(int k) { typedef std::pair Pair; typename GR::template NodeMap level(_gr, Pair(-1, 0)); - typename GR::template NodeMap pi(_gr); + typename GR::template NodeMap pi(_gr); int n = _nodes->size(); - LargeValue length; + LargeCost cost; int size; Node u; @@ -595,10 +595,10 @@ for (int j = k; j >= 0; --j) { if (level[u].first == i && level[u].second > 0) { // A cycle is found - length = _data[u][level[u].second].dist - _data[u][j].dist; + cost = _data[u][level[u].second].dist - _data[u][j].dist; size = level[u].second - j; - if (!_curr_found || length * _curr_size < _curr_length * size) { - _curr_length = length; + if (!_curr_found || cost * _curr_size < _curr_cost * size) { + _curr_cost = cost; _curr_size = size; _curr_node = u; _curr_level = level[u].second; @@ -613,7 +613,7 @@ } // If at least one cycle is found, check the optimality condition - LargeValue d; + LargeCost d; if (_curr_found && k < n) { // Find node potentials for (int i = 0; i < n; ++i) { @@ -621,7 +621,7 @@ pi[u] = INF; for (int j = 0; j <= k; ++j) { if (_data[u][j].dist < INF) { - d = _data[u][j].dist * _curr_size - j * _curr_length; + d = _data[u][j].dist * _curr_size - j * _curr_cost; if (_tolerance.less(d, pi[u])) pi[u] = d; } } @@ -630,7 +630,7 @@ // Check the optimality condition for all arcs bool done = true; for (ArcIt a(_gr); a != INVALID; ++a) { - if (_tolerance.less(_length[a] * _curr_size - _curr_length, + if (_tolerance.less(_cost[a] * _curr_size - _curr_cost, pi[_gr.target(a)] - pi[_gr.source(a)]) ) { done = false; break; @@ -641,10 +641,10 @@ return (k == n); } - }; //class HartmannOrlin + }; //class HartmannOrlinMmc ///@} } //namespace lemon -#endif //LEMON_HARTMANN_ORLIN_H +#endif //LEMON_HARTMANN_ORLIN_MMC_H diff --git a/lemon/howard.h b/lemon/howard_mmc.h rename from lemon/howard.h rename to lemon/howard_mmc.h --- a/lemon/howard.h +++ b/lemon/howard_mmc.h @@ -16,8 +16,8 @@ * */ -#ifndef LEMON_HOWARD_H -#define LEMON_HOWARD_H +#ifndef LEMON_HOWARD_MMC_H +#define LEMON_HOWARD_MMC_H /// \ingroup min_mean_cycle /// @@ -33,37 +33,37 @@ namespace lemon { - /// \brief Default traits class of Howard class. + /// \brief Default traits class of HowardMmc class. /// - /// Default traits class of Howard class. + /// Default traits class of HowardMmc class. /// \tparam GR The type of the digraph. - /// \tparam LEN The type of the length map. + /// \tparam CM The type of the cost map. /// It must conform to the \ref concepts::ReadMap "ReadMap" concept. #ifdef DOXYGEN - template + template #else - template ::is_integer> + template ::is_integer> #endif - struct HowardDefaultTraits + struct HowardMmcDefaultTraits { /// The type of the digraph typedef GR Digraph; - /// The type of the length map - typedef LEN LengthMap; - /// The type of the arc lengths - typedef typename LengthMap::Value Value; + /// The type of the cost map + typedef CM CostMap; + /// The type of the arc costs + typedef typename CostMap::Value Cost; - /// \brief The large value type used for internal computations + /// \brief The large cost type used for internal computations /// - /// The large value type used for internal computations. - /// It is \c long \c long if the \c Value type is integer, + /// The large cost type used for internal computations. + /// It is \c long \c long if the \c Cost type is integer, /// otherwise it is \c double. - /// \c Value must be convertible to \c LargeValue. - typedef double LargeValue; + /// \c Cost must be convertible to \c LargeCost. + typedef double LargeCost; /// The tolerance type used for internal computations - typedef lemon::Tolerance Tolerance; + typedef lemon::Tolerance Tolerance; /// \brief The path type of the found cycles /// @@ -73,19 +73,19 @@ typedef lemon::Path Path; }; - // Default traits class for integer value types - template - struct HowardDefaultTraits + // Default traits class for integer cost types + template + struct HowardMmcDefaultTraits { typedef GR Digraph; - typedef LEN LengthMap; - typedef typename LengthMap::Value Value; + typedef CM CostMap; + typedef typename CostMap::Value Cost; #ifdef LEMON_HAVE_LONG_LONG - typedef long long LargeValue; + typedef long long LargeCost; #else - typedef long LargeValue; + typedef long LargeCost; #endif - typedef lemon::Tolerance Tolerance; + typedef lemon::Tolerance Tolerance; typedef lemon::Path Path; }; @@ -97,44 +97,44 @@ /// mean cycle. /// /// This class implements Howard's policy iteration algorithm for finding - /// a directed cycle of minimum mean length (cost) in a digraph + /// a directed cycle of minimum mean cost in a digraph /// \ref amo93networkflows, \ref dasdan98minmeancycle. /// This class provides the most efficient algorithm for the /// minimum mean cycle problem, though the best known theoretical /// bound on its running time is exponential. /// /// \tparam GR The type of the digraph the algorithm runs on. - /// \tparam LEN The type of the length map. The default + /// \tparam CM The type of the cost map. The default /// map type is \ref concepts::Digraph::ArcMap "GR::ArcMap". /// \tparam TR The traits class that defines various types used by the - /// algorithm. By default, it is \ref HowardDefaultTraits - /// "HowardDefaultTraits". + /// algorithm. By default, it is \ref HowardMmcDefaultTraits + /// "HowardMmcDefaultTraits". /// In most cases, this parameter should not be set directly, /// consider to use the named template parameters instead. #ifdef DOXYGEN - template + template #else template < typename GR, - typename LEN = typename GR::template ArcMap, - typename TR = HowardDefaultTraits > + typename CM = typename GR::template ArcMap, + typename TR = HowardMmcDefaultTraits > #endif - class Howard + class HowardMmc { public: /// The type of the digraph typedef typename TR::Digraph Digraph; - /// The type of the length map - typedef typename TR::LengthMap LengthMap; - /// The type of the arc lengths - typedef typename TR::Value Value; + /// The type of the cost map + typedef typename TR::CostMap CostMap; + /// The type of the arc costs + typedef typename TR::Cost Cost; - /// \brief The large value type + /// \brief The large cost type /// - /// The large value type used for internal computations. - /// By default, it is \c long \c long if the \c Value type is integer, + /// The large cost type used for internal computations. + /// By default, it is \c long \c long if the \c Cost type is integer, /// otherwise it is \c double. - typedef typename TR::LargeValue LargeValue; + typedef typename TR::LargeCost LargeCost; /// The tolerance type typedef typename TR::Tolerance Tolerance; @@ -142,11 +142,11 @@ /// \brief The path type of the found cycles /// /// The path type of the found cycles. - /// Using the \ref HowardDefaultTraits "default traits class", + /// Using the \ref HowardMmcDefaultTraits "default traits class", /// it is \ref lemon::Path "Path". typedef typename TR::Path Path; - /// The \ref HowardDefaultTraits "traits class" of the algorithm + /// The \ref HowardMmcDefaultTraits "traits class" of the algorithm typedef TR Traits; private: @@ -155,12 +155,12 @@ // The digraph the algorithm runs on const Digraph &_gr; - // The length of the arcs - const LengthMap &_length; + // The cost of the arcs + const CostMap &_cost; // Data for the found cycles bool _curr_found, _best_found; - LargeValue _curr_length, _best_length; + LargeCost _curr_cost, _best_cost; int _curr_size, _best_size; Node _curr_node, _best_node; @@ -171,7 +171,7 @@ typename Digraph::template NodeMap _policy; typename Digraph::template NodeMap _reached; typename Digraph::template NodeMap _level; - typename Digraph::template NodeMap _dist; + typename Digraph::template NodeMap _dist; // Data for storing the strongly connected components int _comp_num; @@ -187,7 +187,7 @@ Tolerance _tolerance; // Infinite constant - const LargeValue INF; + const LargeCost INF; public: @@ -195,20 +195,20 @@ /// @{ template - struct SetLargeValueTraits : public Traits { - typedef T LargeValue; + struct SetLargeCostTraits : public Traits { + typedef T LargeCost; typedef lemon::Tolerance Tolerance; }; /// \brief \ref named-templ-param "Named parameter" for setting - /// \c LargeValue type. + /// \c LargeCost type. /// - /// \ref named-templ-param "Named parameter" for setting \c LargeValue + /// \ref named-templ-param "Named parameter" for setting \c LargeCost /// type. It is used for internal computations in the algorithm. template - struct SetLargeValue - : public Howard > { - typedef Howard > Create; + struct SetLargeCost + : public HowardMmc > { + typedef HowardMmc > Create; }; template @@ -225,15 +225,15 @@ /// and it must have an \c addBack() function. template struct SetPath - : public Howard > { - typedef Howard > Create; + : public HowardMmc > { + typedef HowardMmc > Create; }; /// @} protected: - Howard() {} + HowardMmc() {} public: @@ -242,20 +242,20 @@ /// The constructor of the class. /// /// \param digraph The digraph the algorithm runs on. - /// \param length The lengths (costs) of the arcs. - Howard( const Digraph &digraph, - const LengthMap &length ) : - _gr(digraph), _length(length), _best_found(false), - _best_length(0), _best_size(1), _cycle_path(NULL), _local_path(false), + /// \param cost The costs of the arcs. + HowardMmc( const Digraph &digraph, + const CostMap &cost ) : + _gr(digraph), _cost(cost), _best_found(false), + _best_cost(0), _best_size(1), _cycle_path(NULL), _local_path(false), _policy(digraph), _reached(digraph), _level(digraph), _dist(digraph), _comp(digraph), _in_arcs(digraph), - INF(std::numeric_limits::has_infinity ? - std::numeric_limits::infinity() : - std::numeric_limits::max()) + INF(std::numeric_limits::has_infinity ? + std::numeric_limits::infinity() : + std::numeric_limits::max()) {} /// Destructor. - ~Howard() { + ~HowardMmc() { if (_local_path) delete _cycle_path; } @@ -265,7 +265,7 @@ /// found cycle. /// /// If you don't call this function before calling \ref run() or - /// \ref findMinMean(), it will allocate a local \ref Path "path" + /// \ref findCycleMean(), it will allocate a local \ref Path "path" /// structure. The destuctor deallocates this automatically /// allocated object, of course. /// @@ -273,7 +273,7 @@ /// "addBack()" function of the given path structure. /// /// \return (*this) - Howard& cycle(Path &path) { + HowardMmc& cycle(Path &path) { if (_local_path) { delete _cycle_path; _local_path = false; @@ -287,7 +287,7 @@ /// This function sets the tolerance object used by the algorithm. /// /// \return (*this) - Howard& tolerance(const Tolerance& tolerance) { + HowardMmc& tolerance(const Tolerance& tolerance) { _tolerance = tolerance; return *this; } @@ -303,8 +303,8 @@ /// \name Execution control /// The simplest way to execute the algorithm is to call the \ref run() /// function.\n - /// If you only need the minimum mean length, you may call - /// \ref findMinMean(). + /// If you only need the minimum mean cost, you may call + /// \ref findCycleMean(). /// @{ @@ -312,25 +312,25 @@ /// /// This function runs the algorithm. /// It can be called more than once (e.g. if the underlying digraph - /// and/or the arc lengths have been modified). + /// and/or the arc costs have been modified). /// /// \return \c true if a directed cycle exists in the digraph. /// /// \note mmc.run() is just a shortcut of the following code. /// \code - /// return mmc.findMinMean() && mmc.findCycle(); + /// return mmc.findCycleMean() && mmc.findCycle(); /// \endcode bool run() { - return findMinMean() && findCycle(); + return findCycleMean() && findCycle(); } /// \brief Find the minimum cycle mean. /// - /// This function finds the minimum mean length of the directed + /// This function finds the minimum mean cost of the directed /// cycles in the digraph. /// /// \return \c true if a directed cycle exists in the digraph. - bool findMinMean() { + bool findCycleMean() { // Initialize and find strongly connected components init(); findComponents(); @@ -345,9 +345,9 @@ } // Update the best cycle (global minimum mean cycle) if ( _curr_found && (!_best_found || - _curr_length * _best_size < _best_length * _curr_size) ) { + _curr_cost * _best_size < _best_cost * _curr_size) ) { _best_found = true; - _best_length = _curr_length; + _best_cost = _curr_cost; _best_size = _curr_size; _best_node = _curr_node; } @@ -357,12 +357,12 @@ /// \brief Find a minimum mean directed cycle. /// - /// This function finds a directed cycle of minimum mean length - /// in the digraph using the data computed by findMinMean(). + /// This function finds a directed cycle of minimum mean cost + /// in the digraph using the data computed by findCycleMean(). /// /// \return \c true if a directed cycle exists in the digraph. /// - /// \pre \ref findMinMean() must be called before using this function. + /// \pre \ref findCycleMean() must be called before using this function. bool findCycle() { if (!_best_found) return false; _cycle_path->addBack(_policy[_best_node]); @@ -382,40 +382,40 @@ /// @{ - /// \brief Return the total length of the found cycle. + /// \brief Return the total cost of the found cycle. /// - /// This function returns the total length of the found cycle. + /// This function returns the total cost of the found cycle. /// - /// \pre \ref run() or \ref findMinMean() must be called before + /// \pre \ref run() or \ref findCycleMean() must be called before /// using this function. - Value cycleLength() const { - return static_cast(_best_length); + Cost cycleCost() const { + return static_cast(_best_cost); } /// \brief Return the number of arcs on the found cycle. /// /// This function returns the number of arcs on the found cycle. /// - /// \pre \ref run() or \ref findMinMean() must be called before + /// \pre \ref run() or \ref findCycleMean() must be called before /// using this function. - int cycleArcNum() const { + int cycleSize() const { return _best_size; } - /// \brief Return the mean length of the found cycle. + /// \brief Return the mean cost of the found cycle. /// - /// This function returns the mean length of the found cycle. + /// This function returns the mean cost of the found cycle. /// /// \note alg.cycleMean() is just a shortcut of the /// following code. /// \code - /// return static_cast(alg.cycleLength()) / alg.cycleArcNum(); + /// return static_cast(alg.cycleCost()) / alg.cycleSize(); /// \endcode /// - /// \pre \ref run() or \ref findMinMean() must be called before + /// \pre \ref run() or \ref findCycleMean() must be called before /// using this function. double cycleMean() const { - return static_cast(_best_length) / _best_size; + return static_cast(_best_cost) / _best_size; } /// \brief Return the found cycle. @@ -441,7 +441,7 @@ } _queue.resize(countNodes(_gr)); _best_found = false; - _best_length = 0; + _best_cost = 0; _best_size = 1; _cycle_path->clear(); } @@ -492,8 +492,8 @@ for (int j = 0; j < int(_in_arcs[v].size()); ++j) { e = _in_arcs[v][j]; u = _gr.source(e); - if (_length[e] < _dist[u]) { - _dist[u] = _length[e]; + if (_cost[e] < _dist[u]) { + _dist[u] = _cost[e]; _policy[u] = e; } } @@ -506,7 +506,7 @@ for (int i = 0; i < int(_nodes->size()); ++i) { _level[(*_nodes)[i]] = -1; } - LargeValue clength; + LargeCost ccost; int csize; Node u, v; _curr_found = false; @@ -518,16 +518,16 @@ } if (_level[u] == i) { // A cycle is found - clength = _length[_policy[u]]; + ccost = _cost[_policy[u]]; csize = 1; for (v = u; (v = _gr.target(_policy[v])) != u; ) { - clength += _length[_policy[v]]; + ccost += _cost[_policy[v]]; ++csize; } if ( !_curr_found || - (clength * _curr_size < _curr_length * csize) ) { + (ccost * _curr_size < _curr_cost * csize) ) { _curr_found = true; - _curr_length = clength; + _curr_cost = ccost; _curr_size = csize; _curr_node = u; } @@ -555,7 +555,7 @@ u = _gr.source(e); if (_policy[u] == e && !_reached[u]) { _reached[u] = true; - _dist[u] = _dist[v] + _length[e] * _curr_size - _curr_length; + _dist[u] = _dist[v] + _cost[e] * _curr_size - _curr_cost; _queue[++_qback] = u; } } @@ -572,7 +572,7 @@ if (!_reached[u]) { _reached[u] = true; _policy[u] = e; - _dist[u] = _dist[v] + _length[e] * _curr_size - _curr_length; + _dist[u] = _dist[v] + _cost[e] * _curr_size - _curr_cost; _queue[++_qback] = u; } } @@ -585,7 +585,7 @@ for (int j = 0; j < int(_in_arcs[v].size()); ++j) { e = _in_arcs[v][j]; u = _gr.source(e); - LargeValue delta = _dist[v] + _length[e] * _curr_size - _curr_length; + LargeCost delta = _dist[v] + _cost[e] * _curr_size - _curr_cost; if (_tolerance.less(delta, _dist[u])) { _dist[u] = delta; _policy[u] = e; @@ -596,10 +596,10 @@ return improved; } - }; //class Howard + }; //class HowardMmc ///@} } //namespace lemon -#endif //LEMON_HOWARD_H +#endif //LEMON_HOWARD_MMC_H diff --git a/lemon/karp.h b/lemon/karp_mmc.h rename from lemon/karp.h rename to lemon/karp_mmc.h --- a/lemon/karp.h +++ b/lemon/karp_mmc.h @@ -16,8 +16,8 @@ * */ -#ifndef LEMON_KARP_H -#define LEMON_KARP_H +#ifndef LEMON_KARP_MMC_H +#define LEMON_KARP_MMC_H /// \ingroup min_mean_cycle /// @@ -33,37 +33,37 @@ namespace lemon { - /// \brief Default traits class of Karp algorithm. + /// \brief Default traits class of KarpMmc class. /// - /// Default traits class of Karp algorithm. + /// Default traits class of KarpMmc class. /// \tparam GR The type of the digraph. - /// \tparam LEN The type of the length map. + /// \tparam CM The type of the cost map. /// It must conform to the \ref concepts::ReadMap "ReadMap" concept. #ifdef DOXYGEN - template + template #else - template ::is_integer> + template ::is_integer> #endif - struct KarpDefaultTraits + struct KarpMmcDefaultTraits { /// The type of the digraph typedef GR Digraph; - /// The type of the length map - typedef LEN LengthMap; - /// The type of the arc lengths - typedef typename LengthMap::Value Value; + /// The type of the cost map + typedef CM CostMap; + /// The type of the arc costs + typedef typename CostMap::Value Cost; - /// \brief The large value type used for internal computations + /// \brief The large cost type used for internal computations /// - /// The large value type used for internal computations. - /// It is \c long \c long if the \c Value type is integer, + /// The large cost type used for internal computations. + /// It is \c long \c long if the \c Cost type is integer, /// otherwise it is \c double. - /// \c Value must be convertible to \c LargeValue. - typedef double LargeValue; + /// \c Cost must be convertible to \c LargeCost. + typedef double LargeCost; /// The tolerance type used for internal computations - typedef lemon::Tolerance Tolerance; + typedef lemon::Tolerance Tolerance; /// \brief The path type of the found cycles /// @@ -73,19 +73,19 @@ typedef lemon::Path Path; }; - // Default traits class for integer value types - template - struct KarpDefaultTraits + // Default traits class for integer cost types + template + struct KarpMmcDefaultTraits { typedef GR Digraph; - typedef LEN LengthMap; - typedef typename LengthMap::Value Value; + typedef CM CostMap; + typedef typename CostMap::Value Cost; #ifdef LEMON_HAVE_LONG_LONG - typedef long long LargeValue; + typedef long long LargeCost; #else - typedef long LargeValue; + typedef long LargeCost; #endif - typedef lemon::Tolerance Tolerance; + typedef lemon::Tolerance Tolerance; typedef lemon::Path Path; }; @@ -97,42 +97,42 @@ /// mean cycle. /// /// This class implements Karp's algorithm for finding a directed - /// cycle of minimum mean length (cost) in a digraph + /// cycle of minimum mean cost in a digraph /// \ref amo93networkflows, \ref dasdan98minmeancycle. /// It runs in time O(ne) and uses space O(n2+e). /// /// \tparam GR The type of the digraph the algorithm runs on. - /// \tparam LEN The type of the length map. The default + /// \tparam CM The type of the cost map. The default /// map type is \ref concepts::Digraph::ArcMap "GR::ArcMap". /// \tparam TR The traits class that defines various types used by the - /// algorithm. By default, it is \ref KarpDefaultTraits - /// "KarpDefaultTraits". + /// algorithm. By default, it is \ref KarpMmcDefaultTraits + /// "KarpMmcDefaultTraits". /// In most cases, this parameter should not be set directly, /// consider to use the named template parameters instead. #ifdef DOXYGEN - template + template #else template < typename GR, - typename LEN = typename GR::template ArcMap, - typename TR = KarpDefaultTraits > + typename CM = typename GR::template ArcMap, + typename TR = KarpMmcDefaultTraits > #endif - class Karp + class KarpMmc { public: /// The type of the digraph typedef typename TR::Digraph Digraph; - /// The type of the length map - typedef typename TR::LengthMap LengthMap; - /// The type of the arc lengths - typedef typename TR::Value Value; + /// The type of the cost map + typedef typename TR::CostMap CostMap; + /// The type of the arc costs + typedef typename TR::Cost Cost; - /// \brief The large value type + /// \brief The large cost type /// - /// The large value type used for internal computations. - /// By default, it is \c long \c long if the \c Value type is integer, + /// The large cost type used for internal computations. + /// By default, it is \c long \c long if the \c Cost type is integer, /// otherwise it is \c double. - typedef typename TR::LargeValue LargeValue; + typedef typename TR::LargeCost LargeCost; /// The tolerance type typedef typename TR::Tolerance Tolerance; @@ -140,11 +140,11 @@ /// \brief The path type of the found cycles /// /// The path type of the found cycles. - /// Using the \ref KarpDefaultTraits "default traits class", + /// Using the \ref KarpMmcDefaultTraits "default traits class", /// it is \ref lemon::Path "Path". typedef typename TR::Path Path; - /// The \ref KarpDefaultTraits "traits class" of the algorithm + /// The \ref KarpMmcDefaultTraits "traits class" of the algorithm typedef TR Traits; private: @@ -154,9 +154,9 @@ // Data sturcture for path data struct PathData { - LargeValue dist; + LargeCost dist; Arc pred; - PathData(LargeValue d, Arc p = INVALID) : + PathData(LargeCost d, Arc p = INVALID) : dist(d), pred(p) {} }; @@ -167,8 +167,8 @@ // The digraph the algorithm runs on const Digraph &_gr; - // The length of the arcs - const LengthMap &_length; + // The cost of the arcs + const CostMap &_cost; // Data for storing the strongly connected components int _comp_num; @@ -178,7 +178,7 @@ typename Digraph::template NodeMap > _out_arcs; // Data for the found cycle - LargeValue _cycle_length; + LargeCost _cycle_cost; int _cycle_size; Node _cycle_node; @@ -193,7 +193,7 @@ Tolerance _tolerance; // Infinite constant - const LargeValue INF; + const LargeCost INF; public: @@ -201,20 +201,20 @@ /// @{ template - struct SetLargeValueTraits : public Traits { - typedef T LargeValue; + struct SetLargeCostTraits : public Traits { + typedef T LargeCost; typedef lemon::Tolerance Tolerance; }; /// \brief \ref named-templ-param "Named parameter" for setting - /// \c LargeValue type. + /// \c LargeCost type. /// - /// \ref named-templ-param "Named parameter" for setting \c LargeValue + /// \ref named-templ-param "Named parameter" for setting \c LargeCost /// type. It is used for internal computations in the algorithm. template - struct SetLargeValue - : public Karp > { - typedef Karp > Create; + struct SetLargeCost + : public KarpMmc > { + typedef KarpMmc > Create; }; template @@ -231,15 +231,15 @@ /// and it must have an \c addFront() function. template struct SetPath - : public Karp > { - typedef Karp > Create; + : public KarpMmc > { + typedef KarpMmc > Create; }; /// @} protected: - Karp() {} + KarpMmc() {} public: @@ -248,19 +248,19 @@ /// The constructor of the class. /// /// \param digraph The digraph the algorithm runs on. - /// \param length The lengths (costs) of the arcs. - Karp( const Digraph &digraph, - const LengthMap &length ) : - _gr(digraph), _length(length), _comp(digraph), _out_arcs(digraph), - _cycle_length(0), _cycle_size(1), _cycle_node(INVALID), + /// \param cost The costs of the arcs. + KarpMmc( const Digraph &digraph, + const CostMap &cost ) : + _gr(digraph), _cost(cost), _comp(digraph), _out_arcs(digraph), + _cycle_cost(0), _cycle_size(1), _cycle_node(INVALID), _cycle_path(NULL), _local_path(false), _data(digraph), - INF(std::numeric_limits::has_infinity ? - std::numeric_limits::infinity() : - std::numeric_limits::max()) + INF(std::numeric_limits::has_infinity ? + std::numeric_limits::infinity() : + std::numeric_limits::max()) {} /// Destructor. - ~Karp() { + ~KarpMmc() { if (_local_path) delete _cycle_path; } @@ -270,7 +270,7 @@ /// found cycle. /// /// If you don't call this function before calling \ref run() or - /// \ref findMinMean(), it will allocate a local \ref Path "path" + /// \ref findCycleMean(), it will allocate a local \ref Path "path" /// structure. The destuctor deallocates this automatically /// allocated object, of course. /// @@ -278,7 +278,7 @@ /// "addFront()" function of the given path structure. /// /// \return (*this) - Karp& cycle(Path &path) { + KarpMmc& cycle(Path &path) { if (_local_path) { delete _cycle_path; _local_path = false; @@ -292,7 +292,7 @@ /// This function sets the tolerance object used by the algorithm. /// /// \return (*this) - Karp& tolerance(const Tolerance& tolerance) { + KarpMmc& tolerance(const Tolerance& tolerance) { _tolerance = tolerance; return *this; } @@ -308,8 +308,8 @@ /// \name Execution control /// The simplest way to execute the algorithm is to call the \ref run() /// function.\n - /// If you only need the minimum mean length, you may call - /// \ref findMinMean(). + /// If you only need the minimum mean cost, you may call + /// \ref findCycleMean(). /// @{ @@ -317,25 +317,25 @@ /// /// This function runs the algorithm. /// It can be called more than once (e.g. if the underlying digraph - /// and/or the arc lengths have been modified). + /// and/or the arc costs have been modified). /// /// \return \c true if a directed cycle exists in the digraph. /// /// \note mmc.run() is just a shortcut of the following code. /// \code - /// return mmc.findMinMean() && mmc.findCycle(); + /// return mmc.findCycleMean() && mmc.findCycle(); /// \endcode bool run() { - return findMinMean() && findCycle(); + return findCycleMean() && findCycle(); } /// \brief Find the minimum cycle mean. /// - /// This function finds the minimum mean length of the directed + /// This function finds the minimum mean cost of the directed /// cycles in the digraph. /// /// \return \c true if a directed cycle exists in the digraph. - bool findMinMean() { + bool findCycleMean() { // Initialization and find strongly connected components init(); findComponents(); @@ -351,12 +351,12 @@ /// \brief Find a minimum mean directed cycle. /// - /// This function finds a directed cycle of minimum mean length - /// in the digraph using the data computed by findMinMean(). + /// This function finds a directed cycle of minimum mean cost + /// in the digraph using the data computed by findCycleMean(). /// /// \return \c true if a directed cycle exists in the digraph. /// - /// \pre \ref findMinMean() must be called before using this function. + /// \pre \ref findCycleMean() must be called before using this function. bool findCycle() { if (_cycle_node == INVALID) return false; IntNodeMap reached(_gr, -1); @@ -369,13 +369,13 @@ r = reached[u]; Arc e = _data[u][r].pred; _cycle_path->addFront(e); - _cycle_length = _length[e]; + _cycle_cost = _cost[e]; _cycle_size = 1; Node v; while ((v = _gr.source(e)) != u) { e = _data[v][--r].pred; _cycle_path->addFront(e); - _cycle_length += _length[e]; + _cycle_cost += _cost[e]; ++_cycle_size; } return true; @@ -390,40 +390,40 @@ /// @{ - /// \brief Return the total length of the found cycle. + /// \brief Return the total cost of the found cycle. /// - /// This function returns the total length of the found cycle. + /// This function returns the total cost of the found cycle. /// - /// \pre \ref run() or \ref findMinMean() must be called before + /// \pre \ref run() or \ref findCycleMean() must be called before /// using this function. - Value cycleLength() const { - return static_cast(_cycle_length); + Cost cycleCost() const { + return static_cast(_cycle_cost); } /// \brief Return the number of arcs on the found cycle. /// /// This function returns the number of arcs on the found cycle. /// - /// \pre \ref run() or \ref findMinMean() must be called before + /// \pre \ref run() or \ref findCycleMean() must be called before /// using this function. - int cycleArcNum() const { + int cycleSize() const { return _cycle_size; } - /// \brief Return the mean length of the found cycle. + /// \brief Return the mean cost of the found cycle. /// - /// This function returns the mean length of the found cycle. + /// This function returns the mean cost of the found cycle. /// /// \note alg.cycleMean() is just a shortcut of the /// following code. /// \code - /// return static_cast(alg.cycleLength()) / alg.cycleArcNum(); + /// return static_cast(alg.cycleCost()) / alg.cycleSize(); /// \endcode /// - /// \pre \ref run() or \ref findMinMean() must be called before + /// \pre \ref run() or \ref findCycleMean() must be called before /// using this function. double cycleMean() const { - return static_cast(_cycle_length) / _cycle_size; + return static_cast(_cycle_cost) / _cycle_size; } /// \brief Return the found cycle. @@ -448,7 +448,7 @@ _cycle_path = new Path; } _cycle_path->clear(); - _cycle_length = 0; + _cycle_cost = 0; _cycle_size = 1; _cycle_node = INVALID; for (NodeIt u(_gr); u != INVALID; ++u) @@ -497,7 +497,7 @@ } // Process all rounds of computing path data for the current component. - // _data[v][k] is the length of a shortest directed walk from the root + // _data[v][k] is the cost of a shortest directed walk from the root // node to node v containing exactly k arcs. void processRounds() { Node start = (*_nodes)[0]; @@ -519,13 +519,13 @@ std::vector next; Node u, v; Arc e; - LargeValue d; + LargeCost d; for (int i = 0; i < int(_process.size()); ++i) { u = _process[i]; for (int j = 0; j < int(_out_arcs[u].size()); ++j) { e = _out_arcs[u][j]; v = _gr.target(e); - d = _data[u][k-1].dist + _length[e]; + d = _data[u][k-1].dist + _cost[e]; if (_tolerance.less(d, _data[v][k].dist)) { if (_data[v][k].dist == INF) next.push_back(v); _data[v][k] = PathData(d, e); @@ -539,13 +539,13 @@ void processNextFullRound(int k) { Node u, v; Arc e; - LargeValue d; + LargeCost d; for (int i = 0; i < int(_nodes->size()); ++i) { u = (*_nodes)[i]; for (int j = 0; j < int(_out_arcs[u].size()); ++j) { e = _out_arcs[u][j]; v = _gr.target(e); - d = _data[u][k-1].dist + _length[e]; + d = _data[u][k-1].dist + _cost[e]; if (_tolerance.less(d, _data[v][k].dist)) { _data[v][k] = PathData(d, e); } @@ -559,32 +559,32 @@ for (int i = 0; i < n; ++i) { Node u = (*_nodes)[i]; if (_data[u][n].dist == INF) continue; - LargeValue length, max_length = 0; + LargeCost cost, max_cost = 0; int size, max_size = 1; bool found_curr = false; for (int k = 0; k < n; ++k) { if (_data[u][k].dist == INF) continue; - length = _data[u][n].dist - _data[u][k].dist; + cost = _data[u][n].dist - _data[u][k].dist; size = n - k; - if (!found_curr || length * max_size > max_length * size) { + if (!found_curr || cost * max_size > max_cost * size) { found_curr = true; - max_length = length; + max_cost = cost; max_size = size; } } if ( found_curr && (_cycle_node == INVALID || - max_length * _cycle_size < _cycle_length * max_size) ) { - _cycle_length = max_length; + max_cost * _cycle_size < _cycle_cost * max_size) ) { + _cycle_cost = max_cost; _cycle_size = max_size; _cycle_node = u; } } } - }; //class Karp + }; //class KarpMmc ///@} } //namespace lemon -#endif //LEMON_KARP_H +#endif //LEMON_KARP_MMC_H diff --git a/test/min_mean_cycle_test.cc b/test/min_mean_cycle_test.cc --- a/test/min_mean_cycle_test.cc +++ b/test/min_mean_cycle_test.cc @@ -25,9 +25,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include "test_tools.h" @@ -63,7 +63,7 @@ // Check the interface of an MMC algorithm -template +template struct MmcClassConcept { template @@ -73,30 +73,30 @@ typedef typename MMC ::template SetPath > - ::template SetLargeValue + ::template SetLargeCost ::Create MmcAlg; - MmcAlg mmc(me.g, me.length); + MmcAlg mmc(me.g, me.cost); const MmcAlg& const_mmc = mmc; typename MmcAlg::Tolerance tol = const_mmc.tolerance(); mmc.tolerance(tol); b = mmc.cycle(p).run(); - b = mmc.findMinMean(); + b = mmc.findCycleMean(); b = mmc.findCycle(); - v = const_mmc.cycleLength(); - i = const_mmc.cycleArcNum(); + v = const_mmc.cycleCost(); + i = const_mmc.cycleSize(); d = const_mmc.cycleMean(); p = const_mmc.cycle(); } - typedef concepts::ReadMap LM; + typedef concepts::ReadMap CM; GR g; - LM length; + CM cost; ListPath p; - Value v; + Cost v; int i; double d; bool b; @@ -108,13 +108,13 @@ void checkMmcAlg(const SmartDigraph& gr, const SmartDigraph::ArcMap& lm, const SmartDigraph::ArcMap& cm, - int length, int size) { + int cost, int size) { MMC alg(gr, lm); - alg.findMinMean(); - check(alg.cycleMean() == static_cast(length) / size, + alg.findCycleMean(); + check(alg.cycleMean() == static_cast(cost) / size, "Wrong cycle mean"); alg.findCycle(); - check(alg.cycleLength() == length && alg.cycleArcNum() == size, + check(alg.cycleCost() == cost && alg.cycleSize() == size, "Wrong path"); SmartDigraph::ArcMap cycle(gr, 0); for (typename MMC::Path::ArcIt a(alg.cycle()); a != INVALID; ++a) { @@ -148,28 +148,28 @@ { typedef concepts::Digraph GR; - // Karp + // KarpMmc checkConcept< MmcClassConcept, - Karp > >(); + KarpMmc > >(); checkConcept< MmcClassConcept, - Karp > >(); + KarpMmc > >(); - // HartmannOrlin + // HartmannOrlinMmc checkConcept< MmcClassConcept, - HartmannOrlin > >(); + HartmannOrlinMmc > >(); checkConcept< MmcClassConcept, - HartmannOrlin > >(); + HartmannOrlinMmc > >(); - // Howard + // HowardMmc checkConcept< MmcClassConcept, - Howard > >(); + HowardMmc > >(); checkConcept< MmcClassConcept, - Howard > >(); + HowardMmc > >(); - if (IsSameType >::LargeValue, - long_int>::result == 0) check(false, "Wrong LargeValue type"); - if (IsSameType >::LargeValue, - double>::result == 0) check(false, "Wrong LargeValue type"); + check((IsSameType > + ::LargeCost, long_int>::result == 1), "Wrong LargeCost type"); + check((IsSameType > + ::LargeCost, double>::result == 1), "Wrong LargeCost type"); } // Run various tests @@ -194,22 +194,22 @@ run(); // Karp - checkMmcAlg >(gr, l1, c1, 6, 3); - checkMmcAlg >(gr, l2, c2, 5, 2); - checkMmcAlg >(gr, l3, c3, 0, 1); - checkMmcAlg >(gr, l4, c4, -1, 1); + checkMmcAlg >(gr, l1, c1, 6, 3); + checkMmcAlg >(gr, l2, c2, 5, 2); + checkMmcAlg >(gr, l3, c3, 0, 1); + checkMmcAlg >(gr, l4, c4, -1, 1); // HartmannOrlin - checkMmcAlg >(gr, l1, c1, 6, 3); - checkMmcAlg >(gr, l2, c2, 5, 2); - checkMmcAlg >(gr, l3, c3, 0, 1); - checkMmcAlg >(gr, l4, c4, -1, 1); + checkMmcAlg >(gr, l1, c1, 6, 3); + checkMmcAlg >(gr, l2, c2, 5, 2); + checkMmcAlg >(gr, l3, c3, 0, 1); + checkMmcAlg >(gr, l4, c4, -1, 1); // Howard - checkMmcAlg >(gr, l1, c1, 6, 3); - checkMmcAlg >(gr, l2, c2, 5, 2); - checkMmcAlg >(gr, l3, c3, 0, 1); - checkMmcAlg >(gr, l4, c4, -1, 1); + checkMmcAlg >(gr, l1, c1, 6, 3); + checkMmcAlg >(gr, l2, c2, 5, 2); + checkMmcAlg >(gr, l3, c3, 0, 1); + checkMmcAlg >(gr, l4, c4, -1, 1); } return 0;