Three new methods in UnionFindEnum.
UnionFindEnum completed.
     2 #ifndef HUGO_GRAPH_WRAPPER_H
 
     3 #define HUGO_GRAPH_WRAPPER_H
 
     7 ///\brief Several graph wrappers.
 
     9 ///This file contains several useful graph wrapper functions.
 
    11 ///\author Marton Makai
 
    20   /// \addtogroup gwrappers
 
    21   /// A main parts of HUGOlib are the different graph structures, 
 
    22   /// generic graph algorithms, graph concepts which couple these, and 
 
    23   /// graph wrappers. While the previous ones are more or less clear, the 
 
    24   /// latter notion needs further explanation.
 
    25   /// Graph wrappers are graph classes which serve for considering graph 
 
    26   /// structures in different ways. A short example makes the notion much 
 
    28   /// Suppose that we have an instance \c g of a directed graph
 
    29   /// type say \c ListGraph and an algorithm 
 
    30   /// \code template<typename Graph> int algorithm(const Graph&); \endcode 
 
    31   /// is needed to run on the reversely oriented graph. 
 
    32   /// It may be expensive (in time or in memory usage) to copy 
 
    33   /// \c g with the reverse orientation. 
 
    34   /// Thus, a wrapper class
 
    35   /// \code template<typename Graph> class RevGraphWrapper; \endcode is used. 
 
    36   /// The code looks as follows
 
    39   /// RevGraphWrapper<ListGraph> rgw(g);
 
    40   /// int result=algorithm(rgw);
 
    42   /// After running the algorithm, the original graph \c g 
 
    43   /// remains untouched. Thus the graph wrapper used above is to consider the 
 
    44   /// original graph with reverse orientation. 
 
    45   /// This techniques gives rise to an elegant code, and 
 
    46   /// based on stable graph wrappers, complex algorithms can be 
 
    47   /// implemented easily. 
 
    48   /// In flow, circulation and bipartite matching problems, the residual 
 
    49   /// graph is of particular importance. Combining a wrapper implementing 
 
    50   /// this, shortest path algorithms and minimum mean cycle algorithms, 
 
    51   /// a range of weighted and cardinality optimization algorithms can be 
 
    52   /// obtained. For lack of space, for other examples, 
 
    53   /// the interested user is referred to the detailed documentation of graph 
 
    55   /// The behavior of graph wrappers can be very different. Some of them keep 
 
    56   /// capabilities of the original graph while in other cases this would be 
 
    57   /// meaningless. This means that the concepts that they are a model of depend 
 
    58   /// on the graph wrapper, and the wrapped graph(s). 
 
    59   /// If an edge of \c rgw is deleted, this is carried out by 
 
    60   /// deleting the corresponding edge of \c g. But for a residual 
 
    61   /// graph, this operation has no sense. 
 
    62   /// Let we stand one more example here to simplify your work. 
 
    64   /// \code template<typename Graph> class RevGraphWrapper; \endcode 
 
    66   /// <tt> RevGraphWrapper(Graph& _g)</tt>. 
 
    67   /// This means that in a situation, 
 
    68   /// when a <tt> const ListGraph& </tt> reference to a graph is given, 
 
    69   /// then it have to be instantiated with <tt>Graph=const ListGraph</tt>.
 
    71   /// int algorithm1(const ListGraph& g) {
 
    72   ///   RevGraphWrapper<const ListGraph> rgw(g);
 
    73   ///   return algorithm2(rgw);
 
    77   /// \addtogroup gwrappers
 
    80   ///Base type for the Graph Wrappers
 
    82   ///This is the base type for the Graph Wrappers.
 
    83   ///\todo Some more docs... 
 
    85   ///\author Marton Makai
 
    87   template<typename Graph>
 
    93     typedef Graph BaseGraph;
 
    94     typedef Graph ParentGraph;
 
    96 //     GraphWrapper() : graph(0) { }
 
    97     GraphWrapper(Graph& _graph) : graph(&_graph) { }
 
    98 //     void setGraph(Graph& _graph) { graph=&_graph; }
 
    99 //     Graph& getGraph() const { return *graph; }
 
   101 //    typedef typename Graph::Node Node;
 
   102     class Node : public Graph::Node {
 
   103       friend class GraphWrapper<Graph>;
 
   106       Node(const typename Graph::Node& _n) : Graph::Node(_n) { }
 
   107       Node(const Invalid& i) : Graph::Node(i) { }
 
   110       friend class GraphWrapper<Graph>;
 
   111       typename Graph::NodeIt n;
 
   114       NodeIt(const typename Graph::NodeIt& _n) : n(_n) { }
 
   115       NodeIt(const Invalid& i) : n(i) { }
 
   116       NodeIt(const GraphWrapper<Graph>& _G) : n(*(_G.graph)) { }
 
   117       operator Node() const { return Node(typename Graph::Node(n)); }
 
   119 //    typedef typename Graph::Edge Edge;
 
   120     class Edge : public Graph::Edge {
 
   121       friend class GraphWrapper<Graph>;
 
   124       Edge(const typename Graph::Edge& _e) : Graph::Edge(_e) { }
 
   125       Edge(const Invalid& i) : Graph::Edge(i) { }
 
   128       friend class GraphWrapper<Graph>;
 
   129       typename Graph::OutEdgeIt e;
 
   132       OutEdgeIt(const typename Graph::OutEdgeIt& _e) : e(_e) { }
 
   133       OutEdgeIt(const Invalid& i) : e(i) { }
 
   134       OutEdgeIt(const GraphWrapper<Graph>& _G, const Node& _n) : 
 
   135 	e(*(_G.graph), typename Graph::Node(_n)) { }
 
   136       operator Edge() const { return Edge(typename Graph::Edge(e)); }
 
   139       friend class GraphWrapper<Graph>;
 
   140       typename Graph::InEdgeIt e;
 
   143       InEdgeIt(const typename Graph::InEdgeIt& _e) : e(_e) { }
 
   144       InEdgeIt(const Invalid& i) : e(i) { }
 
   145       InEdgeIt(const GraphWrapper<Graph>& _G, const Node& _n) : 
 
   146 	e(*(_G.graph), typename Graph::Node(_n)) { }
 
   147       operator Edge() const { return Edge(typename Graph::Edge(e)); }
 
   149     //typedef typename Graph::SymEdgeIt SymEdgeIt;
 
   151       friend class GraphWrapper<Graph>;
 
   152       typename Graph::EdgeIt e;
 
   155       EdgeIt(const typename Graph::EdgeIt& _e) : e(_e) { }
 
   156       EdgeIt(const Invalid& i) : e(i) { }
 
   157       EdgeIt(const GraphWrapper<Graph>& _G) : e(*(_G.graph)) { }
 
   158       operator Edge() const { return Edge(typename Graph::Edge(e)); }
 
   161     NodeIt& first(NodeIt& i) const { 
 
   162       i=NodeIt(*this); return i;
 
   164     OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
 
   165       i=OutEdgeIt(*this, p); return i;
 
   167     InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
 
   168       i=InEdgeIt(*this, p); return i;
 
   170     EdgeIt& first(EdgeIt& i) const { 
 
   171       i=EdgeIt(*this); return i;
 
   174     NodeIt& next(NodeIt& i) const { graph->next(i.n); return i; }
 
   175     OutEdgeIt& next(OutEdgeIt& i) const { graph->next(i.e); return i; }
 
   176     InEdgeIt& next(InEdgeIt& i) const { graph->next(i.e); return i; }
 
   177     EdgeIt& next(EdgeIt& i) const { graph->next(i.e); return i; }    
 
   179     Node tail(const Edge& e) const { 
 
   180       return Node(graph->tail(static_cast<typename Graph::Edge>(e))); }
 
   181     Node head(const Edge& e) const { 
 
   182       return Node(graph->head(static_cast<typename Graph::Edge>(e))); }
 
   184     bool valid(const Node& n) const { 
 
   185       return graph->valid(static_cast<typename Graph::Node>(n)); }
 
   186     bool valid(const Edge& e) const { 
 
   187       return graph->valid(static_cast<typename Graph::Edge>(e)); }
 
   189     int nodeNum() const { return graph->nodeNum(); }
 
   190     int edgeNum() const { return graph->edgeNum(); }
 
   192     Node aNode(const OutEdgeIt& e) const { return Node(graph->aNode(e.e)); }
 
   193     Node aNode(const InEdgeIt& e) const { return Node(graph->aNode(e.e)); }
 
   194     Node bNode(const OutEdgeIt& e) const { return Node(graph->bNode(e.e)); }
 
   195     Node bNode(const InEdgeIt& e) const { return Node(graph->bNode(e.e)); }
 
   197     Node addNode() const { return Node(graph->addNode()); }
 
   198     Edge addEdge(const Node& tail, const Node& head) const { 
 
   199       return Edge(graph->addEdge(tail, head)); }
 
   201     void erase(const Node& i) const { graph->erase(i); }
 
   202     void erase(const Edge& i) const { graph->erase(i); }
 
   204     void clear() const { graph->clear(); }
 
   206     template<typename T> class NodeMap : public Graph::template NodeMap<T> { 
 
   207       typedef typename Graph::template NodeMap<T> Parent;
 
   209       NodeMap(const GraphWrapper<Graph>& _G) :  Parent(*(_G.graph)) { }
 
   210       NodeMap(const GraphWrapper<Graph>& _G, T a) : Parent(*(_G.graph), a) { }
 
   213     template<typename T> class EdgeMap : public Graph::template EdgeMap<T> { 
 
   214       typedef typename Graph::template EdgeMap<T> Parent;
 
   216       EdgeMap(const GraphWrapper<Graph>& _G) : Parent(*(_G.graph)) { }
 
   217       EdgeMap(const GraphWrapper<Graph>& _G, T a) : Parent(*(_G.graph), a) { }
 
   221   /// A graph wrapper which reverses the orientation of the edges.
 
   223   /// A graph wrapper which reverses the orientation of the edges.
 
   225   ///\author Marton Makai
 
   226   template<typename Graph>
 
   227   class RevGraphWrapper : public GraphWrapper<Graph> {
 
   230     RevGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { }  
 
   232     typedef typename GraphWrapper<Graph>::Node Node;
 
   233     typedef typename GraphWrapper<Graph>::Edge Edge;
 
   234     //If Graph::OutEdgeIt is not defined
 
   235     //and we do not want to use RevGraphWrapper::InEdgeIt,
 
   236     //the typdef techinque does not work.
 
   237     //Unfortunately all the typedefs are instantiated in templates.
 
   238     //typedef typename GraphWrapper<Graph>::OutEdgeIt InEdgeIt;
 
   239     //typedef typename GraphWrapper<Graph>::InEdgeIt OutEdgeIt;
 
   242       friend class GraphWrapper<Graph>;
 
   243       friend class RevGraphWrapper<Graph>;
 
   244       typename Graph::InEdgeIt e;
 
   247       OutEdgeIt(const typename Graph::InEdgeIt& _e) : e(_e) { }
 
   248       OutEdgeIt(const Invalid& i) : e(i) { }
 
   249       OutEdgeIt(const RevGraphWrapper<Graph>& _G, const Node& _n) : 
 
   250 	e(*(_G.graph), typename Graph::Node(_n)) { }
 
   251       operator Edge() const { return Edge(typename Graph::Edge(e)); }
 
   254       friend class GraphWrapper<Graph>;
 
   255       friend class RevGraphWrapper<Graph>;
 
   256       typename Graph::OutEdgeIt e;
 
   259       InEdgeIt(const typename Graph::OutEdgeIt& _e) : e(_e) { }
 
   260       InEdgeIt(const Invalid& i) : e(i) { }
 
   261       InEdgeIt(const RevGraphWrapper<Graph>& _G, const Node& _n) : 
 
   262 	e(*(_G.graph), typename Graph::Node(_n)) { }
 
   263       operator Edge() const { return Edge(typename Graph::Edge(e)); }
 
   266     using GraphWrapper<Graph>::first;
 
   267     OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
 
   268       i=OutEdgeIt(*this, p); return i;
 
   270     InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
 
   271       i=InEdgeIt(*this, p); return i;
 
   274     using GraphWrapper<Graph>::next;
 
   275     OutEdgeIt& next(OutEdgeIt& i) const { this->graph->next(i.e); return i; }
 
   276     InEdgeIt& next(InEdgeIt& i) const { this->graph->next(i.e); return i; }
 
   278     Node aNode(const OutEdgeIt& e) const { 
 
   279       return Node(this->graph->aNode(e.e)); }
 
   280     Node aNode(const InEdgeIt& e) const { 
 
   281       return Node(this->graph->aNode(e.e)); }
 
   282     Node bNode(const OutEdgeIt& e) const { 
 
   283       return Node(this->graph->bNode(e.e)); }
 
   284     Node bNode(const InEdgeIt& e) const { 
 
   285       return Node(this->graph->bNode(e.e)); }
 
   287     Node tail(const Edge& e) const { 
 
   288       return GraphWrapper<Graph>::head(e); }
 
   289     Node head(const Edge& e) const { 
 
   290       return GraphWrapper<Graph>::tail(e); }
 
   294   /// Wrapper for hiding nodes and edges from a graph.
 
   296   /// This wrapper shows a graph with filtered node-set and 
 
   297   /// edge-set. The quick brown fox iterator jumps over 
 
   298   /// the lazy dog nodes or edges if the values for them are false 
 
   299   /// in the bool maps. 
 
   301   ///\author Marton Makai
 
   302   template<typename Graph, typename NodeFilterMap, 
 
   303 	   typename EdgeFilterMap>
 
   304   class SubGraphWrapper : public GraphWrapper<Graph> {
 
   306     NodeFilterMap* node_filter_map;
 
   307     EdgeFilterMap* edge_filter_map;
 
   310     SubGraphWrapper(Graph& _graph, NodeFilterMap& _node_filter_map, 
 
   311 		    EdgeFilterMap& _edge_filter_map) : 
 
   312       GraphWrapper<Graph>(_graph), node_filter_map(&_node_filter_map), 
 
   313       edge_filter_map(&_edge_filter_map) { }  
 
   315     typedef typename GraphWrapper<Graph>::Node Node;
 
   317       friend class GraphWrapper<Graph>;
 
   318       friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
 
   319       typename Graph::NodeIt n;
 
   322       NodeIt(const typename Graph::NodeIt& _n) : n(_n) { }
 
   323       NodeIt(const Invalid& i) : n(i) { }
 
   324       NodeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _G) : 
 
   326 	while (_G.graph->valid(n) && !(*(_G.node_filter_map))[n]) 
 
   329       operator Node() const { return Node(typename Graph::Node(n)); }
 
   331     typedef typename GraphWrapper<Graph>::Edge Edge;
 
   333       friend class GraphWrapper<Graph>;
 
   334       friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
 
   335       typename Graph::OutEdgeIt e;
 
   338       OutEdgeIt(const typename Graph::OutEdgeIt& _e) : e(_e) { }
 
   339       OutEdgeIt(const Invalid& i) : e(i) { }
 
   340       OutEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _G, 
 
   342 	e(*(_G.graph), typename Graph::Node(_n)) { 
 
   343       	while (_G.graph->valid(e) && !(*(_G.edge_filter_map))[e]) 
 
   346       operator Edge() const { return Edge(typename Graph::Edge(e)); }
 
   349       friend class GraphWrapper<Graph>;
 
   350       friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
 
   351       typename Graph::InEdgeIt e;
 
   354       InEdgeIt(const typename Graph::InEdgeIt& _e) : e(_e) { }
 
   355       InEdgeIt(const Invalid& i) : e(i) { }
 
   356       InEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _G, 
 
   358 	e(*(_G.graph), typename Graph::Node(_n)) { 
 
   359       	while (_G.graph->valid(e) && !(*(_G.edge_filter_map))[e]) 
 
   362       operator Edge() const { return Edge(typename Graph::Edge(e)); }
 
   364     //typedef typename Graph::SymEdgeIt SymEdgeIt;
 
   366       friend class GraphWrapper<Graph>;
 
   367       friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
 
   368       typename Graph::EdgeIt e;
 
   371       EdgeIt(const typename Graph::EdgeIt& _e) : e(_e) { }
 
   372       EdgeIt(const Invalid& i) : e(i) { }
 
   373       EdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _G) : 
 
   375       	while (_G.graph->valid(e) && !(*(_G.edge_filter_map))[e]) 
 
   378       operator Edge() const { return Edge(typename Graph::Edge(e)); }
 
   381     NodeIt& first(NodeIt& i) const { 
 
   382       i=NodeIt(*this); return i;
 
   384     OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
 
   385       i=OutEdgeIt(*this, p); return i;
 
   387     InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
 
   388       i=InEdgeIt(*this, p); return i;
 
   390     EdgeIt& first(EdgeIt& i) const { 
 
   391       i=EdgeIt(*this); return i;
 
   394     NodeIt& next(NodeIt& i) const {
 
   395       this->graph->next(i.n); 
 
   396       while (this->graph->valid(i) && !(*node_filter_map)[i.n]) { 
 
   397 	this->graph->next(i.n); }
 
   400     OutEdgeIt& next(OutEdgeIt& i) const {
 
   401       this->graph->next(i.e); 
 
   402       while (this->graph->valid(i) && !(*edge_filter_map)[i.e]) { 
 
   403 	this->graph->next(i.e); }
 
   406     InEdgeIt& next(InEdgeIt& i) const {
 
   407       this->graph->next(i.e); 
 
   408       while (this->graph->valid(i) && !(*edge_filter_map)[i.e]) { 
 
   409 	this->graph->next(i.e); }
 
   412     EdgeIt& next(EdgeIt& i) const {
 
   413       this->graph->next(i.e); 
 
   414       while (this->graph->valid(i) && !(*edge_filter_map)[i.e]) { 
 
   415 	this->graph->next(i.e); }
 
   419     Node aNode(const OutEdgeIt& e) const { 
 
   420       return Node(this->graph->aNode(e.e)); }
 
   421     Node aNode(const InEdgeIt& e) const { 
 
   422       return Node(this->graph->aNode(e.e)); }
 
   423     Node bNode(const OutEdgeIt& e) const { 
 
   424       return Node(this->graph->bNode(e.e)); }
 
   425     Node bNode(const InEdgeIt& e) const { 
 
   426       return Node(this->graph->bNode(e.e)); }
 
   429     ///Some doki, please.
 
   430     void hide(const Node& n) const { node_filter_map->set(n, false); }
 
   432     ///Some doki, please.
 
   433     void hide(const Edge& e) const { edge_filter_map->set(e, false); }
 
   436     ///Some doki, please.
 
   437     void unHide(const Node& n) const { node_filter_map->set(n, true); }
 
   439     ///Some doki, please.
 
   440     void unHide(const Edge& e) const { edge_filter_map->set(e, true); }
 
   443     ///Some doki, please.
 
   444     bool hidden(const Node& n) const { return (*node_filter_map)[n]; }
 
   446     ///Some doki, please.
 
   447     bool hidden(const Edge& e) const { return (*edge_filter_map)[e]; }
 
   450   /// A wrapper for forgetting the orientation of a graph.
 
   452   /// A wrapper for getting an undirected graph by forgetting
 
   453   /// the orientation of a directed one.
 
   454   template<typename Graph>
 
   455   class UndirGraphWrapper : public GraphWrapper<Graph> {
 
   457     typedef typename GraphWrapper<Graph>::Node Node;
 
   458     typedef typename GraphWrapper<Graph>::NodeIt NodeIt;
 
   459     typedef typename GraphWrapper<Graph>::Edge Edge;
 
   460     typedef typename GraphWrapper<Graph>::EdgeIt EdgeIt;
 
   462     UndirGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { }  
 
   465       friend class UndirGraphWrapper<Graph>;
 
   466       bool out_or_in; //true iff out
 
   467       typename Graph::OutEdgeIt out;
 
   468       typename Graph::InEdgeIt in;
 
   471       OutEdgeIt(const Invalid& i) : Edge(i) { }
 
   472       OutEdgeIt(const UndirGraphWrapper<Graph>& _G, const Node& _n) {
 
   473 	out_or_in=true; _G.graph->first(out, _n);
 
   474 	if (!(_G.graph->valid(out))) { out_or_in=false; _G.graph->first(in, _n);	}
 
   476       operator Edge() const { 
 
   477 	if (out_or_in) return Edge(out); else return Edge(in); 
 
   482     typedef OutEdgeIt InEdgeIt; 
 
   484     using GraphWrapper<Graph>::first;
 
   485 //     NodeIt& first(NodeIt& i) const { 
 
   486 //       i=NodeIt(*this); return i;
 
   488     OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
 
   489       i=OutEdgeIt(*this, p); return i;
 
   492 //     InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
 
   493 //       i=InEdgeIt(*this, p); return i;
 
   495 //     EdgeIt& first(EdgeIt& i) const { 
 
   496 //       i=EdgeIt(*this); return i;
 
   499     using GraphWrapper<Graph>::next;
 
   500 //     NodeIt& next(NodeIt& n) const {
 
   501 //       GraphWrapper<Graph>::next(n);
 
   504     OutEdgeIt& next(OutEdgeIt& e) const {
 
   506 	typename Graph::Node n=this->graph->tail(e.out);
 
   507 	this->graph->next(e.out);
 
   508 	if (!this->graph->valid(e.out)) { 
 
   509 	  e.out_or_in=false; this->graph->first(e.in, n); }
 
   511 	this->graph->next(e.in);
 
   516 //     EdgeIt& next(EdgeIt& e) const {
 
   517 //       GraphWrapper<Graph>::next(n);
 
   518 // //      graph->next(e.e);
 
   522     Node aNode(const OutEdgeIt& e) const { 
 
   523       if (e.out_or_in) return this->graph->tail(e); else 
 
   524 	return this->graph->head(e); }
 
   525     Node bNode(const OutEdgeIt& e) const { 
 
   526       if (e.out_or_in) return this->graph->head(e); else 
 
   527 	return this->graph->tail(e); }
 
   530   /// A wrapper for composing the residual graph for directed flow and circulation problems.
 
   532   /// A wrapper for composing the residual graph for directed flow and circulation problems.
 
   533   template<typename Graph, typename Number, 
 
   534 	   typename CapacityMap, typename FlowMap>
 
   535   class ResGraphWrapper : public GraphWrapper<Graph> {
 
   537     const CapacityMap* capacity;
 
   541     ResGraphWrapper(Graph& _graph, const CapacityMap& _capacity, 
 
   543       GraphWrapper<Graph>(_graph), capacity(&_capacity), flow(&_flow) { }
 
   548     friend class OutEdgeIt; 
 
   550     typedef typename GraphWrapper<Graph>::Node Node;
 
   551     typedef typename GraphWrapper<Graph>::NodeIt NodeIt;
 
   552     class Edge : public Graph::Edge {
 
   553       friend class ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>;
 
   555       bool forward; //true, iff forward
 
   556 //      typename Graph::Edge e;
 
   559       Edge(const typename Graph::Edge& _e, bool _forward) : 
 
   560 	Graph::Edge(_e), forward(_forward) { }
 
   561       Edge(const Invalid& i) : Graph::Edge(i), forward(false) { }
 
   562 //the unique invalid iterator
 
   563       friend bool operator==(const Edge& u, const Edge& v) { 
 
   564 	return (v.forward==u.forward && 
 
   565 		static_cast<typename Graph::Edge>(u)==
 
   566 		static_cast<typename Graph::Edge>(v));
 
   568       friend bool operator!=(const Edge& u, const Edge& v) { 
 
   569 	return (v.forward!=u.forward || 
 
   570 		static_cast<typename Graph::Edge>(u)!=
 
   571 		static_cast<typename Graph::Edge>(v));
 
   576       friend class ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>;
 
   578       typename Graph::OutEdgeIt out;
 
   579       typename Graph::InEdgeIt in;
 
   584 //      OutEdgeIt(const Edge& e) : Edge(e) { }
 
   585       OutEdgeIt(const Invalid& i) : out(i), in(i), forward(false) { }
 
   586 //the unique invalid iterator
 
   587       OutEdgeIt(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& resG, Node v) { 
 
   589 	resG.graph->first(out, v);
 
   590 	while( resG.graph->valid(out) && !(resG.resCap(*this)>0) ) { resG.graph->next(out); }
 
   591 	if (!resG.graph->valid(out)) {
 
   593 	  resG.graph->first(in, v);
 
   594 	  while( resG.graph->valid(in) && !(resG.resCap(*this)>0) ) { resG.graph->next(in); }
 
   597       operator Edge() const { 
 
   599 //	e.forward=this->forward;
 
   600 //	if (this->forward) e=out; else e=in;
 
   603 	  return Edge(out, this->forward); 
 
   605 	  return Edge(in, this->forward);
 
   610       friend class ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>;
 
   612       typename Graph::OutEdgeIt out;
 
   613       typename Graph::InEdgeIt in;
 
   618 //      OutEdgeIt(const Edge& e) : Edge(e) { }
 
   619       InEdgeIt(const Invalid& i) : out(i), in(i), forward(false) { }
 
   620 //the unique invalid iterator
 
   621       InEdgeIt(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& resG, Node v) { 
 
   623 	resG.graph->first(in, v);
 
   624 	while( resG.graph->valid(in) && !(resG.resCap(*this)>0) ) { resG.graph->next(in); }
 
   625 	if (!resG.graph->valid(in)) {
 
   627 	  resG.graph->first(out, v);
 
   628 	  while( resG.graph->valid(out) && !(resG.resCap(*this)>0) ) { resG.graph->next(out); }
 
   631       operator Edge() const { 
 
   633 //	e.forward=this->forward;
 
   634 //	if (this->forward) e=out; else e=in;
 
   637 	  return Edge(in, this->forward); 
 
   639 	  return Edge(out, this->forward);
 
   644       friend class ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>;
 
   646       typename Graph::EdgeIt e;
 
   650       EdgeIt(const Invalid& i) : e(i), forward(false) { }
 
   651       EdgeIt(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& resG) { 
 
   653 	resG.graph->first(e);
 
   654 	while (resG.graph->valid(e) && !(resG.resCap(*this)>0)) resG.graph->next(e);
 
   655 	if (!resG.graph->valid(e)) {
 
   657 	  resG.graph->first(e);
 
   658 	  while (resG.graph->valid(e) && !(resG.resCap(*this)>0)) resG.graph->next(e);
 
   661       operator Edge() const { 
 
   662 	return Edge(e, this->forward);
 
   666     using GraphWrapper<Graph>::first;
 
   667 //     NodeIt& first(NodeIt& i) const { 
 
   668 //       i=NodeIt(*this); return i;
 
   670     OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
 
   671       i=OutEdgeIt(*this, p); return i;
 
   674     InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
 
   675       i=InEdgeIt(*this, p); return i;
 
   677     EdgeIt& first(EdgeIt& i) const { 
 
   678       i=EdgeIt(*this); return i;
 
   681     using GraphWrapper<Graph>::next;
 
   682 //    NodeIt& next(NodeIt& n) const { GraphWrapper<Graph>::next(n); return n; }
 
   683     OutEdgeIt& next(OutEdgeIt& e) const { 
 
   685 	Node v=this->graph->aNode(e.out);
 
   686 	this->graph->next(e.out);
 
   687 	while( this->graph->valid(e.out) && !(resCap(e)>0) ) { 
 
   688 	  this->graph->next(e.out); }
 
   689 	if (!this->graph->valid(e.out)) {
 
   691 	  this->graph->first(e.in, v); 
 
   692 	  while( this->graph->valid(e.in) && !(resCap(e)>0) ) { 
 
   693 	    this->graph->next(e.in); }
 
   696 	this->graph->next(e.in);
 
   697 	while( this->graph->valid(e.in) && !(resCap(e)>0) ) { 
 
   698 	  this->graph->next(e.in); } 
 
   703     InEdgeIt& next(InEdgeIt& e) const { 
 
   705 	Node v=this->graph->aNode(e.in);
 
   706 	this->graph->next(e.in);
 
   707 	while( this->graph->valid(e.in) && !(resCap(e)>0) ) { 
 
   708 	  this->graph->next(e.in); }
 
   709 	if (!this->graph->valid(e.in)) {
 
   711 	  this->graph->first(e.out, v); 
 
   712 	  while( this->graph->valid(e.out) && !(resCap(e)>0) ) { 
 
   713 	    this->graph->next(e.out); }
 
   716 	this->graph->next(e.out);
 
   717 	while( this->graph->valid(e.out) && !(resCap(e)>0) ) { 
 
   718 	  this->graph->next(e.out); } 
 
   722     EdgeIt& next(EdgeIt& e) const {
 
   724 	this->graph->next(e.e);
 
   725 	while( this->graph->valid(e.e) && !(resCap(e)>0) ) { 
 
   726 	  this->graph->next(e.e); }
 
   727 	if (!this->graph->valid(e.e)) {
 
   729 	  this->graph->first(e.e); 
 
   730 	  while( this->graph->valid(e.e) && !(resCap(e)>0) ) { 
 
   731 	    this->graph->next(e.e); }
 
   734 	this->graph->next(e.e);
 
   735 	while( this->graph->valid(e.e) && !(resCap(e)>0) ) { 
 
   736 	  this->graph->next(e.e); } 
 
   741     Node tail(Edge e) const { 
 
   742       return ((e.forward) ? this->graph->tail(e) : this->graph->head(e)); }
 
   743     Node head(Edge e) const { 
 
   744       return ((e.forward) ? this->graph->head(e) : this->graph->tail(e)); }
 
   746     Node aNode(OutEdgeIt e) const { 
 
   747       return ((e.forward) ? this->graph->aNode(e.out) : 
 
   748 	      this->graph->aNode(e.in)); }
 
   749     Node bNode(OutEdgeIt e) const { 
 
   750       return ((e.forward) ? this->graph->bNode(e.out) : 
 
   751 	      this->graph->bNode(e.in)); }
 
   753     Node aNode(InEdgeIt e) const { 
 
   754       return ((e.forward) ? this->graph->aNode(e.in) : 
 
   755 	      this->graph->aNode(e.out)); }
 
   756     Node bNode(InEdgeIt e) const { 
 
   757       return ((e.forward) ? this->graph->bNode(e.in) : 
 
   758 	      this->graph->bNode(e.out)); }
 
   760 //    int nodeNum() const { return graph->nodeNum(); }
 
   762     void edgeNum() const { }
 
   763     //int edgeNum() const { return graph->edgeNum(); }
 
   766 //    int id(Node v) const { return graph->id(v); }
 
   768     bool valid(Node n) const { return GraphWrapper<Graph>::valid(n); }
 
   769     bool valid(Edge e) const { 
 
   770       return this->graph->valid(e);
 
   771 	//return e.forward ? graph->valid(e.out) : graph->valid(e.in); 
 
   774     void augment(const Edge& e, Number a) const {
 
   776 // 	flow->set(e.out, flow->get(e.out)+a);
 
   777 	flow->set(e, (*flow)[e]+a);
 
   779 // 	flow->set(e.in, flow->get(e.in)-a);
 
   780 	flow->set(e, (*flow)[e]-a);
 
   783     Number resCap(const Edge& e) const { 
 
   785 //	return (capacity->get(e.out)-flow->get(e.out)); 
 
   786 	return ((*capacity)[e]-(*flow)[e]); 
 
   788 //	return (flow->get(e.in)); 
 
   792 //     Number resCap(typename Graph::OutEdgeIt out) const { 
 
   793 // //      return (capacity->get(out)-flow->get(out)); 
 
   794 //       return ((*capacity)[out]-(*flow)[out]); 
 
   797 //     Number resCap(typename Graph::InEdgeIt in) const { 
 
   798 // //      return (flow->get(in)); 
 
   799 //       return ((*flow)[in]); 
 
   802     template <typename T>
 
   804       typename Graph::template EdgeMap<T> forward_map, backward_map; 
 
   806       EdgeMap(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& _G) : forward_map(*(_G.graph)), backward_map(*(_G.graph)) { }
 
   807       EdgeMap(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& _G, T a) : forward_map(*(_G.graph), a), backward_map(*(_G.graph), a) { }
 
   808       void set(Edge e, T a) { 
 
   810 	  forward_map.set(e.out, a); 
 
   812 	  backward_map.set(e.in, a); 
 
   814       T operator[](Edge e) const { 
 
   816 	  return forward_map[e.out]; 
 
   818 	  return backward_map[e.in]; 
 
   820 //       T get(Edge e) const { 
 
   822 // 	  return forward_map.get(e.out); 
 
   824 // 	  return backward_map.get(e.in); 
 
   829   /// ErasingFirstGraphWrapper for blocking flows.
 
   831   /// ErasingFirstGraphWrapper for blocking flows.
 
   833   ///\author Marton Makai
 
   834   template<typename Graph, typename FirstOutEdgesMap>
 
   835   class ErasingFirstGraphWrapper : public GraphWrapper<Graph> {
 
   837     FirstOutEdgesMap* first_out_edges;
 
   839     ErasingFirstGraphWrapper(Graph& _graph, 
 
   840 			     FirstOutEdgesMap& _first_out_edges) : 
 
   841       GraphWrapper<Graph>(_graph), first_out_edges(&_first_out_edges) { }  
 
   843     typedef typename GraphWrapper<Graph>::Node Node;
 
   845 //       friend class GraphWrapper<Graph>;
 
   846 //       friend class ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>;
 
   847 //       typename Graph::NodeIt n;
 
   850 //       NodeIt(const typename Graph::NodeIt& _n) : n(_n) { }
 
   851 //       NodeIt(const Invalid& i) : n(i) { }
 
   852 //       NodeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _G) : 
 
   853 // 	n(*(_G.graph)) { }
 
   854 //       operator Node() const { return Node(typename Graph::Node(n)); }
 
   856     typedef typename GraphWrapper<Graph>::Edge Edge;
 
   858       friend class GraphWrapper<Graph>;
 
   859       friend class ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>;
 
   860 //      typedef typename Graph::OutEdgeIt GraphOutEdgeIt;
 
   861       typename Graph::OutEdgeIt e;
 
   864       OutEdgeIt(const typename Graph::OutEdgeIt& _e) : e(_e) { }
 
   865       OutEdgeIt(const Invalid& i) : e(i) { }
 
   866       OutEdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _G, 
 
   868 	e((*_G.first_out_edges)[_n]) { }
 
   869       operator Edge() const { return Edge(typename Graph::Edge(e)); }
 
   872       friend class GraphWrapper<Graph>;
 
   873       friend class ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>;
 
   874 //      typedef typename Graph::InEdgeIt GraphInEdgeIt;
 
   875       typename Graph::InEdgeIt e;
 
   878       InEdgeIt(const typename Graph::InEdgeIt& _e) : e(_e) { }
 
   879       InEdgeIt(const Invalid& i) : e(i) { }
 
   880       InEdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _G, 
 
   882 	e(*(_G.graph), typename Graph::Node(_n)) { }
 
   883       operator Edge() const { return Edge(typename Graph::Edge(e)); }
 
   885     //typedef typename Graph::SymEdgeIt SymEdgeIt;
 
   887       friend class GraphWrapper<Graph>;
 
   888       friend class ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>;
 
   889 //      typedef typename Graph::EdgeIt GraphEdgeIt;
 
   890       typename Graph::EdgeIt e;
 
   893       EdgeIt(const typename Graph::EdgeIt& _e) : e(_e) { }
 
   894       EdgeIt(const Invalid& i) : e(i) { }
 
   895       EdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _G) : 
 
   897       operator Edge() const { return Edge(typename Graph::Edge(e)); }
 
   900     using GraphWrapper<Graph>::first;
 
   901 //     NodeIt& first(NodeIt& i) const { 
 
   902 //       i=NodeIt(*this); return i;
 
   904     OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
 
   905       i=OutEdgeIt(*this, p); return i;
 
   907     InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
 
   908       i=InEdgeIt(*this, p); return i;
 
   910     EdgeIt& first(EdgeIt& i) const { 
 
   911       i=EdgeIt(*this); return i;
 
   914     using GraphWrapper<Graph>::next;
 
   915 //    NodeIt& next(NodeIt& i) const { graph->next(i.n); return i; }
 
   916     OutEdgeIt& next(OutEdgeIt& i) const { this->graph->next(i.e); return i; }
 
   917     InEdgeIt& next(InEdgeIt& i) const { this->graph->next(i.e); return i; }
 
   918     EdgeIt& next(EdgeIt& i) const { this->graph->next(i.e); return i; }    
 
   920     Node aNode(const OutEdgeIt& e) const { 
 
   921       return Node(this->graph->aNode(e.e)); }
 
   922     Node aNode(const InEdgeIt& e) const { 
 
   923       return Node(this->graph->aNode(e.e)); }
 
   924     Node bNode(const OutEdgeIt& e) const { 
 
   925       return Node(this->graph->bNode(e.e)); }
 
   926     Node bNode(const InEdgeIt& e) const { 
 
   927       return Node(this->graph->bNode(e.e)); }
 
   929     void erase(const OutEdgeIt& e) const {
 
   932       first_out_edges->set(this->tail(e), f.e);
 
   936   /// A wrapper for composing a bipartite graph.
 
   937   /// \c _graph have to be a reference to a graph of type \c Graph 
 
   938   /// and \c _s_false_t_true_map is an \c IterableBoolMap 
 
   939   /// reference containing the elements for the 
 
   940   /// color classes S and T. \c _graph is to be referred to an undirected 
 
   941   /// graph or a directed graph with edges oriented from S to T.
 
   943   ///\author Marton Makai
 
   944   template<typename Graph> 
 
   945   class BipartiteGraphWrapper : public GraphWrapper<Graph> {
 
   946     typedef IterableBoolMap< typename Graph::template NodeMap<int> > 
 
   948     SFalseTTrueMap* s_false_t_true_map;
 
   952     //FIXME vhogy igy kellene, csak az en forditom nem eszi meg
 
   953     //static const bool S_CLASS=false;
 
   954     //static const bool T_CLASS=true;
 
   959     BipartiteGraphWrapper(Graph& _graph, SFalseTTrueMap& _s_false_t_true_map) 
 
   960       : GraphWrapper<Graph>(_graph), s_false_t_true_map(&_s_false_t_true_map), 
 
   961       S_CLASS(false), T_CLASS(true) { }
 
   962     typedef typename GraphWrapper<Graph>::Node Node;
 
   963     //using GraphWrapper<Graph>::NodeIt;
 
   964     typedef typename GraphWrapper<Graph>::Edge Edge;
 
   965     //using GraphWrapper<Graph>::EdgeIt;
 
   967     friend class ClassNodeIt;
 
   969     friend class OutEdgeIt;
 
   971     friend class InEdgeIt;
 
   973       friend class BipartiteGraphWrapper<Graph>;
 
   978       ClassNodeIt(const Invalid& i) : n(i) { }
 
   979       ClassNodeIt(const BipartiteGraphWrapper<Graph>& _G, bool _class) { 
 
   980 	_G.s_false_t_true_map->first(n, _class); 
 
   982       //FIXME needed in new concept, important here
 
   983       ClassNodeIt(const Node& _n) : n(_n) { }
 
   984       operator Node() const { return n; }
 
   990 //       SNodeIt(const Invalid& i) : n(i) { }
 
   991 //       SNodeIt(const BipartiteGraphWrapper<Graph>& _G) { 
 
   992 // 	_G.s_false_t_true_map->first(n, false); 
 
   994 //       operator Node() const { return n; }
 
  1000 //       TNodeIt(const Invalid& i) : n(i) { }
 
  1001 //       TNodeIt(const BipartiteGraphWrapper<Graph>& _G) { 
 
  1002 // 	_G.s_false_t_true_map->first(n, true); 
 
  1004 //       operator Node() const { return n; }
 
  1007       friend class BipartiteGraphWrapper<Graph>;
 
  1009       typename Graph::OutEdgeIt e;
 
  1012       OutEdgeIt(const Invalid& i) : e(i) { }
 
  1013       OutEdgeIt(const BipartiteGraphWrapper<Graph>& _G, const Node& _n) {
 
  1014 	if (!(*(_G.s_false_t_true_map))[_n]) 
 
  1015 	  e=typename Graph::OutEdgeIt(*(_G.graph), typename Graph::Node(_n));
 
  1019       operator Edge() const { return Edge(typename Graph::Edge(e)); }
 
  1022       friend class BipartiteGraphWrapper<Graph>;
 
  1024       typename Graph::InEdgeIt e;
 
  1027       InEdgeIt(const Invalid& i) : e(i) { }
 
  1028       InEdgeIt(const BipartiteGraphWrapper<Graph>& _G, const Node& _n) {
 
  1029 	if ((*(_G.s_false_t_true_map))[_n]) 
 
  1030 	  e=typename Graph::InEdgeIt(*(_G.graph), typename Graph::Node(_n));
 
  1034       operator Edge() const { return Edge(typename Graph::Edge(e)); }
 
  1037     using GraphWrapper<Graph>::first;
 
  1038     ClassNodeIt& first(ClassNodeIt& n, bool _class) const { 
 
  1039       n=ClassNodeIt(*this, _class) ; return n; }
 
  1040 //    SNodeIt& first(SNodeIt& n) const { n=SNodeIt(*this); return n; }
 
  1041 //    TNodeIt& first(TNodeIt& n) const { n=TNodeIt(*this); return n; }
 
  1042     OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
 
  1043       i=OutEdgeIt(*this, p); return i;
 
  1045     InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
 
  1046       i=InEdgeIt(*this, p); return i;
 
  1049     using GraphWrapper<Graph>::next;
 
  1050     ClassNodeIt& next(ClassNodeIt& n) const { 
 
  1051       this->s_false_t_true_map->next(n.n); return n; 
 
  1053 //     SNodeIt& next(SNodeIt& n) const { 
 
  1054 //       this->s_false_t_true_map->next(n); return n; 
 
  1056 //     TNodeIt& next(TNodeIt& n) const { 
 
  1057 //       this->s_false_t_true_map->next(n); return n; 
 
  1059     OutEdgeIt& next(OutEdgeIt& i) const { this->graph->next(i.e); return i; }
 
  1060     InEdgeIt& next(InEdgeIt& i) const { this->graph->next(i.e); return i; }
 
  1062     Node tail(const Edge& e) { 
 
  1063       if (!(*(this->s_false_t_true_map))[this->graph->tail(e)]) 
 
  1064 	return Node(this->graph->tail(e));
 
  1066 	return Node(this->graph->head(e));	
 
  1068     Node head(const Edge& e) { 
 
  1069       if (!(*(this->s_false_t_true_map))[this->graph->tail(e)]) 
 
  1070 	return Node(this->graph->head(e));
 
  1072 	return Node(this->graph->tail(e));	
 
  1075     Node aNode(const OutEdgeIt& e) const { 
 
  1076       return Node(this->graph->aNode(e.e)); 
 
  1078     Node aNode(const InEdgeIt& e) const { 
 
  1079       return Node(this->graph->aNode(e.e)); 
 
  1081     Node bNode(const OutEdgeIt& e) const { 
 
  1082       return Node(this->graph->bNode(e.e)); 
 
  1084     Node bNode(const InEdgeIt& e) const { 
 
  1085       return Node(this->graph->bNode(e.e)); 
 
  1088     bool inSClass(const Node& n) const {
 
  1089       return !(*(this->s_false_t_true_map))[n];
 
  1091     bool inTClass(const Node& n) const {
 
  1092       return (*(this->s_false_t_true_map))[n];
 
  1096   template<typename Graph>
 
  1097   class stGraphWrapper;
 
  1099 //   template<typename Graph> 
 
  1101 //   operator<<(std::ostream& os, const typename stGraphWrapper<Graph>::Node& i) { 
 
  1102 //     os << "(node: " << typename Graph::Node(i) << " spec: " << i.spec <<")"; 
 
  1105 //   template<typename Graph> 
 
  1107 //   operator<<(std::ostream& os, const typename stGraphWrapper<Graph>::Edge& i) { 
 
  1108 //     os << "(edge: " << typename Graph::Edge(i) << " spec: " << i.spec << 
 
  1109 //       " node: " << i.n << ")"; 
 
  1113   /// experimentral, do not try it.
 
  1114   /// It eats a bipartite graph, oriented from S to T.
 
  1115   /// Such one can be made e.g. by the above wrapper.
 
  1117   ///\author Marton Makai
 
  1118   template<typename Graph>
 
  1119   class stGraphWrapper : public GraphWrapper<Graph> {
 
  1124 //0 normalis, 1 s, 2, true, ez az iteralasi sorrend, 
 
  1125 //es a vege a false azaz (invalid, 3)    
 
  1127     friend class NodeIt;
 
  1132 //0 normalis, 1 s->vmi, 2 vmi->t, ez a sorrend,
 
  1133 //invalid: (invalid, 3, invalid)
 
  1135     friend class OutEdgeIt;
 
  1137 //normalis pontbol (first, 0, invalid), ..., (invalid, 2, vmi), ... (invalid, 3, invalid)
 
  1138 //s-bol (invalid, 1, first), ... (invalid, 3, invalid)
 
  1139 //t-bol (invalid, 3, invalid)
 
  1141     friend class InEdgeIt;
 
  1143 //normalis pontbol (first, 0, invalid), ..., (invalid, 1, vmi), ... (invalid, 3, invalid)
 
  1144 //s-be (invalid, 3, invalid)
 
  1145 //t-be (invalid, 2, first), ... (invalid, 3, invalid)
 
  1147     friend class EdgeIt;
 
  1148 //(first, 0, invalid) ...
 
  1151 //invalid, 3, invalid)
 
  1152     template <typename T> class NodeMap;
 
  1153     template <typename T, typename Parent> class EdgeMap;
 
  1155 //    template <typename T> friend class NodeMap;
 
  1156 //    template <typename T> friend class EdgeMap;
 
  1161     static const bool S_CLASS=false;
 
  1162     static const bool T_CLASS=true;
 
  1164     stGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) , 
 
  1166 				    T_NODE(INVALID, 2) { }
 
  1170 //    operator<<(std::ostream& os, const /*typename stGraphWrapper<Graph>::*/Node& i);
 
  1171 //    friend std::ostream& 
 
  1172 //    operator<<(std::ostream& os, const /*typename stGraphWrapper<Graph>::*/Node& i);
 
  1173 //    friend std::ostream& 
 
  1174 //    operator<<(std::ostream& os, const /*typename stGraphWrapper<Graph>::*/Edge& i);
 
  1176     class Node : public Graph::Node {
 
  1178       friend class GraphWrapper<Graph>;
 
  1179       friend class stGraphWrapper<Graph>;
 
  1180       template <typename T> friend class NodeMap;
 
  1182       friend class OutEdgeIt;
 
  1183       friend class InEdgeIt;
 
  1184       friend class EdgeIt;
 
  1188       Node(const typename Graph::Node& _n, int _spec=0) : 
 
  1189 	Graph::Node(_n), spec(_spec) { }
 
  1190       Node(const Invalid& i) : Graph::Node(i), spec(3) { }
 
  1191       friend bool operator==(const Node& u, const Node& v) { 
 
  1192 	return (u.spec==v.spec && 
 
  1193 		static_cast<typename Graph::Node>(u)==
 
  1194 		static_cast<typename Graph::Node>(v));
 
  1196       friend bool operator!=(const Node& u, const Node& v) { 
 
  1197 	return (v.spec!=u.spec || 
 
  1198 		static_cast<typename Graph::Node>(u)!=
 
  1199 		static_cast<typename Graph::Node>(v));
 
  1201 //      template<typename G> 
 
  1202 //      friend std::ostream& 
 
  1203 //      operator<<(std::ostream& os, const typename stGraphWrapper<G>::Node& i); 
 
  1204       friend std::ostream& operator<< (std::ostream& os, const Node& i);
 
  1205       int getSpec() const { return spec; }
 
  1209       friend class GraphWrapper<Graph>;
 
  1210       friend class stGraphWrapper<Graph>;
 
  1211       typename Graph::NodeIt n;
 
  1215       NodeIt(const typename Graph::NodeIt& _n, int _spec) : 
 
  1216 	n(_n), spec(_spec) { }
 
  1217       NodeIt(const Invalid& i) : n(i), spec(3) { }
 
  1218       NodeIt(const stGraphWrapper<Graph>& _G) : n(*(_G.graph)), spec(0) { 
 
  1219 	if (!_G.graph->valid(n)) spec=1;
 
  1221       operator Node() const { return Node(n, spec); }
 
  1224     class Edge : public Graph::Edge {
 
  1225       friend class GraphWrapper<Graph>;
 
  1226       friend class stGraphWrapper<Graph>;
 
  1227       template <typename T, typename Parent> friend class EdgeMap;
 
  1229       typename Graph::Node n;
 
  1232       Edge(const typename Graph::Edge& _e, int _spec, 
 
  1233 	   const typename Graph::Node& _n) : 
 
  1234 	Graph::Edge(_e), spec(_spec), n(_n) { 
 
  1236       Edge(const Invalid& i) : Graph::Edge(i), spec(3), n(i) { }
 
  1237       friend bool operator==(const Edge& u, const Edge& v) { 
 
  1238 	return (u.spec==v.spec && 
 
  1239 		static_cast<typename Graph::Edge>(u)==
 
  1240 		static_cast<typename Graph::Edge>(v) && 
 
  1243       friend bool operator!=(const Edge& u, const Edge& v) { 
 
  1244 	return (v.spec!=u.spec || 
 
  1245 		static_cast<typename Graph::Edge>(u)!=
 
  1246 		static_cast<typename Graph::Edge>(v) || 
 
  1249 //      template<typename G> 
 
  1250 //      friend std::ostream& 
 
  1251 //      operator<<(std::ostream& os, const typename stGraphWrapper<G>::Edge& i); 
 
  1252       friend std::ostream& operator<< (std::ostream& os, const Edge& i);
 
  1253       int getSpec() const { return spec; }
 
  1257       friend class GraphWrapper<Graph>;
 
  1258       friend class stGraphWrapper<Graph>;
 
  1259       typename Graph::OutEdgeIt e;
 
  1261       typename Graph::ClassNodeIt n;
 
  1264       OutEdgeIt(const typename Graph::OutEdgeIt& _e, int _spec, 
 
  1265 		const typename Graph::ClassNodeIt& _n) : 
 
  1266 	e(_e), spec(_spec), n(_n) { 
 
  1268       OutEdgeIt(const Invalid& i) : e(i), spec(3), n(i) { }
 
  1269       OutEdgeIt(const stGraphWrapper<Graph>& _G, const Node& _n) {
 
  1272 	    if (_G.graph->inSClass(_n)) { //S, van normalis kiel 
 
  1273 	      e=typename Graph::OutEdgeIt(*(_G.graph), 
 
  1274 					  typename Graph::Node(_n)); 
 
  1277 	      if (!_G.graph->valid(e)) spec=3;
 
  1278 	    } else { //T, specko kiel van
 
  1287 	    _G.graph->first(n, S_CLASS); //s->vmi;
 
  1288 	    if (!_G.graph->valid(n)) spec=3; //Ha S ures
 
  1297       operator Edge() const { return Edge(e, spec, n); }
 
  1301       friend class GraphWrapper<Graph>;
 
  1302       friend class stGraphWrapper<Graph>;
 
  1303       typename Graph::InEdgeIt e;
 
  1305       typename Graph::ClassNodeIt n;
 
  1308       InEdgeIt(const typename Graph::InEdgeIt& _e, int _spec, 
 
  1309 	       const typename Graph::ClassNodeIt& _n) : 
 
  1310 	e(_e), spec(_spec), n(_n) { 
 
  1312       InEdgeIt(const Invalid& i) : e(i), spec(3), n(i) { }
 
  1313       InEdgeIt(const stGraphWrapper<Graph>& _G, const Node& _n) {
 
  1316 	    if (_G.graph->inTClass(_n)) { //T, van normalis beel 
 
  1317 	      e=typename Graph::InEdgeIt(*(_G.graph), 
 
  1318 					 typename Graph::Node(_n)); 
 
  1321 	      if (!_G.graph->valid(e)) spec=3;
 
  1322 	    } else { //S, specko beel van
 
  1336 	    _G.graph->first(n, T_CLASS); //vmi->t;
 
  1337 	    if (!_G.graph->valid(n)) spec=3; //Ha T ures
 
  1341       operator Edge() const { return Edge(e, spec, n); }
 
  1345       friend class GraphWrapper<Graph>;
 
  1346       friend class stGraphWrapper<Graph>;
 
  1347       typename Graph::EdgeIt e;
 
  1349       typename Graph::ClassNodeIt n;
 
  1352       EdgeIt(const typename Graph::EdgeIt& _e, int _spec, 
 
  1353 	     const typename Graph::ClassNodeIt& _n) : 
 
  1354 	e(_e), spec(_spec), n(_n) { }
 
  1355       EdgeIt(const Invalid& i) : e(i), spec(3), n(i) { }
 
  1356       EdgeIt(const stGraphWrapper<Graph>& _G) : 
 
  1357 	e(*(_G.graph)), spec(0), n(INVALID) { 
 
  1358 	if (!_G.graph->valid(e)) {
 
  1360 	  _G.graph->first(n, S_CLASS);
 
  1361 	  if (!_G.graph->valid(n)) { //Ha S ures
 
  1363 	    _G.graph->first(n, T_CLASS);
 
  1364 	    if (!_G.graph->valid(n)) { //Ha T ures
 
  1370       operator Edge() const { return Edge(e, spec, n); }
 
  1373     NodeIt& first(NodeIt& i) const { 
 
  1374       i=NodeIt(*this); return i;
 
  1376     OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
 
  1377       i=OutEdgeIt(*this, p); return i;
 
  1379     InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
 
  1380       i=InEdgeIt(*this, p); return i;
 
  1382     EdgeIt& first(EdgeIt& i) const { 
 
  1383       i=EdgeIt(*this); return i;
 
  1386     NodeIt& next(NodeIt& i) const { 
 
  1389 	  this->graph->next(i.n);
 
  1390 	  if (!this->graph->valid(i.n)) {
 
  1403     OutEdgeIt& next(OutEdgeIt& i) const { 
 
  1404       typename Graph::Node v;
 
  1406 	case 0: //normal edge
 
  1407 	  v=this->graph->aNode(i.e);
 
  1408 	  this->graph->next(i.e);
 
  1409 	  if (!this->graph->valid(i.e)) { //Az igazi elek vegere ertunk
 
  1410 	    if (this->graph->inSClass(v)) { //S, nincs kiel
 
  1413 	    } else { //T, van kiel
 
  1420 	  this->graph->next(i.n);
 
  1421 	  if (!this->graph->valid(i.n)) i.spec=3;
 
  1430     InEdgeIt& next(InEdgeIt& i) const { 
 
  1431       typename Graph::Node v;
 
  1433 	case 0: //normal edge
 
  1434 	  v=this->graph->aNode(i.e);
 
  1435 	  this->graph->next(i.e);
 
  1436 	  if (!this->graph->valid(i.e)) { //Az igazi elek vegere ertunk
 
  1437 	    if (this->graph->inTClass(v)) { //S, nincs beel
 
  1440 	    } else { //S, van beel
 
  1451 	  this->graph->next(i.n);
 
  1452 	  if (!this->graph->valid(i.n)) i.spec=3;
 
  1458     EdgeIt& next(EdgeIt& i) const { 
 
  1461 	  this->graph->next(i.e);
 
  1462 	  if (!this->graph->valid(i.e)) { 
 
  1464 	    this->graph->first(i.n, S_CLASS);
 
  1465 	    if (!this->graph->valid(i.n)) {
 
  1467 	      this->graph->first(i.n, T_CLASS);
 
  1468 	      if (!this->graph->valid(i.n)) i.spec=3;
 
  1473 	  this->graph->next(i.n);
 
  1474 	  if (!this->graph->valid(i.n)) {
 
  1476 	    this->graph->first(i.n, T_CLASS);
 
  1477 	    if (!this->graph->valid(i.n)) i.spec=3;
 
  1481 	  this->graph->next(i.n);
 
  1482 	  if (!this->graph->valid(i.n)) i.spec=3;
 
  1488     Node tail(const Edge& e) const { 
 
  1491 	return Node(this->graph->tail(e));
 
  1502     Node head(const Edge& e) const { 
 
  1505 	return Node(this->graph->head(e));
 
  1517     bool valid(const Node& n) const { return (n.spec<3); }
 
  1518     bool valid(const Edge& e) const { return (e.spec<3); }
 
  1520     int nodeNum() const { return this->graph->nodeNum()+2; }
 
  1521     int edgeNum() const { 
 
  1522       return this->graph->edgeNum()+this->graph->nodeNum(); 
 
  1525     Node aNode(const OutEdgeIt& e) const { return tail(e); }
 
  1526     Node aNode(const InEdgeIt& e) const { return head(e); }
 
  1527     Node bNode(const OutEdgeIt& e) const { return head(e); }
 
  1528     Node bNode(const InEdgeIt& e) const { return tail(e); }
 
  1530     void addNode() const { }
 
  1531     void addEdge() const { }
 
  1533 //    Node addNode() const { return Node(this->graph->addNode()); }
 
  1534 //    Edge addEdge(const Node& tail, const Node& head) const { 
 
  1535 //      return Edge(this->graph->addEdge(tail, head)); }
 
  1537 //    void erase(const Node& i) const { this->graph->erase(i); }
 
  1538 //    void erase(const Edge& i) const { this->graph->erase(i); }
 
  1540 //    void clear() const { this->graph->clear(); }
 
  1542     template<typename T> class NodeMap : public GraphWrapper<Graph>::template NodeMap<T> { 
 
  1543       typedef typename GraphWrapper<Graph>::template NodeMap<T> Parent;
 
  1546       NodeMap(const stGraphWrapper<Graph>& _G) :  Parent(_G), 
 
  1549       NodeMap(const stGraphWrapper<Graph>& _G, T a) : Parent(_G, a), 
 
  1552       T operator[](const Node& n) const { 
 
  1555 	  return Parent::operator[](n);
 
  1566       void set(const Node& n, T t) { 
 
  1569 	  GraphWrapper<Graph>::template NodeMap<T>::set(n, t);
 
  1582     template<typename T, 
 
  1584 	     typename GraphWrapper<Graph>::template EdgeMap<T> > 
 
  1585     class EdgeMap : public Parent { 
 
  1586       //typedef typename GraphWrapper<Graph>::template EdgeMap<T> Parent;
 
  1587       typename GraphWrapper<Graph>::template NodeMap<T> node_value;
 
  1589       EdgeMap(const stGraphWrapper<Graph>& _G) : Parent(_G), 
 
  1591       EdgeMap(const stGraphWrapper<Graph>& _G, T a) : Parent(_G, a), 
 
  1592 						      node_value(_G, a) { }
 
  1593       T operator[](const Edge& e) const { 
 
  1596 	  return Parent::operator[](e);
 
  1599 	  return node_value[e.n];
 
  1603 	  return node_value[e.n];
 
  1607       void set(const Edge& e, T t) { 
 
  1613 	  node_value.set(e.n, t);
 
  1617 	  node_value.set(e.n, t);
 
  1623 //     template<typename T> class EdgeMap : public GraphWrapper<Graph>::template EdgeMap<T> { 
 
  1624 //       typedef typename GraphWrapper<Graph>::template EdgeMap<T> Parent;
 
  1625 //       typename GraphWrapper<Graph>::template NodeMap<T> node_value;
 
  1627 //       EdgeMap(const stGraphWrapper<Graph>& _G) : Parent(_G), 
 
  1628 // 						 node_value(_G) { }
 
  1629 //       EdgeMap(const stGraphWrapper<Graph>& _G, T a) : Parent(_G, a), 
 
  1630 // 						      node_value(_G, a) { }
 
  1631 //       T operator[](const Edge& e) const { 
 
  1632 // 	switch (e.spec) {
 
  1634 // 	  return Parent::operator[](e);
 
  1637 // 	  return node_value[e.n];
 
  1641 // 	  return node_value[e.n];
 
  1645 //       void set(const Edge& e, T t) { 
 
  1646 // 	switch (e.spec) {
 
  1648 // 	  GraphWrapper<Graph>::template EdgeMap<T>::set(e, t);
 
  1651 // 	  node_value.set(e.n, t);
 
  1655 // 	  node_value.set(e.n, t);
 
  1661 //  template<typename G> 
 
  1662     friend std::ostream& 
 
  1663     operator<<(std::ostream& os, const /*typename stGraphWrapper<Graph>::*/Node& i) { 
 
  1664       os << "(node: " << typename Graph::Node(i) << " spec: " << i.spec <<")"; 
 
  1667 //  template<typename G> 
 
  1668     friend std::ostream& 
 
  1669     operator<<(std::ostream& os, const /*typename stGraphWrapper<Graph>::*/Edge& i) { 
 
  1670       os << "(edge: " << typename Graph::Edge(i) << " spec: " << i.spec << 
 
  1671 	" node: " << i.n << ")"; 
 
  1682 #endif //HUGO_GRAPH_WRAPPER_H