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