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/bits/utility.h>
24 #include <lemon/error.h>
26 #include <lemon/bits/map_extender.h>
27 #include <lemon/bits/default_map.h>
29 #include <lemon/concept_check.h>
30 #include <lemon/concepts/maps.h>
34 ///\brief Extenders for the graph types
37 /// \ingroup graphbits
39 /// \brief Extender for the Graphs
40 template <typename Base>
41 class GraphExtender : public Base {
45 typedef GraphExtender Graph;
49 typedef typename Parent::Node Node;
50 typedef typename Parent::Edge Edge;
52 int maxId(Node) const {
53 return Parent::maxNodeId();
56 int maxId(Edge) const {
57 return Parent::maxEdgeId();
60 Node fromId(int id, Node) const {
61 return Parent::nodeFromId(id);
64 Edge fromId(int id, Edge) const {
65 return Parent::edgeFromId(id);
68 Node oppositeNode(const Node &n, const Edge &e) const {
69 if (n == Parent::source(e))
70 return Parent::target(e);
71 else if(n==Parent::target(e))
72 return Parent::source(e);
77 // Alterable extension
79 typedef AlterationNotifier<GraphExtender, Node> NodeNotifier;
80 typedef AlterationNotifier<GraphExtender, Edge> EdgeNotifier;
85 mutable NodeNotifier node_notifier;
86 mutable EdgeNotifier edge_notifier;
90 NodeNotifier& notifier(Node) const {
94 EdgeNotifier& notifier(Edge) const {
98 class NodeIt : public Node {
104 NodeIt(Invalid i) : Node(i) { }
106 explicit NodeIt(const Graph& _graph) : graph(&_graph) {
107 _graph.first(static_cast<Node&>(*this));
110 NodeIt(const Graph& _graph, const Node& node)
111 : Node(node), graph(&_graph) {}
113 NodeIt& operator++() {
121 class EdgeIt : public Edge {
127 EdgeIt(Invalid i) : Edge(i) { }
129 explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
130 _graph.first(static_cast<Edge&>(*this));
133 EdgeIt(const Graph& _graph, const Edge& e) :
134 Edge(e), graph(&_graph) { }
136 EdgeIt& operator++() {
144 class OutEdgeIt : public Edge {
150 OutEdgeIt(Invalid i) : Edge(i) { }
152 OutEdgeIt(const Graph& _graph, const Node& node)
154 _graph.firstOut(*this, node);
157 OutEdgeIt(const Graph& _graph, const Edge& edge)
158 : Edge(edge), graph(&_graph) {}
160 OutEdgeIt& operator++() {
161 graph->nextOut(*this);
168 class InEdgeIt : public Edge {
174 InEdgeIt(Invalid i) : Edge(i) { }
176 InEdgeIt(const Graph& _graph, const Node& node)
178 _graph.firstIn(*this, node);
181 InEdgeIt(const Graph& _graph, const Edge& edge) :
182 Edge(edge), graph(&_graph) {}
184 InEdgeIt& operator++() {
185 graph->nextIn(*this);
191 /// \brief Base node of the iterator
193 /// Returns the base node (i.e. the source in this case) of the iterator
194 Node baseNode(const OutEdgeIt &e) const {
195 return Parent::source(e);
197 /// \brief Running node of the iterator
199 /// Returns the running node (i.e. the target in this case) of the
201 Node runningNode(const OutEdgeIt &e) const {
202 return Parent::target(e);
205 /// \brief Base node of the iterator
207 /// Returns the base node (i.e. the target in this case) of the iterator
208 Node baseNode(const InEdgeIt &e) const {
209 return Parent::target(e);
211 /// \brief Running node of the iterator
213 /// Returns the running node (i.e. the source in this case) of the
215 Node runningNode(const InEdgeIt &e) const {
216 return Parent::source(e);
220 template <typename _Value>
222 : public MapExtender<DefaultMap<Graph, Node, _Value> > {
224 typedef GraphExtender Graph;
225 typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent;
227 explicit NodeMap(const Graph& graph)
229 NodeMap(const Graph& graph, const _Value& value)
230 : Parent(graph, value) {}
232 NodeMap& operator=(const NodeMap& cmap) {
233 return operator=<NodeMap>(cmap);
236 template <typename CMap>
237 NodeMap& operator=(const CMap& cmap) {
238 Parent::operator=(cmap);
244 template <typename _Value>
246 : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
248 typedef GraphExtender Graph;
249 typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
251 explicit EdgeMap(const Graph& graph)
253 EdgeMap(const Graph& graph, const _Value& value)
254 : Parent(graph, value) {}
256 EdgeMap& operator=(const EdgeMap& cmap) {
257 return operator=<EdgeMap>(cmap);
260 template <typename CMap>
261 EdgeMap& operator=(const CMap& cmap) {
262 Parent::operator=(cmap);
269 Node node = Parent::addNode();
270 notifier(Node()).add(node);
274 Edge addEdge(const Node& from, const Node& to) {
275 Edge edge = Parent::addEdge(from, to);
276 notifier(Edge()).add(edge);
281 notifier(Edge()).clear();
282 notifier(Node()).clear();
286 template <typename Graph, typename NodeRefMap, typename EdgeRefMap>
287 void build(const Graph& graph, NodeRefMap& nodeRef, EdgeRefMap& edgeRef) {
288 Parent::build(graph, nodeRef, edgeRef);
289 notifier(Node()).build();
290 notifier(Edge()).build();
293 void erase(const Node& node) {
295 Parent::firstOut(edge, node);
296 while (edge != INVALID ) {
298 Parent::firstOut(edge, node);
301 Parent::firstIn(edge, node);
302 while (edge != INVALID ) {
304 Parent::firstIn(edge, node);
307 notifier(Node()).erase(node);
311 void erase(const Edge& edge) {
312 notifier(Edge()).erase(edge);
317 node_notifier.setContainer(*this);
318 edge_notifier.setContainer(*this);
323 edge_notifier.clear();
324 node_notifier.clear();
328 /// \ingroup graphbits
330 /// \brief Extender for the UGraphs
331 template <typename Base>
332 class UGraphExtender : public Base {
336 typedef UGraphExtender Graph;
338 typedef True UndirectedTag;
340 typedef typename Parent::Node Node;
341 typedef typename Parent::Edge Edge;
342 typedef typename Parent::UEdge UEdge;
346 int maxId(Node) const {
347 return Parent::maxNodeId();
350 int maxId(Edge) const {
351 return Parent::maxEdgeId();
354 int maxId(UEdge) const {
355 return Parent::maxUEdgeId();
358 Node fromId(int id, Node) const {
359 return Parent::nodeFromId(id);
362 Edge fromId(int id, Edge) const {
363 return Parent::edgeFromId(id);
366 UEdge fromId(int id, UEdge) const {
367 return Parent::uEdgeFromId(id);
370 Node oppositeNode(const Node &n, const UEdge &e) const {
371 if( n == Parent::source(e))
372 return Parent::target(e);
373 else if( n == Parent::target(e))
374 return Parent::source(e);
379 Edge oppositeEdge(const Edge &e) const {
380 return Parent::direct(e, !Parent::direction(e));
383 using Parent::direct;
384 Edge direct(const UEdge &ue, const Node &s) const {
385 return Parent::direct(ue, Parent::source(ue) == s);
388 // Alterable extension
390 typedef AlterationNotifier<UGraphExtender, Node> NodeNotifier;
391 typedef AlterationNotifier<UGraphExtender, Edge> EdgeNotifier;
392 typedef AlterationNotifier<UGraphExtender, UEdge> UEdgeNotifier;
397 mutable NodeNotifier node_notifier;
398 mutable EdgeNotifier edge_notifier;
399 mutable UEdgeNotifier uedge_notifier;
403 NodeNotifier& notifier(Node) const {
404 return node_notifier;
407 EdgeNotifier& notifier(Edge) const {
408 return edge_notifier;
411 UEdgeNotifier& notifier(UEdge) const {
412 return uedge_notifier;
417 class NodeIt : public Node {
423 NodeIt(Invalid i) : Node(i) { }
425 explicit NodeIt(const Graph& _graph) : graph(&_graph) {
426 _graph.first(static_cast<Node&>(*this));
429 NodeIt(const Graph& _graph, const Node& node)
430 : Node(node), graph(&_graph) {}
432 NodeIt& operator++() {
440 class EdgeIt : public Edge {
446 EdgeIt(Invalid i) : Edge(i) { }
448 explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
449 _graph.first(static_cast<Edge&>(*this));
452 EdgeIt(const Graph& _graph, const Edge& e) :
453 Edge(e), graph(&_graph) { }
455 EdgeIt& operator++() {
463 class OutEdgeIt : public Edge {
469 OutEdgeIt(Invalid i) : Edge(i) { }
471 OutEdgeIt(const Graph& _graph, const Node& node)
473 _graph.firstOut(*this, node);
476 OutEdgeIt(const Graph& _graph, const Edge& edge)
477 : Edge(edge), graph(&_graph) {}
479 OutEdgeIt& operator++() {
480 graph->nextOut(*this);
487 class InEdgeIt : public Edge {
493 InEdgeIt(Invalid i) : Edge(i) { }
495 InEdgeIt(const Graph& _graph, const Node& node)
497 _graph.firstIn(*this, node);
500 InEdgeIt(const Graph& _graph, const Edge& edge) :
501 Edge(edge), graph(&_graph) {}
503 InEdgeIt& operator++() {
504 graph->nextIn(*this);
511 class UEdgeIt : public Parent::UEdge {
517 UEdgeIt(Invalid i) : UEdge(i) { }
519 explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
520 _graph.first(static_cast<UEdge&>(*this));
523 UEdgeIt(const Graph& _graph, const UEdge& e) :
524 UEdge(e), graph(&_graph) { }
526 UEdgeIt& operator++() {
533 class IncEdgeIt : public Parent::UEdge {
534 friend class UGraphExtender;
541 IncEdgeIt(Invalid i) : UEdge(i), direction(false) { }
543 IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
544 _graph.firstInc(*this, direction, n);
547 IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
548 : graph(&_graph), UEdge(ue) {
549 direction = (_graph.source(ue) == n);
552 IncEdgeIt& operator++() {
553 graph->nextInc(*this, direction);
558 /// \brief Base node of the iterator
560 /// Returns the base node (ie. the source in this case) of the iterator
561 Node baseNode(const OutEdgeIt &e) const {
562 return Parent::source(static_cast<const Edge&>(e));
564 /// \brief Running node of the iterator
566 /// Returns the running node (ie. the target in this case) of the
568 Node runningNode(const OutEdgeIt &e) const {
569 return Parent::target(static_cast<const Edge&>(e));
572 /// \brief Base node of the iterator
574 /// Returns the base node (ie. the target in this case) of the iterator
575 Node baseNode(const InEdgeIt &e) const {
576 return Parent::target(static_cast<const Edge&>(e));
578 /// \brief Running node of the iterator
580 /// Returns the running node (ie. the source in this case) of the
582 Node runningNode(const InEdgeIt &e) const {
583 return Parent::source(static_cast<const Edge&>(e));
586 /// Base node of the iterator
588 /// Returns the base node of the iterator
589 Node baseNode(const IncEdgeIt &e) const {
590 return e.direction ? source(e) : target(e);
592 /// Running node of the iterator
594 /// Returns the running node of the iterator
595 Node runningNode(const IncEdgeIt &e) const {
596 return e.direction ? target(e) : source(e);
599 // Mappable extension
601 template <typename _Value>
603 : public MapExtender<DefaultMap<Graph, Node, _Value> > {
605 typedef UGraphExtender Graph;
606 typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent;
608 NodeMap(const Graph& graph)
610 NodeMap(const Graph& graph, const _Value& value)
611 : Parent(graph, value) {}
613 NodeMap& operator=(const NodeMap& cmap) {
614 return operator=<NodeMap>(cmap);
617 template <typename CMap>
618 NodeMap& operator=(const CMap& cmap) {
619 Parent::operator=(cmap);
625 template <typename _Value>
627 : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
629 typedef UGraphExtender Graph;
630 typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
632 EdgeMap(const Graph& graph)
634 EdgeMap(const Graph& graph, const _Value& value)
635 : Parent(graph, value) {}
637 EdgeMap& operator=(const EdgeMap& cmap) {
638 return operator=<EdgeMap>(cmap);
641 template <typename CMap>
642 EdgeMap& operator=(const CMap& cmap) {
643 Parent::operator=(cmap);
649 template <typename _Value>
651 : public MapExtender<DefaultMap<Graph, UEdge, _Value> > {
653 typedef UGraphExtender Graph;
654 typedef MapExtender<DefaultMap<Graph, UEdge, _Value> > Parent;
656 UEdgeMap(const Graph& graph)
659 UEdgeMap(const Graph& graph, const _Value& value)
660 : Parent(graph, value) {}
662 UEdgeMap& operator=(const UEdgeMap& cmap) {
663 return operator=<UEdgeMap>(cmap);
666 template <typename CMap>
667 UEdgeMap& operator=(const CMap& cmap) {
668 Parent::operator=(cmap);
674 // Alteration extension
677 Node node = Parent::addNode();
678 notifier(Node()).add(node);
682 UEdge addEdge(const Node& from, const Node& to) {
683 UEdge uedge = Parent::addEdge(from, to);
684 notifier(UEdge()).add(uedge);
685 std::vector<Edge> ev;
686 ev.push_back(Parent::direct(uedge, true));
687 ev.push_back(Parent::direct(uedge, false));
688 notifier(Edge()).add(ev);
693 notifier(Edge()).clear();
694 notifier(UEdge()).clear();
695 notifier(Node()).clear();
699 template <typename Graph, typename NodeRefMap, typename UEdgeRefMap>
700 void build(const Graph& graph, NodeRefMap& nodeRef,
701 UEdgeRefMap& uEdgeRef) {
702 Parent::build(graph, nodeRef, uEdgeRef);
703 notifier(Node()).build();
704 notifier(UEdge()).build();
705 notifier(Edge()).build();
708 void erase(const Node& node) {
710 Parent::firstOut(edge, node);
711 while (edge != INVALID ) {
713 Parent::firstOut(edge, node);
716 Parent::firstIn(edge, node);
717 while (edge != INVALID ) {
719 Parent::firstIn(edge, node);
722 notifier(Node()).erase(node);
726 void erase(const UEdge& uedge) {
727 std::vector<Edge> ev;
728 ev.push_back(Parent::direct(uedge, true));
729 ev.push_back(Parent::direct(uedge, false));
730 notifier(Edge()).erase(ev);
731 notifier(UEdge()).erase(uedge);
732 Parent::erase(uedge);
736 node_notifier.setContainer(*this);
737 edge_notifier.setContainer(*this);
738 uedge_notifier.setContainer(*this);
742 uedge_notifier.clear();
743 edge_notifier.clear();
744 node_notifier.clear();
749 /// \ingroup graphbits
751 /// \brief Extender for the BpUGraphs
752 template <typename Base>
753 class BpUGraphExtender : public Base {
757 typedef BpUGraphExtender Graph;
759 typedef True UndirectedTag;
761 typedef typename Parent::Node Node;
762 typedef typename Parent::ANode ANode;
763 typedef typename Parent::BNode BNode;
764 typedef typename Parent::Edge Edge;
765 typedef typename Parent::UEdge UEdge;
768 Node oppositeNode(const Node& node, const UEdge& edge) const {
769 return Parent::aNode(edge) == node ?
770 Parent::bNode(edge) : Parent::aNode(edge);
773 using Parent::direct;
774 Edge direct(const UEdge& edge, const Node& node) const {
775 return Parent::direct(edge, node == Parent::source(edge));
778 Edge oppositeEdge(const Edge& edge) const {
779 return direct(edge, !Parent::direction(edge));
782 int maxId(Node) const {
783 return Parent::maxNodeId();
785 int maxId(BNode) const {
786 return Parent::maxBNodeId();
788 int maxId(ANode) const {
789 return Parent::maxANodeId();
791 int maxId(Edge) const {
792 return Parent::maxEdgeId();
794 int maxId(UEdge) const {
795 return Parent::maxUEdgeId();
799 Node fromId(int id, Node) const {
800 return Parent::nodeFromId(id);
802 ANode fromId(int id, ANode) const {
803 return Parent::nodeFromANodeId(id);
805 BNode fromId(int id, BNode) const {
806 return Parent::nodeFromBNodeId(id);
808 Edge fromId(int id, Edge) const {
809 return Parent::edgeFromId(id);
811 UEdge fromId(int id, UEdge) const {
812 return Parent::uEdgeFromId(id);
815 typedef AlterationNotifier<BpUGraphExtender, ANode> ANodeNotifier;
816 typedef AlterationNotifier<BpUGraphExtender, BNode> BNodeNotifier;
817 typedef AlterationNotifier<BpUGraphExtender, Node> NodeNotifier;
818 typedef AlterationNotifier<BpUGraphExtender, Edge> EdgeNotifier;
819 typedef AlterationNotifier<BpUGraphExtender, UEdge> UEdgeNotifier;
823 mutable ANodeNotifier anode_notifier;
824 mutable BNodeNotifier bnode_notifier;
825 mutable NodeNotifier node_notifier;
826 mutable EdgeNotifier edge_notifier;
827 mutable UEdgeNotifier uedge_notifier;
831 NodeNotifier& notifier(Node) const {
832 return node_notifier;
835 ANodeNotifier& notifier(ANode) const {
836 return anode_notifier;
839 BNodeNotifier& notifier(BNode) const {
840 return bnode_notifier;
843 EdgeNotifier& notifier(Edge) const {
844 return edge_notifier;
847 UEdgeNotifier& notifier(UEdge) const {
848 return uedge_notifier;
851 class NodeIt : public Node {
857 NodeIt(Invalid i) : Node(INVALID) { }
859 explicit NodeIt(const Graph& _graph) : graph(&_graph) {
860 graph->first(static_cast<Node&>(*this));
863 NodeIt(const Graph& _graph, const Node& node)
864 : Node(node), graph(&_graph) { }
866 NodeIt& operator++() {
873 class ANodeIt : public Node {
874 friend class BpUGraphExtender;
880 ANodeIt(Invalid i) : Node(INVALID) { }
882 explicit ANodeIt(const Graph& _graph) : graph(&_graph) {
883 graph->firstANode(static_cast<Node&>(*this));
886 ANodeIt(const Graph& _graph, const Node& node)
887 : Node(node), graph(&_graph) {}
889 ANodeIt& operator++() {
890 graph->nextANode(*this);
895 class BNodeIt : public Node {
896 friend class BpUGraphExtender;
902 BNodeIt(Invalid i) : Node(INVALID) { }
904 explicit BNodeIt(const Graph& _graph) : graph(&_graph) {
905 graph->firstBNode(static_cast<Node&>(*this));
908 BNodeIt(const Graph& _graph, const Node& node)
909 : Node(node), graph(&_graph) {}
911 BNodeIt& operator++() {
912 graph->nextBNode(*this);
917 class EdgeIt : public Edge {
918 friend class BpUGraphExtender;
924 EdgeIt(Invalid i) : Edge(INVALID) { }
926 explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
927 graph->first(static_cast<Edge&>(*this));
930 EdgeIt(const Graph& _graph, const Edge& edge)
931 : Edge(edge), graph(&_graph) { }
933 EdgeIt& operator++() {
940 class UEdgeIt : public UEdge {
941 friend class BpUGraphExtender;
947 UEdgeIt(Invalid i) : UEdge(INVALID) { }
949 explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
950 graph->first(static_cast<UEdge&>(*this));
953 UEdgeIt(const Graph& _graph, const UEdge& edge)
954 : UEdge(edge), graph(&_graph) { }
956 UEdgeIt& operator++() {
962 class OutEdgeIt : public Edge {
963 friend class BpUGraphExtender;
969 OutEdgeIt(Invalid i) : Edge(i) { }
971 OutEdgeIt(const Graph& _graph, const Node& node)
973 graph->firstOut(*this, node);
976 OutEdgeIt(const Graph& _graph, const Edge& edge)
977 : Edge(edge), graph(&_graph) {}
979 OutEdgeIt& operator++() {
980 graph->nextOut(*this);
987 class InEdgeIt : public Edge {
988 friend class BpUGraphExtender;
994 InEdgeIt(Invalid i) : Edge(i) { }
996 InEdgeIt(const Graph& _graph, const Node& node)
998 graph->firstIn(*this, node);
1001 InEdgeIt(const Graph& _graph, const Edge& edge) :
1002 Edge(edge), graph(&_graph) {}
1004 InEdgeIt& operator++() {
1005 graph->nextIn(*this);
1011 /// \brief Base node of the iterator
1013 /// Returns the base node (ie. the source in this case) of the iterator
1014 Node baseNode(const OutEdgeIt &e) const {
1015 return Parent::source(static_cast<const Edge&>(e));
1017 /// \brief Running node of the iterator
1019 /// Returns the running node (ie. the target in this case) of the
1021 Node runningNode(const OutEdgeIt &e) const {
1022 return Parent::target(static_cast<const Edge&>(e));
1025 /// \brief Base node of the iterator
1027 /// Returns the base node (ie. the target in this case) of the iterator
1028 Node baseNode(const InEdgeIt &e) const {
1029 return Parent::target(static_cast<const Edge&>(e));
1031 /// \brief Running node of the iterator
1033 /// Returns the running node (ie. the source in this case) of the
1035 Node runningNode(const InEdgeIt &e) const {
1036 return Parent::source(static_cast<const Edge&>(e));
1039 class IncEdgeIt : public Parent::UEdge {
1040 friend class BpUGraphExtender;
1047 IncEdgeIt(Invalid i) : UEdge(i), direction(true) { }
1049 IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
1050 graph->firstInc(*this, direction, n);
1053 IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
1054 : graph(&_graph), UEdge(ue) {
1055 direction = (graph->source(ue) == n);
1058 IncEdgeIt& operator++() {
1059 graph->nextInc(*this, direction);
1065 /// Base node of the iterator
1067 /// Returns the base node of the iterator
1068 Node baseNode(const IncEdgeIt &e) const {
1069 return e.direction ? source(e) : target(e);
1072 /// Running node of the iterator
1074 /// Returns the running node of the iterator
1075 Node runningNode(const IncEdgeIt &e) const {
1076 return e.direction ? target(e) : source(e);
1079 template <typename _Value>
1081 : public MapExtender<DefaultMap<Graph, ANode, _Value> > {
1083 typedef BpUGraphExtender Graph;
1084 typedef MapExtender<DefaultMap<Graph, ANode, _Value> > Parent;
1086 ANodeMap(const Graph& graph)
1088 ANodeMap(const Graph& graph, const _Value& value)
1089 : Parent(graph, value) {}
1091 ANodeMap& operator=(const ANodeMap& cmap) {
1092 return operator=<ANodeMap>(cmap);
1095 template <typename CMap>
1096 ANodeMap& operator=(const CMap& cmap) {
1097 Parent::operator=(cmap);
1103 template <typename _Value>
1105 : public MapExtender<DefaultMap<Graph, BNode, _Value> > {
1107 typedef BpUGraphExtender Graph;
1108 typedef MapExtender<DefaultMap<Graph, BNode, _Value> > Parent;
1110 BNodeMap(const Graph& graph)
1112 BNodeMap(const Graph& graph, const _Value& value)
1113 : Parent(graph, value) {}
1115 BNodeMap& operator=(const BNodeMap& cmap) {
1116 return operator=<BNodeMap>(cmap);
1119 template <typename CMap>
1120 BNodeMap& operator=(const CMap& cmap) {
1121 Parent::operator=(cmap);
1129 template <typename _Value>
1132 typedef BpUGraphExtender Graph;
1135 typedef _Value Value;
1137 /// The reference type of the map;
1138 typedef typename ANodeMap<_Value>::Reference Reference;
1139 /// The const reference type of the map;
1140 typedef typename ANodeMap<_Value>::ConstReference ConstReference;
1142 typedef True ReferenceMapTag;
1144 NodeMap(const Graph& _graph)
1145 : graph(_graph), aNodeMap(_graph), bNodeMap(_graph) {}
1146 NodeMap(const Graph& _graph, const _Value& _value)
1147 : graph(_graph), aNodeMap(_graph, _value), bNodeMap(_graph, _value) {}
1149 NodeMap& operator=(const NodeMap& cmap) {
1150 return operator=<NodeMap>(cmap);
1153 template <typename CMap>
1154 NodeMap& operator=(const CMap& cmap) {
1155 checkConcept<concepts::ReadMap<Node, _Value>, CMap>();
1161 ConstReference operator[](const Key& node) const {
1162 if (Parent::aNode(node)) {
1163 return aNodeMap[node];
1165 return bNodeMap[node];
1169 Reference operator[](const Key& node) {
1170 if (Parent::aNode(node)) {
1171 return aNodeMap[node];
1173 return bNodeMap[node];
1177 void set(const Key& node, const Value& value) {
1178 if (Parent::aNode(node)) {
1179 aNodeMap.set(node, value);
1181 bNodeMap.set(node, value);
1185 class MapIt : public NodeIt {
1188 typedef NodeIt Parent;
1190 explicit MapIt(NodeMap& _map)
1191 : Parent(_map.graph), map(_map) {}
1193 typename MapTraits<NodeMap>::ConstReturnValue operator*() const {
1197 typename MapTraits<NodeMap>::ReturnValue operator*() {
1201 void set(const Value& value) {
1202 map.set(*this, value);
1209 class ConstMapIt : public NodeIt {
1212 typedef NodeIt Parent;
1214 explicit ConstMapIt(const NodeMap& _map)
1215 : Parent(_map.graph), map(_map) {}
1217 typename MapTraits<NodeMap>::ConstReturnValue operator*() const {
1225 class ItemIt : public NodeIt {
1228 typedef NodeIt Parent;
1230 explicit ItemIt(const NodeMap& _map)
1231 : Parent(_map.graph) {}
1237 ANodeMap<_Value> aNodeMap;
1238 BNodeMap<_Value> bNodeMap;
1242 template <typename _Value>
1244 : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
1246 typedef BpUGraphExtender Graph;
1247 typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
1249 EdgeMap(const Graph& graph)
1251 EdgeMap(const Graph& graph, const _Value& value)
1252 : Parent(graph, value) {}
1254 EdgeMap& operator=(const EdgeMap& cmap) {
1255 return operator=<EdgeMap>(cmap);
1258 template <typename CMap>
1259 EdgeMap& operator=(const CMap& cmap) {
1260 Parent::operator=(cmap);
1265 template <typename _Value>
1267 : public MapExtender<DefaultMap<Graph, UEdge, _Value> > {
1269 typedef BpUGraphExtender Graph;
1270 typedef MapExtender<DefaultMap<Graph, UEdge, _Value> > Parent;
1272 UEdgeMap(const Graph& graph)
1274 UEdgeMap(const Graph& graph, const _Value& value)
1275 : Parent(graph, value) {}
1277 UEdgeMap& operator=(const UEdgeMap& cmap) {
1278 return operator=<UEdgeMap>(cmap);
1281 template <typename CMap>
1282 UEdgeMap& operator=(const CMap& cmap) {
1283 Parent::operator=(cmap);
1290 Node node = Parent::addANode();
1291 notifier(ANode()).add(node);
1292 notifier(Node()).add(node);
1297 Node node = Parent::addBNode();
1298 notifier(BNode()).add(node);
1299 notifier(Node()).add(node);
1303 UEdge addEdge(const Node& s, const Node& t) {
1304 UEdge uedge = Parent::addEdge(s, t);
1305 notifier(UEdge()).add(uedge);
1307 std::vector<Edge> ev;
1308 ev.push_back(Parent::direct(uedge, true));
1309 ev.push_back(Parent::direct(uedge, false));
1310 notifier(Edge()).add(ev);
1316 notifier(Edge()).clear();
1317 notifier(UEdge()).clear();
1318 notifier(Node()).clear();
1319 notifier(BNode()).clear();
1320 notifier(ANode()).clear();
1324 template <typename Graph, typename ANodeRefMap,
1325 typename BNodeRefMap, typename UEdgeRefMap>
1326 void build(const Graph& graph, ANodeRefMap& aNodeRef,
1327 BNodeRefMap& bNodeRef, UEdgeRefMap& uEdgeRef) {
1328 Parent::build(graph, aNodeRef, bNodeRef, uEdgeRef);
1329 notifier(ANode()).build();
1330 notifier(BNode()).build();
1331 notifier(Node()).build();
1332 notifier(UEdge()).build();
1333 notifier(Edge()).build();
1336 void erase(const Node& node) {
1338 if (Parent::aNode(node)) {
1339 Parent::firstFromANode(uedge, node);
1340 while (uedge != INVALID) {
1342 Parent::firstFromANode(uedge, node);
1344 notifier(ANode()).erase(node);
1346 Parent::firstFromBNode(uedge, node);
1347 while (uedge != INVALID) {
1349 Parent::firstFromBNode(uedge, node);
1351 notifier(BNode()).erase(node);
1354 notifier(Node()).erase(node);
1355 Parent::erase(node);
1358 void erase(const UEdge& uedge) {
1359 std::vector<Edge> ev;
1360 ev.push_back(Parent::direct(uedge, true));
1361 ev.push_back(Parent::direct(uedge, false));
1362 notifier(Edge()).erase(ev);
1363 notifier(UEdge()).erase(uedge);
1364 Parent::erase(uedge);
1368 BpUGraphExtender() {
1369 anode_notifier.setContainer(*this);
1370 bnode_notifier.setContainer(*this);
1371 node_notifier.setContainer(*this);
1372 edge_notifier.setContainer(*this);
1373 uedge_notifier.setContainer(*this);
1376 ~BpUGraphExtender() {
1377 uedge_notifier.clear();
1378 edge_notifier.clear();
1379 node_notifier.clear();
1380 anode_notifier.clear();
1381 bnode_notifier.clear();
1384 Edge findEdge(Node u, Node v, Edge prev = INVALID) const {
1385 UEdge uedge = Parent::findUEdge(u, v, prev);
1386 if (uedge != INVALID) {
1387 return Parent::direct(uedge, Parent::aNode(u));