lemon/min_cost_max_flow.h
changeset 2624 dc4dd5fc0e25
parent 2587 061be2e64eca
equal deleted inserted replaced
9:96705287a028 10:acd4d5cb7fca
    56   /// - Edge capacities and costs should be \e non-negative \e integers.
    56   /// - Edge capacities and costs should be \e non-negative \e integers.
    57   /// - \c CapacityMap::Value must be convertible to \c CostMap::Value.
    57   /// - \c CapacityMap::Value must be convertible to \c CostMap::Value.
    58   /// - \c CostMap::Value must be signed type.
    58   /// - \c CostMap::Value must be signed type.
    59   ///
    59   ///
    60   /// \author Peter Kovacs
    60   /// \author Peter Kovacs
    61 
       
    62   template < typename Graph,
    61   template < typename Graph,
    63              typename CapacityMap = typename Graph::template EdgeMap<int>,
    62              typename CapacityMap = typename Graph::template EdgeMap<int>,
    64              typename CostMap = typename Graph::template EdgeMap<int> >
    63              typename CostMap = typename Graph::template EdgeMap<int> >
    65   class MinCostMaxFlow
    64   class MinCostMaxFlow
    66   {
    65   {
   125     ~MinCostMaxFlow() {
   124     ~MinCostMaxFlow() {
   126       if (_local_flow) delete _flow;
   125       if (_local_flow) delete _flow;
   127       if (_local_potential) delete _potential;
   126       if (_local_potential) delete _potential;
   128     }
   127     }
   129 
   128 
   130     /// \brief Sets the flow map.
   129     /// \brief Set the flow map.
   131     ///
   130     ///
   132     /// Sets the flow map.
   131     /// Set the flow map.
   133     ///
   132     ///
   134     /// \return \c (*this)
   133     /// \return \c (*this)
   135     MinCostMaxFlow& flowMap(FlowMap &map) {
   134     MinCostMaxFlow& flowMap(FlowMap &map) {
   136       if (_local_flow) {
   135       if (_local_flow) {
   137         delete _flow;
   136         delete _flow;
   139       }
   138       }
   140       _flow = &map;
   139       _flow = &map;
   141       return *this;
   140       return *this;
   142     }
   141     }
   143 
   142 
   144     /// \brief Sets the potential map.
   143     /// \brief Set the potential map.
   145     ///
   144     ///
   146     /// Sets the potential map.
   145     /// Set the potential map.
   147     ///
   146     ///
   148     /// \return \c (*this)
   147     /// \return \c (*this)
   149     MinCostMaxFlow& potentialMap(PotentialMap &map) {
   148     MinCostMaxFlow& potentialMap(PotentialMap &map) {
   150       if (_local_potential) {
   149       if (_local_potential) {
   151         delete _potential;
   150         delete _potential;
   154       _potential = &map;
   153       _potential = &map;
   155       return *this;
   154       return *this;
   156     }
   155     }
   157 
   156 
   158     /// \name Execution control
   157     /// \name Execution control
   159     /// The only way to execute the algorithm is to call the run()
       
   160     /// function.
       
   161 
   158 
   162     /// @{
   159     /// @{
   163 
   160 
   164     /// \brief Runs the algorithm.
   161     /// \brief Run the algorithm.
   165     ///
   162     ///
   166     /// Runs the algorithm.
   163     /// Run the algorithm.
   167     void run() {
   164     void run() {
   168       // Initializing maps
   165       // Initializing maps
   169       if (!_flow) {
   166       if (!_flow) {
   170         _flow = new FlowMap(_graph);
   167         _flow = new FlowMap(_graph);
   171         _local_flow = true;
   168         _local_flow = true;
   184     }
   181     }
   185 
   182 
   186     /// @}
   183     /// @}
   187 
   184 
   188     /// \name Query Functions
   185     /// \name Query Functions
   189     /// The result of the algorithm can be obtained using these
   186     /// The results of the algorithm can be obtained using these
   190     /// functions.
   187     /// functions.\n
   191     /// \n run() must be called before using them.
   188     /// \ref lemon::MinCostMaxFlow::run() "run()" must be called before
       
   189     /// using them.
   192 
   190 
   193     /// @{
   191     /// @{
   194 
   192 
   195     /// \brief Returns a const reference to the edge map storing the
   193     /// \brief Return a const reference to the edge map storing the
   196     /// found flow.
   194     /// found flow.
   197     ///
   195     ///
   198     /// Returns a const reference to the edge map storing the found flow.
   196     /// Return a const reference to the edge map storing the found flow.
   199     ///
   197     ///
   200     /// \pre \ref run() must be called before using this function.
   198     /// \pre \ref run() must be called before using this function.
   201     const FlowMap& flowMap() const {
   199     const FlowMap& flowMap() const {
   202       return *_flow;
   200       return *_flow;
   203     }
   201     }
   204 
   202 
   205     /// \brief Returns a const reference to the node map storing the
   203     /// \brief Return a const reference to the node map storing the
   206     /// found potentials (the dual solution).
   204     /// found potentials (the dual solution).
   207     ///
   205     ///
   208     /// Returns a const reference to the node map storing the found
   206     /// Return a const reference to the node map storing the found
   209     /// potentials (the dual solution).
   207     /// potentials (the dual solution).
   210     ///
   208     ///
   211     /// \pre \ref run() must be called before using this function.
   209     /// \pre \ref run() must be called before using this function.
   212     const PotentialMap& potentialMap() const {
   210     const PotentialMap& potentialMap() const {
   213       return *_potential;
   211       return *_potential;
   214     }
   212     }
   215 
   213 
   216     /// \brief Returns the flow on the given edge.
   214     /// \brief Return the flow on the given edge.
   217     ///
   215     ///
   218     /// Returns the flow on the given edge.
   216     /// Return the flow on the given edge.
   219     ///
   217     ///
   220     /// \pre \ref run() must be called before using this function.
   218     /// \pre \ref run() must be called before using this function.
   221     Capacity flow(const Edge& edge) const {
   219     Capacity flow(const Edge& edge) const {
   222       return (*_flow)[edge];
   220       return (*_flow)[edge];
   223     }
   221     }
   224 
   222 
   225     /// \brief Returns the potential of the given node.
   223     /// \brief Return the potential of the given node.
   226     ///
   224     ///
   227     /// Returns the potential of the given node.
   225     /// Return the potential of the given node.
   228     ///
   226     ///
   229     /// \pre \ref run() must be called before using this function.
   227     /// \pre \ref run() must be called before using this function.
   230     Cost potential(const Node& node) const {
   228     Cost potential(const Node& node) const {
   231       return (*_potential)[node];
   229       return (*_potential)[node];
   232     }
   230     }
   233 
   231 
   234     /// \brief Returns the total cost of the found flow.
   232     /// \brief Return the total cost of the found flow.
   235     ///
   233     ///
   236     /// Returns the total cost of the found flow. The complexity of the
   234     /// Return the total cost of the found flow. The complexity of the
   237     /// function is \f$ O(e) \f$.
   235     /// function is \f$ O(e) \f$.
   238     ///
   236     ///
   239     /// \pre \ref run() must be called before using this function.
   237     /// \pre \ref run() must be called before using this function.
   240     Cost totalCost() const {
   238     Cost totalCost() const {
   241       Cost c = 0;
   239       Cost c = 0;