Changeset 777:a82713ed19f3 in lemon-0.x for src
- Timestamp:
- 08/31/04 19:54:22 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1070
- Location:
- src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/hugo/graph_wrapper.h
r775 r777 182 182 Edge(typename Graph::EdgeIt(*(_gw.graph))), gw(&_gw) { } 183 183 EdgeIt(const GraphWrapper<Graph>& _gw, const Edge& e) : 184 Edge( w), gw(&_gw) { }184 Edge(e), gw(&_gw) { } 185 185 EdgeIt& operator++() { 186 186 *(static_cast<Edge*>(this))= … … 429 429 OutEdgeIt(Invalid i) : Edge(i) { } 430 430 OutEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw, const Node& n) : 431 Edge(typename Graph::OutEdgeIt(*(_gw.graph) ), n), gw(&_gw) { }431 Edge(typename Graph::OutEdgeIt(*(_gw.graph), n)), gw(&_gw) { } 432 432 OutEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw, 433 433 const Edge& e) : … … 451 451 InEdgeIt(Invalid i) : Edge(i) { } 452 452 InEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw, const Node& n) : 453 Edge(typename Graph::InEdgeIt(*(_gw.graph) ), n), gw(&_gw) { }453 Edge(typename Graph::InEdgeIt(*(_gw.graph), n)), gw(&_gw) { } 454 454 InEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw, 455 455 const Edge& e) : … … 2041 2041 // }; 2042 2042 typedef typename GraphWrapper<Graph>::Edge Edge; 2043 class OutEdgeIt {2043 class OutEdgeIt : public Edge { 2044 2044 friend class GraphWrapper<Graph>; 2045 2045 friend class ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>; 2046 // typedef typename Graph::OutEdgeIt GraphOutEdgeIt; 2047 typename Graph::OutEdgeIt e; 2046 const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>* gw; 2048 2047 public: 2049 2048 OutEdgeIt() { } 2050 OutEdgeIt(const typename Graph::OutEdgeIt& _e) : e(_e) { } 2051 OutEdgeIt(const Invalid& i) : e(i) { } 2052 OutEdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _G, 2053 const Node& _n) : 2054 e((*_G.first_out_edges)[_n]) { } 2055 operator Edge() const { return Edge(typename Graph::Edge(e)); } 2056 }; 2057 class InEdgeIt { 2058 friend class GraphWrapper<Graph>; 2059 friend class ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>; 2060 // typedef typename Graph::InEdgeIt GraphInEdgeIt; 2061 typename Graph::InEdgeIt e; 2062 public: 2063 InEdgeIt() { } 2064 InEdgeIt(const typename Graph::InEdgeIt& _e) : e(_e) { } 2065 InEdgeIt(const Invalid& i) : e(i) { } 2066 InEdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _G, 2067 const Node& _n) : 2068 e(*(_G.graph), typename Graph::Node(_n)) { } 2069 operator Edge() const { return Edge(typename Graph::Edge(e)); } 2070 }; 2049 //OutEdgeIt(const OutEdgeIt& e) : Edge(e), gw(e.gw) { } 2050 OutEdgeIt(Invalid i) : Edge(i) { } 2051 OutEdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _gw, 2052 const Node& n) : 2053 Edge((*(_gw.first_out_edges))[n]), gw(&_gw) { } 2054 OutEdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _gw, 2055 const Edge& e) : 2056 Edge(e), gw(&_gw) { } 2057 OutEdgeIt& operator++() { 2058 *(static_cast<Edge*>(this))= 2059 ++(typename Graph::OutEdgeIt(*(gw->graph), *this)); 2060 return *this; 2061 } 2062 }; 2063 // class InEdgeIt { 2064 // friend class GraphWrapper<Graph>; 2065 // friend class ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>; 2066 // // typedef typename Graph::InEdgeIt GraphInEdgeIt; 2067 // typename Graph::InEdgeIt e; 2068 // public: 2069 // InEdgeIt() { } 2070 // InEdgeIt(const typename Graph::InEdgeIt& _e) : e(_e) { } 2071 // InEdgeIt(const Invalid& i) : e(i) { } 2072 // InEdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _G, 2073 // const Node& _n) : 2074 // e(*(_G.graph), typename Graph::Node(_n)) { } 2075 // operator Edge() const { return Edge(typename Graph::Edge(e)); } 2076 // }; 2071 2077 //typedef typename Graph::SymEdgeIt SymEdgeIt; 2072 class EdgeIt {2073 friend class GraphWrapper<Graph>;2074 friend class ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>;2075 // typedef typename Graph::EdgeIt GraphEdgeIt;2076 typename Graph::EdgeIt e;2077 public:2078 EdgeIt() { }2079 EdgeIt(const typename Graph::EdgeIt& _e) : e(_e) { }2080 EdgeIt(const Invalid& i) : e(i) { }2081 EdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _G) :2082 e(*(_G.graph)) { }2083 operator Edge() const { return Edge(typename Graph::Edge(e)); }2084 };2078 // class EdgeIt { 2079 // friend class GraphWrapper<Graph>; 2080 // friend class ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>; 2081 // // typedef typename Graph::EdgeIt GraphEdgeIt; 2082 // typename Graph::EdgeIt e; 2083 // public: 2084 // EdgeIt() { } 2085 // EdgeIt(const typename Graph::EdgeIt& _e) : e(_e) { } 2086 // EdgeIt(const Invalid& i) : e(i) { } 2087 // EdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _G) : 2088 // e(*(_G.graph)) { } 2089 // operator Edge() const { return Edge(typename Graph::Edge(e)); } 2090 // }; 2085 2091 2086 2092 using GraphWrapper<Graph>::first; … … 2091 2097 i=OutEdgeIt(*this, p); return i; 2092 2098 } 2093 InEdgeIt& first(InEdgeIt& i, const Node& p) const {2094 i=InEdgeIt(*this, p); return i;2095 }2096 EdgeIt& first(EdgeIt& i) const {2097 i=EdgeIt(*this); return i;2098 }2099 2100 using GraphWrapper<Graph>::next;2101 // NodeIt& next(NodeIt& i) const { graph->next(i.n); return i; }2102 OutEdgeIt& next(OutEdgeIt& i) const { this->graph->next(i.e); return i; }2103 InEdgeIt& next(InEdgeIt& i) const { this->graph->next(i.e); return i; }2104 EdgeIt& next(EdgeIt& i) const { this->graph->next(i.e); return i; }2099 // InEdgeIt& first(InEdgeIt& i, const Node& p) const { 2100 // i=InEdgeIt(*this, p); return i; 2101 // } 2102 // EdgeIt& first(EdgeIt& i) const { 2103 // i=EdgeIt(*this); return i; 2104 // } 2105 2106 // using GraphWrapper<Graph>::next; 2107 // // NodeIt& next(NodeIt& i) const { graph->next(i.n); return i; } 2108 // OutEdgeIt& next(OutEdgeIt& i) const { this->graph->next(i.e); return i; } 2109 // InEdgeIt& next(InEdgeIt& i) const { this->graph->next(i.e); return i; } 2110 // EdgeIt& next(EdgeIt& i) const { this->graph->next(i.e); return i; } 2105 2111 2106 Node aNode(const OutEdgeIt& e) const { 2107 return Node(this->graph->aNode(e.e)); } 2108 Node aNode(const InEdgeIt& e) const { 2109 return Node(this->graph->aNode(e.e)); } 2110 Node bNode(const OutEdgeIt& e) const { 2111 return Node(this->graph->bNode(e.e)); } 2112 Node bNode(const InEdgeIt& e) const { 2113 return Node(this->graph->bNode(e.e)); } 2114 2115 void erase(const OutEdgeIt& e) const { 2116 OutEdgeIt f=e; 2117 this->next(f); 2118 first_out_edges->set(this->tail(e), f.e); 2112 // Node aNode(const OutEdgeIt& e) const { 2113 // return Node(this->graph->aNode(e.e)); } 2114 // Node aNode(const InEdgeIt& e) const { 2115 // return Node(this->graph->aNode(e.e)); } 2116 // Node bNode(const OutEdgeIt& e) const { 2117 // return Node(this->graph->bNode(e.e)); } 2118 // Node bNode(const InEdgeIt& e) const { 2119 // return Node(this->graph->bNode(e.e)); } 2120 2121 void erase(const Edge& e) const { 2122 Node n=tail(e); 2123 typename Graph::OutEdgeIt f(*graph, n); 2124 ++f; 2125 first_out_edges->set(n, f); 2119 2126 } 2120 2127 }; -
src/work/marci/augmenting_flow.h
r775 r777 12 12 #include <hugo/invalid.h> 13 13 #include <hugo/maps.h> 14 #include <for_each_macros.h>14 //#include <for_each_macros.h> 15 15 16 16 /// \file … … 1083 1083 Num flowValue() const { 1084 1084 Num a=0; 1085 FOR_EACH_INC_LOC(InEdgeIt, e, *g, t) a+=(*flow)[e];1086 FOR_EACH_INC_LOC(OutEdgeIt, e, *g, t) a-=(*flow)[e];1085 for (InEdgeIt e(*g, t); e!=INVALID; ++e) a+=(*flow)[e]; 1086 for (OutEdgeIt e(*g, t); e!=INVALID; ++e) a-=(*flow)[e]; 1087 1087 return a; 1088 1088 //marci figyu: excess[t] epp ezt adja preflow 1. fazisa utan … … 1122 1122 1123 1123 //ReachedMap level(res_graph); 1124 FOR_EACH_LOC(typename Graph::NodeIt, e, *g) level.set(e, 0);1124 for (typename Graph::NodeIt n(*g); n!=INVALID; ++n) level.set(n, 0); 1125 1125 BfsIterator<ResGW, ReachedMap> bfs(res_graph, level); 1126 1126 bfs.pushAndSetReached(s); … … 1133 1133 //searching for augmenting path 1134 1134 while ( !bfs.finished() ) { 1135 ResGW OutEdgeIte=bfs;1135 ResGWEdge e=bfs; 1136 1136 if (e!=INVALID && bfs.isBNodeNewlyReached()) { 1137 1137 Node v=res_graph.tail(e); … … 1170 1170 1171 1171 if (status!=AFTER_FAST_AUGMENTING) { 1172 FOR_EACH_LOC(typename Graph::NodeIt, e, *g) level.set(e, 0);1172 for (typename Graph::NodeIt n(*g); n!=INVALID; ++n) level.set(n, 0); 1173 1173 number_of_augmentations=1; 1174 1174 } else { … … 1190 1190 //searching for augmenting path 1191 1191 while ( !bfs.finished() ) { 1192 ResGW OutEdgeIte=bfs;1192 ResGWEdge e=bfs; 1193 1193 if (e!=INVALID && bfs.isBNodeNewlyReached()) { 1194 1194 Node v=res_graph.tail(e); … … 1232 1232 //bfs for distances on the residual graph 1233 1233 //ReachedMap level(res_graph); 1234 FOR_EACH_LOC(typename Graph::NodeIt, e, *g) level.set(e, 0);1234 for (typename Graph::NodeIt n(*g); n!=INVALID; ++n) level.set(n, 0); 1235 1235 BfsIterator<ResGW, ReachedMap> bfs(res_graph, level); 1236 1236 bfs.pushAndSetReached(s); … … 1256 1256 1257 1257 while ( !bfs.finished() ) { 1258 ResGW OutEdgeIte=bfs;1258 ResGWEdge e=bfs; 1259 1259 if (e!=INVALID) { 1260 1260 if (bfs.isBNodeNewlyReached()) { … … 1297 1297 if (F.valid(/*typename MG::OutEdgeIt*/(dfs))) { 1298 1298 if (dfs.isBNodeNewlyReached()) { 1299 typename MG::Node v=F. aNode(dfs);1300 typename MG::Node w=F. bNode(dfs);1299 typename MG::Node v=F.tail(dfs); 1300 typename MG::Node w=F.head(dfs); 1301 1301 pred.set(w, dfs); 1302 1302 if (pred[v]!=INVALID) { … … 1346 1346 1347 1347 //ReachedMap level(res_graph); 1348 FOR_EACH_LOC(typename Graph::NodeIt, e, *g) level.set(e, 0);1348 for (typename Graph::NodeIt n(*g); n!=INVALID; ++n) level.set(n, 0); 1349 1349 BfsIterator<ResGW, ReachedMap> bfs(res_graph, level); 1350 1350 … … 1352 1352 DistanceMap<ResGW> dist(res_graph); 1353 1353 while ( !bfs.finished() ) { 1354 ResGW OutEdgeIte=bfs;1354 ResGWEdge e=bfs; 1355 1355 if (e!=INVALID && bfs.isBNodeNewlyReached()) { 1356 1356 dist.set(res_graph.head(e), dist[res_graph.tail(e)]+1); … … 1359 1359 } //computing distances from s in the residual graph 1360 1360 1361 1361 //Subgraph containing the edges on some shortest paths 1362 1362 ConstMap<typename ResGW::Node, bool> true_map(true); 1363 1363 typedef SubGraphWrapper<ResGW, ConstMap<typename ResGW::Node, bool>, … … 1367 1367 //Subgraph, which is able to delete edges which are already 1368 1368 //met by the dfs 1369 typename FilterResGW::template NodeMap<typename FilterResGW:: OutEdgeIt>1369 typename FilterResGW::template NodeMap<typename FilterResGW::Edge> 1370 1370 first_out_edges(filter_res_graph); 1371 1371 typename FilterResGW::NodeIt v; 1372 1372 for(filter_res_graph.first(v); v!=INVALID; ++v) 1373 1373 { 1374 typename FilterResGW::OutEdgeIt e;1375 filter_res_graph.first(e, v);1376 first_out_edges.set(v, e);1374 typename FilterResGW::OutEdgeIt e; 1375 filter_res_graph.first(e, v); 1376 first_out_edges.set(v, e); 1377 1377 } 1378 1378 typedef ErasingFirstGraphWrapper<FilterResGW, typename FilterResGW:: 1379 template NodeMap<typename FilterResGW:: OutEdgeIt> > ErasingResGW;1379 template NodeMap<typename FilterResGW::Edge> > ErasingResGW; 1380 1380 ErasingResGW erasing_res_graph(filter_res_graph, first_out_edges); 1381 1381 … … 1390 1390 dfs(erasing_res_graph); 1391 1391 typename ErasingResGW:: 1392 template NodeMap<typename ErasingResGW::OutEdgeIt> 1393 pred(erasing_res_graph); 1392 template NodeMap<typename ErasingResGW::Edge> pred(erasing_res_graph); 1394 1393 pred.set(s, INVALID); 1395 1394 //invalid iterators for sources … … 1399 1398 1400 1399 dfs.pushAndSetReached 1401 /// \bug hugo 0.21400 /// \bug hugo 0.2 1402 1401 (typename ErasingResGW::Node 1403 1402 (typename FilterResGW::Node … … 1406 1405 ) 1407 1406 ); 1407 1408 1408 while (!dfs.finished()) { 1409 1409 ++dfs; 1410 if ( erasing_res_graph.valid(typename ErasingResGW::OutEdgeIt(dfs)))1410 if (typename ErasingResGW::Edge(dfs)!=INVALID) 1411 1411 { 1412 1412 if (dfs.isBNodeNewlyReached()) { 1413 1413 1414 typename ErasingResGW::Node v=erasing_res_graph. aNode(dfs);1415 typename ErasingResGW::Node w=erasing_res_graph. bNode(dfs);1416 1417 pred.set(w, /*typename ErasingResGW::OutEdgeIt*/(dfs));1414 typename ErasingResGW::Node v=erasing_res_graph.tail(dfs); 1415 typename ErasingResGW::Node w=erasing_res_graph.head(dfs); 1416 1417 pred.set(w, typename ErasingResGW::Edge(dfs)); 1418 1418 if (pred[v]!=INVALID) { 1419 1419 free1.set 1420 1420 (w, std::min(free1[v], res_graph.resCap 1421 (typename ErasingResGW:: OutEdgeIt(dfs))));1421 (typename ErasingResGW::Edge(dfs)))); 1422 1422 } else { 1423 1423 free1.set 1424 1424 (w, res_graph.resCap 1425 (typename ErasingResGW:: OutEdgeIt(dfs)));1425 (typename ErasingResGW::Edge(dfs))); 1426 1426 } 1427 1427 … … 1450 1450 // Num j2=a2[b2]; 1451 1451 Num augment_value=free1[n]; 1452 while ( erasing_res_graph.valid(pred[n])) {1453 typename ErasingResGW:: OutEdgeIte=pred[n];1452 while (pred[n]!=INVALID) { 1453 typename ErasingResGW::Edge e=pred[n]; 1454 1454 res_graph.augment(e, augment_value); 1455 1455 n=erasing_res_graph.tail(e); -
src/work/marci/bfs_dfs.h
r774 r777 28 28 protected: 29 29 typedef typename Graph::Node Node; 30 typedef typename Graph::Edge Edge; 30 31 typedef typename Graph::OutEdgeIt OutEdgeIt; 31 32 const Graph* graph; … … 33 34 ReachedMap& reached; 34 35 bool b_node_newly_reached; 35 OutEdgeItactual_edge;36 Edge actual_edge; 36 37 bool own_reached_map; 37 38 public: … … 56 57 /// and the first out-edge is processed. 57 58 /// If the queue is not empty, then \c s is simply pushed. 58 voidpushAndSetReached(Node s) {59 BfsIterator<Graph, /*OutEdgeIt,*/ ReachedMap>& pushAndSetReached(Node s) { 59 60 reached.set(s, true); 60 61 if (bfs_queue.empty()) { 61 62 bfs_queue.push(s); 62 graph->first(actual_edge, s); 63 actual_edge=OutEdgeIt(*graph, s); 64 //graph->first(actual_edge, s); 63 65 if (actual_edge!=INVALID) { 64 66 Node w=graph->head(actual_edge); … … 74 76 bfs_queue.push(s); 75 77 } 78 return *this; 76 79 } 77 80 /// As \c BfsIterator<Graph, ReachedMap> works as an edge-iterator, … … 80 83 operator++() { 81 84 if (actual_edge!=INVALID) { 82 ++actual_edge; 85 actual_edge=++OutEdgeIt(*graph, actual_edge); 86 //++actual_edge; 83 87 if (actual_edge!=INVALID) { 84 88 Node w=graph->head(actual_edge); … … 94 98 bfs_queue.pop(); 95 99 if (!bfs_queue.empty()) { 96 graph->first(actual_edge, bfs_queue.front()); 100 actual_edge=OutEdgeIt(*graph, bfs_queue.front()); 101 //graph->first(actual_edge, bfs_queue.front()); 97 102 if (actual_edge!=INVALID) { 98 103 Node w=graph->head(actual_edge); … … 114 119 /// to an \c out-edge-iterator. 115 120 ///\bug Edge have to be in HUGO 0.2 116 operator OutEdgeIt() const { return actual_edge; }121 operator Edge() const { return actual_edge; } 117 122 /// Returns if b-node has been reached just now. 118 123 bool isBNodeNewlyReached() const { return b_node_newly_reached; } … … 120 125 bool isANodeExamined() const { return actual_edge==INVALID; } 121 126 /// Returns a-node of the actual edge, so does if the edge is invalid. 122 Node aNode() const { return bfs_queue.front(); }127 Node tail() const { return bfs_queue.front(); } 123 128 /// \pre The actual edge have to be valid. 124 Node bNode() const { return graph->bNode(actual_edge); }129 Node head() const { return graph->head(actual_edge); } 125 130 /// Guess what? 126 131 /// \deprecated … … 160 165 /// in addition its pred is set to be \c INVALID, and dist to \c 0. 161 166 /// if \c s was marked previuosly, then it is simply pushed. 162 voidpush(Node s) {167 Bfs<Graph, ReachedMap, PredMap, DistMap>& push(Node s) { 163 168 if (this->reached[s]) { 164 169 Parent::pushAndSetReached(s); … … 168 173 dist.set(s, 0); 169 174 } 175 return *this; 170 176 } 171 177 /// A bfs is processed from \c s. 172 voidrun(Node s) {178 Bfs<Graph, ReachedMap, PredMap, DistMap>& run(Node s) { 173 179 push(s); 174 180 while (!this->finished()) this->operator++(); 181 return *this; 175 182 } 176 183 /// Beside the bfs iteration, \c pred and \dist are saved in a … … 180 187 if (this->graph->valid(this->actual_edge) && this->b_node_newly_reached) 181 188 { 182 pred.set(this-> bNode(), this->actual_edge);183 dist.set(this-> bNode(), dist[this->aNode()]);189 pred.set(this->head(), this->actual_edge); 190 dist.set(this->head(), dist[this->tail()]); 184 191 } 185 192 return *this; … … 202 209 protected: 203 210 typedef typename Graph::Node Node; 211 typedef typename Graph::Edge Edge; 204 212 typedef typename Graph::OutEdgeIt OutEdgeIt; 205 213 const Graph* graph; 206 214 std::stack<OutEdgeIt> dfs_stack; 207 215 bool b_node_newly_reached; 208 OutEdgeItactual_edge;216 Edge actual_edge; 209 217 Node actual_node; 210 218 ReachedMap& reached; … … 225 233 ~DfsIterator() { if (own_reached_map) delete &reached; } 226 234 /// This method markes s reached and first out-edge is processed. 227 voidpushAndSetReached(Node s) {235 DfsIterator<Graph, /*OutEdgeIt,*/ ReachedMap>& pushAndSetReached(Node s) { 228 236 actual_node=s; 229 237 reached.set(s, true); 230 OutEdgeIt e ;231 graph->first(e, s);238 OutEdgeIt e(*graph, s); 239 //graph->first(e, s); 232 240 dfs_stack.push(e); 241 return *this; 233 242 } 234 243 /// As \c DfsIterator<Graph, ReachedMap> works as an edge-iterator, … … 237 246 operator++() { 238 247 actual_edge=dfs_stack.top(); 239 //actual_node=G.aNode(actual_edge);240 248 if (actual_edge!=INVALID/*.valid()*/) { 241 249 Node w=graph->head(actual_edge); 242 250 actual_node=w; 243 251 if (!reached[w]) { 244 OutEdgeIt e ;245 graph->first(e, w);252 OutEdgeIt e(*graph, w); 253 //graph->first(e, w); 246 254 dfs_stack.push(e); 247 255 reached.set(w, true); … … 263 271 /// to an \c out-edge-iterator. 264 272 ///\bug Edge have to be in HUGO 0.2 265 operator OutEdgeIt() const { return actual_edge; }273 operator Edge() const { return actual_edge; } 266 274 /// Returns if b-node has been reached just now. 267 275 bool isBNodeNewlyReached() const { return b_node_newly_reached; } … … 269 277 bool isANodeExamined() const { return actual_edge==INVALID; } 270 278 /// Returns a-node of the actual edge, so does if the edge is invalid. 271 Node aNode() const { return actual_node; /*FIXME*/}279 Node tail() const { return actual_node; /*FIXME*/} 272 280 /// Returns b-node of the actual edge. 273 281 /// \pre The actual edge have to be valid. 274 Node bNode() const { return graph->bNode(actual_edge); }282 Node head() const { return graph->head(actual_edge); } 275 283 /// Guess what? 276 284 /// \deprecated … … 305 313 /// in addition its pred is set to be \c INVALID. 306 314 /// if \c s was marked previuosly, then it is simply pushed. 307 voidpush(Node s) {315 Dfs<Graph, ReachedMap, PredMap>& push(Node s) { 308 316 if (this->reached[s]) { 309 317 Parent::pushAndSetReached(s); … … 312 320 pred.set(s, INVALID); 313 321 } 322 return *this; 314 323 } 315 324 /// A bfs is processed from \c s. 316 voidrun(Node s) {325 Dfs<Graph, ReachedMap, PredMap>& run(Node s) { 317 326 push(s); 318 327 while (!this->finished()) this->operator++(); 328 return *this; 319 329 } 320 330 /// Beside the dfs iteration, \c pred is saved in a … … 324 334 if (this->graph->valid(this->actual_edge) && this->b_node_newly_reached) 325 335 { 326 pred.set(this-> bNode(), this->actual_edge);336 pred.set(this->head(), this->actual_edge); 327 337 } 328 338 return *this; -
src/work/marci/bfsit_vs_byhand.cc
r773 r777 34 34 cout << g.edgeNum() << endl; 35 35 36 Graph::NodeMap< OutEdgeIt> pred(g);36 Graph::NodeMap<Edge> pred(g); 37 37 cout << "iteration time of bfs written by hand..." << endl; 38 38 Timer ts; … … 70 70 ++bfs; 71 71 if (g.valid(bfs) && bfs.isBNodeNewlyReached()) 72 pred.set(bfs. bNode(), bfs);72 pred.set(bfs.head(), Graph::Edge(bfs)); 73 73 } 74 74 std::cout << ts << std::endl; -
src/work/marci/graph_wrapper_time.cc
r773 r777 1 1 // -*- c++ -*- 2 3 // Use a DIMACS max flow file as follows: 4 // graph_wrapper_time dimacs_max_flow_file 2 5 3 6 #include <iostream> … … 29 32 Timer ts; 30 33 ts.reset(); 31 cout << g.nodeNum() << endl; 32 cout << g.edgeNum() << endl; 34 33 35 typedef MaxFlow<Graph, int, FlowMap, FlowMap> MyMaxFlow; 34 36 MyMaxFlow max_flow(g, s, t, cap, flow); … … 42 44 typedef ListGraph Graph; 43 45 Graph g; 44 // cout << g.id(g.addNode()) << endl;45 // cout << g.id(g.addNode()) << endl;46 // cout << g.nodeNum() << endl;47 46 timeTest<Graph>(in, g); 48 47 typedef GraphWrapper<Graph> Graph1; 49 48 Graph1 g1(g); 50 // g1.clear();51 // cout << g.id(g1.addNode()) << endl;52 // cout << g.id(g1.addNode()) << endl;53 // cout << g1.nodeNum() << endl;54 // g1.clear();55 49 timeTest<Graph1>(in, g1); 56 50 typedef GraphWrapper<Graph1> Graph2; … … 60 54 Graph3 g3(g2); 61 55 timeTest<Graph3>(in, g3); 62 //typedef GraphWrapper<Graph3> Graph4;63 //Graph4 g4(g3);64 //timeTest<Graph4>(in, g4);65 //typedef GraphWrapper<Graph4> Graph5;66 //Graph5 g5(g4);67 //timeTest<Graph5>(in, g5);68 //typedef GraphWrapper<Graph5> Graph6;69 //Graph6 g6(g5);70 //timeTest<Graph6>(in, g6);71 //typedef GraphWrapper<Graph6> Graph7;72 //Graph7 g7(g6);73 //timeTest<Graph7>(in, g7);56 typedef GraphWrapper<Graph3> Graph4; 57 Graph4 g4(g3); 58 timeTest<Graph4>(in, g4); 59 typedef GraphWrapper<Graph4> Graph5; 60 Graph5 g5(g4); 61 timeTest<Graph5>(in, g5); 62 typedef GraphWrapper<Graph5> Graph6; 63 Graph6 g6(g5); 64 timeTest<Graph6>(in, g6); 65 typedef GraphWrapper<Graph6> Graph7; 66 Graph7 g7(g6); 67 timeTest<Graph7>(in, g7); 74 68 75 69 return 0; -
src/work/marci/iterator_bfs_demo.cc
r774 r777 10 10 11 11 using namespace hugo; 12 12 13 using std::cout; 13 14 using std::endl; … … 73 74 cout << " \\--> -------------> "<< endl; 74 75 75 // typedef TrivGraphWrapper<const Graph> CGW;76 // CGW gw(G);77 78 // cout << "bfs and dfs demo on the directed graph" << endl;79 // for(CGW::NodeIt n=gw.first<CGW::NodeIt>(); n.valid(); ++n) {80 // cout << n << ": ";81 // cout << "out edges: ";82 // for(CGW::OutEdgeIt e=gw.first<CGW::OutEdgeIt>(n); e.valid(); ++e)83 // cout << e << " ";84 // cout << "in edges: ";85 // for(CGW::InEdgeIt e=gw.first<CGW::InEdgeIt>(n); e.valid(); ++e)86 // cout << e << " ";87 // cout << endl;88 // }89 90 76 { 91 77 EdgeNameMap< Graph, Graph::NodeMap<string> > edge_name(G, node_name); … … 108 94 while (!bfs.finished()) { 109 95 //cout << "edge: "; 110 if (Graph::Edge( Graph::OutEdgeIt(bfs))!=INVALID) {96 if (Graph::Edge(bfs)!=INVALID) { 111 97 cout << edge_name[bfs] << /*endl*/", " << 112 98 node_name[G.tail(bfs)] << … … 117 103 } else { 118 104 cout << "invalid" << /*endl*/", " << 119 node_name[bfs. aNode()] <<105 node_name[bfs.tail()] << 120 106 (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 121 107 … … 142 128 ++dfs; 143 129 //cout << "edge: "; 144 if (Graph::Edge( Graph::OutEdgeIt(dfs))!=INVALID) {130 if (Graph::Edge(dfs)!=INVALID) { 145 131 cout << edge_name[dfs] << /*endl*/", " << 146 132 node_name[G.tail(dfs)] << … … 151 137 } else { 152 138 cout << "invalid" << /*endl*/", " << 153 node_name[dfs. aNode()] <<139 node_name[dfs.tail()] << 154 140 (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 155 141 … … 184 170 while (!bfs.finished()) { 185 171 //cout << "edge: "; 186 if (GW::Edge( GW::OutEdgeIt(bfs))!=INVALID) {187 cout << edge_name[GW:: OutEdgeIt(bfs)] << /*endl*/", " <<172 if (GW::Edge(bfs)!=INVALID) { 173 cout << edge_name[GW::Edge(bfs)] << /*endl*/", " << 188 174 node_name[gw.tail(bfs)] << 189 175 (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << … … 193 179 } else { 194 180 cout << "invalid" << /*endl*/", " << 195 node_name[bfs. aNode()] <<181 node_name[bfs.tail()] << 196 182 (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 197 183 … … 218 204 ++dfs; 219 205 //cout << "edge: "; 220 if (GW:: OutEdgeIt(dfs)!=INVALID) {221 cout << edge_name[GW:: OutEdgeIt(dfs)] << /*endl*/", " <<206 if (GW::Edge(dfs)!=INVALID) { 207 cout << edge_name[GW::Edge(dfs)] << /*endl*/", " << 222 208 node_name[gw.tail(dfs)] << 223 209 (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << … … 227 213 } else { 228 214 cout << "invalid" << /*endl*/", " << 229 node_name[dfs. aNode()] <<215 node_name[dfs.tail()] << 230 216 (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 231 217 … … 347 333 while (!bfs.finished()) { 348 334 //cout << "edge: "; 349 if (GW:: OutEdgeIt(bfs)!=INVALID) {350 cout << edge_name[GW:: OutEdgeIt(bfs)] << /*endl*/", " <<335 if (GW::Edge(bfs)!=INVALID) { 336 cout << edge_name[GW::Edge(bfs)] << /*endl*/", " << 351 337 node_name[gw.tail(bfs)] << 352 338 (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << … … 356 342 } else { 357 343 cout << "invalid" << /*endl*/", " << 358 node_name[bfs. aNode()] <<344 node_name[bfs.tail()] << 359 345 (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 360 346 … … 381 367 ++dfs; 382 368 //cout << "edge: "; 383 if (GW:: OutEdgeIt(dfs)!=INVALID) {384 cout << edge_name[GW:: OutEdgeIt(dfs)] << /*endl*/", " <<369 if (GW::Edge(dfs)!=INVALID) { 370 cout << edge_name[GW::Edge(dfs)] << /*endl*/", " << 385 371 node_name[gw.tail(dfs)] << 386 372 (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << … … 390 376 } else { 391 377 cout << "invalid" << /*endl*/", " << 392 node_name[dfs. aNode()] <<378 node_name[dfs.tail()] << 393 379 (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 394 380 -
src/work/marci/lg_vs_sg_vs_sg.cc
r762 r777 54 54 { 55 55 std::cout << "physical blocking flow augmentation ..." << std::endl; 56 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);56 for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0); 57 57 ts.reset(); 58 58 int i=0; … … 76 76 { 77 77 std::cout << "on-the-fly blocking flow augmentation ..." << std::endl; 78 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);78 for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0); 79 79 ts.reset(); 80 80 int i=0; … … 87 87 { 88 88 std::cout << "on-the-fly shortest path augmentation ..." << std::endl; 89 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);89 for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0); 90 90 ts.reset(); 91 91 int i=0; … … 122 122 { 123 123 std::cout << "preflow ..." << std::endl; 124 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);124 for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0); 125 125 ts.reset(); 126 126 max_flow_test.run(); … … 131 131 { 132 132 std::cout << "physical blocking flow augmentation ..." << std::endl; 133 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);133 for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0); 134 134 ts.reset(); 135 135 int i=0; … … 153 153 { 154 154 std::cout << "on-the-fly blocking flow augmentation ..." << std::endl; 155 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);155 for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0); 156 156 ts.reset(); 157 157 int i=0; … … 164 164 { 165 165 std::cout << "on-the-fly shortest path augmentation ..." << std::endl; 166 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);166 for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0); 167 167 ts.reset(); 168 168 int i=0; … … 199 199 { 200 200 std::cout << "preflow ..." << std::endl; 201 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);201 for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0); 202 202 ts.reset(); 203 203 max_flow_test.run(); … … 208 208 { 209 209 std::cout << "physical blocking flow augmentation ..." << std::endl; 210 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);210 for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0); 211 211 ts.reset(); 212 212 int i=0; … … 230 230 { 231 231 std::cout << "on-the-fly blocking flow augmentation ..." << std::endl; 232 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);232 for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0); 233 233 ts.reset(); 234 234 int i=0; … … 241 241 { 242 242 std::cout << "on-the-fly shortest path augmentation ..." << std::endl; 243 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);243 for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0); 244 244 ts.reset(); 245 245 int i=0; -
src/work/marci/max_flow_demo.cc
r775 r777 1 1 // -*- c++ -*- 2 3 // Use a DIMACS max flow file as stdin. 4 // max_flow_demo < dimacs_max_flow_file 5 6 2 7 #include <iostream> 3 8 #include <fstream> … … 15 20 16 21 using namespace hugo; 17 18 // Use a DIMACS max flow file as stdin.19 // max_flow_demo < dimacs_max_flow_file20 22 21 23 int main(int, char **) { … … 103 105 } 104 106 105 //{106 //std::cout << "on-the-fly blocking flow augmentation ..." << std::endl;107 //FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);108 //ts.reset();109 //int i=0;110 //while (augmenting_flow_test.augmentOnBlockingFlow2()) { ++i; }111 //std::cout << "elapsed time: " << ts << std::endl;112 //std::cout << "number of augmentation phases: " << i << std::endl;113 //std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;107 { 108 std::cout << "on-the-fly blocking flow augmentation ..." << std::endl; 109 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0); 110 ts.reset(); 111 int i=0; 112 while (augmenting_flow_test.augmentOnBlockingFlow2()) { ++i; } 113 std::cout << "elapsed time: " << ts << std::endl; 114 std::cout << "number of augmentation phases: " << i << std::endl; 115 std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl; 114 116 115 //FOR_EACH_LOC(Graph::EdgeIt, e, g) {116 //if (cut[g.tail(e)] && !cut[g.head(e)] && !flow[e]==cap[e])117 //std::cout << "Slackness does not hold!" << std::endl;118 //if (!cut[g.tail(e)] && cut[g.head(e)] && flow[e]>0)119 //std::cout << "Slackness does not hold!" << std::endl;120 //}121 //}117 FOR_EACH_LOC(Graph::EdgeIt, e, g) { 118 if (cut[g.tail(e)] && !cut[g.head(e)] && !flow[e]==cap[e]) 119 std::cout << "Slackness does not hold!" << std::endl; 120 if (!cut[g.tail(e)] && cut[g.head(e)] && flow[e]>0) 121 std::cout << "Slackness does not hold!" << std::endl; 122 } 123 } 122 124 123 125 {
Note: See TracChangeset
for help on using the changeset viewer.