[Lemon-commits] [lemon_svn] athos: r440 - hugo/trunk/src/work/athos

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:39:28 CET 2006


Author: athos
Date: Wed Apr 14 15:30:05 2004
New Revision: 440

Modified:
   hugo/trunk/src/work/athos/makefile
   hugo/trunk/src/work/athos/minlengthpaths.h

Log:
The paths are stored in vectors, assumed there is no circle of length 0

Modified: hugo/trunk/src/work/athos/makefile
==============================================================================
--- hugo/trunk/src/work/athos/makefile	(original)
+++ hugo/trunk/src/work/athos/makefile	Wed Apr 14 15:30:05 2004
@@ -6,7 +6,7 @@
 #BOOSTROOT ?= /home/marci/boost
 INCLUDEDIRS ?= -I../../include -I.. -I../{marci,jacint,alpar,athos,akos,klao} #-I$(BOOSTROOT)
 #LEDAINCLUDE ?= -I$(LEDAROOT)/incl
-CXXFLAGS = -g -O -W -Wall $(INCLUDEDIRS) -ansi -pedantic
+CXXFLAGS = -g -W -Wall $(INCLUDEDIRS) -ansi -pedantic
 
 #LEDABINARIES = lg_vs_sg leda_graph_demo leda_bfs_dfs max_bipartite_matching_demo
 BINARIES = suurballe

Modified: hugo/trunk/src/work/athos/minlengthpaths.h
==============================================================================
--- hugo/trunk/src/work/athos/minlengthpaths.h	(original)
+++ hugo/trunk/src/work/athos/minlengthpaths.h	Wed Apr 14 15:30:05 2004
@@ -9,10 +9,13 @@
 #include <dijkstra.h>
 #include <graph_wrapper.h>
 #include <maps.h>
+#include <vector>
+
 
 namespace hugo {
 
 
+
   ///\brief Implementation of an algorithm for finding k paths between 2 nodes 
   /// of minimal total length 
   ///
@@ -48,10 +51,9 @@
       typedef typename LengthMap::ValueType ValueType;
 
       ValueType operator[](typename ResGraphType::Edge e) const {     
-	if ( (1-2*rev[e])*ol[e]-(pot[G.head(e)]-pot[G.tail(e)] ) <0 ){
-	  ///\TODO This has to be removed
-	  std::cout<<"Negative length!!"<<std::endl;
-	}
+	//if ( (1-2*rev[e])*ol[e]-(pot[G.head(e)]-pot[G.tail(e)] ) <0 ){
+	//  std::cout<<"Negative length!!"<<std::endl;
+	//}
 	return (1-2*rev[e])*ol[e]-(pot[G.head(e)]-pot[G.tail(e)]);   
       }     
 
@@ -64,19 +66,22 @@
     const Graph& G;
     const LengthMap& length;
 
-    //auxiliry variable
+    //auxiliry variables
+
     //The value is 1 iff the edge is reversed. 
     //If the algorithm has finished, the edges of the seeked paths are 
     //exactly those that are reversed 
     EdgeIntMap reversed; 
     
+    //Container to store found paths
+    std::vector< std::vector<Edge> > paths;
+
   public :
 
 
     MinLengthPaths(Graph& _G, LengthMap& _length) : G(_G), 
       length(_length), reversed(_G)/*, dijkstra_dist(_G)*/{ }
 
-    ///Runs the algorithm
     
     ///Runs the algorithm
     ///Returns k if there are at least k edge-disjoint paths from s to t.
@@ -92,12 +97,13 @@
       ModLengthMap mod_length(res_graph, reversed, length, dijkstra_dist);
 
       Dijkstra<ResGraphType, ModLengthMap> dijkstra(res_graph, mod_length);
-      
-      for (int i=0; i<k; ++i){
+
+      int i;
+      for (i=0; i<k; ++i){
 	dijkstra.run(s);
 	if (!dijkstra.reached(t)){
 	  //There are no k paths from s to t
-	  return i;
+	  break;
 	};
 	
 	{
@@ -120,11 +126,34 @@
 
 	  
       }
-      return k;
-    }
+      
+      //Let's find the paths
+      //We put the paths into vectors (just for now). In the meantime we lose 
+      //the information stored in 'reversed'
+      //We suppose the lengths to be positive now.
+      paths.clear();
+      paths.resize(k);
+      for (int j=0; j<i; ++j){
+	Node n=s;
+	OutEdgeIt e;
 
+	while (n!=t){
 
 
+	  G.first(e,n);
+	  
+	  while (!reversed[e]){
+	    G.next(e);
+	  }
+	  n = G.head(e);
+	  paths[j].push_back(e);
+	  reversed[e] = 1-reversed[e];
+	}
+	
+      }
+
+      return i;
+    }
 
 
   }; //class MinLengthPaths



More information about the Lemon-commits mailing list