3  * This file is a part of LEMON, a generic C++ optimization library
 
     5  * Copyright (C) 2003-2006
 
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
 
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
 
     9  * Permission to use, modify and distribute this software is granted
 
    10  * provided that this copyright notice appears in all copies. For
 
    11  * precise terms see the accompanying LICENSE file.
 
    13  * This software is provided "AS IS" with no warranty of any kind,
 
    14  * express or implied, and with no claim as to its suitability for any
 
    19 #ifndef LEMON_BITS_GRAPH_EXTENDER_H
 
    20 #define LEMON_BITS_GRAPH_EXTENDER_H
 
    22 #include <lemon/bits/invalid.h>
 
    23 #include <lemon/error.h>
 
    25 #include <lemon/bits/map_extender.h>
 
    26 #include <lemon/bits/default_map.h>
 
    28 #include <lemon/concept_check.h>
 
    29 #include <lemon/concept/maps.h>
 
    33 ///\brief Extenders for the graph types
 
    36   /// \ingroup graphbits
 
    38   /// \brief Extender for the Graphs
 
    39   template <typename Base>
 
    40   class GraphExtender : public Base {
 
    44     typedef GraphExtender Graph;
 
    48     typedef typename Parent::Node Node;
 
    49     typedef typename Parent::Edge Edge;
 
    51     int maxId(Node) const {
 
    52       return Parent::maxNodeId();
 
    55     int maxId(Edge) const {
 
    56       return Parent::maxEdgeId();
 
    59     Node fromId(int id, Node) const {
 
    60       return Parent::nodeFromId(id);
 
    63     Edge fromId(int id, Edge) const {
 
    64       return Parent::edgeFromId(id);
 
    67     Node oppositeNode(const Node &n, const Edge &e) const {
 
    68       if (n == Parent::source(e))
 
    69 	return Parent::target(e);
 
    70       else if(n==Parent::target(e))
 
    71 	return Parent::source(e);
 
    76     // Alterable extension
 
    78     typedef AlterationNotifier<GraphExtender, Node> NodeNotifier;
 
    79     typedef AlterationNotifier<GraphExtender, Edge> EdgeNotifier;
 
    84     mutable NodeNotifier node_notifier;
 
    85     mutable EdgeNotifier edge_notifier;
 
    89     NodeNotifier& getNotifier(Node) const {
 
    93     EdgeNotifier& getNotifier(Edge) const {
 
    97     class NodeIt : public Node { 
 
   103       NodeIt(Invalid i) : Node(i) { }
 
   105       explicit NodeIt(const Graph& _graph) : graph(&_graph) {
 
   106 	_graph.first(*static_cast<Node*>(this));
 
   109       NodeIt(const Graph& _graph, const Node& node) 
 
   110 	: Node(node), graph(&_graph) {}
 
   112       NodeIt& operator++() { 
 
   120     class EdgeIt : public Edge { 
 
   126       EdgeIt(Invalid i) : Edge(i) { }
 
   128       explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
 
   129 	_graph.first(*static_cast<Edge*>(this));
 
   132       EdgeIt(const Graph& _graph, const Edge& e) : 
 
   133 	Edge(e), graph(&_graph) { }
 
   135       EdgeIt& operator++() { 
 
   143     class OutEdgeIt : public Edge { 
 
   149       OutEdgeIt(Invalid i) : Edge(i) { }
 
   151       OutEdgeIt(const Graph& _graph, const Node& node) 
 
   153 	_graph.firstOut(*this, node);
 
   156       OutEdgeIt(const Graph& _graph, const Edge& edge) 
 
   157 	: Edge(edge), graph(&_graph) {}
 
   159       OutEdgeIt& operator++() { 
 
   160 	graph->nextOut(*this);
 
   167     class InEdgeIt : public Edge { 
 
   173       InEdgeIt(Invalid i) : Edge(i) { }
 
   175       InEdgeIt(const Graph& _graph, const Node& node) 
 
   177 	_graph.firstIn(*this, node);
 
   180       InEdgeIt(const Graph& _graph, const Edge& edge) : 
 
   181 	Edge(edge), graph(&_graph) {}
 
   183       InEdgeIt& operator++() { 
 
   184 	graph->nextIn(*this);
 
   190     /// \brief Base node of the iterator
 
   192     /// Returns the base node (ie. the source in this case) of the iterator
 
   193     Node baseNode(const OutEdgeIt &e) const {
 
   194       return Parent::source(e);
 
   196     /// \brief Running node of the iterator
 
   198     /// Returns the running node (ie. the target in this case) of the
 
   200     Node runningNode(const OutEdgeIt &e) const {
 
   201       return Parent::target(e);
 
   204     /// \brief Base node of the iterator
 
   206     /// Returns the base node (ie. the target in this case) of the iterator
 
   207     Node baseNode(const InEdgeIt &e) const {
 
   208       return Parent::target(e);
 
   210     /// \brief Running node of the iterator
 
   212     /// Returns the running node (ie. the source in this case) of the
 
   214     Node runningNode(const InEdgeIt &e) const {
 
   215       return Parent::source(e);
 
   219     template <typename _Value>
 
   221       : public MapExtender<DefaultMap<Graph, Node, _Value> > {
 
   223       typedef GraphExtender Graph;
 
   224       typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent;
 
   226       NodeMap(const Graph& graph) 
 
   228       NodeMap(const Graph& graph, const _Value& value) 
 
   229 	: Parent(graph, value) {}
 
   231       NodeMap& operator=(const NodeMap& cmap) {
 
   232 	return operator=<NodeMap>(cmap);
 
   236       /// \brief Template assign operator.
 
   238       /// The given parameter should be conform to the ReadMap
 
   239       /// concecpt and could be indiced by the current item set of
 
   240       /// the NodeMap. In this case the value for each item
 
   241       /// is assigned by the value of the given ReadMap. 
 
   242       template <typename CMap>
 
   243       NodeMap& operator=(const CMap& cmap) {
 
   244 	checkConcept<concept::ReadMap<Node, _Value>, CMap>();
 
   245 	const typename Parent::Notifier* notifier = Parent::getNotifier();
 
   247 	for (notifier->first(it); it != INVALID; notifier->next(it)) {
 
   248 	  Parent::set(it, cmap[it]);
 
   255     template <typename _Value>
 
   257       : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
 
   259       typedef GraphExtender Graph;
 
   260       typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
 
   262       EdgeMap(const Graph& graph) 
 
   264       EdgeMap(const Graph& graph, const _Value& value) 
 
   265 	: Parent(graph, value) {}
 
   267       EdgeMap& operator=(const EdgeMap& cmap) {
 
   268 	return operator=<EdgeMap>(cmap);
 
   271       template <typename CMap>
 
   272       EdgeMap& operator=(const CMap& cmap) {
 
   273 	checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
 
   274 	const typename Parent::Notifier* notifier = Parent::getNotifier();
 
   276 	for (notifier->first(it); it != INVALID; notifier->next(it)) {
 
   277 	  Parent::set(it, cmap[it]);
 
   285       Node node = Parent::addNode();
 
   286       getNotifier(Node()).add(node);
 
   290     Edge addEdge(const Node& from, const Node& to) {
 
   291       Edge edge = Parent::addEdge(from, to);
 
   292       getNotifier(Edge()).add(edge);
 
   297       getNotifier(Edge()).clear();
 
   298       getNotifier(Node()).clear();
 
   303     void erase(const Node& node) {
 
   305       Parent::firstOut(edge, node);
 
   306       while (edge != INVALID ) {
 
   308 	Parent::firstOut(edge, node);
 
   311       Parent::firstIn(edge, node);
 
   312       while (edge != INVALID ) {
 
   314 	Parent::firstIn(edge, node);
 
   317       getNotifier(Node()).erase(node);
 
   321     void erase(const Edge& edge) {
 
   322       getNotifier(Edge()).erase(edge);
 
   327       node_notifier.setContainer(*this);
 
   328       edge_notifier.setContainer(*this);
 
   333       edge_notifier.clear();
 
   334       node_notifier.clear();
 
   338   /// \ingroup graphbits
 
   340   /// \brief Extender for the UGraphs
 
   341   template <typename Base> 
 
   342   class UGraphExtender : public Base {
 
   346     typedef UGraphExtender Graph;
 
   348     typedef typename Parent::Node Node;
 
   349     typedef typename Parent::Edge Edge;
 
   350     typedef typename Parent::UEdge UEdge;
 
   354     int maxId(Node) const {
 
   355       return Parent::maxNodeId();
 
   358     int maxId(Edge) const {
 
   359       return Parent::maxEdgeId();
 
   362     int maxId(UEdge) const {
 
   363       return Parent::maxUEdgeId();
 
   366     Node fromId(int id, Node) const {
 
   367       return Parent::nodeFromId(id);
 
   370     Edge fromId(int id, Edge) const {
 
   371       return Parent::edgeFromId(id);
 
   374     UEdge fromId(int id, UEdge) const {
 
   375       return Parent::uEdgeFromId(id);
 
   378     Node oppositeNode(const Node &n, const UEdge &e) const {
 
   379       if( n == Parent::source(e))
 
   380 	return Parent::target(e);
 
   381       else if( n == Parent::target(e))
 
   382 	return Parent::source(e);
 
   387     Edge oppositeEdge(const Edge &e) const {
 
   388       return Parent::direct(e, !Parent::direction(e));
 
   391     using Parent::direct;
 
   392     Edge direct(const UEdge &ue, const Node &s) const {
 
   393       return Parent::direct(ue, Parent::source(ue) == s);
 
   396     // Alterable extension
 
   398     typedef AlterationNotifier<UGraphExtender, Node> NodeNotifier;
 
   399     typedef AlterationNotifier<UGraphExtender, Edge> EdgeNotifier;
 
   400     typedef AlterationNotifier<UGraphExtender, UEdge> UEdgeNotifier;
 
   405     mutable NodeNotifier node_notifier;
 
   406     mutable EdgeNotifier edge_notifier;
 
   407     mutable UEdgeNotifier uedge_notifier;
 
   411     NodeNotifier& getNotifier(Node) const {
 
   412       return node_notifier;
 
   415     EdgeNotifier& getNotifier(Edge) const {
 
   416       return edge_notifier;
 
   419     UEdgeNotifier& getNotifier(UEdge) const {
 
   420       return uedge_notifier;
 
   425     class NodeIt : public Node { 
 
   431       NodeIt(Invalid i) : Node(i) { }
 
   433       explicit NodeIt(const Graph& _graph) : graph(&_graph) {
 
   434 	_graph.first(*static_cast<Node*>(this));
 
   437       NodeIt(const Graph& _graph, const Node& node) 
 
   438 	: Node(node), graph(&_graph) {}
 
   440       NodeIt& operator++() { 
 
   448     class EdgeIt : public Edge { 
 
   454       EdgeIt(Invalid i) : Edge(i) { }
 
   456       explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
 
   457 	_graph.first(*static_cast<Edge*>(this));
 
   460       EdgeIt(const Graph& _graph, const Edge& e) : 
 
   461 	Edge(e), graph(&_graph) { }
 
   463       EdgeIt& operator++() { 
 
   471     class OutEdgeIt : public Edge { 
 
   477       OutEdgeIt(Invalid i) : Edge(i) { }
 
   479       OutEdgeIt(const Graph& _graph, const Node& node) 
 
   481 	_graph.firstOut(*this, node);
 
   484       OutEdgeIt(const Graph& _graph, const Edge& edge) 
 
   485 	: Edge(edge), graph(&_graph) {}
 
   487       OutEdgeIt& operator++() { 
 
   488 	graph->nextOut(*this);
 
   495     class InEdgeIt : public Edge { 
 
   501       InEdgeIt(Invalid i) : Edge(i) { }
 
   503       InEdgeIt(const Graph& _graph, const Node& node) 
 
   505 	_graph.firstIn(*this, node);
 
   508       InEdgeIt(const Graph& _graph, const Edge& edge) : 
 
   509 	Edge(edge), graph(&_graph) {}
 
   511       InEdgeIt& operator++() { 
 
   512 	graph->nextIn(*this);
 
   519     class UEdgeIt : public Parent::UEdge { 
 
   525       UEdgeIt(Invalid i) : UEdge(i) { }
 
   527       explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
 
   528 	_graph.first(*static_cast<UEdge*>(this));
 
   531       UEdgeIt(const Graph& _graph, const UEdge& e) : 
 
   532 	UEdge(e), graph(&_graph) { }
 
   534       UEdgeIt& operator++() { 
 
   541     class IncEdgeIt : public Parent::UEdge {
 
   542       friend class UGraphExtender;
 
   549       IncEdgeIt(Invalid i) : UEdge(i), direction(false) { }
 
   551       IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
 
   552 	_graph.firstInc(*this, direction, n);
 
   555       IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
 
   556 	: graph(&_graph), UEdge(ue) {
 
   557 	direction = (_graph.source(ue) == n);
 
   560       IncEdgeIt& operator++() {
 
   561 	graph->nextInc(*this, direction);
 
   566     /// \brief Base node of the iterator
 
   568     /// Returns the base node (ie. the source in this case) of the iterator
 
   569     Node baseNode(const OutEdgeIt &e) const {
 
   570       return Parent::source((Edge)e);
 
   572     /// \brief Running node of the iterator
 
   574     /// Returns the running node (ie. the target in this case) of the
 
   576     Node runningNode(const OutEdgeIt &e) const {
 
   577       return Parent::target((Edge)e);
 
   580     /// \brief Base node of the iterator
 
   582     /// Returns the base node (ie. the target in this case) of the iterator
 
   583     Node baseNode(const InEdgeIt &e) const {
 
   584       return Parent::target((Edge)e);
 
   586     /// \brief Running node of the iterator
 
   588     /// Returns the running node (ie. the source in this case) of the
 
   590     Node runningNode(const InEdgeIt &e) const {
 
   591       return Parent::source((Edge)e);
 
   594     /// Base node of the iterator
 
   596     /// Returns the base node of the iterator
 
   597     Node baseNode(const IncEdgeIt &e) const {
 
   598       return e.direction ? source(e) : target(e);
 
   600     /// Running node of the iterator
 
   602     /// Returns the running node of the iterator
 
   603     Node runningNode(const IncEdgeIt &e) const {
 
   604       return e.direction ? target(e) : source(e);
 
   607     // Mappable extension
 
   609     template <typename _Value>
 
   611       : public MapExtender<DefaultMap<Graph, Node, _Value> > {
 
   613       typedef UGraphExtender Graph;
 
   614       typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent;
 
   616       NodeMap(const Graph& graph) 
 
   618       NodeMap(const Graph& graph, const _Value& value) 
 
   619 	: Parent(graph, value) {}
 
   621       NodeMap& operator=(const NodeMap& cmap) {
 
   622 	return operator=<NodeMap>(cmap);
 
   626       /// \brief Template assign operator.
 
   628       /// The given parameter should be conform to the ReadMap
 
   629       /// concecpt and could be indiced by the current item set of
 
   630       /// the NodeMap. In this case the value for each item
 
   631       /// is assigned by the value of the given ReadMap. 
 
   632       template <typename CMap>
 
   633       NodeMap& operator=(const CMap& cmap) {
 
   634 	checkConcept<concept::ReadMap<Node, _Value>, CMap>();
 
   635 	const typename Parent::Notifier* notifier = Parent::getNotifier();
 
   637 	for (notifier->first(it); it != INVALID; notifier->next(it)) {
 
   638 	  Parent::set(it, cmap[it]);
 
   645     template <typename _Value>
 
   647       : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
 
   649       typedef UGraphExtender Graph;
 
   650       typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
 
   652       EdgeMap(const Graph& graph) 
 
   654       EdgeMap(const Graph& graph, const _Value& value) 
 
   655 	: Parent(graph, value) {}
 
   657       EdgeMap& operator=(const EdgeMap& cmap) {
 
   658 	return operator=<EdgeMap>(cmap);
 
   661       template <typename CMap>
 
   662       EdgeMap& operator=(const CMap& cmap) {
 
   663 	checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
 
   664 	const typename Parent::Notifier* notifier = Parent::getNotifier();
 
   666 	for (notifier->first(it); it != INVALID; notifier->next(it)) {
 
   667 	  Parent::set(it, cmap[it]);
 
   674     template <typename _Value>
 
   676       : public MapExtender<DefaultMap<Graph, UEdge, _Value> > {
 
   678       typedef UGraphExtender Graph;
 
   679       typedef MapExtender<DefaultMap<Graph, UEdge, _Value> > Parent;
 
   681       UEdgeMap(const Graph& graph) 
 
   683       UEdgeMap(const Graph& graph, const _Value& value) 
 
   684 	: Parent(graph, value) {}
 
   686       UEdgeMap& operator=(const UEdgeMap& cmap) {
 
   687 	return operator=<UEdgeMap>(cmap);
 
   690       template <typename CMap>
 
   691       UEdgeMap& operator=(const CMap& cmap) {
 
   692 	checkConcept<concept::ReadMap<UEdge, _Value>, CMap>();
 
   693 	const typename Parent::Notifier* notifier = Parent::getNotifier();
 
   695 	for (notifier->first(it); it != INVALID; notifier->next(it)) {
 
   696 	  Parent::set(it, cmap[it]);
 
   702     // Alteration extension
 
   705       Node node = Parent::addNode();
 
   706       getNotifier(Node()).add(node);
 
   710     UEdge addEdge(const Node& from, const Node& to) {
 
   711       UEdge uedge = Parent::addEdge(from, to);
 
   712       getNotifier(UEdge()).add(uedge);
 
   713       getNotifier(Edge()).add(Parent::direct(uedge, true));
 
   714       getNotifier(Edge()).add(Parent::direct(uedge, false));
 
   719       getNotifier(Edge()).clear();
 
   720       getNotifier(UEdge()).clear();
 
   721       getNotifier(Node()).clear();
 
   725     void erase(const Node& node) {
 
   727       Parent::firstOut(edge, node);
 
   728       while (edge != INVALID ) {
 
   730 	Parent::firstOut(edge, node);
 
   733       Parent::firstIn(edge, node);
 
   734       while (edge != INVALID ) {
 
   736 	Parent::firstIn(edge, node);
 
   739       getNotifier(Node()).erase(node);
 
   743     void erase(const UEdge& uedge) {
 
   744       getNotifier(Edge()).erase(Parent::direct(uedge, true));
 
   745       getNotifier(Edge()).erase(Parent::direct(uedge, false));
 
   746       getNotifier(UEdge()).erase(uedge);
 
   747       Parent::erase(uedge);
 
   751       node_notifier.setContainer(*this); 
 
   752       edge_notifier.setContainer(*this);
 
   753       uedge_notifier.setContainer(*this);
 
   757       uedge_notifier.clear();
 
   758       edge_notifier.clear();
 
   759       node_notifier.clear(); 
 
   764   /// \ingroup graphbits
 
   766   /// \brief Extender for the BpUGraphs
 
   767   template <typename Base>
 
   768   class BpUGraphExtender : public Base {
 
   771     typedef BpUGraphExtender Graph;
 
   773     typedef typename Parent::Node Node;
 
   774     typedef typename Parent::BNode BNode;
 
   775     typedef typename Parent::ANode ANode;
 
   776     typedef typename Parent::Edge Edge;
 
   777     typedef typename Parent::UEdge UEdge;
 
   779     Node oppositeNode(const UEdge& edge, const Node& node) const {
 
   780       return source(edge) == node ? 
 
   781 	target(edge) : source(edge);
 
   784     using Parent::direct;
 
   785     Edge direct(const UEdge& edge, const Node& node) const {
 
   786       return Edge(edge, node == Parent::source(edge));
 
   789     Edge oppositeEdge(const Edge& edge) const {
 
   790       return Parent::direct(edge, !Parent::direction(edge));
 
   794     int maxId(Node) const {
 
   795       return Parent::maxNodeId();
 
   797     int maxId(BNode) const {
 
   798       return Parent::maxBNodeId();
 
   800     int maxId(ANode) const {
 
   801       return Parent::maxANodeId();
 
   803     int maxId(Edge) const {
 
   804       return Parent::maxEdgeId();
 
   806     int maxId(UEdge) const {
 
   807       return Parent::maxUEdgeId();
 
   811     Node fromId(int id, Node) const {
 
   812       return Parent::nodeFromId(id);
 
   814     ANode fromId(int id, ANode) const {
 
   815       return Parent::fromANodeId(id);
 
   817     BNode fromId(int id, BNode) const {
 
   818       return Parent::fromBNodeId(id);
 
   820     Edge fromId(int id, Edge) const {
 
   821       return Parent::edgeFromId(id);
 
   823     UEdge fromId(int id, UEdge) const {
 
   824       return Parent::uEdgeFromId(id);
 
   827     typedef AlterationNotifier<BpUGraphExtender, ANode> ANodeNotifier;
 
   828     typedef AlterationNotifier<BpUGraphExtender, BNode> BNodeNotifier;
 
   829     typedef AlterationNotifier<BpUGraphExtender, Node> NodeNotifier;
 
   830     typedef AlterationNotifier<BpUGraphExtender, Edge> EdgeNotifier;
 
   831     typedef AlterationNotifier<BpUGraphExtender, UEdge> UEdgeNotifier;
 
   835     mutable ANodeNotifier anode_notifier;
 
   836     mutable BNodeNotifier bnode_notifier;
 
   837     mutable NodeNotifier node_notifier;
 
   838     mutable EdgeNotifier edge_notifier;
 
   839     mutable UEdgeNotifier uedge_notifier;
 
   843     NodeNotifier& getNotifier(Node) const {
 
   844       return node_notifier;
 
   847     ANodeNotifier& getNotifier(ANode) const {
 
   848       return anode_notifier;
 
   851     BNodeNotifier& getNotifier(BNode) const {
 
   852       return bnode_notifier;
 
   855     EdgeNotifier& getNotifier(Edge) const {
 
   856       return edge_notifier;
 
   859     UEdgeNotifier& getNotifier(UEdge) const {
 
   860       return uedge_notifier;
 
   863     class NodeIt : public Node { 
 
   869       NodeIt(Invalid i) : Node(INVALID) { }
 
   871       explicit NodeIt(const Graph& _graph) : graph(&_graph) {
 
   872 	graph->first(static_cast<Node&>(*this));
 
   875       NodeIt(const Graph& _graph, const Node& node) 
 
   876 	: Node(node), graph(&_graph) { }
 
   878       NodeIt& operator++() { 
 
   885     class ANodeIt : public Node { 
 
   886       friend class BpUGraphExtender;
 
   892       ANodeIt(Invalid i) : Node(INVALID) { }
 
   894       explicit ANodeIt(const Graph& _graph) : graph(&_graph) {
 
   895 	graph->firstANode(static_cast<Node&>(*this));
 
   898       ANodeIt(const Graph& _graph, const Node& node) 
 
   899 	: Node(node), graph(&_graph) {}
 
   901       ANodeIt& operator++() { 
 
   902 	graph->nextANode(*this);
 
   907     class BNodeIt : public Node { 
 
   908       friend class BpUGraphExtender;
 
   914       BNodeIt(Invalid i) : Node(INVALID) { }
 
   916       explicit BNodeIt(const Graph& _graph) : graph(&_graph) {
 
   917 	graph->firstBNode(static_cast<Node&>(*this));
 
   920       BNodeIt(const Graph& _graph, const Node& node) 
 
   921 	: Node(node), graph(&_graph) {}
 
   923       BNodeIt& operator++() { 
 
   924 	graph->nextBNode(*this);
 
   929     class EdgeIt : public Edge { 
 
   930       friend class BpUGraphExtender;
 
   936       EdgeIt(Invalid i) : Edge(INVALID) { }
 
   938       explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
 
   939 	graph->first(static_cast<Edge&>(*this));
 
   942       EdgeIt(const Graph& _graph, const Edge& edge) 
 
   943 	: Edge(edge), graph(&_graph) { }
 
   945       EdgeIt& operator++() { 
 
   952     class UEdgeIt : public UEdge { 
 
   953       friend class BpUGraphExtender;
 
   959       UEdgeIt(Invalid i) : UEdge(INVALID) { }
 
   961       explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
 
   962 	graph->first(static_cast<UEdge&>(*this));
 
   965       UEdgeIt(const Graph& _graph, const UEdge& edge) 
 
   966 	: UEdge(edge), graph(&_graph) { }
 
   968       UEdgeIt& operator++() { 
 
   974     class OutEdgeIt : public Edge { 
 
   975       friend class BpUGraphExtender;
 
   981       OutEdgeIt(Invalid i) : Edge(i) { }
 
   983       OutEdgeIt(const Graph& _graph, const Node& node) 
 
   985 	graph->firstOut(*this, node);
 
   988       OutEdgeIt(const Graph& _graph, const Edge& edge) 
 
   989 	: Edge(edge), graph(&_graph) {}
 
   991       OutEdgeIt& operator++() { 
 
   992 	graph->nextOut(*this);
 
   999     class InEdgeIt : public Edge { 
 
  1000       friend class BpUGraphExtender;
 
  1006       InEdgeIt(Invalid i) : Edge(i) { }
 
  1008       InEdgeIt(const Graph& _graph, const Node& node) 
 
  1010 	graph->firstIn(*this, node);
 
  1013       InEdgeIt(const Graph& _graph, const Edge& edge) : 
 
  1014 	Edge(edge), graph(&_graph) {}
 
  1016       InEdgeIt& operator++() { 
 
  1017 	graph->nextIn(*this);
 
  1023     /// \brief Base node of the iterator
 
  1025     /// Returns the base node (ie. the source in this case) of the iterator
 
  1026     Node baseNode(const OutEdgeIt &e) const {
 
  1027       return Parent::source((Edge&)e);
 
  1029     /// \brief Running node of the iterator
 
  1031     /// Returns the running node (ie. the target in this case) of the
 
  1033     Node runningNode(const OutEdgeIt &e) const {
 
  1034       return Parent::target((Edge&)e);
 
  1037     /// \brief Base node of the iterator
 
  1039     /// Returns the base node (ie. the target in this case) of the iterator
 
  1040     Node baseNode(const InEdgeIt &e) const {
 
  1041       return Parent::target((Edge&)e);
 
  1043     /// \brief Running node of the iterator
 
  1045     /// Returns the running node (ie. the source in this case) of the
 
  1047     Node runningNode(const InEdgeIt &e) const {
 
  1048       return Parent::source((Edge&)e);
 
  1051     class IncEdgeIt : public Parent::UEdge { 
 
  1052       friend class BpUGraphExtender;
 
  1059       IncEdgeIt(Invalid i) : UEdge(i), direction(true) { }
 
  1061       IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
 
  1062 	graph->firstInc(*this, direction, n);
 
  1065       IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
 
  1066 	: graph(&_graph), UEdge(ue) {
 
  1067 	direction = (graph->source(ue) == n);
 
  1070       IncEdgeIt& operator++() {
 
  1071 	graph->nextInc(*this, direction);
 
  1077     /// Base node of the iterator
 
  1079     /// Returns the base node of the iterator
 
  1080     Node baseNode(const IncEdgeIt &e) const {
 
  1081       return e.direction ? source(e) : target(e);
 
  1084     /// Running node of the iterator
 
  1086     /// Returns the running node of the iterator
 
  1087     Node runningNode(const IncEdgeIt &e) const {
 
  1088       return e.direction ? target(e) : source(e);
 
  1091     template <typename _Value>
 
  1093       : public MapExtender<DefaultMap<Graph, ANode, _Value> > {
 
  1095       typedef BpUGraphExtender Graph;
 
  1096       typedef MapExtender<DefaultMap<Graph, ANode, _Value> > Parent;
 
  1098       ANodeMap(const Graph& graph) 
 
  1100       ANodeMap(const Graph& graph, const _Value& value) 
 
  1101 	: Parent(graph, value) {}
 
  1103       ANodeMap& operator=(const ANodeMap& cmap) {
 
  1104 	return operator=<ANodeMap>(cmap);
 
  1108       /// \brief Template assign operator.
 
  1110       /// The given parameter should be conform to the ReadMap
 
  1111       /// concept and could be indiced by the current item set of
 
  1112       /// the ANodeMap. In this case the value for each item
 
  1113       /// is assigned by the value of the given ReadMap. 
 
  1114       template <typename CMap>
 
  1115       ANodeMap& operator=(const CMap& cmap) {
 
  1116 	checkConcept<concept::ReadMap<ANode, _Value>, CMap>();
 
  1117 	const typename Parent::Graph* graph = Parent::getGraph();
 
  1119 	for (graph->first(it); it != INVALID; graph->next(it)) {
 
  1120 	  Parent::set(it, cmap[it]);
 
  1127     template <typename _Value>
 
  1129       : public MapExtender<DefaultMap<Graph, BNode, _Value> > {
 
  1131       typedef BpUGraphExtender Graph;
 
  1132       typedef MapExtender<DefaultMap<Graph, BNode, _Value> > Parent;
 
  1134       BNodeMap(const Graph& graph) 
 
  1136       BNodeMap(const Graph& graph, const _Value& value) 
 
  1137 	: Parent(graph, value) {}
 
  1139       BNodeMap& operator=(const BNodeMap& cmap) {
 
  1140 	return operator=<BNodeMap>(cmap);
 
  1144       /// \brief Template assign operator.
 
  1146       /// The given parameter should be conform to the ReadMap
 
  1147       /// concept and could be indiced by the current item set of
 
  1148       /// the BNodeMap. In this case the value for each item
 
  1149       /// is assigned by the value of the given ReadMap. 
 
  1150       template <typename CMap>
 
  1151       BNodeMap& operator=(const CMap& cmap) {
 
  1152 	checkConcept<concept::ReadMap<BNode, _Value>, CMap>();
 
  1153 	const typename Parent::Graph* graph = Parent::getGraph();
 
  1155 	for (graph->first(it); it != INVALID; graph->next(it)) {
 
  1156 	  Parent::set(it, cmap[it]);
 
  1165     template <typename _Value>
 
  1168       typedef BpUGraphExtender Graph;
 
  1171       typedef _Value Value;
 
  1173       /// The reference type of the map;
 
  1174       typedef typename ANodeMap<_Value>::Reference Reference;
 
  1175       /// The const reference type of the map;
 
  1176       typedef typename ANodeMap<_Value>::ConstReference ConstReference;
 
  1178       typedef True ReferenceMapTag;
 
  1180       NodeMapBase(const Graph& graph) 
 
  1181 	: aNodeMap(graph), bNodeMap(graph) {}
 
  1182       NodeMapBase(const Graph& graph, const _Value& value) 
 
  1183 	: aNodeMap(graph, value), bNodeMap(graph, value) {}
 
  1185       ConstReference operator[](const Key& node) const {
 
  1186 	if (Parent::aNode(node)) {
 
  1187 	  return aNodeMap[node];
 
  1189 	  return bNodeMap[node];
 
  1193       Reference operator[](const Key& node) {
 
  1194 	if (Parent::aNode(node)) {
 
  1195 	  return aNodeMap[node];
 
  1197 	  return bNodeMap[node];
 
  1201       void set(const Key& node, const Value& value) {
 
  1202 	if (Parent::aNode(node)) {
 
  1203 	  aNodeMap.set(node, value);
 
  1205 	  bNodeMap.set(node, value);
 
  1209       const Graph* getGraph() const {
 
  1210         return aNodeMap.getGraph();
 
  1214       ANodeMap<_Value> aNodeMap;
 
  1215       BNodeMap<_Value> bNodeMap;
 
  1220     template <typename _Value>
 
  1222       : public MapExtender<NodeMapBase<_Value> > {
 
  1224       typedef BpUGraphExtender Graph;
 
  1225       typedef MapExtender< NodeMapBase<_Value> > Parent;
 
  1227       NodeMap(const Graph& graph) 
 
  1229       NodeMap(const Graph& graph, const _Value& value) 
 
  1230 	: Parent(graph, value) {}
 
  1232       NodeMap& operator=(const NodeMap& cmap) {
 
  1233 	return operator=<NodeMap>(cmap);
 
  1237       /// \brief Template assign operator.
 
  1239       /// The given parameter should be conform to the ReadMap
 
  1240       /// concept and could be indiced by the current item set of
 
  1241       /// the NodeMap. In this case the value for each item
 
  1242       /// is assigned by the value of the given ReadMap. 
 
  1243       template <typename CMap>
 
  1244       NodeMap& operator=(const CMap& cmap) {
 
  1245 	checkConcept<concept::ReadMap<Node, _Value>, CMap>();
 
  1246 	const typename Parent::Notifier* notifier = Parent::getNotifier();
 
  1248 	for (notifier->first(it); it != INVALID; notifier->next(it)) {
 
  1249 	  Parent::set(it, cmap[it]);
 
  1258     template <typename _Value>
 
  1260       : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
 
  1262       typedef BpUGraphExtender Graph;
 
  1263       typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
 
  1265       EdgeMap(const Graph& graph) 
 
  1267       EdgeMap(const Graph& graph, const _Value& value) 
 
  1268 	: Parent(graph, value) {}
 
  1270       EdgeMap& operator=(const EdgeMap& cmap) {
 
  1271 	return operator=<EdgeMap>(cmap);
 
  1274       template <typename CMap>
 
  1275       EdgeMap& operator=(const CMap& cmap) {
 
  1276 	checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
 
  1277 	const typename Parent::Notifier* notifier = Parent::getNotifier();
 
  1279 	for (notifier->first(it); it != INVALID; notifier->next(it)) {
 
  1280 	  Parent::set(it, cmap[it]);
 
  1286     template <typename _Value>
 
  1288       : public MapExtender<DefaultMap<Graph, UEdge, _Value> > {
 
  1290       typedef BpUGraphExtender Graph;
 
  1291       typedef MapExtender<DefaultMap<Graph, UEdge, _Value> > Parent;
 
  1293       UEdgeMap(const Graph& graph) 
 
  1295       UEdgeMap(const Graph& graph, const _Value& value) 
 
  1296 	: Parent(graph, value) {}
 
  1298       UEdgeMap& operator=(const UEdgeMap& cmap) {
 
  1299 	return operator=<UEdgeMap>(cmap);
 
  1302       template <typename CMap>
 
  1303       UEdgeMap& operator=(const CMap& cmap) {
 
  1304 	checkConcept<concept::ReadMap<UEdge, _Value>, CMap>();
 
  1305 	const typename Parent::Notifier* notifier = Parent::getNotifier();
 
  1307 	for (notifier->first(it); it != INVALID; notifier->next(it)) {
 
  1308 	  Parent::set(it, cmap[it]);
 
  1316       Node node = Parent::addANode();
 
  1317       getNotifier(ANode()).add(node);
 
  1318       getNotifier(Node()).add(node);
 
  1323       Node node = Parent::addBNode();
 
  1324       getNotifier(BNode()).add(node);
 
  1325       getNotifier(Node()).add(node);
 
  1329     UEdge addEdge(const Node& source, const Node& target) {
 
  1330       UEdge uedge = Parent::addEdge(source, target);
 
  1331       getNotifier(UEdge()).add(uedge);
 
  1333       std::vector<Edge> edges;
 
  1334       edges.push_back(direct(uedge, true));
 
  1335       edges.push_back(direct(uedge, false));
 
  1336       getNotifier(Edge()).add(edges);
 
  1342       getNotifier(Edge()).clear();
 
  1343       getNotifier(UEdge()).clear();
 
  1344       getNotifier(Node()).clear();
 
  1345       getNotifier(BNode()).clear();
 
  1346       getNotifier(ANode()).clear();
 
  1350     void erase(const Node& node) {
 
  1353       Parent::firstInc(uedge, dir, node);
 
  1354       while (uedge != INVALID ) {
 
  1356 	Parent::firstInc(uedge, dir, node);
 
  1359       getNotifier(Node()).erase(node);
 
  1360       Parent::erase(node);
 
  1363     void erase(const UEdge& uedge) {
 
  1364       std::vector<Edge> edges;
 
  1365       edges.push_back(direct(uedge, true));
 
  1366       edges.push_back(direct(uedge, false));
 
  1367       getNotifier(Edge()).erase(edges);
 
  1368       getNotifier(UEdge()).erase(uedge);
 
  1369       Parent::erase(uedge);
 
  1373     BpUGraphExtender() {
 
  1374       anode_notifier.setContainer(*this); 
 
  1375       bnode_notifier.setContainer(*this); 
 
  1376       node_notifier.setContainer(*this); 
 
  1377       edge_notifier.setContainer(*this); 
 
  1378       uedge_notifier.setContainer(*this);
 
  1381     ~BpUGraphExtender() {
 
  1382       uedge_notifier.clear();
 
  1383       edge_notifier.clear(); 
 
  1384       node_notifier.clear(); 
 
  1385       anode_notifier.clear(); 
 
  1386       bnode_notifier.clear();