Changeset 774:4297098d9677 in lemon-0.x for src
- Timestamp:
- 08/30/04 14:01:47 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1066
- Location:
- src
- Files:
-
- 2 added
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
src/benchmark/bfs-bench.cc
r751 r774 49 49 Node m; 50 50 Q.pop(); 51 for(OutEdgeIt e(G,n); G.valid(e);G.next(e))51 for(OutEdgeIt e(G,n);e!=INVALID;++e) 52 52 if(!visited[m=G.head(e)]) { 53 53 Q.push(m); … … 77 77 Node m; 78 78 Node n=Q[Qt++]; 79 for(OutEdgeIt e(G,n); G.valid(e);G.next(e))79 for(OutEdgeIt e(G,n);e!=INVALID;++e) 80 80 if(!visited[m=G.head(e)]) { 81 81 Q[Qh++]=m; … … 92 92 int i=0; 93 93 94 for(NodeIt n(G); G.valid(n);G.next(n))95 for(OutEdgeIt e(G,n); G.valid(e);G.next(e))94 for(NodeIt n(G);n!=INVALID;++n) 95 for(OutEdgeIt e(G,n);e!=INVALID;++e) 96 96 i++; 97 97 } -
src/hugo/Makefile.am
r731 r774 1 1 pkginclude_HEADERS = \ 2 bfs.h \ 2 3 bin_heap.h \ 3 4 dijkstra.h \ -
src/hugo/dijkstra.h
r758 r774 85 85 bool local_distance; 86 86 87 //The source node of the last execution. 88 Node source; 89 87 90 ///Initialize maps 88 91 … … 213 216 init_maps(); 214 217 215 for ( NodeIt u(*G) ; G->valid(u) ; G->next(u) ) { 218 source = s; 219 220 for ( NodeIt u(*G) ; u!=INVALID ; ++u ) { 216 221 predecessor->set(u,INVALID); 217 222 pred_node->set(u,INVALID); … … 236 241 237 242 238 for(OutEdgeIt e(*G,v); G->valid(e); G->next(e)) {239 Node w=G-> bNode(e);243 for(OutEdgeIt e(*G,v); e!=INVALID; ++e) { 244 Node w=G->head(e); 240 245 241 246 switch(heap.state(w)) { … … 311 316 312 317 ///Returns \c true if \c v is reachable from the root. 313 ///\warning the root node is reported to be unreached! 314 ///\todo Is this what we want? 318 ///\warning the root node is reported to be reached! 315 319 ///\pre \ref run() must be called before using this function. 316 320 /// 317 bool reached(Node v) { return G->valid((*predecessor)[v]); }321 bool reached(Node v) { return v==source || (*predecessor)[v]==INVALID; } 318 322 319 323 }; -
src/hugo/full_graph.h
r752 r774 64 64 Node head(Edge e) const { return e.n/NodeNum; } 65 65 66 Node aNode(OutEdgeIt e) const { return tail(e); }67 Node aNode(InEdgeIt e) const { return head(e); }68 69 Node bNode(OutEdgeIt e) const { return head(e); }70 Node bNode(InEdgeIt e) const { return tail(e); }71 72 66 NodeIt& first(NodeIt& v) const { 73 67 v=NodeIt(*this); return v; } … … 79 73 e=InEdgeIt(*this,v); return e; } 80 74 81 static bool valid(Edge e) { return e.n!=-1; }82 static bool valid(Node n) { return n.n!=-1; }83 84 template <typename It> It getNext(It it) const85 { It tmp(it); return next(tmp); }86 87 NodeIt& next(NodeIt& it) const {88 it.n=(it.n+2)%(NodeNum+1)-1;89 return it;90 }91 OutEdgeIt& next(OutEdgeIt& it) const92 { it.n+=NodeNum; if(it.n>=EdgeNum) it.n=-1; return it; }93 InEdgeIt& next(InEdgeIt& it) const94 { if(!((++it.n)%NodeNum)) it.n=-1; return it; }95 static EdgeIt& next(EdgeIt& it) { --it.n; return it; }96 97 75 static int id(Node v) { return v.n; } 98 76 static int id(Edge e) { return e.n; } 99 77 78 /// Finds an edge between two nodes. 79 80 /// Finds an edge from node \c u to node \c v. 81 /// 82 /// If \c prev is \ref INVALID (this is the default value), then 83 /// It finds the first edge from \c u to \c v. Otherwise it looks for 84 /// the next edge from \c u to \c v after \c prev. 85 /// \return The found edge or INVALID if there is no such an edge. 86 Edge findEdge(Node u,Node v, Edge prev = INVALID) 87 { 88 return prev.n==-1?Edge(*this,u.n,v.n):INVALID; 89 } 90 91 100 92 class Node { 101 93 friend class FullGraph; … … 120 112 121 113 class NodeIt : public Node { 114 const FullGraph *G; 122 115 friend class FullGraph; 123 116 public: 124 117 NodeIt() : Node() { } 118 NodeIt(const FullGraph& _G,Node n) : Node(n), G(&_G) { } 125 119 NodeIt(Invalid i) : Node(i) { } 126 NodeIt(const FullGraph& G) : Node(G.NodeNum?0:-1) { }120 NodeIt(const FullGraph& _G) : Node(_G.NodeNum?0:-1), G(&_G) { } 127 121 ///\todo Undocumented conversion Node -\> NodeIt. 128 NodeIt (const FullGraph& G, const Node &n) : Node(n) {}122 NodeIt& operator++() { n=(n+2)%(G->NodeNum+1)-1;return *this; } 129 123 }; 130 124 … … 139 133 friend int FullGraph::id(Edge e); 140 134 141 Edge(int nn) {n=nn;} 135 Edge(int nn) : n(nn) {} 136 Edge(const FullGraph &G, int tail, int head) : n(G.NodeNum*head+tail) {} 142 137 public: 143 138 Edge() { } … … 155 150 friend class FullGraph; 156 151 public: 157 EdgeIt(const FullGraph& G) : Edge(G.EdgeNum-1) { } 152 EdgeIt(const FullGraph& _G) : Edge(_G.EdgeNum-1) { } 153 EdgeIt(const FullGraph&, Edge e) : Edge(e) { } 158 154 EdgeIt (Invalid i) : Edge(i) { } 159 155 EdgeIt() : Edge() { } 156 EdgeIt& operator++() { --n; return *this; } 157 160 158 ///\bug This is a workaround until somebody tells me how to 161 159 ///make class \c SymFullGraph::SymEdgeMap friend of Edge … … 164 162 165 163 class OutEdgeIt : public Edge { 164 const FullGraph *G; 166 165 friend class FullGraph; 167 166 public: 168 167 OutEdgeIt() : Edge() { } 168 OutEdgeIt(const FullGraph& _G, Edge e) : Edge(e), G(&_G) { } 169 169 OutEdgeIt (Invalid i) : Edge(i) { } 170 170 171 OutEdgeIt(const FullGraph& G,const Node v) 172 : Edge(v.n) {} 171 OutEdgeIt(const FullGraph& _G,const Node v) : Edge(v.n), G(&_G) {} 172 173 OutEdgeIt& operator++() 174 { n+=G->NodeNum; if(n>=G->EdgeNum) n=-1; return *this; } 175 173 176 }; 174 177 175 178 class InEdgeIt : public Edge { 179 const FullGraph *G; 176 180 friend class FullGraph; 177 181 public: 178 182 InEdgeIt() : Edge() { } 183 InEdgeIt(const FullGraph& _G, Edge e) : Edge(e), G(&_G) { } 179 184 InEdgeIt (Invalid i) : Edge(i) { } 180 InEdgeIt(const FullGraph& G,Node v) :Edge(v.n*G.NodeNum){} 185 InEdgeIt(const FullGraph& _G,Node v) : Edge(v.n*_G.NodeNum), G(&_G) {} 186 InEdgeIt& operator++() 187 { if(!((++n)%G->NodeNum)) n=-1; return *this; } 181 188 }; 182 189 … … 280 287 return *this; 281 288 } 282 289 283 290 void update() {} 284 291 void update(T a) {} -
src/hugo/graph_wrapper.h
r739 r774 13 13 #include <hugo/invalid.h> 14 14 #include <hugo/maps.h> 15 //#include <iter_map.h>15 #include <iostream> 16 16 17 17 namespace hugo { … … 97 97 98 98 GraphWrapper(Graph& _graph) : graph(&_graph) { } 99 GraphWrapper(const GraphWrapper<Graph>& gw) : graph(gw.graph) { } 99 100 // Graph& getGraph() const { return *graph; } 100 101 101 // typedef typename Graph::Node Node; 102 class Node : public Graph::Node { 102 typedef typename Graph::Node Node; 103 // class Node : public Graph::Node { 104 // friend class GraphWrapper<Graph>; 105 // public: 106 // Node() { } 107 // Node(const typename Graph::Node& _n) : Graph::Node(_n) { } 108 // // /// \bug construction throughrthr multiple levels should be 109 // // /// handled better 110 // // Node(const typename ParentGraph::ParentGraph::Node& _n) : 111 // // Graph::Node(_n) { } 112 // Node(const Invalid& i) : Graph::Node(i) { } 113 // }; 114 class NodeIt : public Node { 115 const GraphWrapper<Graph>* gw; 103 116 friend class GraphWrapper<Graph>; 104 public:105 Node() { }106 Node(const typename Graph::Node& _n) : Graph::Node(_n) { }107 // /// \bug construction throughrthr multiple levels should be108 // /// handled better109 // Node(const typename ParentGraph::ParentGraph::Node& _n) :110 // Graph::Node(_n) { }111 Node(const Invalid& i) : Graph::Node(i) { }112 };113 class NodeIt {114 friend class GraphWrapper<Graph>;115 typename Graph::NodeIt n;116 117 public: 117 118 NodeIt() { } 118 NodeIt(const typename Graph::NodeIt& _n) : n(_n) { } 119 NodeIt(const Invalid& i) : n(i) { } 120 NodeIt(const GraphWrapper<Graph>& _G) : n(*(_G.graph)) { } 121 operator Node() const { return Node(typename Graph::Node(n)); } 122 }; 123 // typedef typename Graph::Edge Edge; 124 class Edge : public Graph::Edge { 119 // NodeIt(const NodeIt& n) : Node(n), gw(n.gw) { } 120 NodeIt(Invalid i) : Node(i) { } 121 NodeIt(const GraphWrapper<Graph>& _gw) : 122 Node(typename Graph::NodeIt(*(_gw.graph))), gw(&_gw) { } 123 NodeIt(const GraphWrapper<Graph>& _gw, const Node& n) : 124 Node(n), gw(&_gw) { } 125 NodeIt& operator++() { 126 *(static_cast<Node*>(this))= 127 ++(typename Graph::NodeIt(*(gw->graph), *this)); 128 return *this; 129 } 130 }; 131 typedef typename Graph::Edge Edge; 132 // class Edge : public Graph::Edge { 133 // friend class GraphWrapper<Graph>; 134 // public: 135 // Edge() { } 136 // Edge(const typename Graph::Edge& _e) : Graph::Edge(_e) { } 137 // Edge(const Invalid& i) : Graph::Edge(i) { } 138 // }; 139 class OutEdgeIt : public Edge { 140 const GraphWrapper<Graph>* gw; 125 141 friend class GraphWrapper<Graph>; 126 public: 127 Edge() { } 128 Edge(const typename Graph::Edge& _e) : Graph::Edge(_e) { } 129 Edge(const Invalid& i) : Graph::Edge(i) { } 130 }; 131 class OutEdgeIt { 142 public: 143 OutEdgeIt() { } 144 //OutEdgeIt(const OutEdgeIt& e) : Edge(e), gw(e.gw) { } 145 OutEdgeIt(Invalid i) : Edge(i) { } 146 OutEdgeIt(const GraphWrapper<Graph>& _gw, const Node& n) : 147 Edge(typename Graph::OutEdgeIt(*(_gw.graph), n)), gw(&_gw) { } 148 OutEdgeIt(const GraphWrapper<Graph>& _gw, const Edge& e) : 149 Edge(e), gw(&_gw) { } 150 OutEdgeIt& operator++() { 151 *(static_cast<Edge*>(this))= 152 ++(typename Graph::OutEdgeIt(*(gw->graph), *this)); 153 return *this; 154 } 155 }; 156 class InEdgeIt : public Edge { 157 const GraphWrapper<Graph>* gw; 132 158 friend class GraphWrapper<Graph>; 133 typename Graph::OutEdgeIt e; 134 public: 135 OutEdgeIt() { } 136 OutEdgeIt(const typename Graph::OutEdgeIt& _e) : e(_e) { } 137 OutEdgeIt(const Invalid& i) : e(i) { } 138 OutEdgeIt(const GraphWrapper<Graph>& _G, const Node& _n) : 139 e(*(_G.graph), typename Graph::Node(_n)) { } 140 operator Edge() const { return Edge(typename Graph::Edge(e)); } 141 }; 142 class InEdgeIt { 159 public: 160 InEdgeIt() { } 161 //InEdgeIt(const InEdgeIt& e) : Edge(e), gw(e.gw) { } 162 InEdgeIt(Invalid i) : Edge(i) { } 163 InEdgeIt(const GraphWrapper<Graph>& _gw, const Node& n) : 164 Edge(typename Graph::InEdgeIt(*(_gw.graph), n)), gw(&_gw) { } 165 InEdgeIt(const GraphWrapper<Graph>& _gw, const Edge& e) : 166 Edge(e), gw(&_gw) { } 167 InEdgeIt& operator++() { 168 *(static_cast<Edge*>(this))= 169 ++(typename Graph::InEdgeIt(*(gw->graph), *this)); 170 return *this; 171 } 172 }; 173 //typedef typename Graph::SymEdgeIt SymEdgeIt; 174 class EdgeIt : public Edge { 175 const GraphWrapper<Graph>* gw; 143 176 friend class GraphWrapper<Graph>; 144 typename Graph::InEdgeIt e; 145 public: 146 InEdgeIt() { } 147 InEdgeIt(const typename Graph::InEdgeIt& _e) : e(_e) { } 148 InEdgeIt(const Invalid& i) : e(i) { } 149 InEdgeIt(const GraphWrapper<Graph>& _G, const Node& _n) : 150 e(*(_G.graph), typename Graph::Node(_n)) { } 151 operator Edge() const { return Edge(typename Graph::Edge(e)); } 152 }; 153 //typedef typename Graph::SymEdgeIt SymEdgeIt; 154 class EdgeIt { 155 friend class GraphWrapper<Graph>; 156 typename Graph::EdgeIt e; 157 public: 177 public: 158 178 EdgeIt() { } 159 EdgeIt(const typename Graph::EdgeIt& _e) : e(_e) { } 160 EdgeIt(const Invalid& i) : e(i) { } 161 EdgeIt(const GraphWrapper<Graph>& _G) : e(*(_G.graph)) { } 162 operator Edge() const { return Edge(typename Graph::Edge(e)); } 179 //EdgeIt(const EdgeIt& e) : Edge(e), gw(e.gw) { } 180 EdgeIt(Invalid i) : Edge(i) { } 181 EdgeIt(const GraphWrapper<Graph>& _gw) : 182 Edge(typename Graph::EdgeIt(*(_gw.graph))), gw(&_gw) { } 183 EdgeIt(const GraphWrapper<Graph>& _gw, const Edge& e) : 184 Edge(w), gw(&_gw) { } 185 EdgeIt& operator++() { 186 *(static_cast<Edge*>(this))= 187 ++(typename Graph::EdgeIt(*(gw->graph), *this)); 188 return *this; 189 } 163 190 }; 164 191 … … 176 203 } 177 204 178 NodeIt& next(NodeIt& i) const { graph->next(i.n); return i; }179 OutEdgeIt& next(OutEdgeIt& i) const { graph->next(i.e); return i; }180 InEdgeIt& next(InEdgeIt& i) const { graph->next(i.e); return i; }181 EdgeIt& next(EdgeIt& i) const { graph->next(i.e); return i; }205 // NodeIt& next(NodeIt& i) const { graph->next(i.n); return i; } 206 // OutEdgeIt& next(OutEdgeIt& i) const { graph->next(i.e); return i; } 207 // InEdgeIt& next(InEdgeIt& i) const { graph->next(i.e); return i; } 208 // EdgeIt& next(EdgeIt& i) const { graph->next(i.e); return i; } 182 209 183 210 Node tail(const Edge& e) const { … … 186 213 return Node(graph->head(static_cast<typename Graph::Edge>(e))); } 187 214 188 bool valid(const Node& n) const {189 return graph->valid(static_cast<typename Graph::Node>(n)); }190 bool valid(const Edge& e) const {191 return graph->valid(static_cast<typename Graph::Edge>(e)); }215 // bool valid(const Node& n) const { 216 // return graph->valid(static_cast<typename Graph::Node>(n)); } 217 // bool valid(const Edge& e) const { 218 // return graph->valid(static_cast<typename Graph::Edge>(e)); } 192 219 193 220 int nodeNum() const { return graph->nodeNum(); } 194 221 int edgeNum() const { return graph->edgeNum(); } 195 222 196 Node aNode(const OutEdgeIt& e) const { return Node(graph->aNode(e.e)); }197 Node aNode(const InEdgeIt& e) const { return Node(graph->aNode(e.e)); }198 Node bNode(const OutEdgeIt& e) const { return Node(graph->bNode(e.e)); }199 Node bNode(const InEdgeIt& e) const { return Node(graph->bNode(e.e)); }223 // Node aNode(const OutEdgeIt& e) const { return Node(graph->aNode(e.e)); } 224 // Node aNode(const InEdgeIt& e) const { return Node(graph->aNode(e.e)); } 225 // Node bNode(const OutEdgeIt& e) const { return Node(graph->bNode(e.e)); } 226 // Node bNode(const InEdgeIt& e) const { return Node(graph->bNode(e.e)); } 200 227 201 228 Node addNode() const { return Node(graph->addNode()); } … … 219 246 typedef typename Graph::template NodeMap<T> Parent; 220 247 public: 221 NodeMap(const GraphWrapper<Graph>& _G) : Parent(*(_G.graph)) { }222 NodeMap(const GraphWrapper<Graph>& _G, T a) : Parent(*(_G.graph), a) { }248 NodeMap(const GraphWrapper<Graph>& gw) : Parent(*(gw.graph)) { } 249 NodeMap(const GraphWrapper<Graph>& gw, T a) : Parent(*(gw.graph), a) { } 223 250 }; 224 251 … … 226 253 typedef typename Graph::template EdgeMap<T> Parent; 227 254 public: 228 EdgeMap(const GraphWrapper<Graph>& _G) : Parent(*(_G.graph)) { }229 EdgeMap(const GraphWrapper<Graph>& _G, T a) : Parent(*(_G.graph), a) { }255 EdgeMap(const GraphWrapper<Graph>& gw) : Parent(*(gw.graph)) { } 256 EdgeMap(const GraphWrapper<Graph>& gw, T a) : Parent(*(gw.graph), a) { } 230 257 }; 231 258 }; … … 247 274 public: 248 275 RevGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { } 276 RevGraphWrapper(const RevGraphWrapper<Graph>& gw) : Parent(gw) { } 249 277 250 278 typedef typename GraphWrapper<Graph>::Node Node; … … 257 285 //typedef typename GraphWrapper<Graph>::InEdgeIt OutEdgeIt; 258 286 259 class OutEdgeIt { 287 class OutEdgeIt : public Edge { 288 const RevGraphWrapper<Graph>* gw; 260 289 friend class GraphWrapper<Graph>; 261 friend class RevGraphWrapper<Graph>; 262 typename Graph::InEdgeIt e; 263 public: 290 public: 264 291 OutEdgeIt() { } 265 OutEdgeIt(const typename Graph::InEdgeIt& _e) : e(_e) { } 266 OutEdgeIt(const Invalid& i) : e(i) { } 267 OutEdgeIt(const RevGraphWrapper<Graph>& _G, const Node& _n) : 268 e(*(_G.graph), typename Graph::Node(_n)) { } 269 operator Edge() const { return Edge(typename Graph::Edge(e)); } 270 }; 271 class InEdgeIt { 292 //OutEdgeIt(const OutEdgeIt& e) : Edge(e), gw(e.gw) { } 293 OutEdgeIt(Invalid i) : Edge(i) { } 294 OutEdgeIt(const RevGraphWrapper<Graph>& _gw, const Node& n) : 295 Edge(typename Graph::InEdgeIt(*(_gw.graph), n)), gw(&_gw) { } 296 OutEdgeIt(const RevGraphWrapper<Graph>& _gw, const Edge& e) : 297 Edge(e), gw(&_gw) { } 298 OutEdgeIt& operator++() { 299 *(static_cast<Edge*>(this))= 300 ++(typename Graph::InEdgeIt(*(gw->graph), *this)); 301 return *this; 302 } 303 }; 304 class InEdgeIt : public Edge { 305 const RevGraphWrapper<Graph>* gw; 272 306 friend class GraphWrapper<Graph>; 273 friend class RevGraphWrapper<Graph>; 274 typename Graph::OutEdgeIt e; 275 public: 307 public: 276 308 InEdgeIt() { } 277 InEdgeIt(const typename Graph::OutEdgeIt& _e) : e(_e) { } 278 InEdgeIt(const Invalid& i) : e(i) { } 279 InEdgeIt(const RevGraphWrapper<Graph>& _G, const Node& _n) : 280 e(*(_G.graph), typename Graph::Node(_n)) { } 281 operator Edge() const { return Edge(typename Graph::Edge(e)); } 309 //InEdgeIt(const InEdgeIt& e) : Edge(e), gw(e.gw) { } 310 InEdgeIt(Invalid i) : Edge(i) { } 311 InEdgeIt(const RevGraphWrapper<Graph>& _gw, const Node& n) : 312 Edge(typename Graph::OutEdgeIt(*(_gw.graph), n)), gw(&_gw) { } 313 InEdgeIt(const RevGraphWrapper<Graph>& _gw, const Edge& e) : 314 Edge(e), gw(&_gw) { } 315 InEdgeIt& operator++() { 316 *(static_cast<Edge*>(this))= 317 ++(typename Graph::OutEdgeIt(*(gw->graph), *this)); 318 return *this; 319 } 282 320 }; 283 321 … … 290 328 } 291 329 292 using GraphWrapper<Graph>::next;293 OutEdgeIt& next(OutEdgeIt& i) const { this->graph->next(i.e); return i; }294 InEdgeIt& next(InEdgeIt& i) const { this->graph->next(i.e); return i; }295 296 Node aNode(const OutEdgeIt& e) const {297 return Node(this->graph->aNode(e.e)); }298 Node aNode(const InEdgeIt& e) const {299 return Node(this->graph->aNode(e.e)); }300 Node bNode(const OutEdgeIt& e) const {301 return Node(this->graph->bNode(e.e)); }302 Node bNode(const InEdgeIt& e) const {303 return Node(this->graph->bNode(e.e)); }330 // using GraphWrapper<Graph>::next; 331 // OutEdgeIt& next(OutEdgeIt& i) const { this->graph->next(i.e); return i; } 332 // InEdgeIt& next(InEdgeIt& i) const { this->graph->next(i.e); return i; } 333 334 // Node aNode(const OutEdgeIt& e) const { 335 // return Node(this->graph->aNode(e.e)); } 336 // Node aNode(const InEdgeIt& e) const { 337 // return Node(this->graph->aNode(e.e)); } 338 // Node bNode(const OutEdgeIt& e) const { 339 // return Node(this->graph->bNode(e.e)); } 340 // Node bNode(const InEdgeIt& e) const { 341 // return Node(this->graph->bNode(e.e)); } 304 342 305 343 Node tail(const Edge& e) const { … … 309 347 310 348 }; 311 312 313 349 314 350 /// A graph wrapper for hiding nodes and edges from a graph. … … 627 663 typedef GraphWrapper<Graph> Parent; 628 664 protected: 629 //const CapacityMap* capacity;630 //FlowMap* flow;631 632 665 ForwardFilterMap* forward_filter; 633 666 BackwardFilterMap* backward_filter; … … 648 681 GraphWrapper<Graph>(_graph), 649 682 forward_filter(&_forward_filter), backward_filter(&_backward_filter) { } 683 SubBidirGraphWrapper(const SubBidirGraphWrapper<Graph, 684 ForwardFilterMap, BackwardFilterMap>& gw) : 685 Parent(gw), 686 forward_filter(gw.forward_filter), 687 backward_filter(gw.backward_filter) { } 650 688 651 689 class Edge; … … 658 696 659 697 typedef typename GraphWrapper<Graph>::Node Node; 660 typedef typename GraphWrapper<Graph>::NodeIt NodeIt; 661 698 //typedef typename GraphWrapper<Graph>::NodeIt NodeIt; 699 700 typedef typename Graph::Edge GraphEdge; 662 701 class Edge : public Graph::Edge { 663 702 friend class SubBidirGraphWrapper<Graph, … … 672 711 Edge() { } 673 712 ///\bug =false kell-e? zsoltnak kell az addEdge miatt 674 Edge(const typename Graph::Edge& _e, bool _backward=false) :675 Graph::Edge( _e), backward(_backward) { }676 Edge( const Invalid&i) : Graph::Edge(i), backward(true) { }713 Edge(const typename Graph::Edge& e, bool _backward/*=false*/) : 714 Graph::Edge(e), backward(_backward) { } 715 Edge(Invalid i) : Graph::Edge(i), backward(true) { } 677 716 //the unique invalid iterator 678 friend bool operator==(const Edge& u, const Edge& v) { 679 return (v.backward==u.backward && 680 static_cast<typename Graph::Edge>(u)== 717 // friend bool operator==(const Edge& u, const Edge& v) { 718 // return (u.backward==v.backward && 719 // static_cast<typename Graph::Edge>(u)== 720 // static_cast<typename Graph::Edge>(v)); 721 // } 722 // friend bool operator!=(const Edge& u, const Edge& v) { 723 // return (u.backward!=v.backward || 724 // static_cast<typename Graph::Edge>(u)!= 725 // static_cast<typename Graph::Edge>(v)); 726 // } 727 bool operator==(const Edge& v) const { 728 return (this->backward==v.backward && 729 static_cast<typename Graph::Edge>(*this)== 681 730 static_cast<typename Graph::Edge>(v)); 682 731 } 683 friend bool operator!=(const Edge& u, const Edge& v){684 return ( v.backward!=u.backward ||685 static_cast<typename Graph::Edge>( u)!=732 bool operator!=(const Edge& v) const { 733 return (this->backward!=v.backward || 734 static_cast<typename Graph::Edge>(*this)!= 686 735 static_cast<typename Graph::Edge>(v)); 687 } 688 }; 689 690 class OutEdgeIt {736 } 737 }; 738 739 class OutEdgeIt : public Edge { 691 740 friend class SubBidirGraphWrapper<Graph, 692 741 ForwardFilterMap, BackwardFilterMap>; 693 742 protected: 694 typename Graph::OutEdgeIt out; 695 typename Graph::InEdgeIt in; 696 bool backward; 743 const SubBidirGraphWrapper<Graph, 744 ForwardFilterMap, BackwardFilterMap>* gw; 697 745 public: 698 746 OutEdgeIt() { } 699 //FIXME 700 // OutEdgeIt(const Edge& e) : Edge(e) { } 701 OutEdgeIt(const Invalid& i) : out(i), in(i), backward(true) { } 747 OutEdgeIt(Invalid i) : Edge(i) { } 702 748 //the unique invalid iterator 703 749 OutEdgeIt(const SubBidirGraphWrapper<Graph, 704 ForwardFilterMap, BackwardFilterMap>& _G, Node v) { 705 backward=false; 706 _G.graph->first(out, v); 707 while(_G.graph->valid(out) && !(*_G.forward_filter)[*this]) { _G.graph->next(out); } 708 if (!_G.graph->valid(out)) { 709 backward=true; 710 _G.graph->first(in, v); 711 while(_G.graph->valid(in) && !(*_G.backward_filter)[*this]) { _G.graph->next(in); } 750 ForwardFilterMap, BackwardFilterMap>& _gw, const Node& n) : 751 Edge(typename Graph::OutEdgeIt(*(_gw.graph), n), false), gw(&_gw) { 752 while (*static_cast<GraphEdge*>(this)!=INVALID && 753 !(*(gw->forward_filter))[*this]) 754 *(static_cast<GraphEdge*>(this))= 755 ++(typename Graph::OutEdgeIt(*(gw->graph), *this)); 756 if (*static_cast<GraphEdge*>(this)==INVALID) 757 *static_cast<Edge*>(this)= 758 Edge(typename Graph::InEdgeIt(*(_gw.graph), n), true); 759 while (*static_cast<GraphEdge*>(this)!=INVALID && 760 !(*(gw->backward_filter))[*this]) 761 *(static_cast<GraphEdge*>(this))= 762 ++(typename Graph::InEdgeIt(*(gw->graph), *this)); 763 } 764 OutEdgeIt(const SubBidirGraphWrapper<Graph, 765 ForwardFilterMap, BackwardFilterMap>& _gw, const Edge& e) : 766 Edge(e), gw(&_gw) { } 767 OutEdgeIt& operator++() { 768 if (!this->backward) { 769 Node n=gw->tail(*this); 770 *(static_cast<GraphEdge*>(this))= 771 ++(typename Graph::OutEdgeIt(*(gw->graph), *this)); 772 while (*static_cast<GraphEdge*>(this)!=INVALID && 773 !(*(gw->forward_filter))[*this]) 774 *(static_cast<GraphEdge*>(this))= 775 ++(typename Graph::OutEdgeIt(*(gw->graph), *this)); 776 if (*static_cast<GraphEdge*>(this)==INVALID) 777 *static_cast<Edge*>(this)= 778 Edge(typename Graph::InEdgeIt(*(gw->graph), n), true); 779 while (*static_cast<GraphEdge*>(this)!=INVALID && 780 !(*(gw->backward_filter))[*this]) 781 *(static_cast<GraphEdge*>(this))= 782 ++(typename Graph::InEdgeIt(*(gw->graph), *this)); 783 } else { 784 *(static_cast<GraphEdge*>(this))= 785 ++(typename Graph::InEdgeIt(*(gw->graph), *this)); 786 while (*static_cast<GraphEdge*>(this)!=INVALID && 787 !(*(gw->backward_filter))[*this]) 788 *(static_cast<GraphEdge*>(this))= 789 ++(typename Graph::InEdgeIt(*(gw->graph), *this)); 712 790 } 713 } 714 operator Edge() const { 715 // Edge e; 716 // e.forward=this->forward; 717 // if (this->forward) e=out; else e=in; 718 // return e; 719 if (this->backward) 720 return Edge(in, this->backward); 721 else 722 return Edge(out, this->backward); 723 } 724 }; 725 726 class InEdgeIt { 791 return *this; 792 } 793 }; 794 795 class InEdgeIt : public Edge { 727 796 friend class SubBidirGraphWrapper<Graph, 728 797 ForwardFilterMap, BackwardFilterMap>; 729 798 protected: 730 typename Graph::OutEdgeIt out; 731 typename Graph::InEdgeIt in; 732 bool backward; 799 const SubBidirGraphWrapper<Graph, 800 ForwardFilterMap, BackwardFilterMap>* gw; 733 801 public: 734 802 InEdgeIt() { } 735 //FIXME 736 // OutEdgeIt(const Edge& e) : Edge(e) { } 737 InEdgeIt(const Invalid& i) : out(i), in(i), backward(true) { } 803 InEdgeIt(Invalid i) : Edge(i) { } 738 804 //the unique invalid iterator 739 805 InEdgeIt(const SubBidirGraphWrapper<Graph, 740 ForwardFilterMap, BackwardFilterMap>& _G, Node v) { 741 backward=false; 742 _G.graph->first(in, v); 743 while(_G.graph->valid(in) && !(*_G.forward_filter)[*this]) { _G.graph->next(in); } 744 if (!_G.graph->valid(in)) { 745 backward=true; 746 _G.graph->first(out, v); 747 while(_G.graph->valid(out) && !(*_G.backward_filter)[*this]) { _G.graph->next(out); } 806 ForwardFilterMap, BackwardFilterMap>& _gw, const Node& n) : 807 Edge(typename Graph::InEdgeIt(*(_gw.graph), n), false), gw(&_gw) { 808 while (*static_cast<GraphEdge*>(this)!=INVALID && 809 !(*(gw->forward_filter))[*this]) 810 *(static_cast<GraphEdge*>(this))= 811 ++(typename Graph::InEdgeIt(*(gw->graph), *this)); 812 if (*static_cast<GraphEdge*>(this)==INVALID) 813 *static_cast<Edge*>(this)= 814 Edge(typename Graph::OutEdgeIt(*(_gw.graph), n), true); 815 while (*static_cast<GraphEdge*>(this)!=INVALID && 816 !(*(gw->backward_filter))[*this]) 817 *(static_cast<GraphEdge*>(this))= 818 ++(typename Graph::OutEdgeIt(*(gw->graph), *this)); 819 } 820 InEdgeIt(const SubBidirGraphWrapper<Graph, 821 ForwardFilterMap, BackwardFilterMap>& _gw, const Edge& e) : 822 Edge(e), gw(&_gw) { } 823 InEdgeIt& operator++() { 824 if (!this->backward) { 825 Node n=gw->head(*this); 826 *(static_cast<GraphEdge*>(this))= 827 ++(typename Graph::InEdgeIt(*(gw->graph), *this)); 828 while (*static_cast<GraphEdge*>(this)!=INVALID && 829 !(*(gw->forward_filter))[*this]) 830 *(static_cast<GraphEdge*>(this))= 831 ++(typename Graph::InEdgeIt(*(gw->graph), *this)); 832 if (*static_cast<GraphEdge*>(this)==INVALID) 833 *static_cast<Edge*>(this)= 834 Edge(typename Graph::OutEdgeIt(*(gw->graph), n), true); 835 while (*static_cast<GraphEdge*>(this)!=INVALID && 836 !(*(gw->backward_filter))[*this]) 837 *(static_cast<GraphEdge*>(this))= 838 ++(typename Graph::OutEdgeIt(*(gw->graph), *this)); 839 } else { 840 *(static_cast<GraphEdge*>(this))= 841 ++(typename Graph::OutEdgeIt(*(gw->graph), *this)); 842 while (*static_cast<GraphEdge*>(this)!=INVALID && 843 !(*(gw->backward_filter))[*this]) 844 *(static_cast<GraphEdge*>(this))= 845 ++(typename Graph::OutEdgeIt(*(gw->graph), *this)); 748 846 } 749 } 750 operator Edge() const { 751 // Edge e; 752 // e.forward=this->forward; 753 // if (this->forward) e=out; else e=in; 754 // return e; 755 if (this->backward) 756 return Edge(out, this->backward); 757 else 758 return Edge(in, this->backward); 759 } 760 }; 761 762 class EdgeIt { 847 return *this; 848 } 849 }; 850 851 class EdgeIt : public Edge { 763 852 friend class SubBidirGraphWrapper<Graph, 764 853 ForwardFilterMap, BackwardFilterMap>; 765 854 protected: 766 typename Graph::EdgeIt e;767 bool backward;855 const SubBidirGraphWrapper<Graph, 856 ForwardFilterMap, BackwardFilterMap>* gw; 768 857 public: 769 858 EdgeIt() { } 770 EdgeIt(const Invalid& i) : e(i), backward(true) { } 859 EdgeIt(Invalid i) : Edge(i) { } 860 //the unique invalid iterator 771 861 EdgeIt(const SubBidirGraphWrapper<Graph, 772 ForwardFilterMap, BackwardFilterMap>& _G) { 773 backward=false; 774 _G.graph->first(e); 775 while (_G.graph->valid(e) && !(*_G.forward_filter)[*this]) _G.graph->next(e); 776 if (!_G.graph->valid(e)) { 777 backward=true; 778 _G.graph->first(e); 779 while (_G.graph->valid(e) && !(*_G.backward_filter)[*this]) _G.graph->next(e); 862 ForwardFilterMap, BackwardFilterMap>& _gw) : 863 Edge(typename Graph::EdgeIt(*(_gw.graph)), false), gw(&_gw) { 864 while (*static_cast<GraphEdge*>(this)!=INVALID && 865 !(*(gw->forward_filter))[*this]) 866 *(static_cast<GraphEdge*>(this))= 867 ++(typename Graph::EdgeIt(*(gw->graph), *this)); 868 if (*static_cast<GraphEdge*>(this)==INVALID) 869 *static_cast<Edge*>(this)= 870 Edge(typename Graph::EdgeIt(*(_gw.graph)), true); 871 while (*static_cast<GraphEdge*>(this)!=INVALID && 872 !(*(gw->backward_filter))[*this]) 873 *(static_cast<GraphEdge*>(this))= 874 ++(typename Graph::EdgeIt(*(gw->graph), *this)); 875 } 876 EdgeIt(const SubBidirGraphWrapper<Graph, 877 ForwardFilterMap, BackwardFilterMap>& _gw, const Edge& e) : 878 Edge(e), gw(&_gw) { } 879 EdgeIt& operator++() { 880 if (!this->backward) { 881 *(static_cast<GraphEdge*>(this))= 882 ++(typename Graph::EdgeIt(*(gw->graph), *this)); 883 while (*static_cast<GraphEdge*>(this)!=INVALID && 884 !(*(gw->forward_filter))[*this]) 885 *(static_cast<GraphEdge*>(this))= 886 ++(typename Graph::EdgeIt(*(gw->graph), *this)); 887 if (*static_cast<GraphEdge*>(this)==INVALID) 888 *static_cast<Edge*>(this)= 889 Edge(typename Graph::EdgeIt(*(gw->graph)), true); 890 while (*static_cast<GraphEdge*>(this)!=INVALID && 891 !(*(gw->backward_filter))[*this]) 892 *(static_cast<GraphEdge*>(this))= 893 ++(typename Graph::EdgeIt(*(gw->graph), *this)); 894 } else { 895 *(static_cast<GraphEdge*>(this))= 896 ++(typename Graph::EdgeIt(*(gw->graph), *this)); 897 while (*static_cast<GraphEdge*>(this)!=INVALID && 898 !(*(gw->backward_filter))[*this]) 899 *(static_cast<GraphEdge*>(this))= 900 ++(typename Graph::EdgeIt(*(gw->graph), *this)); 780 901 } 781 } 782 operator Edge() const { 783 return Edge(e, this->backward); 902 return *this; 784 903 } 785 904 }; … … 800 919 } 801 920 802 using GraphWrapper<Graph>::next;803 // NodeIt& next(NodeIt& n) const { GraphWrapper<Graph>::next(n); return n; }804 OutEdgeIt& next(OutEdgeIt& e) const {805 if (!e.backward) {806 Node v=this->graph->aNode(e.out);807 this->graph->next(e.out);808 while(this->graph->valid(e.out) && !(*forward_filter)[e]) {809 this->graph->next(e.out); }810 if (!this->graph->valid(e.out)) {811 e.backward=true;812 this->graph->first(e.in, v);813 while(this->graph->valid(e.in) && !(*backward_filter)[e]) {814 this->graph->next(e.in); }815 }816 } else {817 this->graph->next(e.in);818 while(this->graph->valid(e.in) && !(*backward_filter)[e]) {819 this->graph->next(e.in); }820 }821 return e;822 }823 // FIXME Not tested824 InEdgeIt& next(InEdgeIt& e) const {825 if (!e.backward) {826 Node v=this->graph->aNode(e.in);827 this->graph->next(e.in);828 while(this->graph->valid(e.in) && !(*forward_filter)[e]) {829 this->graph->next(e.in); }830 if (!this->graph->valid(e.in)) {831 e.backward=true;832 this->graph->first(e.out, v);833 while(this->graph->valid(e.out) && !(*backward_filter)[e]) {834 this->graph->next(e.out); }835 }836 } else {837 this->graph->next(e.out);838 while(this->graph->valid(e.out) && !(*backward_filter)[e]) {839 this->graph->next(e.out); }840 }841 return e;842 }843 EdgeIt& next(EdgeIt& e) const {844 if (!e.backward) {845 this->graph->next(e.e);846 while(this->graph->valid(e.e) && !(*forward_filter)[e]) {847 this->graph->next(e.e); }848 if (!this->graph->valid(e.e)) {849 e.backward=true;850 this->graph->first(e.e);851 while(this->graph->valid(e.e) && !(*backward_filter)[e]) {852 this->graph->next(e.e); }853 }854 } else {855 this->graph->next(e.e);856 while(this->graph->valid(e.e) && !(*backward_filter)[e]) {857 this->graph->next(e.e); }858 }859 return e;860 }921 // using GraphWrapper<Graph>::next; 922 // // NodeIt& next(NodeIt& n) const { GraphWrapper<Graph>::next(n); return n; } 923 // OutEdgeIt& next(OutEdgeIt& e) const { 924 // if (!e.backward) { 925 // Node v=this->graph->aNode(e.out); 926 // this->graph->next(e.out); 927 // while(this->graph->valid(e.out) && !(*forward_filter)[e]) { 928 // this->graph->next(e.out); } 929 // if (!this->graph->valid(e.out)) { 930 // e.backward=true; 931 // this->graph->first(e.in, v); 932 // while(this->graph->valid(e.in) && !(*backward_filter)[e]) { 933 // this->graph->next(e.in); } 934 // } 935 // } else { 936 // this->graph->next(e.in); 937 // while(this->graph->valid(e.in) && !(*backward_filter)[e]) { 938 // this->graph->next(e.in); } 939 // } 940 // return e; 941 // } 942 // // FIXME Not tested 943 // InEdgeIt& next(InEdgeIt& e) const { 944 // if (!e.backward) { 945 // Node v=this->graph->aNode(e.in); 946 // this->graph->next(e.in); 947 // while(this->graph->valid(e.in) && !(*forward_filter)[e]) { 948 // this->graph->next(e.in); } 949 // if (!this->graph->valid(e.in)) { 950 // e.backward=true; 951 // this->graph->first(e.out, v); 952 // while(this->graph->valid(e.out) && !(*backward_filter)[e]) { 953 // this->graph->next(e.out); } 954 // } 955 // } else { 956 // this->graph->next(e.out); 957 // while(this->graph->valid(e.out) && !(*backward_filter)[e]) { 958 // this->graph->next(e.out); } 959 // } 960 // return e; 961 // } 962 // EdgeIt& next(EdgeIt& e) const { 963 // if (!e.backward) { 964 // this->graph->next(e.e); 965 // while(this->graph->valid(e.e) && !(*forward_filter)[e]) { 966 // this->graph->next(e.e); } 967 // if (!this->graph->valid(e.e)) { 968 // e.backward=true; 969 // this->graph->first(e.e); 970 // while(this->graph->valid(e.e) && !(*backward_filter)[e]) { 971 // this->graph->next(e.e); } 972 // } 973 // } else { 974 // this->graph->next(e.e); 975 // while(this->graph->valid(e.e) && !(*backward_filter)[e]) { 976 // this->graph->next(e.e); } 977 // } 978 // return e; 979 // } 861 980 862 981 Node tail(Edge e) const { … … 865 984 return ((!e.backward) ? this->graph->head(e) : this->graph->tail(e)); } 866 985 867 Node aNode(OutEdgeIt e) const {868 return ((!e.backward) ? this->graph->aNode(e.out) :869 this->graph->aNode(e.in)); }870 Node bNode(OutEdgeIt e) const {871 return ((!e.backward) ? this->graph->bNode(e.out) :872 this->graph->bNode(e.in)); }873 874 Node aNode(InEdgeIt e) const {875 return ((!e.backward) ? this->graph->aNode(e.in) :876 this->graph->aNode(e.out)); }877 Node bNode(InEdgeIt e) const {878 return ((!e.backward) ? this->graph->bNode(e.in) :879 this->graph->bNode(e.out)); }986 // Node aNode(OutEdgeIt e) const { 987 // return ((!e.backward) ? this->graph->aNode(e.out) : 988 // this->graph->aNode(e.in)); } 989 // Node bNode(OutEdgeIt e) const { 990 // return ((!e.backward) ? this->graph->bNode(e.out) : 991 // this->graph->bNode(e.in)); } 992 993 // Node aNode(InEdgeIt e) const { 994 // return ((!e.backward) ? this->graph->aNode(e.in) : 995 // this->graph->aNode(e.out)); } 996 // Node bNode(InEdgeIt e) const { 997 // return ((!e.backward) ? this->graph->bNode(e.in) : 998 // this->graph->bNode(e.out)); } 880 999 881 1000 /// Gives back the opposite edge. … … 894 1013 // int id(Node v) const { return graph->id(v); } 895 1014 896 bool valid(Node n) const { return GraphWrapper<Graph>::valid(n); }897 bool valid(Edge e) const {898 return this->graph->valid(e);899 //return e.forward ? graph->valid(e.out) : graph->valid(e.in);900 }1015 // bool valid(Node n) const { return GraphWrapper<Graph>::valid(n); } 1016 // bool valid(Edge e) const { 1017 // return this->graph->valid(e); 1018 // //return e.forward ? graph->valid(e.out) : graph->valid(e.in); 1019 // } 901 1020 902 1021 bool forward(const Edge& e) const { return !e.backward; } … … 940 1059 typedef Edge KeyType; 941 1060 EdgeMap(const SubBidirGraphWrapper<Graph, 942 ForwardFilterMap, BackwardFilterMap>& _G) :943 forward_map(*( _G.graph)), backward_map(*(_G.graph)) { }1061 ForwardFilterMap, BackwardFilterMap>& g) : 1062 forward_map(*(g.graph)), backward_map(*(g.graph)) { } 944 1063 EdgeMap(const SubBidirGraphWrapper<Graph, 945 ForwardFilterMap, BackwardFilterMap>& _G, T a) :946 forward_map(*( _G.graph), a), backward_map(*(_G.graph), a) { }1064 ForwardFilterMap, BackwardFilterMap>& g, T a) : 1065 forward_map(*(g.graph), a), backward_map(*(g.graph), a) { } 947 1066 void set(Edge e, T a) { 948 1067 if (!e.backward) -
src/hugo/list_graph.h
r722 r774 132 132 Node head(Edge e) const { return edges[e.n].head; } 133 133 134 Node aNode(OutEdgeIt e) const { return edges[e.n].tail; }135 Node aNode(InEdgeIt e) const { return edges[e.n].head; }136 137 Node bNode(OutEdgeIt e) const { return edges[e.n].head; }138 Node bNode(InEdgeIt e) const { return edges[e.n].tail; }139 140 134 NodeIt& first(NodeIt& v) const { 141 135 v=NodeIt(*this); return v; } … … 147 141 e=InEdgeIt(*this,v); return e; } 148 142 149 // template< typename It >150 // It first() const { It e; first(e); return e; }151 152 // template< typename It >153 // It first(Node v) const { It e; first(e,v); return e; }154 155 static bool valid(Edge e) { return e.n!=-1; }156 static bool valid(Node n) { return n.n!=-1; }157 158 static void setInvalid(Edge &e) { e.n=-1; }159 static void setInvalid(Node &n) { n.n=-1; }160 161 template <typename It> static It getNext(It it)162 { It tmp(it); return next(tmp); }163 164 NodeIt& next(NodeIt& it) const {165 it.n=nodes[it.n].next;166 return it;167 }168 OutEdgeIt& next(OutEdgeIt& it) const169 { it.n=edges[it.n].next_out; return it; }170 InEdgeIt& next(InEdgeIt& it) const171 { it.n=edges[it.n].next_in; return it; }172 EdgeIt& next(EdgeIt& it) const {173 if(edges[it.n].next_in!=-1) {174 it.n=edges[it.n].next_in;175 }176 else {177 int n;178 for(n=nodes[edges[it.n].head].next;179 n!=-1 && nodes[n].first_in == -1;180 n = nodes[n].next) ;181 it.n = (n==-1)?-1:nodes[n].first_in;182 }183 return it;184 }185 186 143 static int id(Node v) { return v.n; } 187 144 static int id(Edge e) { return e.n; } … … 251 208 return e; 252 209 } 253 210 211 /// Finds an edge between two nodes. 212 213 /// Finds an edge from node \c u to node \c v. 214 /// 215 /// If \c prev is \ref INVALID (this is the default value), then 216 /// It finds the first edge from \c u to \c v. Otherwise it looks for 217 /// the next edge from \c u to \c v after \c prev. 218 /// \return The found edge or INVALID if there is no such an edge. 219 Edge findEdge(Node u,Node v, Edge prev = INVALID) 220 { 221 int e = (prev.n==-1)? nodes[u.n].first_out : edges[prev.n].next_out; 222 while(e!=-1 && edges[e].tail!=v.n) e = edges[e].next_out; 223 prev.n=e; 224 return prev; 225 } 226 254 227 private: 255 228 void eraseEdge(int n) { … … 325 298 bool operator!=(const Node i) const {return n!=i.n;} 326 299 bool operator<(const Node i) const {return n<i.n;} 300 // ///Validity check 301 // operator bool() { return n!=-1; } 327 302 }; 328 303 329 304 class NodeIt : public Node { 305 const ListGraph *G; 330 306 friend class ListGraph; 331 307 public: 332 308 NodeIt() : Node() { } 333 309 NodeIt(Invalid i) : Node(i) { } 334 NodeIt(const ListGraph& G) : Node(G.first_node) { }310 NodeIt(const ListGraph& _G) : Node(_G.first_node), G(&_G) { } 335 311 ///\todo Undocumented conversion Node -\> NodeIt. 336 NodeIt(const ListGraph& G, const Node &n) : Node(n) { } 312 NodeIt(const ListGraph& _G,Node n) : Node(n), G(&_G) { } 313 NodeIt &operator++() { 314 n=G->nodes[n].next; 315 return *this; 316 } 317 // ///Validity check 318 // operator bool() { return Node::operator bool(); } 337 319 }; 338 320 … … 365 347 ///make class \c SymListGraph::SymEdgeMap friend of Edge 366 348 int &idref() {return n;} 367 const int &idref() const {return n;} 368 }; 349 const int &idref() const {return n;} 350 // ///Validity check 351 // operator bool() { return n!=-1; } 352 }; 369 353 370 354 class EdgeIt : public Edge { 355 const ListGraph *G; 371 356 friend class ListGraph; 372 357 public: 373 EdgeIt(const ListGraph& G) : Edge() {358 EdgeIt(const ListGraph& _G) : Edge(), G(&_G) { 374 359 int m; 375 for(m= G.first_node;376 m!=-1 && G.nodes[m].first_in == -1; m =G.nodes[m].next);377 n = (m==-1)?-1: G.nodes[m].first_in;360 for(m=_G.first_node; 361 m!=-1 && _G.nodes[m].first_in == -1; m = _G.nodes[m].next); 362 n = (m==-1)?-1:_G.nodes[m].first_in; 378 363 } 379 364 EdgeIt (Invalid i) : Edge(i) { } 365 EdgeIt(const ListGraph& _G, Edge e) : Edge(e), G(&_G) { } 380 366 EdgeIt() : Edge() { } 381 367 ///\bug This is a workaround until somebody tells me how to 382 368 ///make class \c SymListGraph::SymEdgeMap friend of Edge 383 369 int &idref() {return n;} 370 EdgeIt &operator++() { 371 if(G->edges[n].next_in!=-1) n=G->edges[n].next_in; 372 else { 373 int nn; 374 for(nn=G->nodes[G->edges[n].head].next; 375 nn!=-1 && G->nodes[nn].first_in == -1; 376 nn = G->nodes[nn].next) ; 377 n = (nn==-1)?-1:G->nodes[nn].first_in; 378 } 379 return *this; 380 } 381 // ///Validity check 382 // operator bool() { return Edge::operator bool(); } 384 383 }; 385 384 386 385 class OutEdgeIt : public Edge { 386 const ListGraph *G; 387 387 friend class ListGraph; 388 388 public: 389 389 OutEdgeIt() : Edge() { } 390 OutEdgeIt(const ListGraph& _G, Edge e) : Edge(e), G(&_G) { } 390 391 OutEdgeIt (Invalid i) : Edge(i) { } 391 392 392 OutEdgeIt(const ListGraph& G,const Node v) 393 : Edge(G.nodes[v.n].first_out) {} 393 OutEdgeIt(const ListGraph& _G,const Node v) 394 : Edge(_G.nodes[v.n].first_out), G(&_G) {} 395 OutEdgeIt &operator++() { n=G->edges[n].next_out; return *this; } 396 // ///Validity check 397 // operator bool() { return Edge::operator bool(); } 394 398 }; 395 399 396 400 class InEdgeIt : public Edge { 401 const ListGraph *G; 397 402 friend class ListGraph; 398 403 public: 399 404 InEdgeIt() : Edge() { } 405 InEdgeIt(const ListGraph& _G, Edge e) : Edge(e), G(&_G) { } 400 406 InEdgeIt (Invalid i) : Edge(i) { } 401 InEdgeIt(const ListGraph& G,Node v) :Edge(G.nodes[v.n].first_in) {} 407 InEdgeIt(const ListGraph& _G,Node v) 408 : Edge(_G.nodes[v.n].first_in), G(&_G) { } 409 InEdgeIt &operator++() { n=G->edges[n].next_in; return *this; } 410 // ///Validity check 411 // operator bool() { return Edge::operator bool(); } 402 412 }; 403 413 … … 839 849 Node head(Edge e) const { return INVALID; } 840 850 841 Node aNode(OutEdgeIt e) const { return INVALID; }842 Node aNode(InEdgeIt e) const { return INVALID; }843 844 Node bNode(OutEdgeIt e) const { return INVALID; }845 Node bNode(InEdgeIt e) const { return INVALID; }846 847 851 NodeIt& first(NodeIt& v) const { 848 852 v=NodeIt(*this); return v; } … … 854 858 e=InEdgeIt(*this,v); return e; } 855 859 856 // template< typename It >857 // It first() const { It e; first(e); return e; }858 859 // template< typename It >860 // It first(Node v) const { It e; first(e,v); return e; }861 862 bool valid(Edge e) const { return false; }863 bool valid(Node n) const { return n.n!=-1; }864 865 void setInvalid(Edge &e) { }866 void setInvalid(Node &n) { n.n=-1; }867 868 template <typename It> It getNext(It it) const869 { It tmp(it); return next(tmp); }870 871 NodeIt& next(NodeIt& it) const {872 it.n=nodes[it.n].next;873 return it;874 }875 OutEdgeIt& next(OutEdgeIt& it) const { return it; }876 InEdgeIt& next(InEdgeIt& it) const { return it; }877 EdgeIt& next(EdgeIt& it) const { return it; }878 879 860 int id(Node v) const { return v.n; } 880 861 int id(Edge e) const { return -1; } … … 928 909 } 929 910 911 912 Edge findEdge(Node u,Node v, Edge prev = INVALID) 913 { 914 return INVALID; 915 } 916 930 917 ///\bug Dynamic maps must be updated! 931 918 /// … … 956 943 957 944 class NodeIt : public Node { 945 const NodeSet *G; 958 946 friend class NodeSet; 959 947 public: 960 948 NodeIt() : Node() { } 949 NodeIt(const NodeSet& _G,Node n) : Node(n), G(&_G) { } 961 950 NodeIt(Invalid i) : Node(i) { } 962 NodeIt(const NodeSet& G) : Node(G.first_node) { } 963 ///\todo Undocumented conversion Node -\> NodeIt. 964 NodeIt(const NodeSet& G, const Node &n) : Node(n) { } 965 951 NodeIt(const NodeSet& _G) : Node(_G.first_node), G(&_G) { } 952 NodeIt &operator++() { 953 n=G->nodes[n].next; 954 return *this; 955 } 966 956 }; 967 957 … … 994 984 public: 995 985 EdgeIt(const NodeSet& G) : Edge() { } 986 EdgeIt(const NodeSet&, Edge) : Edge() { } 996 987 EdgeIt (Invalid i) : Edge(i) { } 997 988 EdgeIt() : Edge() { } … … 999 990 ///make class \c SymNodeSet::SymEdgeMap friend of Edge 1000 991 // int idref() {return -1;} 992 EdgeIt operator++() { return INVALID; } 1001 993 }; 1002 994 … … 1005 997 public: 1006 998 OutEdgeIt() : Edge() { } 999 OutEdgeIt(const NodeSet&, Edge) : Edge() { } 1007 1000 OutEdgeIt (Invalid i) : Edge(i) { } 1008 1001 OutEdgeIt(const NodeSet& G,const Node v) : Edge() {} 1002 OutEdgeIt operator++() { return INVALID; } 1009 1003 }; 1010 1004 … … 1013 1007 public: 1014 1008 InEdgeIt() : Edge() { } 1009 InEdgeIt(const NodeSet&, Edge) : Edge() { } 1015 1010 InEdgeIt (Invalid i) : Edge(i) { } 1016 1011 InEdgeIt(const NodeSet& G,Node v) :Edge() {} 1012 InEdgeIt operator++() { return INVALID; } 1017 1013 }; 1018 1014 … … 1200 1196 public: 1201 1197 NodeIt() : NodeGraphType::NodeIt() { } 1198 NodeIt(const EdgeSet& _G,Node n) : NodeGraphType::NodeIt(_G.G,n) { } 1202 1199 NodeIt (Invalid i) : NodeGraphType::NodeIt(i) {} 1203 1200 NodeIt(const EdgeSet& _G) : NodeGraphType::NodeIt(_G.G) { } 1204 1201 NodeIt(const typename NodeGraphType::NodeIt &n) 1205 1202 : NodeGraphType::NodeIt(n) {} 1206 ///\todo Undocumented conversion Node -\> NodeIt.1207 NodeIt(const EdgeSet& _G, const Node &n)1208 : NodeGraphType::NodeIt(_G.G,n) { }1209 1203 1210 1204 operator Node() { return Node(*this);} 1205 NodeIt &operator++() 1206 { this->NodeGraphType::NodeIt::operator++(); return *this;} 1211 1207 }; 1212 1208 … … 1311 1307 Node tail(Edge e) const { return edges[e.n].tail; } 1312 1308 Node head(Edge e) const { return edges[e.n].head; } 1313 1314 Node aNode(OutEdgeIt e) const { return edges[e.n].tail; }1315 Node aNode(InEdgeIt e) const { return edges[e.n].head; }1316 1317 Node bNode(OutEdgeIt e) const { return edges[e.n].head; }1318 Node bNode(InEdgeIt e) const { return edges[e.n].tail; }1319 1309 1320 1310 NodeIt& first(NodeIt& v) const { … … 1327 1317 e=InEdgeIt(*this,v); return e; } 1328 1318 1329 // template< typename It >1330 // It first() const { It e; first(e); return e; }1331 1332 // template< typename It >1333 // It first(Node v) const { It e; first(e,v); return e; }1334 1335 bool valid(Edge e) const { return e.n!=-1; }1336 bool valid(Node n) const { return G.valid(n); }1337 1338 void setInvalid(Edge &e) { e.n=-1; }1339 void setInvalid(Node &n) { G.setInvalid(n); }1340 1341 template <typename It> It getNext(It it) const1342 { It tmp(it); return next(tmp); }1343 1344 NodeIt& next(NodeIt& it) const { G.next(it); return it; }1345 OutEdgeIt& next(OutEdgeIt& it) const1346 { it.n=edges[it.n].next_out; return it; }1347 InEdgeIt& next(InEdgeIt& it) const1348 { it.n=edges[it.n].next_in; return it; }1349 EdgeIt& next(EdgeIt& it) const {1350 if(edges[it.n].next_in!=-1) {1351 it.n=edges[it.n].next_in;1352 }1353 else {1354 NodeIt n(*this,edges[it.n].head);1355 for(n=next(n);1356 valid(n) && nodes[n].first_in == -1;1357 next(n)) ;1358 it.n = (valid(n))?-1:nodes[n].first_in;1359 }1360 return it;1361 }1362 1363 1319 int id(Edge e) const { return e.n; } 1364 1320 … … 1399 1355 } 1400 1356 1357 /// Finds an edge between two nodes. 1358 1359 /// Finds an edge from node \c u to node \c v. 1360 /// 1361 /// If \c prev is \ref INVALID (this is the default value), then 1362 /// It finds the first edge from \c u to \c v. Otherwise it looks for 1363 /// the next edge from \c u to \c v after \c prev. 1364 /// \return The found edge or INVALID if there is no such an edge. 1365 Edge findEdge(Node u,Node v, Edge prev = INVALID) 1366 { 1367 int e = (prev.n==-1)? nodes[u].first_out : edges[prev.n].next_out; 1368 while(e!=-1 && edges[e].tail!=v) e = edges[e].next_out; 1369 prev.n=e; 1370 return prev; 1371 } 1372 1401 1373 private: 1402 1374 void eraseEdge(int n) { … … 1461 1433 friend class NodeIt; 1462 1434 public: 1463 ///\bug It shou d be at least protected1435 ///\bug It should be at least protected 1464 1436 /// 1465 1437 int n; … … 1484 1456 template <typename T> friend class EdgeMap; 1485 1457 1486 1487 public: 1488 EdgeIt(const EdgeSet& G) : Edge() {1458 const EdgeSet *G; 1459 public: 1460 EdgeIt(const EdgeSet& _G) : Edge(), G(&_G) { 1489 1461 // typename NodeGraphType::Node m; 1490 1462 NodeIt m; 1491 for(G.first(m); 1492 G.valid(m) && G.nodes[m].first_in == -1; G.next(m)); 1493 //AJJAJ! This is a non sense!!!!!!! 1494 this->n = G.valid(m)?-1:G.nodes[m].first_in; 1495 } 1463 for(G->first(m); 1464 m!=INVALID && G->nodes[m].first_in == -1; ++m); 1465 ///\bug AJJAJ! This is a non sense!!!!!!! 1466 this->n = m!=INVALID?-1:G->nodes[m].first_in; 1467 } 1468 EdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { } 1496 1469 EdgeIt (Invalid i) : Edge(i) { } 1497 1470 EdgeIt() : Edge() { } 1498 ///\bug This is a workaround until somebody tells me how to 1471 ///. 1472 1473 ///\bug UNIMPLEMENTED!!!!! 1474 // 1475 EdgeIt &operator++() { 1476 return *this; 1477 } 1478 ///\bug This is a workaround until somebody tells me how to 1499 1479 ///make class \c SymEdgeSet::SymEdgeMap friend of Edge 1500 1480 int &idref() {return this->n;} … … 1502 1482 1503 1483 class OutEdgeIt : public Edge { 1484 const EdgeSet *G; 1504 1485 friend class EdgeSet; 1505 1486 public: 1506 1487 OutEdgeIt() : Edge() { } 1507 1488 OutEdgeIt (Invalid i) : Edge(i) { } 1508 1509 OutEdgeIt(const EdgeSet& G,const Node v) : Edge(G.nodes[v].first_out) { } 1489 OutEdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { } 1490 1491 OutEdgeIt(const EdgeSet& _G,const Node v) : 1492 Edge(_G.nodes[v].first_out), G(&_G) { } 1493 OutEdgeIt &operator++() { n=G->edges[n].next_out; return *this; } 1510 1494 }; 1511 1495 1512 1496 class InEdgeIt : public Edge { 1497 const EdgeSet *G; 1513 1498 friend class EdgeSet; 1514 1499 public: 1515 1500 InEdgeIt() : Edge() { } 1516 1501 InEdgeIt (Invalid i) : Edge(i) { } 1517 InEdgeIt(const EdgeSet& G,Node v) :Edge(G.nodes[v].first_in) { } 1502 InEdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { } 1503 InEdgeIt(const EdgeSet& _G,Node v) 1504 : Edge(_G.nodes[v].first_in), G(&_G) { } 1505 InEdgeIt &operator++() { n=G->edges[n].next_in; return *this; } 1518 1506 }; 1519 1507 … … 1555 1543 //FIXME: What if there are empty Id's? 1556 1544 //FIXME: Can I use 'this' in a constructor? 1557 G->dyn_edge_maps.push_back(this);1545 this->G->dyn_edge_maps.push_back(this); 1558 1546 } 1559 1547 EdgeMap(const EdgeSet &_G,const T &t) : 1560 1548 DynMapBase<Edge>(_G), container(_G.maxEdgeId(),t) 1561 1549 { 1562 G->dyn_edge_maps.push_back(this);1550 this->G->dyn_edge_maps.push_back(this); 1563 1551 } 1564 1552 EdgeMap(const EdgeMap<T> &m) : 1565 1553 DynMapBase<Edge>(*m.G), container(m.container) 1566 1554 { 1567 G->dyn_edge_maps.push_back(this);1555 this->G->dyn_edge_maps.push_back(this); 1568 1556 } 1569 1557 … … 1573 1561 DynMapBase<Edge>(*m.G), container(m.container.size()) 1574 1562 { 1575 G->dyn_edge_maps.push_back(this);1563 this->G->dyn_edge_maps.push_back(this); 1576 1564 typename std::vector<TT>::const_iterator i; 1577 1565 for(typename std::vector<TT>::const_iterator i=m.container.begin(); … … 1582 1570 ~EdgeMap() 1583 1571 { 1584 if( G) {1572 if(this->G) { 1585 1573 typename std::vector<DynMapBase<Edge>* >::iterator i; 1586 for(i= G->dyn_edge_maps.begin();1587 i!= G->dyn_edge_maps.end() && *i!=this; ++i) ;1574 for(i=this->G->dyn_edge_maps.begin(); 1575 i!=this->G->dyn_edge_maps.end() && *i!=this; ++i) ; 1588 1576 //if(*i==this) G->dyn_edge_maps.erase(i); //Way too slow... 1589 1577 //A better way to do that: (Is this really important?) 1590 1578 if(*i==this) { 1591 *i= G->dyn_edge_maps.back();1592 G->dyn_edge_maps.pop_back();1579 *i=this->G->dyn_edge_maps.back(); 1580 this->G->dyn_edge_maps.pop_back(); 1593 1581 } 1594 1582 } … … 1603 1591 ///\bug This doesn't work. Why? 1604 1592 /// void set(Edge n, T a) { container[n.n]=a; } 1605 void set(Edge n, T a) { container[ G->id(n)]=a; }1593 void set(Edge n, T a) { container[this->G->id(n)]=a; } 1606 1594 //T get(Edge n) const { return container[n.n]; } 1607 1595 typename std::vector<T>::reference 1608 1596 ///\bug This doesn't work. Why? 1609 1597 /// operator[](Edge n) { return container[n.n]; } 1610 operator[](Edge n) { return container[ G->id(n)]; }1598 operator[](Edge n) { return container[this->G->id(n)]; } 1611 1599 typename std::vector<T>::const_reference 1612 1600 ///\bug This doesn't work. Why? 1613 1601 /// operator[](Edge n) const { return container[n.n]; } 1614 operator[](Edge n) const { return container[ G->id(n)]; }1602 operator[](Edge n) const { return container[this->G->id(n)]; } 1615 1603 1616 1604 ///\warning There is no safety check at all! -
src/hugo/max_flow.h
r773 r774 6 6 #include <queue> 7 7 8 #include <hugo/graph_wrapper.h>8 //#include <hugo/graph_wrapper.h> 9 9 #include <hugo/invalid.h> 10 10 #include <hugo/maps.h> … … 63 63 FlowMap* flow; 64 64 int n; //the number of nodes of G 65 typedef ResGraphWrapper<const Graph, Num, CapMap, FlowMap> ResGW;65 // typedef ResGraphWrapper<const Graph, Num, CapMap, FlowMap> ResGW; 66 66 //typedef ExpResGraphWrapper<const Graph, Num, CapMap, FlowMap> ResGW; 67 typedef typename ResGW::OutEdgeIt ResGWOutEdgeIt;68 typedef typename ResGW::Edge ResGWEdge;67 // typedef typename ResGW::OutEdgeIt ResGWOutEdgeIt; 68 // typedef typename ResGW::Edge ResGWEdge; 69 69 typedef typename Graph::template NodeMap<int> ReachedMap; 70 70 … … 113 113 StatusEnum status; 114 114 115 // int number_of_augmentations;116 117 118 // template<typename IntMap>119 // class TrickyReachedMap {120 // protected:121 // IntMap* map;122 // int* number_of_augmentations;123 // public:124 // TrickyReachedMap(IntMap& _map, int& _number_of_augmentations) :125 // map(&_map), number_of_augmentations(&_number_of_augmentations) { }126 // void set(const Node& n, bool b) {127 // if (b)128 // map->set(n, *number_of_augmentations);129 // else130 // map->set(n, *number_of_augmentations-1);131 // }132 // bool operator[](const Node& n) const {133 // return (*map)[n]==*number_of_augmentations;134 // }135 // };115 // int number_of_augmentations; 116 117 118 // template<typename IntMap> 119 // class TrickyReachedMap { 120 // protected: 121 // IntMap* map; 122 // int* number_of_augmentations; 123 // public: 124 // TrickyReachedMap(IntMap& _map, int& _number_of_augmentations) : 125 // map(&_map), number_of_augmentations(&_number_of_augmentations) { } 126 // void set(const Node& n, bool b) { 127 // if (b) 128 // map->set(n, *number_of_augmentations); 129 // else 130 // map->set(n, *number_of_augmentations-1); 131 // } 132 // bool operator[](const Node& n) const { 133 // return (*map)[n]==*number_of_augmentations; 134 // } 135 // }; 136 136 137 137 ///Constructor … … 235 235 } 236 236 237 if ( !g->valid(first[b])) --b;237 if ( first[b]==INVALID ) --b; 238 238 else { 239 239 end=false; … … 290 290 int l=level[v]+1; 291 291 292 InEdgeIt e; 293 for(g->first(e,v); g->valid(e); g->next(e)) { 292 for(InEdgeIt e(*g,v); e!=INVALID; ++e) { 294 293 if ( (*capacity)[e] <= (*flow)[e] ) continue; 295 294 Node u=g->tail(e); … … 304 303 } 305 304 306 OutEdgeIt f; 307 for(g->first(f,v); g->valid(f); g->next(f)) { 308 if ( 0 >= (*flow)[f] ) continue; 309 Node u=g->head(f); 305 for(OutEdgeIt e(*g,v); e!=INVALID; ++e) { 306 if ( 0 >= (*flow)[e] ) continue; 307 Node u=g->head(e); 310 308 if ( level[u] >= n ) { 311 309 bfs_queue.push(u); … … 324 322 if ( b == 0 ) break; 325 323 326 if ( !g->valid(first[b])) --b;324 if ( first[b]==INVALID ) --b; 327 325 else { 328 326 … … 352 350 /// It can be called already after running \ref preflowPhase1. 353 351 Num flowValue() const { 354 // Num a=0;355 // for(InEdgeIt e(*g,t);g->valid(e);g->next(e)) a+=(*flow)[e];356 // for(OutEdgeIt e(*g,t);g->valid(e);g->next(e)) a-=(*flow)[e];357 // return a;352 // Num a=0; 353 // for(InEdgeIt e(*g,t);g->valid(e);g->next(e)) a+=(*flow)[e]; 354 // for(OutEdgeIt e(*g,t);g->valid(e);g->next(e)) a-=(*flow)[e]; 355 // return a; 358 356 return excess[t]; 359 357 //marci figyu: excess[t] epp ezt adja preflow 1. fazisa utan … … 375 373 template<typename _CutMap> 376 374 void actMinCut(_CutMap& M) const { 377 NodeIt v;378 375 switch (status) { 379 380 for( g->first(v); g->valid(v); g->next(v)) {376 case AFTER_PRE_FLOW_PHASE_1: 377 for(NodeIt v(*g); v!=INVALID; ++v) { 381 378 if (level[v] < n) { 382 379 M.set(v, false); … … 386 383 } 387 384 break; 388 389 390 391 385 case AFTER_PRE_FLOW_PHASE_2: 386 case AFTER_NOTHING: 387 case AFTER_AUGMENTING: 388 case AFTER_FAST_AUGMENTING: 392 389 minMinCut(M); 393 390 break; … … 413 410 queue.pop(); 414 411 415 OutEdgeIt e; 416 for(g->first(e,w) ; g->valid(e); g->next(e)) { 412 for(OutEdgeIt e(*g,w) ; e!=INVALID; ++e) { 417 413 Node v=g->head(e); 418 414 if (!M[v] && (*flow)[e] < (*capacity)[e] ) { … … 422 418 } 423 419 424 InEdgeIt f; 425 for(g->first(f,w) ; g->valid(f); g->next(f)) { 426 Node v=g->tail(f); 427 if (!M[v] && (*flow)[f] > 0 ) { 420 for(InEdgeIt e(*g,w) ; e!=INVALID; ++e) { 421 Node v=g->tail(e); 422 if (!M[v] && (*flow)[e] > 0 ) { 428 423 queue.push(v); 429 424 M.set(v, true); … … 443 438 void maxMinCut(_CutMap& M) const { 444 439 445 NodeIt v; 446 for(g->first(v) ; g->valid(v); g->next(v)) { 447 M.set(v, true); 448 } 440 for(NodeIt v(*g) ; v!=INVALID; ++v) M.set(v, true); 449 441 450 442 std::queue<Node> queue; … … 457 449 queue.pop(); 458 450 459 InEdgeIt e; 460 for(g->first(e,w) ; g->valid(e); g->next(e)) { 451 for(InEdgeIt e(*g,w) ; e!=INVALID; ++e) { 461 452 Node v=g->tail(e); 462 453 if (M[v] && (*flow)[e] < (*capacity)[e] ) { … … 466 457 } 467 458 468 OutEdgeIt f; 469 for(g->first(f,w) ; g->valid(f); g->next(f)) { 470 Node v=g->head(f); 471 if (M[v] && (*flow)[f] > 0 ) { 459 for(OutEdgeIt e(*g,w) ; e!=INVALID; ++e) { 460 Node v=g->head(e); 461 if (M[v] && (*flow)[e] > 0 ) { 472 462 queue.push(v); 473 463 M.set(v, false); … … 519 509 int newlevel=n; //bound on the next level of w 520 510 521 OutEdgeIt e; 522 for(g->first(e,w); g->valid(e); g->next(e)) { 523 511 for(OutEdgeIt e(*g,w) ; e!=INVALID; ++e) { 524 512 if ( (*flow)[e] >= (*capacity)[e] ) continue; 525 513 Node v=g->head(e); 526 514 527 515 if( lev > level[v] ) { //Push is allowed now 528 516 529 517 if ( excess[v]<=0 && v!=t && v!=s ) { 530 518 next.set(v,first[level[v]]); … … 535 523 Num flo=(*flow)[e]; 536 524 Num remcap=cap-flo; 537 525 538 526 if ( remcap >= exc ) { //A nonsaturating push. 539 527 540 528 flow->set(e, flo+exc); 541 529 excess.set(v, excess[v]+exc); … … 552 540 553 541 if ( exc > 0 ) { 554 InEdgeIt e; 555 for(g->first(e,w); g->valid(e); g->next(e)) { 556 542 for(InEdgeIt e(*g,w) ; e!=INVALID; ++e) { 543 557 544 if( (*flow)[e] <= 0 ) continue; 558 545 Node v=g->tail(e); … … 585 572 586 573 excess.set(w, exc); 587 574 588 575 return newlevel; 589 576 } 590 591 592 577 578 579 593 580 void preflowPreproc(FlowEnum fe, NNMap& next, VecFirst& first, 594 581 VecNode& level_list, NNMap& left, NNMap& right) 595 582 { 596 switch (fe) { //setting excess583 switch (fe) { //setting excess 597 584 case NO_FLOW: 585 for(EdgeIt e(*g); e!=INVALID; ++e) flow->set(e,0); 586 for(NodeIt v(*g); v!=INVALID; ++v) excess.set(v,0); 587 break; 588 case ZERO_FLOW: 589 for(NodeIt v(*g); v!=INVALID; ++v) excess.set(v,0); 590 break; 591 case GEN_FLOW: 592 for(NodeIt v(*g); v!=INVALID; ++v) excess.set(v,0); 598 593 { 599 EdgeIt e;600 for(g->first(e); g->valid(e); g->next(e)) flow->set(e,0);601 602 NodeIt v;603 for(g->first(v); g->valid(v); g->next(v)) excess.set(v,0);604 break;605 }606 case ZERO_FLOW:607 {608 NodeIt v;609 for(g->first(v); g->valid(v); g->next(v)) excess.set(v,0);610 break;611 }612 case GEN_FLOW:613 {614 NodeIt v;615 for(g->first(v); g->valid(v); g->next(v)) excess.set(v,0);616 617 594 Num exc=0; 618 InEdgeIt e; 619 for(g->first(e,t); g->valid(e); g->next(e)) exc+=(*flow)[e]; 620 OutEdgeIt f; 621 for(g->first(f,t); g->valid(f); g->next(f)) exc-=(*flow)[f]; 595 for(InEdgeIt e(*g,t) ; e!=INVALID; ++e) exc+=(*flow)[e]; 596 for(OutEdgeIt e(*g,t) ; e!=INVALID; ++e) exc-=(*flow)[e]; 622 597 excess.set(t,exc); 623 break;624 }625 default: break;626 } 627 628 NodeIt v;629 for( g->first(v); g->valid(v); g->next(v)) level.set(v,n);598 } 599 break; 600 default: 601 break; 602 } 603 604 for(NodeIt v(*g); v!=INVALID; ++v) level.set(v,n); 630 605 //setting each node to level n 631 606 … … 636 611 case NO_FLOW: //flow is already set to const zero 637 612 case ZERO_FLOW: 638 { 639 //Reverse_bfs from t, to find the starting level. 640 level.set(t,0); 641 bfs_queue.push(t); 642 643 while (!bfs_queue.empty()) { 644 645 Node v=bfs_queue.front(); 646 bfs_queue.pop(); 647 int l=level[v]+1; 648 649 InEdgeIt e; 650 for(g->first(e,v); g->valid(e); g->next(e)) { 651 Node w=g->tail(e); 652 if ( level[w] == n && w != s ) { 653 bfs_queue.push(w); 654 Node z=level_list[l]; 655 if ( g->valid(z) ) left.set(z,w); 656 right.set(w,z); 657 level_list[l]=w; 658 level.set(w, l); 659 } 660 } 661 } 662 663 //the starting flow 664 OutEdgeIt e; 665 for(g->first(e,s); g->valid(e); g->next(e)) 613 //Reverse_bfs from t, to find the starting level. 614 level.set(t,0); 615 bfs_queue.push(t); 616 617 while (!bfs_queue.empty()) { 618 619 Node v=bfs_queue.front(); 620 bfs_queue.pop(); 621 int l=level[v]+1; 622 623 for(InEdgeIt e(*g,v) ; e!=INVALID; ++e) { 624 Node w=g->tail(e); 625 if ( level[w] == n && w != s ) { 626 bfs_queue.push(w); 627 Node z=level_list[l]; 628 if ( z!=INVALID ) left.set(z,w); 629 right.set(w,z); 630 level_list[l]=w; 631 level.set(w, l); 632 } 633 } 634 } 635 636 //the starting flow 637 for(OutEdgeIt e(*g,s) ; e!=INVALID; ++e) 638 { 639 Num c=(*capacity)[e]; 640 if ( c <= 0 ) continue; 641 Node w=g->head(e); 642 if ( level[w] < n ) { 643 if ( excess[w] <= 0 && w!=t ) //putting into the stack 644 { 645 next.set(w,first[level[w]]); 646 first[level[w]]=w; 647 } 648 flow->set(e, c); 649 excess.set(w, excess[w]+c); 650 } 651 } 652 break; 653 case GEN_FLOW: 654 //Reverse_bfs from t in the residual graph, 655 //to find the starting level. 656 level.set(t,0); 657 bfs_queue.push(t); 658 659 while (!bfs_queue.empty()) { 660 661 Node v=bfs_queue.front(); 662 bfs_queue.pop(); 663 int l=level[v]+1; 664 665 for(InEdgeIt e(*g,v) ; e!=INVALID; ++e) { 666 if ( (*capacity)[e] <= (*flow)[e] ) continue; 667 Node w=g->tail(e); 668 if ( level[w] == n && w != s ) { 669 bfs_queue.push(w); 670 Node z=level_list[l]; 671 if ( z!=INVALID ) left.set(z,w); 672 right.set(w,z); 673 level_list[l]=w; 674 level.set(w, l); 675 } 676 } 677 678 for(OutEdgeIt e(*g,v) ; e!=INVALID; ++e) { 679 if ( 0 >= (*flow)[e] ) continue; 680 Node w=g->head(e); 681 if ( level[w] == n && w != s ) { 682 bfs_queue.push(w); 683 Node z=level_list[l]; 684 if ( z!=INVALID ) left.set(z,w); 685 right.set(w,z); 686 level_list[l]=w; 687 level.set(w, l); 688 } 689 } 690 } 691 692 //the starting flow 693 for(OutEdgeIt e(*g,s); e!=INVALID; ++e) 694 { 695 Num rem=(*capacity)[e]-(*flow)[e]; 696 if ( rem <= 0 ) continue; 697 Node w=g->head(e); 698 if ( level[w] < n ) { 699 if ( excess[w] <= 0 && w!=t ) //putting into the stack 700 { 701 next.set(w,first[level[w]]); 702 first[level[w]]=w; 703 } 704 flow->set(e, (*capacity)[e]); 705 excess.set(w, excess[w]+rem); 706 } 707 } 708 709 for(InEdgeIt e(*g,s); e!=INVALID; ++e) 710 { 711 if ( (*flow)[e] <= 0 ) continue; 712 Node w=g->tail(e); 713 if ( level[w] < n ) { 714 if ( excess[w] <= 0 && w!=t ) 715 { 716 next.set(w,first[level[w]]); 717 first[level[w]]=w; 718 } 719 excess.set(w, excess[w]+(*flow)[e]); 720 flow->set(e, 0); 721 } 722 } 723 break; 724 case PRE_FLOW: 725 //Reverse_bfs from t in the residual graph, 726 //to find the starting level. 727 level.set(t,0); 728 bfs_queue.push(t); 729 730 while (!bfs_queue.empty()) { 731 732 Node v=bfs_queue.front(); 733 bfs_queue.pop(); 734 int l=level[v]+1; 735 736 for(InEdgeIt e(*g,v) ; e!=INVALID; ++e) { 737 if ( (*capacity)[e] <= (*flow)[e] ) continue; 738 Node w=g->tail(e); 739 if ( level[w] == n && w != s ) { 740 bfs_queue.push(w); 741 Node z=level_list[l]; 742 if ( z!=INVALID ) left.set(z,w); 743 right.set(w,z); 744 level_list[l]=w; 745 level.set(w, l); 746 } 747 } 748 749 for(OutEdgeIt e(*g,v) ; e!=INVALID; ++e) { 750 if ( 0 >= (*flow)[e] ) continue; 751 Node w=g->head(e); 752 if ( level[w] == n && w != s ) { 753 bfs_queue.push(w); 754 Node z=level_list[l]; 755 if ( z!=INVALID ) left.set(z,w); 756 right.set(w,z); 757 level_list[l]=w; 758 level.set(w, l); 759 } 760 } 761 } 762 763 764 //the starting flow 765 for(OutEdgeIt e(*g,s) ; e!=INVALID; ++e) { 766 Num rem=(*capacity)[e]-(*flow)[e]; 767 if ( rem <= 0 ) continue; 768 Node w=g->head(e); 769 if ( level[w] < n ) { 770 flow->set(e, (*capacity)[e]); 771 excess.set(w, excess[w]+rem); 772 } 773 } 774 775 for(InEdgeIt e(*g,s) ; e!=INVALID; ++e) { 776 if ( (*flow)[e] <= 0 ) continue; 777 Node w=g->tail(e); 778 if ( level[w] < n ) { 779 excess.set(w, excess[w]+(*flow)[e]); 780 flow->set(e, 0); 781 } 782 } 783 784 //computing the excess 785 for(NodeIt w(*g); w!=INVALID; ++w) { 786 Num exc=0; 787 788 for(InEdgeIt e(*g,w) ; e!=INVALID; ++e) exc+=(*flow)[e]; 789 for(OutEdgeIt e(*g,w) ; e!=INVALID; ++e) exc-=(*flow)[e]; 790 791 excess.set(w,exc); 792 793 //putting the active nodes into the stack 794 int lev=level[w]; 795 if ( exc > 0 && lev < n && Node(w) != t ) 796 ///\bug if ( exc > 0 && lev < n && w != t ) temporarily for working with wrappers. 666 797 { 667 Num c=(*capacity)[e]; 668 if ( c <= 0 ) continue; 669 Node w=g->head(e); 670 if ( level[w] < n ) { 671 if ( excess[w] <= 0 && w!=t ) //putting into the stack 672 { 673 next.set(w,first[level[w]]); 674 first[level[w]]=w; 675 } 676 flow->set(e, c); 677 excess.set(w, excess[w]+c); 678 } 679 } 680 break; 681 } 682 683 case GEN_FLOW: 684 { 685 //Reverse_bfs from t in the residual graph, 686 //to find the starting level. 687 level.set(t,0); 688 bfs_queue.push(t); 689 690 while (!bfs_queue.empty()) { 691 692 Node v=bfs_queue.front(); 693 bfs_queue.pop(); 694 int l=level[v]+1; 695 696 InEdgeIt e; 697 for(g->first(e,v); g->valid(e); g->next(e)) { 698 if ( (*capacity)[e] <= (*flow)[e] ) continue; 699 Node w=g->tail(e); 700 if ( level[w] == n && w != s ) { 701 bfs_queue.push(w); 702 Node z=level_list[l]; 703 if ( g->valid(z) ) left.set(z,w); 704 right.set(w,z); 705 level_list[l]=w; 706 level.set(w, l); 707 } 708 } 709 710 OutEdgeIt f; 711 for(g->first(f,v); g->valid(f); g->next(f)) { 712 if ( 0 >= (*flow)[f] ) continue; 713 Node w=g->head(f); 714 if ( level[w] == n && w != s ) { 715 bfs_queue.push(w); 716 Node z=level_list[l]; 717 if ( g->valid(z) ) left.set(z,w); 718 right.set(w,z); 719 level_list[l]=w; 720 level.set(w, l); 721 } 722 } 723 } 724 725 //the starting flow 726 OutEdgeIt e; 727 for(g->first(e,s); g->valid(e); g->next(e)) 728 { 729 Num rem=(*capacity)[e]-(*flow)[e]; 730 if ( rem <= 0 ) continue; 731 Node w=g->head(e); 732 if ( level[w] < n ) { 733 if ( excess[w] <= 0 && w!=t ) //putting into the stack 734 { 735 next.set(w,first[level[w]]); 736 first[level[w]]=w; 737 } 738 flow->set(e, (*capacity)[e]); 739 excess.set(w, excess[w]+rem); 740 } 741 } 742 743 InEdgeIt f; 744 for(g->first(f,s); g->valid(f); g->next(f)) 745 { 746 if ( (*flow)[f] <= 0 ) continue; 747 Node w=g->tail(f); 748 if ( level[w] < n ) { 749 if ( excess[w] <= 0 && w!=t ) 750 { 751 next.set(w,first[level[w]]); 752 first[level[w]]=w; 753 } 754 excess.set(w, excess[w]+(*flow)[f]); 755 flow->set(f, 0); 756 } 757 } 758 break; 759 } //case GEN_FLOW 760 761 case PRE_FLOW: 762 { 763 //Reverse_bfs from t in the residual graph, 764 //to find the starting level. 765 level.set(t,0); 766 bfs_queue.push(t); 767 768 while (!bfs_queue.empty()) { 769 770 Node v=bfs_queue.front(); 771 bfs_queue.pop(); 772 int l=level[v]+1; 773 774 InEdgeIt e; 775 for(g->first(e,v); g->valid(e); g->next(e)) { 776 if ( (*capacity)[e] <= (*flow)[e] ) continue; 777 Node w=g->tail(e); 778 if ( level[w] == n && w != s ) { 779 bfs_queue.push(w); 780 Node z=level_list[l]; 781 if ( g->valid(z) ) left.set(z,w); 782 right.set(w,z); 783 level_list[l]=w; 784 level.set(w, l); 785 } 786 } 787 788 OutEdgeIt f; 789 for(g->first(f,v); g->valid(f); g->next(f)) { 790 if ( 0 >= (*flow)[f] ) continue; 791 Node w=g->head(f); 792 if ( level[w] == n && w != s ) { 793 bfs_queue.push(w); 794 Node z=level_list[l]; 795 if ( g->valid(z) ) left.set(z,w); 796 right.set(w,z); 797 level_list[l]=w; 798 level.set(w, l); 799 } 800 } 801 } 802 803 804 //the starting flow 805 OutEdgeIt e; 806 for(g->first(e,s); g->valid(e); g->next(e)) 807 { 808 Num rem=(*capacity)[e]-(*flow)[e]; 809 if ( rem <= 0 ) continue; 810 Node w=g->head(e); 811 if ( level[w] < n ) { 812 flow->set(e, (*capacity)[e]); 813 excess.set(w, excess[w]+rem); 814 } 815 } 816 817 InEdgeIt f; 818 for(g->first(f,s); g->valid(f); g->next(f)) 819 { 820 if ( (*flow)[f] <= 0 ) continue; 821 Node w=g->tail(f); 822 if ( level[w] < n ) { 823 excess.set(w, excess[w]+(*flow)[f]); 824 flow->set(f, 0); 825 } 826 } 827 828 NodeIt w; //computing the excess 829 for(g->first(w); g->valid(w); g->next(w)) { 830 Num exc=0; 831 832 InEdgeIt e; 833 for(g->first(e,w); g->valid(e); g->next(e)) exc+=(*flow)[e]; 834 OutEdgeIt f; 835 for(g->first(f,w); g->valid(f); g->next(f)) exc-=(*flow)[f]; 836 837 excess.set(w,exc); 838 839 //putting the active nodes into the stack 840 int lev=level[w]; 841 if ( exc > 0 && lev < n && Node(w) != t ) 842 ///\bug if ( exc > 0 && lev < n && w != t ) tempararily for working with wrappers. in hugo 0.2 it will work. Amugy mukodik sage_graph-fal, de smart_graph-fal nem, azt hozzatennem. 843 { 844 next.set(w,first[lev]); 845 first[lev]=w; 846 } 847 } 848 break; 849 } //case PRE_FLOW 850 } 798 next.set(w,first[lev]); 799 first[lev]=w; 800 } 801 } 802 break; 803 } //switch 851 804 } //preflowPreproc 852 805 … … 863 816 864 817 //unlacing starts 865 if ( g->valid(right_n)) {866 if ( g->valid(left_n)) {818 if ( right_n!=INVALID ) { 819 if ( left_n!=INVALID ) { 867 820 right.set(left_n, right_n); 868 821 left.set(right_n, left_n); … … 872 825 } 873 826 } else { 874 if ( g->valid(left_n)) {827 if ( left_n!=INVALID ) { 875 828 right.set(left_n, INVALID); 876 829 } else { … … 880 833 //unlacing ends 881 834 882 if ( !g->valid(level_list[lev])) {835 if ( level_list[lev]==INVALID ) { 883 836 884 837 //gapping starts 885 838 for (int i=lev; i!=k ; ) { 886 839 Node v=level_list[++i]; 887 while ( g->valid(v)) {840 while ( v!=INVALID ) { 888 841 level.set(v,n); 889 842 v=right[v]; … … 908 861 if ( k < newlevel ) ++k; //now k=newlevel 909 862 Node z=level_list[newlevel]; 910 if ( g->valid(z)) left.set(z,w);863 if ( z!=INVALID ) left.set(z,w); 911 864 right.set(w,z); 912 865 left.set(w,INVALID); … … 919 872 std::cout << "Excesses:" <<std::endl; 920 873 921 NodeIt v; 922 for(g->first(v); g->valid(v); g->next(v)) { 874 for(NodeIt v(*g); v!=INVALID ; ++v) { 923 875 std::cout << 1+(g->id(v)) << ":" << excess[v]<<std::endl; 924 876 } 925 877 } 926 878 927 void printlevel() {////879 void printlevel() {//// 928 880 std::cout << "Levels:" <<std::endl; 929 881 930 NodeIt v; 931 for(g->first(v); g->valid(v); g->next(v)) { 882 for(NodeIt v(*g); v!=INVALID ; ++v) { 932 883 std::cout << 1+(g->id(v)) << ":" << level[v]<<std::endl; 933 884 } 934 885 } 935 886 936 void printactive() {////887 void printactive() {//// 937 888 std::cout << "Levels:" <<std::endl; 938 889 939 NodeIt v; 940 for(g->first(v); g->valid(v); g->next(v)) { 890 for(NodeIt v(*g); v!=INVALID ; ++v) { 941 891 std::cout << 1+(g->id(v)) << ":" << level[v]<<std::endl; 942 892 } -
src/hugo/skeletons/graph.h
r732 r774 35 35 public: 36 36 /// Defalult constructor. 37 StaticGraphSkeleton() { }37 StaticGraphSkeleton() { } 38 38 ///Copy consructor. 39 39 40 40 ///\todo It is not clear, what we expect from a copy constructor. 41 41 ///E.g. How to assign the nodes/edges to each other? What about maps? 42 StaticGraphSkeleton(const StaticGraphSkeleton &G) {} 43 44 /// The base type of the node iterators. 45 46 /// This is the base type of each node iterators, 47 /// thus each kind of node iterator will convert to this. 42 StaticGraphSkeleton(const StaticGraphSkeleton& g) { } 43 44 /// The base type of node iterators, 45 /// or in other words, the trivial node iterator. 46 47 /// This is the base type of each node iterator, 48 /// thus each kind of node iterator converts to this. 49 /// More precisely each kind of node iterator have to be inherited 50 /// from the trivial node iterator. 48 51 class Node { 49 52 public: 50 53 /// @warning The default constructor sets the iterator 51 54 /// to an undefined value. 52 Node() {} //FIXME 55 Node() { } 56 /// Copy constructor. 57 Node(const Node&) { } 53 58 /// Invalid constructor \& conversion. 54 59 55 60 /// This constructor initializes the iterator to be invalid. 56 61 /// \sa Invalid for more details. 57 58 Node(Invalid) {} 59 //Node(const Node &) {} 60 62 Node(Invalid) { } 61 63 /// Two iterators are equal if and only if they point to the 62 64 /// same object or both are invalid. … … 74 76 /// This iterator goes through each node. 75 77 /// Its usage is quite simple, for example you can count the number 76 /// of nodes in graph \c Gof type \c Graph like this:78 /// of nodes in graph \c g of type \c Graph like this: 77 79 /// \code 78 /// int count=0;79 /// for(Graph::NodeIt n(G);G.valid(n);G.next(n)) count++;80 /// int count=0; 81 /// for (Graph::NodeIt n(g); g.valid(n); ++n) ++count; 80 82 /// \endcode 81 83 class NodeIt : public Node { … … 83 85 /// @warning The default constructor sets the iterator 84 86 /// to an undefined value. 85 NodeIt() {} //FIXME 87 NodeIt() { } 88 /// Copy constructor. 89 NodeIt(const NodeIt&) { } 86 90 /// Invalid constructor \& conversion. 87 91 88 /// Initialize the iterator to be invalid 92 /// Initialize the iterator to be invalid. 89 93 /// \sa Invalid for more details. 90 NodeIt(Invalid) {} 91 /// Sets the iterator to the first node of \c G. 92 NodeIt(const StaticGraphSkeleton &) {} 93 /// @warning The default constructor sets the iterator 94 /// to an undefined value. 95 NodeIt(const NodeIt &n) : Node(n) {} 94 NodeIt(Invalid) { } 95 /// Sets the iterator to the first node of \c g. 96 NodeIt(const StaticGraphSkeleton& g) { } 97 /// Sets the iterator to the node of \c g pointed by the trivial 98 /// iterator n. This feature necessitates that each time we 99 /// iterate the node-set, the iteration order is the same. 100 NodeIt(const StaticGraphSkeleton& g, const Node& n) { } 101 /// Assign the iterator to the next node. 102 NodeIt& operator++() { return *this; } 96 103 }; 97 104 … … 102 109 /// @warning The default constructor sets the iterator 103 110 /// to an undefined value. 104 Edge() {} //FIXME 105 /// Initialize the iterator to be invalid 106 Edge(Invalid) {} 111 Edge() { } 112 /// Copy constructor. 113 Edge(const Edge&) { } 114 /// Initialize the iterator to be invalid. 115 Edge(Invalid) { } 107 116 /// Two iterators are equal if and only if they point to the 108 117 /// same object or both are invalid. … … 118 127 /// Its usage is quite simple, for example you can count the number 119 128 /// of outgoing edges of a node \c n 120 /// in graph \c Gof type \c Graph as follows.129 /// in graph \c g of type \c Graph as follows. 121 130 /// \code 122 /// int count=0;123 /// for(Graph::OutEdgeIt e(G,n);G.valid(e);G.next(e)) count++;131 /// int count=0; 132 /// for (Graph::OutEdgeIt e(g, n); g.valid(e); ++e) ++count; 124 133 /// \endcode 125 134 … … 128 137 /// @warning The default constructor sets the iterator 129 138 /// to an undefined value. 130 OutEdgeIt() {} 131 /// Initialize the iterator to be invalid 132 OutEdgeIt(Invalid) {} 139 OutEdgeIt() { } 140 /// Copy constructor. 141 OutEdgeIt(const OutEdgeIt&) { } 142 /// Initialize the iterator to be invalid. 143 OutEdgeIt(Invalid) { } 133 144 /// This constructor sets the iterator to first outgoing edge. 134 145 … … 136 147 /// node 137 148 ///@param n the node 138 ///@param G the graph 139 OutEdgeIt(const StaticGraphSkeleton &, Node) {} 149 ///@param g the graph 150 OutEdgeIt(const StaticGraphSkeleton& g, const Node& n) { } 151 /// Sets the iterator to the value of the trivial iterator \c e. 152 /// This feature necessitates that each time we 153 /// iterate the edge-set, the iteration order is the same. 154 OutEdgeIt(const StaticGraphSkeleton& g, const Edge& e) { } 155 /// Assign the iterator to the next outedge of the corresponding node. 156 OutEdgeIt& operator++() { return *this; } 140 157 }; 141 158 … … 146 163 /// Its usage is quite simple, for example you can count the number 147 164 /// of outgoing edges of a node \c n 148 /// in graph \c Gof type \c Graph as follows.165 /// in graph \c g of type \c Graph as follows. 149 166 /// \code 150 /// int count=0;151 /// for(Graph::InEdgeIt e(G,n);G.valid(e);G.next(e)) count++;167 /// int count=0; 168 /// for(Graph::InEdgeIt e(g, n); g.valid(e); ++) ++count; 152 169 /// \endcode 153 170 … … 156 173 /// @warning The default constructor sets the iterator 157 174 /// to an undefined value. 158 InEdgeIt() {} 159 /// Initialize the iterator to be invalid 160 InEdgeIt(Invalid) {} 161 InEdgeIt(const StaticGraphSkeleton &, Node) {} 175 InEdgeIt() { } 176 /// Copy constructor. 177 InEdgeIt(const InEdgeIt&) { } 178 /// Initialize the iterator to be invalid. 179 InEdgeIt(Invalid) { } 180 /// . 181 InEdgeIt(const StaticGraphSkeleton&, const Node&) { } 182 /// . 183 InEdgeIt(const StaticGraphSkeleton&, const Edge&) { } 184 /// Assign the iterator to the next inedge of the corresponding node. 185 InEdgeIt& operator++() { return *this; } 162 186 }; 163 187 // class SymEdgeIt : public Edge {}; … … 167 191 /// This iterator goes through each edge of a graph. 168 192 /// Its usage is quite simple, for example you can count the number 169 /// of edges in a graph \c Gof type \c Graph as follows:193 /// of edges in a graph \c g of type \c Graph as follows: 170 194 /// \code 171 /// int count=0;172 /// for(Graph::EdgeIt e(G);G.valid(e);G.next(e)) count++;195 /// int count=0; 196 /// for(Graph::EdgeIt e(g); g.valid(e); ++e) ++count; 173 197 /// \endcode 174 198 class EdgeIt : public Edge { … … 176 200 /// @warning The default constructor sets the iterator 177 201 /// to an undefined value. 178 EdgeIt() {} 179 /// Initialize the iterator to be invalid 180 EdgeIt(Invalid) {} 181 EdgeIt(const StaticGraphSkeleton &) {} 202 EdgeIt() { } 203 /// Copy constructor. 204 EdgeIt(const EdgeIt&) { } 205 /// Initialize the iterator to be invalid. 206 EdgeIt(Invalid) { } 207 /// . 208 EdgeIt(const StaticGraphSkeleton&) { } 209 /// . 210 EdgeIt(const StaticGraphSkeleton&, const Edge&) { } 211 EdgeIt& operator++() { return *this; } 182 212 }; 183 213 … … 187 217 /// \return the first node. 188 218 /// 189 NodeIt &first(NodeIt &i) const { return i;}219 NodeIt& first(NodeIt& i) const { return i; } 190 220 191 221 /// The first incoming edge. 192 InEdgeIt &first(InEdgeIt &i, Node) const { return i;}222 InEdgeIt& first(InEdgeIt &i, Node) const { return i; } 193 223 /// The first outgoing edge. 194 OutEdgeIt &first(OutEdgeIt &i, Node) const { return i;}195 // SymEdgeIt &first(SymEdgeIt &, Node) const { return i;}224 OutEdgeIt& first(OutEdgeIt& i, Node) const { return i; } 225 // SymEdgeIt& first(SymEdgeIt&, Node) const { return i; } 196 226 /// The first edge of the Graph. 197 EdgeIt &first(EdgeIt &i) const { return i;}227 EdgeIt& first(EdgeIt& i) const { return i; } 198 228 199 229 // Node getNext(Node) const {} … … 204 234 205 235 /// Go to the next node. 206 NodeIt &next(NodeIt &i) const { return i;}236 NodeIt& next(NodeIt& i) const { return i; } 207 237 /// Go to the next incoming edge. 208 InEdgeIt &next(InEdgeIt &i) const { return i;}238 InEdgeIt& next(InEdgeIt& i) const { return i; } 209 239 /// Go to the next outgoing edge. 210 OutEdgeIt &next(OutEdgeIt &i) const { return i;}211 //SymEdgeIt &next(SymEdgeIt &) const {}240 OutEdgeIt& next(OutEdgeIt& i) const { return i; } 241 //SymEdgeIt& next(SymEdgeIt&) const { } 212 242 /// Go to the next edge. 213 EdgeIt &next(EdgeIt &i) const { return i;}243 EdgeIt& next(EdgeIt& i) const { return i; } 214 244 215 245 ///Gives back the head node of an edge. … … 230 260 ///\todo Maybe, it would be better if iterator converted to 231 261 ///bool directly, as Jacint prefers. 232 bool valid(const Node&) const { return true; }262 bool valid(const Node&) const { return true; } 233 263 /// Checks if an edge iterator is valid 234 264 235 265 ///\todo Maybe, it would be better if iterator converted to 236 266 ///bool directly, as Jacint prefers. 237 bool valid(const Edge&) const { return true; }267 bool valid(const Edge&) const { return true; } 238 268 239 269 ///Gives back the \e id of a node. … … 241 271 ///\warning Not all graph structures provide this feature. 242 272 /// 243 int id(const Node&) const { return 0; }273 int id(const Node&) const { return 0; } 244 274 ///Gives back the \e id of an edge. 245 275 246 276 ///\warning Not all graph structures provide this feature. 247 277 /// 248 int id(const Edge&) const { return 0; }278 int id(const Edge&) const { return 0; } 249 279 250 280 /// Resets the graph. … … 252 282 /// This function deletes all edges and nodes of the graph. 253 283 /// It also frees the memory allocated to store them. 254 void clear() {} 255 256 int nodeNum() const { return 0;} 257 int edgeNum() const { return 0;} 258 284 void clear() { } 285 286 int nodeNum() const { return 0; } 287 int edgeNum() const { return 0; } 259 288 260 289 … … 271 300 public: 272 301 273 class ReferenceMap<Node,T>; 274 275 NodeMap(const StaticGraphSkeleton &) {} 276 NodeMap(const StaticGraphSkeleton &, T) {} 302 NodeMap(const StaticGraphSkeleton&) { } 303 NodeMap(const StaticGraphSkeleton&, T) { } 277 304 278 305 ///Copy constructor 279 template<typename TT> NodeMap(const NodeMap<TT> &) {}306 template<typename TT> NodeMap(const NodeMap<TT>&) { } 280 307 ///Assignment operator 281 template<typename TT> NodeMap &operator=(const NodeMap<TT>&)282 { return *this;}308 template<typename TT> NodeMap& operator=(const NodeMap<TT>&) 309 { return *this; } 283 310 }; 284 311 … … 296 323 typedef Edge KeyType; 297 324 298 EdgeMap(const StaticGraphSkeleton &) {}299 EdgeMap(const StaticGraphSkeleton &, T ) {}325 EdgeMap(const StaticGraphSkeleton&) { } 326 EdgeMap(const StaticGraphSkeleton&, T) { } 300 327 301 328 ///Copy constructor 302 template<typename TT> EdgeMap(const EdgeMap<TT> &) {}329 template<typename TT> EdgeMap(const EdgeMap<TT>&) { } 303 330 ///Assignment operator 304 template<typename TT> EdgeMap &operator=(const EdgeMap<TT> 305 { return *this;}331 template<typename TT> EdgeMap &operator=(const EdgeMap<TT>&) 332 { return *this; } 306 333 }; 307 334 }; … … 318 345 public: 319 346 /// Defalult constructor. 320 GraphSkeleton() { }347 GraphSkeleton() { } 321 348 ///Copy consructor. 322 349 323 350 ///\todo It is not clear, what we expect from a copy constructor. 324 351 ///E.g. How to assign the nodes/edges to each other? What about maps? 325 GraphSkeleton(const GraphSkeleton &G) {}352 GraphSkeleton(const GraphSkeleton&) { } 326 353 327 354 ///Add a new node to the graph. … … 329 356 /// \return the new node. 330 357 /// 331 Node addNode() { return INVALID; }358 Node addNode() { return INVALID; } 332 359 ///Add a new edge to the graph. 333 360 … … 335 362 ///and head node \c head. 336 363 ///\return the new edge. 337 Edge addEdge(Node, Node) { return INVALID; }364 Edge addEdge(Node, Node) { return INVALID; } 338 365 339 366 /// Resets the graph. … … 342 369 /// It also frees the memory allocated to store them. 343 370 /// \todo It might belong to \c EraseableGraphSkeleton. 344 void clear() { }371 void clear() { } 345 372 }; 346 373 … … 353 380 public: 354 381 /// Deletes a node. 355 void erase(Node n) { }382 void erase(Node n) { } 356 383 /// Deletes an edge. 357 void erase(Edge e) { }384 void erase(Edge e) { } 358 385 359 386 /// Defalult constructor. 360 EraseableGraphSkeleton() { }387 EraseableGraphSkeleton() { } 361 388 ///Copy consructor. 362 EraseableGraphSkeleton(const GraphSkeleton &G) {}389 EraseableGraphSkeleton(const GraphSkeleton&) { } 363 390 }; 364 391 -
src/hugo/smart_graph.h
r753 r774 122 122 Node head(Edge e) const { return edges[e.n].head; } 123 123 124 Node aNode(OutEdgeIt e) const { return edges[e.n].tail; }125 Node aNode(InEdgeIt e) const { return edges[e.n].head; }126 127 Node bNode(OutEdgeIt e) const { return edges[e.n].head; }128 Node bNode(InEdgeIt e) const { return edges[e.n].tail; }129 130 124 NodeIt& first(NodeIt& v) const { 131 125 v=NodeIt(*this); return v; } … … 137 131 e=InEdgeIt(*this,v); return e; } 138 132 139 // template< typename It >140 // It first() const { It e; first(e); return e; }141 142 // template< typename It >143 // It first(Node v) const { It e; first(e,v); return e; }144 145 static bool valid(Edge e) { return e.n!=-1; }146 static bool valid(Node n) { return n.n!=-1; }147 148 ///\deprecated Use149 ///\code150 /// e=INVALID;151 ///\endcode152 ///instead.153 static void setInvalid(Edge &e) { e.n=-1; }154 ///\deprecated Use155 ///\code156 /// e=INVALID;157 ///\endcode158 ///instead.159 static void setInvalid(Node &n) { n.n=-1; }160 161 template <typename It> It getNext(It it) const162 { It tmp(it); return next(tmp); }163 164 NodeIt& next(NodeIt& it) const {165 it.n=(it.n+2)%(nodes.size()+1)-1;166 return it;167 }168 OutEdgeIt& next(OutEdgeIt& it) const169 { it.n=edges[it.n].next_out; return it; }170 InEdgeIt& next(InEdgeIt& it) const171 { it.n=edges[it.n].next_in; return it; }172 EdgeIt& next(EdgeIt& it) const { --it.n; return it; }173 174 133 static int id(Node v) { return v.n; } 175 134 static int id(Edge e) { return e.n; } … … 198 157 } 199 158 159 /// Finds an edge between two nodes. 160 161 /// Finds an edge from node \c u to node \c v. 162 /// 163 /// If \c prev is \ref INVALID (this is the default value), then 164 /// It finds the first edge from \c u to \c v. Otherwise it looks for 165 /// the next edge from \c u to \c v after \c prev. 166 /// \return The found edge or INVALID if there is no such an edge. 167 Edge findEdge(Node u,Node v, Edge prev = INVALID) 168 { 169 int e = (prev.n==-1)? nodes[u.n].first_out : edges[prev.n].next_out; 170 while(e!=-1 && edges[e].tail!=v.n) e = edges[e].next_out; 171 prev.n=e; 172 return prev; 173 } 174 200 175 void clear() {nodes.clear();edges.clear();} 201 176 … … 219 194 bool operator!=(const Node i) const {return n!=i.n;} 220 195 bool operator<(const Node i) const {return n<i.n;} 196 // ///Validity check 197 // operator bool() { return n!=-1; } 221 198 }; 222 199 223 200 class NodeIt : public Node { 201 const SmartGraph *G; 224 202 friend class SmartGraph; 225 203 public: 226 204 NodeIt() : Node() { } 205 NodeIt(const SmartGraph& _G,Node n) : Node(n), G(&_G) { } 227 206 NodeIt(Invalid i) : Node(i) { } 228 NodeIt(const SmartGraph& G) : Node(G.nodes.size()?0:-1) { } 229 ///\todo Undocumented conversion Node -\> NodeIt. 230 NodeIt(const SmartGraph& G, const Node &n) : Node(n) { } 207 NodeIt(const SmartGraph& _G) : Node(_G.nodes.size()?0:-1), G(&_G) { } 208 NodeIt &operator++() { 209 n=(n+2)%(G->nodes.size()+1)-1; 210 return *this; 211 } 212 // ///Validity check 213 // operator bool() { return Node::operator bool(); } 231 214 }; 232 215 … … 258 241 ///make class \c SymSmartGraph::SymEdgeMap friend of Edge 259 242 int &idref() {return n;} 260 const int &idref() const {return n;} 261 }; 243 const int &idref() const {return n;} 244 // ///Validity check 245 // operator bool() { return n!=-1; } 246 }; 262 247 263 248 class EdgeIt : public Edge { 249 const SmartGraph *G; 264 250 friend class SmartGraph; 265 251 public: 266 EdgeIt(const SmartGraph& G) : Edge(G.edges.size()-1) { } 252 EdgeIt(const SmartGraph& _G) : Edge(_G.edges.size()-1), G(&_G) { } 253 EdgeIt(const SmartGraph& _G, Edge e) : Edge(e), G(&_G) { } 267 254 EdgeIt (Invalid i) : Edge(i) { } 268 255 EdgeIt() : Edge() { } … … 270 257 ///make class \c SymSmartGraph::SymEdgeMap friend of Edge 271 258 int &idref() {return n;} 259 EdgeIt &operator++() { --n; return *this; } 260 // ///Validity check 261 // operator bool() { return Edge::operator bool(); } 272 262 }; 273 263 274 264 class OutEdgeIt : public Edge { 265 const SmartGraph *G; 275 266 friend class SmartGraph; 276 267 public: 277 268 OutEdgeIt() : Edge() { } 269 OutEdgeIt(const SmartGraph& _G, Edge e) : Edge(e), G(&_G) { } 278 270 OutEdgeIt (Invalid i) : Edge(i) { } 279 271 280 OutEdgeIt(const SmartGraph& G,const Node v) 281 : Edge(G.nodes[v.n].first_out) {} 272 OutEdgeIt(const SmartGraph& _G,const Node v) 273 : Edge(_G.nodes[v.n].first_out), G(&_G) {} 274 OutEdgeIt &operator++() { n=G->edges[n].next_out; return *this; } 275 // ///Validity check 276 // operator bool() { return Edge::operator bool(); } 282 277 }; 283 278 284 279 class InEdgeIt : public Edge { 280 const SmartGraph *G; 285 281 friend class SmartGraph; 286 282 public: 287 283 InEdgeIt() : Edge() { } 284 InEdgeIt(const SmartGraph& _G, Edge e) : Edge(e), G(&_G) { } 288 285 InEdgeIt (Invalid i) : Edge(i) { } 289 InEdgeIt(const SmartGraph& G,Node v) :Edge(G.nodes[v.n].first_in){} 286 InEdgeIt(const SmartGraph& _G,Node v) 287 : Edge(_G.nodes[v.n].first_in), G(&_G) { } 288 InEdgeIt &operator++() { n=G->edges[n].next_in; return *this; } 289 // ///Validity check 290 // operator bool() { return Edge::operator bool(); } 290 291 }; 291 292 -
src/hugo/unionfind.h
r649 r774 6 6 //!\file 7 7 //!\brief Union-Find data structures. 8 //! 9 //!\bug unionfind_test.cc doesn't work with Intel compiler. It compiles but 10 //!fails to run (Segmentation fault). 8 11 9 12 -
src/test/Makefile.am
r727 r774 3 3 noinst_HEADERS = test_tools.h 4 4 5 check_PROGRAMS = graph_test dijkstra_test time_measure_test error_test xy_test \ 6 test_tools_pass test_tools_fail 5 check_PROGRAMS = graph_test dijkstra_test bfs_test time_measure_test \ 6 error_test xy_test \ 7 unionfind_test test_tools_pass test_tools_fail 7 8 8 9 TESTS = $(check_PROGRAMS) … … 11 12 graph_test_SOURCES = graph_test.cc 12 13 dijkstra_test_SOURCES = dijkstra_test.cc 14 bfs_test_SOURCES = bfs_test.cc 15 unionfind_test_SOURCES = unionfind_test.cc 13 16 time_measure_test_SOURCES = time_measure_test.cc 14 17 error_test_SOURCES = error_test.cc -
src/test/dijkstra_test.cc
r585 r774 76 76 77 77 78 for(EdgeIt e(G); G.valid(e); G.next(e)) {78 for(EdgeIt e(G); e==INVALID; ++e) { 79 79 Node u=G.tail(e); 80 80 Node v=G.head(e); … … 87 87 88 88 ///\bug This works only for integer lengths 89 for(NodeIt v(G); G.valid(v); G.next(v))89 for(NodeIt v(G); v==INVALID; ++v) 90 90 if ( dijkstra_test.reached(v) ) { 91 91 Edge e=dijkstra_test.pred(v); -
src/test/graph_test.cc
r733 r774 7 7 #include"test_tools.h" 8 8 9 /* 9 /** 10 \file 10 11 This test makes consistency checks of list graph structures. 11 12 12 G.addNode(), G.addEdge(), G. valid(), G.tail(), G.head()13 G.addNode(), G.addEdge(), G.tail(), G.head() 13 14 14 15 \todo Checks for empty graphs and isolated points. 16 \todo Checks for Node->NodeIt, Edge->{EdgeIt,InEdgeIt,OutEdgeIt} 17 conversion. 15 18 */ 16 19 … … 30 33 Node i; Node j(i); Node k(INVALID); 31 34 i=j; 32 bool b=G.valid(i); b=b; 35 // bool b=G.valid(i); b=b; 36 bool b; b=b; 37 b=(i==INVALID); b=(i!=INVALID); 33 38 b=(i==j); b=(i!=j); b=(i<j); 34 39 } … … 37 42 i=j; 38 43 j=G.first(i); 39 j=G.next(i); 40 bool b=G.valid(i); b=b; 44 j=++i; 45 // bool b=G.valid(i); b=b; 46 bool b; b=b; 47 b=(i==INVALID); b=(i!=INVALID); 41 48 Node n(i); 42 49 n=i; 43 50 b=(i==j); b=(i!=j); b=(i<j); 51 //Node ->NodeIt conversion 52 NodeIt ni(G,n); 44 53 } 45 54 { 46 55 Edge i; Edge j(i); Edge k(INVALID); 47 56 i=j; 48 bool b=G.valid(i); b=b; 57 // bool b=G.valid(i); b=b; 58 bool b; b=b; 59 b=(i==INVALID); b=(i!=INVALID); 49 60 b=(i==j); b=(i!=j); b=(i<j); 50 61 } … … 53 64 i=j; 54 65 j=G.first(i); 55 j=G.next(i); 56 bool b=G.valid(i); b=b; 66 j=++i; 67 // bool b=G.valid(i); b=b; 68 bool b; b=b; 69 b=(i==INVALID); b=(i!=INVALID); 57 70 Edge e(i); 58 71 e=i; 59 72 b=(i==j); b=(i!=j); b=(i<j); 73 //Edge ->EdgeIt conversion 74 EdgeIt ei(G,e); 60 75 } 61 76 { … … 64 79 i=j; 65 80 j=G.first(i,n); 66 j=G.next(i); 67 bool b=G.valid(i); b=b; 81 j=++i; 82 // bool b=G.valid(i); b=b; 83 bool b; b=b; 84 b=(i==INVALID); b=(i!=INVALID); 68 85 Edge e(i); 69 86 e=i; 70 87 b=(i==j); b=(i!=j); b=(i<j); 88 //Edge ->InEdgeIt conversion 89 InEdgeIt ei(G,e); 71 90 } 72 91 { … … 75 94 i=j; 76 95 j=G.first(i,n); 77 j=G.next(i); 78 bool b=G.valid(i); b=b; 96 j=++i; 97 // bool b=G.valid(i); b=b; 98 bool b; b=b; 99 b=(i==INVALID); b=(i!=INVALID); 79 100 Edge e(i); 80 101 e=i; 81 102 b=(i==j); b=(i!=j); b=(i<j); 82 }83 84 Node n,m;85 n=m=INVALID;86 Edge e;87 e=INVALID;88 n=G.tail(e);89 n=G.head(e);90 91 //aNode, bNode ?92 103 //Edge ->OutEdgeIt conversion 104 OutEdgeIt ei(G,e); 105 } 106 { 107 Node n,m; 108 n=m=INVALID; 109 Edge e; 110 e=INVALID; 111 n=G.tail(e); 112 n=G.head(e); 113 } 93 114 // id tests 94 { int i=G.id(n); i=i; } 95 { int i=G.id(e); i=i; } 96 97 // G.clear(); 98 115 { Node n; int i=G.id(n); i=i; } 116 { Edge e; int i=G.id(e); i=i; } 99 117 //NodeMap tests 100 118 { 101 119 Node k; 102 120 typename Graph::template NodeMap<int> m(G); 103 typename Graph::template NodeMap<int> const &cm = m; //Const map 121 //Const map 122 typename Graph::template NodeMap<int> const &cm = m; 104 123 //Inicialize with default value 105 124 typename Graph::template NodeMap<int> mdef(G,12); 106 typename Graph::template NodeMap<int> mm(cm); //Copy 107 typename Graph::template NodeMap<double> dm(cm); //Copy from another type 125 //Copy 126 typename Graph::template NodeMap<int> mm(cm); 127 //Copy from another type 128 typename Graph::template NodeMap<double> dm(cm); 108 129 int v; 109 130 v=m[k]; m[k]=v; m.set(k,v); … … 161 182 m=dm; //Copy to another type 162 183 } 163 164 184 } 165 185 … … 178 198 n=G.addNode(); 179 199 m=G.addNode(); 180 181 G.addEdge(n,m); 200 Edge e; 201 e=G.addEdge(n,m); 202 203 // G.clear(); 204 } 205 206 template<class Graph> void checkCompileErase(Graph &G) 207 { 208 typedef typename Graph::Node Node; 209 typedef typename Graph::Edge Edge; 210 Node n; 211 Edge e; 212 G.erase(n); 213 G.erase(e); 214 } 215 216 template<class Graph> void checkCompileEraseEdge(Graph &G) 217 { 218 typedef typename Graph::Edge Edge; 219 Edge e; 220 G.erase(e); 221 } 222 223 template<class Graph> void checkCompileFindEdge(Graph &G) 224 { 225 typedef typename Graph::NodeIt Node; 226 typedef typename Graph::NodeIt NodeIt; 227 228 G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G))); 229 G.findEdge(Node(),Node(),G.findEdge(Node(),Node())); 182 230 } 183 231 … … 187 235 typename Graph::NodeIt n(G); 188 236 for(int i=0;i<nn;i++) { 189 check( G.valid(n),"Wrong Node list linking.");190 G.next(n);191 } 192 check( !G.valid(n),"Wrong Node list linking.");237 check(n!=INVALID,"Wrong Node list linking."); 238 ++n; 239 } 240 check(n==INVALID,"Wrong Node list linking."); 193 241 } 194 242 … … 199 247 EdgeIt e(G); 200 248 for(int i=0;i<nn;i++) { 201 check( G.valid(e),"Wrong Edge list linking.");202 G.next(e);203 } 204 check( !G.valid(e),"Wrong Edge list linking.");249 check(e!=INVALID,"Wrong Edge list linking."); 250 ++e; 251 } 252 check(e==INVALID,"Wrong Edge list linking."); 205 253 } 206 254 … … 211 259 typename Graph::OutEdgeIt e(G,n); 212 260 for(int i=0;i<nn;i++) { 213 check( G.valid(e),"Wrong OutEdge list linking.");214 G.next(e);215 } 216 check( !G.valid(e),"Wrong OutEdge list linking.");261 check(e!=INVALID,"Wrong OutEdge list linking."); 262 ++e; 263 } 264 check(e==INVALID,"Wrong OutEdge list linking."); 217 265 } 218 266 219 267 template<class Graph> void checkInEdgeList(Graph &G, 220 221 268 typename Graph::Node n, 269 int nn) 222 270 { 223 271 typename Graph::InEdgeIt e(G,n); 224 272 for(int i=0;i<nn;i++) { 225 check(G.valid(e),"Wrong InEdge list linking."); 226 G.next(e); 227 } 228 check(!G.valid(e),"Wrong InEdge list linking."); 229 } 230 231 //Checks head(), tail() as well; 273 check(e!=INVALID,"Wrong InEdge list linking."); 274 ++e; 275 } 276 check(e==INVALID,"Wrong InEdge list linking."); 277 } 278 279 ///\file 280 ///\todo Checks head(), tail() as well; 281 232 282 template<class Graph> void bidirPetersen(Graph &G) 233 283 { … … 239 289 std::vector<Edge> ee; 240 290 241 for(EdgeIt e(G); G.valid(e);G.next(e)) ee.push_back(e);291 for(EdgeIt e(G);e!=INVALID;++e) ee.push_back(e); 242 292 243 293 for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++) … … 255 305 checkEdgeList(G,30); 256 306 257 for(NodeIt n(G); G.valid(n);G.next(n)) {307 for(NodeIt n(G);n!=INVALID;++n) { 258 308 checkInEdgeList(G,n,3); 259 309 checkOutEdgeList(G,n,3); 260 G.next(n);310 ++n; 261 311 } 262 312 } 263 313 264 template 314 //Compile GraphSkeleton 315 template 265 316 void checkCompileStaticGraph<StaticGraphSkeleton>(StaticGraphSkeleton &); 266 317 template void checkCompile<GraphSkeleton>(GraphSkeleton &); 267 318 template 319 void checkCompileErase<EraseableGraphSkeleton>(EraseableGraphSkeleton &); 320 321 //Compile SmartGraph 268 322 template void checkCompile<SmartGraph>(SmartGraph &); 323 //Compile SymSmartGraph 269 324 template void checkCompile<SymSmartGraph>(SymSmartGraph &); 325 326 //Compile ListGraph 270 327 template void checkCompile<ListGraph>(ListGraph &); 328 template void checkCompileErase<ListGraph>(ListGraph &); 329 template void checkCompileFindEdge<ListGraph>(ListGraph &); 330 331 //Compile SymListGraph 271 332 template void checkCompile<SymListGraph>(SymListGraph &); 333 template void checkCompileErase<SymListGraph>(SymListGraph &); 334 template void checkCompileFindEdge<SymListGraph>(SymListGraph &); 335 336 //Compile FullGraph 272 337 template void checkCompileStaticGraph<FullGraph>(FullGraph &); 273 338 template void checkCompileFindEdge<FullGraph>(FullGraph &); 339 340 //Compile EdgeSet <ListGraph> 274 341 template void checkCompile<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &); 342 template 343 void checkCompileEraseEdge<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &); 344 template 345 void checkCompileFindEdge<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &); 346 347 //Compile EdgeSet <NodeSet> 275 348 template void checkCompile<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &); 349 template 350 void checkCompileEraseEdge<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &); 351 template void checkCompileFindEdge<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &); 352 276 353 277 354 int main() … … 300 377 } 301 378 302 //\todo map tests. 303 //\todo copy constr tests. 379 ///\file 380 ///\todo map tests. 381 ///\todo copy constr tests. 304 382 305 383 std::cout << __FILE__ ": All tests passed.\n"; -
src/test/test_tools.h
r721 r774 21 21 ///print this (and then exits). 22 22 ///\verbatim graph_test.cc:123: error: This is obviously false. \endverbatim 23 /// 24 ///\todo It should be in \c error.h 23 25 #define check(rc, msg) \ 24 26 if(!(rc)) { \ -
src/test/unionfind_test.cc
r542 r774 3 3 #include <hugo/maps.h> 4 4 #include <hugo/unionfind.h> 5 #include "test_tools.h" 5 6 6 7 using namespace hugo; 7 8 using namespace std; 8 9 bool passed = true;10 11 void check(bool rc) {12 passed = passed && rc;13 if(!rc) {14 cout << "Test failed!" << endl;15 }16 }17 9 18 10 template <typename T> … … 23 15 void print(UFE const &ufe) { 24 16 UFE::ClassIt cit; 25 cout << " printingthe classes of the structure:" << endl;17 cout << "Print the classes of the structure:" << endl; 26 18 int i = 1; 27 19 for (ufe.first(cit); ufe.valid(cit); ufe.next(cit)) { … … 42 34 UFE U(base); 43 35 44 print(U);36 // print(U); 45 37 46 cout << "Insert ing1..." << endl;38 cout << "Insert 1..." << endl; 47 39 U.insert(1); 48 print(U);40 // print(U); 49 41 50 cout << "Insert ing2..." << endl;42 cout << "Insert 2..." << endl; 51 43 U.insert(2); 52 print(U);44 // print(U); 53 45 54 cout << "Join ing1 and 2..." << endl;55 check(U.join(1,2) );56 print(U);46 cout << "Join 1 and 2..." << endl; 47 check(U.join(1,2),"Test failed."); 48 // print(U); 57 49 58 cout << "Insert ing3, 4, 5, 6, 7..." << endl;50 cout << "Insert 3, 4, 5, 6, 7..." << endl; 59 51 U.insert(3); 60 52 U.insert(4); … … 62 54 U.insert(6); 63 55 U.insert(7); 64 print (U);56 // print (U); 65 57 66 cout << "Join ing1 - 4, 2 - 4 and 3 - 5 ..." << endl;67 check(U.join(1,4) );68 check(!U.join(2,4) );69 check(U.join(3,5) );70 print(U);58 cout << "Join 1 - 4, 2 - 4 and 3 - 5 ..." << endl; 59 check(U.join(1,4),"Test failed."); 60 check(!U.join(2,4),"Test failed."); 61 check(U.join(3,5),"Test failed."); 62 // print(U); 71 63 72 cout << "Insert ing8 to the component of 5 ..." << endl;64 cout << "Insert 8 to the component of 5 ..." << endl; 73 65 U.insert(8,5); 74 print(U);66 // print(U); 75 67 76 cout << " size of the class of 4: " << U.size(4) << endl;77 check(U.size(4) == 3 );78 cout << " size of the class of 5: " << U.size(5) << endl;79 check(U.size(5) == 3 );80 cout << " size of the class of 6: " << U.size(6) << endl;81 check(U.size(6) == 1 );82 cout << " size of the class of 2: " << U.size(2) << endl;83 check(U.size(2) == 3 );68 cout << "Size of the class of 4: " << U.size(4) << endl; 69 check(U.size(4) == 3,"Test failed."); 70 cout << "Size of the class of 5: " << U.size(5) << endl; 71 check(U.size(5) == 3,"Test failed."); 72 cout << "Size of the class of 6: " << U.size(6) << endl; 73 check(U.size(6) == 1,"Test failed."); 74 cout << "Size of the class of 2: " << U.size(2) << endl; 75 check(U.size(2) == 3,"Test failed."); 84 76 85 cout << "Insert ing9 ..." << endl;77 cout << "Insert 9 ..." << endl; 86 78 U.insert(9); 87 print(U);88 cout << "Insert ing10 to the component of 9 ..." << endl;79 // print(U); 80 cout << "Insert 10 to the component of 9 ..." << endl; 89 81 U.insert(10,9); 90 print(U);82 // print(U); 91 83 92 cout << "Join ing8 and 10..." << endl;93 check(U.join(8,10) );94 print(U);84 cout << "Join 8 and 10..." << endl; 85 check(U.join(8,10),"Test failed."); 86 // print(U); 95 87 96 88 cout << "Move 9 to the class of 4 ..." << endl; 97 check(U.move(9,4) );98 print(U);89 check(U.move(9,4),"Test failed."); 90 // print(U); 99 91 100 92 cout << "Move 9 to the class of 2 ..." << endl; 101 check(!U.move(9,2) );102 print(U);93 check(!U.move(9,2),"Test failed."); 94 // print(U); 103 95 104 cout << " size of the class of 4: " << U.size(4) << endl;105 check(U.size(4) == 4 );106 cout << " size of the class of 9: " << U.size(9) << endl;107 check(U.size(9) == 4 );96 cout << "Size of the class of 4: " << U.size(4) << endl; 97 check(U.size(4) == 4,"Test failed."); 98 cout << "Size of the class of 9: " << U.size(9) << endl; 99 check(U.size(9) == 4,"Test failed."); 108 100 109 101 cout << "Move 5 to the class of 6 ..." << endl; 110 check(U.move(5,6) );111 print(U);102 check(U.move(5,6),"Test failed."); 103 // print(U); 112 104 113 cout << " size of the class of 5: " << U.size(5) << endl;114 check(U.size(5) == 2 );115 cout << " size of the class of 8: " << U.size(8) << endl;116 check(U.size(8) == 3 );105 cout << "Size of the class of 5: " << U.size(5) << endl; 106 check(U.size(5) == 2,"Test failed."); 107 cout << "Size of the class of 8: " << U.size(8) << endl; 108 check(U.size(8) == 3,"Test failed."); 117 109 118 110 cout << "Move 7 to the class of 10 ..." << endl; 119 check(U.move(7,10) );120 print(U);111 check(U.move(7,10),"Test failed."); 112 // print(U); 121 113 122 cout << " size of the class of 7: " << U.size(7) << endl;123 check(U.size(7) == 4 );114 cout << "Size of the class of 7: " << U.size(7) << endl; 115 check(U.size(7) == 4,"Test failed."); 124 116 125 cout <<" erase 9:" << endl;117 cout <<"Erase 9... " << endl; 126 118 U.erase(9); 127 print(U);119 // print(U); 128 120 129 cout <<" erase 1:" << endl;121 cout <<"Erase 1... " << endl; 130 122 U.erase(1); 131 print(U);123 // print(U); 132 124 133 cout << " size of the class of 4: " << U.size(4) << endl;134 check(U.size(4) == 2 );135 cout << " size of the class of 2: " << U.size(2) << endl;136 check(U.size(2) == 2 );125 cout << "Size of the class of 4: " << U.size(4) << endl; 126 check(U.size(4) == 2,"Test failed."); 127 cout << "Size of the class of 2: " << U.size(2) << endl; 128 check(U.size(2) == 2,"Test failed."); 137 129 138 130 139 cout <<" erase 1:" << endl;131 cout <<"Erase 1... " << endl; 140 132 U.erase(1); 141 print(U);133 // print(U); 142 134 143 cout <<" erase 6:" << endl;135 cout <<"Erase 6... " << endl; 144 136 U.erase(6); 145 print(U);137 // print(U); 146 138 147 cout << " split the class of 8:" << endl;139 cout << "Split the class of 8... " << endl; 148 140 U.split(8); 149 print(U);141 // print(U); 150 142 151 143 152 cout << " size of the class of 4: " << U.size(4) << endl;153 check(U.size(4) == 2 );154 cout << " size of the class of 3: " << U.size(3) << endl;155 check(U.size(3) == 1 );156 cout << " size of the class of 2: " << U.size(2) << endl;157 check(U.size(2) == 2 );144 cout << "Size of the class of 4: " << U.size(4) << endl; 145 check(U.size(4) == 2,"Test failed."); 146 cout << "Size of the class of 3: " << U.size(3) << endl; 147 check(U.size(3) == 1,"Test failed."); 148 cout << "Size of the class of 2: " << U.size(2) << endl; 149 check(U.size(2) == 2,"Test failed."); 158 150 159 151 160 cout << "Join ing3 - 4 and 2 - 4 ..." << endl;161 check(U.join(3,4) );162 check(!U.join(2,4) );163 print(U);152 cout << "Join 3 - 4 and 2 - 4 ..." << endl; 153 check(U.join(3,4),"Test failed."); 154 check(!U.join(2,4),"Test failed."); 155 // print(U); 164 156 165 157 166 cout << " size of the class of 4: " << U.size(4) << endl;167 check(U.size(4) == 3 );168 cout << " size of the class of 3: " << U.size(3) << endl;169 check(U.size(3) == 3 );170 cout << " size of the class of 2: " << U.size(2) << endl;171 check(U.size(2) == 3 );158 cout << "Size of the class of 4: " << U.size(4) << endl; 159 check(U.size(4) == 3,"Test failed."); 160 cout << "Size of the class of 3: " << U.size(3) << endl; 161 check(U.size(3) == 3,"Test failed."); 162 cout << "Size of the class of 2: " << U.size(2) << endl; 163 check(U.size(2) == 3,"Test failed."); 172 164 173 cout << "makeRep(4) " << endl;165 cout << "makeRep(4)..." << endl; 174 166 U.makeRep(4); 175 print(U);176 cout << "makeRep(3) " << endl;167 // print(U); 168 cout << "makeRep(3)..." << endl; 177 169 U.makeRep(3); 178 print(U);179 cout << "makeRep(2) " << endl;170 // print(U); 171 cout << "makeRep(2)..." << endl; 180 172 U.makeRep(2); 181 print(U);173 // print(U); 182 174 183 cout << " size of the class of 4: " << U.size(4) << endl;184 check(U.size(4) == 3 );185 cout << " size of the class of 3: " << U.size(3) << endl;186 check(U.size(3) == 3 );187 cout << " size of the class of 2: " << U.size(2) << endl;188 check(U.size(2) == 3 );175 cout << "Size of the class of 4: " << U.size(4) << endl; 176 check(U.size(4) == 3,"Test failed."); 177 cout << "Size of the class of 3: " << U.size(3) << endl; 178 check(U.size(3) == 3,"Test failed."); 179 cout << "Size of the class of 2: " << U.size(2) << endl; 180 check(U.size(2) == 3,"Test failed."); 189 181 190 182 191 183 cout << "eraseClass 4 ..." << endl; 192 184 U.eraseClass(4); 193 print(U);185 // print(U); 194 186 195 187 cout << "eraseClass 7 ..." << endl; 196 188 U.eraseClass(7); 197 print(U);189 // print(U); 198 190 199 cout << "done" << endl; 200 201 cout << (passed ? "All tests passed." : "Some of the tests failed!!!") 202 << endl; 203 204 return passed ? 0 : 1; 191 cout << "done." << endl; 205 192 } -
src/test/xy_test.cc
r727 r774 8 8 { 9 9 10 cout << "Testing classes xy and boundingbox." << endl;10 cout << "Testing classes `xy' and `boundingbox'." << endl; 11 11 12 12 typedef xy<int> XY; … … 34 34 typedef BoundingBox<int> BB; 35 35 BB doboz1; 36 check(doboz1.empty(), " empty? Should be.");36 check(doboz1.empty(), "It should be empty."); 37 37 38 38 doboz1 += a; 39 check(!doboz1.empty(), " empty? Should not be.");39 check(!doboz1.empty(), "It should not be empty."); 40 40 doboz1 += b; 41 41 … … 47 47 48 48 seged.x=2;seged.y=3; 49 check(doboz1.inside(seged),"I nside? It should be.");49 check(doboz1.inside(seged),"It should be inside."); 50 50 51 51 seged.x=1;seged.y=3; 52 check(doboz1.inside(seged),"I nside? It should be.");52 check(doboz1.inside(seged),"It should be inside."); 53 53 54 54 seged.x=0;seged.y=3; 55 check(!doboz1.inside(seged),"I nside? It should not be.");55 check(!doboz1.inside(seged),"It should not be inside."); 56 56 57 57 BB doboz2(seged); 58 58 check(!doboz2.empty(), 59 " empty? Should not be. Constructed from 1 point.");59 "It should not be empty. Constructed from 1 point."); 60 60 61 61 doboz2 += doboz1; 62 62 check(doboz2.inside(seged), 63 " Not inside? It should be. Incremented a box with an other.");63 "It should be inside. Incremented a box with an other."); 64 64 } -
src/work/marci/bfs_dfs.h
r671 r774 61 61 bfs_queue.push(s); 62 62 graph->first(actual_edge, s); 63 if ( graph->valid(actual_edge)) {64 Node w=graph-> bNode(actual_edge);63 if (actual_edge!=INVALID) { 64 Node w=graph->head(actual_edge); 65 65 if (!reached[w]) { 66 66 bfs_queue.push(w); … … 79 79 BfsIterator<Graph, /*OutEdgeIt,*/ ReachedMap>& 80 80 operator++() { 81 if ( graph->valid(actual_edge)) {82 graph->next(actual_edge);83 if ( graph->valid(actual_edge)) {84 Node w=graph-> bNode(actual_edge);81 if (actual_edge!=INVALID) { 82 ++actual_edge; 83 if (actual_edge!=INVALID) { 84 Node w=graph->head(actual_edge); 85 85 if (!reached[w]) { 86 86 bfs_queue.push(w); … … 95 95 if (!bfs_queue.empty()) { 96 96 graph->first(actual_edge, bfs_queue.front()); 97 if ( graph->valid(actual_edge)) {98 Node w=graph-> bNode(actual_edge);97 if (actual_edge!=INVALID) { 98 Node w=graph->head(actual_edge); 99 99 if (!reached[w]) { 100 100 bfs_queue.push(w); … … 118 118 bool isBNodeNewlyReached() const { return b_node_newly_reached; } 119 119 /// Returns if a-node is examined. 120 bool isANodeExamined() const { return !(graph->valid(actual_edge)); }120 bool isANodeExamined() const { return actual_edge==INVALID; } 121 121 /// Returns a-node of the actual edge, so does if the edge is invalid. 122 122 Node aNode() const { return bfs_queue.front(); } … … 238 238 actual_edge=dfs_stack.top(); 239 239 //actual_node=G.aNode(actual_edge); 240 if ( graph->valid(actual_edge)/*.valid()*/) {241 Node w=graph-> bNode(actual_edge);240 if (actual_edge!=INVALID/*.valid()*/) { 241 Node w=graph->head(actual_edge); 242 242 actual_node=w; 243 243 if (!reached[w]) { … … 248 248 b_node_newly_reached=true; 249 249 } else { 250 actual_node=graph-> aNode(actual_edge);251 graph->next(dfs_stack.top());250 actual_node=graph->tail(actual_edge); 251 ++dfs_stack.top(); 252 252 b_node_newly_reached=false; 253 253 } … … 267 267 bool isBNodeNewlyReached() const { return b_node_newly_reached; } 268 268 /// Returns if a-node is examined. 269 bool isANodeExamined() const { return !(graph->valid(actual_edge)); }269 bool isANodeExamined() const { return actual_edge==INVALID; } 270 270 /// Returns a-node of the actual edge, so does if the edge is invalid. 271 271 Node aNode() const { return actual_node; /*FIXME*/} -
src/work/marci/iterator_bfs_demo.cc
r642 r774 5 5 6 6 #include <sage_graph.h> 7 //#include <smart_graph.h>7 #include <hugo/smart_graph.h> 8 8 #include <bfs_dfs.h> 9 9 #include <hugo/graph_wrapper.h> … … 29 29 int main (int, char*[]) 30 30 { 31 //typedef SmartGraph Graph;32 typedef SageGraph Graph;31 typedef SmartGraph Graph; 32 //typedef SageGraph Graph; 33 33 34 34 typedef Graph::Node Node; … … 92 92 93 93 cout << "bfs and dfs iterator demo on the directed graph" << endl; 94 for(Graph::NodeIt n(G); G.valid(n); G.next(n)) {94 for(Graph::NodeIt n(G); n!=INVALID; ++n) { 95 95 cout << node_name[n] << ": "; 96 96 cout << "out edges: "; 97 for(Graph::OutEdgeIt e(G, n); G.valid(e); G.next(e))97 for(Graph::OutEdgeIt e(G, n); e!=INVALID; ++e) 98 98 cout << edge_name[e] << " "; 99 99 cout << "in edges: "; 100 for(Graph::InEdgeIt e(G, n); G.valid(e); G.next(e))100 for(Graph::InEdgeIt e(G, n); e!=INVALID; ++e) 101 101 cout << edge_name[e] << " "; 102 102 cout << endl; … … 108 108 while (!bfs.finished()) { 109 109 //cout << "edge: "; 110 if (G .valid(bfs)) {110 if (Graph::Edge(Graph::OutEdgeIt(bfs))!=INVALID) { 111 111 cout << edge_name[bfs] << /*endl*/", " << 112 node_name[G. aNode(bfs)] <<113 (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 114 node_name[G. bNode(bfs)] <<112 node_name[G.tail(bfs)] << 113 (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 114 node_name[G.head(bfs)] << 115 115 (bfs.isBNodeNewlyReached() ? ": is newly reached." : 116 116 ": is not newly reached."); … … 142 142 ++dfs; 143 143 //cout << "edge: "; 144 if (G .valid(dfs)) {144 if (Graph::Edge(Graph::OutEdgeIt(dfs))!=INVALID) { 145 145 cout << edge_name[dfs] << /*endl*/", " << 146 node_name[G. aNode(dfs)] <<147 (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 148 node_name[G. bNode(dfs)] <<146 node_name[G.tail(dfs)] << 147 (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 148 node_name[G.head(dfs)] << 149 149 (dfs.isBNodeNewlyReached() ? ": is newly reached." : 150 150 ": is not newly reached."); … … 168 168 169 169 cout << "bfs and dfs iterator demo on the reversed directed graph" << endl; 170 for(GW::NodeIt n(gw); gw.valid(n); gw.next(n)) {170 for(GW::NodeIt n(gw); n!=INVALID; ++n) { 171 171 cout << node_name[GW::Node(n)] << ": "; 172 172 cout << "out edges: "; 173 for(GW::OutEdgeIt e(gw, n); gw.valid(e); gw.next(e))173 for(GW::OutEdgeIt e(gw, n); e!=INVALID; ++e) 174 174 cout << edge_name[e] << " "; 175 175 cout << "in edges: "; 176 for(GW::InEdgeIt e(gw, n); gw.valid(e); gw.next(e))176 for(GW::InEdgeIt e(gw, n); e!=INVALID; ++e) 177 177 cout << edge_name[e] << " "; 178 178 cout << endl; … … 184 184 while (!bfs.finished()) { 185 185 //cout << "edge: "; 186 if ( gw.valid(GW::OutEdgeIt(bfs))) {186 if (GW::Edge(GW::OutEdgeIt(bfs))!=INVALID) { 187 187 cout << edge_name[GW::OutEdgeIt(bfs)] << /*endl*/", " << 188 node_name[gw. aNode(bfs)] <<189 (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 190 node_name[gw. bNode(bfs)] <<188 node_name[gw.tail(bfs)] << 189 (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 190 node_name[gw.head(bfs)] << 191 191 (bfs.isBNodeNewlyReached() ? ": is newly reached." : 192 192 ": is not newly reached."); … … 218 218 ++dfs; 219 219 //cout << "edge: "; 220 if ( gw.valid(GW::OutEdgeIt(dfs))) {220 if (GW::OutEdgeIt(dfs)!=INVALID) { 221 221 cout << edge_name[GW::OutEdgeIt(dfs)] << /*endl*/", " << 222 node_name[gw. aNode(dfs)] <<223 (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 224 node_name[gw. bNode(dfs)] <<222 node_name[gw.tail(dfs)] << 223 (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 224 node_name[gw.head(dfs)] << 225 225 (dfs.isBNodeNewlyReached() ? ": is newly reached." : 226 226 ": is not newly reached."); … … 236 236 } 237 237 238 // { 239 // typedef UndirGraphWrapper<const Graph> GW; 240 // GW gw(G); 241 242 // EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name); 243 244 // cout << "bfs and dfs iterator demo on the undirected graph" << endl; 245 // for(GW::NodeIt n(gw); gw.valid(n); gw.next(n)) { 246 // cout << node_name[GW::Node(n)] << ": "; 247 // cout << "out edges: "; 248 // for(GW::OutEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 249 // cout << edge_name[e] << " "; 250 // cout << "in edges: "; 251 // for(GW::InEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 252 // cout << edge_name[e] << " "; 253 // cout << endl; 254 // } 255 // // for(GW::EdgeIt e=gw.first<GW::EdgeIt>(); gw.valid(e); gw.next(e)) { 256 // // cout << edge_name.get(e) << " "; 257 // // } 258 // // cout << endl; 259 260 // cout << "bfs from t ..." << endl; 261 // BfsIterator< GW, GW::NodeMap<bool> > bfs(gw); 262 // bfs.pushAndSetReached(t); 263 // while (!bfs.finished()) { 264 // //cout << "edge: "; 265 // if (gw.valid(GW::OutEdgeIt(bfs))) { 266 // cout << edge_name[GW::OutEdgeIt(bfs)] << /*endl*/", " << 267 // node_name[gw.aNode(bfs)] << 268 // (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 269 // node_name[gw.bNode(bfs)] << 270 // (bfs.isBNodeNewlyReached() ? ": is newly reached." : 271 // ": is not newly reached."); 272 // } else { 273 // cout << "invalid" << /*endl*/", " << 274 // node_name[bfs.aNode()] << 275 // (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 276 277 // "invalid."; 278 // } 279 // cout << endl; 280 // ++bfs; 281 // } 282 283 // cout << " /--> -------------> "<< endl; 284 // cout << " / /-- v1 <-\\ /---- v3-\\ "<< endl; 285 // cout << " / | | / /-> \\ "<< endl; 286 // cout << " / | | / | ^ \\ "<< endl; 287 // cout << "s | | / | | \\-> t "<< endl; 288 // cout << " \\ | | / | | /-> "<< endl; 289 // cout << " \\ | --/ / | | / "<< endl; 290 // cout << " \\ \\-> v2 <--/ \\-- v4 -/ "<< endl; 291 // cout << " \\--> -------------> "<< endl; 292 293 // cout << "dfs from t ..." << endl; 294 // DfsIterator< GW, GW::NodeMap<bool> > dfs(gw); 295 // dfs.pushAndSetReached(t); 296 // while (!dfs.finished()) { 297 // ++dfs; 298 // //cout << "edge: "; 299 // if (gw.valid(GW::OutEdgeIt(dfs))) { 300 // cout << edge_name[GW::OutEdgeIt(dfs)] << /*endl*/", " << 301 // node_name[gw.aNode(dfs)] << 302 // (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 303 // node_name[gw.bNode(dfs)] << 304 // (dfs.isBNodeNewlyReached() ? ": is newly reached." : 305 // ": is not newly reached."); 306 // } else { 307 // cout << "invalid" << /*endl*/", " << 308 // node_name[dfs.aNode()] << 309 // (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 310 311 // "invalid."; 312 // } 313 // cout << endl; 314 // } 315 // } 316 317 318 238 319 { 239 typedef UndirGraphWrapper<const Graph> GW;320 typedef BidirGraphWrapper<const Graph> GW; 240 321 GW gw(G); 241 322 242 323 EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name); 243 324 244 cout << "bfs and dfs iterator demo on the undirected graph" << endl; 245 for(GW::NodeIt n(gw); gw.valid(n); gw.next(n)) { 325 cout << "bfs and dfs iterator demo on the bidirected graph" << endl; 326 // for(GW::EdgeIt e(gw); e!=INVALID; ++e) { 327 // cout << node_name[gw.tail(e)] << "->" << node_name[gw.head(e)] << " "; 328 // } 329 for(GW::NodeIt n(gw); n!=INVALID; ++n) { 246 330 cout << node_name[GW::Node(n)] << ": "; 247 331 cout << "out edges: "; 248 for(GW::OutEdgeIt e(gw, n); gw.valid(e); gw.next(e))332 for(GW::OutEdgeIt e(gw, n); e!=INVALID; ++e) 249 333 cout << edge_name[e] << " "; 250 334 cout << "in edges: "; 251 for(GW::InEdgeIt e(gw, n); gw.valid(e); gw.next(e))335 for(GW::InEdgeIt e(gw, n); e!=INVALID; ++e) 252 336 cout << edge_name[e] << " "; 253 337 cout << endl; … … 263 347 while (!bfs.finished()) { 264 348 //cout << "edge: "; 265 if ( gw.valid(GW::OutEdgeIt(bfs))) {349 if (GW::OutEdgeIt(bfs)!=INVALID) { 266 350 cout << edge_name[GW::OutEdgeIt(bfs)] << /*endl*/", " << 267 node_name[gw. aNode(bfs)] <<268 (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 269 node_name[gw. bNode(bfs)] <<351 node_name[gw.tail(bfs)] << 352 (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 353 node_name[gw.head(bfs)] << 270 354 (bfs.isBNodeNewlyReached() ? ": is newly reached." : 271 355 ": is not newly reached."); … … 297 381 ++dfs; 298 382 //cout << "edge: "; 299 if ( gw.valid(GW::OutEdgeIt(dfs))) {383 if (GW::OutEdgeIt(dfs)!=INVALID) { 300 384 cout << edge_name[GW::OutEdgeIt(dfs)] << /*endl*/", " << 301 node_name[gw. aNode(dfs)] <<302 (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 303 node_name[gw. bNode(dfs)] <<385 node_name[gw.tail(dfs)] << 386 (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 387 node_name[gw.head(dfs)] << 304 388 (dfs.isBNodeNewlyReached() ? ": is newly reached." : 305 389 ": is not newly reached."); … … 314 398 } 315 399 } 316 317 318 319 {320 typedef BidirGraphWrapper<const Graph> GW;321 GW gw(G);322 323 EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);324 325 cout << "bfs and dfs iterator demo on the undirected graph" << endl;326 for(GW::NodeIt n(gw); gw.valid(n); gw.next(n)) {327 cout << node_name[GW::Node(n)] << ": ";328 cout << "out edges: ";329 for(GW::OutEdgeIt e(gw, n); gw.valid(e); gw.next(e))330 cout << edge_name[e] << " ";331 cout << "in edges: ";332 for(GW::InEdgeIt e(gw, n); gw.valid(e); gw.next(e))333 cout << edge_name[e] << " ";334 cout << endl;335 }336 // for(GW::EdgeIt e=gw.first<GW::EdgeIt>(); gw.valid(e); gw.next(e)) {337 // cout << edge_name.get(e) << " ";338 // }339 // cout << endl;340 341 cout << "bfs from t ..." << endl;342 BfsIterator< GW, GW::NodeMap<bool> > bfs(gw);343 bfs.pushAndSetReached(t);344 while (!bfs.finished()) {345 //cout << "edge: ";346 if (gw.valid(GW::OutEdgeIt(bfs))) {347 cout << edge_name[GW::OutEdgeIt(bfs)] << /*endl*/", " <<348 node_name[gw.aNode(bfs)] <<349 (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<350 node_name[gw.bNode(bfs)] <<351 (bfs.isBNodeNewlyReached() ? ": is newly reached." :352 ": is not newly reached.");353 } else {354 cout << "invalid" << /*endl*/", " <<355 node_name[bfs.aNode()] <<356 (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<357 358 "invalid.";359 }360 cout << endl;361 ++bfs;362 }363 364 cout << " /--> -------------> "<< endl;365 cout << " / /-- v1 <-\\ /---- v3-\\ "<< endl;366 cout << " / | | / /-> \\ "<< endl;367 cout << " / | | / | ^ \\ "<< endl;368 cout << "s | | / | | \\-> t "<< endl;369 cout << " \\ | | / | | /-> "<< endl;370 cout << " \\ | --/ / | | / "<< endl;371 cout << " \\ \\-> v2 <--/ \\-- v4 -/ "<< endl;372 cout << " \\--> -------------> "<< endl;373 374 cout << "dfs from t ..." << endl;375 DfsIterator< GW, GW::NodeMap<bool> > dfs(gw);376 dfs.pushAndSetReached(t);377 while (!dfs.finished()) {378 ++dfs;379 //cout << "edge: ";380 if (gw.valid(GW::OutEdgeIt(dfs))) {381 cout << edge_name[GW::OutEdgeIt(dfs)] << /*endl*/", " <<382 node_name[gw.aNode(dfs)] <<383 (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<384 node_name[gw.bNode(dfs)] <<385 (dfs.isBNodeNewlyReached() ? ": is newly reached." :386 ": is not newly reached.");387 } else {388 cout << "invalid" << /*endl*/", " <<389 node_name[dfs.aNode()] <<390 (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<391 392 "invalid.";393 }394 cout << endl;395 }396 }397 398 399 400 400 401 return 0; -
src/work/sage_graph.h
r642 r774 10 10 namespace hugo { 11 11 12 template <typename It>13 int count(It it) {14 int i=0;15 for( ; it.valid(); ++it) { ++i; }16 return i;17 }12 // template <typename It> 13 // int count(It it) { 14 // int i=0; 15 // for( ; it.valid(); ++it) { ++i; } 16 // return i; 17 // } 18 18 19 19 class SageGraph { … … 386 386 public: //for everybody but marci 387 387 NodeIt(const SageGraph& G) : Node(G._first_node) { } 388 NodeIt(const SageGraph& G, const Node& n) : Node(n) { } 388 389 public: 389 390 NodeIt() : Node() { } … … 391 392 protected: 392 393 NodeIt(node_item* v) : Node(v) { } 394 public: 393 395 NodeIt& operator++() { node=node->_next_node; return *this; } 394 396 //FIXME:: … … 426 428 class EdgeIt : public Edge { 427 429 friend class SageGraph; 428 //protected: 429 public: //for alpar 430 public: 431 EdgeIt() : Edge() { } 432 EdgeIt(const Invalid& i) : Edge(i) { } 430 433 EdgeIt(const SageGraph& G) { 431 434 node_item* v=G._first_node; … … 433 436 while (v && !edge) { v=v->_next_node; if (v) edge=v->_first_out_edge; } 434 437 } 435 public: 436 EdgeIt() : Edge() { } 437 EdgeIt(const Invalid& i) : Edge(i) { } 438 protected: 439 EdgeIt(edge_item* _e) : Edge(_e) { } 438 EdgeIt(const SageGraph& G, const Edge& e) : Edge(e) { } 439 // protected: 440 // EdgeIt(edge_item* _e) : Edge(_e) { } 441 public: 440 442 EdgeIt& operator++() { 441 443 node_item* v=edge->_tail; … … 448 450 class OutEdgeIt : public Edge { 449 451 friend class SageGraph; 450 //node_item* v; 451 //protected: 452 protected: //for alpar 453 OutEdgeIt(const Node& _v) /*: v(_v.node)*/ { edge=_v.node->_first_out_edge; } 454 public: 455 OutEdgeIt() : Edge()/*, v(0)*/ { } 452 public: 453 OutEdgeIt() : Edge() { } 456 454 OutEdgeIt(const Invalid& i) : Edge(i) { } 457 OutEdgeIt(const SageGraph&, Node _v) /*: v(_v.node)*/ { edge=_v.node->_first_out_edge;}458 protected:455 OutEdgeIt(const SageGraph&, Node _v) : Edge(_v.node->_first_out_edge) { } 456 OutEdgeIt(const SageGraph&, const Edge& e) : Edge(e) { } 459 457 OutEdgeIt& operator++() { edge=edge->_next_out; return *this; } 460 458 protected: … … 465 463 class InEdgeIt : public Edge { 466 464 friend class SageGraph; 467 //node_item* v; 468 //protected: 469 protected: //for alpar 470 InEdgeIt(const Node& _v) /*: v(_v.node)*/ { edge=_v.node->_first_in_edge; } 471 public: 472 InEdgeIt() : Edge()/*, v(0)*/ { } 473 InEdgeIt(const Invalid& i) : Edge(i) { } 474 InEdgeIt(const SageGraph&, Node _v) /*: v(_v.node)*/ { edge=_v.node->_first_in_edge; } 475 protected: 465 public: 466 InEdgeIt() : Edge() { } 467 InEdgeIt(Invalid i) : Edge(i) { } 468 InEdgeIt(const SageGraph&, Node _v) : Edge(_v.node->_first_in_edge) { } 469 InEdgeIt(const SageGraph&, const Edge& e) : Edge(e) { } 476 470 InEdgeIt& operator++() { edge=edge->_next_in; return *this; } 477 471 protected:
Note: See TracChangeset
for help on using the changeset viewer.