1.1 --- a/src/work/marci/graph_wrapper.h Thu Apr 22 20:36:21 2004 +0000
1.2 +++ b/src/work/marci/graph_wrapper.h Fri Apr 23 07:41:48 2004 +0000
1.3 @@ -156,10 +156,10 @@
1.4 InEdgeIt& next(InEdgeIt& i) const { graph->next(i.e); return i; }
1.5 EdgeIt& next(EdgeIt& i) const { graph->next(i.e); return i; }
1.6
1.7 + Node tail(const Edge& e) const {
1.8 + return Node(graph->tail(static_cast<typename Graph::Edge>(e))); }
1.9 Node head(const Edge& e) const {
1.10 return Node(graph->head(static_cast<typename Graph::Edge>(e))); }
1.11 - Node tail(const Edge& e) const {
1.12 - return Node(graph->tail(static_cast<typename Graph::Edge>(e))); }
1.13
1.14 bool valid(const Node& n) const {
1.15 return graph->valid(static_cast<typename Graph::Node>(n)); }
1.16 @@ -221,10 +221,10 @@
1.17 class OutEdgeIt {
1.18 friend class GraphWrapper<Graph>;
1.19 friend class RevGraphWrapper<Graph>;
1.20 - typename Graph::OutEdgeIt e;
1.21 + typename Graph::InEdgeIt e;
1.22 public:
1.23 OutEdgeIt() { }
1.24 - OutEdgeIt(const typename Graph::OutEdgeIt& _e) : e(_e) { }
1.25 + OutEdgeIt(const typename Graph::InEdgeIt& _e) : e(_e) { }
1.26 OutEdgeIt(const Invalid& i) : e(i) { }
1.27 OutEdgeIt(const RevGraphWrapper<Graph>& _G, const Node& _n) :
1.28 e(*(_G.graph), typename Graph::Node(_n)) { }
1.29 @@ -233,10 +233,10 @@
1.30 class InEdgeIt {
1.31 friend class GraphWrapper<Graph>;
1.32 friend class RevGraphWrapper<Graph>;
1.33 - typename Graph::InEdgeIt e;
1.34 + typename Graph::OutEdgeIt e;
1.35 public:
1.36 InEdgeIt() { }
1.37 - InEdgeIt(const typename Graph::InEdgeIt& _e) : e(_e) { }
1.38 + InEdgeIt(const typename Graph::OutEdgeIt& _e) : e(_e) { }
1.39 InEdgeIt(const Invalid& i) : e(i) { }
1.40 InEdgeIt(const RevGraphWrapper<Graph>& _G, const Node& _n) :
1.41 e(*(_G.graph), typename Graph::Node(_n)) { }
1.42 @@ -259,6 +259,12 @@
1.43 Node aNode(const InEdgeIt& e) const { return Node(graph->aNode(e.e)); }
1.44 Node bNode(const OutEdgeIt& e) const { return Node(graph->bNode(e.e)); }
1.45 Node bNode(const InEdgeIt& e) const { return Node(graph->bNode(e.e)); }
1.46 +
1.47 + Node tail(const Edge& e) const {
1.48 + return GraphWrapper<Graph>::head(e); }
1.49 + Node head(const Edge& e) const {
1.50 + return GraphWrapper<Graph>::tail(e); }
1.51 +
1.52 };
1.53
1.54 /// Wrapper for hiding nodes and edges from a graph.
1.55 @@ -883,6 +889,9 @@
1.56 SFalseTTrueMap* s_false_t_true_map;
1.57
1.58 public:
1.59 + static const bool S_CLASS=false;
1.60 + static const bool T_CLASS=true;
1.61 +
1.62 BipartiteGraphWrapper(Graph& _graph, SFalseTTrueMap& _s_false_t_true_map)
1.63 : GraphWrapper<Graph>(_graph), s_false_t_true_map(&_s_false_t_true_map) {
1.64 }
1.65 @@ -890,35 +899,46 @@
1.66 //using GraphWrapper<Graph>::NodeIt;
1.67 typedef typename GraphWrapper<Graph>::Edge Edge;
1.68 //using GraphWrapper<Graph>::EdgeIt;
1.69 - class SNodeIt {
1.70 + class ClassNodeIt {
1.71 Node n;
1.72 public:
1.73 - SNodeIt() { }
1.74 - SNodeIt(const Invalid& i) : n(i) { }
1.75 - SNodeIt(const BipartiteGraphWrapper<Graph>& _G) {
1.76 - _G.s_false_t_true_map->first(n, false);
1.77 + ClassNodeIt() { }
1.78 + ClassNodeIt(const Invalid& i) : n(i) { }
1.79 + ClassNodeIt(const BipartiteGraphWrapper<Graph>& _G, bool _class) {
1.80 + _G.s_false_t_true_map->first(n, _class);
1.81 }
1.82 operator Node() const { return n; }
1.83 };
1.84 - class TNodeIt {
1.85 - Node n;
1.86 - public:
1.87 - TNodeIt() { }
1.88 - TNodeIt(const Invalid& i) : n(i) { }
1.89 - TNodeIt(const BipartiteGraphWrapper<Graph>& _G) {
1.90 - _G.s_false_t_true_map->first(n, true);
1.91 - }
1.92 - operator Node() const { return n; }
1.93 - };
1.94 +// class SNodeIt {
1.95 +// Node n;
1.96 +// public:
1.97 +// SNodeIt() { }
1.98 +// SNodeIt(const Invalid& i) : n(i) { }
1.99 +// SNodeIt(const BipartiteGraphWrapper<Graph>& _G) {
1.100 +// _G.s_false_t_true_map->first(n, false);
1.101 +// }
1.102 +// operator Node() const { return n; }
1.103 +// };
1.104 +// class TNodeIt {
1.105 +// Node n;
1.106 +// public:
1.107 +// TNodeIt() { }
1.108 +// TNodeIt(const Invalid& i) : n(i) { }
1.109 +// TNodeIt(const BipartiteGraphWrapper<Graph>& _G) {
1.110 +// _G.s_false_t_true_map->first(n, true);
1.111 +// }
1.112 +// operator Node() const { return n; }
1.113 +// };
1.114 class OutEdgeIt {
1.115 public:
1.116 +
1.117 typename Graph::OutEdgeIt e;
1.118 public:
1.119 OutEdgeIt() { }
1.120 OutEdgeIt(const Invalid& i) : e(i) { }
1.121 OutEdgeIt(const BipartiteGraphWrapper<Graph>& _G, const Node& _n) {
1.122 if (!(*(_G.s_false_t_true_map))[_n])
1.123 - e=OutEdgeIt(*(_G.graph), typename Graph::Node(_n));
1.124 + e=typename Graph::OutEdgeIt(*(_G.graph), typename Graph::Node(_n));
1.125 else
1.126 e=INVALID;
1.127 }
1.128 @@ -932,7 +952,7 @@
1.129 InEdgeIt(const Invalid& i) : e(i) { }
1.130 InEdgeIt(const BipartiteGraphWrapper<Graph>& _G, const Node& _n) {
1.131 if ((*(_G.s_false_t_true_map))[_n])
1.132 - e=InEdgeIt(*(_G.graph), typename Graph::Node(_n));
1.133 + e=typename Graph::InEdgeIt(*(_G.graph), typename Graph::Node(_n));
1.134 else
1.135 e=INVALID;
1.136 }
1.137 @@ -940,16 +960,29 @@
1.138 };
1.139
1.140 using GraphWrapper<Graph>::first;
1.141 - SNodeIt& first(SNodeIt& n) const { n=SNodeIt(*this); return n; }
1.142 - TNodeIt& first(TNodeIt& n) const { n=TNodeIt(*this); return n; }
1.143 + ClassNodeIt& first(ClassNodeIt& n, bool _class) const {
1.144 + n=SNodeIt(*this, _class) ; return n; }
1.145 +// SNodeIt& first(SNodeIt& n) const { n=SNodeIt(*this); return n; }
1.146 +// TNodeIt& first(TNodeIt& n) const { n=TNodeIt(*this); return n; }
1.147 + OutEdgeIt& first(OutEdgeIt& i, const Node& p) const {
1.148 + i=OutEdgeIt(*this, p); return i;
1.149 + }
1.150 + InEdgeIt& first(InEdgeIt& i, const Node& p) const {
1.151 + i=InEdgeIt(*this, p); return i;
1.152 + }
1.153
1.154 using GraphWrapper<Graph>::next;
1.155 - SNodeIt& next(SNodeIt& n) const {
1.156 + ClassNodeIt& next(ClassNodeIt& n) const {
1.157 this->s_false_t_true_map->next(n); return n;
1.158 }
1.159 - TNodeIt& next(TNodeIt& n) const {
1.160 - this->s_false_t_true_map->next(n); return n;
1.161 - }
1.162 +// SNodeIt& next(SNodeIt& n) const {
1.163 +// this->s_false_t_true_map->next(n); return n;
1.164 +// }
1.165 +// TNodeIt& next(TNodeIt& n) const {
1.166 +// this->s_false_t_true_map->next(n); return n;
1.167 +// }
1.168 + OutEdgeIt& next(OutEdgeIt& i) const { graph->next(i.e); return i; }
1.169 + InEdgeIt& next(InEdgeIt& i) const { graph->next(i.e); return i; }
1.170
1.171 Node tail(const Edge& e) {
1.172 if (!(*(this->s_false_t_true_map))[this->graph->tail(e)])
1.173 @@ -976,186 +1009,473 @@
1.174 Node bNode(const InEdgeIt& e) const {
1.175 return Node(this->graph->bNode(e.e));
1.176 }
1.177 +
1.178 + bool inSClass(const Node& n) const {
1.179 + return !(this->s_false_t_true_map[n]);
1.180 + }
1.181 + bool inTClass(const Node& n) const {
1.182 + return (this->s_false_t_true_map[n]);
1.183 + }
1.184 };
1.185
1.186
1.187 + /// experimentral, do not try it.
1.188 + /// It eats a bipartite graph, oriented from S to T.
1.189 + /// Such one can be made e.g. by the above wrapper.
1.190 + template<typename Graph>
1.191 + class stGraphWrapper : public GraphWrapper<Graph> {
1.192 + public:
1.193 + class Node;
1.194 +//GN, int
1.195 +//0 normalis, 1 s, 2, true, ez az iteralasi sorrend,
1.196 +//es a vege a false azaz (invalid, 3)
1.197 + class NodeIt;
1.198 +//GNI, int
1.199 + class Edge;
1.200 +//GE, int, GN
1.201 +//0 normalis, 1 s->vmi, 2 vmi->t, ez a sorrend,
1.202 +//invalid: (invalid, 3, invalid)
1.203 + class OutEdgeIt;
1.204 +//GO, int, GNI
1.205 +//normalis pontbol (first, 0, invalid), ..., (invalid, 2, vmi), ... (invalid, 3, invalid)
1.206 +//s-bol (invalid, 1, first), ... (invalid, 3, invalid)
1.207 +//t-bol (invalid, 3, invalid)
1.208 + class InEdgeIt;
1.209 +//GI, int, GNI
1.210 +//normalis pontbol (first, 0, invalid), ..., (invalid, 1, vmi), ... (invalid, 3, invalid)
1.211 +//s-be (invalid, 3, invalid)
1.212 +//t-be (invalid, 2, first), ... (invalid, 3, invalid)
1.213 + class EdgeIt;
1.214 +//(first, 0, invalid) ...
1.215 +//(invalid, 1, vmi)
1.216 +//(invalid, 2, vmi)
1.217 +//invalid, 3, invalid)
1.218 + template <typename T> class NodeMap;
1.219 + template <typename T> class EdgeMap;
1.220
1.221 -// /// experimentral, do not try it.
1.222 -// template<typename Graph>
1.223 -// class stGraphWrapper : public GraphWrapper<Graph> {
1.224 -// public:
1.225 -// class Node;
1.226 -// class NodeIt;
1.227 -// class Edge;
1.228 -// class OutEdgeIt;
1.229 -// class InEdgeIt;
1.230 -// class EdgeIt;
1.231 +// template <typename T> friend class NodeMap;
1.232 +// template <typename T> friend class EdgeMap;
1.233
1.234 -// const Node s;
1.235 -// const Node t;
1.236 + const Node S_NODE;
1.237 + const Node T_NODE;
1.238
1.239 -// stGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph),
1.240 -// s(INVALID, 1), t(INVALID, 2) { }
1.241 + static const bool S_CLASS=false;
1.242 + static const bool T_CLASS=true;
1.243
1.244 -// class Node : public Graph::Node {
1.245 -// friend class GraphWrapper<Graph>;
1.246 -// friend class stGraphWrapper<Graph>;
1.247 -// protected:
1.248 -// int spec; //0 if real node, 1 iff s, 2 iff t
1.249 -// public:
1.250 -// Node() { }
1.251 -// Node(const typename Graph::Node& _n, int _spec=0) :
1.252 -// Graph::Node(_n), spec(_spec) { }
1.253 -// Node(const Invalid& i) : Graph::Node(i), spec(2) { }
1.254 -// //invalid: (invalid, 2);
1.255 -// };
1.256 + stGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) ,
1.257 + S_NODE(INVALID, 1),
1.258 + T_NODE(INVALID, 2) { }
1.259
1.260 -// class NodeIt {
1.261 -// friend class GraphWrapper<Graph>;
1.262 -// friend class stGraphWrapper<Graph>;
1.263 -// typename Graph::NodeIt n;
1.264 -// int spec;
1.265 -// public:
1.266 -// NodeIt() { }
1.267 -// NodeIt(const typename Graph::NodeIt& _n, int _spec=0) :
1.268 -// n(_n), spec(_spec) { }
1.269 -// NodeIt(const Invalid& i) : n(i), spec(2) { }
1.270 -// NodeIt(const GraphWrapper<Graph>& _G) : n(*(_G.graph)), spec(0) {
1.271 -// if (!_G->valid(n)) spec=1;
1.272 -// }
1.273 -// operator Node() const { return Node(n, spec); }
1.274 -// };
1.275 -// // typedef typename Graph::Edge Edge;
1.276 -// class Edge : public Graph::Edge {
1.277 -// friend class GraphWrapper<Graph>;
1.278 -// friend class stGraphWrapper<Graph>;
1.279 -// Node tail_spec;
1.280 -// Node head_spec;
1.281 -// public:
1.282 -// Edge() { }
1.283 -// Edge(const typename Graph::Edge& _e) :
1.284 -// Graph::Edge(_e), tail_spec(i, 0), head_spec(i, 0) {
1.285 -// //a tail-t es a head-et real node-ra csinaljuk
1.286 -// }
1.287 -// Edge(const Invalid& i) : Graph::Edge(i), tail_spec(i), head_spec(i) { }
1.288 -// };
1.289 -// class OutEdgeIt {
1.290 -// friend class GraphWrapper<Graph>;
1.291 -// friend class stGraphWrapper<Graph>;
1.292 -// typename Graph::OutEdgeIt e;
1.293 -// Node tail_spec;
1.294 -// Node head_spec;
1.295 -// public:
1.296 -// OutEdgeIt() { }
1.297 -// OutEdgeIt(const typename Graph::OutEdgeIt& _e) :
1.298 -// e(_e), tail_spec(i, 0), head_spec(i, 0) {
1.299 -// //a tail-t es a head-et real node-ra csinaljuk
1.300 -// }
1.301 -// OutEdgeIt(const Invalid& i) : e(i), tail_spec(i), head_spec(i) { }
1.302 -// //invalid: (barmi, 0, 2)
1.303 -// OutEdgeIt(const GraphWrapper<Graph>& _G, const Node& _n) {
1.304 -// switch (_n.spec) {
1.305 -// case 0 :
1.306 -// e=typename Graph::OutEdgeIt(*(_G.graph), typename Graph::Node(_n));
1.307 -// _tail.spec=0;
1.308 -// _head.spec=0;
1.309 -// if (!_G.graph->valid(e)) spec=1;
1.310 -// break;
1.311 -// case 1:
1.312 -// e=INVALID;
1.313 -// _tail.spec=1;
1.314 -// _head(_G.graph->first(typename Graph::NodeIt()));
1.315 -// if _head.spec==1
1.316 -// break;
1.317 -// };
1.318 -
1.319 -// }
1.320 -// operator Edge() const { return Edge(typename Graph::Edge(e)); }
1.321 -// };
1.322 -// class InEdgeIt {
1.323 -// friend class GraphWrapper<Graph>;
1.324 -// typename Graph::InEdgeIt e;
1.325 -// public:
1.326 -// InEdgeIt() { }
1.327 -// InEdgeIt(const typename Graph::InEdgeIt& _e) : e(_e) { }
1.328 -// InEdgeIt(const Invalid& i) : e(i) { }
1.329 -// InEdgeIt(const GraphWrapper<Graph>& _G, const Node& _n) :
1.330 -// e(*(_G.graph), typename Graph::Node(_n)) { }
1.331 -// operator Edge() const { return Edge(typename Graph::Edge(e)); }
1.332 -// };
1.333 -// //typedef typename Graph::SymEdgeIt SymEdgeIt;
1.334 -// class EdgeIt {
1.335 -// friend class GraphWrapper<Graph>;
1.336 -// typename Graph::EdgeIt e;
1.337 -// public:
1.338 -// EdgeIt() { }
1.339 -// EdgeIt(const typename Graph::EdgeIt& _e) : e(_e) { }
1.340 -// EdgeIt(const Invalid& i) : e(i) { }
1.341 -// EdgeIt(const GraphWrapper<Graph>& _G) : e(*(_G.graph)) { }
1.342 -// operator Edge() const { return Edge(typename Graph::Edge(e)); }
1.343 -// };
1.344 + class Node : public Graph::Node {
1.345 + protected:
1.346 + friend class GraphWrapper<Graph>;
1.347 + friend class stGraphWrapper<Graph>;
1.348 + template <typename T> friend class stGraphWrapper<Graph>::NodeMap;
1.349 + int spec;
1.350 + public:
1.351 + Node() { }
1.352 + Node(const typename Graph::Node& _n, int _spec=0) :
1.353 + Graph::Node(_n), spec(_spec) { }
1.354 + Node(const Invalid& i) : Graph::Node(i), spec(3) { }
1.355 + friend bool operator==(const Node& u, const Node& v) {
1.356 + return (u.spec==v.spec &&
1.357 + static_cast<typename Graph::Node>(u)==
1.358 + static_cast<typename Graph::Node>(v));
1.359 + }
1.360 + friend bool operator!=(const Node& u, const Node& v) {
1.361 + return (v.spec!=u.spec ||
1.362 + static_cast<typename Graph::Node>(u)!=
1.363 + static_cast<typename Graph::Node>(v));
1.364 + }
1.365 + int getSpec() const { return spec; }
1.366 + };
1.367 + class NodeIt {
1.368 + friend class GraphWrapper<Graph>;
1.369 + friend class stGraphWrapper<Graph>;
1.370 + typename Graph::NodeIt n;
1.371 + int spec;
1.372 + public:
1.373 + NodeIt() { }
1.374 + NodeIt(const typename Graph::NodeIt& _n, int _spec) :
1.375 + n(_n), spec(_spec) { }
1.376 + NodeIt(const Invalid& i) : n(i), spec(3) { }
1.377 + NodeIt(const GraphWrapper<Graph>& _G) : n(*(_G.graph)), spec(0) {
1.378 + if (!_G->valid(n)) spec=1;
1.379 + }
1.380 + operator Node() const { return Node(n, spec); }
1.381 + };
1.382 + class Edge : public Graph::Edge {
1.383 + friend class GraphWrapper<Graph>;
1.384 + friend class stGraphWrapper<Graph>;
1.385 + template <typename T> friend class stGraphWrapper<Graph>::EdgeMap;
1.386 + int spec;
1.387 + typename Graph::Node n;
1.388 + public:
1.389 + Edge() { }
1.390 + Edge(const typename Graph::Edge& _e, int _spec,
1.391 + const typename Graph::Node& _n) :
1.392 + Graph::Edge(_e), spec(_spec), n(_n) {
1.393 + }
1.394 + Edge(const Invalid& i) : Graph::Edge(i), spec(3), n(i) { }
1.395 + friend bool operator==(const Edge& u, const Edge& v) {
1.396 + return (u.spec==v.spec &&
1.397 + static_cast<typename Graph::Edge>(u)==
1.398 + static_cast<typename Graph::Edge>(v) &&
1.399 + u.n==v.n);
1.400 + }
1.401 + friend bool operator!=(const Edge& u, const Edge& v) {
1.402 + return (v.spec!=u.spec ||
1.403 + static_cast<typename Graph::Edge>(u)!=
1.404 + static_cast<typename Graph::Edge>(v) ||
1.405 + u.n!=v.n);
1.406 + }
1.407 + int getSpec() const { return spec; }
1.408 + };
1.409 + class OutEdgeIt {
1.410 + friend class GraphWrapper<Graph>;
1.411 + friend class stGraphWrapper<Graph>;
1.412 + typename Graph::OutEdgeIt e;
1.413 + int spec;
1.414 + typename Graph::ClassNodeIt n;
1.415 + public:
1.416 + OutEdgeIt() { }
1.417 + OutEdgeIt(const typename Graph::OutEdgeIt& _e, int _spec,
1.418 + const typename Graph::ClassNodeIt& _n) :
1.419 + e(_e), spec(_spec), n(_n) {
1.420 + }
1.421 + OutEdgeIt(const Invalid& i) : e(i), spec(3), n(i) { }
1.422 + OutEdgeIt(const GraphWrapper<Graph>& _G, const Node& _n) {
1.423 + switch (_n.spec) {
1.424 + case 0 :
1.425 + if (_G.graph->inSClass) { //S, van normalis kiel
1.426 + e=typename Graph::OutEdgeIt(*(_G.graph),
1.427 + typename Graph::Node(_n));
1.428 + spec=0;
1.429 + n=INVALID;
1.430 + if (!_G.graph->valid(e)) spec=3;
1.431 + } else { //T, specko kiel van
1.432 + e=INVALID;
1.433 + spec=2;
1.434 + n=_n;
1.435 + }
1.436 + break;
1.437 + case 1:
1.438 + e=INVALID;
1.439 + spec=1;
1.440 + _G.graph->first(n, S_CLASS); //s->vmi;
1.441 + if (!_G.graph->valid(n)) spec=3; //Ha S ures
1.442 + break;
1.443 + case 2:
1.444 + e=INVALID;
1.445 + spec=3;
1.446 + n=INVALID;
1.447 + break;
1.448 + }
1.449 + }
1.450 + operator Edge() const { return Edge(e, spec, n); }
1.451 + };
1.452 + class InEdgeIt {
1.453 + friend class GraphWrapper<Graph>;
1.454 + friend class stGraphWrapper<Graph>;
1.455 + typename Graph::InEdgeIt e;
1.456 + int spec;
1.457 + typename Graph::ClassNodeIt n;
1.458 + public:
1.459 + InEdgeIt() { }
1.460 + InEdgeIt(const typename Graph::InEdgeIt& _e, int _spec,
1.461 + const typename Graph::ClassNodeIt& _n) :
1.462 + e(_e), spec(_spec), n(_n) {
1.463 + }
1.464 + InEdgeIt(const Invalid& i) : e(i), spec(3), n(i) { }
1.465 + InEdgeIt(const GraphWrapper<Graph>& _G, const Node& _n) {
1.466 + switch (_n.spec) {
1.467 + case 0 :
1.468 + if (_G.graph->inTClass) { //T, van normalis beel
1.469 + e=typename Graph::InEdgeIt(*(_G.graph),
1.470 + typename Graph::Node(_n));
1.471 + spec=0;
1.472 + n=INVALID;
1.473 + if (!_G.graph->valid(e)) spec=3;
1.474 + } else { //S, specko beel van
1.475 + e=INVALID;
1.476 + spec=1;
1.477 + n=_n;
1.478 + }
1.479 + break;
1.480 + case 1:
1.481 + e=INVALID;
1.482 + spec=3;
1.483 + n=INVALID;
1.484 + case 2:
1.485 + e=INVALID;
1.486 + spec=1;
1.487 + _G.graph->first(n, T_CLASS); //vmi->t;
1.488 + if (!_G.graph->valid(n)) spec=3; //Ha T ures
1.489 + break;
1.490 + }
1.491 + }
1.492 + operator Edge() const { return Edge(e, spec, n); }
1.493 + };
1.494 + class EdgeIt {
1.495 + friend class GraphWrapper<Graph>;
1.496 + friend class stGraphWrapper<Graph>;
1.497 + typename Graph::EdgeIt e;
1.498 + int spec;
1.499 + typename Graph::ClassNodeIt n;
1.500 + public:
1.501 + EdgeIt() { }
1.502 + EdgeIt(const typename Graph::EdgeIt& _e, int _spec,
1.503 + const typename Graph::ClassNodeIt& _n) :
1.504 + e(_e), spec(_spec), n(_n) { }
1.505 + EdgeIt(const Invalid& i) : e(i), spec(3), n(i) { }
1.506 + EdgeIt(const GraphWrapper<Graph>& _G) :
1.507 + e(*(_G.graph)), spec(0), n(INVALID) {
1.508 + if (!_G.graph->valid(e)) {
1.509 + spec=1;
1.510 + _G.graph->first(n, S_CLASS);
1.511 + if (!_G.graph->valid(n)) { //Ha S ures
1.512 + spec=2;
1.513 + _G.graph->first(n, T_CLASS);
1.514 + if (!_G.graph->valid(n)) { //Ha T ures
1.515 + spec=3;
1.516 + }
1.517 + }
1.518 + }
1.519 + }
1.520 + operator Edge() const { return Edge(e, spec, n); }
1.521 + };
1.522
1.523 -// NodeIt& first(NodeIt& i) const {
1.524 -// i=NodeIt(*this); return i;
1.525 -// }
1.526 -// OutEdgeIt& first(OutEdgeIt& i, const Node& p) const {
1.527 -// i=OutEdgeIt(*this, p); return i;
1.528 -// }
1.529 -// InEdgeIt& first(InEdgeIt& i, const Node& p) const {
1.530 -// i=InEdgeIt(*this, p); return i;
1.531 -// }
1.532 -// EdgeIt& first(EdgeIt& i) const {
1.533 -// i=EdgeIt(*this); return i;
1.534 -// }
1.535 + NodeIt& first(NodeIt& i) const {
1.536 + i=NodeIt(*this); return i;
1.537 + }
1.538 + OutEdgeIt& first(OutEdgeIt& i, const Node& p) const {
1.539 + i=OutEdgeIt(*this, p); return i;
1.540 + }
1.541 + InEdgeIt& first(InEdgeIt& i, const Node& p) const {
1.542 + i=InEdgeIt(*this, p); return i;
1.543 + }
1.544 + EdgeIt& first(EdgeIt& i) const {
1.545 + i=EdgeIt(*this); return i;
1.546 + }
1.547
1.548 -// NodeIt& next(NodeIt& i) const { graph->next(i.n); return i; }
1.549 -// OutEdgeIt& next(OutEdgeIt& i) const { graph->next(i.e); return i; }
1.550 -// InEdgeIt& next(InEdgeIt& i) const { graph->next(i.e); return i; }
1.551 -// EdgeIt& next(EdgeIt& i) const { graph->next(i.e); return i; }
1.552 + NodeIt& next(NodeIt& i) const {
1.553 + switch (i.spec) {
1.554 + case 0:
1.555 + graph->next(i.n);
1.556 + if (!graph->valid(i.n)) {
1.557 + i.spec=1;
1.558 + }
1.559 + break;
1.560 + case 1:
1.561 + i.spec=2;
1.562 + break;
1.563 + case 2:
1.564 + i.spec=3;
1.565 + break;
1.566 + }
1.567 + return i;
1.568 + }
1.569 + OutEdgeIt& next(OutEdgeIt& i) const {
1.570 + switch (i.spec) {
1.571 + case 0: //normal edge
1.572 + typename Graph::Node v=graph->aNode(i.e);
1.573 + graph->next(i.e);
1.574 + if (!graph->valid(i.e)) { //Az igazi elek vegere ertunk
1.575 + if (graph->inSClass(v)) { //S, nincs kiel
1.576 + i.spec=3;
1.577 + i.n=INVALID;
1.578 + } else { //T, van kiel
1.579 + i.spec=2;
1.580 + i.n=v;
1.581 + }
1.582 + }
1.583 + break;
1.584 + case 1: //s->vmi
1.585 + graph->next(i.n);
1.586 + if (!graph->valid(i.n)) i.spec=3;
1.587 + break;
1.588 + case 2: //vmi->t
1.589 + i.spec=3;
1.590 + i.n=INVALID;
1.591 + break;
1.592 + }
1.593 + return i;
1.594 + }
1.595 + InEdgeIt& next(InEdgeIt& i) const {
1.596 + switch (i.spec) {
1.597 + case 0: //normal edge
1.598 + typename Graph::Node v=graph->aNode(i.e);
1.599 + graph->next(i.e);
1.600 + if (!graph->valid(i.e)) { //Az igazi elek vegere ertunk
1.601 + if (graph->inTClass(v)) { //S, nincs beel
1.602 + i.spec=3;
1.603 + i.n=INVALID;
1.604 + } else { //S, van beel
1.605 + i.spec=1;
1.606 + i.n=v;
1.607 + }
1.608 + }
1.609 + break;
1.610 + case 1: //s->vmi
1.611 + i.spec=3;
1.612 + i.n=INVALID;
1.613 + break;
1.614 + case 2: //vmi->t
1.615 + graph->next(i.n);
1.616 + if (!graph->valid(i.n)) i.spec=3;
1.617 + break;
1.618 + }
1.619 + return i;
1.620 + }
1.621
1.622 -// Node head(const Edge& e) const {
1.623 -// return Node(graph->head(static_cast<typename Graph::Edge>(e))); }
1.624 -// Node tail(const Edge& e) const {
1.625 -// return Node(graph->tail(static_cast<typename Graph::Edge>(e))); }
1.626 + EdgeIt& next(EdgeIt& i) const {
1.627 + switch (i.spec) {
1.628 + case 0:
1.629 + graph->next(i.e);
1.630 + if (!graph->valid(i.e)) {
1.631 + i.spec=1;
1.632 + graph->first(n, S_CLASS);
1.633 + if (!graph->valid(i.n)) {
1.634 + i.spec=2;
1.635 + graph->first(n, T_CLASS);
1.636 + if (!graph->valid(i.n)) spec=3;
1.637 + }
1.638 + }
1.639 + break;
1.640 + case 1:
1.641 + graph->next(i.n);
1.642 + if (!graph->valid(i.n)) {
1.643 + i.spec=2;
1.644 + graph->first(n, T_CLASS);
1.645 + if (!graph->valid(i.n)) spec=3;
1.646 + }
1.647 + break;
1.648 + case 2:
1.649 + graph->next(i.n);
1.650 + if (!graph->valid(i.n)) i.spec=3;
1.651 + break;
1.652 + }
1.653 + return i;
1.654 + }
1.655
1.656 -// bool valid(const Node& n) const {
1.657 -// return graph->valid(static_cast<typename Graph::Node>(n)); }
1.658 -// bool valid(const Edge& e) const {
1.659 -// return graph->valid(static_cast<typename Graph::Edge>(e)); }
1.660 + Node tail(const Edge& e) const {
1.661 + switch (e.spec) {
1.662 + case 0:
1.663 + return Node(graph->tail(e));
1.664 + break;
1.665 + case 1:
1.666 + return S_NODE;
1.667 + break;
1.668 + case 2:
1.669 + return Node(e.n);
1.670 + break;
1.671 + }
1.672 + }
1.673 + Node head(const Edge& e) const {
1.674 + switch (e.spec) {
1.675 + case 0:
1.676 + return Node(graph->head(e));
1.677 + break;
1.678 + case 1:
1.679 + return Node(e.n);
1.680 + break;
1.681 + case 2:
1.682 + return T_NODE;
1.683 + break;
1.684 + }
1.685 + }
1.686
1.687 -// int nodeNum() const { return graph->nodeNum(); }
1.688 -// int edgeNum() const { return graph->edgeNum(); }
1.689 + bool valid(const Node& n) const { return (n.spec<3); }
1.690 + bool valid(const Edge& e) const { return (e.spec<3); }
1.691 +
1.692 +// int nodeNum() const { return graph->nodeNum(); }
1.693 +// int edgeNum() const { return graph->edgeNum(); }
1.694
1.695 -// Node aNode(const OutEdgeIt& e) const { return Node(graph->aNode(e.e)); }
1.696 -// Node aNode(const InEdgeIt& e) const { return Node(graph->aNode(e.e)); }
1.697 -// Node bNode(const OutEdgeIt& e) const { return Node(graph->bNode(e.e)); }
1.698 -// Node bNode(const InEdgeIt& e) const { return Node(graph->bNode(e.e)); }
1.699 + Node aNode(const OutEdgeIt& e) const { return tail(e); }
1.700 + Node aNode(const InEdgeIt& e) const { return head(e); }
1.701 + Node bNode(const OutEdgeIt& e) const { return head(e); }
1.702 + Node bNode(const InEdgeIt& e) const { return tail(e); }
1.703
1.704 -// Node addNode() const { return Node(graph->addNode()); }
1.705 -// Edge addEdge(const Node& tail, const Node& head) const {
1.706 -// return Edge(graph->addEdge(tail, head)); }
1.707 +// Node addNode() const { return Node(graph->addNode()); }
1.708 +// Edge addEdge(const Node& tail, const Node& head) const {
1.709 +// return Edge(graph->addEdge(tail, head)); }
1.710
1.711 -// void erase(const Node& i) const { graph->erase(i); }
1.712 -// void erase(const Edge& i) const { graph->erase(i); }
1.713 +// void erase(const Node& i) const { graph->erase(i); }
1.714 +// void erase(const Edge& i) const { graph->erase(i); }
1.715
1.716 -// void clear() const { graph->clear(); }
1.717 +// void clear() const { graph->clear(); }
1.718
1.719 -// template<typename T> class NodeMap : public Graph::NodeMap<T> {
1.720 -// public:
1.721 -// NodeMap(const GraphWrapper<Graph>& _G) :
1.722 -// Graph::NodeMap<T>(*(_G.graph)) { }
1.723 -// NodeMap(const GraphWrapper<Graph>& _G, T a) :
1.724 -// Graph::NodeMap<T>(*(_G.graph), a) { }
1.725 -// };
1.726 + template<typename T> class NodeMap : public GraphWrapper<Graph>::NodeMap<T> {
1.727 + T s_value, t_value;
1.728 + public:
1.729 + NodeMap(const stGraphWrapper<Graph>& _G) :
1.730 + GraphWrapper<Graph>::NodeMap<T>(_G) { }
1.731 + NodeMap(const stGraphWrapper<Graph>& _G, T a) :
1.732 + GraphWrapper<Graph>::NodeMap<T>(_G, a), s_value(a), t_value(a) { }
1.733 + T operator[](const Node& n) const {
1.734 + switch (n.spec) {
1.735 + case 0:
1.736 + return (*this)[n];
1.737 + break;
1.738 + case 1:
1.739 + return s_value;
1.740 + break;
1.741 + case 2:
1.742 + return t_value;
1.743 + break;
1.744 + }
1.745 + }
1.746 + void set(const Node& n, T t) {
1.747 + switch (n.spec) {
1.748 + case 0:
1.749 + GraphWrapper<Graph>::NodeMap<T>::set(n, t);
1.750 + break;
1.751 + case 1:
1.752 + s_value=t;
1.753 + break;
1.754 + case 2:
1.755 + t_value=t;
1.756 + break;
1.757 + }
1.758 + }
1.759 + };
1.760
1.761 -// template<typename T> class EdgeMap : public Graph::EdgeMap<T> {
1.762 -// public:
1.763 -// EdgeMap(const GraphWrapper<Graph>& _G) :
1.764 -// Graph::EdgeMap<T>(*(_G.graph)) { }
1.765 -// EdgeMap(const GraphWrapper<Graph>& _G, T a) :
1.766 -// Graph::EdgeMap<T>(*(_G.graph), a) { }
1.767 -// };
1.768 -// };
1.769 + template<typename T> class EdgeMap : public GraphWrapper<Graph>::EdgeMap<T> {
1.770 + typename GraphWrapper<Graph>::NodeMap<T> node_value;
1.771 + public:
1.772 + EdgeMap(const stGraphWrapper<Graph>& _G) :
1.773 + GraphWrapper<Graph>::EdgeMap<T>(_G), node_value(_G) { }
1.774 + EdgeMap(const stGraphWrapper<Graph>& _G, T a) :
1.775 + GraphWrapper<Graph>::EdgeMap<T>(_G, a), node_value(_G, a) { }
1.776 + T operator[](const Edge& e) const {
1.777 + switch (e.spec) {
1.778 + case 0:
1.779 + return (*this)[e];
1.780 + break;
1.781 + case 1:
1.782 + return node_value[e.n];
1.783 + break;
1.784 + case 2:
1.785 + return node_value[e.n];
1.786 + break;
1.787 + }
1.788 + }
1.789 + void set(const Edge& e, T t) {
1.790 + switch (e.spec) {
1.791 + case 0:
1.792 + GraphWrapper<Graph>::set(e, t);
1.793 + break;
1.794 + case 1:
1.795 + node_value.set(e, t);
1.796 + break;
1.797 + case 2:
1.798 + node_value.set(e, t);
1.799 + break;
1.800 + }
1.801 + }
1.802 + };
1.803 + };
1.804 +
1.805
1.806 } //namespace hugo
1.807