Changeset 527:7550fed0cd91 in lemon-0.x for src/work/athos/mincostflows.h
- Timestamp:
- 05/04/04 16:54:21 (21 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@693
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.