3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2007
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::notifier(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::notifier(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;
516 void nextInc(UEdge &edge, bool& d) const {
517 int de = (edges[(edge.id * 2) | (d ? 1 : 0)].next_out);
527 static int id(Node v) { return v.id; }
528 static int id(Edge e) { return e.id; }
529 static int id(UEdge e) { return e.id; }
531 static Node nodeFromId(int id) { return Node(id);}
532 static Edge edgeFromId(int id) { return Edge(id);}
533 static UEdge uEdgeFromId(int id) { return UEdge(id);}
536 int n = nodes.size();
537 nodes.push_back(NodeT());
538 nodes[n].first_out = -1;
543 UEdge addEdge(Node u, Node v) {
544 int n = edges.size();
545 edges.push_back(EdgeT());
546 edges.push_back(EdgeT());
548 edges[n].target = u.id;
549 edges[n | 1].target = v.id;
551 edges[n].next_out = nodes[v.id].first_out;
552 edges[n | 1].next_out = nodes[u.id].first_out;
554 nodes[v.id].first_out = n;
555 nodes[u.id].first_out = (n | 1);
567 typedef UGraphExtender<SmartUGraphBase> ExtendedSmartUGraphBase;
571 /// \brief A smart undirected graph class.
573 /// This is a simple and fast undirected graph implementation.
574 /// It is also quite memory efficient, but at the price
575 /// that <b> it does support only limited (only stack-like)
576 /// node and edge deletions</b>.
577 /// Except from this it conforms to
578 /// the \ref concepts::UGraph "UGraph concept".
581 ///important extra feature that
582 ///its maps are real \ref concepts::ReferenceMap "reference map"s.
584 /// \sa concepts::UGraph.
586 class SmartUGraph : public ExtendedSmartUGraphBase {
589 ///SmartUGraph is \e not copy constructible. Use UGraphCopy() instead.
591 ///SmartUGraph is \e not copy constructible. Use UGraphCopy() instead.
593 SmartUGraph(const SmartUGraph &) : ExtendedSmartUGraphBase() {};
595 ///\brief Assignment of SmartUGraph to another one is \e not allowed.
596 ///Use UGraphCopy() instead.
598 ///Assignment of SmartUGraph to another one is \e not allowed.
599 ///Use UGraphCopy() instead.
600 void operator=(const SmartUGraph &) {}
604 typedef ExtendedSmartUGraphBase Parent;
605 typedef Parent::OutEdgeIt IncEdgeIt;
613 ///Add a new node to the graph.
615 /// \return the new node.
617 Node addNode() { return Parent::addNode(); }
619 ///Add a new undirected edge to the graph.
621 ///Add a new undirected edge to the graph with node \c s
623 ///\return the new undirected edge.
624 UEdge addEdge(const Node& s, const Node& t) {
625 return Parent::addEdge(s, t);
630 ///Erase all the nodes and edges from the graph.
642 void saveSnapshot(Snapshot &s)
645 s.node_num = nodes.size();
646 s.edge_num = edges.size();
649 void restoreSnapshot(const Snapshot &s)
651 while(s.edge_num<edges.size()) {
652 int n=edges.size()-1;
653 UEdge edge=uEdgeFromId(n/2);
654 Parent::notifier(UEdge()).erase(edge);
655 std::vector<Edge> dir;
656 dir.push_back(edgeFromId(n));
657 dir.push_back(edgeFromId(n-1));
658 Parent::notifier(Edge()).erase(dir);
659 nodes[edges[n].target].first_out=edges[n].next_out;
660 nodes[edges[n-1].target].first_out=edges[n-1].next_out;
664 while(s.node_num<nodes.size()) {
665 int n=nodes.size()-1;
666 Node node = nodeFromId(n);
667 Parent::notifier(Node()).erase(node);
674 ///Class to make a snapshot of the graph and to restrore to it later.
676 ///Class to make a snapshot of the graph and to restrore to it later.
678 ///The newly added nodes and edges can be removed using the
679 ///restore() function.
681 ///\note After you restore a state, you cannot restore
682 ///a later state, in other word you cannot add again the edges deleted
683 ///by restore() using another one Snapshot instance.
685 ///\warning If you do not use correctly the snapshot that can cause
686 ///either broken program, invalid state of the graph, valid but
687 ///not the restored graph or no change. Because the runtime performance
688 ///the validity of the snapshot is not stored.
693 friend class SmartUGraph;
694 unsigned int node_num;
695 unsigned int edge_num;
697 ///Default constructor.
699 ///Default constructor.
700 ///To actually make a snapshot you must call save().
702 Snapshot() : graph(0) {}
703 ///Constructor that immediately makes a snapshot
705 ///This constructor immediately makes a snapshot of the graph.
706 ///\param g The graph we make a snapshot of.
707 Snapshot(SmartUGraph &g) {
708 g.saveSnapshot(*this);
713 ///Make a snapshot of the graph.
715 ///This function can be called more than once. In case of a repeated
716 ///call, the previous snapshot gets lost.
717 ///\param g The graph we make the snapshot of.
718 void save(SmartUGraph &g)
720 g.saveSnapshot(*this);
723 ///Undo the changes until a snapshot.
725 ///Undo the changes until a snapshot created by save().
727 ///\note After you restored a state, you cannot restore
728 ///a later state, in other word you cannot add again the edges deleted
732 graph->restoreSnapshot(*this);
738 class SmartBpUGraphBase {
741 class NodeSetError : public LogicError {
743 virtual const char* what() const throw() {
744 return "lemon::SmartBpUGraph::NodeSetError";
753 NodeT(int _first) : first(_first) {}
761 std::vector<NodeT> aNodes;
762 std::vector<NodeT> bNodes;
764 std::vector<UEdgeT> edges;
769 friend class SmartBpUGraphBase;
773 explicit Node(int _id) : id(_id) {}
776 Node(Invalid) : id(-1) {}
777 bool operator==(const Node i) const {return id==i.id;}
778 bool operator!=(const Node i) const {return id!=i.id;}
779 bool operator<(const Node i) const {return id<i.id;}
783 friend class SmartBpUGraphBase;
787 UEdge(int _id) : id(_id) {}
790 UEdge(Invalid) : id(-1) {}
791 bool operator==(const UEdge i) const {return id==i.id;}
792 bool operator!=(const UEdge i) const {return id!=i.id;}
793 bool operator<(const UEdge i) const {return id<i.id;}
796 void firstANode(Node& node) const {
797 node.id = 2 * aNodes.size() - 2;
798 if (node.id < 0) node.id = -1;
800 void nextANode(Node& node) const {
802 if (node.id < 0) node.id = -1;
805 void firstBNode(Node& node) const {
806 node.id = 2 * bNodes.size() - 1;
808 void nextBNode(Node& node) const {
812 void first(Node& node) const {
813 if (aNodes.size() > 0) {
814 node.id = 2 * aNodes.size() - 2;
816 node.id = 2 * bNodes.size() - 1;
819 void next(Node& node) const {
822 node.id = 2 * bNodes.size() - 1;
826 void first(UEdge& edge) const {
827 edge.id = edges.size() - 1;
829 void next(UEdge& edge) const {
833 void firstFromANode(UEdge& edge, const Node& node) const {
834 LEMON_ASSERT((node.id & 1) == 0, NodeSetError());
835 edge.id = aNodes[node.id >> 1].first;
837 void nextFromANode(UEdge& edge) const {
838 edge.id = edges[edge.id].next_out;
841 void firstFromBNode(UEdge& edge, const Node& node) const {
842 LEMON_ASSERT((node.id & 1) == 1, NodeSetError());
843 edge.id = bNodes[node.id >> 1].first;
845 void nextFromBNode(UEdge& edge) const {
846 edge.id = edges[edge.id].next_in;
849 static int id(const Node& node) {
852 static Node nodeFromId(int id) {
855 int maxNodeId() const {
856 return aNodes.size() > bNodes.size() ?
857 aNodes.size() * 2 - 2 : bNodes.size() * 2 - 1;
860 static int id(const UEdge& edge) {
863 static UEdge uEdgeFromId(int id) {
866 int maxUEdgeId() const {
870 static int aNodeId(const Node& node) {
873 static Node nodeFromANodeId(int id) {
874 return Node(id << 1);
876 int maxANodeId() const {
877 return aNodes.size();
880 static int bNodeId(const Node& node) {
883 static Node nodeFromBNodeId(int id) {
884 return Node((id << 1) + 1);
886 int maxBNodeId() const {
887 return bNodes.size();
890 Node aNode(const UEdge& edge) const {
891 return Node(edges[edge.id].aNode);
893 Node bNode(const UEdge& edge) const {
894 return Node(edges[edge.id].bNode);
897 static bool aNode(const Node& node) {
898 return (node.id & 1) == 0;
901 static bool bNode(const Node& node) {
902 return (node.id & 1) == 1;
908 aNodes.push_back(nodeT);
909 return Node(aNodes.size() * 2 - 2);
915 bNodes.push_back(nodeT);
916 return Node(bNodes.size() * 2 - 1);
919 UEdge addEdge(const Node& source, const Node& target) {
920 LEMON_ASSERT(((source.id ^ target.id) & 1) == 1, NodeSetError());
922 if ((source.id & 1) == 0) {
923 edgeT.aNode = source.id;
924 edgeT.bNode = target.id;
926 edgeT.aNode = target.id;
927 edgeT.bNode = source.id;
929 edgeT.next_out = aNodes[edgeT.aNode >> 1].first;
930 aNodes[edgeT.aNode >> 1].first = edges.size();
931 edgeT.next_in = bNodes[edgeT.bNode >> 1].first;
932 bNodes[edgeT.bNode >> 1].first = edges.size();
933 edges.push_back(edgeT);
934 return UEdge(edges.size() - 1);
943 typedef True NodeNumTag;
944 int nodeNum() const { return aNodes.size() + bNodes.size(); }
945 int aNodeNum() const { return aNodes.size(); }
946 int bNodeNum() const { return bNodes.size(); }
948 typedef True EdgeNumTag;
949 int uEdgeNum() const { return edges.size(); }
954 typedef BpUGraphExtender<BidirBpUGraphExtender<SmartBpUGraphBase> >
955 ExtendedSmartBpUGraphBase;
959 /// \brief A smart bipartite undirected graph class.
961 /// This is a simple and fast bipartite undirected graph implementation.
962 /// It is also quite memory efficient, but at the price
963 /// that <b> it does not support node and edge deletions</b>.
964 /// Except from this it conforms to
965 /// the \ref concepts::BpUGraph "BpUGraph concept".
968 ///important extra feature that
969 ///its maps are real \ref concepts::ReferenceMap "reference map"s.
971 /// \sa concepts::BpUGraph.
973 class SmartBpUGraph : public ExtendedSmartBpUGraphBase {
976 /// \brief SmartBpUGraph is \e not copy constructible.
978 ///SmartBpUGraph is \e not copy constructible.
979 SmartBpUGraph(const SmartBpUGraph &) : ExtendedSmartBpUGraphBase() {};
981 /// \brief Assignment of SmartBpUGraph to another one is \e not
984 /// Assignment of SmartBpUGraph to another one is \e not allowed.
985 void operator=(const SmartBpUGraph &) {}
989 typedef ExtendedSmartBpUGraphBase Parent;
995 SmartBpUGraph() : ExtendedSmartBpUGraphBase() {}
997 ///Add a new ANode to the graph.
999 /// \return the new node.
1001 Node addANode() { return Parent::addANode(); }
1003 ///Add a new BNode to the graph.
1005 /// \return the new node.
1007 Node addBNode() { return Parent::addBNode(); }
1009 ///Add a new undirected edge to the graph.
1011 ///Add a new undirected edge to the graph with node \c s
1013 ///\return the new undirected edge.
1014 UEdge addEdge(const Node& s, const Node& t) {
1015 return Parent::addEdge(s, t);
1020 ///Erase all the nodes and edges from the graph.
1032 void restoreSnapshot(const Snapshot &s)
1034 while(s.edge_num<edges.size()) {
1035 UEdge edge = uEdgeFromId(edges.size()-1);
1036 Parent::notifier(UEdge()).erase(edge);
1037 std::vector<Edge> dir;
1038 dir.push_back(Parent::direct(edge, true));
1039 dir.push_back(Parent::direct(edge, false));
1040 Parent::notifier(Edge()).erase(dir);
1041 aNodes[edges.back().aNode >> 1].first=edges.back().next_out;
1042 bNodes[edges.back().bNode >> 1].first=edges.back().next_in;
1045 while(s.anode_num<aNodes.size()) {
1046 Node node = nodeFromANodeId(aNodes.size() - 1);
1047 Parent::notifier(ANode()).erase(node);
1048 Parent::notifier(Node()).erase(node);
1051 while(s.bnode_num<bNodes.size()) {
1052 Node node = nodeFromBNodeId(bNodes.size() - 1);
1053 Parent::notifier(BNode()).erase(node);
1054 Parent::notifier(Node()).erase(node);
1061 ///Class to make a snapshot of the graph and to restrore to it later.
1063 ///Class to make a snapshot of the graph and to restrore to it later.
1065 ///The newly added nodes and edges can be removed using the
1066 ///restore() function.
1068 ///\note After you restore a state, you cannot restore
1069 ///a later state, in other word you cannot add again the edges deleted
1070 ///by restore() using another one Snapshot instance.
1072 ///\warning If you do not use correctly the snapshot that can cause
1073 ///either broken program, invalid state of the graph, valid but
1074 ///not the restored graph or no change. Because the runtime performance
1075 ///the validity of the snapshot is not stored.
1080 friend class SmartBpUGraph;
1081 unsigned int anode_num;
1082 unsigned int bnode_num;
1083 unsigned int edge_num;
1085 ///Default constructor.
1087 ///Default constructor.
1088 ///To actually make a snapshot you must call save().
1090 Snapshot() : g(0) {}
1092 ///Constructor that immediately makes a snapshot
1094 ///This constructor immediately makes a snapshot of the graph.
1095 ///\param _g The graph we make a snapshot of.
1096 Snapshot(SmartBpUGraph &_g) : g(&_g) {
1097 anode_num=g->aNodes.size();
1098 bnode_num=g->bNodes.size();
1099 edge_num=g->edges.size();
1104 ///Make a snapshot of the graph.
1106 ///This function can be called more than once. In case of a repeated
1107 ///call, the previous snapshot gets lost.
1108 ///\param _g The graph we make the snapshot of.
1109 void save(SmartBpUGraph &_g)
1112 anode_num=g->aNodes.size();
1113 bnode_num=g->bNodes.size();
1114 edge_num=g->edges.size();
1117 ///Undo the changes until a snapshot.
1119 ///Undo the changes until a snapshot created by save().
1121 ///\note After you restored a state, you cannot restore
1122 ///a later state, in other word you cannot add again the edges deleted
1126 g->restoreSnapshot(*this);
1136 #endif //LEMON_SMART_GRAPH_H