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