Index: src/work/athos/makefile
===================================================================
--- src/work/athos/makefile	(revision 551)
+++ src/work/athos/makefile	(revision 607)
@@ -1,3 +1,3 @@
-BINARIES = suurballe minlength_demo mincostflows_test
+BINARIES = minlengthpaths_test minlength_demo
 INCLUDEDIRS= -I../.. -I.. -I../{athos,klao,marci,jacint,alpar,johanna,akos} 
 include ../makefile
Index: src/work/athos/mincostflows.h
===================================================================
--- src/work/athos/mincostflows.h	(revision 554)
+++ src/work/athos/mincostflows.h	(revision 607)
@@ -9,5 +9,5 @@
 #include <iostream>
 #include <hugo/dijkstra.h>
-#include <graph_wrapper.h>
+#include <hugo/graph_wrapper.h>
 #include <hugo/maps.h>
 #include <vector>
@@ -78,4 +78,5 @@
 
 
+  protected:
     
     //Input
@@ -84,4 +85,5 @@
     const CapacityMap& capacity;
 
+
     //auxiliary variables
 
@@ -99,4 +101,5 @@
     Length total_length;
 
+
   public :
 
@@ -111,4 +114,6 @@
     ///Returns k if there are at least k edge-disjoint paths from s to t.
     ///Otherwise it returns the number of found edge-disjoint paths from s to t.
+    ///\todo May be it does make sense to be able to start with a nonzero 
+    /// feasible primal-dual solution pair as well.
     int run(Node s, Node t, int k) {
 
@@ -186,8 +191,18 @@
     }
 
-    //This function checks, whether the given solution is optimal
-    //Running after a \c run() should return with true
-    //In this "state of the art" this only check optimality, doesn't bother with feasibility
-    bool checkSolution(){
+    ///Returns a const reference to the EdgeMap \c flow. \pre \ref run() must
+    ///be called before using this function.
+    const EdgeIntMap &getFlow() const { return flow;}
+
+  ///Returns a const reference to the NodeMap \c potential (the dual solution).
+    /// \pre \ref run() must be called before using this function.
+    const EdgeIntMap &getPotential() const { return potential;}
+
+    ///This function checks, whether the given solution is optimal
+    ///Running after a \c run() should return with true
+    ///In this "state of the art" this only check optimality, doesn't bother with feasibility
+    ///
+    ///\todo Is this OK here?
+    bool checkComplementarySlackness(){
       Length mod_pot;
       Length fl_e;
Index: src/work/athos/minlength_demo.cc
===================================================================
--- src/work/athos/minlength_demo.cc	(revision 511)
+++ src/work/athos/minlength_demo.cc	(revision 607)
@@ -3,6 +3,7 @@
 
 #include <list_graph.h>
-#include <dimacs.h>
-#include <minlengthpaths.h>
+#include <hugo/dimacs.h>
+#include <hugo/time_measure.h>
+#include "minlengthpaths.h"
 //#include <time_measure.h>
 
@@ -20,7 +21,7 @@
   Node s, t;
   Graph::EdgeMap<int> cap(G);
-  readDimacsMaxFlow(std::cin, G, s, t, cap);
+  readDimacs(std::cin, G, cap, s, t);
 
-  std::cout << "preflow demo (ATHOS)..." << std::endl;
+  std::cout << "Minlengthpaths demo (ATHOS)..." << std::endl;
   //Graph::EdgeMap<int> flow(G); //0 flow
 
@@ -32,6 +33,12 @@
   MinLengthPaths<Graph, Graph::EdgeMap<int> >
     surb_test(G,cap);
-  std::cout << surb_test.run(s,t,k) << std::endl;
-  std::cout << surb_test.totalLength() << std::endl;
+  Timer ts;
+  ts.reset();
+  std::cout << "Number of found paths: " << surb_test.run(s,t,k) << std::endl;
+  std::cout << "elapsed time: " << ts << std::endl;
+  
+  std::cout << "Total length of found paths: " << surb_test.totalLength() << std::endl;
+  //std::cout << (surb_test.checkComplementarySlackness() ? "OK (compl. slackn.)." : "Problem (compl. slackn.)!!!") << std::endl;
+
   //preflow_push<Graph, int> max_flow_test(G, s, t, cap);
   //int flow_value=max_flow_test.run();
Index: src/work/athos/minlengthpaths.h
===================================================================
--- src/work/athos/minlengthpaths.h	(revision 520)
+++ src/work/athos/minlengthpaths.h	(revision 607)
@@ -8,9 +8,10 @@
 
 #include <iostream>
-#include <dijkstra.h>
-#include <graph_wrapper.h>
-#include <maps.h>
-#include <vector.h>
-
+//#include <hugo/dijkstra.h>
+//#include <hugo/graph_wrapper.h>
+#include <hugo/maps.h>
+#include <vector>
+#include <mincostflows.h>
+#include <for_each_macros.h>
 
 namespace hugo {
@@ -27,7 +28,11 @@
   /// edge-weighted directed graph having minimal total weigth (length).
   ///
+  ///\warning It is assumed that the lengths are positive, since the
+  /// general flow-decomposition is not implemented yet.
+  ///
   ///\author Attila Bernath
   template <typename Graph, typename LengthMap>
-  class MinLengthPaths {
+  class MinLengthPaths{
+
 
     typedef typename LengthMap::ValueType Length;
@@ -41,103 +46,33 @@
     typedef ConstMap<Edge,int> ConstMap;
 
-    typedef ResGraphWrapper<const Graph,int,ConstMap,EdgeIntMap> ResGraphType;
+    //Input
+    const Graph& G;
 
-    class ModLengthMap {   
-      typedef typename ResGraphType::template NodeMap<Length> NodeMap;
-      const ResGraphType& G;
-      const EdgeIntMap& rev;
-      const LengthMap &ol;
-      const NodeMap &pot;
-    public :
-      typedef typename LengthMap::KeyType KeyType;
-      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 ){
-	//  std::cout<<"Negative length!!"<<std::endl;
-	//}
-	return (1-2*rev[e])*ol[e]-(pot[G.head(e)]-pot[G.tail(e)]);   
-      }     
-	
-      ModLengthMap(const ResGraphType& _G, const EdgeIntMap& _rev, 
-		   const LengthMap &o,  const NodeMap &p) : 
-	G(_G), rev(_rev), ol(o), pot(p){}; 
-    };//ModLengthMap
+    //Auxiliary variables
+    //This is the capacity map for the mincostflow problem
+    ConstMap const1map;
+    //This MinCostFlows instance will actually solve the problem
+    MinCostFlows<Graph, LengthMap, ConstMap> mincost_flow;
 
-
-    
-
-    const Graph& G;
-    const LengthMap& length;
-
-    //auxiliary 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;
-    //typedef DirPath<Graph> DPath;
-    //DPath paths;
-
-
-    Length total_length;
 
   public :
 
 
-    MinLengthPaths(Graph& _G, LengthMap& _length) : G(_G), 
-      length(_length), reversed(_G)/*, dijkstra_dist(_G)*/{ }
+    MinLengthPaths(Graph& _G, LengthMap& _length) : G(_G),
+      const1map(1), mincost_flow(_G, _length, const1map){}
 
-    
     ///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 found edge-disjoint paths from s to t.
+   ///Otherwise it returns the number of found edge-disjoint paths from s to t.
     int run(Node s, Node t, int k) {
-      ConstMap const1map(1);
+
+      int i = mincost_flow.run(s,t,k);
+      
 
 
-      //We need a residual graph, in which some of the edges are reversed
-      ResGraphType res_graph(G, const1map, reversed);
-
-      //Initialize the copy of the Dijkstra potential to zero
-      typename ResGraphType::template NodeMap<Length> dijkstra_dist(res_graph);
-      ModLengthMap mod_length(res_graph, reversed, length, dijkstra_dist);
-
-      Dijkstra<ResGraphType, ModLengthMap> dijkstra(res_graph, mod_length);
-
-      int i;
-      for (i=0; i<k; ++i){
-	dijkstra.run(s);
-	if (!dijkstra.reached(t)){
-	  //There are no k paths from s to t
-	  break;
-	};
-	
-	{
-	  //We have to copy the potential
-	  typename ResGraphType::NodeIt n;
-	  for ( res_graph.first(n) ; res_graph.valid(n) ; res_graph.next(n) ) {
-	      dijkstra_dist[n] += dijkstra.distMap()[n];
-	  }
-	}
-
-
-	//Reversing the sortest path
-	Node n=t;
-	Edge e;
-	while (n!=s){
-	  e = dijkstra.pred(n);
-	  n = dijkstra.predNode(n);
-	  reversed[e] = 1-reversed[e];
-	}
-
-	  
-      }
-      
       //Let's find the paths
       //We put the paths into stl vectors (as an inner representation). 
@@ -145,8 +80,14 @@
       //We suppose the lengths to be positive now.
 
-      //Meanwhile we put the total length of the found paths 
-      //in the member variable total_length
+      //We don't want to change the flow of mincost_flow, so we make a copy
+      //The name here suggests that the flow has only 0/1 values.
+      EdgeIntMap reversed(G); 
+
+      FOR_EACH_LOC(typename Graph::EdgeIt, e, G){
+	reversed[e] = mincost_flow.getFlow()[e];
+      }
+      
       paths.clear();
-      total_length=0;
+      //total_length=0;
       paths.resize(k);
       for (int j=0; j<i; ++j){
@@ -164,25 +105,46 @@
 	  n = G.head(e);
 	  paths[j].push_back(e);
-	  total_length += length[e];
+	  //total_length += length[e];
 	  reversed[e] = 1-reversed[e];
 	}
 	
       }
-
       return i;
     }
 
+    
     ///This function gives back the total length of the found paths.
     ///Assumes that \c run() has been run and nothing changed since then.
     Length totalLength(){
-      return total_length;
+      return mincost_flow.totalLength();
+    }
+
+    ///Returns a const reference to the EdgeMap \c flow. \pre \ref run() must
+    ///be called before using this function.
+    const EdgeIntMap &getFlow() const { return mincost_flow.flow;}
+
+  ///Returns a const reference to the NodeMap \c potential (the dual solution).
+    /// \pre \ref run() must be called before using this function.
+    const EdgeIntMap &getPotential() const { return mincost_flow.potential;}
+
+    ///This function checks, whether the given solution is optimal
+    ///Running after a \c run() should return with true
+    ///In this "state of the art" this only checks optimality, doesn't bother with feasibility
+    ///
+    ///\todo Is this OK here?
+    bool checkComplementarySlackness(){
+      return mincost_flow.checkComplementarySlackness();
     }
 
     ///This function gives back the \c j-th path in argument p.
     ///Assumes that \c run() has been run and nothing changed since then.
-    /// \warning It is assumed that \c p is constructed to be a path of graph \c G. If \c j is greater than the result of previous \c run, then the result here will be an empty path.
+    /// \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).
     template<typename DirPath>
-    void getPath(DirPath& p, int j){
+    void getPath(DirPath& p, size_t j){
+      
       p.clear();
+      if (j>paths.size()-1){
+	return;
+      }
       typename DirPath::Builder B(p);
       for(typename std::vector<Edge>::iterator i=paths[j].begin(); 
Index: src/work/athos/minlengthpaths_test.cc
===================================================================
--- src/work/athos/minlengthpaths_test.cc	(revision 520)
+++ src/work/athos/minlengthpaths_test.cc	(revision 607)
@@ -70,4 +70,6 @@
   check(  surb_test.run(s,t,k) == 2 && surb_test.totalLength() == 46,"Two paths, total length should be 46");
 
+  check(  surb_test.checkComplementarySlackness(), "Complementary slackness conditions are not met.");
+
   typedef DirPath<ListGraph> DPath;
   DPath P(graph);
@@ -81,4 +83,6 @@
   k=1;
   check(  surb_test.run(s,t,k) == 1 && surb_test.totalLength() == 19,"One path, total length should be 19");
+
+  check(  surb_test.checkComplementarySlackness(), "Complementary slackness conditions are not met.");
  
   surb_test.getPath(P,0);
Index: src/work/athos/old/minlengthpaths.h
===================================================================
--- src/work/athos/old/minlengthpaths.h	(revision 601)
+++ src/work/athos/old/minlengthpaths.h	(revision 607)
@@ -8,8 +8,8 @@
 
 #include <iostream>
-#include <dijkstra.h>
-#include <graph_wrapper.h>
-#include <maps.h>
-#include <vector.h>
+#include <hugo/dijkstra.h>
+#include <hugo/graph_wrapper.h>
+#include <hugo/maps.h>
+#include <vector>
 
 
Index: src/work/klao/path.h
===================================================================
--- src/work/klao/path.h	(revision 493)
+++ src/work/klao/path.h	(revision 607)
@@ -12,6 +12,6 @@
 #include <algorithm>
 
-#include <invalid.h>
-#include <error.h>
+#include <hugo/invalid.h>
+#include <hugo/error.h>
 #include <debug.h>
 
