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;
392 friend class SmartUGraphBase;
396 explicit Node(int pid) { id = pid;}
400 Node (Invalid) { id = -1; }
401 bool operator==(const Node& node) const {return id == node.id;}
402 bool operator!=(const Node& node) const {return id != node.id;}
403 bool operator<(const Node& node) const {return id < node.id;}
407 friend class SmartUGraphBase;
411 explicit UEdge(int pid) { id = pid;}
415 UEdge (Invalid) { id = -1; }
416 bool operator==(const UEdge& edge) const {return id == edge.id;}
417 bool operator!=(const UEdge& edge) const {return id != edge.id;}
418 bool operator<(const UEdge& edge) const {return id < edge.id;}
422 friend class SmartUGraphBase;
426 explicit Edge(int pid) { id = pid;}
429 operator UEdge() const { return UEdge(id / 2); }
432 Edge (Invalid) { id = -1; }
433 bool operator==(const Edge& edge) const {return id == edge.id;}
434 bool operator!=(const Edge& edge) const {return id != edge.id;}
435 bool operator<(const Edge& edge) const {return id < edge.id;}
441 : nodes(), edges() {}
444 int maxNodeId() const { return nodes.size()-1; }
445 int maxUEdgeId() const { return edges.size() / 2 - 1; }
446 int maxEdgeId() const { return edges.size()-1; }
448 Node source(Edge e) const { return Node(edges[e.id ^ 1].target); }
449 Node target(Edge e) const { return Node(edges[e.id].target); }
451 Node source(UEdge e) const { return Node(edges[2 * e.id].target); }
452 Node target(UEdge e) const { return Node(edges[2 * e.id + 1].target); }
454 static bool direction(Edge e) {
455 return (e.id & 1) == 1;
458 static Edge direct(UEdge e, bool d) {
459 return Edge(e.id * 2 + (d ? 1 : 0));
462 void first(Node& node) const {
463 node.id = nodes.size() - 1;
466 void next(Node& node) const {
470 void first(Edge& edge) const {
471 edge.id = edges.size() - 1;
474 void next(Edge& edge) const {
478 void first(UEdge& edge) const {
479 edge.id = edges.size() / 2 - 1;
482 void next(UEdge& edge) const {
486 void firstOut(Edge &edge, const Node& v) const {
487 edge.id = nodes[v.id].first_out;
489 void nextOut(Edge &edge) const {
490 edge.id = edges[edge.id].next_out;
493 void firstIn(Edge &edge, const Node& v) const {
494 edge.id = ((nodes[v.id].first_out) ^ 1);
495 if (e.id == -2) e.id = -1;
497 void nextIn(Edge &edge) const {
498 edge.id = ((edges[edge.id ^ 1].next_out) ^ 1);
499 if (e.id == -2) e.id = -1;
502 void firstInc(UEdge &edge, bool& d, const Node& v) const {
503 int de = nodes[v.id].first_out;
507 void nextInc(UEdge &edge, bool& d) const {
508 int de = (edges[(edge.id * 2) | (d ? 1 : 0)].next_out);
513 static int id(Node v) { return v.id; }
514 static int id(Edge e) { return e.id; }
515 static int id(UEdge e) { return e.id; }
517 static Node nodeFromId(int id) { return Node(id);}
518 static Edge edgeFromId(int id) { return Edge(id);}
519 static UEdge uEdgeFromId(int id) { return UEdge(id);}
522 int n = nodes.size();
523 nodes.push_back(NodeT());
524 nodes[n].first_out = -1;
529 UEdge addEdge(Node u, Node v) {
530 int n = edges.size();
531 edges.push_back(EdgeT());
532 edges.push_back(EdgeT());
534 edges[n].target = u.id;
535 edges[n | 1].target = v.id;
537 edges[n].next_out = nodes[v.id].first_out;
538 edges[n | 1].next_out = nodes[u.id].first_out;
540 nodes[v.id].first_out = n;
541 nodes[u.id].first_out = (n | 1);
553 typedef UGraphExtender<SmartUGraphBase> ExtendedSmartUGraphBase;
557 /// \brief A smart undirected graph class.
559 /// This is a simple and fast undirected graph implementation.
560 /// It is also quite memory efficient, but at the price
561 /// that <b> it does support only limited (only stack-like)
562 /// node and edge deletions</b>.
563 /// Except from this it conforms to
564 /// the \ref concepts::UGraph "UGraph concept".
567 ///important extra feature that
568 ///its maps are real \ref concepts::ReferenceMap "reference map"s.
570 /// \sa concepts::UGraph.
572 class SmartUGraph : public ExtendedSmartUGraphBase {
575 ///SmartUGraph is \e not copy constructible. Use UGraphCopy() instead.
577 ///SmartUGraph is \e not copy constructible. Use UGraphCopy() instead.
579 SmartUGraph(const SmartUGraph &) : ExtendedSmartUGraphBase() {};
581 ///\brief Assignment of SmartUGraph to another one is \e not allowed.
582 ///Use UGraphCopy() instead.
584 ///Assignment of SmartUGraph to another one is \e not allowed.
585 ///Use UGraphCopy() instead.
586 void operator=(const SmartUGraph &) {}
590 typedef ExtendedSmartUGraphBase Parent;
591 typedef Parent::OutEdgeIt IncEdgeIt;
599 ///Add a new node to the graph.
601 /// \return the new node.
603 Node addNode() { return Parent::addNode(); }
605 ///Add a new undirected edge to the graph.
607 ///Add a new undirected edge to the graph with node \c s
609 ///\return the new undirected edge.
610 UEdge addEdge(const Node& s, const Node& t) {
611 return Parent::addEdge(s, t);
616 ///Erase all the nodes and edges from the graph.
628 void saveSnapshot(Snapshot &s)
631 s.node_num = nodes.size();
632 s.edge_num = edges.size();
635 void restoreSnapshot(const Snapshot &s)
637 while(s.edge_num<edges.size()) {
638 int n=edges.size()-1;
639 UEdge edge=uEdgeFromId(n/2);
640 Parent::getNotifier(UEdge()).erase(edge);
641 std::vector<Edge> dir;
642 dir.push_back(edgeFromId(n));
643 dir.push_back(edgeFromId(n-1));
644 Parent::getNotifier(Edge()).erase(dir);
645 nodes[edges[n].target].first_out=edges[n].next_out;
646 nodes[edges[n-1].target].first_out=edges[n-1].next_out;
650 while(s.node_num<nodes.size()) {
651 int n=nodes.size()-1;
652 Node node = nodeFromId(n);
653 Parent::getNotifier(Node()).erase(node);
660 ///Class to make a snapshot of the graph and to restrore to it later.
662 ///Class to make a snapshot of the graph and to restrore to it later.
664 ///The newly added nodes and edges can be removed using the
665 ///restore() function.
667 ///\note After you restore a state, you cannot restore
668 ///a later state, in other word you cannot add again the edges deleted
669 ///by restore() using another one Snapshot instance.
671 ///\warning If you do not use correctly the snapshot that can cause
672 ///either broken program, invalid state of the graph, valid but
673 ///not the restored graph or no change. Because the runtime performance
674 ///the validity of the snapshot is not stored.
679 friend class SmartUGraph;
680 unsigned int node_num;
681 unsigned int edge_num;
683 ///Default constructor.
685 ///Default constructor.
686 ///To actually make a snapshot you must call save().
689 ///Constructor that immediately makes a snapshot
691 ///This constructor immediately makes a snapshot of the graph.
692 ///\param _g The graph we make a snapshot of.
693 Snapshot(SmartUGraph &g) {
694 g.saveSnapshot(*this);
699 ///Make a snapshot of the graph.
701 ///This function can be called more than once. In case of a repeated
702 ///call, the previous snapshot gets lost.
703 ///\param _g The graph we make the snapshot of.
704 void save(SmartUGraph &g)
706 g.saveSnapshot(*this);
709 ///Undo the changes until a snapshot.
711 ///Undo the changes until a snapshot created by save().
713 ///\note After you restored a state, you cannot restore
714 ///a later state, in other word you cannot add again the edges deleted
718 g->restoreSnapshot(*this);
724 class SmartBpUGraphBase {
727 class NodeSetError : public LogicError {
729 virtual const char* what() const throw() {
730 return "lemon::SmartBpUGraph::NodeSetError";
739 NodeT(int _first) : first(_first) {}
747 std::vector<NodeT> aNodes;
748 std::vector<NodeT> bNodes;
750 std::vector<UEdgeT> edges;
755 friend class SmartBpUGraphBase;
759 explicit Node(int _id) : id(_id) {}
762 Node(Invalid) : id(-1) {}
763 bool operator==(const Node i) const {return id==i.id;}
764 bool operator!=(const Node i) const {return id!=i.id;}
765 bool operator<(const Node i) const {return id<i.id;}
769 friend class SmartBpUGraphBase;
773 UEdge(int _id) : id(_id) {}
776 UEdge(Invalid) : id(-1) {}
777 bool operator==(const UEdge i) const {return id==i.id;}
778 bool operator!=(const UEdge i) const {return id!=i.id;}
779 bool operator<(const UEdge i) const {return id<i.id;}
782 void firstANode(Node& node) const {
783 node.id = 2 * aNodes.size() - 2;
784 if (node.id < 0) node.id = -1;
786 void nextANode(Node& node) const {
788 if (node.id < 0) node.id = -1;
791 void firstBNode(Node& node) const {
792 node.id = 2 * bNodes.size() - 1;
794 void nextBNode(Node& node) const {
798 void first(Node& node) const {
799 if (aNodes.size() > 0) {
800 node.id = 2 * aNodes.size() - 2;
802 node.id = 2 * bNodes.size() - 1;
805 void next(Node& node) const {
808 node.id = 2 * bNodes.size() - 1;
812 void first(UEdge& edge) const {
813 edge.id = edges.size() - 1;
815 void next(UEdge& edge) const {
819 void firstFromANode(UEdge& edge, const Node& node) const {
820 LEMON_ASSERT((node.id & 1) == 0, NodeSetError());
821 edge.id = aNodes[node.id >> 1].first;
823 void nextFromANode(UEdge& edge) const {
824 edge.id = edges[edge.id].next_out;
827 void firstFromBNode(UEdge& edge, const Node& node) const {
828 LEMON_ASSERT((node.id & 1) == 1, NodeSetError());
829 edge.id = bNodes[node.id >> 1].first;
831 void nextFromBNode(UEdge& edge) const {
832 edge.id = edges[edge.id].next_in;
835 static int id(const Node& node) {
838 static Node nodeFromId(int id) {
841 int maxNodeId() const {
842 return aNodes.size() > bNodes.size() ?
843 aNodes.size() * 2 - 2 : bNodes.size() * 2 - 1;
846 static int id(const UEdge& edge) {
849 static UEdge uEdgeFromId(int id) {
852 int maxUEdgeId() const {
856 static int aNodeId(const Node& node) {
859 static Node nodeFromANodeId(int id) {
860 return Node(id << 1);
862 int maxANodeId() const {
863 return aNodes.size();
866 static int bNodeId(const Node& node) {
869 static Node nodeFromBNodeId(int id) {
870 return Node((id << 1) + 1);
872 int maxBNodeId() const {
873 return bNodes.size();
876 Node aNode(const UEdge& edge) const {
877 return Node(edges[edge.id].aNode);
879 Node bNode(const UEdge& edge) const {
880 return Node(edges[edge.id].bNode);
883 static bool aNode(const Node& node) {
884 return (node.id & 1) == 0;
887 static bool bNode(const Node& node) {
888 return (node.id & 1) == 1;
894 aNodes.push_back(nodeT);
895 return Node(aNodes.size() * 2 - 2);
901 bNodes.push_back(nodeT);
902 return Node(bNodes.size() * 2 - 1);
905 UEdge addEdge(const Node& source, const Node& target) {
906 LEMON_ASSERT(((source.id ^ target.id) & 1) == 1, NodeSetError());
908 if ((source.id & 1) == 0) {
909 edgeT.aNode = source.id;
910 edgeT.bNode = target.id;
912 edgeT.aNode = target.id;
913 edgeT.bNode = source.id;
915 edgeT.next_out = aNodes[edgeT.aNode >> 1].first;
916 aNodes[edgeT.aNode >> 1].first = edges.size();
917 edgeT.next_in = bNodes[edgeT.bNode >> 1].first;
918 bNodes[edgeT.bNode >> 1].first = edges.size();
919 edges.push_back(edgeT);
920 return UEdge(edges.size() - 1);
929 typedef True NodeNumTag;
930 int nodeNum() const { return aNodes.size() + bNodes.size(); }
931 int aNodeNum() const { return aNodes.size(); }
932 int bNodeNum() const { return bNodes.size(); }
934 typedef True EdgeNumTag;
935 int uEdgeNum() const { return edges.size(); }
940 typedef BpUGraphExtender<BidirBpUGraphExtender<SmartBpUGraphBase> >
941 ExtendedSmartBpUGraphBase;
945 /// \brief A smart bipartite undirected graph class.
947 /// This is a simple and fast bipartite undirected graph implementation.
948 /// It is also quite memory efficient, but at the price
949 /// that <b> it does not support node and edge deletions</b>.
950 /// Except from this it conforms to
951 /// the \ref concepts::BpUGraph "BpUGraph concept".
954 ///important extra feature that
955 ///its maps are real \ref concepts::ReferenceMap "reference map"s.
957 /// \sa concepts::BpUGraph.
959 class SmartBpUGraph : public ExtendedSmartBpUGraphBase {
962 /// \brief SmartBpUGraph is \e not copy constructible.
964 ///SmartBpUGraph is \e not copy constructible.
965 SmartBpUGraph(const SmartBpUGraph &) : ExtendedSmartBpUGraphBase() {};
967 /// \brief Assignment of SmartBpUGraph to another one is \e not
970 /// Assignment of SmartBpUGraph to another one is \e not allowed.
971 void operator=(const SmartBpUGraph &) {}
975 typedef ExtendedSmartBpUGraphBase Parent;
981 SmartBpUGraph() : ExtendedSmartBpUGraphBase() {}
983 ///Add a new ANode to the graph.
985 /// \return the new node.
987 Node addANode() { return Parent::addANode(); }
989 ///Add a new BNode to the graph.
991 /// \return the new node.
993 Node addBNode() { return Parent::addBNode(); }
995 ///Add a new undirected edge to the graph.
997 ///Add a new undirected edge to the graph with node \c s
999 ///\return the new undirected edge.
1000 UEdge addEdge(const Node& s, const Node& t) {
1001 return Parent::addEdge(s, t);
1006 ///Erase all the nodes and edges from the graph.
1018 void restoreSnapshot(const Snapshot &s)
1020 while(s.edge_num<edges.size()) {
1021 UEdge edge = uEdgeFromId(edges.size()-1);
1022 Parent::getNotifier(UEdge()).erase(edge);
1023 std::vector<Edge> dir;
1024 dir.push_back(Parent::direct(edge, true));
1025 dir.push_back(Parent::direct(edge, false));
1026 Parent::getNotifier(Edge()).erase(dir);
1027 aNodes[edges.back().aNode >> 1].first=edges.back().next_out;
1028 bNodes[edges.back().bNode >> 1].first=edges.back().next_in;
1031 while(s.anode_num<aNodes.size()) {
1032 Node node = nodeFromANodeId(aNodes.size() - 1);
1033 Parent::getNotifier(ANode()).erase(node);
1034 Parent::getNotifier(Node()).erase(node);
1037 while(s.bnode_num<bNodes.size()) {
1038 Node node = nodeFromBNodeId(bNodes.size() - 1);
1039 Parent::getNotifier(BNode()).erase(node);
1040 Parent::getNotifier(Node()).erase(node);
1047 ///Class to make a snapshot of the graph and to restrore to it later.
1049 ///Class to make a snapshot of the graph and to restrore to it later.
1051 ///The newly added nodes and edges can be removed using the
1052 ///restore() function.
1054 ///\note After you restore a state, you cannot restore
1055 ///a later state, in other word you cannot add again the edges deleted
1056 ///by restore() using another one Snapshot instance.
1058 ///\warning If you do not use correctly the snapshot that can cause
1059 ///either broken program, invalid state of the graph, valid but
1060 ///not the restored graph or no change. Because the runtime performance
1061 ///the validity of the snapshot is not stored.
1066 friend class SmartBpUGraph;
1067 unsigned int anode_num;
1068 unsigned int bnode_num;
1069 unsigned int edge_num;
1071 ///Default constructor.
1073 ///Default constructor.
1074 ///To actually make a snapshot you must call save().
1076 Snapshot() : g(0) {}
1078 ///Constructor that immediately makes a snapshot
1080 ///This constructor immediately makes a snapshot of the graph.
1081 ///\param _g The graph we make a snapshot of.
1082 Snapshot(SmartBpUGraph &_g) : g(&_g) {
1083 anode_num=g->aNodes.size();
1084 bnode_num=g->bNodes.size();
1085 edge_num=g->edges.size();
1090 ///Make a snapshot of the graph.
1092 ///This function can be called more than once. In case of a repeated
1093 ///call, the previous snapshot gets lost.
1094 ///\param _g The graph we make the snapshot of.
1095 void save(SmartBpUGraph &_g)
1098 anode_num=g->aNodes.size();
1099 bnode_num=g->bNodes.size();
1100 edge_num=g->edges.size();
1103 ///Undo the changes until a snapshot.
1105 ///Undo the changes until a snapshot created by save().
1107 ///\note After you restored a state, you cannot restore
1108 ///a later state, in other word you cannot add again the edges deleted
1112 g->restoreSnapshot(*this);
1122 #endif //LEMON_SMART_GRAPH_H