# HG changeset patch # User athos # Date 1083682461 0 # Node ID 7550fed0cd9197543a50c5c2c5b072f267ddc034 # Parent def920ddaba755b8b803b015c095d194c16c65f4 Nem tudom, a hugo-n miert nem megy. diff -r def920ddaba7 -r 7550fed0cd91 src/work/athos/makefile --- a/src/work/athos/makefile Tue May 04 14:06:00 2004 +0000 +++ b/src/work/athos/makefile Tue May 04 14:54:21 2004 +0000 @@ -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 diff -r def920ddaba7 -r 7550fed0cd91 src/work/athos/mincostflows.h --- a/src/work/athos/mincostflows.h Tue May 04 14:06:00 2004 +0000 +++ b/src/work/athos/mincostflows.h Tue May 04 14:54:21 2004 +0000 @@ -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 EdgeIntMap; - typedef ConstMap ConstMap; + // typedef ConstMap ConstMap; - typedef ResGraphWrapper ResGraphType; + typedef ResGraphWrapper ResGraphType; class ModLengthMap { typedef typename ResGraphType::template NodeMap 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!!"< > 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 dijkstra_dist(res_graph); - ModLengthMap mod_length(res_graph, reversed, length, dijkstra_dist); + ModLengthMap mod_length(res_graph, length, dijkstra_dist); Dijkstra 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 diff -r def920ddaba7 -r 7550fed0cd91 src/work/athos/mincostflows_test.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/athos/mincostflows_test.cc Tue May 04 14:54:21 2004 +0000 @@ -0,0 +1,94 @@ +#include +#include +#include +//#include +#include + +using namespace std; +using namespace hugo; + + + +bool passed = true; + +void check(bool rc, char *msg="") { + passed = passed && rc; + if(!rc) { + std::cerr << "Test failed! ("<< msg << ")" << std::endl; \ + + + } +} + + + +int main() +{ + + typedef ListGraph::Node Node; + typedef ListGraph::Edge Edge; + + ListGraph graph; + + //Ahuja könyv példája + + Node s=graph.addNode(); + Node v1=graph.addNode(); + Node v2=graph.addNode(); + Node v3=graph.addNode(); + Node v4=graph.addNode(); + Node v5=graph.addNode(); + Node t=graph.addNode(); + + Edge s_v1=graph.addEdge(s, v1); + Edge v1_v2=graph.addEdge(v1, v2); + Edge s_v3=graph.addEdge(s, v3); + Edge v2_v4=graph.addEdge(v2, v4); + Edge v2_v5=graph.addEdge(v2, v5); + Edge v3_v5=graph.addEdge(v3, v5); + Edge v4_t=graph.addEdge(v4, t); + Edge v5_t=graph.addEdge(v5, t); + + + ListGraph::EdgeMap length(graph); + + length.set(s_v1, 6); + length.set(v1_v2, 4); + length.set(s_v3, 10); + length.set(v2_v4, 5); + length.set(v2_v5, 1); + length.set(v3_v5, 5); + length.set(v4_t, 8); + length.set(v5_t, 8); + + ConstMap const1map(1); + std::cout << "Minlengthpaths algorithm test..." << std::endl; + + + int k=3; + MinCostFlows< ListGraph, ListGraph::EdgeMap > + surb_test(graph, length, const1map); + + check( surb_test.run(s,t,k) == 2 && surb_test.totalLength() == 46,"Two paths, total length should be 46"); + + typedef DirPath DPath; + DPath P(graph); + + surb_test.getPath(P,0); + check(P.length() == 4, "First path should contain 4 edges."); + + surb_test.getPath(P,1); + check(P.length() == 3, "Second path: 3 edges."); + + k=1; + check( surb_test.run(s,t,k) == 1 && surb_test.totalLength() == 19,"One path, total length should be 19"); + + surb_test.getPath(P,0); + check(P.length() == 4, "First path should contain 4 edges."); + + cout << (passed ? "All tests passed." : "Some of the tests failed!!!") + << endl; + + return passed ? 0 : 1; + +}