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,464 @@
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
+ #include <lemon/clp.h>
20
+ #include <coin/ClpSimplex.hpp>
21
+
22
+ namespace lemon {
23
+
24
+ ClpLp::ClpLp() {
25
+ _prob = new ClpSimplex();
26
+ _init_temporals();
27
+ messageLevel(MESSAGE_NOTHING);
28
+ }
29
+
30
+ ClpLp::ClpLp(const ClpLp& other) {
31
+ _prob = new ClpSimplex(*other._prob);
32
+ rows = other.rows;
33
+ cols = other.cols;
34
+ _init_temporals();
35
+ messageLevel(MESSAGE_NOTHING);
36
+ }
37
+
38
+ ClpLp::~ClpLp() {
39
+ delete _prob;
40
+ _clear_temporals();
41
+ }
42
+
43
+ void ClpLp::_init_temporals() {
44
+ _primal_ray = 0;
45
+ _dual_ray = 0;
46
+ }
47
+
48
+ void ClpLp::_clear_temporals() {
49
+ if (_primal_ray) {
50
+ delete[] _primal_ray;
51
+ _primal_ray = 0;
52
+ }
53
+ if (_dual_ray) {
54
+ delete[] _dual_ray;
55
+ _dual_ray = 0;
56
+ }
57
+ }
58
+
59
+ ClpLp* ClpLp::newSolver() const {
60
+ ClpLp* newlp = new ClpLp;
61
+ return newlp;
62
+ }
63
+
64
+ ClpLp* ClpLp::cloneSolver() const {
65
+ ClpLp* copylp = new ClpLp(*this);
66
+ return copylp;
67
+ }
68
+
69
+ const char* ClpLp::_solverName() const { return "ClpLp"; }
70
+
71
+ int ClpLp::_addCol() {
72
+ _prob->addColumn(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX, 0.0);
73
+ return _prob->numberColumns() - 1;
74
+ }
75
+
76
+ int ClpLp::_addRow() {
77
+ _prob->addRow(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX);
78
+ return _prob->numberRows() - 1;
79
+ }
80
+
81
+ int ClpLp::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
82
+ std::vector<int> indexes;
83
+ std::vector<Value> values;
84
+
85
+ for(ExprIterator it = b; it != e; ++it) {
86
+ indexes.push_back(it->first);
87
+ values.push_back(it->second);
88
+ }
89
+
90
+ _prob->addRow(values.size(), &indexes.front(), &values.front(), l, u);
91
+ return _prob->numberRows() - 1;
92
+ }
93
+
94
+
95
+ void ClpLp::_eraseCol(int c) {
96
+ _col_names_ref.erase(_prob->getColumnName(c));
97
+ _prob->deleteColumns(1, &c);
98
+ }
99
+
100
+ void ClpLp::_eraseRow(int r) {
101
+ _row_names_ref.erase(_prob->getRowName(r));
102
+ _prob->deleteRows(1, &r);
103
+ }
104
+
105
+ void ClpLp::_eraseColId(int i) {
106
+ cols.eraseIndex(i);
107
+ cols.shiftIndices(i);
108
+ }
109
+
110
+ void ClpLp::_eraseRowId(int i) {
111
+ rows.eraseIndex(i);
112
+ rows.shiftIndices(i);
113
+ }
114
+
115
+ void ClpLp::_getColName(int c, std::string& name) const {
116
+ name = _prob->getColumnName(c);
117
+ }
118
+
119
+ void ClpLp::_setColName(int c, const std::string& name) {
120
+ _prob->setColumnName(c, const_cast<std::string&>(name));
121
+ _col_names_ref[name] = c;
122
+ }
123
+
124
+ int ClpLp::_colByName(const std::string& name) const {
125
+ std::map<std::string, int>::const_iterator it = _col_names_ref.find(name);
126
+ return it != _col_names_ref.end() ? it->second : -1;
127
+ }
128
+
129
+ void ClpLp::_getRowName(int r, std::string& name) const {
130
+ name = _prob->getRowName(r);
131
+ }
132
+
133
+ void ClpLp::_setRowName(int r, const std::string& name) {
134
+ _prob->setRowName(r, const_cast<std::string&>(name));
135
+ _row_names_ref[name] = r;
136
+ }
137
+
138
+ int ClpLp::_rowByName(const std::string& name) const {
139
+ std::map<std::string, int>::const_iterator it = _row_names_ref.find(name);
140
+ return it != _row_names_ref.end() ? it->second : -1;
141
+ }
142
+
143
+
144
+ void ClpLp::_setRowCoeffs(int ix, ExprIterator b, ExprIterator e) {
145
+ std::map<int, Value> coeffs;
146
+
147
+ int n = _prob->clpMatrix()->getNumCols();
148
+
149
+ const int* indices = _prob->clpMatrix()->getIndices();
150
+ const double* elements = _prob->clpMatrix()->getElements();
151
+
152
+ for (int i = 0; i < n; ++i) {
153
+ CoinBigIndex begin = _prob->clpMatrix()->getVectorStarts()[i];
154
+ CoinBigIndex end = begin + _prob->clpMatrix()->getVectorLengths()[i];
155
+
156
+ const int* it = std::lower_bound(indices + begin, indices + end, ix);
157
+ if (it != indices + end && *it == ix && elements[it - indices] != 0.0) {
158
+ coeffs[i] = 0.0;
159
+ }
160
+ }
161
+
162
+ for (ExprIterator it = b; it != e; ++it) {
163
+ coeffs[it->first] = it->second;
164
+ }
165
+
166
+ for (std::map<int, Value>::iterator it = coeffs.begin();
167
+ it != coeffs.end(); ++it) {
168
+ _prob->modifyCoefficient(ix, it->first, it->second);
169
+ }
170
+ }
171
+
172
+ void ClpLp::_getRowCoeffs(int ix, InsertIterator b) const {
173
+ int n = _prob->clpMatrix()->getNumCols();
174
+
175
+ const int* indices = _prob->clpMatrix()->getIndices();
176
+ const double* elements = _prob->clpMatrix()->getElements();
177
+
178
+ for (int i = 0; i < n; ++i) {
179
+ CoinBigIndex begin = _prob->clpMatrix()->getVectorStarts()[i];
180
+ CoinBigIndex end = begin + _prob->clpMatrix()->getVectorLengths()[i];
181
+
182
+ const int* it = std::lower_bound(indices + begin, indices + end, ix);
183
+ if (it != indices + end && *it == ix) {
184
+ *b = std::make_pair(i, elements[it - indices]);
185
+ }
186
+ }
187
+ }
188
+
189
+ void ClpLp::_setColCoeffs(int ix, ExprIterator b, ExprIterator e) {
190
+ std::map<int, Value> coeffs;
191
+
192
+ CoinBigIndex begin = _prob->clpMatrix()->getVectorStarts()[ix];
193
+ CoinBigIndex end = begin + _prob->clpMatrix()->getVectorLengths()[ix];
194
+
195
+ const int* indices = _prob->clpMatrix()->getIndices();
196
+ const double* elements = _prob->clpMatrix()->getElements();
197
+
198
+ for (CoinBigIndex i = begin; i != end; ++i) {
199
+ if (elements[i] != 0.0) {
200
+ coeffs[indices[i]] = 0.0;
201
+ }
202
+ }
203
+ for (ExprIterator it = b; it != e; ++it) {
204
+ coeffs[it->first] = it->second;
205
+ }
206
+ for (std::map<int, Value>::iterator it = coeffs.begin();
207
+ it != coeffs.end(); ++it) {
208
+ _prob->modifyCoefficient(it->first, ix, it->second);
209
+ }
210
+ }
211
+
212
+ void ClpLp::_getColCoeffs(int ix, InsertIterator b) const {
213
+ CoinBigIndex begin = _prob->clpMatrix()->getVectorStarts()[ix];
214
+ CoinBigIndex end = begin + _prob->clpMatrix()->getVectorLengths()[ix];
215
+
216
+ const int* indices = _prob->clpMatrix()->getIndices();
217
+ const double* elements = _prob->clpMatrix()->getElements();
218
+
219
+ for (CoinBigIndex i = begin; i != end; ++i) {
220
+ *b = std::make_pair(indices[i], elements[i]);
221
+ ++b;
222
+ }
223
+ }
224
+
225
+ void ClpLp::_setCoeff(int ix, int jx, Value value) {
226
+ _prob->modifyCoefficient(ix, jx, value);
227
+ }
228
+
229
+ ClpLp::Value ClpLp::_getCoeff(int ix, int jx) const {
230
+ CoinBigIndex begin = _prob->clpMatrix()->getVectorStarts()[ix];
231
+ CoinBigIndex end = begin + _prob->clpMatrix()->getVectorLengths()[ix];
232
+
233
+ const int* indices = _prob->clpMatrix()->getIndices();
234
+ const double* elements = _prob->clpMatrix()->getElements();
235
+
236
+ const int* it = std::lower_bound(indices + begin, indices + end, jx);
237
+ if (it != indices + end && *it == jx) {
238
+ return elements[it - indices];
239
+ } else {
240
+ return 0.0;
241
+ }
242
+ }
243
+
244
+ void ClpLp::_setColLowerBound(int i, Value lo) {
245
+ _prob->setColumnLower(i, lo == - INF ? - COIN_DBL_MAX : lo);
246
+ }
247
+
248
+ ClpLp::Value ClpLp::_getColLowerBound(int i) const {
249
+ double val = _prob->getColLower()[i];
250
+ return val == - COIN_DBL_MAX ? - INF : val;
251
+ }
252
+
253
+ void ClpLp::_setColUpperBound(int i, Value up) {
254
+ _prob->setColumnUpper(i, up == INF ? COIN_DBL_MAX : up);
255
+ }
256
+
257
+ ClpLp::Value ClpLp::_getColUpperBound(int i) const {
258
+ double val = _prob->getColUpper()[i];
259
+ return val == COIN_DBL_MAX ? INF : val;
260
+ }
261
+
262
+ void ClpLp::_setRowLowerBound(int i, Value lo) {
263
+ _prob->setRowLower(i, lo == - INF ? - COIN_DBL_MAX : lo);
264
+ }
265
+
266
+ ClpLp::Value ClpLp::_getRowLowerBound(int i) const {
267
+ double val = _prob->getRowLower()[i];
268
+ return val == - COIN_DBL_MAX ? - INF : val;
269
+ }
270
+
271
+ void ClpLp::_setRowUpperBound(int i, Value up) {
272
+ _prob->setRowUpper(i, up == INF ? COIN_DBL_MAX : up);
273
+ }
274
+
275
+ ClpLp::Value ClpLp::_getRowUpperBound(int i) const {
276
+ double val = _prob->getRowUpper()[i];
277
+ return val == COIN_DBL_MAX ? INF : val;
278
+ }
279
+
280
+ void ClpLp::_setObjCoeffs(ExprIterator b, ExprIterator e) {
281
+ int num = _prob->clpMatrix()->getNumCols();
282
+ for (int i = 0; i < num; ++i) {
283
+ _prob->setObjectiveCoefficient(i, 0.0);
284
+ }
285
+ for (ExprIterator it = b; it != e; ++it) {
286
+ _prob->setObjectiveCoefficient(it->first, it->second);
287
+ }
288
+ }
289
+
290
+ void ClpLp::_getObjCoeffs(InsertIterator b) const {
291
+ int num = _prob->clpMatrix()->getNumCols();
292
+ for (int i = 0; i < num; ++i) {
293
+ Value coef = _prob->getObjCoefficients()[i];
294
+ if (coef != 0.0) {
295
+ *b = std::make_pair(i, coef);
296
+ ++b;
297
+ }
298
+ }
299
+ }
300
+
301
+ void ClpLp::_setObjCoeff(int i, Value obj_coef) {
302
+ _prob->setObjectiveCoefficient(i, obj_coef);
303
+ }
304
+
305
+ ClpLp::Value ClpLp::_getObjCoeff(int i) const {
306
+ return _prob->getObjCoefficients()[i];
307
+ }
308
+
309
+ ClpLp::SolveExitStatus ClpLp::_solve() {
310
+ return _prob->primal() >= 0 ? SOLVED : UNSOLVED;
311
+ }
312
+
313
+ ClpLp::SolveExitStatus ClpLp::solvePrimal() {
314
+ return _prob->primal() >= 0 ? SOLVED : UNSOLVED;
315
+ }
316
+
317
+ ClpLp::SolveExitStatus ClpLp::solveDual() {
318
+ return _prob->dual() >= 0 ? SOLVED : UNSOLVED;
319
+ }
320
+
321
+ ClpLp::SolveExitStatus ClpLp::solveBarrier() {
322
+ return _prob->barrier() >= 0 ? SOLVED : UNSOLVED;
323
+ }
324
+
325
+ ClpLp::Value ClpLp::_getPrimal(int i) const {
326
+ return _prob->primalColumnSolution()[i];
327
+ }
328
+ ClpLp::Value ClpLp::_getPrimalValue() const {
329
+ return _prob->objectiveValue();
330
+ }
331
+
332
+ ClpLp::Value ClpLp::_getDual(int i) const {
333
+ return _prob->dualRowSolution()[i];
334
+ }
335
+
336
+ ClpLp::Value ClpLp::_getPrimalRay(int i) const {
337
+ if (!_primal_ray) {
338
+ _primal_ray = _prob->unboundedRay();
339
+ LEMON_ASSERT(_primal_ray != 0, "Primal ray is not provided");
340
+ }
341
+ return _primal_ray[i];
342
+ }
343
+
344
+ ClpLp::Value ClpLp::_getDualRay(int i) const {
345
+ if (!_dual_ray) {
346
+ _dual_ray = _prob->infeasibilityRay();
347
+ LEMON_ASSERT(_dual_ray != 0, "Dual ray is not provided");
348
+ }
349
+ return _dual_ray[i];
350
+ }
351
+
352
+ ClpLp::VarStatus ClpLp::_getColStatus(int i) const {
353
+ switch (_prob->getColumnStatus(i)) {
354
+ case ClpSimplex::basic:
355
+ return BASIC;
356
+ case ClpSimplex::isFree:
357
+ return FREE;
358
+ case ClpSimplex::atUpperBound:
359
+ return UPPER;
360
+ case ClpSimplex::atLowerBound:
361
+ return LOWER;
362
+ case ClpSimplex::isFixed:
363
+ return FIXED;
364
+ case ClpSimplex::superBasic:
365
+ return FREE;
366
+ default:
367
+ LEMON_ASSERT(false, "Wrong column status");
368
+ return VarStatus();
369
+ }
370
+ }
371
+
372
+ ClpLp::VarStatus ClpLp::_getRowStatus(int i) const {
373
+ switch (_prob->getColumnStatus(i)) {
374
+ case ClpSimplex::basic:
375
+ return BASIC;
376
+ case ClpSimplex::isFree:
377
+ return FREE;
378
+ case ClpSimplex::atUpperBound:
379
+ return UPPER;
380
+ case ClpSimplex::atLowerBound:
381
+ return LOWER;
382
+ case ClpSimplex::isFixed:
383
+ return FIXED;
384
+ case ClpSimplex::superBasic:
385
+ return FREE;
386
+ default:
387
+ LEMON_ASSERT(false, "Wrong row status");
388
+ return VarStatus();
389
+ }
390
+ }
391
+
392
+
393
+ ClpLp::ProblemType ClpLp::_getPrimalType() const {
394
+ if (_prob->isProvenOptimal()) {
395
+ return OPTIMAL;
396
+ } else if (_prob->isProvenPrimalInfeasible()) {
397
+ return INFEASIBLE;
398
+ } else if (_prob->isProvenDualInfeasible()) {
399
+ return UNBOUNDED;
400
+ } else {
401
+ return UNDEFINED;
402
+ }
403
+ }
404
+
405
+ ClpLp::ProblemType ClpLp::_getDualType() const {
406
+ if (_prob->isProvenOptimal()) {
407
+ return OPTIMAL;
408
+ } else if (_prob->isProvenDualInfeasible()) {
409
+ return INFEASIBLE;
410
+ } else if (_prob->isProvenPrimalInfeasible()) {
411
+ return INFEASIBLE;
412
+ } else {
413
+ return UNDEFINED;
414
+ }
415
+ }
416
+
417
+ void ClpLp::_setSense(ClpLp::Sense sense) {
418
+ switch (sense) {
419
+ case MIN:
420
+ _prob->setOptimizationDirection(1);
421
+ break;
422
+ case MAX:
423
+ _prob->setOptimizationDirection(-1);
424
+ break;
425
+ }
426
+ }
427
+
428
+ ClpLp::Sense ClpLp::_getSense() const {
429
+ double dir = _prob->optimizationDirection();
430
+ if (dir > 0.0) {
431
+ return MIN;
432
+ } else {
433
+ return MAX;
434
+ }
435
+ }
436
+
437
+ void ClpLp::_clear() {
438
+ delete _prob;
439
+ _prob = new ClpSimplex();
440
+ _col_names_ref.clear();
441
+ _clear_temporals();
442
+ }
443
+
444
+ void ClpLp::_messageLevel(MessageLevel level) {
445
+ switch (level) {
446
+ case MESSAGE_NOTHING:
447
+ _prob->setLogLevel(0);
448
+ break;
449
+ case MESSAGE_ERROR:
450
+ _prob->setLogLevel(1);
451
+ break;
452
+ case MESSAGE_WARNING:
453
+ _prob->setLogLevel(2);
454
+ break;
455
+ case MESSAGE_NORMAL:
456
+ _prob->setLogLevel(3);
457
+ break;
458
+ case MESSAGE_VERBOSE:
459
+ _prob->setLogLevel(4);
460
+ break;
461
+ }
462
+ }
463
+
464
+ } //END OF NAMESPACE LEMON
@@ -0,0 +1,164 @@
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_CLP_H
20
+ #define LEMON_CLP_H
21
+
22
+ ///\file
23
+ ///\brief Header of the LEMON-CLP lp solver interface.
24
+
25
+ #include <vector>
26
+ #include <string>
27
+
28
+ #include <lemon/lp_base.h>
29
+
30
+ class ClpSimplex;
31
+
32
+ namespace lemon {
33
+
34
+ /// \ingroup lp_group
35
+ ///
36
+ /// \brief Interface for the CLP solver
37
+ ///
38
+ /// This class implements an interface for the Clp LP solver. The
39
+ /// Clp library is an object oriented lp solver library developed at
40
+ /// the IBM. The CLP is part of the COIN-OR package and it can be
41
+ /// used with Common Public License.
42
+ class ClpLp : public LpSolver {
43
+ protected:
44
+
45
+ ClpSimplex* _prob;
46
+
47
+ std::map<std::string, int> _col_names_ref;
48
+ std::map<std::string, int> _row_names_ref;
49
+
50
+ public:
51
+
52
+ /// \e
53
+ ClpLp();
54
+ /// \e
55
+ ClpLp(const ClpLp&);
56
+ /// \e
57
+ ~ClpLp();
58
+
59
+ /// \e
60
+ virtual ClpLp* newSolver() const;
61
+ /// \e
62
+ virtual ClpLp* cloneSolver() const;
63
+
64
+ protected:
65
+
66
+ mutable double* _primal_ray;
67
+ mutable double* _dual_ray;
68
+
69
+ void _init_temporals();
70
+ void _clear_temporals();
71
+
72
+ protected:
73
+
74
+ virtual const char* _solverName() const;
75
+
76
+ virtual int _addCol();
77
+ virtual int _addRow();
78
+ virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
79
+
80
+ virtual void _eraseCol(int i);
81
+ virtual void _eraseRow(int i);
82
+
83
+ virtual void _eraseColId(int i);
84
+ virtual void _eraseRowId(int i);
85
+
86
+ virtual void _getColName(int col, std::string& name) const;
87
+ virtual void _setColName(int col, const std::string& name);
88
+ virtual int _colByName(const std::string& name) const;
89
+
90
+ virtual void _getRowName(int row, std::string& name) const;
91
+ virtual void _setRowName(int row, const std::string& name);
92
+ virtual int _rowByName(const std::string& name) const;
93
+
94
+ virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e);
95
+ virtual void _getRowCoeffs(int i, InsertIterator b) const;
96
+
97
+ virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e);
98
+ virtual void _getColCoeffs(int i, InsertIterator b) const;
99
+
100
+ virtual void _setCoeff(int row, int col, Value value);
101
+ virtual Value _getCoeff(int row, int col) const;
102
+
103
+ virtual void _setColLowerBound(int i, Value value);
104
+ virtual Value _getColLowerBound(int i) const;
105
+ virtual void _setColUpperBound(int i, Value value);
106
+ virtual Value _getColUpperBound(int i) const;
107
+
108
+ virtual void _setRowLowerBound(int i, Value value);
109
+ virtual Value _getRowLowerBound(int i) const;
110
+ virtual void _setRowUpperBound(int i, Value value);
111
+ virtual Value _getRowUpperBound(int i) const;
112
+
113
+ virtual void _setObjCoeffs(ExprIterator, ExprIterator);
114
+ virtual void _getObjCoeffs(InsertIterator) const;
115
+
116
+ virtual void _setObjCoeff(int i, Value obj_coef);
117
+ virtual Value _getObjCoeff(int i) const;
118
+
119
+ virtual void _setSense(Sense sense);
120
+ virtual Sense _getSense() const;
121
+
122
+ virtual SolveExitStatus _solve();
123
+
124
+ virtual Value _getPrimal(int i) const;
125
+ virtual Value _getDual(int i) const;
126
+
127
+ virtual Value _getPrimalValue() const;
128
+
129
+ virtual Value _getPrimalRay(int i) const;
130
+ virtual Value _getDualRay(int i) const;
131
+
132
+ virtual VarStatus _getColStatus(int i) const;
133
+ virtual VarStatus _getRowStatus(int i) const;
134
+
135
+ virtual ProblemType _getPrimalType() const;
136
+ virtual ProblemType _getDualType() const;
137
+
138
+ virtual void _clear();
139
+
140
+ virtual void _messageLevel(MessageLevel);
141
+
142
+ public:
143
+
144
+ ///Solves LP with primal simplex method.
145
+ SolveExitStatus solvePrimal();
146
+
147
+ ///Solves LP with dual simplex method.
148
+ SolveExitStatus solveDual();
149
+
150
+ ///Solves LP with barrier method.
151
+ SolveExitStatus solveBarrier();
152
+
153
+ ///Returns the constraint identifier understood by CLP.
154
+ int clpRow(Row r) const { return rows(id(r)); }
155
+
156
+ ///Returns the variable identifier understood by CLP.
157
+ int clpCol(Col c) const { return cols(id(c)); }
158
+
159
+ };
160
+
161
+ } //END OF NAMESPACE LEMON
162
+
163
+ #endif //LEMON_CLP_H
164
+
@@ -0,0 +1,44 @@
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-2009
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
+ ///\file
20
+ ///\brief Color constants
21
+
22
+ #include<lemon/color.h>
23
+
24
+ namespace lemon {
25
+
26
+ const Color WHITE(1,1,1);
27
+
28
+ const Color BLACK(0,0,0);
29
+ const Color RED(1,0,0);
30
+ const Color GREEN(0,1,0);
31
+ const Color BLUE(0,0,1);
32
+ const Color YELLOW(1,1,0);
33
+ const Color MAGENTA(1,0,1);
34
+ const Color CYAN(0,1,1);
35
+
36
+ const Color GREY(0,0,0);
37
+ const Color DARK_RED(.5,0,0);
38
+ const Color DARK_GREEN(0,.5,0);
39
+ const Color DARK_BLUE(0,0,.5);
40
+ const Color DARK_YELLOW(.5,.5,0);
41
+ const Color DARK_MAGENTA(.5,0,.5);
42
+ const Color DARK_CYAN(0,.5,.5);
43
+
44
+ } //namespace lemon