Changeset 777:a82713ed19f3 in lemon-0.x for src/work/marci/bfs_dfs.h
- Timestamp:
- 08/31/04 19:54:22 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1070
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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;
Note: See TracChangeset
for help on using the changeset viewer.