lemongraph 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +8 -0
  3. data/LICENSE +674 -0
  4. data/README.md +6 -0
  5. data/ext/lemon-1.3.1/AUTHORS +26 -0
  6. data/ext/lemon-1.3.1/CMakeLists.txt +371 -0
  7. data/ext/lemon-1.3.1/INSTALL +167 -0
  8. data/ext/lemon-1.3.1/LICENSE +32 -0
  9. data/ext/lemon-1.3.1/NEWS +337 -0
  10. data/ext/lemon-1.3.1/README +50 -0
  11. data/ext/lemon-1.3.1/cmake/FindCOIN.cmake +110 -0
  12. data/ext/lemon-1.3.1/cmake/FindGLPK.cmake +55 -0
  13. data/ext/lemon-1.3.1/cmake/FindGhostscript.cmake +10 -0
  14. data/ext/lemon-1.3.1/cmake/FindILOG.cmake +102 -0
  15. data/ext/lemon-1.3.1/cmake/FindSOPLEX.cmake +23 -0
  16. data/ext/lemon-1.3.1/cmake/LEMONConfig.cmake.in +13 -0
  17. data/ext/lemon-1.3.1/cmake/nsis/lemon.ico +0 -0
  18. data/ext/lemon-1.3.1/cmake/nsis/uninstall.ico +0 -0
  19. data/ext/lemon-1.3.1/cmake/version.cmake +1 -0
  20. data/ext/lemon-1.3.1/cmake/version.cmake.in +1 -0
  21. data/ext/lemon-1.3.1/contrib/CMakeLists.txt +19 -0
  22. data/ext/lemon-1.3.1/lemon/CMakeLists.txt +91 -0
  23. data/ext/lemon-1.3.1/lemon/adaptors.h +3638 -0
  24. data/ext/lemon-1.3.1/lemon/arg_parser.cc +474 -0
  25. data/ext/lemon-1.3.1/lemon/arg_parser.h +440 -0
  26. data/ext/lemon-1.3.1/lemon/assert.h +214 -0
  27. data/ext/lemon-1.3.1/lemon/base.cc +37 -0
  28. data/ext/lemon-1.3.1/lemon/bellman_ford.h +1116 -0
  29. data/ext/lemon-1.3.1/lemon/bfs.h +1754 -0
  30. data/ext/lemon-1.3.1/lemon/bin_heap.h +347 -0
  31. data/ext/lemon-1.3.1/lemon/binomial_heap.h +445 -0
  32. data/ext/lemon-1.3.1/lemon/bits/alteration_notifier.h +472 -0
  33. data/ext/lemon-1.3.1/lemon/bits/array_map.h +351 -0
  34. data/ext/lemon-1.3.1/lemon/bits/bezier.h +174 -0
  35. data/ext/lemon-1.3.1/lemon/bits/default_map.h +182 -0
  36. data/ext/lemon-1.3.1/lemon/bits/edge_set_extender.h +627 -0
  37. data/ext/lemon-1.3.1/lemon/bits/enable_if.h +131 -0
  38. data/ext/lemon-1.3.1/lemon/bits/graph_adaptor_extender.h +401 -0
  39. data/ext/lemon-1.3.1/lemon/bits/graph_extender.h +1332 -0
  40. data/ext/lemon-1.3.1/lemon/bits/lock.h +65 -0
  41. data/ext/lemon-1.3.1/lemon/bits/map_extender.h +332 -0
  42. data/ext/lemon-1.3.1/lemon/bits/path_dump.h +177 -0
  43. data/ext/lemon-1.3.1/lemon/bits/solver_bits.h +194 -0
  44. data/ext/lemon-1.3.1/lemon/bits/traits.h +388 -0
  45. data/ext/lemon-1.3.1/lemon/bits/variant.h +494 -0
  46. data/ext/lemon-1.3.1/lemon/bits/vector_map.h +244 -0
  47. data/ext/lemon-1.3.1/lemon/bits/windows.cc +166 -0
  48. data/ext/lemon-1.3.1/lemon/bits/windows.h +44 -0
  49. data/ext/lemon-1.3.1/lemon/bucket_heap.h +594 -0
  50. data/ext/lemon-1.3.1/lemon/capacity_scaling.h +1014 -0
  51. data/ext/lemon-1.3.1/lemon/cbc.cc +460 -0
  52. data/ext/lemon-1.3.1/lemon/cbc.h +129 -0
  53. data/ext/lemon-1.3.1/lemon/christofides_tsp.h +254 -0
  54. data/ext/lemon-1.3.1/lemon/circulation.h +807 -0
  55. data/ext/lemon-1.3.1/lemon/clp.cc +464 -0
  56. data/ext/lemon-1.3.1/lemon/clp.h +164 -0
  57. data/ext/lemon-1.3.1/lemon/color.cc +44 -0
  58. data/ext/lemon-1.3.1/lemon/color.h +204 -0
  59. data/ext/lemon-1.3.1/lemon/concept_check.h +77 -0
  60. data/ext/lemon-1.3.1/lemon/concepts/bpgraph.h +1029 -0
  61. data/ext/lemon-1.3.1/lemon/concepts/digraph.h +491 -0
  62. data/ext/lemon-1.3.1/lemon/concepts/graph.h +788 -0
  63. data/ext/lemon-1.3.1/lemon/concepts/graph_components.h +2134 -0
  64. data/ext/lemon-1.3.1/lemon/concepts/heap.h +324 -0
  65. data/ext/lemon-1.3.1/lemon/concepts/maps.h +223 -0
  66. data/ext/lemon-1.3.1/lemon/concepts/path.h +312 -0
  67. data/ext/lemon-1.3.1/lemon/config.h.in +22 -0
  68. data/ext/lemon-1.3.1/lemon/connectivity.h +1688 -0
  69. data/ext/lemon-1.3.1/lemon/core.h +2506 -0
  70. data/ext/lemon-1.3.1/lemon/cost_scaling.h +1607 -0
  71. data/ext/lemon-1.3.1/lemon/counter.h +249 -0
  72. data/ext/lemon-1.3.1/lemon/cplex.cc +994 -0
  73. data/ext/lemon-1.3.1/lemon/cplex.h +292 -0
  74. data/ext/lemon-1.3.1/lemon/cycle_canceling.h +1230 -0
  75. data/ext/lemon-1.3.1/lemon/dfs.h +1637 -0
  76. data/ext/lemon-1.3.1/lemon/dheap.h +352 -0
  77. data/ext/lemon-1.3.1/lemon/dijkstra.h +1303 -0
  78. data/ext/lemon-1.3.1/lemon/dim2.h +726 -0
  79. data/ext/lemon-1.3.1/lemon/dimacs.h +448 -0
  80. data/ext/lemon-1.3.1/lemon/edge_set.h +1420 -0
  81. data/ext/lemon-1.3.1/lemon/edmonds_karp.h +556 -0
  82. data/ext/lemon-1.3.1/lemon/elevator.h +982 -0
  83. data/ext/lemon-1.3.1/lemon/error.h +276 -0
  84. data/ext/lemon-1.3.1/lemon/euler.h +287 -0
  85. data/ext/lemon-1.3.1/lemon/fib_heap.h +475 -0
  86. data/ext/lemon-1.3.1/lemon/fractional_matching.h +2139 -0
  87. data/ext/lemon-1.3.1/lemon/full_graph.h +1082 -0
  88. data/ext/lemon-1.3.1/lemon/glpk.cc +1012 -0
  89. data/ext/lemon-1.3.1/lemon/glpk.h +263 -0
  90. data/ext/lemon-1.3.1/lemon/gomory_hu.h +568 -0
  91. data/ext/lemon-1.3.1/lemon/graph_to_eps.h +1186 -0
  92. data/ext/lemon-1.3.1/lemon/greedy_tsp.h +251 -0
  93. data/ext/lemon-1.3.1/lemon/grid_graph.h +699 -0
  94. data/ext/lemon-1.3.1/lemon/grosso_locatelli_pullan_mc.h +840 -0
  95. data/ext/lemon-1.3.1/lemon/hao_orlin.h +1015 -0
  96. data/ext/lemon-1.3.1/lemon/hartmann_orlin_mmc.h +654 -0
  97. data/ext/lemon-1.3.1/lemon/howard_mmc.h +651 -0
  98. data/ext/lemon-1.3.1/lemon/hypercube_graph.h +459 -0
  99. data/ext/lemon-1.3.1/lemon/insertion_tsp.h +533 -0
  100. data/ext/lemon-1.3.1/lemon/karp_mmc.h +590 -0
  101. data/ext/lemon-1.3.1/lemon/kruskal.h +324 -0
  102. data/ext/lemon-1.3.1/lemon/lemon.pc.in +10 -0
  103. data/ext/lemon-1.3.1/lemon/lgf_reader.h +3854 -0
  104. data/ext/lemon-1.3.1/lemon/lgf_writer.h +2687 -0
  105. data/ext/lemon-1.3.1/lemon/list_graph.h +2510 -0
  106. data/ext/lemon-1.3.1/lemon/lp.h +95 -0
  107. data/ext/lemon-1.3.1/lemon/lp_base.cc +30 -0
  108. data/ext/lemon-1.3.1/lemon/lp_base.h +2147 -0
  109. data/ext/lemon-1.3.1/lemon/lp_skeleton.cc +143 -0
  110. data/ext/lemon-1.3.1/lemon/lp_skeleton.h +234 -0
  111. data/ext/lemon-1.3.1/lemon/maps.h +4057 -0
  112. data/ext/lemon-1.3.1/lemon/matching.h +3505 -0
  113. data/ext/lemon-1.3.1/lemon/math.h +77 -0
  114. data/ext/lemon-1.3.1/lemon/max_cardinality_search.h +794 -0
  115. data/ext/lemon-1.3.1/lemon/min_cost_arborescence.h +808 -0
  116. data/ext/lemon-1.3.1/lemon/nagamochi_ibaraki.h +702 -0
  117. data/ext/lemon-1.3.1/lemon/nauty_reader.h +113 -0
  118. data/ext/lemon-1.3.1/lemon/nearest_neighbor_tsp.h +238 -0
  119. data/ext/lemon-1.3.1/lemon/network_simplex.h +1659 -0
  120. data/ext/lemon-1.3.1/lemon/opt2_tsp.h +367 -0
  121. data/ext/lemon-1.3.1/lemon/pairing_heap.h +474 -0
  122. data/ext/lemon-1.3.1/lemon/path.h +1164 -0
  123. data/ext/lemon-1.3.1/lemon/planarity.h +2754 -0
  124. data/ext/lemon-1.3.1/lemon/preflow.h +985 -0
  125. data/ext/lemon-1.3.1/lemon/quad_heap.h +343 -0
  126. data/ext/lemon-1.3.1/lemon/radix_heap.h +438 -0
  127. data/ext/lemon-1.3.1/lemon/radix_sort.h +487 -0
  128. data/ext/lemon-1.3.1/lemon/random.cc +29 -0
  129. data/ext/lemon-1.3.1/lemon/random.h +1005 -0
  130. data/ext/lemon-1.3.1/lemon/smart_graph.h +1344 -0
  131. data/ext/lemon-1.3.1/lemon/soplex.cc +465 -0
  132. data/ext/lemon-1.3.1/lemon/soplex.h +158 -0
  133. data/ext/lemon-1.3.1/lemon/static_graph.h +476 -0
  134. data/ext/lemon-1.3.1/lemon/suurballe.h +776 -0
  135. data/ext/lemon-1.3.1/lemon/time_measure.h +610 -0
  136. data/ext/lemon-1.3.1/lemon/tolerance.h +242 -0
  137. data/ext/lemon-1.3.1/lemon/unionfind.h +1824 -0
  138. data/ext/lemon-1.3.1/scripts/unify-sources.sh +390 -0
  139. data/ext/lemon-1.3.1/scripts/valgrind-wrapper.sh +22 -0
  140. data/ext/lemongraph/arc_map.cc +1007 -0
  141. data/ext/lemongraph/digraph.cc +282 -0
  142. data/ext/lemongraph/digraph_arc.cc +153 -0
  143. data/ext/lemongraph/digraph_node.cc +277 -0
  144. data/ext/lemongraph/edge_map.cc +770 -0
  145. data/ext/lemongraph/extconf.rb +53 -0
  146. data/ext/lemongraph/graph.cc +351 -0
  147. data/ext/lemongraph/graph_arc.cc +95 -0
  148. data/ext/lemongraph/graph_edge.cc +153 -0
  149. data/ext/lemongraph/graph_item.cc +76 -0
  150. data/ext/lemongraph/graph_node.cc +321 -0
  151. data/ext/lemongraph/lemongraph.cc +260 -0
  152. data/ext/lemongraph/lemongraph.hh +295 -0
  153. data/ext/lemongraph/lemongraph.map +6 -0
  154. data/ext/lemongraph/lemongraph_export.hh +31 -0
  155. data/ext/lemongraph/node_map.cc +1011 -0
  156. data/lemongraph.gemspec +176 -0
  157. data/lib/lemongraph/graphviz.rb +240 -0
  158. data/lib/lemongraph/version.rb +4 -0
  159. data/lib/lemongraph.rb +21 -0
  160. data/samples/lemondeps.rb +38 -0
  161. metadata +202 -0
@@ -0,0 +1,627 @@
1
+ /* -*- mode: C++; indent-tabs-mode: nil; -*-
2
+ *
3
+ * This file is a part of LEMON, a generic C++ optimization library.
4
+ *
5
+ * Copyright (C) 2003-2013
6
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
8
+ *
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.
12
+ *
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
15
+ * purpose.
16
+ *
17
+ */
18
+
19
+ #ifndef LEMON_BITS_EDGE_SET_EXTENDER_H
20
+ #define LEMON_BITS_EDGE_SET_EXTENDER_H
21
+
22
+ #include <lemon/core.h>
23
+ #include <lemon/error.h>
24
+ #include <lemon/bits/default_map.h>
25
+ #include <lemon/bits/map_extender.h>
26
+
27
+ //\ingroup digraphbits
28
+ //\file
29
+ //\brief Extenders for the arc set types
30
+ namespace lemon {
31
+
32
+ // \ingroup digraphbits
33
+ //
34
+ // \brief Extender for the ArcSets
35
+ template <typename Base>
36
+ class ArcSetExtender : public Base {
37
+ typedef Base Parent;
38
+
39
+ public:
40
+
41
+ typedef ArcSetExtender Digraph;
42
+
43
+ // Base extensions
44
+
45
+ typedef typename Parent::Node Node;
46
+ typedef typename Parent::Arc Arc;
47
+
48
+ int maxId(Node) const {
49
+ return Parent::maxNodeId();
50
+ }
51
+
52
+ int maxId(Arc) const {
53
+ return Parent::maxArcId();
54
+ }
55
+
56
+ Node fromId(int id, Node) const {
57
+ return Parent::nodeFromId(id);
58
+ }
59
+
60
+ Arc fromId(int id, Arc) const {
61
+ return Parent::arcFromId(id);
62
+ }
63
+
64
+ Node oppositeNode(const Node &n, const Arc &e) const {
65
+ if (n == Parent::source(e))
66
+ return Parent::target(e);
67
+ else if(n==Parent::target(e))
68
+ return Parent::source(e);
69
+ else
70
+ return INVALID;
71
+ }
72
+
73
+
74
+ // Alteration notifier extensions
75
+
76
+ // The arc observer registry.
77
+ typedef AlterationNotifier<ArcSetExtender, Arc> ArcNotifier;
78
+
79
+ protected:
80
+
81
+ mutable ArcNotifier arc_notifier;
82
+
83
+ public:
84
+
85
+ using Parent::notifier;
86
+
87
+ // Gives back the arc alteration notifier.
88
+ ArcNotifier& notifier(Arc) const {
89
+ return arc_notifier;
90
+ }
91
+
92
+ // Iterable extensions
93
+
94
+ class NodeIt : public Node {
95
+ const Digraph* digraph;
96
+ public:
97
+
98
+ NodeIt() {}
99
+
100
+ NodeIt(Invalid i) : Node(i) { }
101
+
102
+ explicit NodeIt(const Digraph& _graph) : digraph(&_graph) {
103
+ _graph.first(static_cast<Node&>(*this));
104
+ }
105
+
106
+ NodeIt(const Digraph& _graph, const Node& node)
107
+ : Node(node), digraph(&_graph) {}
108
+
109
+ NodeIt& operator++() {
110
+ digraph->next(*this);
111
+ return *this;
112
+ }
113
+
114
+ };
115
+
116
+
117
+ class ArcIt : public Arc {
118
+ const Digraph* digraph;
119
+ public:
120
+
121
+ ArcIt() { }
122
+
123
+ ArcIt(Invalid i) : Arc(i) { }
124
+
125
+ explicit ArcIt(const Digraph& _graph) : digraph(&_graph) {
126
+ _graph.first(static_cast<Arc&>(*this));
127
+ }
128
+
129
+ ArcIt(const Digraph& _graph, const Arc& e) :
130
+ Arc(e), digraph(&_graph) { }
131
+
132
+ ArcIt& operator++() {
133
+ digraph->next(*this);
134
+ return *this;
135
+ }
136
+
137
+ };
138
+
139
+
140
+ class OutArcIt : public Arc {
141
+ const Digraph* digraph;
142
+ public:
143
+
144
+ OutArcIt() { }
145
+
146
+ OutArcIt(Invalid i) : Arc(i) { }
147
+
148
+ OutArcIt(const Digraph& _graph, const Node& node)
149
+ : digraph(&_graph) {
150
+ _graph.firstOut(*this, node);
151
+ }
152
+
153
+ OutArcIt(const Digraph& _graph, const Arc& arc)
154
+ : Arc(arc), digraph(&_graph) {}
155
+
156
+ OutArcIt& operator++() {
157
+ digraph->nextOut(*this);
158
+ return *this;
159
+ }
160
+
161
+ };
162
+
163
+
164
+ class InArcIt : public Arc {
165
+ const Digraph* digraph;
166
+ public:
167
+
168
+ InArcIt() { }
169
+
170
+ InArcIt(Invalid i) : Arc(i) { }
171
+
172
+ InArcIt(const Digraph& _graph, const Node& node)
173
+ : digraph(&_graph) {
174
+ _graph.firstIn(*this, node);
175
+ }
176
+
177
+ InArcIt(const Digraph& _graph, const Arc& arc) :
178
+ Arc(arc), digraph(&_graph) {}
179
+
180
+ InArcIt& operator++() {
181
+ digraph->nextIn(*this);
182
+ return *this;
183
+ }
184
+
185
+ };
186
+
187
+ // \brief Base node of the iterator
188
+ //
189
+ // Returns the base node (ie. the source in this case) of the iterator
190
+ Node baseNode(const OutArcIt &e) const {
191
+ return Parent::source(static_cast<const Arc&>(e));
192
+ }
193
+ // \brief Running node of the iterator
194
+ //
195
+ // Returns the running node (ie. the target in this case) of the
196
+ // iterator
197
+ Node runningNode(const OutArcIt &e) const {
198
+ return Parent::target(static_cast<const Arc&>(e));
199
+ }
200
+
201
+ // \brief Base node of the iterator
202
+ //
203
+ // Returns the base node (ie. the target in this case) of the iterator
204
+ Node baseNode(const InArcIt &e) const {
205
+ return Parent::target(static_cast<const Arc&>(e));
206
+ }
207
+ // \brief Running node of the iterator
208
+ //
209
+ // Returns the running node (ie. the source in this case) of the
210
+ // iterator
211
+ Node runningNode(const InArcIt &e) const {
212
+ return Parent::source(static_cast<const Arc&>(e));
213
+ }
214
+
215
+ using Parent::first;
216
+
217
+ // Mappable extension
218
+
219
+ template <typename _Value>
220
+ class ArcMap
221
+ : public MapExtender<DefaultMap<Digraph, Arc, _Value> > {
222
+ typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent;
223
+
224
+ public:
225
+ explicit ArcMap(const Digraph& _g)
226
+ : Parent(_g) {}
227
+ ArcMap(const Digraph& _g, const _Value& _v)
228
+ : Parent(_g, _v) {}
229
+
230
+ ArcMap& operator=(const ArcMap& cmap) {
231
+ return operator=<ArcMap>(cmap);
232
+ }
233
+
234
+ template <typename CMap>
235
+ ArcMap& operator=(const CMap& cmap) {
236
+ Parent::operator=(cmap);
237
+ return *this;
238
+ }
239
+
240
+ };
241
+
242
+
243
+ // Alteration extension
244
+
245
+ Arc addArc(const Node& from, const Node& to) {
246
+ Arc arc = Parent::addArc(from, to);
247
+ notifier(Arc()).add(arc);
248
+ return arc;
249
+ }
250
+
251
+ void clear() {
252
+ notifier(Arc()).clear();
253
+ Parent::clear();
254
+ }
255
+
256
+ void erase(const Arc& arc) {
257
+ notifier(Arc()).erase(arc);
258
+ Parent::erase(arc);
259
+ }
260
+
261
+ ArcSetExtender() {
262
+ arc_notifier.setContainer(*this);
263
+ }
264
+
265
+ ~ArcSetExtender() {
266
+ arc_notifier.clear();
267
+ }
268
+
269
+ };
270
+
271
+
272
+ // \ingroup digraphbits
273
+ //
274
+ // \brief Extender for the EdgeSets
275
+ template <typename Base>
276
+ class EdgeSetExtender : public Base {
277
+ typedef Base Parent;
278
+
279
+ public:
280
+
281
+ typedef EdgeSetExtender Graph;
282
+
283
+ typedef True UndirectedTag;
284
+
285
+ typedef typename Parent::Node Node;
286
+ typedef typename Parent::Arc Arc;
287
+ typedef typename Parent::Edge Edge;
288
+
289
+ int maxId(Node) const {
290
+ return Parent::maxNodeId();
291
+ }
292
+
293
+ int maxId(Arc) const {
294
+ return Parent::maxArcId();
295
+ }
296
+
297
+ int maxId(Edge) const {
298
+ return Parent::maxEdgeId();
299
+ }
300
+
301
+ Node fromId(int id, Node) const {
302
+ return Parent::nodeFromId(id);
303
+ }
304
+
305
+ Arc fromId(int id, Arc) const {
306
+ return Parent::arcFromId(id);
307
+ }
308
+
309
+ Edge fromId(int id, Edge) const {
310
+ return Parent::edgeFromId(id);
311
+ }
312
+
313
+ Node oppositeNode(const Node &n, const Edge &e) const {
314
+ if( n == Parent::u(e))
315
+ return Parent::v(e);
316
+ else if( n == Parent::v(e))
317
+ return Parent::u(e);
318
+ else
319
+ return INVALID;
320
+ }
321
+
322
+ Arc oppositeArc(const Arc &e) const {
323
+ return Parent::direct(e, !Parent::direction(e));
324
+ }
325
+
326
+ using Parent::direct;
327
+ Arc direct(const Edge &e, const Node &s) const {
328
+ return Parent::direct(e, Parent::u(e) == s);
329
+ }
330
+
331
+ typedef AlterationNotifier<EdgeSetExtender, Arc> ArcNotifier;
332
+ typedef AlterationNotifier<EdgeSetExtender, Edge> EdgeNotifier;
333
+
334
+
335
+ protected:
336
+
337
+ mutable ArcNotifier arc_notifier;
338
+ mutable EdgeNotifier edge_notifier;
339
+
340
+ public:
341
+
342
+ using Parent::notifier;
343
+
344
+ ArcNotifier& notifier(Arc) const {
345
+ return arc_notifier;
346
+ }
347
+
348
+ EdgeNotifier& notifier(Edge) const {
349
+ return edge_notifier;
350
+ }
351
+
352
+
353
+ class NodeIt : public Node {
354
+ const Graph* graph;
355
+ public:
356
+
357
+ NodeIt() {}
358
+
359
+ NodeIt(Invalid i) : Node(i) { }
360
+
361
+ explicit NodeIt(const Graph& _graph) : graph(&_graph) {
362
+ _graph.first(static_cast<Node&>(*this));
363
+ }
364
+
365
+ NodeIt(const Graph& _graph, const Node& node)
366
+ : Node(node), graph(&_graph) {}
367
+
368
+ NodeIt& operator++() {
369
+ graph->next(*this);
370
+ return *this;
371
+ }
372
+
373
+ };
374
+
375
+
376
+ class ArcIt : public Arc {
377
+ const Graph* graph;
378
+ public:
379
+
380
+ ArcIt() { }
381
+
382
+ ArcIt(Invalid i) : Arc(i) { }
383
+
384
+ explicit ArcIt(const Graph& _graph) : graph(&_graph) {
385
+ _graph.first(static_cast<Arc&>(*this));
386
+ }
387
+
388
+ ArcIt(const Graph& _graph, const Arc& e) :
389
+ Arc(e), graph(&_graph) { }
390
+
391
+ ArcIt& operator++() {
392
+ graph->next(*this);
393
+ return *this;
394
+ }
395
+
396
+ };
397
+
398
+
399
+ class OutArcIt : public Arc {
400
+ const Graph* graph;
401
+ public:
402
+
403
+ OutArcIt() { }
404
+
405
+ OutArcIt(Invalid i) : Arc(i) { }
406
+
407
+ OutArcIt(const Graph& _graph, const Node& node)
408
+ : graph(&_graph) {
409
+ _graph.firstOut(*this, node);
410
+ }
411
+
412
+ OutArcIt(const Graph& _graph, const Arc& arc)
413
+ : Arc(arc), graph(&_graph) {}
414
+
415
+ OutArcIt& operator++() {
416
+ graph->nextOut(*this);
417
+ return *this;
418
+ }
419
+
420
+ };
421
+
422
+
423
+ class InArcIt : public Arc {
424
+ const Graph* graph;
425
+ public:
426
+
427
+ InArcIt() { }
428
+
429
+ InArcIt(Invalid i) : Arc(i) { }
430
+
431
+ InArcIt(const Graph& _graph, const Node& node)
432
+ : graph(&_graph) {
433
+ _graph.firstIn(*this, node);
434
+ }
435
+
436
+ InArcIt(const Graph& _graph, const Arc& arc) :
437
+ Arc(arc), graph(&_graph) {}
438
+
439
+ InArcIt& operator++() {
440
+ graph->nextIn(*this);
441
+ return *this;
442
+ }
443
+
444
+ };
445
+
446
+
447
+ class EdgeIt : public Parent::Edge {
448
+ const Graph* graph;
449
+ public:
450
+
451
+ EdgeIt() { }
452
+
453
+ EdgeIt(Invalid i) : Edge(i) { }
454
+
455
+ explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
456
+ _graph.first(static_cast<Edge&>(*this));
457
+ }
458
+
459
+ EdgeIt(const Graph& _graph, const Edge& e) :
460
+ Edge(e), graph(&_graph) { }
461
+
462
+ EdgeIt& operator++() {
463
+ graph->next(*this);
464
+ return *this;
465
+ }
466
+
467
+ };
468
+
469
+ class IncEdgeIt : public Parent::Edge {
470
+ friend class EdgeSetExtender;
471
+ const Graph* graph;
472
+ bool direction;
473
+ public:
474
+
475
+ IncEdgeIt() { }
476
+
477
+ IncEdgeIt(Invalid i) : Edge(i), direction(false) { }
478
+
479
+ IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
480
+ _graph.firstInc(*this, direction, n);
481
+ }
482
+
483
+ IncEdgeIt(const Graph& _graph, const Edge &ue, const Node &n)
484
+ : graph(&_graph), Edge(ue) {
485
+ direction = (_graph.source(ue) == n);
486
+ }
487
+
488
+ IncEdgeIt& operator++() {
489
+ graph->nextInc(*this, direction);
490
+ return *this;
491
+ }
492
+ };
493
+
494
+ // \brief Base node of the iterator
495
+ //
496
+ // Returns the base node (ie. the source in this case) of the iterator
497
+ Node baseNode(const OutArcIt &e) const {
498
+ return Parent::source(static_cast<const Arc&>(e));
499
+ }
500
+ // \brief Running node of the iterator
501
+ //
502
+ // Returns the running node (ie. the target in this case) of the
503
+ // iterator
504
+ Node runningNode(const OutArcIt &e) const {
505
+ return Parent::target(static_cast<const Arc&>(e));
506
+ }
507
+
508
+ // \brief Base node of the iterator
509
+ //
510
+ // Returns the base node (ie. the target in this case) of the iterator
511
+ Node baseNode(const InArcIt &e) const {
512
+ return Parent::target(static_cast<const Arc&>(e));
513
+ }
514
+ // \brief Running node of the iterator
515
+ //
516
+ // Returns the running node (ie. the source in this case) of the
517
+ // iterator
518
+ Node runningNode(const InArcIt &e) const {
519
+ return Parent::source(static_cast<const Arc&>(e));
520
+ }
521
+
522
+ // Base node of the iterator
523
+ //
524
+ // Returns the base node of the iterator
525
+ Node baseNode(const IncEdgeIt &e) const {
526
+ return e.direction ? this->u(e) : this->v(e);
527
+ }
528
+ // Running node of the iterator
529
+ //
530
+ // Returns the running node of the iterator
531
+ Node runningNode(const IncEdgeIt &e) const {
532
+ return e.direction ? this->v(e) : this->u(e);
533
+ }
534
+
535
+
536
+ template <typename _Value>
537
+ class ArcMap
538
+ : public MapExtender<DefaultMap<Graph, Arc, _Value> > {
539
+ typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent;
540
+
541
+ public:
542
+ explicit ArcMap(const Graph& _g)
543
+ : Parent(_g) {}
544
+ ArcMap(const Graph& _g, const _Value& _v)
545
+ : Parent(_g, _v) {}
546
+
547
+ ArcMap& operator=(const ArcMap& cmap) {
548
+ return operator=<ArcMap>(cmap);
549
+ }
550
+
551
+ template <typename CMap>
552
+ ArcMap& operator=(const CMap& cmap) {
553
+ Parent::operator=(cmap);
554
+ return *this;
555
+ }
556
+
557
+ };
558
+
559
+
560
+ template <typename _Value>
561
+ class EdgeMap
562
+ : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
563
+ typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
564
+
565
+ public:
566
+ explicit EdgeMap(const Graph& _g)
567
+ : Parent(_g) {}
568
+
569
+ EdgeMap(const Graph& _g, const _Value& _v)
570
+ : Parent(_g, _v) {}
571
+
572
+ EdgeMap& operator=(const EdgeMap& cmap) {
573
+ return operator=<EdgeMap>(cmap);
574
+ }
575
+
576
+ template <typename CMap>
577
+ EdgeMap& operator=(const CMap& cmap) {
578
+ Parent::operator=(cmap);
579
+ return *this;
580
+ }
581
+
582
+ };
583
+
584
+
585
+ // Alteration extension
586
+
587
+ Edge addEdge(const Node& from, const Node& to) {
588
+ Edge edge = Parent::addEdge(from, to);
589
+ notifier(Edge()).add(edge);
590
+ std::vector<Arc> arcs;
591
+ arcs.push_back(Parent::direct(edge, true));
592
+ arcs.push_back(Parent::direct(edge, false));
593
+ notifier(Arc()).add(arcs);
594
+ return edge;
595
+ }
596
+
597
+ void clear() {
598
+ notifier(Arc()).clear();
599
+ notifier(Edge()).clear();
600
+ Parent::clear();
601
+ }
602
+
603
+ void erase(const Edge& edge) {
604
+ std::vector<Arc> arcs;
605
+ arcs.push_back(Parent::direct(edge, true));
606
+ arcs.push_back(Parent::direct(edge, false));
607
+ notifier(Arc()).erase(arcs);
608
+ notifier(Edge()).erase(edge);
609
+ Parent::erase(edge);
610
+ }
611
+
612
+
613
+ EdgeSetExtender() {
614
+ arc_notifier.setContainer(*this);
615
+ edge_notifier.setContainer(*this);
616
+ }
617
+
618
+ ~EdgeSetExtender() {
619
+ edge_notifier.clear();
620
+ arc_notifier.clear();
621
+ }
622
+
623
+ };
624
+
625
+ }
626
+
627
+ #endif