Changeset 774:4297098d9677 in lemon-0.x for src/hugo
- 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/hugo
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.