Changeset 527:7550fed0cd91 in lemon-0.x for src
- Timestamp:
- 05/04/04 16:54:21 (21 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@693
- Location:
- src/work/athos
- Files:
-
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
src/work/athos/makefile
r511 r527 1 BINARIES = suurballe minlength_demo 1 BINARIES = suurballe minlength_demo mincostflows_test 2 2 INCLUDEDIRS= -I../../include -I.. -I../{athos,klao,marci,jacint,alpar,johanna,akos} 3 3 include ../makefile -
src/work/athos/mincostflows.h
r523 r527 39 39 40 40 typedef typename LengthMap::ValueType Length; 41 42 typedef typename LengthMap::ValueType Length; 41 43 42 44 typedef typename Graph::Node Node; … … 46 48 typedef typename Graph::template EdgeMap<int> EdgeIntMap; 47 49 48 typedef ConstMap<Edge,int> ConstMap;49 50 typedef ResGraphWrapper<const Graph,int, ConstMap,EdgeIntMap> ResGraphType;50 // typedef ConstMap<Edge,int> ConstMap; 51 52 typedef ResGraphWrapper<const Graph,int,EdgeIntMap,EdgeIntMap> ResGraphType; 51 53 52 54 class ModLengthMap { 53 55 typedef typename ResGraphType::template NodeMap<Length> NodeMap; 54 56 const ResGraphType& G; 55 const EdgeIntMap& rev;57 // const EdgeIntMap& rev; 56 58 const LengthMap &ol; 57 59 const NodeMap &pot; … … 61 63 62 64 ValueType operator[](typename ResGraphType::Edge e) const { 63 //if ( (1-2*rev[e])*ol[e]-(pot[G.head(e)]-pot[G.tail(e)] ) <0 ){64 // std::cout<<"Negative length!!"<<std::endl;65 //}66 return (1-2*rev[e])*ol[e]-(pot[G.head(e)]-pot[G.tail(e)]);65 if (G.forward(e)) 66 return ol[e]-(pot[G.head(e)]-pot[G.tail(e)]); 67 else 68 return -ol[e]-(pot[G.head(e)]-pot[G.tail(e)]); 67 69 } 68 70 69 71 ModLengthMap(const ResGraphType& _G, const EdgeIntMap& _rev, 70 72 const LengthMap &o, const NodeMap &p) : 71 G(_G), rev(_rev),ol(o), pot(p){};73 G(_G), /*rev(_rev),*/ ol(o), pot(p){}; 72 74 };//ModLengthMap 73 75 74 76 75 77 76 78 //Input 77 79 const Graph& G; 78 80 const LengthMap& length; 81 const EdgeIntMap& capacity; 79 82 80 83 //auxiliary variables … … 83 86 //If the algorithm has finished, the edges of the seeked paths are 84 87 //exactly those that are reversed 85 EdgeIntMap reversed;88 EdgeIntMap flow; 86 89 87 90 //Container to store found paths … … 96 99 97 100 98 MinLengthPaths(Graph& _G, LengthMap& _length ) : G(_G),99 length(_length), reversed(_G)/*, dijkstra_dist(_G)*/{ }101 MinLengthPaths(Graph& _G, LengthMap& _length, EdgeIntMap& _cap) : G(_G), 102 length(_length), capacity(_cap), flow(_G)/*, dijkstra_dist(_G)*/{ } 100 103 101 104 … … 106 109 ///Otherwise it returns the number of found edge-disjoint paths from s to t. 107 110 int run(Node s, Node t, int k) { 108 ConstMap const1map(1); 109 110 111 //We need a residual graph, in which some of the edges are reversed 112 ResGraphType res_graph(G, const1map, reversed); 111 112 113 //We need a residual graph 114 ResGraphType res_graph(G, capacity, flow); 113 115 114 116 //Initialize the copy of the Dijkstra potential to zero 115 117 typename ResGraphType::template NodeMap<Length> dijkstra_dist(res_graph); 116 ModLengthMap mod_length(res_graph, reversed,length, dijkstra_dist);118 ModLengthMap mod_length(res_graph, length, dijkstra_dist); 117 119 118 120 Dijkstra<ResGraphType, ModLengthMap> dijkstra(res_graph, mod_length); … … 135 137 136 138 137 // Reversingthe sortest path139 //Augmenting on the sortest path 138 140 Node n=t; 139 141 Edge e; … … 141 143 e = dijkstra.pred(n); 142 144 n = dijkstra.predNode(n); 143 reversed[e] = 1-reversed[e];145 G.augment(e,1); 144 146 } 145 147 … … 147 149 } 148 150 151 /* 152 ///\TODO To be implemented later 153 149 154 //Let's find the paths 150 155 //We put the paths into stl vectors (as an inner representation). … … 176 181 177 182 } 183 */ 178 184 179 185 return i; … … 207 213 } //namespace hugo 208 214 209 #endif //HUGO_MIN LENGTHPATHS_H215 #endif //HUGO_MINCOSTFLOW_H -
src/work/athos/mincostflows_test.cc
r520 r527 1 1 #include <iostream> 2 2 #include <list_graph.h> 3 #include <minlengthpaths.h> 4 #include <path.h> 3 #include <mincostflows.h> 4 //#include <path.h> 5 #include <maps.h> 5 6 6 7 using namespace std; … … 61 62 length.set(v5_t, 8); 62 63 64 ConstMap const1map(1); 63 65 std::cout << "Minlengthpaths algorithm test..." << std::endl; 64 66 65 67 66 68 int k=3; 67 Min LengthPaths< ListGraph, ListGraph::EdgeMap<int> >68 surb_test(graph, length );69 MinCostFlows< ListGraph, ListGraph::EdgeMap<int> > 70 surb_test(graph, length, const1map); 69 71 70 72 check( surb_test.run(s,t,k) == 2 && surb_test.totalLength() == 46,"Two paths, total length should be 46");
Note: See TracChangeset
for help on using the changeset viewer.