[Lemon-commits] [lemon_svn] deba: r3039 - in hugo/trunk: lemon test

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 21:52:00 CET 2006


Author: deba
Date: Mon Oct 30 18:22:14 2006
New Revision: 3039

Added:
   hugo/trunk/lemon/ssp_min_cost_flow.h
      - copied, changed from r3026, /hugo/trunk/lemon/min_cost_flow.h
Removed:
   hugo/trunk/lemon/min_cost_flow.h
Modified:
   hugo/trunk/lemon/Makefile.am
   hugo/trunk/lemon/suurballe.h
   hugo/trunk/test/min_cost_flow_test.cc

Log:
Min cost flow is renamed to SspMinCostFlow



Modified: hugo/trunk/lemon/Makefile.am
==============================================================================
--- hugo/trunk/lemon/Makefile.am	(original)
+++ hugo/trunk/lemon/Makefile.am	Mon Oct 30 18:22:14 2006
@@ -76,7 +76,6 @@
 	lemon/matrix_maps.h \
 	lemon/max_matching.h \
 	lemon/min_cost_arborescence.h \
-	lemon/min_cost_flow.h \
 	lemon/min_cut.h \
 	lemon/mip_glpk.h \
 	lemon/mip_cplex.h \
@@ -90,6 +89,7 @@
 	lemon/refptr.h \
 	lemon/simann.h \
 	lemon/smart_graph.h \
+	lemon/ssp_min_cost_flow.h \
 	lemon/sub_graph.h \
 	lemon/suurballe.h \
 	lemon/tabu_search.h \

Copied: hugo/trunk/lemon/ssp_min_cost_flow.h (from r3026, /hugo/trunk/lemon/min_cost_flow.h)
==============================================================================
--- /hugo/trunk/lemon/min_cost_flow.h	(original)
+++ hugo/trunk/lemon/ssp_min_cost_flow.h	Mon Oct 30 18:22:14 2006
@@ -19,9 +19,10 @@
 #ifndef LEMON_MIN_COST_FLOW_H
 #define LEMON_MIN_COST_FLOW_H
 
-///\ingroup flowalgs
-///\file
-///\brief An algorithm for finding a flow of value \c k (for small values of \c k) having minimal total cost 
+///\ingroup flowalgs 
+///
+///\file \brief An algorithm for finding a flow of value \c k (for
+///small values of \c k) having minimal total cost
 
 
 #include <lemon/dijkstra.h>
@@ -31,20 +32,21 @@
 
 namespace lemon {
 
-/// \addtogroup flowalgs
-/// @{
+  /// \addtogroup flowalgs
+  /// @{
 
-  ///\brief Implementation of an algorithm for finding a flow of value \c k 
-  ///(for small values of \c k) having minimal total cost between 2 nodes 
+  /// \brief Implementation of an algorithm for finding a flow of
+  /// value \c k (for small values of \c k) having minimal total cost
+  /// between two nodes
   /// 
   ///
-  /// The class \ref lemon::MinCostFlow "MinCostFlow" implements an
-  /// algorithm for finding a flow of value \c k having minimal total
-  /// cost from a given source node to a given target node in a
-  /// directed graph with a cost function on the edges. To
-  /// this end, the edge-capacities and edge-costs have to be
-  /// nonnegative.  The edge-capacities should be integers, but the
-  /// edge-costs can be integers, reals or of other comparable
+  /// The \ref lemon::SspMinCostFlow "Successive Shortest Path Minimum
+  /// Cost Flow" implements an algorithm for finding a flow of value
+  /// \c k having minimal total cost from a given source node to a
+  /// given target node in a directed graph with a cost function on
+  /// the edges. To this end, the edge-capacities and edge-costs have
+  /// to be nonnegative.  The edge-capacities should be integers, but
+  /// the edge-costs can be integers, reals or of other comparable
   /// numeric type.  This algorithm is intended to be used only for
   /// small values of \c k, since it is only polynomial in k, not in
   /// the length of k (which is log k): in order to find the minimum
@@ -57,7 +59,7 @@
   ///
   ///\author Attila Bernath
   template <typename Graph, typename LengthMap, typename CapacityMap>
-  class MinCostFlow {
+  class SspMinCostFlow {
 
     typedef typename LengthMap::Value Length;
 
@@ -116,27 +118,25 @@
 
   public :
 
-    /*! \brief The constructor of the class.
-    
-    \param _g The directed graph the algorithm runs on. 
-    \param _length The length (cost) of the edges. 
-    \param _cap The capacity of the edges. 
-    \param _s Source node.
-    \param _t Target node.
-    */
-    MinCostFlow(Graph& _g, LengthMap& _length, CapacityMap& _cap, 
-		Node _s, Node _t) : 
+    /// \brief The constructor of the class.
+    ///
+    /// \param _g The directed graph the algorithm runs on. 
+    /// \param _length The length (cost) of the edges. 
+    /// \param _cap The capacity of the edges. 
+    /// \param _s Source node.
+    /// \param _t Target node.
+    SspMinCostFlow(Graph& _g, LengthMap& _length, CapacityMap& _cap, 
+                   Node _s, Node _t) : 
       g(_g), length(_length), capacity(_cap), flow(_g), potential(_g), 
       s(_s), t(_t), 
       res_graph(g, capacity, flow), 
       mod_length(res_graph, length, potential),
       dijkstra(res_graph, mod_length) { 
       reset();
-      }
-
-    /*! Tries to augment the flow between s and t by 1.
-      The return value shows if the augmentation is successful.
-     */
+    }
+    
+    /// \brief Tries to augment the flow between s and t by 1. The
+    /// return value shows if the augmentation is successful.
     bool augment() {
       dijkstra.run(s);
       if (!dijkstra.reached(t)) {
@@ -167,37 +167,35 @@
       }
     }
     
-    /*! \brief Runs the algorithm.
-    
-    Runs the algorithm.
-    Returns k if there is a flow of value at least k from s to t.
-    Otherwise it returns the maximum value of a flow from s to t.
-    
-    \param k The value of the flow we are looking for.
-    
-    \todo May be it does make sense to be able to start with a nonzero 
-    feasible primal-dual solution pair as well.
-    
-    \todo If the actual flow value is bigger than k, then everything is 
-    cleared and the algorithm starts from zero flow. Is it a good approach?
-    */
+    /// \brief Runs the algorithm.
+    ///
+    /// Runs the algorithm.
+    /// Returns k if there is a flow of value at least k from s to t.
+    /// Otherwise it returns the maximum value of a flow from s to t.
+    ///
+    /// \param k The value of the flow we are looking for.
+    ///
+    /// \todo May be it does make sense to be able to start with a
+    /// nonzero feasible primal-dual solution pair as well.
+    ///
+    /// \todo If the actual flow value is bigger than k, then
+    /// everything is cleared and the algorithm starts from zero
+    /// flow. Is it a good approach?
     int run(int k) {
       if (flowValue()>k) reset();
       while (flowValue()<k && augment()) { }
       return flowValue();
     }
 
-    /*! \brief The class is reset to zero flow and potential.
-      The class is reset to zero flow and potential.
-     */
+    /// \brief The class is reset to zero flow and potential. The
+    /// class is reset to zero flow and potential.
     void reset() {
       total_length=0;
       for (typename Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
       for (typename Graph::NodeIt n(g); n!=INVALID; ++n) potential.set(n, 0);  
     }
 
-    /*! Returns the value of the actual flow. 
-     */
+    /// \brief Returns the value of the actual flow. 
     int flowValue() const {
       int i=0;
       for (typename Graph::OutEdgeIt e(g, s); e!=INVALID; ++e) i+=flow[e];
@@ -205,31 +203,31 @@
       return i;
     }
 
-    /// Total cost of the found flow.
-
+    /// \brief Total cost of the found flow.
+    ///
     /// This function gives back the total cost of the found flow.
     Length totalLength(){
       return total_length;
     }
 
-    ///Returns a const reference to the EdgeMap \c flow. 
-
-    ///Returns a const reference to the EdgeMap \c flow. 
+    /// \brief Returns a const reference to the EdgeMap \c flow. 
+    ///
+    /// Returns a const reference to the EdgeMap \c flow. 
     const EdgeIntMap &getFlow() const { return flow;}
 
-    /*! \brief Returns a const reference to the NodeMap \c potential (the dual solution).
-
-    Returns a const reference to the NodeMap \c potential (the dual solution).
-    */
+    /// \brief Returns a const reference to the NodeMap \c potential
+    /// (the dual solution).
+    ///
+    /// Returns a const reference to the NodeMap \c potential (the
+    /// dual solution).
     const PotentialMap &getPotential() const { return potential;}
 
-    /*! \brief Checking the complementary slackness optimality criteria.
-
-    This function checks, whether the given flow and potential 
-    satisfy the complementary slackness conditions (i.e. these are optimal).
-    This function only checks optimality, doesn't bother with feasibility.
-    For testing purpose.
-    */
+    /// \brief Checking the complementary slackness optimality criteria.
+    ///
+    /// This function checks, whether the given flow and potential 
+    /// satisfy the complementary slackness conditions (i.e. these are optimal).
+    /// This function only checks optimality, doesn't bother with feasibility.
+    /// For testing purpose.
     bool checkComplementarySlackness(){
       Length mod_pot;
       Length fl_e;
@@ -253,7 +251,7 @@
       return true;
     }
     
-  }; //class MinCostFlow
+  }; //class SspMinCostFlow
 
   ///@}
 

Modified: hugo/trunk/lemon/suurballe.h
==============================================================================
--- hugo/trunk/lemon/suurballe.h	(original)
+++ hugo/trunk/lemon/suurballe.h	Mon Oct 30 18:22:14 2006
@@ -26,15 +26,15 @@
 
 #include <lemon/maps.h>
 #include <vector>
-#include <lemon/min_cost_flow.h>
+#include <lemon/ssp_min_cost_flow.h>
 
 namespace lemon {
 
 /// \addtogroup flowalgs
 /// @{
 
-  ///\brief Implementation of an algorithm for finding k edge-disjoint paths between 2 nodes 
-  /// of minimal total length 
+  ///\brief Implementation of an algorithm for finding k edge-disjoint
+  /// paths between 2 nodes of minimal total length
   ///
   /// The class \ref lemon::Suurballe implements
   /// an algorithm for finding k edge-disjoint paths
@@ -49,7 +49,7 @@
   ///\note It it questionable whether it is correct to call this method after
   ///%Suurballe for it is just a special case of Edmonds' and Karp's algorithm
   ///for finding minimum cost flows. In fact, this implementation just
-  ///wraps the MinCostFlow algorithms. The paper of both %Suurballe and
+  ///wraps the SspMinCostFlow algorithms. The paper of both %Suurballe and
   ///Edmonds-Karp published in 1972, therefore it is possibly right to
   ///state that they are
   ///independent results. Most frequently this special case is referred as
@@ -79,7 +79,7 @@
     //This is the capacity map for the mincostflow problem
     ConstMap const1map;
     //This MinCostFlow instance will actually solve the problem
-    MinCostFlow<Graph, LengthMap, ConstMap> min_cost_flow;
+    SspMinCostFlow<Graph, LengthMap, ConstMap> min_cost_flow;
 
     //Container to store found paths
     std::vector< std::vector<Edge> > paths;
@@ -87,25 +87,24 @@
   public :
 
 
-    /*! \brief The constructor of the class.
-    
-    \param _G The directed graph the algorithm runs on. 
-    \param _length The length (weight or cost) of the edges. 
-    \param _s Source node.
-    \param _t Target node.
-    */
+    /// \brief The constructor of the class.
+    ///
+    /// \param _G The directed graph the algorithm runs on. 
+    /// \param _length The length (weight or cost) of the edges. 
+    /// \param _s Source node.
+    /// \param _t Target node.
     Suurballe(Graph& _G, LengthMap& _length, Node _s, Node _t) : 
       G(_G), s(_s), t(_t), const1map(1), 
       min_cost_flow(_G, _length, const1map, _s, _t) { }
 
-    ///Runs the algorithm.
-
-    ///Runs the algorithm.
-    ///Returns k if there are at least k edge-disjoint paths from s to t.
-    ///Otherwise it returns the number of edge-disjoint paths found 
-    ///from s to t.
+    /// \brief Runs the algorithm.
+    ///
+    /// Runs the algorithm.
+    /// Returns k if there are at least k edge-disjoint paths from s to t.
+    /// Otherwise it returns the number of edge-disjoint paths found 
+    /// from s to t.
     ///
-    ///\param k How many paths are we looking for?
+    /// \param k How many paths are we looking for?
     ///
     int run(int k) {
       int i = min_cost_flow.run(k);
@@ -144,46 +143,49 @@
     }
 
     
-    ///Returns the total length of the paths.
-    
-    ///This function gives back the total length of the found paths.
+    /// \brief Returns the total length of the paths.
+    ///
+    /// This function gives back the total length of the found paths.
     Length totalLength(){
       return min_cost_flow.totalLength();
     }
 
-    ///Returns the found flow.
-
-    ///This function returns a const reference to the EdgeMap \c flow.
+    /// \brief Returns the found flow.
+    ///
+    /// This function returns a const reference to the EdgeMap \c flow.
     const EdgeIntMap &getFlow() const { return min_cost_flow.flow;}
 
-    /// Returns the optimal dual solution
-    
-    ///This function returns a const reference to the NodeMap
-    ///\c potential (the dual solution).
+    /// \brief Returns the optimal dual solution
+    ///
+    /// This function returns a const reference to the NodeMap \c
+    /// potential (the dual solution).
     const EdgeIntMap &getPotential() const { return min_cost_flow.potential;}
 
-    ///Checks whether the complementary slackness holds.
-
-    ///This function checks, whether the given solution is optimal.
-    ///Currently this function only checks optimality,
-    ///doesn't bother with feasibility.
-    ///It is meant for testing purposes.
+    /// \brief Checks whether the complementary slackness holds.
+    ///
+    /// This function checks, whether the given solution is optimal.
+    /// Currently this function only checks optimality, doesn't bother
+    /// with feasibility.  It is meant for testing purposes.
     bool checkComplementarySlackness(){
       return min_cost_flow.checkComplementarySlackness();
     }
 
-    ///Read the found paths.
-    
-    ///This function gives back the \c j-th path in argument p.
-    ///Assumes that \c run() has been run and nothing has changed since then.
-    /// \warning It is assumed that \c p is constructed to
-    ///be a path of graph \c G.
-    ///If \c j is not less than the result of previous \c run,
-    ///then the result here will be an empty path (\c j can be 0 as well).
-    ///
-    ///\param Path The type of the path structure to put the result to (must meet lemon path concept).
-    ///\param p The path to put the result to.
-    ///\param j Which path you want to get from the found paths (in a real application you would get the found paths iteratively).
+    /// \brief Read the found paths.
+    ///
+    /// This function gives back the \c j-th path in argument p.
+    /// Assumes that \c run() has been run and nothing has changed
+    /// since then.
+    ///
+    /// \warning It is assumed that \c p is constructed to be a path
+    /// of graph \c G.  If \c j is not less than the result of
+    /// previous \c run, then the result here will be an empty path
+    /// (\c j can be 0 as well).
+    ///
+    /// \param Path The type of the path structure to put the result
+    /// to (must meet lemon path concept).
+    /// \param p The path to put the result to.
+    /// \param j Which path you want to get from the found paths (in a
+    /// real application you would get the found paths iteratively).
     template<typename Path>
     void getPath(Path& p, size_t j){
 

Modified: hugo/trunk/test/min_cost_flow_test.cc
==============================================================================
--- hugo/trunk/test/min_cost_flow_test.cc	(original)
+++ hugo/trunk/test/min_cost_flow_test.cc	Mon Oct 30 18:22:14 2006
@@ -19,7 +19,7 @@
 #include <iostream>
 #include "test_tools.h"
 #include <lemon/list_graph.h>
-#include <lemon/min_cost_flow.h>
+#include <lemon/ssp_min_cost_flow.h>
 //#include <path.h>
 //#include <maps.h>
 
@@ -92,7 +92,7 @@
   //  ConstMap<Edge, int> const1map(1);
   std::cout << "Mincostflows algorithm test..." << std::endl;
 
-  MinCostFlow< Graph, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
+  SspMinCostFlow< Graph, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
     surb_test(graph, length, capacity, s, t);
 
   int k=1;



More information about the Lemon-commits mailing list