[Lemon-commits] [lemon_svn] athos: r693 - hugo/trunk/src/work/athos
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:40:59 CET 2006
Author: athos
Date: Tue May 4 16:54:21 2004
New Revision: 693
Added:
hugo/trunk/src/work/athos/mincostflows_test.cc
- copied, changed from r692, /hugo/trunk/src/work/athos/minlengthpaths_test.cc
Modified:
hugo/trunk/src/work/athos/makefile
hugo/trunk/src/work/athos/mincostflows.h
Log:
Nem tudom, a hugo-n miert nem megy.
Modified: hugo/trunk/src/work/athos/makefile
==============================================================================
--- hugo/trunk/src/work/athos/makefile (original)
+++ hugo/trunk/src/work/athos/makefile Tue May 4 16:54:21 2004
@@ -1,4 +1,4 @@
-BINARIES = suurballe minlength_demo
+BINARIES = suurballe minlength_demo mincostflows_test
INCLUDEDIRS= -I../../include -I.. -I../{athos,klao,marci,jacint,alpar,johanna,akos}
include ../makefile
Modified: hugo/trunk/src/work/athos/mincostflows.h
==============================================================================
--- hugo/trunk/src/work/athos/mincostflows.h (original)
+++ hugo/trunk/src/work/athos/mincostflows.h Tue May 4 16:54:21 2004
@@ -38,6 +38,8 @@
class MinCostFlows {
typedef typename LengthMap::ValueType Length;
+
+ typedef typename LengthMap::ValueType Length;
typedef typename Graph::Node Node;
typedef typename Graph::NodeIt NodeIt;
@@ -45,14 +47,14 @@
typedef typename Graph::OutEdgeIt OutEdgeIt;
typedef typename Graph::template EdgeMap<int> EdgeIntMap;
- typedef ConstMap<Edge,int> ConstMap;
+ // typedef ConstMap<Edge,int> ConstMap;
- typedef ResGraphWrapper<const Graph,int,ConstMap,EdgeIntMap> ResGraphType;
+ typedef ResGraphWrapper<const Graph,int,EdgeIntMap,EdgeIntMap> ResGraphType;
class ModLengthMap {
typedef typename ResGraphType::template NodeMap<Length> NodeMap;
const ResGraphType& G;
- const EdgeIntMap& rev;
+ // const EdgeIntMap& rev;
const LengthMap &ol;
const NodeMap &pot;
public :
@@ -60,29 +62,30 @@
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)]);
+ if (G.forward(e))
+ return ol[e]-(pot[G.head(e)]-pot[G.tail(e)]);
+ else
+ return -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){};
+ G(_G), /*rev(_rev),*/ ol(o), pot(p){};
};//ModLengthMap
-
+ //Input
const Graph& G;
const LengthMap& length;
+ const EdgeIntMap& capacity;
//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;
+ EdgeIntMap flow;
//Container to store found paths
std::vector< std::vector<Edge> > paths;
@@ -95,8 +98,8 @@
public :
- MinLengthPaths(Graph& _G, LengthMap& _length) : G(_G),
- length(_length), reversed(_G)/*, dijkstra_dist(_G)*/{ }
+ MinLengthPaths(Graph& _G, LengthMap& _length, EdgeIntMap& _cap) : G(_G),
+ length(_length), capacity(_cap), flow(_G)/*, dijkstra_dist(_G)*/{ }
///Runs the algorithm.
@@ -105,15 +108,14 @@
///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.
int run(Node s, Node t, int k) {
- ConstMap const1map(1);
- //We need a residual graph, in which some of the edges are reversed
- ResGraphType res_graph(G, const1map, reversed);
+ //We need a residual graph
+ ResGraphType res_graph(G, capacity, flow);
//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);
+ ModLengthMap mod_length(res_graph, length, dijkstra_dist);
Dijkstra<ResGraphType, ModLengthMap> dijkstra(res_graph, mod_length);
@@ -134,18 +136,21 @@
}
- //Reversing the sortest path
+ //Augmenting on the sortest path
Node n=t;
Edge e;
while (n!=s){
e = dijkstra.pred(n);
n = dijkstra.predNode(n);
- reversed[e] = 1-reversed[e];
+ G.augment(e,1);
}
}
+ /*
+ ///\TODO To be implemented later
+
//Let's find the paths
//We put the paths into stl vectors (as an inner representation).
//In the meantime we lose the information stored in 'reversed'.
@@ -175,6 +180,7 @@
}
}
+ */
return i;
}
@@ -206,4 +212,4 @@
} //namespace hugo
-#endif //HUGO_MINLENGTHPATHS_H
+#endif //HUGO_MINCOSTFLOW_H
Copied: hugo/trunk/src/work/athos/mincostflows_test.cc (from r692, /hugo/trunk/src/work/athos/minlengthpaths_test.cc)
==============================================================================
--- /hugo/trunk/src/work/athos/minlengthpaths_test.cc (original)
+++ hugo/trunk/src/work/athos/mincostflows_test.cc Tue May 4 16:54:21 2004
@@ -1,7 +1,8 @@
#include <iostream>
#include <list_graph.h>
-#include <minlengthpaths.h>
-#include <path.h>
+#include <mincostflows.h>
+//#include <path.h>
+#include <maps.h>
using namespace std;
using namespace hugo;
@@ -60,12 +61,13 @@
length.set(v4_t, 8);
length.set(v5_t, 8);
+ ConstMap const1map(1);
std::cout << "Minlengthpaths algorithm test..." << std::endl;
int k=3;
- MinLengthPaths< ListGraph, ListGraph::EdgeMap<int> >
- surb_test(graph, length);
+ MinCostFlows< ListGraph, ListGraph::EdgeMap<int> >
+ surb_test(graph, length, const1map);
check( surb_test.run(s,t,k) == 2 && surb_test.totalLength() == 46,"Two paths, total length should be 46");
More information about the Lemon-commits
mailing list