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,351 @@
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_ARRAY_MAP_H
20
+ #define LEMON_BITS_ARRAY_MAP_H
21
+
22
+ #include <memory>
23
+
24
+ #include <lemon/bits/traits.h>
25
+ #include <lemon/bits/alteration_notifier.h>
26
+ #include <lemon/concept_check.h>
27
+ #include <lemon/concepts/maps.h>
28
+
29
+ // \ingroup graphbits
30
+ // \file
31
+ // \brief Graph map based on the array storage.
32
+
33
+ namespace lemon {
34
+
35
+ // \ingroup graphbits
36
+ //
37
+ // \brief Graph map based on the array storage.
38
+ //
39
+ // The ArrayMap template class is graph map structure that automatically
40
+ // updates the map when a key is added to or erased from the graph.
41
+ // This map uses the allocators to implement the container functionality.
42
+ //
43
+ // The template parameters are the Graph, the current Item type and
44
+ // the Value type of the map.
45
+ template <typename _Graph, typename _Item, typename _Value>
46
+ class ArrayMap
47
+ : public ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase {
48
+ public:
49
+ // The graph type.
50
+ typedef _Graph GraphType;
51
+ // The item type.
52
+ typedef _Item Item;
53
+ // The reference map tag.
54
+ typedef True ReferenceMapTag;
55
+
56
+ // The key type of the map.
57
+ typedef _Item Key;
58
+ // The value type of the map.
59
+ typedef _Value Value;
60
+
61
+ // The const reference type of the map.
62
+ typedef const _Value& ConstReference;
63
+ // The reference type of the map.
64
+ typedef _Value& Reference;
65
+
66
+ // The map type.
67
+ typedef ArrayMap Map;
68
+
69
+ // The notifier type.
70
+ typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier Notifier;
71
+
72
+ private:
73
+
74
+ // The MapBase of the Map which imlements the core regisitry function.
75
+ typedef typename Notifier::ObserverBase Parent;
76
+
77
+ typedef std::allocator<Value> Allocator;
78
+
79
+ public:
80
+
81
+ // \brief Graph initialized map constructor.
82
+ //
83
+ // Graph initialized map constructor.
84
+ explicit ArrayMap(const GraphType& graph) {
85
+ Parent::attach(graph.notifier(Item()));
86
+ allocate_memory();
87
+ Notifier* nf = Parent::notifier();
88
+ Item it;
89
+ for (nf->first(it); it != INVALID; nf->next(it)) {
90
+ int id = nf->id(it);;
91
+ allocator.construct(&(values[id]), Value());
92
+ }
93
+ }
94
+
95
+ // \brief Constructor to use default value to initialize the map.
96
+ //
97
+ // It constructs a map and initialize all of the the map.
98
+ ArrayMap(const GraphType& graph, const Value& value) {
99
+ Parent::attach(graph.notifier(Item()));
100
+ allocate_memory();
101
+ Notifier* nf = Parent::notifier();
102
+ Item it;
103
+ for (nf->first(it); it != INVALID; nf->next(it)) {
104
+ int id = nf->id(it);;
105
+ allocator.construct(&(values[id]), value);
106
+ }
107
+ }
108
+
109
+ private:
110
+ // \brief Constructor to copy a map of the same map type.
111
+ //
112
+ // Constructor to copy a map of the same map type.
113
+ ArrayMap(const ArrayMap& copy) : Parent() {
114
+ if (copy.attached()) {
115
+ attach(*copy.notifier());
116
+ }
117
+ capacity = copy.capacity;
118
+ if (capacity == 0) return;
119
+ values = allocator.allocate(capacity);
120
+ Notifier* nf = Parent::notifier();
121
+ Item it;
122
+ for (nf->first(it); it != INVALID; nf->next(it)) {
123
+ int id = nf->id(it);;
124
+ allocator.construct(&(values[id]), copy.values[id]);
125
+ }
126
+ }
127
+
128
+ // \brief Assign operator.
129
+ //
130
+ // This operator assigns for each item in the map the
131
+ // value mapped to the same item in the copied map.
132
+ // The parameter map should be indiced with the same
133
+ // itemset because this assign operator does not change
134
+ // the container of the map.
135
+ ArrayMap& operator=(const ArrayMap& cmap) {
136
+ return operator=<ArrayMap>(cmap);
137
+ }
138
+
139
+
140
+ // \brief Template assign operator.
141
+ //
142
+ // The given parameter should conform to the ReadMap
143
+ // concecpt and could be indiced by the current item set of
144
+ // the NodeMap. In this case the value for each item
145
+ // is assigned by the value of the given ReadMap.
146
+ template <typename CMap>
147
+ ArrayMap& operator=(const CMap& cmap) {
148
+ checkConcept<concepts::ReadMap<Key, _Value>, CMap>();
149
+ const typename Parent::Notifier* nf = Parent::notifier();
150
+ Item it;
151
+ for (nf->first(it); it != INVALID; nf->next(it)) {
152
+ set(it, cmap[it]);
153
+ }
154
+ return *this;
155
+ }
156
+
157
+ public:
158
+ // \brief The destructor of the map.
159
+ //
160
+ // The destructor of the map.
161
+ virtual ~ArrayMap() {
162
+ if (attached()) {
163
+ clear();
164
+ detach();
165
+ }
166
+ }
167
+
168
+ protected:
169
+
170
+ using Parent::attach;
171
+ using Parent::detach;
172
+ using Parent::attached;
173
+
174
+ public:
175
+
176
+ // \brief The subscript operator.
177
+ //
178
+ // The subscript operator. The map can be subscripted by the
179
+ // actual keys of the graph.
180
+ Value& operator[](const Key& key) {
181
+ int id = Parent::notifier()->id(key);
182
+ return values[id];
183
+ }
184
+
185
+ // \brief The const subscript operator.
186
+ //
187
+ // The const subscript operator. The map can be subscripted by the
188
+ // actual keys of the graph.
189
+ const Value& operator[](const Key& key) const {
190
+ int id = Parent::notifier()->id(key);
191
+ return values[id];
192
+ }
193
+
194
+ // \brief Setter function of the map.
195
+ //
196
+ // Setter function of the map. Equivalent with map[key] = val.
197
+ // This is a compatibility feature with the not dereferable maps.
198
+ void set(const Key& key, const Value& val) {
199
+ (*this)[key] = val;
200
+ }
201
+
202
+ protected:
203
+
204
+ // \brief Adds a new key to the map.
205
+ //
206
+ // It adds a new key to the map. It is called by the observer notifier
207
+ // and it overrides the add() member function of the observer base.
208
+ virtual void add(const Key& key) {
209
+ Notifier* nf = Parent::notifier();
210
+ int id = nf->id(key);
211
+ if (id >= capacity) {
212
+ int new_capacity = (capacity == 0 ? 1 : capacity);
213
+ while (new_capacity <= id) {
214
+ new_capacity <<= 1;
215
+ }
216
+ Value* new_values = allocator.allocate(new_capacity);
217
+ Item it;
218
+ for (nf->first(it); it != INVALID; nf->next(it)) {
219
+ int jd = nf->id(it);;
220
+ if (id != jd) {
221
+ allocator.construct(&(new_values[jd]), values[jd]);
222
+ allocator.destroy(&(values[jd]));
223
+ }
224
+ }
225
+ if (capacity != 0) allocator.deallocate(values, capacity);
226
+ values = new_values;
227
+ capacity = new_capacity;
228
+ }
229
+ allocator.construct(&(values[id]), Value());
230
+ }
231
+
232
+ // \brief Adds more new keys to the map.
233
+ //
234
+ // It adds more new keys to the map. It is called by the observer notifier
235
+ // and it overrides the add() member function of the observer base.
236
+ virtual void add(const std::vector<Key>& keys) {
237
+ Notifier* nf = Parent::notifier();
238
+ int max_id = -1;
239
+ for (int i = 0; i < int(keys.size()); ++i) {
240
+ int id = nf->id(keys[i]);
241
+ if (id > max_id) {
242
+ max_id = id;
243
+ }
244
+ }
245
+ if (max_id >= capacity) {
246
+ int new_capacity = (capacity == 0 ? 1 : capacity);
247
+ while (new_capacity <= max_id) {
248
+ new_capacity <<= 1;
249
+ }
250
+ Value* new_values = allocator.allocate(new_capacity);
251
+ Item it;
252
+ for (nf->first(it); it != INVALID; nf->next(it)) {
253
+ int id = nf->id(it);
254
+ bool found = false;
255
+ for (int i = 0; i < int(keys.size()); ++i) {
256
+ int jd = nf->id(keys[i]);
257
+ if (id == jd) {
258
+ found = true;
259
+ break;
260
+ }
261
+ }
262
+ if (found) continue;
263
+ allocator.construct(&(new_values[id]), values[id]);
264
+ allocator.destroy(&(values[id]));
265
+ }
266
+ if (capacity != 0) allocator.deallocate(values, capacity);
267
+ values = new_values;
268
+ capacity = new_capacity;
269
+ }
270
+ for (int i = 0; i < int(keys.size()); ++i) {
271
+ int id = nf->id(keys[i]);
272
+ allocator.construct(&(values[id]), Value());
273
+ }
274
+ }
275
+
276
+ // \brief Erase a key from the map.
277
+ //
278
+ // Erase a key from the map. It is called by the observer notifier
279
+ // and it overrides the erase() member function of the observer base.
280
+ virtual void erase(const Key& key) {
281
+ int id = Parent::notifier()->id(key);
282
+ allocator.destroy(&(values[id]));
283
+ }
284
+
285
+ // \brief Erase more keys from the map.
286
+ //
287
+ // Erase more keys from the map. It is called by the observer notifier
288
+ // and it overrides the erase() member function of the observer base.
289
+ virtual void erase(const std::vector<Key>& keys) {
290
+ for (int i = 0; i < int(keys.size()); ++i) {
291
+ int id = Parent::notifier()->id(keys[i]);
292
+ allocator.destroy(&(values[id]));
293
+ }
294
+ }
295
+
296
+ // \brief Builds the map.
297
+ //
298
+ // It builds the map. It is called by the observer notifier
299
+ // and it overrides the build() member function of the observer base.
300
+ virtual void build() {
301
+ Notifier* nf = Parent::notifier();
302
+ allocate_memory();
303
+ Item it;
304
+ for (nf->first(it); it != INVALID; nf->next(it)) {
305
+ int id = nf->id(it);;
306
+ allocator.construct(&(values[id]), Value());
307
+ }
308
+ }
309
+
310
+ // \brief Clear the map.
311
+ //
312
+ // It erase all items from the map. It is called by the observer notifier
313
+ // and it overrides the clear() member function of the observer base.
314
+ virtual void clear() {
315
+ Notifier* nf = Parent::notifier();
316
+ if (capacity != 0) {
317
+ Item it;
318
+ for (nf->first(it); it != INVALID; nf->next(it)) {
319
+ int id = nf->id(it);
320
+ allocator.destroy(&(values[id]));
321
+ }
322
+ allocator.deallocate(values, capacity);
323
+ capacity = 0;
324
+ }
325
+ }
326
+
327
+ private:
328
+
329
+ void allocate_memory() {
330
+ int max_id = Parent::notifier()->maxId();
331
+ if (max_id == -1) {
332
+ capacity = 0;
333
+ values = 0;
334
+ return;
335
+ }
336
+ capacity = 1;
337
+ while (capacity <= max_id) {
338
+ capacity <<= 1;
339
+ }
340
+ values = allocator.allocate(capacity);
341
+ }
342
+
343
+ int capacity;
344
+ Value* values;
345
+ Allocator allocator;
346
+
347
+ };
348
+
349
+ }
350
+
351
+ #endif
@@ -0,0 +1,174 @@
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_BEZIER_H
20
+ #define LEMON_BEZIER_H
21
+
22
+ //\ingroup misc
23
+ //\file
24
+ //\brief Classes to compute with Bezier curves.
25
+ //
26
+ //Up to now this file is used internally by \ref graph_to_eps.h
27
+
28
+ #include<lemon/dim2.h>
29
+
30
+ namespace lemon {
31
+ namespace dim2 {
32
+
33
+ class BezierBase {
34
+ public:
35
+ typedef lemon::dim2::Point<double> Point;
36
+ protected:
37
+ static Point conv(Point x,Point y,double t) {return (1-t)*x+t*y;}
38
+ };
39
+
40
+ class Bezier1 : public BezierBase
41
+ {
42
+ public:
43
+ Point p1,p2;
44
+
45
+ Bezier1() {}
46
+ Bezier1(Point _p1, Point _p2) :p1(_p1), p2(_p2) {}
47
+
48
+ Point operator()(double t) const
49
+ {
50
+ // return conv(conv(p1,p2,t),conv(p2,p3,t),t);
51
+ return conv(p1,p2,t);
52
+ }
53
+ Bezier1 before(double t) const
54
+ {
55
+ return Bezier1(p1,conv(p1,p2,t));
56
+ }
57
+
58
+ Bezier1 after(double t) const
59
+ {
60
+ return Bezier1(conv(p1,p2,t),p2);
61
+ }
62
+
63
+ Bezier1 revert() const { return Bezier1(p2,p1);}
64
+ Bezier1 operator()(double a,double b) const { return before(b).after(a/b); }
65
+ Point grad() const { return p2-p1; }
66
+ Point norm() const { return rot90(p2-p1); }
67
+ Point grad(double) const { return grad(); }
68
+ Point norm(double t) const { return rot90(grad(t)); }
69
+ };
70
+
71
+ class Bezier2 : public BezierBase
72
+ {
73
+ public:
74
+ Point p1,p2,p3;
75
+
76
+ Bezier2() {}
77
+ Bezier2(Point _p1, Point _p2, Point _p3) :p1(_p1), p2(_p2), p3(_p3) {}
78
+ Bezier2(const Bezier1 &b) : p1(b.p1), p2(conv(b.p1,b.p2,.5)), p3(b.p2) {}
79
+ Point operator()(double t) const
80
+ {
81
+ // return conv(conv(p1,p2,t),conv(p2,p3,t),t);
82
+ return ((1-t)*(1-t))*p1+(2*(1-t)*t)*p2+(t*t)*p3;
83
+ }
84
+ Bezier2 before(double t) const
85
+ {
86
+ Point q(conv(p1,p2,t));
87
+ Point r(conv(p2,p3,t));
88
+ return Bezier2(p1,q,conv(q,r,t));
89
+ }
90
+
91
+ Bezier2 after(double t) const
92
+ {
93
+ Point q(conv(p1,p2,t));
94
+ Point r(conv(p2,p3,t));
95
+ return Bezier2(conv(q,r,t),r,p3);
96
+ }
97
+ Bezier2 revert() const { return Bezier2(p3,p2,p1);}
98
+ Bezier2 operator()(double a,double b) const { return before(b).after(a/b); }
99
+ Bezier1 grad() const { return Bezier1(2.0*(p2-p1),2.0*(p3-p2)); }
100
+ Bezier1 norm() const { return Bezier1(2.0*rot90(p2-p1),2.0*rot90(p3-p2)); }
101
+ Point grad(double t) const { return grad()(t); }
102
+ Point norm(double t) const { return rot90(grad(t)); }
103
+ };
104
+
105
+ class Bezier3 : public BezierBase
106
+ {
107
+ public:
108
+ Point p1,p2,p3,p4;
109
+
110
+ Bezier3() {}
111
+ Bezier3(Point _p1, Point _p2, Point _p3, Point _p4)
112
+ : p1(_p1), p2(_p2), p3(_p3), p4(_p4) {}
113
+ Bezier3(const Bezier1 &b) : p1(b.p1), p2(conv(b.p1,b.p2,1.0/3.0)),
114
+ p3(conv(b.p1,b.p2,2.0/3.0)), p4(b.p2) {}
115
+ Bezier3(const Bezier2 &b) : p1(b.p1), p2(conv(b.p1,b.p2,2.0/3.0)),
116
+ p3(conv(b.p2,b.p3,1.0/3.0)), p4(b.p3) {}
117
+
118
+ Point operator()(double t) const
119
+ {
120
+ // return Bezier2(conv(p1,p2,t),conv(p2,p3,t),conv(p3,p4,t))(t);
121
+ return ((1-t)*(1-t)*(1-t))*p1+(3*t*(1-t)*(1-t))*p2+
122
+ (3*t*t*(1-t))*p3+(t*t*t)*p4;
123
+ }
124
+ Bezier3 before(double t) const
125
+ {
126
+ Point p(conv(p1,p2,t));
127
+ Point q(conv(p2,p3,t));
128
+ Point r(conv(p3,p4,t));
129
+ Point a(conv(p,q,t));
130
+ Point b(conv(q,r,t));
131
+ Point c(conv(a,b,t));
132
+ return Bezier3(p1,p,a,c);
133
+ }
134
+
135
+ Bezier3 after(double t) const
136
+ {
137
+ Point p(conv(p1,p2,t));
138
+ Point q(conv(p2,p3,t));
139
+ Point r(conv(p3,p4,t));
140
+ Point a(conv(p,q,t));
141
+ Point b(conv(q,r,t));
142
+ Point c(conv(a,b,t));
143
+ return Bezier3(c,b,r,p4);
144
+ }
145
+ Bezier3 revert() const { return Bezier3(p4,p3,p2,p1);}
146
+ Bezier3 operator()(double a,double b) const { return before(b).after(a/b); }
147
+ Bezier2 grad() const { return Bezier2(3.0*(p2-p1),3.0*(p3-p2),3.0*(p4-p3)); }
148
+ Bezier2 norm() const { return Bezier2(3.0*rot90(p2-p1),
149
+ 3.0*rot90(p3-p2),
150
+ 3.0*rot90(p4-p3)); }
151
+ Point grad(double t) const { return grad()(t); }
152
+ Point norm(double t) const { return rot90(grad(t)); }
153
+
154
+ template<class R,class F,class S,class D>
155
+ R recSplit(F &_f,const S &_s,D _d) const
156
+ {
157
+ const Point a=(p1+p2)/2;
158
+ const Point b=(p2+p3)/2;
159
+ const Point c=(p3+p4)/2;
160
+ const Point d=(a+b)/2;
161
+ const Point e=(b+c)/2;
162
+ // const Point f=(d+e)/2;
163
+ R f1=_f(Bezier3(p1,a,d,e),_d);
164
+ R f2=_f(Bezier3(e,d,c,p4),_d);
165
+ return _s(f1,f2);
166
+ }
167
+
168
+ };
169
+
170
+
171
+ } //END OF NAMESPACE dim2
172
+ } //END OF NAMESPACE lemon
173
+
174
+ #endif // LEMON_BEZIER_H
@@ -0,0 +1,182 @@
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_DEFAULT_MAP_H
20
+ #define LEMON_BITS_DEFAULT_MAP_H
21
+
22
+ #include <lemon/config.h>
23
+ #include <lemon/bits/array_map.h>
24
+ #include <lemon/bits/vector_map.h>
25
+ //#include <lemon/bits/debug_map.h>
26
+
27
+ //\ingroup graphbits
28
+ //\file
29
+ //\brief Graph maps that construct and destruct their elements dynamically.
30
+
31
+ namespace lemon {
32
+
33
+
34
+ //#ifndef LEMON_USE_DEBUG_MAP
35
+
36
+ template <typename _Graph, typename _Item, typename _Value>
37
+ struct DefaultMapSelector {
38
+ typedef ArrayMap<_Graph, _Item, _Value> Map;
39
+ };
40
+
41
+ // bool
42
+ template <typename _Graph, typename _Item>
43
+ struct DefaultMapSelector<_Graph, _Item, bool> {
44
+ typedef VectorMap<_Graph, _Item, bool> Map;
45
+ };
46
+
47
+ // char
48
+ template <typename _Graph, typename _Item>
49
+ struct DefaultMapSelector<_Graph, _Item, char> {
50
+ typedef VectorMap<_Graph, _Item, char> Map;
51
+ };
52
+
53
+ template <typename _Graph, typename _Item>
54
+ struct DefaultMapSelector<_Graph, _Item, signed char> {
55
+ typedef VectorMap<_Graph, _Item, signed char> Map;
56
+ };
57
+
58
+ template <typename _Graph, typename _Item>
59
+ struct DefaultMapSelector<_Graph, _Item, unsigned char> {
60
+ typedef VectorMap<_Graph, _Item, unsigned char> Map;
61
+ };
62
+
63
+
64
+ // int
65
+ template <typename _Graph, typename _Item>
66
+ struct DefaultMapSelector<_Graph, _Item, signed int> {
67
+ typedef VectorMap<_Graph, _Item, signed int> Map;
68
+ };
69
+
70
+ template <typename _Graph, typename _Item>
71
+ struct DefaultMapSelector<_Graph, _Item, unsigned int> {
72
+ typedef VectorMap<_Graph, _Item, unsigned int> Map;
73
+ };
74
+
75
+
76
+ // short
77
+ template <typename _Graph, typename _Item>
78
+ struct DefaultMapSelector<_Graph, _Item, signed short> {
79
+ typedef VectorMap<_Graph, _Item, signed short> Map;
80
+ };
81
+
82
+ template <typename _Graph, typename _Item>
83
+ struct DefaultMapSelector<_Graph, _Item, unsigned short> {
84
+ typedef VectorMap<_Graph, _Item, unsigned short> Map;
85
+ };
86
+
87
+
88
+ // long
89
+ template <typename _Graph, typename _Item>
90
+ struct DefaultMapSelector<_Graph, _Item, signed long> {
91
+ typedef VectorMap<_Graph, _Item, signed long> Map;
92
+ };
93
+
94
+ template <typename _Graph, typename _Item>
95
+ struct DefaultMapSelector<_Graph, _Item, unsigned long> {
96
+ typedef VectorMap<_Graph, _Item, unsigned long> Map;
97
+ };
98
+
99
+
100
+ #if defined LEMON_HAVE_LONG_LONG
101
+
102
+ // long long
103
+ template <typename _Graph, typename _Item>
104
+ struct DefaultMapSelector<_Graph, _Item, signed long long> {
105
+ typedef VectorMap<_Graph, _Item, signed long long> Map;
106
+ };
107
+
108
+ template <typename _Graph, typename _Item>
109
+ struct DefaultMapSelector<_Graph, _Item, unsigned long long> {
110
+ typedef VectorMap<_Graph, _Item, unsigned long long> Map;
111
+ };
112
+
113
+ #endif
114
+
115
+
116
+ // float
117
+ template <typename _Graph, typename _Item>
118
+ struct DefaultMapSelector<_Graph, _Item, float> {
119
+ typedef VectorMap<_Graph, _Item, float> Map;
120
+ };
121
+
122
+
123
+ // double
124
+ template <typename _Graph, typename _Item>
125
+ struct DefaultMapSelector<_Graph, _Item, double> {
126
+ typedef VectorMap<_Graph, _Item, double> Map;
127
+ };
128
+
129
+
130
+ // long double
131
+ template <typename _Graph, typename _Item>
132
+ struct DefaultMapSelector<_Graph, _Item, long double> {
133
+ typedef VectorMap<_Graph, _Item, long double> Map;
134
+ };
135
+
136
+
137
+ // pointer
138
+ template <typename _Graph, typename _Item, typename _Ptr>
139
+ struct DefaultMapSelector<_Graph, _Item, _Ptr*> {
140
+ typedef VectorMap<_Graph, _Item, _Ptr*> Map;
141
+ };
142
+
143
+ // #else
144
+
145
+ // template <typename _Graph, typename _Item, typename _Value>
146
+ // struct DefaultMapSelector {
147
+ // typedef DebugMap<_Graph, _Item, _Value> Map;
148
+ // };
149
+
150
+ // #endif
151
+
152
+ // DefaultMap class
153
+ template <typename _Graph, typename _Item, typename _Value>
154
+ class DefaultMap
155
+ : public DefaultMapSelector<_Graph, _Item, _Value>::Map {
156
+ typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent;
157
+
158
+ public:
159
+ typedef DefaultMap<_Graph, _Item, _Value> Map;
160
+
161
+ typedef typename Parent::GraphType GraphType;
162
+ typedef typename Parent::Value Value;
163
+
164
+ explicit DefaultMap(const GraphType& graph) : Parent(graph) {}
165
+ DefaultMap(const GraphType& graph, const Value& value)
166
+ : Parent(graph, value) {}
167
+
168
+ DefaultMap& operator=(const DefaultMap& cmap) {
169
+ return operator=<DefaultMap>(cmap);
170
+ }
171
+
172
+ template <typename CMap>
173
+ DefaultMap& operator=(const CMap& cmap) {
174
+ Parent::operator=(cmap);
175
+ return *this;
176
+ }
177
+
178
+ };
179
+
180
+ }
181
+
182
+ #endif