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.
- checksums.yaml +7 -0
- data/.yardopts +8 -0
- data/LICENSE +674 -0
- data/README.md +6 -0
- data/ext/lemon-1.3.1/AUTHORS +26 -0
- data/ext/lemon-1.3.1/CMakeLists.txt +371 -0
- data/ext/lemon-1.3.1/INSTALL +167 -0
- data/ext/lemon-1.3.1/LICENSE +32 -0
- data/ext/lemon-1.3.1/NEWS +337 -0
- data/ext/lemon-1.3.1/README +50 -0
- data/ext/lemon-1.3.1/cmake/FindCOIN.cmake +110 -0
- data/ext/lemon-1.3.1/cmake/FindGLPK.cmake +55 -0
- data/ext/lemon-1.3.1/cmake/FindGhostscript.cmake +10 -0
- data/ext/lemon-1.3.1/cmake/FindILOG.cmake +102 -0
- data/ext/lemon-1.3.1/cmake/FindSOPLEX.cmake +23 -0
- data/ext/lemon-1.3.1/cmake/LEMONConfig.cmake.in +13 -0
- data/ext/lemon-1.3.1/cmake/nsis/lemon.ico +0 -0
- data/ext/lemon-1.3.1/cmake/nsis/uninstall.ico +0 -0
- data/ext/lemon-1.3.1/cmake/version.cmake +1 -0
- data/ext/lemon-1.3.1/cmake/version.cmake.in +1 -0
- data/ext/lemon-1.3.1/contrib/CMakeLists.txt +19 -0
- data/ext/lemon-1.3.1/lemon/CMakeLists.txt +91 -0
- data/ext/lemon-1.3.1/lemon/adaptors.h +3638 -0
- data/ext/lemon-1.3.1/lemon/arg_parser.cc +474 -0
- data/ext/lemon-1.3.1/lemon/arg_parser.h +440 -0
- data/ext/lemon-1.3.1/lemon/assert.h +214 -0
- data/ext/lemon-1.3.1/lemon/base.cc +37 -0
- data/ext/lemon-1.3.1/lemon/bellman_ford.h +1116 -0
- data/ext/lemon-1.3.1/lemon/bfs.h +1754 -0
- data/ext/lemon-1.3.1/lemon/bin_heap.h +347 -0
- data/ext/lemon-1.3.1/lemon/binomial_heap.h +445 -0
- data/ext/lemon-1.3.1/lemon/bits/alteration_notifier.h +472 -0
- data/ext/lemon-1.3.1/lemon/bits/array_map.h +351 -0
- data/ext/lemon-1.3.1/lemon/bits/bezier.h +174 -0
- data/ext/lemon-1.3.1/lemon/bits/default_map.h +182 -0
- data/ext/lemon-1.3.1/lemon/bits/edge_set_extender.h +627 -0
- data/ext/lemon-1.3.1/lemon/bits/enable_if.h +131 -0
- data/ext/lemon-1.3.1/lemon/bits/graph_adaptor_extender.h +401 -0
- data/ext/lemon-1.3.1/lemon/bits/graph_extender.h +1332 -0
- data/ext/lemon-1.3.1/lemon/bits/lock.h +65 -0
- data/ext/lemon-1.3.1/lemon/bits/map_extender.h +332 -0
- data/ext/lemon-1.3.1/lemon/bits/path_dump.h +177 -0
- data/ext/lemon-1.3.1/lemon/bits/solver_bits.h +194 -0
- data/ext/lemon-1.3.1/lemon/bits/traits.h +388 -0
- data/ext/lemon-1.3.1/lemon/bits/variant.h +494 -0
- data/ext/lemon-1.3.1/lemon/bits/vector_map.h +244 -0
- data/ext/lemon-1.3.1/lemon/bits/windows.cc +166 -0
- data/ext/lemon-1.3.1/lemon/bits/windows.h +44 -0
- data/ext/lemon-1.3.1/lemon/bucket_heap.h +594 -0
- data/ext/lemon-1.3.1/lemon/capacity_scaling.h +1014 -0
- data/ext/lemon-1.3.1/lemon/cbc.cc +460 -0
- data/ext/lemon-1.3.1/lemon/cbc.h +129 -0
- data/ext/lemon-1.3.1/lemon/christofides_tsp.h +254 -0
- data/ext/lemon-1.3.1/lemon/circulation.h +807 -0
- data/ext/lemon-1.3.1/lemon/clp.cc +464 -0
- data/ext/lemon-1.3.1/lemon/clp.h +164 -0
- data/ext/lemon-1.3.1/lemon/color.cc +44 -0
- data/ext/lemon-1.3.1/lemon/color.h +204 -0
- data/ext/lemon-1.3.1/lemon/concept_check.h +77 -0
- data/ext/lemon-1.3.1/lemon/concepts/bpgraph.h +1029 -0
- data/ext/lemon-1.3.1/lemon/concepts/digraph.h +491 -0
- data/ext/lemon-1.3.1/lemon/concepts/graph.h +788 -0
- data/ext/lemon-1.3.1/lemon/concepts/graph_components.h +2134 -0
- data/ext/lemon-1.3.1/lemon/concepts/heap.h +324 -0
- data/ext/lemon-1.3.1/lemon/concepts/maps.h +223 -0
- data/ext/lemon-1.3.1/lemon/concepts/path.h +312 -0
- data/ext/lemon-1.3.1/lemon/config.h.in +22 -0
- data/ext/lemon-1.3.1/lemon/connectivity.h +1688 -0
- data/ext/lemon-1.3.1/lemon/core.h +2506 -0
- data/ext/lemon-1.3.1/lemon/cost_scaling.h +1607 -0
- data/ext/lemon-1.3.1/lemon/counter.h +249 -0
- data/ext/lemon-1.3.1/lemon/cplex.cc +994 -0
- data/ext/lemon-1.3.1/lemon/cplex.h +292 -0
- data/ext/lemon-1.3.1/lemon/cycle_canceling.h +1230 -0
- data/ext/lemon-1.3.1/lemon/dfs.h +1637 -0
- data/ext/lemon-1.3.1/lemon/dheap.h +352 -0
- data/ext/lemon-1.3.1/lemon/dijkstra.h +1303 -0
- data/ext/lemon-1.3.1/lemon/dim2.h +726 -0
- data/ext/lemon-1.3.1/lemon/dimacs.h +448 -0
- data/ext/lemon-1.3.1/lemon/edge_set.h +1420 -0
- data/ext/lemon-1.3.1/lemon/edmonds_karp.h +556 -0
- data/ext/lemon-1.3.1/lemon/elevator.h +982 -0
- data/ext/lemon-1.3.1/lemon/error.h +276 -0
- data/ext/lemon-1.3.1/lemon/euler.h +287 -0
- data/ext/lemon-1.3.1/lemon/fib_heap.h +475 -0
- data/ext/lemon-1.3.1/lemon/fractional_matching.h +2139 -0
- data/ext/lemon-1.3.1/lemon/full_graph.h +1082 -0
- data/ext/lemon-1.3.1/lemon/glpk.cc +1012 -0
- data/ext/lemon-1.3.1/lemon/glpk.h +263 -0
- data/ext/lemon-1.3.1/lemon/gomory_hu.h +568 -0
- data/ext/lemon-1.3.1/lemon/graph_to_eps.h +1186 -0
- data/ext/lemon-1.3.1/lemon/greedy_tsp.h +251 -0
- data/ext/lemon-1.3.1/lemon/grid_graph.h +699 -0
- data/ext/lemon-1.3.1/lemon/grosso_locatelli_pullan_mc.h +840 -0
- data/ext/lemon-1.3.1/lemon/hao_orlin.h +1015 -0
- data/ext/lemon-1.3.1/lemon/hartmann_orlin_mmc.h +654 -0
- data/ext/lemon-1.3.1/lemon/howard_mmc.h +651 -0
- data/ext/lemon-1.3.1/lemon/hypercube_graph.h +459 -0
- data/ext/lemon-1.3.1/lemon/insertion_tsp.h +533 -0
- data/ext/lemon-1.3.1/lemon/karp_mmc.h +590 -0
- data/ext/lemon-1.3.1/lemon/kruskal.h +324 -0
- data/ext/lemon-1.3.1/lemon/lemon.pc.in +10 -0
- data/ext/lemon-1.3.1/lemon/lgf_reader.h +3854 -0
- data/ext/lemon-1.3.1/lemon/lgf_writer.h +2687 -0
- data/ext/lemon-1.3.1/lemon/list_graph.h +2510 -0
- data/ext/lemon-1.3.1/lemon/lp.h +95 -0
- data/ext/lemon-1.3.1/lemon/lp_base.cc +30 -0
- data/ext/lemon-1.3.1/lemon/lp_base.h +2147 -0
- data/ext/lemon-1.3.1/lemon/lp_skeleton.cc +143 -0
- data/ext/lemon-1.3.1/lemon/lp_skeleton.h +234 -0
- data/ext/lemon-1.3.1/lemon/maps.h +4057 -0
- data/ext/lemon-1.3.1/lemon/matching.h +3505 -0
- data/ext/lemon-1.3.1/lemon/math.h +77 -0
- data/ext/lemon-1.3.1/lemon/max_cardinality_search.h +794 -0
- data/ext/lemon-1.3.1/lemon/min_cost_arborescence.h +808 -0
- data/ext/lemon-1.3.1/lemon/nagamochi_ibaraki.h +702 -0
- data/ext/lemon-1.3.1/lemon/nauty_reader.h +113 -0
- data/ext/lemon-1.3.1/lemon/nearest_neighbor_tsp.h +238 -0
- data/ext/lemon-1.3.1/lemon/network_simplex.h +1659 -0
- data/ext/lemon-1.3.1/lemon/opt2_tsp.h +367 -0
- data/ext/lemon-1.3.1/lemon/pairing_heap.h +474 -0
- data/ext/lemon-1.3.1/lemon/path.h +1164 -0
- data/ext/lemon-1.3.1/lemon/planarity.h +2754 -0
- data/ext/lemon-1.3.1/lemon/preflow.h +985 -0
- data/ext/lemon-1.3.1/lemon/quad_heap.h +343 -0
- data/ext/lemon-1.3.1/lemon/radix_heap.h +438 -0
- data/ext/lemon-1.3.1/lemon/radix_sort.h +487 -0
- data/ext/lemon-1.3.1/lemon/random.cc +29 -0
- data/ext/lemon-1.3.1/lemon/random.h +1005 -0
- data/ext/lemon-1.3.1/lemon/smart_graph.h +1344 -0
- data/ext/lemon-1.3.1/lemon/soplex.cc +465 -0
- data/ext/lemon-1.3.1/lemon/soplex.h +158 -0
- data/ext/lemon-1.3.1/lemon/static_graph.h +476 -0
- data/ext/lemon-1.3.1/lemon/suurballe.h +776 -0
- data/ext/lemon-1.3.1/lemon/time_measure.h +610 -0
- data/ext/lemon-1.3.1/lemon/tolerance.h +242 -0
- data/ext/lemon-1.3.1/lemon/unionfind.h +1824 -0
- data/ext/lemon-1.3.1/scripts/unify-sources.sh +390 -0
- data/ext/lemon-1.3.1/scripts/valgrind-wrapper.sh +22 -0
- data/ext/lemongraph/arc_map.cc +1007 -0
- data/ext/lemongraph/digraph.cc +282 -0
- data/ext/lemongraph/digraph_arc.cc +153 -0
- data/ext/lemongraph/digraph_node.cc +277 -0
- data/ext/lemongraph/edge_map.cc +770 -0
- data/ext/lemongraph/extconf.rb +53 -0
- data/ext/lemongraph/graph.cc +351 -0
- data/ext/lemongraph/graph_arc.cc +95 -0
- data/ext/lemongraph/graph_edge.cc +153 -0
- data/ext/lemongraph/graph_item.cc +76 -0
- data/ext/lemongraph/graph_node.cc +321 -0
- data/ext/lemongraph/lemongraph.cc +260 -0
- data/ext/lemongraph/lemongraph.hh +295 -0
- data/ext/lemongraph/lemongraph.map +6 -0
- data/ext/lemongraph/lemongraph_export.hh +31 -0
- data/ext/lemongraph/node_map.cc +1011 -0
- data/lemongraph.gemspec +176 -0
- data/lib/lemongraph/graphviz.rb +240 -0
- data/lib/lemongraph/version.rb +4 -0
- data/lib/lemongraph.rb +21 -0
- data/samples/lemondeps.rb +38 -0
- metadata +202 -0
|
@@ -0,0 +1,465 @@
|
|
|
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 <iostream>
|
|
20
|
+
#include <lemon/soplex.h>
|
|
21
|
+
|
|
22
|
+
#include <soplex.h>
|
|
23
|
+
#include <spxout.h>
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
///\file
|
|
27
|
+
///\brief Implementation of the LEMON-SOPLEX lp solver interface.
|
|
28
|
+
namespace lemon {
|
|
29
|
+
|
|
30
|
+
SoplexLp::SoplexLp() {
|
|
31
|
+
soplex = new soplex::SoPlex;
|
|
32
|
+
messageLevel(MESSAGE_NOTHING);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
SoplexLp::~SoplexLp() {
|
|
36
|
+
delete soplex;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
SoplexLp::SoplexLp(const SoplexLp& lp) {
|
|
40
|
+
rows = lp.rows;
|
|
41
|
+
cols = lp.cols;
|
|
42
|
+
|
|
43
|
+
soplex = new soplex::SoPlex;
|
|
44
|
+
(*static_cast<soplex::SPxLP*>(soplex)) = *(lp.soplex);
|
|
45
|
+
|
|
46
|
+
_col_names = lp._col_names;
|
|
47
|
+
_col_names_ref = lp._col_names_ref;
|
|
48
|
+
|
|
49
|
+
_row_names = lp._row_names;
|
|
50
|
+
_row_names_ref = lp._row_names_ref;
|
|
51
|
+
|
|
52
|
+
messageLevel(MESSAGE_NOTHING);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
void SoplexLp::_clear_temporals() {
|
|
56
|
+
_primal_values.clear();
|
|
57
|
+
_dual_values.clear();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
SoplexLp* SoplexLp::newSolver() const {
|
|
61
|
+
SoplexLp* newlp = new SoplexLp();
|
|
62
|
+
return newlp;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
SoplexLp* SoplexLp::cloneSolver() const {
|
|
66
|
+
SoplexLp* newlp = new SoplexLp(*this);
|
|
67
|
+
return newlp;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const char* SoplexLp::_solverName() const { return "SoplexLp"; }
|
|
71
|
+
|
|
72
|
+
int SoplexLp::_addCol() {
|
|
73
|
+
soplex::LPCol c;
|
|
74
|
+
c.setLower(-soplex::infinity);
|
|
75
|
+
c.setUpper(soplex::infinity);
|
|
76
|
+
soplex->addCol(c);
|
|
77
|
+
|
|
78
|
+
_col_names.push_back(std::string());
|
|
79
|
+
|
|
80
|
+
return soplex->nCols() - 1;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
int SoplexLp::_addRow() {
|
|
84
|
+
soplex::LPRow r;
|
|
85
|
+
r.setLhs(-soplex::infinity);
|
|
86
|
+
r.setRhs(soplex::infinity);
|
|
87
|
+
soplex->addRow(r);
|
|
88
|
+
|
|
89
|
+
_row_names.push_back(std::string());
|
|
90
|
+
|
|
91
|
+
return soplex->nRows() - 1;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
int SoplexLp::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
|
|
95
|
+
soplex::DSVector v;
|
|
96
|
+
for (ExprIterator it = b; it != e; ++it) {
|
|
97
|
+
v.add(it->first, it->second);
|
|
98
|
+
}
|
|
99
|
+
soplex::LPRow r(l, v, u);
|
|
100
|
+
soplex->addRow(r);
|
|
101
|
+
|
|
102
|
+
_row_names.push_back(std::string());
|
|
103
|
+
|
|
104
|
+
return soplex->nRows() - 1;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
void SoplexLp::_eraseCol(int i) {
|
|
109
|
+
soplex->removeCol(i);
|
|
110
|
+
_col_names_ref.erase(_col_names[i]);
|
|
111
|
+
_col_names[i] = _col_names.back();
|
|
112
|
+
_col_names_ref[_col_names.back()] = i;
|
|
113
|
+
_col_names.pop_back();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
void SoplexLp::_eraseRow(int i) {
|
|
117
|
+
soplex->removeRow(i);
|
|
118
|
+
_row_names_ref.erase(_row_names[i]);
|
|
119
|
+
_row_names[i] = _row_names.back();
|
|
120
|
+
_row_names_ref[_row_names.back()] = i;
|
|
121
|
+
_row_names.pop_back();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
void SoplexLp::_eraseColId(int i) {
|
|
125
|
+
cols.eraseIndex(i);
|
|
126
|
+
cols.relocateIndex(i, cols.maxIndex());
|
|
127
|
+
}
|
|
128
|
+
void SoplexLp::_eraseRowId(int i) {
|
|
129
|
+
rows.eraseIndex(i);
|
|
130
|
+
rows.relocateIndex(i, rows.maxIndex());
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
void SoplexLp::_getColName(int c, std::string &name) const {
|
|
134
|
+
name = _col_names[c];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
void SoplexLp::_setColName(int c, const std::string &name) {
|
|
138
|
+
_col_names_ref.erase(_col_names[c]);
|
|
139
|
+
_col_names[c] = name;
|
|
140
|
+
if (!name.empty()) {
|
|
141
|
+
_col_names_ref.insert(std::make_pair(name, c));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
int SoplexLp::_colByName(const std::string& name) const {
|
|
146
|
+
std::map<std::string, int>::const_iterator it =
|
|
147
|
+
_col_names_ref.find(name);
|
|
148
|
+
if (it != _col_names_ref.end()) {
|
|
149
|
+
return it->second;
|
|
150
|
+
} else {
|
|
151
|
+
return -1;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
void SoplexLp::_getRowName(int r, std::string &name) const {
|
|
156
|
+
name = _row_names[r];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
void SoplexLp::_setRowName(int r, const std::string &name) {
|
|
160
|
+
_row_names_ref.erase(_row_names[r]);
|
|
161
|
+
_row_names[r] = name;
|
|
162
|
+
if (!name.empty()) {
|
|
163
|
+
_row_names_ref.insert(std::make_pair(name, r));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
int SoplexLp::_rowByName(const std::string& name) const {
|
|
168
|
+
std::map<std::string, int>::const_iterator it =
|
|
169
|
+
_row_names_ref.find(name);
|
|
170
|
+
if (it != _row_names_ref.end()) {
|
|
171
|
+
return it->second;
|
|
172
|
+
} else {
|
|
173
|
+
return -1;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
void SoplexLp::_setRowCoeffs(int i, ExprIterator b, ExprIterator e) {
|
|
179
|
+
for (int j = 0; j < soplex->nCols(); ++j) {
|
|
180
|
+
soplex->changeElement(i, j, 0.0);
|
|
181
|
+
}
|
|
182
|
+
for(ExprIterator it = b; it != e; ++it) {
|
|
183
|
+
soplex->changeElement(i, it->first, it->second);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
void SoplexLp::_getRowCoeffs(int i, InsertIterator b) const {
|
|
188
|
+
const soplex::SVector& vec = soplex->rowVector(i);
|
|
189
|
+
for (int k = 0; k < vec.size(); ++k) {
|
|
190
|
+
*b = std::make_pair(vec.index(k), vec.value(k));
|
|
191
|
+
++b;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
void SoplexLp::_setColCoeffs(int j, ExprIterator b, ExprIterator e) {
|
|
196
|
+
for (int i = 0; i < soplex->nRows(); ++i) {
|
|
197
|
+
soplex->changeElement(i, j, 0.0);
|
|
198
|
+
}
|
|
199
|
+
for(ExprIterator it = b; it != e; ++it) {
|
|
200
|
+
soplex->changeElement(it->first, j, it->second);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
void SoplexLp::_getColCoeffs(int i, InsertIterator b) const {
|
|
205
|
+
const soplex::SVector& vec = soplex->colVector(i);
|
|
206
|
+
for (int k = 0; k < vec.size(); ++k) {
|
|
207
|
+
*b = std::make_pair(vec.index(k), vec.value(k));
|
|
208
|
+
++b;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
void SoplexLp::_setCoeff(int i, int j, Value value) {
|
|
213
|
+
soplex->changeElement(i, j, value);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
SoplexLp::Value SoplexLp::_getCoeff(int i, int j) const {
|
|
217
|
+
return soplex->rowVector(i)[j];
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
void SoplexLp::_setColLowerBound(int i, Value value) {
|
|
221
|
+
LEMON_ASSERT(value != INF, "Invalid bound");
|
|
222
|
+
soplex->changeLower(i, value != -INF ? value : -soplex::infinity);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
SoplexLp::Value SoplexLp::_getColLowerBound(int i) const {
|
|
226
|
+
double value = soplex->lower(i);
|
|
227
|
+
return value != -soplex::infinity ? value : -INF;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
void SoplexLp::_setColUpperBound(int i, Value value) {
|
|
231
|
+
LEMON_ASSERT(value != -INF, "Invalid bound");
|
|
232
|
+
soplex->changeUpper(i, value != INF ? value : soplex::infinity);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
SoplexLp::Value SoplexLp::_getColUpperBound(int i) const {
|
|
236
|
+
double value = soplex->upper(i);
|
|
237
|
+
return value != soplex::infinity ? value : INF;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
void SoplexLp::_setRowLowerBound(int i, Value lb) {
|
|
241
|
+
LEMON_ASSERT(lb != INF, "Invalid bound");
|
|
242
|
+
soplex->changeRange(i, lb != -INF ? lb : -soplex::infinity, soplex->rhs(i));
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
SoplexLp::Value SoplexLp::_getRowLowerBound(int i) const {
|
|
246
|
+
double res = soplex->lhs(i);
|
|
247
|
+
return res == -soplex::infinity ? -INF : res;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
void SoplexLp::_setRowUpperBound(int i, Value ub) {
|
|
251
|
+
LEMON_ASSERT(ub != -INF, "Invalid bound");
|
|
252
|
+
soplex->changeRange(i, soplex->lhs(i), ub != INF ? ub : soplex::infinity);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
SoplexLp::Value SoplexLp::_getRowUpperBound(int i) const {
|
|
256
|
+
double res = soplex->rhs(i);
|
|
257
|
+
return res == soplex::infinity ? INF : res;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
void SoplexLp::_setObjCoeffs(ExprIterator b, ExprIterator e) {
|
|
261
|
+
for (int j = 0; j < soplex->nCols(); ++j) {
|
|
262
|
+
soplex->changeObj(j, 0.0);
|
|
263
|
+
}
|
|
264
|
+
for (ExprIterator it = b; it != e; ++it) {
|
|
265
|
+
soplex->changeObj(it->first, it->second);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
void SoplexLp::_getObjCoeffs(InsertIterator b) const {
|
|
270
|
+
for (int j = 0; j < soplex->nCols(); ++j) {
|
|
271
|
+
Value coef = soplex->obj(j);
|
|
272
|
+
if (coef != 0.0) {
|
|
273
|
+
*b = std::make_pair(j, coef);
|
|
274
|
+
++b;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
void SoplexLp::_setObjCoeff(int i, Value obj_coef) {
|
|
280
|
+
soplex->changeObj(i, obj_coef);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
SoplexLp::Value SoplexLp::_getObjCoeff(int i) const {
|
|
284
|
+
return soplex->obj(i);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
SoplexLp::SolveExitStatus SoplexLp::_solve() {
|
|
288
|
+
|
|
289
|
+
_clear_temporals();
|
|
290
|
+
|
|
291
|
+
_applyMessageLevel();
|
|
292
|
+
|
|
293
|
+
soplex::SPxSolver::Status status = soplex->solve();
|
|
294
|
+
|
|
295
|
+
switch (status) {
|
|
296
|
+
case soplex::SPxSolver::OPTIMAL:
|
|
297
|
+
case soplex::SPxSolver::INFEASIBLE:
|
|
298
|
+
case soplex::SPxSolver::UNBOUNDED:
|
|
299
|
+
return SOLVED;
|
|
300
|
+
default:
|
|
301
|
+
return UNSOLVED;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
SoplexLp::Value SoplexLp::_getPrimal(int i) const {
|
|
306
|
+
if (_primal_values.empty()) {
|
|
307
|
+
_primal_values.resize(soplex->nCols());
|
|
308
|
+
soplex::Vector pv(_primal_values.size(), &_primal_values.front());
|
|
309
|
+
soplex->getPrimal(pv);
|
|
310
|
+
}
|
|
311
|
+
return _primal_values[i];
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
SoplexLp::Value SoplexLp::_getDual(int i) const {
|
|
315
|
+
if (_dual_values.empty()) {
|
|
316
|
+
_dual_values.resize(soplex->nRows());
|
|
317
|
+
soplex::Vector dv(_dual_values.size(), &_dual_values.front());
|
|
318
|
+
soplex->getDual(dv);
|
|
319
|
+
}
|
|
320
|
+
return _dual_values[i];
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
SoplexLp::Value SoplexLp::_getPrimalValue() const {
|
|
324
|
+
return soplex->objValue();
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
SoplexLp::VarStatus SoplexLp::_getColStatus(int i) const {
|
|
328
|
+
switch (soplex->getBasisColStatus(i)) {
|
|
329
|
+
case soplex::SPxSolver::BASIC:
|
|
330
|
+
return BASIC;
|
|
331
|
+
case soplex::SPxSolver::ON_UPPER:
|
|
332
|
+
return UPPER;
|
|
333
|
+
case soplex::SPxSolver::ON_LOWER:
|
|
334
|
+
return LOWER;
|
|
335
|
+
case soplex::SPxSolver::FIXED:
|
|
336
|
+
return FIXED;
|
|
337
|
+
case soplex::SPxSolver::ZERO:
|
|
338
|
+
return FREE;
|
|
339
|
+
default:
|
|
340
|
+
LEMON_ASSERT(false, "Wrong column status");
|
|
341
|
+
return VarStatus();
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
SoplexLp::VarStatus SoplexLp::_getRowStatus(int i) const {
|
|
346
|
+
switch (soplex->getBasisRowStatus(i)) {
|
|
347
|
+
case soplex::SPxSolver::BASIC:
|
|
348
|
+
return BASIC;
|
|
349
|
+
case soplex::SPxSolver::ON_UPPER:
|
|
350
|
+
return UPPER;
|
|
351
|
+
case soplex::SPxSolver::ON_LOWER:
|
|
352
|
+
return LOWER;
|
|
353
|
+
case soplex::SPxSolver::FIXED:
|
|
354
|
+
return FIXED;
|
|
355
|
+
case soplex::SPxSolver::ZERO:
|
|
356
|
+
return FREE;
|
|
357
|
+
default:
|
|
358
|
+
LEMON_ASSERT(false, "Wrong row status");
|
|
359
|
+
return VarStatus();
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
SoplexLp::Value SoplexLp::_getPrimalRay(int i) const {
|
|
364
|
+
if (_primal_ray.empty()) {
|
|
365
|
+
_primal_ray.resize(soplex->nCols());
|
|
366
|
+
soplex::Vector pv(_primal_ray.size(), &_primal_ray.front());
|
|
367
|
+
soplex->getDualfarkas(pv);
|
|
368
|
+
}
|
|
369
|
+
return _primal_ray[i];
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
SoplexLp::Value SoplexLp::_getDualRay(int i) const {
|
|
373
|
+
if (_dual_ray.empty()) {
|
|
374
|
+
_dual_ray.resize(soplex->nRows());
|
|
375
|
+
soplex::Vector dv(_dual_ray.size(), &_dual_ray.front());
|
|
376
|
+
soplex->getDualfarkas(dv);
|
|
377
|
+
}
|
|
378
|
+
return _dual_ray[i];
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
SoplexLp::ProblemType SoplexLp::_getPrimalType() const {
|
|
382
|
+
switch (soplex->status()) {
|
|
383
|
+
case soplex::SPxSolver::OPTIMAL:
|
|
384
|
+
return OPTIMAL;
|
|
385
|
+
case soplex::SPxSolver::UNBOUNDED:
|
|
386
|
+
return UNBOUNDED;
|
|
387
|
+
case soplex::SPxSolver::INFEASIBLE:
|
|
388
|
+
return INFEASIBLE;
|
|
389
|
+
default:
|
|
390
|
+
return UNDEFINED;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
SoplexLp::ProblemType SoplexLp::_getDualType() const {
|
|
395
|
+
switch (soplex->status()) {
|
|
396
|
+
case soplex::SPxSolver::OPTIMAL:
|
|
397
|
+
return OPTIMAL;
|
|
398
|
+
case soplex::SPxSolver::UNBOUNDED:
|
|
399
|
+
return UNBOUNDED;
|
|
400
|
+
case soplex::SPxSolver::INFEASIBLE:
|
|
401
|
+
return INFEASIBLE;
|
|
402
|
+
default:
|
|
403
|
+
return UNDEFINED;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
void SoplexLp::_setSense(Sense sense) {
|
|
408
|
+
switch (sense) {
|
|
409
|
+
case MIN:
|
|
410
|
+
soplex->changeSense(soplex::SPxSolver::MINIMIZE);
|
|
411
|
+
break;
|
|
412
|
+
case MAX:
|
|
413
|
+
soplex->changeSense(soplex::SPxSolver::MAXIMIZE);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
SoplexLp::Sense SoplexLp::_getSense() const {
|
|
418
|
+
switch (soplex->spxSense()) {
|
|
419
|
+
case soplex::SPxSolver::MAXIMIZE:
|
|
420
|
+
return MAX;
|
|
421
|
+
case soplex::SPxSolver::MINIMIZE:
|
|
422
|
+
return MIN;
|
|
423
|
+
default:
|
|
424
|
+
LEMON_ASSERT(false, "Wrong sense.");
|
|
425
|
+
return SoplexLp::Sense();
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
void SoplexLp::_clear() {
|
|
430
|
+
soplex->clear();
|
|
431
|
+
_col_names.clear();
|
|
432
|
+
_col_names_ref.clear();
|
|
433
|
+
_row_names.clear();
|
|
434
|
+
_row_names_ref.clear();
|
|
435
|
+
cols.clear();
|
|
436
|
+
rows.clear();
|
|
437
|
+
_clear_temporals();
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
void SoplexLp::_messageLevel(MessageLevel level) {
|
|
441
|
+
switch (level) {
|
|
442
|
+
case MESSAGE_NOTHING:
|
|
443
|
+
_message_level = -1;
|
|
444
|
+
break;
|
|
445
|
+
case MESSAGE_ERROR:
|
|
446
|
+
_message_level = soplex::SPxOut::ERROR;
|
|
447
|
+
break;
|
|
448
|
+
case MESSAGE_WARNING:
|
|
449
|
+
_message_level = soplex::SPxOut::WARNING;
|
|
450
|
+
break;
|
|
451
|
+
case MESSAGE_NORMAL:
|
|
452
|
+
_message_level = soplex::SPxOut::INFO2;
|
|
453
|
+
break;
|
|
454
|
+
case MESSAGE_VERBOSE:
|
|
455
|
+
_message_level = soplex::SPxOut::DEBUG;
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
void SoplexLp::_applyMessageLevel() {
|
|
461
|
+
soplex::Param::setVerbose(_message_level);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
} //namespace lemon
|
|
465
|
+
|
|
@@ -0,0 +1,158 @@
|
|
|
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_SOPLEX_H
|
|
20
|
+
#define LEMON_SOPLEX_H
|
|
21
|
+
|
|
22
|
+
///\file
|
|
23
|
+
///\brief Header of the LEMON-SOPLEX lp solver interface.
|
|
24
|
+
|
|
25
|
+
#include <vector>
|
|
26
|
+
#include <string>
|
|
27
|
+
|
|
28
|
+
#include <lemon/lp_base.h>
|
|
29
|
+
|
|
30
|
+
// Forward declaration
|
|
31
|
+
namespace soplex {
|
|
32
|
+
class SoPlex;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
namespace lemon {
|
|
36
|
+
|
|
37
|
+
/// \ingroup lp_group
|
|
38
|
+
///
|
|
39
|
+
/// \brief Interface for the SOPLEX solver
|
|
40
|
+
///
|
|
41
|
+
/// This class implements an interface for the SoPlex LP solver.
|
|
42
|
+
/// The SoPlex library is an object oriented lp solver library
|
|
43
|
+
/// developed at the Konrad-Zuse-Zentrum für Informationstechnik
|
|
44
|
+
/// Berlin (ZIB). You can find detailed information about it at the
|
|
45
|
+
/// <tt>http://soplex.zib.de</tt> address.
|
|
46
|
+
class SoplexLp : public LpSolver {
|
|
47
|
+
private:
|
|
48
|
+
|
|
49
|
+
soplex::SoPlex* soplex;
|
|
50
|
+
|
|
51
|
+
std::vector<std::string> _col_names;
|
|
52
|
+
std::map<std::string, int> _col_names_ref;
|
|
53
|
+
|
|
54
|
+
std::vector<std::string> _row_names;
|
|
55
|
+
std::map<std::string, int> _row_names_ref;
|
|
56
|
+
|
|
57
|
+
private:
|
|
58
|
+
|
|
59
|
+
// these values cannot be retrieved element by element
|
|
60
|
+
mutable std::vector<Value> _primal_values;
|
|
61
|
+
mutable std::vector<Value> _dual_values;
|
|
62
|
+
|
|
63
|
+
mutable std::vector<Value> _primal_ray;
|
|
64
|
+
mutable std::vector<Value> _dual_ray;
|
|
65
|
+
|
|
66
|
+
void _clear_temporals();
|
|
67
|
+
|
|
68
|
+
public:
|
|
69
|
+
|
|
70
|
+
/// \e
|
|
71
|
+
SoplexLp();
|
|
72
|
+
/// \e
|
|
73
|
+
SoplexLp(const SoplexLp&);
|
|
74
|
+
/// \e
|
|
75
|
+
~SoplexLp();
|
|
76
|
+
/// \e
|
|
77
|
+
virtual SoplexLp* newSolver() const;
|
|
78
|
+
/// \e
|
|
79
|
+
virtual SoplexLp* cloneSolver() const;
|
|
80
|
+
|
|
81
|
+
protected:
|
|
82
|
+
|
|
83
|
+
virtual const char* _solverName() const;
|
|
84
|
+
|
|
85
|
+
virtual int _addCol();
|
|
86
|
+
virtual int _addRow();
|
|
87
|
+
virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
|
|
88
|
+
|
|
89
|
+
virtual void _eraseCol(int i);
|
|
90
|
+
virtual void _eraseRow(int i);
|
|
91
|
+
|
|
92
|
+
virtual void _eraseColId(int i);
|
|
93
|
+
virtual void _eraseRowId(int i);
|
|
94
|
+
|
|
95
|
+
virtual void _getColName(int col, std::string& name) const;
|
|
96
|
+
virtual void _setColName(int col, const std::string& name);
|
|
97
|
+
virtual int _colByName(const std::string& name) const;
|
|
98
|
+
|
|
99
|
+
virtual void _getRowName(int row, std::string& name) const;
|
|
100
|
+
virtual void _setRowName(int row, const std::string& name);
|
|
101
|
+
virtual int _rowByName(const std::string& name) const;
|
|
102
|
+
|
|
103
|
+
virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e);
|
|
104
|
+
virtual void _getRowCoeffs(int i, InsertIterator b) const;
|
|
105
|
+
|
|
106
|
+
virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e);
|
|
107
|
+
virtual void _getColCoeffs(int i, InsertIterator b) const;
|
|
108
|
+
|
|
109
|
+
virtual void _setCoeff(int row, int col, Value value);
|
|
110
|
+
virtual Value _getCoeff(int row, int col) const;
|
|
111
|
+
|
|
112
|
+
virtual void _setColLowerBound(int i, Value value);
|
|
113
|
+
virtual Value _getColLowerBound(int i) const;
|
|
114
|
+
virtual void _setColUpperBound(int i, Value value);
|
|
115
|
+
virtual Value _getColUpperBound(int i) const;
|
|
116
|
+
|
|
117
|
+
virtual void _setRowLowerBound(int i, Value value);
|
|
118
|
+
virtual Value _getRowLowerBound(int i) const;
|
|
119
|
+
virtual void _setRowUpperBound(int i, Value value);
|
|
120
|
+
virtual Value _getRowUpperBound(int i) const;
|
|
121
|
+
|
|
122
|
+
virtual void _setObjCoeffs(ExprIterator b, ExprIterator e);
|
|
123
|
+
virtual void _getObjCoeffs(InsertIterator b) const;
|
|
124
|
+
|
|
125
|
+
virtual void _setObjCoeff(int i, Value obj_coef);
|
|
126
|
+
virtual Value _getObjCoeff(int i) const;
|
|
127
|
+
|
|
128
|
+
virtual void _setSense(Sense sense);
|
|
129
|
+
virtual Sense _getSense() const;
|
|
130
|
+
|
|
131
|
+
virtual SolveExitStatus _solve();
|
|
132
|
+
virtual Value _getPrimal(int i) const;
|
|
133
|
+
virtual Value _getDual(int i) const;
|
|
134
|
+
|
|
135
|
+
virtual Value _getPrimalValue() const;
|
|
136
|
+
|
|
137
|
+
virtual Value _getPrimalRay(int i) const;
|
|
138
|
+
virtual Value _getDualRay(int i) const;
|
|
139
|
+
|
|
140
|
+
virtual VarStatus _getColStatus(int i) const;
|
|
141
|
+
virtual VarStatus _getRowStatus(int i) const;
|
|
142
|
+
|
|
143
|
+
virtual ProblemType _getPrimalType() const;
|
|
144
|
+
virtual ProblemType _getDualType() const;
|
|
145
|
+
|
|
146
|
+
virtual void _clear();
|
|
147
|
+
|
|
148
|
+
void _messageLevel(MessageLevel m);
|
|
149
|
+
void _applyMessageLevel();
|
|
150
|
+
|
|
151
|
+
int _message_level;
|
|
152
|
+
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
} //END OF NAMESPACE LEMON
|
|
156
|
+
|
|
157
|
+
#endif //LEMON_SOPLEX_H
|
|
158
|
+
|