Changeset 158:4f54d89fa9d2 in lemon0.x for src/work/marci/graph_wrapper.h
 Timestamp:
 03/08/04 13:29:07 (21 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@223
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

src/work/marci/graph_wrapper.h
r156 r158 63 63 public: 64 64 NodeMap(const TrivGraphWrapper<Graph>& _G) : 65 Graph::NodeMap<T>( *(_G.G)) { }65 Graph::NodeMap<T>(_G.getGraph()) { } 66 66 NodeMap(const TrivGraphWrapper<Graph>& _G, T a) : 67 Graph::NodeMap<T>( *(_G.G), a) { }67 Graph::NodeMap<T>(_G.getGraph(), a) { } 68 68 }; 69 69 template<typename T> class EdgeMap : public Graph::EdgeMap<T> { 70 70 public: 71 71 EdgeMap(const TrivGraphWrapper<Graph>& _G) : 72 Graph::EdgeMap<T>( *(_G.G)) { }72 Graph::EdgeMap<T>(_G.getGraph()) { } 73 73 EdgeMap(const TrivGraphWrapper<Graph>& _G, T a) : 74 Graph::EdgeMap<T>( *(_G.G), a) { }74 Graph::EdgeMap<T>(_G.getGraph(), a) { } 75 75 }; 76 76 … … 141 141 public: 142 142 NodeMap(const RevGraphWrapper<Graph>& _G) : 143 Graph::NodeMap<T>( *(_G.G)) { }143 Graph::NodeMap<T>(_G.getGraph()) { } 144 144 NodeMap(const RevGraphWrapper<Graph>& _G, T a) : 145 Graph::NodeMap<T>( *(_G.G), a) { }145 Graph::NodeMap<T>(_G.getGraph(), a) { } 146 146 }; 147 147 template<typename T> class EdgeMap : public Graph::EdgeMap<T> { 148 148 public: 149 149 EdgeMap(const RevGraphWrapper<Graph>& _G) : 150 Graph::EdgeMap<T>( *(_G.G)) { }150 Graph::EdgeMap<T>(_G.getGraph()) { } 151 151 EdgeMap(const RevGraphWrapper<Graph>& _G, T a) : 152 Graph::EdgeMap<T>( *(_G.G), a) { }152 Graph::EdgeMap<T>(_G.getGraph(), a) { } 153 153 }; 154 154 … … 159 159 RevGraphWrapper(Graph& _graph) : graph(&_graph) { } 160 160 }; 161 162 163 template<typename Graph> 164 class UndirGraphWrapper { 165 Graph* graph; 166 167 public: 168 typedef Graph BaseGraph; 169 170 typedef typename Graph::NodeIt NodeIt; 171 typedef typename Graph::EachNodeIt EachNodeIt; 172 173 //typedef typename Graph::EdgeIt EdgeIt; 174 //typedef typename Graph::OutEdgeIt OutEdgeIt; 175 //typedef typename Graph::InEdgeIt InEdgeIt; 176 //typedef typename Graph::SymEdgeIt SymEdgeIt; 177 //typedef typename Graph::EachEdgeIt EachEdgeIt; 178 179 //private: 180 typedef typename Graph::EdgeIt GraphEdgeIt; 181 typedef typename Graph::OutEdgeIt GraphOutEdgeIt; 182 typedef typename Graph::InEdgeIt GraphInEdgeIt; 183 //public: 184 185 class EdgeIt { 186 friend class UndirGraphWrapper<Graph>; 187 bool out_or_in; //true iff out 188 GraphOutEdgeIt out; 189 GraphInEdgeIt in; 190 public: 191 EdgeIt() : out_or_in(true), out(), in() { } 192 operator GraphEdgeIt() const { 193 if (out_or_in) return(out); else return(in); 194 } 195 }; 196 197 class OutEdgeIt : public EdgeIt { 198 friend class UndirGraphWrapper<Graph>; 199 //bool out_or_in; //true iff out 200 //GraphOutEdgeIt out; 201 //GraphInEdgeIt in; 202 public: 203 OutEdgeIt() : EdgeIt() { } 204 OutEdgeIt(const UndirGraphWrapper& _G, const NodeIt& n) : EdgeIt() { 205 _G.graph>getFirst(out, n); 206 if (!(_G.graph>valid(out))) { 207 out_or_in=false; 208 _G.graph>getFirst(in, n); 209 } 210 } 211 }; 212 213 OutEdgeIt& getFirst(OutEdgeIt& e, const NodeIt& n) const { 214 e.out_or_in=true; 215 graph>getFirst(e.out, n); 216 if (!(graph>valid(e.out))) { 217 e.out_or_in=false; 218 graph>getFirst(e.in, n); 219 } 220 return e; 221 } 222 223 OutEdgeIt& next(OutEdgeIt& e) const { 224 if (e.out_or_in) { 225 NodeIt n=graph>tail(e.out); 226 graph>next(e.out); 227 if (!graph>valid(e.out)) { 228 e.out_or_in=false; 229 graph>getFirst(e.in, n); 230 } 231 } else { 232 graph>next(e.in); 233 } 234 return e; 235 } 236 237 NodeIt aNode(const OutEdgeIt& e) const { 238 if (e.out_or_in) return graph>tail(e); else return graph>head(e); } 239 NodeIt bNode(const OutEdgeIt& e) const { 240 if (e.out_or_in) return graph>head(e); else return graph>tail(e); } 241 242 typedef OutEdgeIt InEdgeIt; 243 244 template<typename I> I& getFirst(I& i) const { return graph>getFirst(i); } 245 // template<typename I, typename P> I& getFirst(I& i, const P& p) const { 246 // return graph>getFirst(i, p); } 247 248 template<typename I> I getNext(const I& i) const { 249 return graph>getNext(i); } 250 template<typename I> I& next(I &i) const { return graph>next(i); } 251 252 template< typename It > It first() const { 253 It e; getFirst(e); return e; } 254 255 template< typename It > It first(const NodeIt& v) const { 256 It e; getFirst(e, v); return e; } 257 258 NodeIt head(const EdgeIt& e) const { return graph>head(e); } 259 NodeIt tail(const EdgeIt& e) const { return graph>tail(e); } 260 261 template<typename I> bool valid(const I& i) const 262 { return graph>valid(i); } 263 264 //template<typename I> void setInvalid(const I &i); 265 //{ return graph>setInvalid(i); } 266 267 int nodeNum() const { return graph>nodeNum(); } 268 int edgeNum() const { return graph>edgeNum(); } 269 270 // template<typename I> NodeIt aNode(const I& e) const { 271 // return graph>aNode(e); } 272 // template<typename I> NodeIt bNode(const I& e) const { 273 // return graph>bNode(e); } 274 275 NodeIt addNode() const { return graph>addNode(); } 276 EdgeIt addEdge(const NodeIt& tail, const NodeIt& head) const { 277 return graph>addEdge(tail, head); } 278 279 template<typename I> void erase(const I& i) const { graph>erase(i); } 280 281 void clear() const { graph>clear(); } 282 283 template<typename T> class NodeMap : public Graph::NodeMap<T> { 284 public: 285 NodeMap(const UndirGraphWrapper<Graph>& _G) : 286 Graph::NodeMap<T>(_G.getGraph()) { } 287 NodeMap(const UndirGraphWrapper<Graph>& _G, T a) : 288 Graph::NodeMap<T>(_G.getGraph(), a) { } 289 }; 290 template<typename T> class EdgeMap : public Graph::EdgeMap<T> { 291 public: 292 EdgeMap(const UndirGraphWrapper<Graph>& _G) : 293 Graph::EdgeMap<T>(_G.getGraph()) { } 294 EdgeMap(const UndirGraphWrapper<Graph>& _G, T a) : 295 Graph::EdgeMap<T>(_G.getGraph(), a) { } 296 }; 297 298 void setGraph(Graph& _graph) { graph = &_graph; } 299 Graph& getGraph() const { return (*graph); } 300 301 //TrivGraphWrapper() : graph(0) { } 302 UndirGraphWrapper(Graph& _graph) : graph(&_graph) { } 303 }; 304 161 305 162 306 … … 248 392 // ResGraphWrapper(const ResGraphWrapper& res_graph_wrapper) : 249 393 // G(res_graph_wrapper.G), flow(res_graph_wrapper.flow), capacity(res_graph_wrapper.capacity) { } 394 void setGraph(Graph& _graph) { graph = &_graph; } 395 Graph& getGraph() const { return (*graph); } 250 396 class EdgeIt; 251 397 class OutEdgeIt; … … 500 646 public: 501 647 NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) 502 : Graph::NodeMap<T>( *(_G.G)) { }648 : Graph::NodeMap<T>(_G.getGraph()) { } 503 649 NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, 504 T a) : Graph::NodeMap<T>( *(_G.G), a) { }650 T a) : Graph::NodeMap<T>(_G.getGraph(), a) { } 505 651 }; 506 652 … … 519 665 typename Graph::EdgeMap<T> forward_map, backward_map; 520 666 public: 521 EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : forward_map( *(_G.G)), backward_map(*(_G.G)) { }522 EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : forward_map( *(_G.G), a), backward_map(*(_G.G), a) { }667 EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : forward_map(_G.getGraph()), backward_map(_G.getGraph()) { } 668 EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : forward_map(_G.getGraph(), a), backward_map(_G.getGraph(), a) { } 523 669 void set(EdgeIt e, T a) { 524 670 if (e.out_or_in)
Note: See TracChangeset
for help on using the changeset viewer.