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_SMART_GRAPH_H
20 #define LEMON_SMART_GRAPH_H
24 ///\brief SmartGraph and SmartUGraph classes.
28 #include <lemon/bits/invalid.h>
30 #include <lemon/bits/base_extender.h>
31 #include <lemon/bits/graph_extender.h>
33 #include <lemon/bits/utility.h>
34 #include <lemon/error.h>
36 #include <lemon/bits/graph_extender.h>
45 class SmartGraphBase {
50 int first_in, first_out;
55 int target, source, next_in, next_out;
59 std::vector<NodeT> nodes;
61 std::vector<EdgeT> edges;
66 typedef SmartGraphBase Graph;
74 SmartGraphBase() : nodes(), edges() { }
75 SmartGraphBase(const SmartGraphBase &_g)
76 : nodes(_g.nodes), edges(_g.edges) { }
78 typedef True NodeNumTag;
79 typedef True EdgeNumTag;
81 int nodeNum() const { return nodes.size(); }
82 int edgeNum() const { return edges.size(); }
84 int maxNodeId() const { return nodes.size()-1; }
85 int maxEdgeId() const { return edges.size()-1; }
89 nodes.push_back(NodeT());
90 nodes[n].first_in = -1;
91 nodes[n].first_out = -1;
95 Edge addEdge(Node u, Node v) {
97 edges.push_back(EdgeT());
98 edges[n].source = u.id;
99 edges[n].target = v.id;
100 edges[n].next_out = nodes[u.id].first_out;
101 edges[n].next_in = nodes[v.id].first_in;
102 nodes[u.id].first_out = nodes[v.id].first_in = n;
112 Node source(Edge e) const { return Node(edges[e.id].source); }
113 Node target(Edge e) const { return Node(edges[e.id].target); }
115 static int id(Node v) { return v.id; }
116 static int id(Edge e) { return e.id; }
118 static Node nodeFromId(int id) { return Node(id);}
119 static Edge edgeFromId(int id) { return Edge(id);}
122 friend class SmartGraphBase;
123 friend class SmartGraph;
127 explicit Node(int _id) : id(_id) {}
130 Node (Invalid) : id(-1) {}
131 bool operator==(const Node i) const {return id == i.id;}
132 bool operator!=(const Node i) const {return id != i.id;}
133 bool operator<(const Node i) const {return id < i.id;}
138 friend class SmartGraphBase;
139 friend class SmartGraph;
143 explicit Edge(int _id) : id(_id) {}
146 Edge (Invalid) : id(-1) {}
147 bool operator==(const Edge i) const {return id == i.id;}
148 bool operator!=(const Edge i) const {return id != i.id;}
149 bool operator<(const Edge i) const {return id < i.id;}
152 void first(Node& node) const {
153 node.id = nodes.size() - 1;
156 static void next(Node& node) {
160 void first(Edge& edge) const {
161 edge.id = edges.size() - 1;
164 static void next(Edge& edge) {
168 void firstOut(Edge& edge, const Node& node) const {
169 edge.id = nodes[node.id].first_out;
172 void nextOut(Edge& edge) const {
173 edge.id = edges[edge.id].next_out;
176 void firstIn(Edge& edge, const Node& node) const {
177 edge.id = nodes[node.id].first_in;
180 void nextIn(Edge& edge) const {
181 edge.id = edges[edge.id].next_in;
186 typedef GraphExtender<SmartGraphBase> ExtendedSmartGraphBase;
190 ///A smart graph class.
192 ///This is a simple and fast graph implementation.
193 ///It is also quite memory efficient, but at the price
194 ///that <b> it does support only limited (only stack-like)
195 ///node and edge deletions</b>.
197 ///the \ref concepts::Graph "Graph concept" with an
198 ///important extra feature that
199 ///its maps are real \ref concepts::ReferenceMap "reference map"s.
201 ///\sa concepts::Graph.
203 ///\author Alpar Juttner
204 class SmartGraph : public ExtendedSmartGraphBase {
207 typedef ExtendedSmartGraphBase Parent;
211 ///SmartGraph is \e not copy constructible. Use GraphCopy() instead.
213 ///SmartGraph is \e not copy constructible. Use GraphCopy() instead.
215 SmartGraph(const SmartGraph &) : ExtendedSmartGraphBase() {};
216 ///\brief Assignment of SmartGraph to another one is \e not allowed.
217 ///Use GraphCopy() instead.
219 ///Assignment of SmartGraph to another one is \e not allowed.
220 ///Use GraphCopy() instead.
221 void operator=(const SmartGraph &) {}
231 ///Add a new node to the graph.
233 /// \return the new node.
235 Node addNode() { return Parent::addNode(); }
237 ///Add a new edge to the graph.
239 ///Add a new edge to the graph with source node \c s
240 ///and target node \c t.
241 ///\return the new edge.
242 Edge addEdge(const Node& s, const Node& t) {
243 return Parent::addEdge(s, t);
248 ///Erase all the nodes and edges from the graph.
256 ///This function splits a node. First a new node is added to the graph,
257 ///then the source of each outgoing edge of \c n is moved to this new node.
258 ///If \c connect is \c true (this is the default value), then a new edge
259 ///from \c n to the newly created node is also added.
260 ///\return The newly created node.
262 ///\note The <tt>Edge</tt>s
263 ///referencing a moved edge remain
264 ///valid. However <tt>InEdge</tt>'s and <tt>OutEdge</tt>'s
265 ///may be invalidated.
266 ///\warning This functionality cannot be used together with the Snapshot
268 ///\todo It could be implemented in a bit faster way.
269 Node split(Node n, bool connect = true)
272 nodes[b.id].first_out=nodes[n.id].first_out;
273 nodes[n.id].first_out=-1;
274 for(int i=nodes[b.id].first_out;i!=-1;i++) edges[i].source=b.id;
275 if(connect) addEdge(n,b);
285 void restoreSnapshot(const Snapshot &s)
287 while(s.edge_num<edges.size()) {
288 Edge edge = edgeFromId(edges.size()-1);
289 Parent::getNotifier(Edge()).erase(edge);
290 nodes[edges.back().source].first_out=edges.back().next_out;
291 nodes[edges.back().target].first_in=edges.back().next_in;
294 while(s.node_num<nodes.size()) {
295 Node node = nodeFromId(nodes.size()-1);
296 Parent::getNotifier(Node()).erase(node);
303 ///Class to make a snapshot of the graph and to restrore to it later.
305 ///Class to make a snapshot of the graph and to restrore to it later.
307 ///The newly added nodes and edges can be removed using the
308 ///restore() function.
309 ///\note After you restore a state, you cannot restore
310 ///a later state, in other word you cannot add again the edges deleted
311 ///by restore() using another one Snapshot instance.
313 ///\warning If you do not use correctly the snapshot that can cause
314 ///either broken program, invalid state of the graph, valid but
315 ///not the restored graph or no change. Because the runtime performance
316 ///the validity of the snapshot is not stored.
321 friend class SmartGraph;
322 unsigned int node_num;
323 unsigned int edge_num;
325 ///Default constructor.
327 ///Default constructor.
328 ///To actually make a snapshot you must call save().
331 ///Constructor that immediately makes a snapshot
333 ///This constructor immediately makes a snapshot of the graph.
334 ///\param _g The graph we make a snapshot of.
335 Snapshot(SmartGraph &_g) :g(&_g) {
336 node_num=g->nodes.size();
337 edge_num=g->edges.size();
342 ///Make a snapshot of the graph.
344 ///This function can be called more than once. In case of a repeated
345 ///call, the previous snapshot gets lost.
346 ///\param _g The graph we make the snapshot of.
347 void save(SmartGraph &_g)
350 node_num=g->nodes.size();
351 edge_num=g->edges.size();
354 ///Undo the changes until a snapshot.
356 ///Undo the changes until a snapshot created by save().
358 ///\note After you restored a state, you cannot restore
359 ///a later state, in other word you cannot add again the edges deleted
363 g->restoreSnapshot(*this);
369 class SmartUGraphBase {
382 std::vector<NodeT> nodes;
383 std::vector<EdgeT> edges;
389 typedef SmartUGraphBase Graph;
396 friend class SmartUGraphBase;
400 explicit Node(int pid) { id = pid;}
404 Node (Invalid) { id = -1; }
405 bool operator==(const Node& node) const {return id == node.id;}
406 bool operator!=(const Node& node) const {return id != node.id;}
407 bool operator<(const Node& node) const {return id < node.id;}
411 friend class SmartUGraphBase;
415 explicit UEdge(int pid) { id = pid;}
419 UEdge (Invalid) { id = -1; }
420 bool operator==(const UEdge& edge) const {return id == edge.id;}
421 bool operator!=(const UEdge& edge) const {return id != edge.id;}
422 bool operator<(const UEdge& edge) const {return id < edge.id;}
426 friend class SmartUGraphBase;
430 explicit Edge(int pid) { id = pid;}
433 operator UEdge() const { return uEdgeFromId(id / 2); }
436 Edge (Invalid) { id = -1; }
437 bool operator==(const Edge& edge) const {return id == edge.id;}
438 bool operator!=(const Edge& edge) const {return id != edge.id;}
439 bool operator<(const Edge& edge) const {return id < edge.id;}
445 : nodes(), edges() {}
448 int maxNodeId() const { return nodes.size()-1; }
449 int maxUEdgeId() const { return edges.size() / 2 - 1; }
450 int maxEdgeId() const { return edges.size()-1; }
452 Node source(Edge e) const { return Node(edges[e.id ^ 1].target); }
453 Node target(Edge e) const { return Node(edges[e.id].target); }
455 Node source(UEdge e) const { return Node(edges[2 * e.id].target); }
456 Node target(UEdge e) const { return Node(edges[2 * e.id + 1].target); }
458 static bool direction(Edge e) {
459 return (e.id & 1) == 1;
462 static Edge direct(UEdge e, bool d) {
463 return Edge(e.id * 2 + (d ? 1 : 0));
466 void first(Node& node) const {
467 node.id = nodes.size() - 1;
470 void next(Node& node) const {
474 void first(Edge& edge) const {
475 edge.id = edges.size() - 1;
478 void next(Edge& edge) const {
482 void first(UEdge& edge) const {
483 edge.id = edges.size() / 2 - 1;
486 void next(UEdge& edge) const {
490 void firstOut(Edge &edge, const Node& v) const {
491 edge.id = nodes[v.id].first_out;
493 void nextOut(Edge &edge) const {
494 edge.id = edges[edge.id].next_out;
497 void firstIn(Edge &edge, const Node& v) const {
498 edge.id = ((nodes[v.id].first_out) ^ 1);
499 if (edge.id == -2) edge.id = -1;
501 void nextIn(Edge &edge) const {
502 edge.id = ((edges[edge.id ^ 1].next_out) ^ 1);
503 if (edge.id == -2) edge.id = -1;
506 void firstInc(UEdge &edge, bool& d, const Node& v) const {
507 int de = nodes[v.id].first_out;
511 void nextInc(UEdge &edge, bool& d) const {
512 int de = (edges[(edge.id * 2) | (d ? 1 : 0)].next_out);
517 static int id(Node v) { return v.id; }
518 static int id(Edge e) { return e.id; }
519 static int id(UEdge e) { return e.id; }
521 static Node nodeFromId(int id) { return Node(id);}
522 static Edge edgeFromId(int id) { return Edge(id);}
523 static UEdge uEdgeFromId(int id) { return UEdge(id);}
526 int n = nodes.size();
527 nodes.push_back(NodeT());
528 nodes[n].first_out = -1;
533 UEdge addEdge(Node u, Node v) {
534 int n = edges.size();
535 edges.push_back(EdgeT());
536 edges.push_back(EdgeT());
538 edges[n].target = u.id;
539 edges[n | 1].target = v.id;
541 edges[n].next_out = nodes[v.id].first_out;
542 edges[n | 1].next_out = nodes[u.id].first_out;
544 nodes[v.id].first_out = n;
545 nodes[u.id].first_out = (n | 1);
557 typedef UGraphExtender<SmartUGraphBase> ExtendedSmartUGraphBase;
561 /// \brief A smart undirected graph class.
563 /// This is a simple and fast undirected graph implementation.
564 /// It is also quite memory efficient, but at the price
565 /// that <b> it does support only limited (only stack-like)
566 /// node and edge deletions</b>.
567 /// Except from this it conforms to
568 /// the \ref concepts::UGraph "UGraph concept".
571 ///important extra feature that
572 ///its maps are real \ref concepts::ReferenceMap "reference map"s.
574 /// \sa concepts::UGraph.
576 class SmartUGraph : public ExtendedSmartUGraphBase {
579 ///SmartUGraph is \e not copy constructible. Use UGraphCopy() instead.
581 ///SmartUGraph is \e not copy constructible. Use UGraphCopy() instead.
583 SmartUGraph(const SmartUGraph &) : ExtendedSmartUGraphBase() {};
585 ///\brief Assignment of SmartUGraph to another one is \e not allowed.
586 ///Use UGraphCopy() instead.
588 ///Assignment of SmartUGraph to another one is \e not allowed.
589 ///Use UGraphCopy() instead.
590 void operator=(const SmartUGraph &) {}
594 typedef ExtendedSmartUGraphBase Parent;
595 typedef Parent::OutEdgeIt IncEdgeIt;
603 ///Add a new node to the graph.
605 /// \return the new node.
607 Node addNode() { return Parent::addNode(); }
609 ///Add a new undirected edge to the graph.
611 ///Add a new undirected edge to the graph with node \c s
613 ///\return the new undirected edge.
614 UEdge addEdge(const Node& s, const Node& t) {
615 return Parent::addEdge(s, t);
620 ///Erase all the nodes and edges from the graph.
632 void saveSnapshot(Snapshot &s)
635 s.node_num = nodes.size();
636 s.edge_num = edges.size();
639 void restoreSnapshot(const Snapshot &s)
641 while(s.edge_num<edges.size()) {
642 int n=edges.size()-1;
643 UEdge edge=uEdgeFromId(n/2);
644 Parent::getNotifier(UEdge()).erase(edge);
645 std::vector<Edge> dir;
646 dir.push_back(edgeFromId(n));
647 dir.push_back(edgeFromId(n-1));
648 Parent::getNotifier(Edge()).erase(dir);
649 nodes[edges[n].target].first_out=edges[n].next_out;
650 nodes[edges[n-1].target].first_out=edges[n-1].next_out;
654 while(s.node_num<nodes.size()) {
655 int n=nodes.size()-1;
656 Node node = nodeFromId(n);
657 Parent::getNotifier(Node()).erase(node);
664 ///Class to make a snapshot of the graph and to restrore to it later.
666 ///Class to make a snapshot of the graph and to restrore to it later.
668 ///The newly added nodes and edges can be removed using the
669 ///restore() function.
671 ///\note After you restore a state, you cannot restore
672 ///a later state, in other word you cannot add again the edges deleted
673 ///by restore() using another one Snapshot instance.
675 ///\warning If you do not use correctly the snapshot that can cause
676 ///either broken program, invalid state of the graph, valid but
677 ///not the restored graph or no change. Because the runtime performance
678 ///the validity of the snapshot is not stored.
683 friend class SmartUGraph;
684 unsigned int node_num;
685 unsigned int edge_num;
687 ///Default constructor.
689 ///Default constructor.
690 ///To actually make a snapshot you must call save().
693 ///Constructor that immediately makes a snapshot
695 ///This constructor immediately makes a snapshot of the graph.
696 ///\param g The graph we make a snapshot of.
697 Snapshot(SmartUGraph &g) {
698 g.saveSnapshot(*this);
703 ///Make a snapshot of the graph.
705 ///This function can be called more than once. In case of a repeated
706 ///call, the previous snapshot gets lost.
707 ///\param g The graph we make the snapshot of.
708 void save(SmartUGraph &g)
710 g.saveSnapshot(*this);
713 ///Undo the changes until a snapshot.
715 ///Undo the changes until a snapshot created by save().
717 ///\note After you restored a state, you cannot restore
718 ///a later state, in other word you cannot add again the edges deleted
722 g->restoreSnapshot(*this);
728 class SmartBpUGraphBase {
731 class NodeSetError : public LogicError {
733 virtual const char* what() const throw() {
734 return "lemon::SmartBpUGraph::NodeSetError";
743 NodeT(int _first) : first(_first) {}
751 std::vector<NodeT> aNodes;
752 std::vector<NodeT> bNodes;
754 std::vector<UEdgeT> edges;
759 friend class SmartBpUGraphBase;
763 explicit Node(int _id) : id(_id) {}
766 Node(Invalid) : id(-1) {}
767 bool operator==(const Node i) const {return id==i.id;}
768 bool operator!=(const Node i) const {return id!=i.id;}
769 bool operator<(const Node i) const {return id<i.id;}
773 friend class SmartBpUGraphBase;
777 UEdge(int _id) : id(_id) {}
780 UEdge(Invalid) : id(-1) {}
781 bool operator==(const UEdge i) const {return id==i.id;}
782 bool operator!=(const UEdge i) const {return id!=i.id;}
783 bool operator<(const UEdge i) const {return id<i.id;}
786 void firstANode(Node& node) const {
787 node.id = 2 * aNodes.size() - 2;
788 if (node.id < 0) node.id = -1;
790 void nextANode(Node& node) const {
792 if (node.id < 0) node.id = -1;
795 void firstBNode(Node& node) const {
796 node.id = 2 * bNodes.size() - 1;
798 void nextBNode(Node& node) const {
802 void first(Node& node) const {
803 if (aNodes.size() > 0) {
804 node.id = 2 * aNodes.size() - 2;
806 node.id = 2 * bNodes.size() - 1;
809 void next(Node& node) const {
812 node.id = 2 * bNodes.size() - 1;
816 void first(UEdge& edge) const {
817 edge.id = edges.size() - 1;
819 void next(UEdge& edge) const {
823 void firstFromANode(UEdge& edge, const Node& node) const {
824 LEMON_ASSERT((node.id & 1) == 0, NodeSetError());
825 edge.id = aNodes[node.id >> 1].first;
827 void nextFromANode(UEdge& edge) const {
828 edge.id = edges[edge.id].next_out;
831 void firstFromBNode(UEdge& edge, const Node& node) const {
832 LEMON_ASSERT((node.id & 1) == 1, NodeSetError());
833 edge.id = bNodes[node.id >> 1].first;
835 void nextFromBNode(UEdge& edge) const {
836 edge.id = edges[edge.id].next_in;
839 static int id(const Node& node) {
842 static Node nodeFromId(int id) {
845 int maxNodeId() const {
846 return aNodes.size() > bNodes.size() ?
847 aNodes.size() * 2 - 2 : bNodes.size() * 2 - 1;
850 static int id(const UEdge& edge) {
853 static UEdge uEdgeFromId(int id) {
856 int maxUEdgeId() const {
860 static int aNodeId(const Node& node) {
863 static Node nodeFromANodeId(int id) {
864 return Node(id << 1);
866 int maxANodeId() const {
867 return aNodes.size();
870 static int bNodeId(const Node& node) {
873 static Node nodeFromBNodeId(int id) {
874 return Node((id << 1) + 1);
876 int maxBNodeId() const {
877 return bNodes.size();
880 Node aNode(const UEdge& edge) const {
881 return Node(edges[edge.id].aNode);
883 Node bNode(const UEdge& edge) const {
884 return Node(edges[edge.id].bNode);
887 static bool aNode(const Node& node) {
888 return (node.id & 1) == 0;
891 static bool bNode(const Node& node) {
892 return (node.id & 1) == 1;
898 aNodes.push_back(nodeT);
899 return Node(aNodes.size() * 2 - 2);
905 bNodes.push_back(nodeT);
906 return Node(bNodes.size() * 2 - 1);
909 UEdge addEdge(const Node& source, const Node& target) {
910 LEMON_ASSERT(((source.id ^ target.id) & 1) == 1, NodeSetError());
912 if ((source.id & 1) == 0) {
913 edgeT.aNode = source.id;
914 edgeT.bNode = target.id;
916 edgeT.aNode = target.id;
917 edgeT.bNode = source.id;
919 edgeT.next_out = aNodes[edgeT.aNode >> 1].first;
920 aNodes[edgeT.aNode >> 1].first = edges.size();
921 edgeT.next_in = bNodes[edgeT.bNode >> 1].first;
922 bNodes[edgeT.bNode >> 1].first = edges.size();
923 edges.push_back(edgeT);
924 return UEdge(edges.size() - 1);
933 typedef True NodeNumTag;
934 int nodeNum() const { return aNodes.size() + bNodes.size(); }
935 int aNodeNum() const { return aNodes.size(); }
936 int bNodeNum() const { return bNodes.size(); }
938 typedef True EdgeNumTag;
939 int uEdgeNum() const { return edges.size(); }
944 typedef BpUGraphExtender<BidirBpUGraphExtender<SmartBpUGraphBase> >
945 ExtendedSmartBpUGraphBase;
949 /// \brief A smart bipartite undirected graph class.
951 /// This is a simple and fast bipartite undirected graph implementation.
952 /// It is also quite memory efficient, but at the price
953 /// that <b> it does not support node and edge deletions</b>.
954 /// Except from this it conforms to
955 /// the \ref concepts::BpUGraph "BpUGraph concept".
958 ///important extra feature that
959 ///its maps are real \ref concepts::ReferenceMap "reference map"s.
961 /// \sa concepts::BpUGraph.
963 class SmartBpUGraph : public ExtendedSmartBpUGraphBase {
966 /// \brief SmartBpUGraph is \e not copy constructible.
968 ///SmartBpUGraph is \e not copy constructible.
969 SmartBpUGraph(const SmartBpUGraph &) : ExtendedSmartBpUGraphBase() {};
971 /// \brief Assignment of SmartBpUGraph to another one is \e not
974 /// Assignment of SmartBpUGraph to another one is \e not allowed.
975 void operator=(const SmartBpUGraph &) {}
979 typedef ExtendedSmartBpUGraphBase Parent;
985 SmartBpUGraph() : ExtendedSmartBpUGraphBase() {}
987 ///Add a new ANode to the graph.
989 /// \return the new node.
991 Node addANode() { return Parent::addANode(); }
993 ///Add a new BNode to the graph.
995 /// \return the new node.
997 Node addBNode() { return Parent::addBNode(); }
999 ///Add a new undirected edge to the graph.
1001 ///Add a new undirected edge to the graph with node \c s
1003 ///\return the new undirected edge.
1004 UEdge addEdge(const Node& s, const Node& t) {
1005 return Parent::addEdge(s, t);
1010 ///Erase all the nodes and edges from the graph.
1022 void restoreSnapshot(const Snapshot &s)
1024 while(s.edge_num<edges.size()) {
1025 UEdge edge = uEdgeFromId(edges.size()-1);
1026 Parent::getNotifier(UEdge()).erase(edge);
1027 std::vector<Edge> dir;
1028 dir.push_back(Parent::direct(edge, true));
1029 dir.push_back(Parent::direct(edge, false));
1030 Parent::getNotifier(Edge()).erase(dir);
1031 aNodes[edges.back().aNode >> 1].first=edges.back().next_out;
1032 bNodes[edges.back().bNode >> 1].first=edges.back().next_in;
1035 while(s.anode_num<aNodes.size()) {
1036 Node node = nodeFromANodeId(aNodes.size() - 1);
1037 Parent::getNotifier(ANode()).erase(node);
1038 Parent::getNotifier(Node()).erase(node);
1041 while(s.bnode_num<bNodes.size()) {
1042 Node node = nodeFromBNodeId(bNodes.size() - 1);
1043 Parent::getNotifier(BNode()).erase(node);
1044 Parent::getNotifier(Node()).erase(node);
1051 ///Class to make a snapshot of the graph and to restrore to it later.
1053 ///Class to make a snapshot of the graph and to restrore to it later.
1055 ///The newly added nodes and edges can be removed using the
1056 ///restore() function.
1058 ///\note After you restore a state, you cannot restore
1059 ///a later state, in other word you cannot add again the edges deleted
1060 ///by restore() using another one Snapshot instance.
1062 ///\warning If you do not use correctly the snapshot that can cause
1063 ///either broken program, invalid state of the graph, valid but
1064 ///not the restored graph or no change. Because the runtime performance
1065 ///the validity of the snapshot is not stored.
1070 friend class SmartBpUGraph;
1071 unsigned int anode_num;
1072 unsigned int bnode_num;
1073 unsigned int edge_num;
1075 ///Default constructor.
1077 ///Default constructor.
1078 ///To actually make a snapshot you must call save().
1080 Snapshot() : g(0) {}
1082 ///Constructor that immediately makes a snapshot
1084 ///This constructor immediately makes a snapshot of the graph.
1085 ///\param _g The graph we make a snapshot of.
1086 Snapshot(SmartBpUGraph &_g) : g(&_g) {
1087 anode_num=g->aNodes.size();
1088 bnode_num=g->bNodes.size();
1089 edge_num=g->edges.size();
1094 ///Make a snapshot of the graph.
1096 ///This function can be called more than once. In case of a repeated
1097 ///call, the previous snapshot gets lost.
1098 ///\param _g The graph we make the snapshot of.
1099 void save(SmartBpUGraph &_g)
1102 anode_num=g->aNodes.size();
1103 bnode_num=g->bNodes.size();
1104 edge_num=g->edges.size();
1107 ///Undo the changes until a snapshot.
1109 ///Undo the changes until a snapshot created by save().
1111 ///\note After you restored a state, you cannot restore
1112 ///a later state, in other word you cannot add again the edges deleted
1116 g->restoreSnapshot(*this);
1126 #endif //LEMON_SMART_GRAPH_H