Graph imlementations actually provide ReferenceMaps.
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 (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 getNotifier(Node()).add(node);
273 Edge addEdge(const Node& from, const Node& to) {
274 Edge edge = Parent::addEdge(from, to);
275 getNotifier(Edge()).add(edge);
280 getNotifier(Edge()).clear();
281 getNotifier(Node()).clear();
286 void erase(const Node& node) {
288 Parent::firstOut(edge, node);
289 while (edge != INVALID ) {
291 Parent::firstOut(edge, node);
294 Parent::firstIn(edge, node);
295 while (edge != INVALID ) {
297 Parent::firstIn(edge, node);
300 getNotifier(Node()).erase(node);
304 void erase(const Edge& edge) {
305 getNotifier(Edge()).erase(edge);
310 node_notifier.setContainer(*this);
311 edge_notifier.setContainer(*this);
316 edge_notifier.clear();
317 node_notifier.clear();
321 /// \ingroup graphbits
323 /// \brief Extender for the UGraphs
324 template <typename Base>
325 class UGraphExtender : public Base {
329 typedef UGraphExtender Graph;
331 typedef typename Parent::Node Node;
332 typedef typename Parent::Edge Edge;
333 typedef typename Parent::UEdge UEdge;
337 int maxId(Node) const {
338 return Parent::maxNodeId();
341 int maxId(Edge) const {
342 return Parent::maxEdgeId();
345 int maxId(UEdge) const {
346 return Parent::maxUEdgeId();
349 Node fromId(int id, Node) const {
350 return Parent::nodeFromId(id);
353 Edge fromId(int id, Edge) const {
354 return Parent::edgeFromId(id);
357 UEdge fromId(int id, UEdge) const {
358 return Parent::uEdgeFromId(id);
361 Node oppositeNode(const Node &n, const UEdge &e) const {
362 if( n == Parent::source(e))
363 return Parent::target(e);
364 else if( n == Parent::target(e))
365 return Parent::source(e);
370 Edge oppositeEdge(const Edge &e) const {
371 return Parent::direct(e, !Parent::direction(e));
374 using Parent::direct;
375 Edge direct(const UEdge &ue, const Node &s) const {
376 return Parent::direct(ue, Parent::source(ue) == s);
379 // Alterable extension
381 typedef AlterationNotifier<UGraphExtender, Node> NodeNotifier;
382 typedef AlterationNotifier<UGraphExtender, Edge> EdgeNotifier;
383 typedef AlterationNotifier<UGraphExtender, UEdge> UEdgeNotifier;
388 mutable NodeNotifier node_notifier;
389 mutable EdgeNotifier edge_notifier;
390 mutable UEdgeNotifier uedge_notifier;
394 NodeNotifier& getNotifier(Node) const {
395 return node_notifier;
398 EdgeNotifier& getNotifier(Edge) const {
399 return edge_notifier;
402 UEdgeNotifier& getNotifier(UEdge) const {
403 return uedge_notifier;
408 class NodeIt : public Node {
414 NodeIt(Invalid i) : Node(i) { }
416 explicit NodeIt(const Graph& _graph) : graph(&_graph) {
417 _graph.first(static_cast<Node&>(*this));
420 NodeIt(const Graph& _graph, const Node& node)
421 : Node(node), graph(&_graph) {}
423 NodeIt& operator++() {
431 class EdgeIt : public Edge {
437 EdgeIt(Invalid i) : Edge(i) { }
439 explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
440 _graph.first(static_cast<Edge&>(*this));
443 EdgeIt(const Graph& _graph, const Edge& e) :
444 Edge(e), graph(&_graph) { }
446 EdgeIt& operator++() {
454 class OutEdgeIt : public Edge {
460 OutEdgeIt(Invalid i) : Edge(i) { }
462 OutEdgeIt(const Graph& _graph, const Node& node)
464 _graph.firstOut(*this, node);
467 OutEdgeIt(const Graph& _graph, const Edge& edge)
468 : Edge(edge), graph(&_graph) {}
470 OutEdgeIt& operator++() {
471 graph->nextOut(*this);
478 class InEdgeIt : public Edge {
484 InEdgeIt(Invalid i) : Edge(i) { }
486 InEdgeIt(const Graph& _graph, const Node& node)
488 _graph.firstIn(*this, node);
491 InEdgeIt(const Graph& _graph, const Edge& edge) :
492 Edge(edge), graph(&_graph) {}
494 InEdgeIt& operator++() {
495 graph->nextIn(*this);
502 class UEdgeIt : public Parent::UEdge {
508 UEdgeIt(Invalid i) : UEdge(i) { }
510 explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
511 _graph.first(static_cast<UEdge&>(*this));
514 UEdgeIt(const Graph& _graph, const UEdge& e) :
515 UEdge(e), graph(&_graph) { }
517 UEdgeIt& operator++() {
524 class IncEdgeIt : public Parent::UEdge {
525 friend class UGraphExtender;
532 IncEdgeIt(Invalid i) : UEdge(i), direction(false) { }
534 IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
535 _graph.firstInc(*this, direction, n);
538 IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
539 : graph(&_graph), UEdge(ue) {
540 direction = (_graph.source(ue) == n);
543 IncEdgeIt& operator++() {
544 graph->nextInc(*this, direction);
549 /// \brief Base node of the iterator
551 /// Returns the base node (ie. the source in this case) of the iterator
552 Node baseNode(const OutEdgeIt &e) const {
553 return Parent::source((Edge)e);
555 /// \brief Running node of the iterator
557 /// Returns the running node (ie. the target in this case) of the
559 Node runningNode(const OutEdgeIt &e) const {
560 return Parent::target((Edge)e);
563 /// \brief Base node of the iterator
565 /// Returns the base node (ie. the target in this case) of the iterator
566 Node baseNode(const InEdgeIt &e) const {
567 return Parent::target((Edge)e);
569 /// \brief Running node of the iterator
571 /// Returns the running node (ie. the source in this case) of the
573 Node runningNode(const InEdgeIt &e) const {
574 return Parent::source((Edge)e);
577 /// Base node of the iterator
579 /// Returns the base node of the iterator
580 Node baseNode(const IncEdgeIt &e) const {
581 return e.direction ? source(e) : target(e);
583 /// Running node of the iterator
585 /// Returns the running node of the iterator
586 Node runningNode(const IncEdgeIt &e) const {
587 return e.direction ? target(e) : source(e);
590 // Mappable extension
592 template <typename _Value>
594 : public MapExtender<DefaultMap<Graph, Node, _Value> > {
596 typedef UGraphExtender Graph;
597 typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent;
599 NodeMap(const Graph& graph)
601 NodeMap(const Graph& graph, const _Value& value)
602 : Parent(graph, value) {}
604 NodeMap& operator=(const NodeMap& cmap) {
605 return operator=<NodeMap>(cmap);
608 template <typename CMap>
609 NodeMap& operator=(const CMap& cmap) {
610 Parent::operator=(cmap);
616 template <typename _Value>
618 : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
620 typedef UGraphExtender Graph;
621 typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
623 EdgeMap(const Graph& graph)
625 EdgeMap(const Graph& graph, const _Value& value)
626 : Parent(graph, value) {}
628 EdgeMap& operator=(const EdgeMap& cmap) {
629 return operator=<EdgeMap>(cmap);
632 template <typename CMap>
633 EdgeMap& operator=(const CMap& cmap) {
634 Parent::operator=(cmap);
640 template <typename _Value>
642 : public MapExtender<DefaultMap<Graph, UEdge, _Value> > {
644 typedef UGraphExtender Graph;
645 typedef MapExtender<DefaultMap<Graph, UEdge, _Value> > Parent;
647 UEdgeMap(const Graph& graph)
650 UEdgeMap(const Graph& graph, const _Value& value)
651 : Parent(graph, value) {}
653 UEdgeMap& operator=(const UEdgeMap& cmap) {
654 return operator=<UEdgeMap>(cmap);
657 template <typename CMap>
658 UEdgeMap& operator=(const CMap& cmap) {
659 Parent::operator=(cmap);
665 // Alteration extension
668 Node node = Parent::addNode();
669 getNotifier(Node()).add(node);
673 UEdge addEdge(const Node& from, const Node& to) {
674 UEdge uedge = Parent::addEdge(from, to);
675 getNotifier(UEdge()).add(uedge);
676 getNotifier(Edge()).add(Parent::direct(uedge, true));
677 getNotifier(Edge()).add(Parent::direct(uedge, false));
682 getNotifier(Edge()).clear();
683 getNotifier(UEdge()).clear();
684 getNotifier(Node()).clear();
688 void erase(const Node& node) {
690 Parent::firstOut(edge, node);
691 while (edge != INVALID ) {
693 Parent::firstOut(edge, node);
696 Parent::firstIn(edge, node);
697 while (edge != INVALID ) {
699 Parent::firstIn(edge, node);
702 getNotifier(Node()).erase(node);
706 void erase(const UEdge& uedge) {
707 getNotifier(Edge()).erase(Parent::direct(uedge, true));
708 getNotifier(Edge()).erase(Parent::direct(uedge, false));
709 getNotifier(UEdge()).erase(uedge);
710 Parent::erase(uedge);
714 node_notifier.setContainer(*this);
715 edge_notifier.setContainer(*this);
716 uedge_notifier.setContainer(*this);
720 uedge_notifier.clear();
721 edge_notifier.clear();
722 node_notifier.clear();
727 /// \ingroup graphbits
729 /// \brief Extender for the BpUGraphs
730 template <typename Base>
731 class BpUGraphExtender : public Base {
735 typedef BpUGraphExtender Graph;
737 typedef typename Parent::Node Node;
738 typedef typename Parent::ANode ANode;
739 typedef typename Parent::BNode BNode;
740 typedef typename Parent::Edge Edge;
741 typedef typename Parent::UEdge UEdge;
744 Node oppositeNode(const Node& node, const UEdge& edge) const {
745 return Parent::aNode(edge) == node ?
746 Parent::bNode(edge) : Parent::aNode(edge);
749 using Parent::direct;
750 Edge direct(const UEdge& edge, const Node& node) const {
751 return Parent::direct(edge, node == Parent::source(edge));
754 Edge oppositeEdge(const Edge& edge) const {
755 return direct(edge, !Parent::direction(edge));
758 int maxId(Node) const {
759 return Parent::maxNodeId();
761 int maxId(BNode) const {
762 return Parent::maxBNodeId();
764 int maxId(ANode) const {
765 return Parent::maxANodeId();
767 int maxId(Edge) const {
768 return Parent::maxEdgeId();
770 int maxId(UEdge) const {
771 return Parent::maxUEdgeId();
775 Node fromId(int id, Node) const {
776 return Parent::nodeFromId(id);
778 ANode fromId(int id, ANode) const {
779 return Parent::nodeFromANodeId(id);
781 BNode fromId(int id, BNode) const {
782 return Parent::nodeFromBNodeId(id);
784 Edge fromId(int id, Edge) const {
785 return Parent::edgeFromId(id);
787 UEdge fromId(int id, UEdge) const {
788 return Parent::uEdgeFromId(id);
791 typedef AlterationNotifier<BpUGraphExtender, ANode> ANodeNotifier;
792 typedef AlterationNotifier<BpUGraphExtender, BNode> BNodeNotifier;
793 typedef AlterationNotifier<BpUGraphExtender, Node> NodeNotifier;
794 typedef AlterationNotifier<BpUGraphExtender, Edge> EdgeNotifier;
795 typedef AlterationNotifier<BpUGraphExtender, UEdge> UEdgeNotifier;
799 mutable ANodeNotifier anode_notifier;
800 mutable BNodeNotifier bnode_notifier;
801 mutable NodeNotifier node_notifier;
802 mutable EdgeNotifier edge_notifier;
803 mutable UEdgeNotifier uedge_notifier;
807 NodeNotifier& getNotifier(Node) const {
808 return node_notifier;
811 ANodeNotifier& getNotifier(ANode) const {
812 return anode_notifier;
815 BNodeNotifier& getNotifier(BNode) const {
816 return bnode_notifier;
819 EdgeNotifier& getNotifier(Edge) const {
820 return edge_notifier;
823 UEdgeNotifier& getNotifier(UEdge) const {
824 return uedge_notifier;
827 class NodeIt : public Node {
833 NodeIt(Invalid i) : Node(INVALID) { }
835 explicit NodeIt(const Graph& _graph) : graph(&_graph) {
836 graph->first(static_cast<Node&>(*this));
839 NodeIt(const Graph& _graph, const Node& node)
840 : Node(node), graph(&_graph) { }
842 NodeIt& operator++() {
849 class ANodeIt : public Node {
850 friend class BpUGraphExtender;
856 ANodeIt(Invalid i) : Node(INVALID) { }
858 explicit ANodeIt(const Graph& _graph) : graph(&_graph) {
859 graph->firstANode(static_cast<Node&>(*this));
862 ANodeIt(const Graph& _graph, const Node& node)
863 : Node(node), graph(&_graph) {}
865 ANodeIt& operator++() {
866 graph->nextANode(*this);
871 class BNodeIt : public Node {
872 friend class BpUGraphExtender;
878 BNodeIt(Invalid i) : Node(INVALID) { }
880 explicit BNodeIt(const Graph& _graph) : graph(&_graph) {
881 graph->firstBNode(static_cast<Node&>(*this));
884 BNodeIt(const Graph& _graph, const Node& node)
885 : Node(node), graph(&_graph) {}
887 BNodeIt& operator++() {
888 graph->nextBNode(*this);
893 class EdgeIt : public Edge {
894 friend class BpUGraphExtender;
900 EdgeIt(Invalid i) : Edge(INVALID) { }
902 explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
903 graph->first(static_cast<Edge&>(*this));
906 EdgeIt(const Graph& _graph, const Edge& edge)
907 : Edge(edge), graph(&_graph) { }
909 EdgeIt& operator++() {
916 class UEdgeIt : public UEdge {
917 friend class BpUGraphExtender;
923 UEdgeIt(Invalid i) : UEdge(INVALID) { }
925 explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
926 graph->first(static_cast<UEdge&>(*this));
929 UEdgeIt(const Graph& _graph, const UEdge& edge)
930 : UEdge(edge), graph(&_graph) { }
932 UEdgeIt& operator++() {
938 class OutEdgeIt : public Edge {
939 friend class BpUGraphExtender;
945 OutEdgeIt(Invalid i) : Edge(i) { }
947 OutEdgeIt(const Graph& _graph, const Node& node)
949 graph->firstOut(*this, node);
952 OutEdgeIt(const Graph& _graph, const Edge& edge)
953 : Edge(edge), graph(&_graph) {}
955 OutEdgeIt& operator++() {
956 graph->nextOut(*this);
963 class InEdgeIt : public Edge {
964 friend class BpUGraphExtender;
970 InEdgeIt(Invalid i) : Edge(i) { }
972 InEdgeIt(const Graph& _graph, const Node& node)
974 graph->firstIn(*this, node);
977 InEdgeIt(const Graph& _graph, const Edge& edge) :
978 Edge(edge), graph(&_graph) {}
980 InEdgeIt& operator++() {
981 graph->nextIn(*this);
987 /// \brief Base node of the iterator
989 /// Returns the base node (ie. the source in this case) of the iterator
990 Node baseNode(const OutEdgeIt &e) const {
991 return Parent::source((Edge&)e);
993 /// \brief Running node of the iterator
995 /// Returns the running node (ie. the target in this case) of the
997 Node runningNode(const OutEdgeIt &e) const {
998 return Parent::target((Edge&)e);
1001 /// \brief Base node of the iterator
1003 /// Returns the base node (ie. the target in this case) of the iterator
1004 Node baseNode(const InEdgeIt &e) const {
1005 return Parent::target((Edge&)e);
1007 /// \brief Running node of the iterator
1009 /// Returns the running node (ie. the source in this case) of the
1011 Node runningNode(const InEdgeIt &e) const {
1012 return Parent::source((Edge&)e);
1015 class IncEdgeIt : public Parent::UEdge {
1016 friend class BpUGraphExtender;
1023 IncEdgeIt(Invalid i) : UEdge(i), direction(true) { }
1025 IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
1026 graph->firstInc(*this, direction, n);
1029 IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
1030 : graph(&_graph), UEdge(ue) {
1031 direction = (graph->source(ue) == n);
1034 IncEdgeIt& operator++() {
1035 graph->nextInc(*this, direction);
1041 /// Base node of the iterator
1043 /// Returns the base node of the iterator
1044 Node baseNode(const IncEdgeIt &e) const {
1045 return e.direction ? source(e) : target(e);
1048 /// Running node of the iterator
1050 /// Returns the running node of the iterator
1051 Node runningNode(const IncEdgeIt &e) const {
1052 return e.direction ? target(e) : source(e);
1055 template <typename _Value>
1057 : public MapExtender<DefaultMap<Graph, ANode, _Value> > {
1059 typedef BpUGraphExtender Graph;
1060 typedef MapExtender<DefaultMap<Graph, ANode, _Value> > Parent;
1062 ANodeMap(const Graph& graph)
1064 ANodeMap(const Graph& graph, const _Value& value)
1065 : Parent(graph, value) {}
1067 ANodeMap& operator=(const ANodeMap& cmap) {
1068 return operator=<ANodeMap>(cmap);
1071 template <typename CMap>
1072 ANodeMap& operator=(const CMap& cmap) {
1073 Parent::operator=(cmap);
1079 template <typename _Value>
1081 : public MapExtender<DefaultMap<Graph, BNode, _Value> > {
1083 typedef BpUGraphExtender Graph;
1084 typedef MapExtender<DefaultMap<Graph, BNode, _Value> > Parent;
1086 BNodeMap(const Graph& graph)
1088 BNodeMap(const Graph& graph, const _Value& value)
1089 : Parent(graph, value) {}
1091 BNodeMap& operator=(const BNodeMap& cmap) {
1092 return operator=<BNodeMap>(cmap);
1095 template <typename CMap>
1096 BNodeMap& operator=(const CMap& cmap) {
1097 Parent::operator=(cmap);
1105 template <typename _Value>
1108 typedef BpUGraphExtender Graph;
1111 typedef _Value Value;
1113 /// The reference type of the map;
1114 typedef typename ANodeMap<_Value>::Reference Reference;
1115 /// The const reference type of the map;
1116 typedef typename ANodeMap<_Value>::ConstReference ConstReference;
1118 typedef True ReferenceMapTag;
1120 NodeMap(const Graph& _graph)
1121 : graph(_graph), aNodeMap(_graph), bNodeMap(_graph) {}
1122 NodeMap(const Graph& _graph, const _Value& _value)
1123 : graph(_graph), aNodeMap(_graph, _value), bNodeMap(_graph, _value) {}
1125 NodeMap& operator=(const NodeMap& cmap) {
1126 return operator=<NodeMap>(cmap);
1129 template <typename CMap>
1130 NodeMap& operator=(const CMap& cmap) {
1131 checkConcept<concept::ReadMap<Node, _Value>, CMap>();
1137 ConstReference operator[](const Key& node) const {
1138 if (Parent::aNode(node)) {
1139 return aNodeMap[node];
1141 return bNodeMap[node];
1145 Reference operator[](const Key& node) {
1146 if (Parent::aNode(node)) {
1147 return aNodeMap[node];
1149 return bNodeMap[node];
1153 void set(const Key& node, const Value& value) {
1154 if (Parent::aNode(node)) {
1155 aNodeMap.set(node, value);
1157 bNodeMap.set(node, value);
1161 class MapIt : public NodeIt {
1164 typedef NodeIt Parent;
1166 explicit MapIt(NodeMap& _map)
1167 : Parent(_map.graph), map(_map) {}
1169 typename MapTraits<NodeMap>::ConstReturnValue operator*() const {
1173 typename MapTraits<NodeMap>::ReturnValue operator*() {
1177 void set(const Value& value) {
1178 map.set(*this, value);
1185 class ConstMapIt : public NodeIt {
1188 typedef NodeIt Parent;
1190 explicit ConstMapIt(const NodeMap& _map)
1191 : Parent(_map.graph), map(_map) {}
1193 typename MapTraits<NodeMap>::ConstReturnValue operator*() const {
1201 class ItemIt : public NodeIt {
1204 typedef NodeIt Parent;
1206 explicit ItemIt(const NodeMap& _map)
1207 : Parent(_map.graph) {}
1213 ANodeMap<_Value> aNodeMap;
1214 BNodeMap<_Value> bNodeMap;
1218 template <typename _Value>
1220 : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
1222 typedef BpUGraphExtender Graph;
1223 typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
1225 EdgeMap(const Graph& graph)
1227 EdgeMap(const Graph& graph, const _Value& value)
1228 : Parent(graph, value) {}
1230 EdgeMap& operator=(const EdgeMap& cmap) {
1231 return operator=<EdgeMap>(cmap);
1234 template <typename CMap>
1235 EdgeMap& operator=(const CMap& cmap) {
1236 Parent::operator=(cmap);
1241 template <typename _Value>
1243 : public MapExtender<DefaultMap<Graph, UEdge, _Value> > {
1245 typedef BpUGraphExtender Graph;
1246 typedef MapExtender<DefaultMap<Graph, UEdge, _Value> > Parent;
1248 UEdgeMap(const Graph& graph)
1250 UEdgeMap(const Graph& graph, const _Value& value)
1251 : Parent(graph, value) {}
1253 UEdgeMap& operator=(const UEdgeMap& cmap) {
1254 return operator=<UEdgeMap>(cmap);
1257 template <typename CMap>
1258 UEdgeMap& operator=(const CMap& cmap) {
1259 Parent::operator=(cmap);
1266 Node node = Parent::addANode();
1267 getNotifier(ANode()).add(node);
1268 getNotifier(Node()).add(node);
1273 Node node = Parent::addBNode();
1274 getNotifier(BNode()).add(node);
1275 getNotifier(Node()).add(node);
1279 UEdge addEdge(const Node& source, const Node& target) {
1280 UEdge uedge = Parent::addEdge(source, target);
1281 getNotifier(UEdge()).add(uedge);
1283 std::vector<Edge> edges;
1284 edges.push_back(Parent::direct(uedge, true));
1285 edges.push_back(Parent::direct(uedge, false));
1286 getNotifier(Edge()).add(edges);
1292 getNotifier(Edge()).clear();
1293 getNotifier(UEdge()).clear();
1294 getNotifier(Node()).clear();
1295 getNotifier(BNode()).clear();
1296 getNotifier(ANode()).clear();
1300 void erase(const Node& node) {
1302 if (Parent::aNode(node)) {
1303 Parent::firstFromANode(uedge, node);
1304 while (uedge != INVALID) {
1306 Parent::firstFromANode(uedge, node);
1308 getNotifier(ANode()).erase(node);
1310 Parent::firstFromBNode(uedge, node);
1311 while (uedge != INVALID) {
1313 Parent::firstFromBNode(uedge, node);
1315 getNotifier(BNode()).erase(node);
1318 getNotifier(Node()).erase(node);
1319 Parent::erase(node);
1322 void erase(const UEdge& uedge) {
1323 std::vector<Edge> edges;
1324 edges.push_back(Parent::direct(uedge, true));
1325 edges.push_back(Parent::direct(uedge, false));
1326 getNotifier(Edge()).erase(edges);
1327 getNotifier(UEdge()).erase(uedge);
1328 Parent::erase(uedge);
1332 BpUGraphExtender() {
1333 anode_notifier.setContainer(*this);
1334 bnode_notifier.setContainer(*this);
1335 node_notifier.setContainer(*this);
1336 edge_notifier.setContainer(*this);
1337 uedge_notifier.setContainer(*this);
1340 ~BpUGraphExtender() {
1341 uedge_notifier.clear();
1342 edge_notifier.clear();
1343 node_notifier.clear();
1344 anode_notifier.clear();
1345 bnode_notifier.clear();
1348 Edge findEdge(Node u, Node v, Edge prev = INVALID) const {
1349 UEdge uedge = Parent::findUEdge(u, v, prev);
1350 if (uedge != INVALID) {
1351 return Parent::direct(uedge, Parent::aNode(u));