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;
412 friend class SmartUGraphBase::Edge;
416 explicit UEdge(int pid) { id = pid;}
420 UEdge (Invalid) { id = -1; }
421 bool operator==(const UEdge& edge) const {return id == edge.id;}
422 bool operator!=(const UEdge& edge) const {return id != edge.id;}
423 bool operator<(const UEdge& edge) const {return id < edge.id;}
427 friend class SmartUGraphBase;
431 explicit Edge(int pid) { id = pid;}
434 operator UEdge() const { return UEdge(id / 2); }
437 Edge (Invalid) { id = -1; }
438 bool operator==(const Edge& edge) const {return id == edge.id;}
439 bool operator!=(const Edge& edge) const {return id != edge.id;}
440 bool operator<(const Edge& edge) const {return id < edge.id;}
446 : nodes(), edges() {}
449 int maxNodeId() const { return nodes.size()-1; }
450 int maxUEdgeId() const { return edges.size() / 2 - 1; }
451 int maxEdgeId() const { return edges.size()-1; }
453 Node source(Edge e) const { return Node(edges[e.id ^ 1].target); }
454 Node target(Edge e) const { return Node(edges[e.id].target); }
456 Node source(UEdge e) const { return Node(edges[2 * e.id].target); }
457 Node target(UEdge e) const { return Node(edges[2 * e.id + 1].target); }
459 static bool direction(Edge e) {
460 return (e.id & 1) == 1;
463 static Edge direct(UEdge e, bool d) {
464 return Edge(e.id * 2 + (d ? 1 : 0));
467 void first(Node& node) const {
468 node.id = nodes.size() - 1;
471 void next(Node& node) const {
475 void first(Edge& edge) const {
476 edge.id = edges.size() - 1;
479 void next(Edge& edge) const {
483 void first(UEdge& edge) const {
484 edge.id = edges.size() / 2 - 1;
487 void next(UEdge& edge) const {
491 void firstOut(Edge &edge, const Node& v) const {
492 edge.id = nodes[v.id].first_out;
494 void nextOut(Edge &edge) const {
495 edge.id = edges[edge.id].next_out;
498 void firstIn(Edge &edge, const Node& v) const {
499 edge.id = ((nodes[v.id].first_out) ^ 1);
500 if (edge.id == -2) edge.id = -1;
502 void nextIn(Edge &edge) const {
503 edge.id = ((edges[edge.id ^ 1].next_out) ^ 1);
504 if (edge.id == -2) edge.id = -1;
507 void firstInc(UEdge &edge, bool& d, const Node& v) const {
508 int de = nodes[v.id].first_out;
512 void nextInc(UEdge &edge, bool& d) const {
513 int de = (edges[(edge.id * 2) | (d ? 1 : 0)].next_out);
518 static int id(Node v) { return v.id; }
519 static int id(Edge e) { return e.id; }
520 static int id(UEdge e) { return e.id; }
522 static Node nodeFromId(int id) { return Node(id);}
523 static Edge edgeFromId(int id) { return Edge(id);}
524 static UEdge uEdgeFromId(int id) { return UEdge(id);}
527 int n = nodes.size();
528 nodes.push_back(NodeT());
529 nodes[n].first_out = -1;
534 UEdge addEdge(Node u, Node v) {
535 int n = edges.size();
536 edges.push_back(EdgeT());
537 edges.push_back(EdgeT());
539 edges[n].target = u.id;
540 edges[n | 1].target = v.id;
542 edges[n].next_out = nodes[v.id].first_out;
543 edges[n | 1].next_out = nodes[u.id].first_out;
545 nodes[v.id].first_out = n;
546 nodes[u.id].first_out = (n | 1);
558 typedef UGraphExtender<SmartUGraphBase> ExtendedSmartUGraphBase;
562 /// \brief A smart undirected graph class.
564 /// This is a simple and fast undirected graph implementation.
565 /// It is also quite memory efficient, but at the price
566 /// that <b> it does support only limited (only stack-like)
567 /// node and edge deletions</b>.
568 /// Except from this it conforms to
569 /// the \ref concepts::UGraph "UGraph concept".
572 ///important extra feature that
573 ///its maps are real \ref concepts::ReferenceMap "reference map"s.
575 /// \sa concepts::UGraph.
577 class SmartUGraph : public ExtendedSmartUGraphBase {
580 ///SmartUGraph is \e not copy constructible. Use UGraphCopy() instead.
582 ///SmartUGraph is \e not copy constructible. Use UGraphCopy() instead.
584 SmartUGraph(const SmartUGraph &) : ExtendedSmartUGraphBase() {};
586 ///\brief Assignment of SmartUGraph to another one is \e not allowed.
587 ///Use UGraphCopy() instead.
589 ///Assignment of SmartUGraph to another one is \e not allowed.
590 ///Use UGraphCopy() instead.
591 void operator=(const SmartUGraph &) {}
595 typedef ExtendedSmartUGraphBase Parent;
596 typedef Parent::OutEdgeIt IncEdgeIt;
604 ///Add a new node to the graph.
606 /// \return the new node.
608 Node addNode() { return Parent::addNode(); }
610 ///Add a new undirected edge to the graph.
612 ///Add a new undirected edge to the graph with node \c s
614 ///\return the new undirected edge.
615 UEdge addEdge(const Node& s, const Node& t) {
616 return Parent::addEdge(s, t);
621 ///Erase all the nodes and edges from the graph.
633 void saveSnapshot(Snapshot &s)
636 s.node_num = nodes.size();
637 s.edge_num = edges.size();
640 void restoreSnapshot(const Snapshot &s)
642 while(s.edge_num<edges.size()) {
643 int n=edges.size()-1;
644 UEdge edge=uEdgeFromId(n/2);
645 Parent::getNotifier(UEdge()).erase(edge);
646 std::vector<Edge> dir;
647 dir.push_back(edgeFromId(n));
648 dir.push_back(edgeFromId(n-1));
649 Parent::getNotifier(Edge()).erase(dir);
650 nodes[edges[n].target].first_out=edges[n].next_out;
651 nodes[edges[n-1].target].first_out=edges[n-1].next_out;
655 while(s.node_num<nodes.size()) {
656 int n=nodes.size()-1;
657 Node node = nodeFromId(n);
658 Parent::getNotifier(Node()).erase(node);
665 ///Class to make a snapshot of the graph and to restrore to it later.
667 ///Class to make a snapshot of the graph and to restrore to it later.
669 ///The newly added nodes and edges can be removed using the
670 ///restore() function.
672 ///\note After you restore a state, you cannot restore
673 ///a later state, in other word you cannot add again the edges deleted
674 ///by restore() using another one Snapshot instance.
676 ///\warning If you do not use correctly the snapshot that can cause
677 ///either broken program, invalid state of the graph, valid but
678 ///not the restored graph or no change. Because the runtime performance
679 ///the validity of the snapshot is not stored.
684 friend class SmartUGraph;
685 unsigned int node_num;
686 unsigned int edge_num;
688 ///Default constructor.
690 ///Default constructor.
691 ///To actually make a snapshot you must call save().
694 ///Constructor that immediately makes a snapshot
696 ///This constructor immediately makes a snapshot of the graph.
697 ///\param _g The graph we make a snapshot of.
698 Snapshot(SmartUGraph &g) {
699 g.saveSnapshot(*this);
704 ///Make a snapshot of the graph.
706 ///This function can be called more than once. In case of a repeated
707 ///call, the previous snapshot gets lost.
708 ///\param _g The graph we make the snapshot of.
709 void save(SmartUGraph &g)
711 g.saveSnapshot(*this);
714 ///Undo the changes until a snapshot.
716 ///Undo the changes until a snapshot created by save().
718 ///\note After you restored a state, you cannot restore
719 ///a later state, in other word you cannot add again the edges deleted
723 g->restoreSnapshot(*this);
729 class SmartBpUGraphBase {
732 class NodeSetError : public LogicError {
734 virtual const char* what() const throw() {
735 return "lemon::SmartBpUGraph::NodeSetError";
744 NodeT(int _first) : first(_first) {}
752 std::vector<NodeT> aNodes;
753 std::vector<NodeT> bNodes;
755 std::vector<UEdgeT> edges;
760 friend class SmartBpUGraphBase;
764 explicit Node(int _id) : id(_id) {}
767 Node(Invalid) : id(-1) {}
768 bool operator==(const Node i) const {return id==i.id;}
769 bool operator!=(const Node i) const {return id!=i.id;}
770 bool operator<(const Node i) const {return id<i.id;}
774 friend class SmartBpUGraphBase;
778 UEdge(int _id) : id(_id) {}
781 UEdge(Invalid) : id(-1) {}
782 bool operator==(const UEdge i) const {return id==i.id;}
783 bool operator!=(const UEdge i) const {return id!=i.id;}
784 bool operator<(const UEdge i) const {return id<i.id;}
787 void firstANode(Node& node) const {
788 node.id = 2 * aNodes.size() - 2;
789 if (node.id < 0) node.id = -1;
791 void nextANode(Node& node) const {
793 if (node.id < 0) node.id = -1;
796 void firstBNode(Node& node) const {
797 node.id = 2 * bNodes.size() - 1;
799 void nextBNode(Node& node) const {
803 void first(Node& node) const {
804 if (aNodes.size() > 0) {
805 node.id = 2 * aNodes.size() - 2;
807 node.id = 2 * bNodes.size() - 1;
810 void next(Node& node) const {
813 node.id = 2 * bNodes.size() - 1;
817 void first(UEdge& edge) const {
818 edge.id = edges.size() - 1;
820 void next(UEdge& edge) const {
824 void firstFromANode(UEdge& edge, const Node& node) const {
825 LEMON_ASSERT((node.id & 1) == 0, NodeSetError());
826 edge.id = aNodes[node.id >> 1].first;
828 void nextFromANode(UEdge& edge) const {
829 edge.id = edges[edge.id].next_out;
832 void firstFromBNode(UEdge& edge, const Node& node) const {
833 LEMON_ASSERT((node.id & 1) == 1, NodeSetError());
834 edge.id = bNodes[node.id >> 1].first;
836 void nextFromBNode(UEdge& edge) const {
837 edge.id = edges[edge.id].next_in;
840 static int id(const Node& node) {
843 static Node nodeFromId(int id) {
846 int maxNodeId() const {
847 return aNodes.size() > bNodes.size() ?
848 aNodes.size() * 2 - 2 : bNodes.size() * 2 - 1;
851 static int id(const UEdge& edge) {
854 static UEdge uEdgeFromId(int id) {
857 int maxUEdgeId() const {
861 static int aNodeId(const Node& node) {
864 static Node nodeFromANodeId(int id) {
865 return Node(id << 1);
867 int maxANodeId() const {
868 return aNodes.size();
871 static int bNodeId(const Node& node) {
874 static Node nodeFromBNodeId(int id) {
875 return Node((id << 1) + 1);
877 int maxBNodeId() const {
878 return bNodes.size();
881 Node aNode(const UEdge& edge) const {
882 return Node(edges[edge.id].aNode);
884 Node bNode(const UEdge& edge) const {
885 return Node(edges[edge.id].bNode);
888 static bool aNode(const Node& node) {
889 return (node.id & 1) == 0;
892 static bool bNode(const Node& node) {
893 return (node.id & 1) == 1;
899 aNodes.push_back(nodeT);
900 return Node(aNodes.size() * 2 - 2);
906 bNodes.push_back(nodeT);
907 return Node(bNodes.size() * 2 - 1);
910 UEdge addEdge(const Node& source, const Node& target) {
911 LEMON_ASSERT(((source.id ^ target.id) & 1) == 1, NodeSetError());
913 if ((source.id & 1) == 0) {
914 edgeT.aNode = source.id;
915 edgeT.bNode = target.id;
917 edgeT.aNode = target.id;
918 edgeT.bNode = source.id;
920 edgeT.next_out = aNodes[edgeT.aNode >> 1].first;
921 aNodes[edgeT.aNode >> 1].first = edges.size();
922 edgeT.next_in = bNodes[edgeT.bNode >> 1].first;
923 bNodes[edgeT.bNode >> 1].first = edges.size();
924 edges.push_back(edgeT);
925 return UEdge(edges.size() - 1);
934 typedef True NodeNumTag;
935 int nodeNum() const { return aNodes.size() + bNodes.size(); }
936 int aNodeNum() const { return aNodes.size(); }
937 int bNodeNum() const { return bNodes.size(); }
939 typedef True EdgeNumTag;
940 int uEdgeNum() const { return edges.size(); }
945 typedef BpUGraphExtender<BidirBpUGraphExtender<SmartBpUGraphBase> >
946 ExtendedSmartBpUGraphBase;
950 /// \brief A smart bipartite undirected graph class.
952 /// This is a simple and fast bipartite undirected graph implementation.
953 /// It is also quite memory efficient, but at the price
954 /// that <b> it does not support node and edge deletions</b>.
955 /// Except from this it conforms to
956 /// the \ref concepts::BpUGraph "BpUGraph concept".
959 ///important extra feature that
960 ///its maps are real \ref concepts::ReferenceMap "reference map"s.
962 /// \sa concepts::BpUGraph.
964 class SmartBpUGraph : public ExtendedSmartBpUGraphBase {
967 /// \brief SmartBpUGraph is \e not copy constructible.
969 ///SmartBpUGraph is \e not copy constructible.
970 SmartBpUGraph(const SmartBpUGraph &) : ExtendedSmartBpUGraphBase() {};
972 /// \brief Assignment of SmartBpUGraph to another one is \e not
975 /// Assignment of SmartBpUGraph to another one is \e not allowed.
976 void operator=(const SmartBpUGraph &) {}
980 typedef ExtendedSmartBpUGraphBase Parent;
986 SmartBpUGraph() : ExtendedSmartBpUGraphBase() {}
988 ///Add a new ANode to the graph.
990 /// \return the new node.
992 Node addANode() { return Parent::addANode(); }
994 ///Add a new BNode to the graph.
996 /// \return the new node.
998 Node addBNode() { return Parent::addBNode(); }
1000 ///Add a new undirected edge to the graph.
1002 ///Add a new undirected edge to the graph with node \c s
1004 ///\return the new undirected edge.
1005 UEdge addEdge(const Node& s, const Node& t) {
1006 return Parent::addEdge(s, t);
1011 ///Erase all the nodes and edges from the graph.
1023 void restoreSnapshot(const Snapshot &s)
1025 while(s.edge_num<edges.size()) {
1026 UEdge edge = uEdgeFromId(edges.size()-1);
1027 Parent::getNotifier(UEdge()).erase(edge);
1028 std::vector<Edge> dir;
1029 dir.push_back(Parent::direct(edge, true));
1030 dir.push_back(Parent::direct(edge, false));
1031 Parent::getNotifier(Edge()).erase(dir);
1032 aNodes[edges.back().aNode >> 1].first=edges.back().next_out;
1033 bNodes[edges.back().bNode >> 1].first=edges.back().next_in;
1036 while(s.anode_num<aNodes.size()) {
1037 Node node = nodeFromANodeId(aNodes.size() - 1);
1038 Parent::getNotifier(ANode()).erase(node);
1039 Parent::getNotifier(Node()).erase(node);
1042 while(s.bnode_num<bNodes.size()) {
1043 Node node = nodeFromBNodeId(bNodes.size() - 1);
1044 Parent::getNotifier(BNode()).erase(node);
1045 Parent::getNotifier(Node()).erase(node);
1052 ///Class to make a snapshot of the graph and to restrore to it later.
1054 ///Class to make a snapshot of the graph and to restrore to it later.
1056 ///The newly added nodes and edges can be removed using the
1057 ///restore() function.
1059 ///\note After you restore a state, you cannot restore
1060 ///a later state, in other word you cannot add again the edges deleted
1061 ///by restore() using another one Snapshot instance.
1063 ///\warning If you do not use correctly the snapshot that can cause
1064 ///either broken program, invalid state of the graph, valid but
1065 ///not the restored graph or no change. Because the runtime performance
1066 ///the validity of the snapshot is not stored.
1071 friend class SmartBpUGraph;
1072 unsigned int anode_num;
1073 unsigned int bnode_num;
1074 unsigned int edge_num;
1076 ///Default constructor.
1078 ///Default constructor.
1079 ///To actually make a snapshot you must call save().
1081 Snapshot() : g(0) {}
1083 ///Constructor that immediately makes a snapshot
1085 ///This constructor immediately makes a snapshot of the graph.
1086 ///\param _g The graph we make a snapshot of.
1087 Snapshot(SmartBpUGraph &_g) : g(&_g) {
1088 anode_num=g->aNodes.size();
1089 bnode_num=g->bNodes.size();
1090 edge_num=g->edges.size();
1095 ///Make a snapshot of the graph.
1097 ///This function can be called more than once. In case of a repeated
1098 ///call, the previous snapshot gets lost.
1099 ///\param _g The graph we make the snapshot of.
1100 void save(SmartBpUGraph &_g)
1103 anode_num=g->aNodes.size();
1104 bnode_num=g->bNodes.size();
1105 edge_num=g->edges.size();
1108 ///Undo the changes until a snapshot.
1110 ///Undo the changes until a snapshot created by save().
1112 ///\note After you restored a state, you cannot restore
1113 ///a later state, in other word you cannot add again the edges deleted
1117 g->restoreSnapshot(*this);
1127 #endif //LEMON_SMART_GRAPH_H