diff -r c86db0f7f917 -r a8081c9cd96a lemon/capacity_scaling.h --- a/lemon/capacity_scaling.h Thu Nov 08 14:21:28 2007 +0000 +++ b/lemon/capacity_scaling.h Wed Nov 14 06:28:08 2007 +0000 @@ -26,8 +26,8 @@ /// flow. #include +#include #include -#include #define WITH_SCALING @@ -43,10 +43,12 @@ /// @{ /// \brief Implementation of the capacity scaling version of the - /// successive shortest path algorithm for finding a minimum cost flow. + /// successive shortest path algorithm for finding a minimum cost + /// flow. /// - /// \ref lemon::CapacityScaling "CapacityScaling" implements a - /// capacity scaling algorithm for finding a minimum cost flow. + /// \ref lemon::CapacityScaling "CapacityScaling" implements the + /// capacity scaling version of the successive shortest path + /// algorithm for finding a minimum cost flow. /// /// \param Graph The directed graph type the algorithm runs on. /// \param LowerMap The type of the lower bound map. @@ -57,7 +59,7 @@ /// \warning /// - Edge capacities and costs should be nonnegative integers. /// However \c CostMap::Value should be signed type. - /// - Supply values should be integers. + /// - Supply values should be signed integers. /// - \c LowerMap::Value must be convertible to /// \c CapacityMap::Value and \c CapacityMap::Value must be /// convertible to \c SupplyMap::Value. @@ -113,15 +115,12 @@ public: - typedef typename MapBase::Value Value; - typedef typename MapBase::Key Key; - ReducedCostMap( const ResGraph &_gr, const CostMap &_cost, const PotentialMap &_pot ) : gr(_gr), cost_map(_cost), pot_map(_pot) {} - Value operator[](const Key &e) const { + Cost operator[](const ResEdge &e) const { return ResGraph::forward(e) ? cost_map[e] - pot_map[gr.source(e)] + pot_map[gr.target(e)] : -cost_map[e] - pot_map[gr.source(e)] + pot_map[gr.target(e)]; @@ -129,8 +128,8 @@ }; //class ReducedCostMap - /// \brief Map adaptor for \ref lemon::Dijkstra "Dijkstra" class to - /// update node potentials. + /// \brief Map class for the \ref lemon::Dijkstra "Dijkstra" + /// algorithm to update node potentials. class PotentialUpdateMap : public MapBase { private: @@ -141,9 +140,6 @@ public: - typedef typename MapBase::Value Value; - typedef typename MapBase::Key Key; - void potentialMap(PotentialMap &_pot) { pot = &_pot; } @@ -152,7 +148,7 @@ data.clear(); } - void set(const Key &n, const Value &v) { + void set(const ResNode &n, const Cost &v) { data.push_back(Pair(n, v)); } @@ -185,7 +181,7 @@ }; //class DeficitBoolMap /// \brief Map adaptor class for filtering edges with at least - /// \c delta residual capacity + /// \c delta residual capacity. class DeltaFilterMap : public MapBase { private: @@ -195,13 +191,10 @@ public: - typedef typename MapBase::Value Value; - typedef typename MapBase::Key Key; - DeltaFilterMap(const ResGraph &_gr, const Capacity &_delta) : gr(_gr), delta(_delta) {} - Value operator[](const Key &e) const { + bool operator[](const ResEdge &e) const { return gr.rescap(e) >= delta; } @@ -298,9 +291,12 @@ /// \brief The delta parameter used for capacity scaling. Capacity delta; - /// \brief Edge filter map. + /// \brief Edge filter map for filtering edges with at least + /// \c delta residual capacity. DeltaFilterMap delta_filter; - /// \brief The delta residual graph. + /// \brief The delta residual graph (i.e. the subgraph of the + /// residual graph consisting of edges with at least \c delta + /// residual capacity). DeltaResGraph dres_graph; /// \brief Map for identifing deficit nodes. DeficitBoolMap delta_deficit; @@ -573,8 +569,8 @@ for (DeltaResEdgeIt e(dres_graph); e != INVALID; ++e) { if (red_cost[e] < 0) { res_graph.augment(e, r = res_graph.rescap(e)); + imbalance[dres_graph.source(e)] -= r; imbalance[dres_graph.target(e)] += r; - imbalance[dres_graph.source(e)] -= r; } }