3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2008
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/concepts/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& notifier(Node) const {
93 EdgeNotifier& notifier(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 (i.e. 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 (i.e. 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 (i.e. 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 (i.e. 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 explicit 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);
235 template <typename CMap>
236 NodeMap& operator=(const CMap& cmap) {
237 Parent::operator=(cmap);
243 template <typename _Value>
245 : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
247 typedef GraphExtender Graph;
248 typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
250 explicit EdgeMap(const Graph& graph)
252 EdgeMap(const Graph& graph, const _Value& value)
253 : Parent(graph, value) {}
255 EdgeMap& operator=(const EdgeMap& cmap) {
256 return operator=<EdgeMap>(cmap);
259 template <typename CMap>
260 EdgeMap& operator=(const CMap& cmap) {
261 Parent::operator=(cmap);
268 Node node = Parent::addNode();
269 notifier(Node()).add(node);
273 Edge addEdge(const Node& from, const Node& to) {
274 Edge edge = Parent::addEdge(from, to);
275 notifier(Edge()).add(edge);
280 notifier(Edge()).clear();
281 notifier(Node()).clear();
285 template <typename Graph, typename NodeRefMap, typename EdgeRefMap>
286 void build(const Graph& graph, NodeRefMap& nodeRef, EdgeRefMap& edgeRef) {
287 Parent::build(graph, nodeRef, edgeRef);
288 notifier(Node()).build();
289 notifier(Edge()).build();
292 void erase(const Node& node) {
294 Parent::firstOut(edge, node);
295 while (edge != INVALID ) {
297 Parent::firstOut(edge, node);
300 Parent::firstIn(edge, node);
301 while (edge != INVALID ) {
303 Parent::firstIn(edge, node);
306 notifier(Node()).erase(node);
310 void erase(const Edge& edge) {
311 notifier(Edge()).erase(edge);
316 node_notifier.setContainer(*this);
317 edge_notifier.setContainer(*this);
322 edge_notifier.clear();
323 node_notifier.clear();
327 /// \ingroup graphbits
329 /// \brief Extender for the UGraphs
330 template <typename Base>
331 class UGraphExtender : public Base {
335 typedef UGraphExtender Graph;
337 typedef typename Parent::Node Node;
338 typedef typename Parent::Edge Edge;
339 typedef typename Parent::UEdge UEdge;
343 int maxId(Node) const {
344 return Parent::maxNodeId();
347 int maxId(Edge) const {
348 return Parent::maxEdgeId();
351 int maxId(UEdge) const {
352 return Parent::maxUEdgeId();
355 Node fromId(int id, Node) const {
356 return Parent::nodeFromId(id);
359 Edge fromId(int id, Edge) const {
360 return Parent::edgeFromId(id);
363 UEdge fromId(int id, UEdge) const {
364 return Parent::uEdgeFromId(id);
367 Node oppositeNode(const Node &n, const UEdge &e) const {
368 if( n == Parent::source(e))
369 return Parent::target(e);
370 else if( n == Parent::target(e))
371 return Parent::source(e);
376 Edge oppositeEdge(const Edge &e) const {
377 return Parent::direct(e, !Parent::direction(e));
380 using Parent::direct;
381 Edge direct(const UEdge &ue, const Node &s) const {
382 return Parent::direct(ue, Parent::source(ue) == s);
385 // Alterable extension
387 typedef AlterationNotifier<UGraphExtender, Node> NodeNotifier;
388 typedef AlterationNotifier<UGraphExtender, Edge> EdgeNotifier;
389 typedef AlterationNotifier<UGraphExtender, UEdge> UEdgeNotifier;
394 mutable NodeNotifier node_notifier;
395 mutable EdgeNotifier edge_notifier;
396 mutable UEdgeNotifier uedge_notifier;
400 NodeNotifier& notifier(Node) const {
401 return node_notifier;
404 EdgeNotifier& notifier(Edge) const {
405 return edge_notifier;
408 UEdgeNotifier& notifier(UEdge) const {
409 return uedge_notifier;
414 class NodeIt : public Node {
420 NodeIt(Invalid i) : Node(i) { }
422 explicit NodeIt(const Graph& _graph) : graph(&_graph) {
423 _graph.first(static_cast<Node&>(*this));
426 NodeIt(const Graph& _graph, const Node& node)
427 : Node(node), graph(&_graph) {}
429 NodeIt& operator++() {
437 class EdgeIt : public Edge {
443 EdgeIt(Invalid i) : Edge(i) { }
445 explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
446 _graph.first(static_cast<Edge&>(*this));
449 EdgeIt(const Graph& _graph, const Edge& e) :
450 Edge(e), graph(&_graph) { }
452 EdgeIt& operator++() {
460 class OutEdgeIt : public Edge {
466 OutEdgeIt(Invalid i) : Edge(i) { }
468 OutEdgeIt(const Graph& _graph, const Node& node)
470 _graph.firstOut(*this, node);
473 OutEdgeIt(const Graph& _graph, const Edge& edge)
474 : Edge(edge), graph(&_graph) {}
476 OutEdgeIt& operator++() {
477 graph->nextOut(*this);
484 class InEdgeIt : public Edge {
490 InEdgeIt(Invalid i) : Edge(i) { }
492 InEdgeIt(const Graph& _graph, const Node& node)
494 _graph.firstIn(*this, node);
497 InEdgeIt(const Graph& _graph, const Edge& edge) :
498 Edge(edge), graph(&_graph) {}
500 InEdgeIt& operator++() {
501 graph->nextIn(*this);
508 class UEdgeIt : public Parent::UEdge {
514 UEdgeIt(Invalid i) : UEdge(i) { }
516 explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
517 _graph.first(static_cast<UEdge&>(*this));
520 UEdgeIt(const Graph& _graph, const UEdge& e) :
521 UEdge(e), graph(&_graph) { }
523 UEdgeIt& operator++() {
530 class IncEdgeIt : public Parent::UEdge {
531 friend class UGraphExtender;
538 IncEdgeIt(Invalid i) : UEdge(i), direction(false) { }
540 IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
541 _graph.firstInc(*this, direction, n);
544 IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
545 : graph(&_graph), UEdge(ue) {
546 direction = (_graph.source(ue) == n);
549 IncEdgeIt& operator++() {
550 graph->nextInc(*this, direction);
555 /// \brief Base node of the iterator
557 /// Returns the base node (ie. the source in this case) of the iterator
558 Node baseNode(const OutEdgeIt &e) const {
559 return Parent::source(static_cast<const Edge&>(e));
561 /// \brief Running node of the iterator
563 /// Returns the running node (ie. the target in this case) of the
565 Node runningNode(const OutEdgeIt &e) const {
566 return Parent::target(static_cast<const Edge&>(e));
569 /// \brief Base node of the iterator
571 /// Returns the base node (ie. the target in this case) of the iterator
572 Node baseNode(const InEdgeIt &e) const {
573 return Parent::target(static_cast<const Edge&>(e));
575 /// \brief Running node of the iterator
577 /// Returns the running node (ie. the source in this case) of the
579 Node runningNode(const InEdgeIt &e) const {
580 return Parent::source(static_cast<const Edge&>(e));
583 /// Base node of the iterator
585 /// Returns the base node of the iterator
586 Node baseNode(const IncEdgeIt &e) const {
587 return e.direction ? source(e) : target(e);
589 /// Running node of the iterator
591 /// Returns the running node of the iterator
592 Node runningNode(const IncEdgeIt &e) const {
593 return e.direction ? target(e) : source(e);
596 // Mappable extension
598 template <typename _Value>
600 : public MapExtender<DefaultMap<Graph, Node, _Value> > {
602 typedef UGraphExtender Graph;
603 typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent;
605 NodeMap(const Graph& graph)
607 NodeMap(const Graph& graph, const _Value& value)
608 : Parent(graph, value) {}
610 NodeMap& operator=(const NodeMap& cmap) {
611 return operator=<NodeMap>(cmap);
614 template <typename CMap>
615 NodeMap& operator=(const CMap& cmap) {
616 Parent::operator=(cmap);
622 template <typename _Value>
624 : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
626 typedef UGraphExtender Graph;
627 typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
629 EdgeMap(const Graph& graph)
631 EdgeMap(const Graph& graph, const _Value& value)
632 : Parent(graph, value) {}
634 EdgeMap& operator=(const EdgeMap& cmap) {
635 return operator=<EdgeMap>(cmap);
638 template <typename CMap>
639 EdgeMap& operator=(const CMap& cmap) {
640 Parent::operator=(cmap);
646 template <typename _Value>
648 : public MapExtender<DefaultMap<Graph, UEdge, _Value> > {
650 typedef UGraphExtender Graph;
651 typedef MapExtender<DefaultMap<Graph, UEdge, _Value> > Parent;
653 UEdgeMap(const Graph& graph)
656 UEdgeMap(const Graph& graph, const _Value& value)
657 : Parent(graph, value) {}
659 UEdgeMap& operator=(const UEdgeMap& cmap) {
660 return operator=<UEdgeMap>(cmap);
663 template <typename CMap>
664 UEdgeMap& operator=(const CMap& cmap) {
665 Parent::operator=(cmap);
671 // Alteration extension
674 Node node = Parent::addNode();
675 notifier(Node()).add(node);
679 UEdge addEdge(const Node& from, const Node& to) {
680 UEdge uedge = Parent::addEdge(from, to);
681 notifier(UEdge()).add(uedge);
682 std::vector<Edge> ev;
683 ev.push_back(Parent::direct(uedge, true));
684 ev.push_back(Parent::direct(uedge, false));
685 notifier(Edge()).add(ev);
690 notifier(Edge()).clear();
691 notifier(UEdge()).clear();
692 notifier(Node()).clear();
696 template <typename Graph, typename NodeRefMap, typename UEdgeRefMap>
697 void build(const Graph& graph, NodeRefMap& nodeRef,
698 UEdgeRefMap& uEdgeRef) {
699 Parent::build(graph, nodeRef, uEdgeRef);
700 notifier(Node()).build();
701 notifier(UEdge()).build();
702 notifier(Edge()).build();
705 void erase(const Node& node) {
707 Parent::firstOut(edge, node);
708 while (edge != INVALID ) {
710 Parent::firstOut(edge, node);
713 Parent::firstIn(edge, node);
714 while (edge != INVALID ) {
716 Parent::firstIn(edge, node);
719 notifier(Node()).erase(node);
723 void erase(const UEdge& uedge) {
724 std::vector<Edge> ev;
725 ev.push_back(Parent::direct(uedge, true));
726 ev.push_back(Parent::direct(uedge, false));
727 notifier(Edge()).erase(ev);
728 notifier(UEdge()).erase(uedge);
729 Parent::erase(uedge);
733 node_notifier.setContainer(*this);
734 edge_notifier.setContainer(*this);
735 uedge_notifier.setContainer(*this);
739 uedge_notifier.clear();
740 edge_notifier.clear();
741 node_notifier.clear();
746 /// \ingroup graphbits
748 /// \brief Extender for the BpUGraphs
749 template <typename Base>
750 class BpUGraphExtender : public Base {
754 typedef BpUGraphExtender Graph;
756 typedef typename Parent::Node Node;
757 typedef typename Parent::ANode ANode;
758 typedef typename Parent::BNode BNode;
759 typedef typename Parent::Edge Edge;
760 typedef typename Parent::UEdge UEdge;
763 Node oppositeNode(const Node& node, const UEdge& edge) const {
764 return Parent::aNode(edge) == node ?
765 Parent::bNode(edge) : Parent::aNode(edge);
768 using Parent::direct;
769 Edge direct(const UEdge& edge, const Node& node) const {
770 return Parent::direct(edge, node == Parent::source(edge));
773 Edge oppositeEdge(const Edge& edge) const {
774 return direct(edge, !Parent::direction(edge));
777 int maxId(Node) const {
778 return Parent::maxNodeId();
780 int maxId(BNode) const {
781 return Parent::maxBNodeId();
783 int maxId(ANode) const {
784 return Parent::maxANodeId();
786 int maxId(Edge) const {
787 return Parent::maxEdgeId();
789 int maxId(UEdge) const {
790 return Parent::maxUEdgeId();
794 Node fromId(int id, Node) const {
795 return Parent::nodeFromId(id);
797 ANode fromId(int id, ANode) const {
798 return Parent::nodeFromANodeId(id);
800 BNode fromId(int id, BNode) const {
801 return Parent::nodeFromBNodeId(id);
803 Edge fromId(int id, Edge) const {
804 return Parent::edgeFromId(id);
806 UEdge fromId(int id, UEdge) const {
807 return Parent::uEdgeFromId(id);
810 typedef AlterationNotifier<BpUGraphExtender, ANode> ANodeNotifier;
811 typedef AlterationNotifier<BpUGraphExtender, BNode> BNodeNotifier;
812 typedef AlterationNotifier<BpUGraphExtender, Node> NodeNotifier;
813 typedef AlterationNotifier<BpUGraphExtender, Edge> EdgeNotifier;
814 typedef AlterationNotifier<BpUGraphExtender, UEdge> UEdgeNotifier;
818 mutable ANodeNotifier anode_notifier;
819 mutable BNodeNotifier bnode_notifier;
820 mutable NodeNotifier node_notifier;
821 mutable EdgeNotifier edge_notifier;
822 mutable UEdgeNotifier uedge_notifier;
826 NodeNotifier& notifier(Node) const {
827 return node_notifier;
830 ANodeNotifier& notifier(ANode) const {
831 return anode_notifier;
834 BNodeNotifier& notifier(BNode) const {
835 return bnode_notifier;
838 EdgeNotifier& notifier(Edge) const {
839 return edge_notifier;
842 UEdgeNotifier& notifier(UEdge) const {
843 return uedge_notifier;
846 class NodeIt : public Node {
852 NodeIt(Invalid i) : Node(INVALID) { }
854 explicit NodeIt(const Graph& _graph) : graph(&_graph) {
855 graph->first(static_cast<Node&>(*this));
858 NodeIt(const Graph& _graph, const Node& node)
859 : Node(node), graph(&_graph) { }
861 NodeIt& operator++() {
868 class ANodeIt : public Node {
869 friend class BpUGraphExtender;
875 ANodeIt(Invalid i) : Node(INVALID) { }
877 explicit ANodeIt(const Graph& _graph) : graph(&_graph) {
878 graph->firstANode(static_cast<Node&>(*this));
881 ANodeIt(const Graph& _graph, const Node& node)
882 : Node(node), graph(&_graph) {}
884 ANodeIt& operator++() {
885 graph->nextANode(*this);
890 class BNodeIt : public Node {
891 friend class BpUGraphExtender;
897 BNodeIt(Invalid i) : Node(INVALID) { }
899 explicit BNodeIt(const Graph& _graph) : graph(&_graph) {
900 graph->firstBNode(static_cast<Node&>(*this));
903 BNodeIt(const Graph& _graph, const Node& node)
904 : Node(node), graph(&_graph) {}
906 BNodeIt& operator++() {
907 graph->nextBNode(*this);
912 class EdgeIt : public Edge {
913 friend class BpUGraphExtender;
919 EdgeIt(Invalid i) : Edge(INVALID) { }
921 explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
922 graph->first(static_cast<Edge&>(*this));
925 EdgeIt(const Graph& _graph, const Edge& edge)
926 : Edge(edge), graph(&_graph) { }
928 EdgeIt& operator++() {
935 class UEdgeIt : public UEdge {
936 friend class BpUGraphExtender;
942 UEdgeIt(Invalid i) : UEdge(INVALID) { }
944 explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
945 graph->first(static_cast<UEdge&>(*this));
948 UEdgeIt(const Graph& _graph, const UEdge& edge)
949 : UEdge(edge), graph(&_graph) { }
951 UEdgeIt& operator++() {
957 class OutEdgeIt : public Edge {
958 friend class BpUGraphExtender;
964 OutEdgeIt(Invalid i) : Edge(i) { }
966 OutEdgeIt(const Graph& _graph, const Node& node)
968 graph->firstOut(*this, node);
971 OutEdgeIt(const Graph& _graph, const Edge& edge)
972 : Edge(edge), graph(&_graph) {}
974 OutEdgeIt& operator++() {
975 graph->nextOut(*this);
982 class InEdgeIt : public Edge {
983 friend class BpUGraphExtender;
989 InEdgeIt(Invalid i) : Edge(i) { }
991 InEdgeIt(const Graph& _graph, const Node& node)
993 graph->firstIn(*this, node);
996 InEdgeIt(const Graph& _graph, const Edge& edge) :
997 Edge(edge), graph(&_graph) {}
999 InEdgeIt& operator++() {
1000 graph->nextIn(*this);
1006 /// \brief Base node of the iterator
1008 /// Returns the base node (ie. the source in this case) of the iterator
1009 Node baseNode(const OutEdgeIt &e) const {
1010 return Parent::source(static_cast<const Edge&>(e));
1012 /// \brief Running node of the iterator
1014 /// Returns the running node (ie. the target in this case) of the
1016 Node runningNode(const OutEdgeIt &e) const {
1017 return Parent::target(static_cast<const Edge&>(e));
1020 /// \brief Base node of the iterator
1022 /// Returns the base node (ie. the target in this case) of the iterator
1023 Node baseNode(const InEdgeIt &e) const {
1024 return Parent::target(static_cast<const Edge&>(e));
1026 /// \brief Running node of the iterator
1028 /// Returns the running node (ie. the source in this case) of the
1030 Node runningNode(const InEdgeIt &e) const {
1031 return Parent::source(static_cast<const Edge&>(e));
1034 class IncEdgeIt : public Parent::UEdge {
1035 friend class BpUGraphExtender;
1042 IncEdgeIt(Invalid i) : UEdge(i), direction(true) { }
1044 IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
1045 graph->firstInc(*this, direction, n);
1048 IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
1049 : graph(&_graph), UEdge(ue) {
1050 direction = (graph->source(ue) == n);
1053 IncEdgeIt& operator++() {
1054 graph->nextInc(*this, direction);
1060 /// Base node of the iterator
1062 /// Returns the base node of the iterator
1063 Node baseNode(const IncEdgeIt &e) const {
1064 return e.direction ? source(e) : target(e);
1067 /// Running node of the iterator
1069 /// Returns the running node of the iterator
1070 Node runningNode(const IncEdgeIt &e) const {
1071 return e.direction ? target(e) : source(e);
1074 template <typename _Value>
1076 : public MapExtender<DefaultMap<Graph, ANode, _Value> > {
1078 typedef BpUGraphExtender Graph;
1079 typedef MapExtender<DefaultMap<Graph, ANode, _Value> > Parent;
1081 ANodeMap(const Graph& graph)
1083 ANodeMap(const Graph& graph, const _Value& value)
1084 : Parent(graph, value) {}
1086 ANodeMap& operator=(const ANodeMap& cmap) {
1087 return operator=<ANodeMap>(cmap);
1090 template <typename CMap>
1091 ANodeMap& operator=(const CMap& cmap) {
1092 Parent::operator=(cmap);
1098 template <typename _Value>
1100 : public MapExtender<DefaultMap<Graph, BNode, _Value> > {
1102 typedef BpUGraphExtender Graph;
1103 typedef MapExtender<DefaultMap<Graph, BNode, _Value> > Parent;
1105 BNodeMap(const Graph& graph)
1107 BNodeMap(const Graph& graph, const _Value& value)
1108 : Parent(graph, value) {}
1110 BNodeMap& operator=(const BNodeMap& cmap) {
1111 return operator=<BNodeMap>(cmap);
1114 template <typename CMap>
1115 BNodeMap& operator=(const CMap& cmap) {
1116 Parent::operator=(cmap);
1124 template <typename _Value>
1127 typedef BpUGraphExtender Graph;
1130 typedef _Value Value;
1132 /// The reference type of the map;
1133 typedef typename ANodeMap<_Value>::Reference Reference;
1134 /// The const reference type of the map;
1135 typedef typename ANodeMap<_Value>::ConstReference ConstReference;
1137 typedef True ReferenceMapTag;
1139 NodeMap(const Graph& _graph)
1140 : graph(_graph), aNodeMap(_graph), bNodeMap(_graph) {}
1141 NodeMap(const Graph& _graph, const _Value& _value)
1142 : graph(_graph), aNodeMap(_graph, _value), bNodeMap(_graph, _value) {}
1144 NodeMap& operator=(const NodeMap& cmap) {
1145 return operator=<NodeMap>(cmap);
1148 template <typename CMap>
1149 NodeMap& operator=(const CMap& cmap) {
1150 checkConcept<concepts::ReadMap<Node, _Value>, CMap>();
1156 ConstReference operator[](const Key& node) const {
1157 if (Parent::aNode(node)) {
1158 return aNodeMap[node];
1160 return bNodeMap[node];
1164 Reference operator[](const Key& node) {
1165 if (Parent::aNode(node)) {
1166 return aNodeMap[node];
1168 return bNodeMap[node];
1172 void set(const Key& node, const Value& value) {
1173 if (Parent::aNode(node)) {
1174 aNodeMap.set(node, value);
1176 bNodeMap.set(node, value);
1180 class MapIt : public NodeIt {
1183 typedef NodeIt Parent;
1185 explicit MapIt(NodeMap& _map)
1186 : Parent(_map.graph), map(_map) {}
1188 typename MapTraits<NodeMap>::ConstReturnValue operator*() const {
1192 typename MapTraits<NodeMap>::ReturnValue operator*() {
1196 void set(const Value& value) {
1197 map.set(*this, value);
1204 class ConstMapIt : public NodeIt {
1207 typedef NodeIt Parent;
1209 explicit ConstMapIt(const NodeMap& _map)
1210 : Parent(_map.graph), map(_map) {}
1212 typename MapTraits<NodeMap>::ConstReturnValue operator*() const {
1220 class ItemIt : public NodeIt {
1223 typedef NodeIt Parent;
1225 explicit ItemIt(const NodeMap& _map)
1226 : Parent(_map.graph) {}
1232 ANodeMap<_Value> aNodeMap;
1233 BNodeMap<_Value> bNodeMap;
1237 template <typename _Value>
1239 : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
1241 typedef BpUGraphExtender Graph;
1242 typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
1244 EdgeMap(const Graph& graph)
1246 EdgeMap(const Graph& graph, const _Value& value)
1247 : Parent(graph, value) {}
1249 EdgeMap& operator=(const EdgeMap& cmap) {
1250 return operator=<EdgeMap>(cmap);
1253 template <typename CMap>
1254 EdgeMap& operator=(const CMap& cmap) {
1255 Parent::operator=(cmap);
1260 template <typename _Value>
1262 : public MapExtender<DefaultMap<Graph, UEdge, _Value> > {
1264 typedef BpUGraphExtender Graph;
1265 typedef MapExtender<DefaultMap<Graph, UEdge, _Value> > Parent;
1267 UEdgeMap(const Graph& graph)
1269 UEdgeMap(const Graph& graph, const _Value& value)
1270 : Parent(graph, value) {}
1272 UEdgeMap& operator=(const UEdgeMap& cmap) {
1273 return operator=<UEdgeMap>(cmap);
1276 template <typename CMap>
1277 UEdgeMap& operator=(const CMap& cmap) {
1278 Parent::operator=(cmap);
1285 Node node = Parent::addANode();
1286 notifier(ANode()).add(node);
1287 notifier(Node()).add(node);
1292 Node node = Parent::addBNode();
1293 notifier(BNode()).add(node);
1294 notifier(Node()).add(node);
1298 UEdge addEdge(const Node& s, const Node& t) {
1299 UEdge uedge = Parent::addEdge(s, t);
1300 notifier(UEdge()).add(uedge);
1302 std::vector<Edge> ev;
1303 ev.push_back(Parent::direct(uedge, true));
1304 ev.push_back(Parent::direct(uedge, false));
1305 notifier(Edge()).add(ev);
1311 notifier(Edge()).clear();
1312 notifier(UEdge()).clear();
1313 notifier(Node()).clear();
1314 notifier(BNode()).clear();
1315 notifier(ANode()).clear();
1319 template <typename Graph, typename ANodeRefMap,
1320 typename BNodeRefMap, typename UEdgeRefMap>
1321 void build(const Graph& graph, ANodeRefMap& aNodeRef,
1322 BNodeRefMap& bNodeRef, UEdgeRefMap& uEdgeRef) {
1323 Parent::build(graph, aNodeRef, bNodeRef, uEdgeRef);
1324 notifier(ANode()).build();
1325 notifier(BNode()).build();
1326 notifier(Node()).build();
1327 notifier(UEdge()).build();
1328 notifier(Edge()).build();
1331 void erase(const Node& node) {
1333 if (Parent::aNode(node)) {
1334 Parent::firstFromANode(uedge, node);
1335 while (uedge != INVALID) {
1337 Parent::firstFromANode(uedge, node);
1339 notifier(ANode()).erase(node);
1341 Parent::firstFromBNode(uedge, node);
1342 while (uedge != INVALID) {
1344 Parent::firstFromBNode(uedge, node);
1346 notifier(BNode()).erase(node);
1349 notifier(Node()).erase(node);
1350 Parent::erase(node);
1353 void erase(const UEdge& uedge) {
1354 std::vector<Edge> ev;
1355 ev.push_back(Parent::direct(uedge, true));
1356 ev.push_back(Parent::direct(uedge, false));
1357 notifier(Edge()).erase(ev);
1358 notifier(UEdge()).erase(uedge);
1359 Parent::erase(uedge);
1363 BpUGraphExtender() {
1364 anode_notifier.setContainer(*this);
1365 bnode_notifier.setContainer(*this);
1366 node_notifier.setContainer(*this);
1367 edge_notifier.setContainer(*this);
1368 uedge_notifier.setContainer(*this);
1371 ~BpUGraphExtender() {
1372 uedge_notifier.clear();
1373 edge_notifier.clear();
1374 node_notifier.clear();
1375 anode_notifier.clear();
1376 bnode_notifier.clear();
1379 Edge findEdge(Node u, Node v, Edge prev = INVALID) const {
1380 UEdge uedge = Parent::findUEdge(u, v, prev);
1381 if (uedge != INVALID) {
1382 return Parent::direct(uedge, Parent::aNode(u));