0
13
0
23
20
4
25
20
4
2
20
30
4
26
68
6
48
... | ... |
@@ -46,30 +46,33 @@ |
46 | 46 |
#include "coin/CglFlowCover.hpp" |
47 | 47 |
#include "coin/CglMixedIntegerRounding.hpp" |
48 | 48 |
|
49 | 49 |
#include "coin/CbcHeuristic.hpp" |
50 | 50 |
|
51 | 51 |
namespace lemon { |
52 | 52 |
|
53 | 53 |
CbcMip::CbcMip() { |
54 | 54 |
_prob = new CoinModel(); |
55 | 55 |
_prob->setProblemName("LEMON"); |
56 | 56 |
_osi_solver = 0; |
57 | 57 |
_cbc_model = 0; |
58 |
messageLevel(MESSAGE_NOTHING); |
|
58 | 59 |
} |
59 | 60 |
|
60 | 61 |
CbcMip::CbcMip(const CbcMip& other) { |
61 | 62 |
_prob = new CoinModel(*other._prob); |
63 |
_prob->setProblemName("LEMON"); |
|
62 | 64 |
_osi_solver = 0; |
63 | 65 |
_cbc_model = 0; |
66 |
messageLevel(MESSAGE_NOTHING); |
|
64 | 67 |
} |
65 | 68 |
|
66 | 69 |
CbcMip::~CbcMip() { |
67 | 70 |
delete _prob; |
68 | 71 |
if (_osi_solver) delete _osi_solver; |
69 | 72 |
if (_cbc_model) delete _cbc_model; |
70 | 73 |
} |
71 | 74 |
|
72 | 75 |
const char* CbcMip::_solverName() const { return "CbcMip"; } |
73 | 76 |
|
74 | 77 |
int CbcMip::_addCol() { |
75 | 78 |
_prob->addColumn(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX, 0.0, 0, false); |
... | ... |
@@ -261,42 +264,26 @@ |
261 | 264 |
_osi_solver = new OsiOslSolverInterface(); |
262 | 265 |
#else |
263 | 266 |
#error Cannot instantiate Osi solver |
264 | 267 |
#endif |
265 | 268 |
|
266 | 269 |
_osi_solver->loadFromCoinModel(*_prob); |
267 | 270 |
|
268 | 271 |
if (_cbc_model) { |
269 | 272 |
delete _cbc_model; |
270 | 273 |
} |
271 | 274 |
_cbc_model= new CbcModel(*_osi_solver); |
272 | 275 |
|
273 |
switch (_message_level) { |
|
274 |
case MESSAGE_NO_OUTPUT: |
|
275 |
_osi_solver->messageHandler()->setLogLevel(0); |
|
276 |
_cbc_model->setLogLevel(0); |
|
277 |
break; |
|
278 |
case MESSAGE_ERROR_MESSAGE: |
|
279 |
_osi_solver->messageHandler()->setLogLevel(1); |
|
280 |
_cbc_model->setLogLevel(1); |
|
281 |
break; |
|
282 |
case MESSAGE_NORMAL_OUTPUT: |
|
283 |
_osi_solver->messageHandler()->setLogLevel(2); |
|
284 |
_cbc_model->setLogLevel(2); |
|
285 |
break; |
|
286 |
case MESSAGE_FULL_OUTPUT: |
|
287 |
_osi_solver->messageHandler()->setLogLevel(3); |
|
288 |
_cbc_model->setLogLevel(3); |
|
289 |
break; |
|
290 |
} |
|
276 |
_osi_solver->messageHandler()->setLogLevel(_message_level); |
|
277 |
_cbc_model->setLogLevel(_message_level); |
|
291 | 278 |
|
292 | 279 |
_cbc_model->initialSolve(); |
293 | 280 |
_cbc_model->solver()->setHintParam(OsiDoReducePrint, true, OsiHintTry); |
294 | 281 |
|
295 | 282 |
if (!_cbc_model->isInitialSolveAbandoned() && |
296 | 283 |
_cbc_model->isInitialSolveProvenOptimal() && |
297 | 284 |
!_cbc_model->isInitialSolveProvenPrimalInfeasible() && |
298 | 285 |
!_cbc_model->isInitialSolveProvenDualInfeasible()) { |
299 | 286 |
|
300 | 287 |
CglProbing generator1; |
301 | 288 |
generator1.setUsingObjective(true); |
302 | 289 |
generator1.setMaxPass(3); |
... | ... |
@@ -444,17 +431,33 @@ |
444 | 431 |
_osi_solver = 0; |
445 | 432 |
} |
446 | 433 |
if (_cbc_model) { |
447 | 434 |
delete _cbc_model; |
448 | 435 |
_cbc_model = 0; |
449 | 436 |
} |
450 | 437 |
|
451 | 438 |
_prob = new CoinModel(); |
452 | 439 |
rows.clear(); |
453 | 440 |
cols.clear(); |
454 | 441 |
} |
455 | 442 |
|
456 |
void CbcMip::messageLevel(MessageLevel m) { |
|
457 |
_message_level = m; |
|
443 |
void CbcMip::_messageLevel(MessageLevel level) { |
|
444 |
switch (level) { |
|
445 |
case MESSAGE_NOTHING: |
|
446 |
_message_level = 0; |
|
447 |
break; |
|
448 |
case MESSAGE_ERROR: |
|
449 |
_message_level = 1; |
|
450 |
break; |
|
451 |
case MESSAGE_WARNING: |
|
452 |
_message_level = 1; |
|
453 |
break; |
|
454 |
case MESSAGE_NORMAL: |
|
455 |
_message_level = 2; |
|
456 |
break; |
|
457 |
case MESSAGE_VERBOSE: |
|
458 |
_message_level = 3; |
|
459 |
break; |
|
460 |
} |
|
458 | 461 |
} |
459 | 462 |
|
460 | 463 |
} //END OF NAMESPACE LEMON |
... | ... |
@@ -106,45 +106,24 @@ |
106 | 106 |
virtual Sense _getSense() const; |
107 | 107 |
|
108 | 108 |
virtual ColTypes _getColType(int col) const; |
109 | 109 |
virtual void _setColType(int col, ColTypes col_type); |
110 | 110 |
|
111 | 111 |
virtual SolveExitStatus _solve(); |
112 | 112 |
virtual ProblemType _getType() const; |
113 | 113 |
virtual Value _getSol(int i) const; |
114 | 114 |
virtual Value _getSolValue() const; |
115 | 115 |
|
116 | 116 |
virtual void _clear(); |
117 | 117 |
|
118 |
|
|
118 |
virtual void _messageLevel(MessageLevel level); |
|
119 |
void _applyMessageLevel(); |
|
119 | 120 |
|
120 |
///Enum for \c messageLevel() parameter |
|
121 |
enum MessageLevel { |
|
122 |
/// no output (default value) |
|
123 |
MESSAGE_NO_OUTPUT = 0, |
|
124 |
/// error messages only |
|
125 |
MESSAGE_ERROR_MESSAGE = 1, |
|
126 |
/// normal output |
|
127 |
MESSAGE_NORMAL_OUTPUT = 2, |
|
128 |
/// full output (includes informational messages) |
|
129 |
MESSAGE_FULL_OUTPUT = 3 |
|
130 |
|
|
121 |
int _message_level; |
|
131 | 122 |
|
132 |
private: |
|
133 |
|
|
134 |
MessageLevel _message_level; |
|
135 |
|
|
136 |
public: |
|
137 |
|
|
138 |
///Set the verbosity of the messages |
|
139 |
|
|
140 |
///Set the verbosity of the messages |
|
141 |
/// |
|
142 |
///\param m is the level of the messages output by the solver routines. |
|
143 |
void messageLevel(MessageLevel m); |
|
144 |
|
|
123 |
|
|
145 | 124 |
|
146 | 125 |
}; |
147 | 126 |
|
148 | 127 |
} |
149 | 128 |
|
150 | 129 |
#endif |
... | ... |
@@ -15,33 +15,33 @@ |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#include <lemon/clp.h> |
20 | 20 |
#include <coin/ClpSimplex.hpp> |
21 | 21 |
|
22 | 22 |
namespace lemon { |
23 | 23 |
|
24 | 24 |
ClpLp::ClpLp() { |
25 | 25 |
_prob = new ClpSimplex(); |
26 | 26 |
_init_temporals(); |
27 |
messageLevel( |
|
27 |
messageLevel(MESSAGE_NOTHING); |
|
28 | 28 |
} |
29 | 29 |
|
30 | 30 |
ClpLp::ClpLp(const ClpLp& other) { |
31 | 31 |
_prob = new ClpSimplex(*other._prob); |
32 | 32 |
rows = other.rows; |
33 | 33 |
cols = other.cols; |
34 | 34 |
_init_temporals(); |
35 |
messageLevel( |
|
35 |
messageLevel(MESSAGE_NOTHING); |
|
36 | 36 |
} |
37 | 37 |
|
38 | 38 |
ClpLp::~ClpLp() { |
39 | 39 |
delete _prob; |
40 | 40 |
_clear_temporals(); |
41 | 41 |
} |
42 | 42 |
|
43 | 43 |
void ClpLp::_init_temporals() { |
44 | 44 |
_primal_ray = 0; |
45 | 45 |
_dual_ray = 0; |
46 | 46 |
} |
47 | 47 |
|
... | ... |
@@ -421,17 +421,33 @@ |
421 | 421 |
} |
422 | 422 |
} |
423 | 423 |
|
424 | 424 |
void ClpLp::_clear() { |
425 | 425 |
delete _prob; |
426 | 426 |
_prob = new ClpSimplex(); |
427 | 427 |
rows.clear(); |
428 | 428 |
cols.clear(); |
429 | 429 |
_col_names_ref.clear(); |
430 | 430 |
_clear_temporals(); |
431 | 431 |
} |
432 | 432 |
|
433 |
void ClpLp::messageLevel(MessageLevel m) { |
|
434 |
_prob->setLogLevel(static_cast<int>(m)); |
|
433 |
void ClpLp::_messageLevel(MessageLevel level) { |
|
434 |
switch (level) { |
|
435 |
case MESSAGE_NOTHING: |
|
436 |
_prob->setLogLevel(0); |
|
437 |
break; |
|
438 |
case MESSAGE_ERROR: |
|
439 |
_prob->setLogLevel(1); |
|
440 |
break; |
|
441 |
case MESSAGE_WARNING: |
|
442 |
_prob->setLogLevel(2); |
|
443 |
break; |
|
444 |
case MESSAGE_NORMAL: |
|
445 |
_prob->setLogLevel(3); |
|
446 |
break; |
|
447 |
case MESSAGE_VERBOSE: |
|
448 |
_prob->setLogLevel(4); |
|
449 |
break; |
|
450 |
} |
|
435 | 451 |
} |
436 | 452 |
|
437 | 453 |
} //END OF NAMESPACE LEMON |
... | ... |
@@ -127,55 +127,37 @@ |
127 | 127 |
|
128 | 128 |
virtual Value _getPrimalRay(int i) const; |
129 | 129 |
virtual Value _getDualRay(int i) const; |
130 | 130 |
|
131 | 131 |
virtual VarStatus _getColStatus(int i) const; |
132 | 132 |
virtual VarStatus _getRowStatus(int i) const; |
133 | 133 |
|
134 | 134 |
virtual ProblemType _getPrimalType() const; |
135 | 135 |
virtual ProblemType _getDualType() const; |
136 | 136 |
|
137 | 137 |
virtual void _clear(); |
138 | 138 |
|
139 |
virtual void _messageLevel(MessageLevel); |
|
140 |
|
|
139 | 141 |
public: |
140 | 142 |
|
141 | 143 |
///Solves LP with primal simplex method. |
142 | 144 |
SolveExitStatus solvePrimal(); |
143 | 145 |
|
144 | 146 |
///Solves LP with dual simplex method. |
145 | 147 |
SolveExitStatus solveDual(); |
146 | 148 |
|
147 | 149 |
///Solves LP with barrier method. |
148 | 150 |
SolveExitStatus solveBarrier(); |
149 | 151 |
|
150 | 152 |
///Returns the constraint identifier understood by CLP. |
151 | 153 |
int clpRow(Row r) const { return rows(id(r)); } |
152 | 154 |
|
153 | 155 |
///Returns the variable identifier understood by CLP. |
154 | 156 |
int clpCol(Col c) const { return cols(id(c)); } |
155 | 157 |
|
156 |
///Enum for \c messageLevel() parameter |
|
157 |
enum MessageLevel { |
|
158 |
/// no output (default value) |
|
159 |
MESSAGE_NO_OUTPUT = 0, |
|
160 |
/// print final solution |
|
161 |
MESSAGE_FINAL_SOLUTION = 1, |
|
162 |
/// print factorization |
|
163 |
MESSAGE_FACTORIZATION = 2, |
|
164 |
/// normal output |
|
165 |
MESSAGE_NORMAL_OUTPUT = 3, |
|
166 |
/// verbose output |
|
167 |
MESSAGE_VERBOSE_OUTPUT = 4 |
|
168 |
}; |
|
169 |
///Set the verbosity of the messages |
|
170 |
|
|
171 |
///Set the verbosity of the messages |
|
172 |
/// |
|
173 |
///\param m is the level of the messages output by the solver routines. |
|
174 |
void messageLevel(MessageLevel m); |
|
175 |
|
|
176 | 158 |
}; |
177 | 159 |
|
178 | 160 |
} //END OF NAMESPACE LEMON |
179 | 161 |
|
180 | 162 |
#endif //LEMON_CLP_H |
181 | 163 |
... | ... |
@@ -63,38 +63,41 @@ |
63 | 63 |
|
64 | 64 |
CplexEnv::~CplexEnv() { |
65 | 65 |
--(*_cnt); |
66 | 66 |
if (*_cnt == 0) { |
67 | 67 |
delete _cnt; |
68 | 68 |
CPXcloseCPLEX(&_env); |
69 | 69 |
} |
70 | 70 |
} |
71 | 71 |
|
72 | 72 |
CplexBase::CplexBase() : LpBase() { |
73 | 73 |
int status; |
74 | 74 |
_prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem"); |
75 |
messageLevel(MESSAGE_NOTHING); |
|
75 | 76 |
} |
76 | 77 |
|
77 | 78 |
CplexBase::CplexBase(const CplexEnv& env) |
78 | 79 |
: LpBase(), _env(env) { |
79 | 80 |
int status; |
80 | 81 |
_prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem"); |
82 |
messageLevel(MESSAGE_NOTHING); |
|
81 | 83 |
} |
82 | 84 |
|
83 | 85 |
CplexBase::CplexBase(const CplexBase& cplex) |
84 | 86 |
: LpBase() { |
85 | 87 |
int status; |
86 | 88 |
_prob = CPXcloneprob(cplexEnv(), cplex._prob, &status); |
87 | 89 |
rows = cplex.rows; |
88 | 90 |
cols = cplex.cols; |
91 |
messageLevel(MESSAGE_NOTHING); |
|
89 | 92 |
} |
90 | 93 |
|
91 | 94 |
CplexBase::~CplexBase() { |
92 | 95 |
CPXfreeprob(cplexEnv(),&_prob); |
93 | 96 |
} |
94 | 97 |
|
95 | 98 |
int CplexBase::_addCol() { |
96 | 99 |
int i = CPXgetnumcols(cplexEnv(), _prob); |
97 | 100 |
double lb = -INF, ub = INF; |
98 | 101 |
CPXnewcols(cplexEnv(), _prob, 1, 0, &lb, &ub, 0, 0); |
99 | 102 |
return i; |
100 | 103 |
} |
... | ... |
@@ -429,24 +432,43 @@ |
429 | 432 |
return CplexBase::Sense(); |
430 | 433 |
} |
431 | 434 |
} |
432 | 435 |
|
433 | 436 |
void CplexBase::_clear() { |
434 | 437 |
CPXfreeprob(cplexEnv(),&_prob); |
435 | 438 |
int status; |
436 | 439 |
_prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem"); |
437 | 440 |
rows.clear(); |
438 | 441 |
cols.clear(); |
439 | 442 |
} |
440 | 443 |
|
444 |
void CplexBase::_messageLevel(MessageLevel level) { |
|
445 |
switch (level) { |
|
446 |
case MESSAGE_NOTHING: |
|
447 |
_message_enabled = false; |
|
448 |
break; |
|
449 |
case MESSAGE_ERROR: |
|
450 |
case MESSAGE_WARNING: |
|
451 |
case MESSAGE_NORMAL: |
|
452 |
case MESSAGE_VERBOSE: |
|
453 |
_message_enabled = true; |
|
454 |
break; |
|
455 |
} |
|
456 |
} |
|
457 |
|
|
458 |
void CplexBase::_applyMessageLevel() { |
|
459 |
CPXsetintparam(cplexEnv(), CPX_PARAM_SCRIND, |
|
460 |
_message_enabled ? CPX_ON : CPX_OFF); |
|
461 |
} |
|
462 |
|
|
441 | 463 |
// CplexLp members |
442 | 464 |
|
443 | 465 |
CplexLp::CplexLp() |
444 | 466 |
: LpBase(), LpSolver(), CplexBase() {} |
445 | 467 |
|
446 | 468 |
CplexLp::CplexLp(const CplexEnv& env) |
447 | 469 |
: LpBase(), LpSolver(), CplexBase(env) {} |
448 | 470 |
|
449 | 471 |
CplexLp::CplexLp(const CplexLp& other) |
450 | 472 |
: LpBase(), LpSolver(), CplexBase(other) {} |
451 | 473 |
|
452 | 474 |
CplexLp::~CplexLp() {} |
... | ... |
@@ -498,39 +520,43 @@ |
498 | 520 |
return UNSOLVED; |
499 | 521 |
default: |
500 | 522 |
return SOLVED; |
501 | 523 |
} |
502 | 524 |
} else { |
503 | 525 |
return UNSOLVED; |
504 | 526 |
} |
505 | 527 |
#endif |
506 | 528 |
} |
507 | 529 |
|
508 | 530 |
CplexLp::SolveExitStatus CplexLp::_solve() { |
509 | 531 |
_clear_temporals(); |
532 |
_applyMessageLevel(); |
|
510 | 533 |
return convertStatus(CPXlpopt(cplexEnv(), _prob)); |
511 | 534 |
} |
512 | 535 |
|
513 | 536 |
CplexLp::SolveExitStatus CplexLp::solvePrimal() { |
514 | 537 |
_clear_temporals(); |
538 |
_applyMessageLevel(); |
|
515 | 539 |
return convertStatus(CPXprimopt(cplexEnv(), _prob)); |
516 | 540 |
} |
517 | 541 |
|
518 | 542 |
CplexLp::SolveExitStatus CplexLp::solveDual() { |
519 | 543 |
_clear_temporals(); |
544 |
_applyMessageLevel(); |
|
520 | 545 |
return convertStatus(CPXdualopt(cplexEnv(), _prob)); |
521 | 546 |
} |
522 | 547 |
|
523 | 548 |
CplexLp::SolveExitStatus CplexLp::solveBarrier() { |
524 | 549 |
_clear_temporals(); |
550 |
_applyMessageLevel(); |
|
525 | 551 |
return convertStatus(CPXbaropt(cplexEnv(), _prob)); |
526 | 552 |
} |
527 | 553 |
|
528 | 554 |
CplexLp::Value CplexLp::_getPrimal(int i) const { |
529 | 555 |
Value x; |
530 | 556 |
CPXgetx(cplexEnv(), _prob, &x, i, i); |
531 | 557 |
return x; |
532 | 558 |
} |
533 | 559 |
|
534 | 560 |
CplexLp::Value CplexLp::_getDual(int i) const { |
535 | 561 |
Value y; |
536 | 562 |
CPXgetpi(cplexEnv(), _prob, &y, i, i); |
... | ... |
@@ -591,25 +617,25 @@ |
591 | 617 |
CPXgetray(cplexEnv(), _prob, &_primal_ray.front()); |
592 | 618 |
} |
593 | 619 |
return _primal_ray[i]; |
594 | 620 |
} |
595 | 621 |
|
596 | 622 |
CplexLp::Value CplexLp::_getDualRay(int i) const { |
597 | 623 |
if (_dual_ray.empty()) { |
598 | 624 |
|
599 | 625 |
} |
600 | 626 |
return _dual_ray[i]; |
601 | 627 |
} |
602 | 628 |
|
603 |
// |
|
629 |
// Cplex 7.0 status values |
|
604 | 630 |
// This table lists the statuses, returned by the CPXgetstat() |
605 | 631 |
// routine, for solutions to LP problems or mixed integer problems. If |
606 | 632 |
// no solution exists, the return value is zero. |
607 | 633 |
|
608 | 634 |
// For Simplex, Barrier |
609 | 635 |
// 1 CPX_OPTIMAL |
610 | 636 |
// Optimal solution found |
611 | 637 |
// 2 CPX_INFEASIBLE |
612 | 638 |
// Problem infeasible |
613 | 639 |
// 3 CPX_UNBOUNDED |
614 | 640 |
// Problem unbounded |
615 | 641 |
// 4 CPX_OBJ_LIM |
... | ... |
@@ -638,25 +664,25 @@ |
638 | 664 |
// Aborted in barrier, primal infeasible |
639 | 665 |
// 16 CPX_ABORT_PRIM_DUAL_INFEAS |
640 | 666 |
// Aborted in barrier, primal and dual infeasible |
641 | 667 |
// 17 CPX_ABORT_PRIM_DUAL_FEAS |
642 | 668 |
// Aborted in barrier, primal and dual feasible |
643 | 669 |
// 18 CPX_ABORT_CROSSOVER |
644 | 670 |
// Aborted in crossover |
645 | 671 |
// 19 CPX_INForUNBD |
646 | 672 |
// Infeasible or unbounded |
647 | 673 |
// 20 CPX_PIVOT |
648 | 674 |
// User pivot used |
649 | 675 |
// |
650 |
// |
|
676 |
// Pending return values |
|
651 | 677 |
// ??case CPX_ABORT_DUAL_INFEAS |
652 | 678 |
// ??case CPX_ABORT_CROSSOVER |
653 | 679 |
// ??case CPX_INForUNBD |
654 | 680 |
// ??case CPX_PIVOT |
655 | 681 |
|
656 | 682 |
//Some more interesting stuff: |
657 | 683 |
|
658 | 684 |
// CPX_PARAM_PROBMETHOD 1062 int LPMETHOD |
659 | 685 |
// 0 Automatic |
660 | 686 |
// 1 Primal Simplex |
661 | 687 |
// 2 Dual Simplex |
662 | 688 |
// 3 Network Simplex |
... | ... |
@@ -709,25 +735,24 @@ |
709 | 735 |
case CPX_STAT_OPTIMAL: |
710 | 736 |
return OPTIMAL; |
711 | 737 |
case CPX_STAT_UNBOUNDED: |
712 | 738 |
return UNBOUNDED; |
713 | 739 |
case CPX_STAT_INFEASIBLE: |
714 | 740 |
return INFEASIBLE; |
715 | 741 |
default: |
716 | 742 |
return UNDEFINED; |
717 | 743 |
} |
718 | 744 |
#else |
719 | 745 |
statusSwitch(cplexEnv(),stat); |
720 | 746 |
//CPXgetstat(cplexEnv(), _prob); |
721 |
//printf("A primal status: %d, CPX_OPTIMAL=%d \n",stat,CPX_OPTIMAL); |
|
722 | 747 |
switch (stat) { |
723 | 748 |
case 0: |
724 | 749 |
return UNDEFINED; //Undefined |
725 | 750 |
case CPX_OPTIMAL://Optimal |
726 | 751 |
return OPTIMAL; |
727 | 752 |
case CPX_UNBOUNDED://Unbounded |
728 | 753 |
return INFEASIBLE;//In case of dual simplex |
729 | 754 |
//return UNBOUNDED; |
730 | 755 |
case CPX_INFEASIBLE://Infeasible |
731 | 756 |
// case CPX_IT_LIM_INFEAS: |
732 | 757 |
// case CPX_TIME_LIM_INFEAS: |
733 | 758 |
// case CPX_NUM_BEST_INFEAS: |
... | ... |
@@ -742,25 +767,25 @@ |
742 | 767 |
// case CPX_TIME_LIM_FEAS: |
743 | 768 |
// case CPX_NUM_BEST_FEAS: |
744 | 769 |
// case CPX_ABORT_FEAS: |
745 | 770 |
// case CPX_ABORT_PRIM_DUAL_FEAS: |
746 | 771 |
// return FEASIBLE; |
747 | 772 |
default: |
748 | 773 |
return UNDEFINED; //Everything else comes here |
749 | 774 |
//FIXME error |
750 | 775 |
} |
751 | 776 |
#endif |
752 | 777 |
} |
753 | 778 |
|
754 |
//9.0 |
|
779 |
// Cplex 9.0 status values |
|
755 | 780 |
// CPX_STAT_ABORT_DUAL_OBJ_LIM |
756 | 781 |
// CPX_STAT_ABORT_IT_LIM |
757 | 782 |
// CPX_STAT_ABORT_OBJ_LIM |
758 | 783 |
// CPX_STAT_ABORT_PRIM_OBJ_LIM |
759 | 784 |
// CPX_STAT_ABORT_TIME_LIM |
760 | 785 |
// CPX_STAT_ABORT_USER |
761 | 786 |
// CPX_STAT_FEASIBLE_RELAXED |
762 | 787 |
// CPX_STAT_INFEASIBLE |
763 | 788 |
// CPX_STAT_INForUNBD |
764 | 789 |
// CPX_STAT_NUM_BEST |
765 | 790 |
// CPX_STAT_OPTIMAL |
766 | 791 |
// CPX_STAT_OPTIMAL_FACE_UNBOUNDED |
... | ... |
@@ -855,24 +880,25 @@ |
855 | 880 |
return INTEGER; |
856 | 881 |
case 'C': |
857 | 882 |
return REAL; |
858 | 883 |
default: |
859 | 884 |
LEMON_ASSERT(false, "Invalid column type"); |
860 | 885 |
return ColTypes(); |
861 | 886 |
} |
862 | 887 |
|
863 | 888 |
} |
864 | 889 |
|
865 | 890 |
CplexMip::SolveExitStatus CplexMip::_solve() { |
866 | 891 |
int status; |
892 |
_applyMessageLevel(); |
|
867 | 893 |
status = CPXmipopt (cplexEnv(), _prob); |
868 | 894 |
if (status==0) |
869 | 895 |
return SOLVED; |
870 | 896 |
else |
871 | 897 |
return UNSOLVED; |
872 | 898 |
|
873 | 899 |
} |
874 | 900 |
|
875 | 901 |
|
876 | 902 |
CplexMip::ProblemType CplexMip::_getType() const { |
877 | 903 |
|
878 | 904 |
int stat = CPXgetstat(cplexEnv(), _prob); |
... | ... |
@@ -135,32 +135,47 @@ |
135 | 135 |
|
136 | 136 |
virtual void _setObjCoeffs(ExprIterator b, ExprIterator e); |
137 | 137 |
virtual void _getObjCoeffs(InsertIterator b) const; |
138 | 138 |
|
139 | 139 |
virtual void _setObjCoeff(int i, Value obj_coef); |
140 | 140 |
virtual Value _getObjCoeff(int i) const; |
141 | 141 |
|
142 | 142 |
virtual void _setSense(Sense sense); |
143 | 143 |
virtual Sense _getSense() const; |
144 | 144 |
|
145 | 145 |
virtual void _clear(); |
146 | 146 |
|
147 |
virtual void _messageLevel(MessageLevel level); |
|
148 |
void _applyMessageLevel(); |
|
149 |
|
|
150 |
bool _message_enabled; |
|
151 |
|
|
147 | 152 |
public: |
148 | 153 |
|
149 | 154 |
/// Returns the used \c CplexEnv instance |
150 | 155 |
const CplexEnv& env() const { return _env; } |
156 |
|
|
157 |
/// \brief Returns the const cpxenv pointer |
|
151 | 158 |
/// |
159 |
/// \note The cpxenv might be destructed with the solver. |
|
152 | 160 |
const cpxenv* cplexEnv() const { return _env.cplexEnv(); } |
153 | 161 |
|
162 |
/// \brief Returns the const cpxenv pointer |
|
163 |
/// |
|
164 |
/// \note The cpxenv might be destructed with the solver. |
|
165 |
cpxenv* cplexEnv() { return _env.cplexEnv(); } |
|
166 |
|
|
167 |
/// Returns the cplex problem object |
|
154 | 168 |
cpxlp* cplexLp() { return _prob; } |
169 |
/// Returns the cplex problem object |
|
155 | 170 |
const cpxlp* cplexLp() const { return _prob; } |
156 | 171 |
|
157 | 172 |
}; |
158 | 173 |
|
159 | 174 |
/// \brief Interface for the CPLEX LP solver |
160 | 175 |
/// |
161 | 176 |
/// This class implements an interface for the CPLEX LP solver. |
162 | 177 |
///\ingroup lp_group |
163 | 178 |
class CplexLp : public LpSolver, public CplexBase { |
164 | 179 |
public: |
165 | 180 |
/// \e |
166 | 181 |
CplexLp(); |
... | ... |
@@ -22,32 +22,34 @@ |
22 | 22 |
#include <lemon/glpk.h> |
23 | 23 |
#include <glpk.h> |
24 | 24 |
|
25 | 25 |
#include <lemon/assert.h> |
26 | 26 |
|
27 | 27 |
namespace lemon { |
28 | 28 |
|
29 | 29 |
// GlpkBase members |
30 | 30 |
|
31 | 31 |
GlpkBase::GlpkBase() : LpBase() { |
32 | 32 |
lp = glp_create_prob(); |
33 | 33 |
glp_create_index(lp); |
34 |
messageLevel(MESSAGE_NOTHING); |
|
34 | 35 |
} |
35 | 36 |
|
36 | 37 |
GlpkBase::GlpkBase(const GlpkBase &other) : LpBase() { |
37 | 38 |
lp = glp_create_prob(); |
38 | 39 |
glp_copy_prob(lp, other.lp, GLP_ON); |
39 | 40 |
glp_create_index(lp); |
40 | 41 |
rows = other.rows; |
41 | 42 |
cols = other.cols; |
43 |
messageLevel(MESSAGE_NOTHING); |
|
42 | 44 |
} |
43 | 45 |
|
44 | 46 |
GlpkBase::~GlpkBase() { |
45 | 47 |
glp_delete_prob(lp); |
46 | 48 |
} |
47 | 49 |
|
48 | 50 |
int GlpkBase::_addCol() { |
49 | 51 |
int i = glp_add_cols(lp, 1); |
50 | 52 |
glp_set_col_bnds(lp, i, GLP_FR, 0.0, 0.0); |
51 | 53 |
return i; |
52 | 54 |
} |
53 | 55 |
|
... | ... |
@@ -517,74 +519,79 @@ |
517 | 519 |
} |
518 | 520 |
|
519 | 521 |
void GlpkBase::_clear() { |
520 | 522 |
glp_erase_prob(lp); |
521 | 523 |
rows.clear(); |
522 | 524 |
cols.clear(); |
523 | 525 |
} |
524 | 526 |
|
525 | 527 |
void GlpkBase::freeEnv() { |
526 | 528 |
glp_free_env(); |
527 | 529 |
} |
528 | 530 |
|
531 |
void GlpkBase::_messageLevel(MessageLevel level) { |
|
532 |
switch (level) { |
|
533 |
case MESSAGE_NOTHING: |
|
534 |
_message_level = GLP_MSG_OFF; |
|
535 |
break; |
|
536 |
case MESSAGE_ERROR: |
|
537 |
_message_level = GLP_MSG_ERR; |
|
538 |
break; |
|
539 |
case MESSAGE_WARNING: |
|
540 |
_message_level = GLP_MSG_ERR; |
|
541 |
break; |
|
542 |
case MESSAGE_NORMAL: |
|
543 |
_message_level = GLP_MSG_ON; |
|
544 |
break; |
|
545 |
case MESSAGE_VERBOSE: |
|
546 |
_message_level = GLP_MSG_ALL; |
|
547 |
break; |
|
548 |
} |
|
549 |
} |
|
550 |
|
|
529 | 551 |
GlpkBase::FreeEnvHelper GlpkBase::freeEnvHelper; |
530 | 552 |
|
531 | 553 |
// GlpkLp members |
532 | 554 |
|
533 | 555 |
GlpkLp::GlpkLp() |
534 | 556 |
: LpBase(), LpSolver(), GlpkBase() { |
535 |
messageLevel(MESSAGE_NO_OUTPUT); |
|
536 | 557 |
presolver(false); |
537 | 558 |
} |
538 | 559 |
|
539 | 560 |
GlpkLp::GlpkLp(const GlpkLp& other) |
540 | 561 |
: LpBase(other), LpSolver(other), GlpkBase(other) { |
541 |
messageLevel(MESSAGE_NO_OUTPUT); |
|
542 | 562 |
presolver(false); |
543 | 563 |
} |
544 | 564 |
|
545 | 565 |
GlpkLp* GlpkLp::newSolver() const { return new GlpkLp; } |
546 | 566 |
GlpkLp* GlpkLp::cloneSolver() const { return new GlpkLp(*this); } |
547 | 567 |
|
548 | 568 |
const char* GlpkLp::_solverName() const { return "GlpkLp"; } |
549 | 569 |
|
550 | 570 |
void GlpkLp::_clear_temporals() { |
551 | 571 |
_primal_ray.clear(); |
552 | 572 |
_dual_ray.clear(); |
553 | 573 |
} |
554 | 574 |
|
555 | 575 |
GlpkLp::SolveExitStatus GlpkLp::_solve() { |
556 | 576 |
return solvePrimal(); |
557 | 577 |
} |
558 | 578 |
|
559 | 579 |
GlpkLp::SolveExitStatus GlpkLp::solvePrimal() { |
560 | 580 |
_clear_temporals(); |
561 | 581 |
|
562 | 582 |
glp_smcp smcp; |
563 | 583 |
glp_init_smcp(&smcp); |
564 | 584 |
|
565 |
switch (_message_level) { |
|
566 |
case MESSAGE_NO_OUTPUT: |
|
567 |
smcp.msg_lev = GLP_MSG_OFF; |
|
568 |
break; |
|
569 |
case MESSAGE_ERROR_MESSAGE: |
|
570 |
smcp.msg_lev = GLP_MSG_ERR; |
|
571 |
break; |
|
572 |
case MESSAGE_NORMAL_OUTPUT: |
|
573 |
smcp.msg_lev = GLP_MSG_ON; |
|
574 |
break; |
|
575 |
case MESSAGE_FULL_OUTPUT: |
|
576 |
smcp.msg_lev = GLP_MSG_ALL; |
|
577 |
break; |
|
578 |
} |
|
585 |
smcp.msg_lev = _message_level; |
|
579 | 586 |
smcp.presolve = _presolve; |
580 | 587 |
|
581 | 588 |
// If the basis is not valid we get an error return value. |
582 | 589 |
// In this case we can try to create a new basis. |
583 | 590 |
switch (glp_simplex(lp, &smcp)) { |
584 | 591 |
case 0: |
585 | 592 |
break; |
586 | 593 |
case GLP_EBADB: |
587 | 594 |
case GLP_ESING: |
588 | 595 |
case GLP_ECOND: |
589 | 596 |
glp_term_out(false); |
590 | 597 |
glp_adv_basis(lp, 0); |
... | ... |
@@ -595,38 +602,25 @@ |
595 | 602 |
return UNSOLVED; |
596 | 603 |
} |
597 | 604 |
|
598 | 605 |
return SOLVED; |
599 | 606 |
} |
600 | 607 |
|
601 | 608 |
GlpkLp::SolveExitStatus GlpkLp::solveDual() { |
602 | 609 |
_clear_temporals(); |
603 | 610 |
|
604 | 611 |
glp_smcp smcp; |
605 | 612 |
glp_init_smcp(&smcp); |
606 | 613 |
|
607 |
switch (_message_level) { |
|
608 |
case MESSAGE_NO_OUTPUT: |
|
609 |
smcp.msg_lev = GLP_MSG_OFF; |
|
610 |
break; |
|
611 |
case MESSAGE_ERROR_MESSAGE: |
|
612 |
smcp.msg_lev = GLP_MSG_ERR; |
|
613 |
break; |
|
614 |
case MESSAGE_NORMAL_OUTPUT: |
|
615 |
smcp.msg_lev = GLP_MSG_ON; |
|
616 |
break; |
|
617 |
case MESSAGE_FULL_OUTPUT: |
|
618 |
smcp.msg_lev = GLP_MSG_ALL; |
|
619 |
break; |
|
620 |
} |
|
614 |
smcp.msg_lev = _message_level; |
|
621 | 615 |
smcp.meth = GLP_DUAL; |
622 | 616 |
smcp.presolve = _presolve; |
623 | 617 |
|
624 | 618 |
// If the basis is not valid we get an error return value. |
625 | 619 |
// In this case we can try to create a new basis. |
626 | 620 |
switch (glp_simplex(lp, &smcp)) { |
627 | 621 |
case 0: |
628 | 622 |
break; |
629 | 623 |
case GLP_EBADB: |
630 | 624 |
case GLP_ESING: |
631 | 625 |
case GLP_ECOND: |
632 | 626 |
glp_term_out(false); |
... | ... |
@@ -849,38 +843,32 @@ |
849 | 843 |
case GLP_NOFEAS: |
850 | 844 |
return INFEASIBLE; |
851 | 845 |
default: |
852 | 846 |
LEMON_ASSERT(false, "Wrong primal type"); |
853 | 847 |
return GlpkLp::ProblemType(); |
854 | 848 |
} |
855 | 849 |
} |
856 | 850 |
|
857 | 851 |
void GlpkLp::presolver(bool presolve) { |
858 | 852 |
_presolve = presolve; |
859 | 853 |
} |
860 | 854 |
|
861 |
void GlpkLp::messageLevel(MessageLevel m) { |
|
862 |
_message_level = m; |
|
863 |
} |
|
864 |
|
|
865 | 855 |
// GlpkMip members |
866 | 856 |
|
867 | 857 |
GlpkMip::GlpkMip() |
868 | 858 |
: LpBase(), MipSolver(), GlpkBase() { |
869 |
messageLevel(MESSAGE_NO_OUTPUT); |
|
870 | 859 |
} |
871 | 860 |
|
872 | 861 |
GlpkMip::GlpkMip(const GlpkMip& other) |
873 | 862 |
: LpBase(), MipSolver(), GlpkBase(other) { |
874 |
messageLevel(MESSAGE_NO_OUTPUT); |
|
875 | 863 |
} |
876 | 864 |
|
877 | 865 |
void GlpkMip::_setColType(int i, GlpkMip::ColTypes col_type) { |
878 | 866 |
switch (col_type) { |
879 | 867 |
case INTEGER: |
880 | 868 |
glp_set_col_kind(lp, i, GLP_IV); |
881 | 869 |
break; |
882 | 870 |
case REAL: |
883 | 871 |
glp_set_col_kind(lp, i, GLP_CV); |
884 | 872 |
break; |
885 | 873 |
} |
886 | 874 |
} |
... | ... |
@@ -891,76 +879,50 @@ |
891 | 879 |
case GLP_BV: |
892 | 880 |
return INTEGER; |
893 | 881 |
default: |
894 | 882 |
return REAL; |
895 | 883 |
} |
896 | 884 |
|
897 | 885 |
} |
898 | 886 |
|
899 | 887 |
GlpkMip::SolveExitStatus GlpkMip::_solve() { |
900 | 888 |
glp_smcp smcp; |
901 | 889 |
glp_init_smcp(&smcp); |
902 | 890 |
|
903 |
switch (_message_level) { |
|
904 |
case MESSAGE_NO_OUTPUT: |
|
905 |
smcp.msg_lev = GLP_MSG_OFF; |
|
906 |
break; |
|
907 |
case MESSAGE_ERROR_MESSAGE: |
|
908 |
smcp.msg_lev = GLP_MSG_ERR; |
|
909 |
break; |
|
910 |
case MESSAGE_NORMAL_OUTPUT: |
|
911 |
smcp.msg_lev = GLP_MSG_ON; |
|
912 |
break; |
|
913 |
case MESSAGE_FULL_OUTPUT: |
|
914 |
smcp.msg_lev = GLP_MSG_ALL; |
|
915 |
break; |
|
916 |
} |
|
891 |
smcp.msg_lev = _message_level; |
|
917 | 892 |
smcp.meth = GLP_DUAL; |
918 | 893 |
|
919 | 894 |
// If the basis is not valid we get an error return value. |
920 | 895 |
// In this case we can try to create a new basis. |
921 | 896 |
switch (glp_simplex(lp, &smcp)) { |
922 | 897 |
case 0: |
923 | 898 |
break; |
924 | 899 |
case GLP_EBADB: |
925 | 900 |
case GLP_ESING: |
926 | 901 |
case GLP_ECOND: |
927 | 902 |
glp_term_out(false); |
928 | 903 |
glp_adv_basis(lp, 0); |
929 | 904 |
glp_term_out(true); |
930 | 905 |
if (glp_simplex(lp, &smcp) != 0) return UNSOLVED; |
931 | 906 |
break; |
932 | 907 |
default: |
933 | 908 |
return UNSOLVED; |
934 | 909 |
} |
935 | 910 |
|
936 | 911 |
if (glp_get_status(lp) != GLP_OPT) return SOLVED; |
937 | 912 |
|
938 | 913 |
glp_iocp iocp; |
939 | 914 |
glp_init_iocp(&iocp); |
940 | 915 |
|
941 |
switch (_message_level) { |
|
942 |
case MESSAGE_NO_OUTPUT: |
|
943 |
iocp.msg_lev = GLP_MSG_OFF; |
|
944 |
break; |
|
945 |
case MESSAGE_ERROR_MESSAGE: |
|
946 |
iocp.msg_lev = GLP_MSG_ERR; |
|
947 |
break; |
|
948 |
case MESSAGE_NORMAL_OUTPUT: |
|
949 |
iocp.msg_lev = GLP_MSG_ON; |
|
950 |
break; |
|
951 |
case MESSAGE_FULL_OUTPUT: |
|
952 |
iocp.msg_lev = GLP_MSG_ALL; |
|
953 |
break; |
|
954 |
} |
|
916 |
iocp.msg_lev = _message_level; |
|
955 | 917 |
|
956 | 918 |
if (glp_intopt(lp, &iocp) != 0) return UNSOLVED; |
957 | 919 |
return SOLVED; |
958 | 920 |
} |
959 | 921 |
|
960 | 922 |
|
961 | 923 |
GlpkMip::ProblemType GlpkMip::_getType() const { |
962 | 924 |
switch (glp_get_status(lp)) { |
963 | 925 |
case GLP_OPT: |
964 | 926 |
switch (glp_mip_status(lp)) { |
965 | 927 |
case GLP_UNDEF: |
966 | 928 |
return UNDEFINED; |
... | ... |
@@ -993,17 +955,13 @@ |
993 | 955 |
return glp_mip_col_val(lp, i); |
994 | 956 |
} |
995 | 957 |
|
996 | 958 |
GlpkMip::Value GlpkMip::_getSolValue() const { |
997 | 959 |
return glp_mip_obj_val(lp); |
998 | 960 |
} |
999 | 961 |
|
1000 | 962 |
GlpkMip* GlpkMip::newSolver() const { return new GlpkMip; } |
1001 | 963 |
GlpkMip* GlpkMip::cloneSolver() const {return new GlpkMip(*this); } |
1002 | 964 |
|
1003 | 965 |
const char* GlpkMip::_solverName() const { return "GlpkMip"; } |
1004 | 966 |
|
1005 |
void GlpkMip::messageLevel(MessageLevel m) { |
|
1006 |
_message_level = m; |
|
1007 |
} |
|
1008 |
|
|
1009 | 967 |
} //END OF NAMESPACE LEMON |
... | ... |
@@ -91,35 +91,41 @@ |
91 | 91 |
|
92 | 92 |
virtual void _setObjCoeffs(ExprIterator b, ExprIterator e); |
93 | 93 |
virtual void _getObjCoeffs(InsertIterator b) const; |
94 | 94 |
|
95 | 95 |
virtual void _setObjCoeff(int i, Value obj_coef); |
96 | 96 |
virtual Value _getObjCoeff(int i) const; |
97 | 97 |
|
98 | 98 |
virtual void _setSense(Sense); |
99 | 99 |
virtual Sense _getSense() const; |
100 | 100 |
|
101 | 101 |
virtual void _clear(); |
102 | 102 |
|
103 |
virtual void _messageLevel(MessageLevel level); |
|
104 |
|
|
103 | 105 |
private: |
104 | 106 |
|
105 | 107 |
static void freeEnv(); |
106 | 108 |
|
107 | 109 |
struct FreeEnvHelper { |
108 | 110 |
~FreeEnvHelper() { |
109 | 111 |
freeEnv(); |
110 | 112 |
} |
111 | 113 |
}; |
112 | 114 |
|
113 | 115 |
static FreeEnvHelper freeEnvHelper; |
116 |
|
|
117 |
protected: |
|
118 |
|
|
119 |
int _message_level; |
|
114 | 120 |
|
115 | 121 |
public: |
116 | 122 |
|
117 | 123 |
///Pointer to the underlying GLPK data structure. |
118 | 124 |
LPX *lpx() {return lp;} |
119 | 125 |
///Const pointer to the underlying GLPK data structure. |
120 | 126 |
const LPX *lpx() const {return lp;} |
121 | 127 |
|
122 | 128 |
///Returns the constraint identifier understood by GLPK. |
123 | 129 |
int lpxRow(Row r) const { return rows(id(r)); } |
124 | 130 |
|
125 | 131 |
///Returns the variable identifier understood by GLPK. |
... | ... |
@@ -182,48 +188,24 @@ |
182 | 188 |
|
183 | 189 |
bool _presolve; |
184 | 190 |
|
185 | 191 |
public: |
186 | 192 |
|
187 | 193 |
///Turns on or off the presolver |
188 | 194 |
|
189 | 195 |
///Turns on (\c b is \c true) or off (\c b is \c false) the presolver |
190 | 196 |
/// |
191 | 197 |
///The presolver is off by default. |
192 | 198 |
void presolver(bool presolve); |
193 | 199 |
|
194 |
///Enum for \c messageLevel() parameter |
|
195 |
enum MessageLevel { |
|
196 |
/// no output (default value) |
|
197 |
MESSAGE_NO_OUTPUT = 0, |
|
198 |
/// error messages only |
|
199 |
MESSAGE_ERROR_MESSAGE = 1, |
|
200 |
/// normal output |
|
201 |
MESSAGE_NORMAL_OUTPUT = 2, |
|
202 |
/// full output (includes informational messages) |
|
203 |
MESSAGE_FULL_OUTPUT = 3 |
|
204 |
}; |
|
205 |
|
|
206 |
private: |
|
207 |
|
|
208 |
MessageLevel _message_level; |
|
209 |
|
|
210 |
public: |
|
211 |
|
|
212 |
///Set the verbosity of the messages |
|
213 |
|
|
214 |
///Set the verbosity of the messages |
|
215 |
/// |
|
216 |
///\param m is the level of the messages output by the solver routines. |
|
217 |
void messageLevel(MessageLevel m); |
|
218 | 200 |
}; |
219 | 201 |
|
220 | 202 |
/// \brief Interface for the GLPK MIP solver |
221 | 203 |
/// |
222 | 204 |
/// This class implements an interface for the GLPK MIP solver. |
223 | 205 |
///\ingroup lp_group |
224 | 206 |
class GlpkMip : public MipSolver, public GlpkBase { |
225 | 207 |
public: |
226 | 208 |
|
227 | 209 |
///\e |
228 | 210 |
GlpkMip(); |
229 | 211 |
///\e |
... | ... |
@@ -235,43 +217,19 @@ |
235 | 217 |
protected: |
236 | 218 |
|
237 | 219 |
virtual const char* _solverName() const; |
238 | 220 |
|
239 | 221 |
virtual ColTypes _getColType(int col) const; |
240 | 222 |
virtual void _setColType(int col, ColTypes col_type); |
241 | 223 |
|
242 | 224 |
virtual SolveExitStatus _solve(); |
243 | 225 |
virtual ProblemType _getType() const; |
244 | 226 |
virtual Value _getSol(int i) const; |
245 | 227 |
virtual Value _getSolValue() const; |
246 | 228 |
|
247 |
///Enum for \c messageLevel() parameter |
|
248 |
enum MessageLevel { |
|
249 |
/// no output (default value) |
|
250 |
MESSAGE_NO_OUTPUT = 0, |
|
251 |
/// error messages only |
|
252 |
MESSAGE_ERROR_MESSAGE = 1, |
|
253 |
/// normal output |
|
254 |
MESSAGE_NORMAL_OUTPUT = 2, |
|
255 |
/// full output (includes informational messages) |
|
256 |
MESSAGE_FULL_OUTPUT = 3 |
|
257 |
}; |
|
258 |
|
|
259 |
private: |
|
260 |
|
|
261 |
MessageLevel _message_level; |
|
262 |
|
|
263 |
public: |
|
264 |
|
|
265 |
///Set the verbosity of the messages |
|
266 |
|
|
267 |
///Set the verbosity of the messages |
|
268 |
/// |
|
269 |
///\param m is the level of the messages output by the solver routines. |
|
270 |
void messageLevel(MessageLevel m); |
|
271 | 229 |
}; |
272 | 230 |
|
273 | 231 |
|
274 | 232 |
} //END OF NAMESPACE LEMON |
275 | 233 |
|
276 | 234 |
#endif //LEMON_GLPK_H |
277 | 235 |
... | ... |
@@ -60,24 +60,39 @@ |
60 | 60 |
///limit has been exceeded) |
61 | 61 |
UNSOLVED = 1 |
62 | 62 |
}; |
63 | 63 |
|
64 | 64 |
///Direction of the optimization |
65 | 65 |
enum Sense { |
66 | 66 |
/// Minimization |
67 | 67 |
MIN, |
68 | 68 |
/// Maximization |
69 | 69 |
MAX |
70 | 70 |
}; |
71 | 71 |
|
72 |
///Enum for \c messageLevel() parameter |
|
73 |
enum MessageLevel { |
|
74 |
/// no output (default value) |
|
75 |
MESSAGE_NOTHING, |
|
76 |
/// error messages only |
|
77 |
MESSAGE_ERROR, |
|
78 |
/// warnings |
|
79 |
MESSAGE_WARNING, |
|
80 |
/// normal output |
|
81 |
MESSAGE_NORMAL, |
|
82 |
/// verbose output |
|
83 |
MESSAGE_VERBOSE |
|
84 |
}; |
|
85 |
|
|
86 |
|
|
72 | 87 |
///The floating point type used by the solver |
73 | 88 |
typedef double Value; |
74 | 89 |
///The infinity constant |
75 | 90 |
static const Value INF; |
76 | 91 |
///The not a number constant |
77 | 92 |
static const Value NaN; |
78 | 93 |
|
79 | 94 |
friend class Col; |
80 | 95 |
friend class ColIt; |
81 | 96 |
friend class Row; |
82 | 97 |
friend class RowIt; |
83 | 98 |
|
... | ... |
@@ -964,24 +979,26 @@ |
964 | 979 |
virtual void _getObjCoeffs(InsertIterator b) const = 0; |
965 | 980 |
|
966 | 981 |
virtual void _setObjCoeff(int i, Value obj_coef) = 0; |
967 | 982 |
virtual Value _getObjCoeff(int i) const = 0; |
968 | 983 |
|
969 | 984 |
virtual void _setSense(Sense) = 0; |
970 | 985 |
virtual Sense _getSense() const = 0; |
971 | 986 |
|
972 | 987 |
virtual void _clear() = 0; |
973 | 988 |
|
974 | 989 |
virtual const char* _solverName() const = 0; |
975 | 990 |
|
991 |
virtual void _messageLevel(MessageLevel level) = 0; |
|
992 |
|
|
976 | 993 |
//Own protected stuff |
977 | 994 |
|
978 | 995 |
//Constant component of the objective function |
979 | 996 |
Value obj_const_comp; |
980 | 997 |
|
981 | 998 |
LpBase() : rows(), cols(), obj_const_comp(0) {} |
982 | 999 |
|
983 | 1000 |
public: |
984 | 1001 |
|
985 | 1002 |
/// Virtual destructor |
986 | 1003 |
virtual ~LpBase() {} |
987 | 1004 |
|
... | ... |
@@ -1518,24 +1535,27 @@ |
1518 | 1535 |
///Query the direction of the optimization |
1519 | 1536 |
Sense sense() const {return _getSense(); } |
1520 | 1537 |
|
1521 | 1538 |
///Set the sense to maximization |
1522 | 1539 |
void max() { _setSense(MAX); } |
1523 | 1540 |
|
1524 | 1541 |
///Set the sense to maximization |
1525 | 1542 |
void min() { _setSense(MIN); } |
1526 | 1543 |
|
1527 | 1544 |
///Clears the problem |
1528 | 1545 |
void clear() { _clear(); } |
1529 | 1546 |
|
1547 |
/// Sets the message level of the solver |
|
1548 |
void messageLevel(MessageLevel level) { _messageLevel(level); } |
|
1549 |
|
|
1530 | 1550 |
///@} |
1531 | 1551 |
|
1532 | 1552 |
}; |
1533 | 1553 |
|
1534 | 1554 |
/// Addition |
1535 | 1555 |
|
1536 | 1556 |
///\relates LpBase::Expr |
1537 | 1557 |
/// |
1538 | 1558 |
inline LpBase::Expr operator+(const LpBase::Expr &a, const LpBase::Expr &b) { |
1539 | 1559 |
LpBase::Expr tmp(a); |
1540 | 1560 |
tmp+=b; |
1541 | 1561 |
return tmp; |
... | ... |
@@ -75,24 +75,26 @@ |
75 | 75 |
void SkeletonSolverBase::_setObjCoeff(int, Value) {} |
76 | 76 |
SkeletonSolverBase::Value SkeletonSolverBase::_getObjCoeff(int) const |
77 | 77 |
{ return 0; } |
78 | 78 |
|
79 | 79 |
void SkeletonSolverBase::_setSense(Sense) {} |
80 | 80 |
SkeletonSolverBase::Sense SkeletonSolverBase::_getSense() const |
81 | 81 |
{ return MIN; } |
82 | 82 |
|
83 | 83 |
void SkeletonSolverBase::_clear() { |
84 | 84 |
row_num = col_num = 0; |
85 | 85 |
} |
86 | 86 |
|
87 |
void SkeletonSolverBase::_messageLevel(MessageLevel) {} |
|
88 |
|
|
87 | 89 |
LpSkeleton::SolveExitStatus LpSkeleton::_solve() { return SOLVED; } |
88 | 90 |
|
89 | 91 |
LpSkeleton::Value LpSkeleton::_getPrimal(int) const { return 0; } |
90 | 92 |
LpSkeleton::Value LpSkeleton::_getDual(int) const { return 0; } |
91 | 93 |
LpSkeleton::Value LpSkeleton::_getPrimalValue() const { return 0; } |
92 | 94 |
|
93 | 95 |
LpSkeleton::Value LpSkeleton::_getPrimalRay(int) const { return 0; } |
94 | 96 |
LpSkeleton::Value LpSkeleton::_getDualRay(int) const { return 0; } |
95 | 97 |
|
96 | 98 |
LpSkeleton::ProblemType LpSkeleton::_getPrimalType() const |
97 | 99 |
{ return UNDEFINED; } |
98 | 100 |
... | ... |
@@ -131,24 +131,26 @@ |
131 | 131 |
virtual void _setObjCoeff(int i, Value obj_coef); |
132 | 132 |
/// \e |
133 | 133 |
virtual Value _getObjCoeff(int i) const; |
134 | 134 |
|
135 | 135 |
///\e |
136 | 136 |
virtual void _setSense(Sense); |
137 | 137 |
///\e |
138 | 138 |
virtual Sense _getSense() const; |
139 | 139 |
|
140 | 140 |
///\e |
141 | 141 |
virtual void _clear(); |
142 | 142 |
|
143 |
///\e |
|
144 |
virtual void _messageLevel(MessageLevel); |
|
143 | 145 |
}; |
144 | 146 |
|
145 | 147 |
/// \brief Skeleton class for an LP solver interface |
146 | 148 |
/// |
147 | 149 |
///This class does nothing, but it can serve as a skeleton when |
148 | 150 |
///implementing an interface to new solvers. |
149 | 151 |
|
150 | 152 |
///\ingroup lp_group |
151 | 153 |
class LpSkeleton : public LpSolver, public SkeletonSolverBase { |
152 | 154 |
public: |
153 | 155 |
///\e |
154 | 156 |
LpSkeleton() : LpSolver(), SkeletonSolverBase() {} |
... | ... |
@@ -11,51 +11,54 @@ |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#include <iostream> |
20 | 20 |
#include <lemon/soplex.h> |
21 | 21 |
|
22 | 22 |
#include <soplex.h> |
23 |
#include <spxout.h> |
|
23 | 24 |
|
24 | 25 |
|
25 | 26 |
///\file |
26 | 27 |
///\brief Implementation of the LEMON-SOPLEX lp solver interface. |
27 | 28 |
namespace lemon { |
28 | 29 |
|
29 | 30 |
SoplexLp::SoplexLp() { |
30 | 31 |
soplex = new soplex::SoPlex; |
32 |
messageLevel(MESSAGE_NOTHING); |
|
31 | 33 |
} |
32 | 34 |
|
33 | 35 |
SoplexLp::~SoplexLp() { |
34 | 36 |
delete soplex; |
35 | 37 |
} |
36 | 38 |
|
37 | 39 |
SoplexLp::SoplexLp(const SoplexLp& lp) { |
38 | 40 |
rows = lp.rows; |
39 | 41 |
cols = lp.cols; |
40 | 42 |
|
41 | 43 |
soplex = new soplex::SoPlex; |
42 | 44 |
(*static_cast<soplex::SPxLP*>(soplex)) = *(lp.soplex); |
43 | 45 |
|
44 | 46 |
_col_names = lp._col_names; |
45 | 47 |
_col_names_ref = lp._col_names_ref; |
46 | 48 |
|
47 | 49 |
_row_names = lp._row_names; |
48 | 50 |
_row_names_ref = lp._row_names_ref; |
49 | 51 |
|
52 |
messageLevel(MESSAGE_NOTHING); |
|
50 | 53 |
} |
51 | 54 |
|
52 | 55 |
void SoplexLp::_clear_temporals() { |
53 | 56 |
_primal_values.clear(); |
54 | 57 |
_dual_values.clear(); |
55 | 58 |
} |
56 | 59 |
|
57 | 60 |
SoplexLp* SoplexLp::newSolver() const { |
58 | 61 |
SoplexLp* newlp = new SoplexLp(); |
59 | 62 |
return newlp; |
60 | 63 |
} |
61 | 64 |
|
... | ... |
@@ -262,24 +265,26 @@ |
262 | 265 |
|
263 | 266 |
void SoplexLp::_setObjCoeff(int i, Value obj_coef) { |
264 | 267 |
soplex->changeObj(i, obj_coef); |
265 | 268 |
} |
266 | 269 |
|
267 | 270 |
SoplexLp::Value SoplexLp::_getObjCoeff(int i) const { |
268 | 271 |
return soplex->obj(i); |
269 | 272 |
} |
270 | 273 |
|
271 | 274 |
SoplexLp::SolveExitStatus SoplexLp::_solve() { |
272 | 275 |
|
273 | 276 |
_clear_temporals(); |
277 |
|
|
278 |
_applyMessageLevel(); |
|
274 | 279 |
|
275 | 280 |
soplex::SPxSolver::Status status = soplex->solve(); |
276 | 281 |
|
277 | 282 |
switch (status) { |
278 | 283 |
case soplex::SPxSolver::OPTIMAL: |
279 | 284 |
case soplex::SPxSolver::INFEASIBLE: |
280 | 285 |
case soplex::SPxSolver::UNBOUNDED: |
281 | 286 |
return SOLVED; |
282 | 287 |
default: |
283 | 288 |
return UNSOLVED; |
284 | 289 |
} |
285 | 290 |
} |
... | ... |
@@ -410,14 +415,38 @@ |
410 | 415 |
|
411 | 416 |
void SoplexLp::_clear() { |
412 | 417 |
soplex->clear(); |
413 | 418 |
_col_names.clear(); |
414 | 419 |
_col_names_ref.clear(); |
415 | 420 |
_row_names.clear(); |
416 | 421 |
_row_names_ref.clear(); |
417 | 422 |
cols.clear(); |
418 | 423 |
rows.clear(); |
419 | 424 |
_clear_temporals(); |
420 | 425 |
} |
421 | 426 |
|
427 |
void SoplexLp::_messageLevel(MessageLevel level) { |
|
428 |
switch (level) { |
|
429 |
case MESSAGE_NOTHING: |
|
430 |
_message_level = -1; |
|
431 |
break; |
|
432 |
case MESSAGE_ERROR: |
|
433 |
_message_level = soplex::SPxOut::ERROR; |
|
434 |
break; |
|
435 |
case MESSAGE_WARNING: |
|
436 |
_message_level = soplex::SPxOut::WARNING; |
|
437 |
break; |
|
438 |
case MESSAGE_NORMAL: |
|
439 |
_message_level = soplex::SPxOut::INFO2; |
|
440 |
break; |
|
441 |
case MESSAGE_VERBOSE: |
|
442 |
_message_level = soplex::SPxOut::DEBUG; |
|
443 |
break; |
|
444 |
} |
|
445 |
} |
|
446 |
|
|
447 |
void SoplexLp::_applyMessageLevel() { |
|
448 |
soplex::Param::setVerbose(_message_level); |
|
449 |
} |
|
450 |
|
|
422 | 451 |
} //namespace lemon |
423 | 452 |
... | ... |
@@ -135,18 +135,23 @@ |
135 | 135 |
|
136 | 136 |
virtual Value _getPrimalRay(int i) const; |
137 | 137 |
virtual Value _getDualRay(int i) const; |
138 | 138 |
|
139 | 139 |
virtual VarStatus _getColStatus(int i) const; |
140 | 140 |
virtual VarStatus _getRowStatus(int i) const; |
141 | 141 |
|
142 | 142 |
virtual ProblemType _getPrimalType() const; |
143 | 143 |
virtual ProblemType _getDualType() const; |
144 | 144 |
|
145 | 145 |
virtual void _clear(); |
146 | 146 |
|
147 |
void _messageLevel(MessageLevel m); |
|
148 |
void _applyMessageLevel(); |
|
149 |
|
|
150 |
int _message_level; |
|
151 |
|
|
147 | 152 |
}; |
148 | 153 |
|
149 | 154 |
} //END OF NAMESPACE LEMON |
150 | 155 |
|
151 | 156 |
#endif //LEMON_SOPLEX_H |
152 | 157 |
|
0 comments (0 inline)