Corrected some typos and grammatical errors.
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/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& 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 std::vector<Edge> edges;
677 edges.push_back(Parent::direct(uedge, true));
678 edges.push_back(Parent::direct(uedge, false));
679 getNotifier(Edge()).add(edges);
684 getNotifier(Edge()).clear();
685 getNotifier(UEdge()).clear();
686 getNotifier(Node()).clear();
690 void erase(const Node& node) {
692 Parent::firstOut(edge, node);
693 while (edge != INVALID ) {
695 Parent::firstOut(edge, node);
698 Parent::firstIn(edge, node);
699 while (edge != INVALID ) {
701 Parent::firstIn(edge, node);
704 getNotifier(Node()).erase(node);
708 void erase(const UEdge& uedge) {
709 std::vector<Edge> edges;
710 edges.push_back(Parent::direct(uedge, true));
711 edges.push_back(Parent::direct(uedge, false));
712 getNotifier(Edge()).erase(edges);
713 getNotifier(UEdge()).erase(uedge);
714 Parent::erase(uedge);
718 node_notifier.setContainer(*this);
719 edge_notifier.setContainer(*this);
720 uedge_notifier.setContainer(*this);
724 uedge_notifier.clear();
725 edge_notifier.clear();
726 node_notifier.clear();
731 /// \ingroup graphbits
733 /// \brief Extender for the BpUGraphs
734 template <typename Base>
735 class BpUGraphExtender : public Base {
739 typedef BpUGraphExtender Graph;
741 typedef typename Parent::Node Node;
742 typedef typename Parent::ANode ANode;
743 typedef typename Parent::BNode BNode;
744 typedef typename Parent::Edge Edge;
745 typedef typename Parent::UEdge UEdge;
748 Node oppositeNode(const Node& node, const UEdge& edge) const {
749 return Parent::aNode(edge) == node ?
750 Parent::bNode(edge) : Parent::aNode(edge);
753 using Parent::direct;
754 Edge direct(const UEdge& edge, const Node& node) const {
755 return Parent::direct(edge, node == Parent::source(edge));
758 Edge oppositeEdge(const Edge& edge) const {
759 return direct(edge, !Parent::direction(edge));
762 int maxId(Node) const {
763 return Parent::maxNodeId();
765 int maxId(BNode) const {
766 return Parent::maxBNodeId();
768 int maxId(ANode) const {
769 return Parent::maxANodeId();
771 int maxId(Edge) const {
772 return Parent::maxEdgeId();
774 int maxId(UEdge) const {
775 return Parent::maxUEdgeId();
779 Node fromId(int id, Node) const {
780 return Parent::nodeFromId(id);
782 ANode fromId(int id, ANode) const {
783 return Parent::nodeFromANodeId(id);
785 BNode fromId(int id, BNode) const {
786 return Parent::nodeFromBNodeId(id);
788 Edge fromId(int id, Edge) const {
789 return Parent::edgeFromId(id);
791 UEdge fromId(int id, UEdge) const {
792 return Parent::uEdgeFromId(id);
795 typedef AlterationNotifier<BpUGraphExtender, ANode> ANodeNotifier;
796 typedef AlterationNotifier<BpUGraphExtender, BNode> BNodeNotifier;
797 typedef AlterationNotifier<BpUGraphExtender, Node> NodeNotifier;
798 typedef AlterationNotifier<BpUGraphExtender, Edge> EdgeNotifier;
799 typedef AlterationNotifier<BpUGraphExtender, UEdge> UEdgeNotifier;
803 mutable ANodeNotifier anode_notifier;
804 mutable BNodeNotifier bnode_notifier;
805 mutable NodeNotifier node_notifier;
806 mutable EdgeNotifier edge_notifier;
807 mutable UEdgeNotifier uedge_notifier;
811 NodeNotifier& getNotifier(Node) const {
812 return node_notifier;
815 ANodeNotifier& getNotifier(ANode) const {
816 return anode_notifier;
819 BNodeNotifier& getNotifier(BNode) const {
820 return bnode_notifier;
823 EdgeNotifier& getNotifier(Edge) const {
824 return edge_notifier;
827 UEdgeNotifier& getNotifier(UEdge) const {
828 return uedge_notifier;
831 class NodeIt : public Node {
837 NodeIt(Invalid i) : Node(INVALID) { }
839 explicit NodeIt(const Graph& _graph) : graph(&_graph) {
840 graph->first(static_cast<Node&>(*this));
843 NodeIt(const Graph& _graph, const Node& node)
844 : Node(node), graph(&_graph) { }
846 NodeIt& operator++() {
853 class ANodeIt : public Node {
854 friend class BpUGraphExtender;
860 ANodeIt(Invalid i) : Node(INVALID) { }
862 explicit ANodeIt(const Graph& _graph) : graph(&_graph) {
863 graph->firstANode(static_cast<Node&>(*this));
866 ANodeIt(const Graph& _graph, const Node& node)
867 : Node(node), graph(&_graph) {}
869 ANodeIt& operator++() {
870 graph->nextANode(*this);
875 class BNodeIt : public Node {
876 friend class BpUGraphExtender;
882 BNodeIt(Invalid i) : Node(INVALID) { }
884 explicit BNodeIt(const Graph& _graph) : graph(&_graph) {
885 graph->firstBNode(static_cast<Node&>(*this));
888 BNodeIt(const Graph& _graph, const Node& node)
889 : Node(node), graph(&_graph) {}
891 BNodeIt& operator++() {
892 graph->nextBNode(*this);
897 class EdgeIt : public Edge {
898 friend class BpUGraphExtender;
904 EdgeIt(Invalid i) : Edge(INVALID) { }
906 explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
907 graph->first(static_cast<Edge&>(*this));
910 EdgeIt(const Graph& _graph, const Edge& edge)
911 : Edge(edge), graph(&_graph) { }
913 EdgeIt& operator++() {
920 class UEdgeIt : public UEdge {
921 friend class BpUGraphExtender;
927 UEdgeIt(Invalid i) : UEdge(INVALID) { }
929 explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
930 graph->first(static_cast<UEdge&>(*this));
933 UEdgeIt(const Graph& _graph, const UEdge& edge)
934 : UEdge(edge), graph(&_graph) { }
936 UEdgeIt& operator++() {
942 class OutEdgeIt : public Edge {
943 friend class BpUGraphExtender;
949 OutEdgeIt(Invalid i) : Edge(i) { }
951 OutEdgeIt(const Graph& _graph, const Node& node)
953 graph->firstOut(*this, node);
956 OutEdgeIt(const Graph& _graph, const Edge& edge)
957 : Edge(edge), graph(&_graph) {}
959 OutEdgeIt& operator++() {
960 graph->nextOut(*this);
967 class InEdgeIt : public Edge {
968 friend class BpUGraphExtender;
974 InEdgeIt(Invalid i) : Edge(i) { }
976 InEdgeIt(const Graph& _graph, const Node& node)
978 graph->firstIn(*this, node);
981 InEdgeIt(const Graph& _graph, const Edge& edge) :
982 Edge(edge), graph(&_graph) {}
984 InEdgeIt& operator++() {
985 graph->nextIn(*this);
991 /// \brief Base node of the iterator
993 /// Returns the base node (ie. the source in this case) of the iterator
994 Node baseNode(const OutEdgeIt &e) const {
995 return Parent::source((Edge&)e);
997 /// \brief Running node of the iterator
999 /// Returns the running node (ie. the target in this case) of the
1001 Node runningNode(const OutEdgeIt &e) const {
1002 return Parent::target((Edge&)e);
1005 /// \brief Base node of the iterator
1007 /// Returns the base node (ie. the target in this case) of the iterator
1008 Node baseNode(const InEdgeIt &e) const {
1009 return Parent::target((Edge&)e);
1011 /// \brief Running node of the iterator
1013 /// Returns the running node (ie. the source in this case) of the
1015 Node runningNode(const InEdgeIt &e) const {
1016 return Parent::source((Edge&)e);
1019 class IncEdgeIt : public Parent::UEdge {
1020 friend class BpUGraphExtender;
1027 IncEdgeIt(Invalid i) : UEdge(i), direction(true) { }
1029 IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
1030 graph->firstInc(*this, direction, n);
1033 IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
1034 : graph(&_graph), UEdge(ue) {
1035 direction = (graph->source(ue) == n);
1038 IncEdgeIt& operator++() {
1039 graph->nextInc(*this, direction);
1045 /// Base node of the iterator
1047 /// Returns the base node of the iterator
1048 Node baseNode(const IncEdgeIt &e) const {
1049 return e.direction ? source(e) : target(e);
1052 /// Running node of the iterator
1054 /// Returns the running node of the iterator
1055 Node runningNode(const IncEdgeIt &e) const {
1056 return e.direction ? target(e) : source(e);
1059 template <typename _Value>
1061 : public MapExtender<DefaultMap<Graph, ANode, _Value> > {
1063 typedef BpUGraphExtender Graph;
1064 typedef MapExtender<DefaultMap<Graph, ANode, _Value> > Parent;
1066 ANodeMap(const Graph& graph)
1068 ANodeMap(const Graph& graph, const _Value& value)
1069 : Parent(graph, value) {}
1071 ANodeMap& operator=(const ANodeMap& cmap) {
1072 return operator=<ANodeMap>(cmap);
1075 template <typename CMap>
1076 ANodeMap& operator=(const CMap& cmap) {
1077 Parent::operator=(cmap);
1083 template <typename _Value>
1085 : public MapExtender<DefaultMap<Graph, BNode, _Value> > {
1087 typedef BpUGraphExtender Graph;
1088 typedef MapExtender<DefaultMap<Graph, BNode, _Value> > Parent;
1090 BNodeMap(const Graph& graph)
1092 BNodeMap(const Graph& graph, const _Value& value)
1093 : Parent(graph, value) {}
1095 BNodeMap& operator=(const BNodeMap& cmap) {
1096 return operator=<BNodeMap>(cmap);
1099 template <typename CMap>
1100 BNodeMap& operator=(const CMap& cmap) {
1101 Parent::operator=(cmap);
1109 template <typename _Value>
1112 typedef BpUGraphExtender Graph;
1115 typedef _Value Value;
1117 /// The reference type of the map;
1118 typedef typename ANodeMap<_Value>::Reference Reference;
1119 /// The const reference type of the map;
1120 typedef typename ANodeMap<_Value>::ConstReference ConstReference;
1122 typedef True ReferenceMapTag;
1124 NodeMap(const Graph& _graph)
1125 : graph(_graph), aNodeMap(_graph), bNodeMap(_graph) {}
1126 NodeMap(const Graph& _graph, const _Value& _value)
1127 : graph(_graph), aNodeMap(_graph, _value), bNodeMap(_graph, _value) {}
1129 NodeMap& operator=(const NodeMap& cmap) {
1130 return operator=<NodeMap>(cmap);
1133 template <typename CMap>
1134 NodeMap& operator=(const CMap& cmap) {
1135 checkConcept<concepts::ReadMap<Node, _Value>, CMap>();
1141 ConstReference operator[](const Key& node) const {
1142 if (Parent::aNode(node)) {
1143 return aNodeMap[node];
1145 return bNodeMap[node];
1149 Reference operator[](const Key& node) {
1150 if (Parent::aNode(node)) {
1151 return aNodeMap[node];
1153 return bNodeMap[node];
1157 void set(const Key& node, const Value& value) {
1158 if (Parent::aNode(node)) {
1159 aNodeMap.set(node, value);
1161 bNodeMap.set(node, value);
1165 class MapIt : public NodeIt {
1168 typedef NodeIt Parent;
1170 explicit MapIt(NodeMap& _map)
1171 : Parent(_map.graph), map(_map) {}
1173 typename MapTraits<NodeMap>::ConstReturnValue operator*() const {
1177 typename MapTraits<NodeMap>::ReturnValue operator*() {
1181 void set(const Value& value) {
1182 map.set(*this, value);
1189 class ConstMapIt : public NodeIt {
1192 typedef NodeIt Parent;
1194 explicit ConstMapIt(const NodeMap& _map)
1195 : Parent(_map.graph), map(_map) {}
1197 typename MapTraits<NodeMap>::ConstReturnValue operator*() const {
1205 class ItemIt : public NodeIt {
1208 typedef NodeIt Parent;
1210 explicit ItemIt(const NodeMap& _map)
1211 : Parent(_map.graph) {}
1217 ANodeMap<_Value> aNodeMap;
1218 BNodeMap<_Value> bNodeMap;
1222 template <typename _Value>
1224 : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
1226 typedef BpUGraphExtender Graph;
1227 typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
1229 EdgeMap(const Graph& graph)
1231 EdgeMap(const Graph& graph, const _Value& value)
1232 : Parent(graph, value) {}
1234 EdgeMap& operator=(const EdgeMap& cmap) {
1235 return operator=<EdgeMap>(cmap);
1238 template <typename CMap>
1239 EdgeMap& operator=(const CMap& cmap) {
1240 Parent::operator=(cmap);
1245 template <typename _Value>
1247 : public MapExtender<DefaultMap<Graph, UEdge, _Value> > {
1249 typedef BpUGraphExtender Graph;
1250 typedef MapExtender<DefaultMap<Graph, UEdge, _Value> > Parent;
1252 UEdgeMap(const Graph& graph)
1254 UEdgeMap(const Graph& graph, const _Value& value)
1255 : Parent(graph, value) {}
1257 UEdgeMap& operator=(const UEdgeMap& cmap) {
1258 return operator=<UEdgeMap>(cmap);
1261 template <typename CMap>
1262 UEdgeMap& operator=(const CMap& cmap) {
1263 Parent::operator=(cmap);
1270 Node node = Parent::addANode();
1271 getNotifier(ANode()).add(node);
1272 getNotifier(Node()).add(node);
1277 Node node = Parent::addBNode();
1278 getNotifier(BNode()).add(node);
1279 getNotifier(Node()).add(node);
1283 UEdge addEdge(const Node& source, const Node& target) {
1284 UEdge uedge = Parent::addEdge(source, target);
1285 getNotifier(UEdge()).add(uedge);
1287 std::vector<Edge> edges;
1288 edges.push_back(Parent::direct(uedge, true));
1289 edges.push_back(Parent::direct(uedge, false));
1290 getNotifier(Edge()).add(edges);
1296 getNotifier(Edge()).clear();
1297 getNotifier(UEdge()).clear();
1298 getNotifier(Node()).clear();
1299 getNotifier(BNode()).clear();
1300 getNotifier(ANode()).clear();
1304 void erase(const Node& node) {
1306 if (Parent::aNode(node)) {
1307 Parent::firstFromANode(uedge, node);
1308 while (uedge != INVALID) {
1310 Parent::firstFromANode(uedge, node);
1312 getNotifier(ANode()).erase(node);
1314 Parent::firstFromBNode(uedge, node);
1315 while (uedge != INVALID) {
1317 Parent::firstFromBNode(uedge, node);
1319 getNotifier(BNode()).erase(node);
1322 getNotifier(Node()).erase(node);
1323 Parent::erase(node);
1326 void erase(const UEdge& uedge) {
1327 std::vector<Edge> edges;
1328 edges.push_back(Parent::direct(uedge, true));
1329 edges.push_back(Parent::direct(uedge, false));
1330 getNotifier(Edge()).erase(edges);
1331 getNotifier(UEdge()).erase(uedge);
1332 Parent::erase(uedge);
1336 BpUGraphExtender() {
1337 anode_notifier.setContainer(*this);
1338 bnode_notifier.setContainer(*this);
1339 node_notifier.setContainer(*this);
1340 edge_notifier.setContainer(*this);
1341 uedge_notifier.setContainer(*this);
1344 ~BpUGraphExtender() {
1345 uedge_notifier.clear();
1346 edge_notifier.clear();
1347 node_notifier.clear();
1348 anode_notifier.clear();
1349 bnode_notifier.clear();
1352 Edge findEdge(Node u, Node v, Edge prev = INVALID) const {
1353 UEdge uedge = Parent::findUEdge(u, v, prev);
1354 if (uedge != INVALID) {
1355 return Parent::direct(uedge, Parent::aNode(u));