0
13
0
| ... | ... |
@@ -49,96 +49,108 @@ |
| 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 | 58 |
messageLevel(MESSAGE_NOTHING); |
| 59 | 59 |
} |
| 60 | 60 |
|
| 61 | 61 |
CbcMip::CbcMip(const CbcMip& other) {
|
| 62 | 62 |
_prob = new CoinModel(*other._prob); |
| 63 | 63 |
_prob->setProblemName("LEMON");
|
| 64 | 64 |
_osi_solver = 0; |
| 65 | 65 |
_cbc_model = 0; |
| 66 | 66 |
messageLevel(MESSAGE_NOTHING); |
| 67 | 67 |
} |
| 68 | 68 |
|
| 69 | 69 |
CbcMip::~CbcMip() {
|
| 70 | 70 |
delete _prob; |
| 71 | 71 |
if (_osi_solver) delete _osi_solver; |
| 72 | 72 |
if (_cbc_model) delete _cbc_model; |
| 73 | 73 |
} |
| 74 | 74 |
|
| 75 | 75 |
const char* CbcMip::_solverName() const { return "CbcMip"; }
|
| 76 | 76 |
|
| 77 | 77 |
int CbcMip::_addCol() {
|
| 78 | 78 |
_prob->addColumn(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX, 0.0, 0, false); |
| 79 | 79 |
return _prob->numberColumns() - 1; |
| 80 | 80 |
} |
| 81 | 81 |
|
| 82 | 82 |
CbcMip* CbcMip::newSolver() const {
|
| 83 | 83 |
CbcMip* newlp = new CbcMip; |
| 84 | 84 |
return newlp; |
| 85 | 85 |
} |
| 86 | 86 |
|
| 87 | 87 |
CbcMip* CbcMip::cloneSolver() const {
|
| 88 | 88 |
CbcMip* copylp = new CbcMip(*this); |
| 89 | 89 |
return copylp; |
| 90 | 90 |
} |
| 91 | 91 |
|
| 92 | 92 |
int CbcMip::_addRow() {
|
| 93 | 93 |
_prob->addRow(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX); |
| 94 | 94 |
return _prob->numberRows() - 1; |
| 95 | 95 |
} |
| 96 | 96 |
|
| 97 |
int CbcMip::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
|
|
| 98 |
std::vector<int> indexes; |
|
| 99 |
std::vector<Value> values; |
|
| 100 |
|
|
| 101 |
for(ExprIterator it = b; it != e; ++it) {
|
|
| 102 |
indexes.push_back(it->first); |
|
| 103 |
values.push_back(it->second); |
|
| 104 |
} |
|
| 105 |
|
|
| 106 |
_prob->addRow(values.size(), &indexes.front(), &values.front(), l, u); |
|
| 107 |
return _prob->numberRows() - 1; |
|
| 108 |
} |
|
| 97 | 109 |
|
| 98 | 110 |
void CbcMip::_eraseCol(int i) {
|
| 99 | 111 |
_prob->deleteColumn(i); |
| 100 | 112 |
} |
| 101 | 113 |
|
| 102 | 114 |
void CbcMip::_eraseRow(int i) {
|
| 103 | 115 |
_prob->deleteRow(i); |
| 104 | 116 |
} |
| 105 | 117 |
|
| 106 | 118 |
void CbcMip::_eraseColId(int i) {
|
| 107 | 119 |
cols.eraseIndex(i); |
| 108 | 120 |
} |
| 109 | 121 |
|
| 110 | 122 |
void CbcMip::_eraseRowId(int i) {
|
| 111 | 123 |
rows.eraseIndex(i); |
| 112 | 124 |
} |
| 113 | 125 |
|
| 114 | 126 |
void CbcMip::_getColName(int c, std::string& name) const {
|
| 115 | 127 |
name = _prob->getColumnName(c); |
| 116 | 128 |
} |
| 117 | 129 |
|
| 118 | 130 |
void CbcMip::_setColName(int c, const std::string& name) {
|
| 119 | 131 |
_prob->setColumnName(c, name.c_str()); |
| 120 | 132 |
} |
| 121 | 133 |
|
| 122 | 134 |
int CbcMip::_colByName(const std::string& name) const {
|
| 123 | 135 |
return _prob->column(name.c_str()); |
| 124 | 136 |
} |
| 125 | 137 |
|
| 126 | 138 |
void CbcMip::_getRowName(int r, std::string& name) const {
|
| 127 | 139 |
name = _prob->getRowName(r); |
| 128 | 140 |
} |
| 129 | 141 |
|
| 130 | 142 |
void CbcMip::_setRowName(int r, const std::string& name) {
|
| 131 | 143 |
_prob->setRowName(r, name.c_str()); |
| 132 | 144 |
} |
| 133 | 145 |
|
| 134 | 146 |
int CbcMip::_rowByName(const std::string& name) const {
|
| 135 | 147 |
return _prob->row(name.c_str()); |
| 136 | 148 |
} |
| 137 | 149 |
|
| 138 | 150 |
void CbcMip::_setRowCoeffs(int i, ExprIterator b, ExprIterator e) {
|
| 139 | 151 |
for (ExprIterator it = b; it != e; ++it) {
|
| 140 | 152 |
_prob->setElement(i, it->first, it->second); |
| 141 | 153 |
} |
| 142 | 154 |
} |
| 143 | 155 |
|
| 144 | 156 |
void CbcMip::_getRowCoeffs(int ix, InsertIterator b) const {
|
| ... | ... |
@@ -17,96 +17,97 @@ |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
// -*- C++ -*- |
| 20 | 20 |
#ifndef LEMON_CBC_H |
| 21 | 21 |
#define LEMON_CBC_H |
| 22 | 22 |
|
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief Header of the LEMON-CBC mip solver interface. |
| 25 | 25 |
///\ingroup lp_group |
| 26 | 26 |
|
| 27 | 27 |
#include <lemon/lp_base.h> |
| 28 | 28 |
|
| 29 | 29 |
class CoinModel; |
| 30 | 30 |
class OsiSolverInterface; |
| 31 | 31 |
class CbcModel; |
| 32 | 32 |
|
| 33 | 33 |
namespace lemon {
|
| 34 | 34 |
|
| 35 | 35 |
/// \brief Interface for the CBC MIP solver |
| 36 | 36 |
/// |
| 37 | 37 |
/// This class implements an interface for the CBC MIP solver. |
| 38 | 38 |
///\ingroup lp_group |
| 39 | 39 |
class CbcMip : public MipSolver {
|
| 40 | 40 |
protected: |
| 41 | 41 |
|
| 42 | 42 |
CoinModel *_prob; |
| 43 | 43 |
OsiSolverInterface *_osi_solver; |
| 44 | 44 |
CbcModel *_cbc_model; |
| 45 | 45 |
|
| 46 | 46 |
public: |
| 47 | 47 |
|
| 48 | 48 |
/// \e |
| 49 | 49 |
CbcMip(); |
| 50 | 50 |
/// \e |
| 51 | 51 |
CbcMip(const CbcMip&); |
| 52 | 52 |
/// \e |
| 53 | 53 |
~CbcMip(); |
| 54 | 54 |
/// \e |
| 55 | 55 |
virtual CbcMip* newSolver() const; |
| 56 | 56 |
/// \e |
| 57 | 57 |
virtual CbcMip* cloneSolver() const; |
| 58 | 58 |
|
| 59 | 59 |
protected: |
| 60 | 60 |
|
| 61 | 61 |
virtual const char* _solverName() const; |
| 62 | 62 |
|
| 63 | 63 |
virtual int _addCol(); |
| 64 | 64 |
virtual int _addRow(); |
| 65 |
virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u); |
|
| 65 | 66 |
|
| 66 | 67 |
virtual void _eraseCol(int i); |
| 67 | 68 |
virtual void _eraseRow(int i); |
| 68 | 69 |
|
| 69 | 70 |
virtual void _eraseColId(int i); |
| 70 | 71 |
virtual void _eraseRowId(int i); |
| 71 | 72 |
|
| 72 | 73 |
virtual void _getColName(int col, std::string& name) const; |
| 73 | 74 |
virtual void _setColName(int col, const std::string& name); |
| 74 | 75 |
virtual int _colByName(const std::string& name) const; |
| 75 | 76 |
|
| 76 | 77 |
virtual void _getRowName(int row, std::string& name) const; |
| 77 | 78 |
virtual void _setRowName(int row, const std::string& name); |
| 78 | 79 |
virtual int _rowByName(const std::string& name) const; |
| 79 | 80 |
|
| 80 | 81 |
virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e); |
| 81 | 82 |
virtual void _getRowCoeffs(int i, InsertIterator b) const; |
| 82 | 83 |
|
| 83 | 84 |
virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e); |
| 84 | 85 |
virtual void _getColCoeffs(int i, InsertIterator b) const; |
| 85 | 86 |
|
| 86 | 87 |
virtual void _setCoeff(int row, int col, Value value); |
| 87 | 88 |
virtual Value _getCoeff(int row, int col) const; |
| 88 | 89 |
|
| 89 | 90 |
virtual void _setColLowerBound(int i, Value value); |
| 90 | 91 |
virtual Value _getColLowerBound(int i) const; |
| 91 | 92 |
virtual void _setColUpperBound(int i, Value value); |
| 92 | 93 |
virtual Value _getColUpperBound(int i) const; |
| 93 | 94 |
|
| 94 | 95 |
virtual void _setRowLowerBound(int i, Value value); |
| 95 | 96 |
virtual Value _getRowLowerBound(int i) const; |
| 96 | 97 |
virtual void _setRowUpperBound(int i, Value value); |
| 97 | 98 |
virtual Value _getRowUpperBound(int i) const; |
| 98 | 99 |
|
| 99 | 100 |
virtual void _setObjCoeffs(ExprIterator b, ExprIterator e); |
| 100 | 101 |
virtual void _getObjCoeffs(InsertIterator b) const; |
| 101 | 102 |
|
| 102 | 103 |
virtual void _setObjCoeff(int i, Value obj_coef); |
| 103 | 104 |
virtual Value _getObjCoeff(int i) const; |
| 104 | 105 |
|
| 105 | 106 |
virtual void _setSense(Sense sense); |
| 106 | 107 |
virtual Sense _getSense() const; |
| 107 | 108 |
|
| 108 | 109 |
virtual ColTypes _getColType(int col) const; |
| 109 | 110 |
virtual void _setColType(int col, ColTypes col_type); |
| 110 | 111 |
|
| 111 | 112 |
virtual SolveExitStatus _solve(); |
| 112 | 113 |
virtual ProblemType _getType() const; |
| ... | ... |
@@ -33,96 +33,109 @@ |
| 33 | 33 |
cols = other.cols; |
| 34 | 34 |
_init_temporals(); |
| 35 | 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 |
|
| 48 | 48 |
void ClpLp::_clear_temporals() {
|
| 49 | 49 |
if (_primal_ray) {
|
| 50 | 50 |
delete[] _primal_ray; |
| 51 | 51 |
_primal_ray = 0; |
| 52 | 52 |
} |
| 53 | 53 |
if (_dual_ray) {
|
| 54 | 54 |
delete[] _dual_ray; |
| 55 | 55 |
_dual_ray = 0; |
| 56 | 56 |
} |
| 57 | 57 |
} |
| 58 | 58 |
|
| 59 | 59 |
ClpLp* ClpLp::newSolver() const {
|
| 60 | 60 |
ClpLp* newlp = new ClpLp; |
| 61 | 61 |
return newlp; |
| 62 | 62 |
} |
| 63 | 63 |
|
| 64 | 64 |
ClpLp* ClpLp::cloneSolver() const {
|
| 65 | 65 |
ClpLp* copylp = new ClpLp(*this); |
| 66 | 66 |
return copylp; |
| 67 | 67 |
} |
| 68 | 68 |
|
| 69 | 69 |
const char* ClpLp::_solverName() const { return "ClpLp"; }
|
| 70 | 70 |
|
| 71 | 71 |
int ClpLp::_addCol() {
|
| 72 | 72 |
_prob->addColumn(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX, 0.0); |
| 73 | 73 |
return _prob->numberColumns() - 1; |
| 74 | 74 |
} |
| 75 | 75 |
|
| 76 | 76 |
int ClpLp::_addRow() {
|
| 77 | 77 |
_prob->addRow(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX); |
| 78 | 78 |
return _prob->numberRows() - 1; |
| 79 | 79 |
} |
| 80 | 80 |
|
| 81 |
int ClpLp::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
|
|
| 82 |
std::vector<int> indexes; |
|
| 83 |
std::vector<Value> values; |
|
| 84 |
|
|
| 85 |
for(ExprIterator it = b; it != e; ++it) {
|
|
| 86 |
indexes.push_back(it->first); |
|
| 87 |
values.push_back(it->second); |
|
| 88 |
} |
|
| 89 |
|
|
| 90 |
_prob->addRow(values.size(), &indexes.front(), &values.front(), l, u); |
|
| 91 |
return _prob->numberRows() - 1; |
|
| 92 |
} |
|
| 93 |
|
|
| 81 | 94 |
|
| 82 | 95 |
void ClpLp::_eraseCol(int c) {
|
| 83 | 96 |
_col_names_ref.erase(_prob->getColumnName(c)); |
| 84 | 97 |
_prob->deleteColumns(1, &c); |
| 85 | 98 |
} |
| 86 | 99 |
|
| 87 | 100 |
void ClpLp::_eraseRow(int r) {
|
| 88 | 101 |
_row_names_ref.erase(_prob->getRowName(r)); |
| 89 | 102 |
_prob->deleteRows(1, &r); |
| 90 | 103 |
} |
| 91 | 104 |
|
| 92 | 105 |
void ClpLp::_eraseColId(int i) {
|
| 93 | 106 |
cols.eraseIndex(i); |
| 94 | 107 |
cols.shiftIndices(i); |
| 95 | 108 |
} |
| 96 | 109 |
|
| 97 | 110 |
void ClpLp::_eraseRowId(int i) {
|
| 98 | 111 |
rows.eraseIndex(i); |
| 99 | 112 |
rows.shiftIndices(i); |
| 100 | 113 |
} |
| 101 | 114 |
|
| 102 | 115 |
void ClpLp::_getColName(int c, std::string& name) const {
|
| 103 | 116 |
name = _prob->getColumnName(c); |
| 104 | 117 |
} |
| 105 | 118 |
|
| 106 | 119 |
void ClpLp::_setColName(int c, const std::string& name) {
|
| 107 | 120 |
_prob->setColumnName(c, const_cast<std::string&>(name)); |
| 108 | 121 |
_col_names_ref[name] = c; |
| 109 | 122 |
} |
| 110 | 123 |
|
| 111 | 124 |
int ClpLp::_colByName(const std::string& name) const {
|
| 112 | 125 |
std::map<std::string, int>::const_iterator it = _col_names_ref.find(name); |
| 113 | 126 |
return it != _col_names_ref.end() ? it->second : -1; |
| 114 | 127 |
} |
| 115 | 128 |
|
| 116 | 129 |
void ClpLp::_getRowName(int r, std::string& name) const {
|
| 117 | 130 |
name = _prob->getRowName(r); |
| 118 | 131 |
} |
| 119 | 132 |
|
| 120 | 133 |
void ClpLp::_setRowName(int r, const std::string& name) {
|
| 121 | 134 |
_prob->setRowName(r, const_cast<std::string&>(name)); |
| 122 | 135 |
_row_names_ref[name] = r; |
| 123 | 136 |
} |
| 124 | 137 |
|
| 125 | 138 |
int ClpLp::_rowByName(const std::string& name) const {
|
| 126 | 139 |
std::map<std::string, int>::const_iterator it = _row_names_ref.find(name); |
| 127 | 140 |
return it != _row_names_ref.end() ? it->second : -1; |
| 128 | 141 |
} |
| ... | ... |
@@ -30,96 +30,97 @@ |
| 30 | 30 |
class ClpSimplex; |
| 31 | 31 |
|
| 32 | 32 |
namespace lemon {
|
| 33 | 33 |
|
| 34 | 34 |
/// \ingroup lp_group |
| 35 | 35 |
/// |
| 36 | 36 |
/// \brief Interface for the CLP solver |
| 37 | 37 |
/// |
| 38 | 38 |
/// This class implements an interface for the Clp LP solver. The |
| 39 | 39 |
/// Clp library is an object oriented lp solver library developed at |
| 40 | 40 |
/// the IBM. The CLP is part of the COIN-OR package and it can be |
| 41 | 41 |
/// used with Common Public License. |
| 42 | 42 |
class ClpLp : public LpSolver {
|
| 43 | 43 |
protected: |
| 44 | 44 |
|
| 45 | 45 |
ClpSimplex* _prob; |
| 46 | 46 |
|
| 47 | 47 |
std::map<std::string, int> _col_names_ref; |
| 48 | 48 |
std::map<std::string, int> _row_names_ref; |
| 49 | 49 |
|
| 50 | 50 |
public: |
| 51 | 51 |
|
| 52 | 52 |
/// \e |
| 53 | 53 |
ClpLp(); |
| 54 | 54 |
/// \e |
| 55 | 55 |
ClpLp(const ClpLp&); |
| 56 | 56 |
/// \e |
| 57 | 57 |
~ClpLp(); |
| 58 | 58 |
|
| 59 | 59 |
/// \e |
| 60 | 60 |
virtual ClpLp* newSolver() const; |
| 61 | 61 |
/// \e |
| 62 | 62 |
virtual ClpLp* cloneSolver() const; |
| 63 | 63 |
|
| 64 | 64 |
protected: |
| 65 | 65 |
|
| 66 | 66 |
mutable double* _primal_ray; |
| 67 | 67 |
mutable double* _dual_ray; |
| 68 | 68 |
|
| 69 | 69 |
void _init_temporals(); |
| 70 | 70 |
void _clear_temporals(); |
| 71 | 71 |
|
| 72 | 72 |
protected: |
| 73 | 73 |
|
| 74 | 74 |
virtual const char* _solverName() const; |
| 75 | 75 |
|
| 76 | 76 |
virtual int _addCol(); |
| 77 | 77 |
virtual int _addRow(); |
| 78 |
virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u); |
|
| 78 | 79 |
|
| 79 | 80 |
virtual void _eraseCol(int i); |
| 80 | 81 |
virtual void _eraseRow(int i); |
| 81 | 82 |
|
| 82 | 83 |
virtual void _eraseColId(int i); |
| 83 | 84 |
virtual void _eraseRowId(int i); |
| 84 | 85 |
|
| 85 | 86 |
virtual void _getColName(int col, std::string& name) const; |
| 86 | 87 |
virtual void _setColName(int col, const std::string& name); |
| 87 | 88 |
virtual int _colByName(const std::string& name) const; |
| 88 | 89 |
|
| 89 | 90 |
virtual void _getRowName(int row, std::string& name) const; |
| 90 | 91 |
virtual void _setRowName(int row, const std::string& name); |
| 91 | 92 |
virtual int _rowByName(const std::string& name) const; |
| 92 | 93 |
|
| 93 | 94 |
virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e); |
| 94 | 95 |
virtual void _getRowCoeffs(int i, InsertIterator b) const; |
| 95 | 96 |
|
| 96 | 97 |
virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e); |
| 97 | 98 |
virtual void _getColCoeffs(int i, InsertIterator b) const; |
| 98 | 99 |
|
| 99 | 100 |
virtual void _setCoeff(int row, int col, Value value); |
| 100 | 101 |
virtual Value _getCoeff(int row, int col) const; |
| 101 | 102 |
|
| 102 | 103 |
virtual void _setColLowerBound(int i, Value value); |
| 103 | 104 |
virtual Value _getColLowerBound(int i) const; |
| 104 | 105 |
virtual void _setColUpperBound(int i, Value value); |
| 105 | 106 |
virtual Value _getColUpperBound(int i) const; |
| 106 | 107 |
|
| 107 | 108 |
virtual void _setRowLowerBound(int i, Value value); |
| 108 | 109 |
virtual Value _getRowLowerBound(int i) const; |
| 109 | 110 |
virtual void _setRowUpperBound(int i, Value value); |
| 110 | 111 |
virtual Value _getRowUpperBound(int i) const; |
| 111 | 112 |
|
| 112 | 113 |
virtual void _setObjCoeffs(ExprIterator, ExprIterator); |
| 113 | 114 |
virtual void _getObjCoeffs(InsertIterator) const; |
| 114 | 115 |
|
| 115 | 116 |
virtual void _setObjCoeff(int i, Value obj_coef); |
| 116 | 117 |
virtual Value _getObjCoeff(int i) const; |
| 117 | 118 |
|
| 118 | 119 |
virtual void _setSense(Sense sense); |
| 119 | 120 |
virtual Sense _getSense() const; |
| 120 | 121 |
|
| 121 | 122 |
virtual SolveExitStatus _solve(); |
| 122 | 123 |
|
| 123 | 124 |
virtual Value _getPrimal(int i) const; |
| 124 | 125 |
virtual Value _getDual(int i) const; |
| 125 | 126 |
| ... | ... |
@@ -66,96 +66,129 @@ |
| 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 | 75 |
messageLevel(MESSAGE_NOTHING); |
| 76 | 76 |
} |
| 77 | 77 |
|
| 78 | 78 |
CplexBase::CplexBase(const CplexEnv& env) |
| 79 | 79 |
: LpBase(), _env(env) {
|
| 80 | 80 |
int status; |
| 81 | 81 |
_prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem"); |
| 82 | 82 |
messageLevel(MESSAGE_NOTHING); |
| 83 | 83 |
} |
| 84 | 84 |
|
| 85 | 85 |
CplexBase::CplexBase(const CplexBase& cplex) |
| 86 | 86 |
: LpBase() {
|
| 87 | 87 |
int status; |
| 88 | 88 |
_prob = CPXcloneprob(cplexEnv(), cplex._prob, &status); |
| 89 | 89 |
rows = cplex.rows; |
| 90 | 90 |
cols = cplex.cols; |
| 91 | 91 |
messageLevel(MESSAGE_NOTHING); |
| 92 | 92 |
} |
| 93 | 93 |
|
| 94 | 94 |
CplexBase::~CplexBase() {
|
| 95 | 95 |
CPXfreeprob(cplexEnv(),&_prob); |
| 96 | 96 |
} |
| 97 | 97 |
|
| 98 | 98 |
int CplexBase::_addCol() {
|
| 99 | 99 |
int i = CPXgetnumcols(cplexEnv(), _prob); |
| 100 | 100 |
double lb = -INF, ub = INF; |
| 101 | 101 |
CPXnewcols(cplexEnv(), _prob, 1, 0, &lb, &ub, 0, 0); |
| 102 | 102 |
return i; |
| 103 | 103 |
} |
| 104 | 104 |
|
| 105 | 105 |
|
| 106 | 106 |
int CplexBase::_addRow() {
|
| 107 | 107 |
int i = CPXgetnumrows(cplexEnv(), _prob); |
| 108 | 108 |
const double ub = INF; |
| 109 | 109 |
const char s = 'L'; |
| 110 | 110 |
CPXnewrows(cplexEnv(), _prob, 1, &ub, &s, 0, 0); |
| 111 | 111 |
return i; |
| 112 | 112 |
} |
| 113 | 113 |
|
| 114 |
int CplexBase::_addRow(Value lb, ExprIterator b, |
|
| 115 |
ExprIterator e, Value ub) {
|
|
| 116 |
int i = CPXgetnumrows(cplexEnv(), _prob); |
|
| 117 |
if (lb == -INF) {
|
|
| 118 |
const char s = 'L'; |
|
| 119 |
CPXnewrows(cplexEnv(), _prob, 1, &ub, &s, 0, 0); |
|
| 120 |
} else if (ub == INF) {
|
|
| 121 |
const char s = 'G'; |
|
| 122 |
CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0); |
|
| 123 |
} else if (lb == ub){
|
|
| 124 |
const char s = 'E'; |
|
| 125 |
CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0); |
|
| 126 |
} else {
|
|
| 127 |
const char s = 'R'; |
|
| 128 |
double len = ub - lb; |
|
| 129 |
CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, &len, 0); |
|
| 130 |
} |
|
| 131 |
|
|
| 132 |
std::vector<int> indices; |
|
| 133 |
std::vector<int> rowlist; |
|
| 134 |
std::vector<Value> values; |
|
| 135 |
|
|
| 136 |
for(ExprIterator it=b; it!=e; ++it) {
|
|
| 137 |
indices.push_back(it->first); |
|
| 138 |
values.push_back(it->second); |
|
| 139 |
rowlist.push_back(i); |
|
| 140 |
} |
|
| 141 |
|
|
| 142 |
CPXchgcoeflist(cplexEnv(), _prob, values.size(), |
|
| 143 |
&rowlist.front(), &indices.front(), &values.front()); |
|
| 144 |
|
|
| 145 |
return i; |
|
| 146 |
} |
|
| 114 | 147 |
|
| 115 | 148 |
void CplexBase::_eraseCol(int i) {
|
| 116 | 149 |
CPXdelcols(cplexEnv(), _prob, i, i); |
| 117 | 150 |
} |
| 118 | 151 |
|
| 119 | 152 |
void CplexBase::_eraseRow(int i) {
|
| 120 | 153 |
CPXdelrows(cplexEnv(), _prob, i, i); |
| 121 | 154 |
} |
| 122 | 155 |
|
| 123 | 156 |
void CplexBase::_eraseColId(int i) {
|
| 124 | 157 |
cols.eraseIndex(i); |
| 125 | 158 |
cols.shiftIndices(i); |
| 126 | 159 |
} |
| 127 | 160 |
void CplexBase::_eraseRowId(int i) {
|
| 128 | 161 |
rows.eraseIndex(i); |
| 129 | 162 |
rows.shiftIndices(i); |
| 130 | 163 |
} |
| 131 | 164 |
|
| 132 | 165 |
void CplexBase::_getColName(int col, std::string &name) const {
|
| 133 | 166 |
int size; |
| 134 | 167 |
CPXgetcolname(cplexEnv(), _prob, 0, 0, 0, &size, col, col); |
| 135 | 168 |
if (size == 0) {
|
| 136 | 169 |
name.clear(); |
| 137 | 170 |
return; |
| 138 | 171 |
} |
| 139 | 172 |
|
| 140 | 173 |
size *= -1; |
| 141 | 174 |
std::vector<char> buf(size); |
| 142 | 175 |
char *cname; |
| 143 | 176 |
int tmp; |
| 144 | 177 |
CPXgetcolname(cplexEnv(), _prob, &cname, &buf.front(), size, |
| 145 | 178 |
&tmp, col, col); |
| 146 | 179 |
name = cname; |
| 147 | 180 |
} |
| 148 | 181 |
|
| 149 | 182 |
void CplexBase::_setColName(int col, const std::string &name) {
|
| 150 | 183 |
char *cname; |
| 151 | 184 |
cname = const_cast<char*>(name.c_str()); |
| 152 | 185 |
CPXchgcolname(cplexEnv(), _prob, 1, &col, &cname); |
| 153 | 186 |
} |
| 154 | 187 |
|
| 155 | 188 |
int CplexBase::_colByName(const std::string& name) const {
|
| 156 | 189 |
int index; |
| 157 | 190 |
if (CPXgetcolindex(cplexEnv(), _prob, |
| 158 | 191 |
const_cast<char*>(name.c_str()), &index) == 0) {
|
| 159 | 192 |
return index; |
| 160 | 193 |
} |
| 161 | 194 |
return -1; |
| ... | ... |
@@ -48,96 +48,97 @@ |
| 48 | 48 |
class LicenseError : public Exception {
|
| 49 | 49 |
friend class CplexEnv; |
| 50 | 50 |
private: |
| 51 | 51 |
|
| 52 | 52 |
LicenseError(int status); |
| 53 | 53 |
char _message[510]; |
| 54 | 54 |
|
| 55 | 55 |
public: |
| 56 | 56 |
|
| 57 | 57 |
/// The short error message |
| 58 | 58 |
virtual const char* what() const throw() {
|
| 59 | 59 |
return _message; |
| 60 | 60 |
} |
| 61 | 61 |
}; |
| 62 | 62 |
|
| 63 | 63 |
/// Constructor |
| 64 | 64 |
CplexEnv(); |
| 65 | 65 |
/// Shallow copy constructor |
| 66 | 66 |
CplexEnv(const CplexEnv&); |
| 67 | 67 |
/// Shallow assignement |
| 68 | 68 |
CplexEnv& operator=(const CplexEnv&); |
| 69 | 69 |
/// Destructor |
| 70 | 70 |
virtual ~CplexEnv(); |
| 71 | 71 |
|
| 72 | 72 |
protected: |
| 73 | 73 |
|
| 74 | 74 |
cpxenv* cplexEnv() { return _env; }
|
| 75 | 75 |
const cpxenv* cplexEnv() const { return _env; }
|
| 76 | 76 |
}; |
| 77 | 77 |
|
| 78 | 78 |
/// \brief Base interface for the CPLEX LP and MIP solver |
| 79 | 79 |
/// |
| 80 | 80 |
/// This class implements the common interface of the CPLEX LP and |
| 81 | 81 |
/// MIP solvers. |
| 82 | 82 |
/// \ingroup lp_group |
| 83 | 83 |
class CplexBase : virtual public LpBase {
|
| 84 | 84 |
protected: |
| 85 | 85 |
|
| 86 | 86 |
CplexEnv _env; |
| 87 | 87 |
cpxlp* _prob; |
| 88 | 88 |
|
| 89 | 89 |
CplexBase(); |
| 90 | 90 |
CplexBase(const CplexEnv&); |
| 91 | 91 |
CplexBase(const CplexBase &); |
| 92 | 92 |
virtual ~CplexBase(); |
| 93 | 93 |
|
| 94 | 94 |
virtual int _addCol(); |
| 95 | 95 |
virtual int _addRow(); |
| 96 |
virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u); |
|
| 96 | 97 |
|
| 97 | 98 |
virtual void _eraseCol(int i); |
| 98 | 99 |
virtual void _eraseRow(int i); |
| 99 | 100 |
|
| 100 | 101 |
virtual void _eraseColId(int i); |
| 101 | 102 |
virtual void _eraseRowId(int i); |
| 102 | 103 |
|
| 103 | 104 |
virtual void _getColName(int col, std::string& name) const; |
| 104 | 105 |
virtual void _setColName(int col, const std::string& name); |
| 105 | 106 |
virtual int _colByName(const std::string& name) const; |
| 106 | 107 |
|
| 107 | 108 |
virtual void _getRowName(int row, std::string& name) const; |
| 108 | 109 |
virtual void _setRowName(int row, const std::string& name); |
| 109 | 110 |
virtual int _rowByName(const std::string& name) const; |
| 110 | 111 |
|
| 111 | 112 |
virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e); |
| 112 | 113 |
virtual void _getRowCoeffs(int i, InsertIterator b) const; |
| 113 | 114 |
|
| 114 | 115 |
virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e); |
| 115 | 116 |
virtual void _getColCoeffs(int i, InsertIterator b) const; |
| 116 | 117 |
|
| 117 | 118 |
virtual void _setCoeff(int row, int col, Value value); |
| 118 | 119 |
virtual Value _getCoeff(int row, int col) const; |
| 119 | 120 |
|
| 120 | 121 |
virtual void _setColLowerBound(int i, Value value); |
| 121 | 122 |
virtual Value _getColLowerBound(int i) const; |
| 122 | 123 |
|
| 123 | 124 |
virtual void _setColUpperBound(int i, Value value); |
| 124 | 125 |
virtual Value _getColUpperBound(int i) const; |
| 125 | 126 |
|
| 126 | 127 |
private: |
| 127 | 128 |
void _set_row_bounds(int i, Value lb, Value ub); |
| 128 | 129 |
protected: |
| 129 | 130 |
|
| 130 | 131 |
virtual void _setRowLowerBound(int i, Value value); |
| 131 | 132 |
virtual Value _getRowLowerBound(int i) const; |
| 132 | 133 |
|
| 133 | 134 |
virtual void _setRowUpperBound(int i, Value value); |
| 134 | 135 |
virtual Value _getRowUpperBound(int i) const; |
| 135 | 136 |
|
| 136 | 137 |
virtual void _setObjCoeffs(ExprIterator b, ExprIterator e); |
| 137 | 138 |
virtual void _getObjCoeffs(InsertIterator b) const; |
| 138 | 139 |
|
| 139 | 140 |
virtual void _setObjCoeff(int i, Value obj_coef); |
| 140 | 141 |
virtual Value _getObjCoeff(int i) const; |
| 141 | 142 |
|
| 142 | 143 |
virtual void _setSense(Sense sense); |
| 143 | 144 |
virtual Sense _getSense() const; |
| ... | ... |
@@ -14,96 +14,132 @@ |
| 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 |
///\file |
| 20 | 20 |
///\brief Implementation of the LEMON GLPK LP and MIP solver interface. |
| 21 | 21 |
|
| 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 | 34 |
messageLevel(MESSAGE_NOTHING); |
| 35 | 35 |
} |
| 36 | 36 |
|
| 37 | 37 |
GlpkBase::GlpkBase(const GlpkBase &other) : LpBase() {
|
| 38 | 38 |
lp = glp_create_prob(); |
| 39 | 39 |
glp_copy_prob(lp, other.lp, GLP_ON); |
| 40 | 40 |
glp_create_index(lp); |
| 41 | 41 |
rows = other.rows; |
| 42 | 42 |
cols = other.cols; |
| 43 | 43 |
messageLevel(MESSAGE_NOTHING); |
| 44 | 44 |
} |
| 45 | 45 |
|
| 46 | 46 |
GlpkBase::~GlpkBase() {
|
| 47 | 47 |
glp_delete_prob(lp); |
| 48 | 48 |
} |
| 49 | 49 |
|
| 50 | 50 |
int GlpkBase::_addCol() {
|
| 51 | 51 |
int i = glp_add_cols(lp, 1); |
| 52 | 52 |
glp_set_col_bnds(lp, i, GLP_FR, 0.0, 0.0); |
| 53 | 53 |
return i; |
| 54 | 54 |
} |
| 55 | 55 |
|
| 56 | 56 |
int GlpkBase::_addRow() {
|
| 57 | 57 |
int i = glp_add_rows(lp, 1); |
| 58 | 58 |
glp_set_row_bnds(lp, i, GLP_FR, 0.0, 0.0); |
| 59 | 59 |
return i; |
| 60 | 60 |
} |
| 61 | 61 |
|
| 62 |
int GlpkBase::_addRow(Value lo, ExprIterator b, |
|
| 63 |
ExprIterator e, Value up) {
|
|
| 64 |
int i = glp_add_rows(lp, 1); |
|
| 65 |
|
|
| 66 |
if (lo == -INF) {
|
|
| 67 |
if (up == INF) {
|
|
| 68 |
glp_set_row_bnds(lp, i, GLP_FR, lo, up); |
|
| 69 |
} else {
|
|
| 70 |
glp_set_row_bnds(lp, i, GLP_UP, lo, up); |
|
| 71 |
} |
|
| 72 |
} else {
|
|
| 73 |
if (up == INF) {
|
|
| 74 |
glp_set_row_bnds(lp, i, GLP_LO, lo, up); |
|
| 75 |
} else if (lo != up) {
|
|
| 76 |
glp_set_row_bnds(lp, i, GLP_DB, lo, up); |
|
| 77 |
} else {
|
|
| 78 |
glp_set_row_bnds(lp, i, GLP_FX, lo, up); |
|
| 79 |
} |
|
| 80 |
} |
|
| 81 |
|
|
| 82 |
std::vector<int> indexes; |
|
| 83 |
std::vector<Value> values; |
|
| 84 |
|
|
| 85 |
indexes.push_back(0); |
|
| 86 |
values.push_back(0); |
|
| 87 |
|
|
| 88 |
for(ExprIterator it = b; it != e; ++it) {
|
|
| 89 |
indexes.push_back(it->first); |
|
| 90 |
values.push_back(it->second); |
|
| 91 |
} |
|
| 92 |
|
|
| 93 |
glp_set_mat_row(lp, i, values.size() - 1, |
|
| 94 |
&indexes.front(), &values.front()); |
|
| 95 |
return i; |
|
| 96 |
} |
|
| 97 |
|
|
| 62 | 98 |
void GlpkBase::_eraseCol(int i) {
|
| 63 | 99 |
int ca[2]; |
| 64 | 100 |
ca[1] = i; |
| 65 | 101 |
glp_del_cols(lp, 1, ca); |
| 66 | 102 |
} |
| 67 | 103 |
|
| 68 | 104 |
void GlpkBase::_eraseRow(int i) {
|
| 69 | 105 |
int ra[2]; |
| 70 | 106 |
ra[1] = i; |
| 71 | 107 |
glp_del_rows(lp, 1, ra); |
| 72 | 108 |
} |
| 73 | 109 |
|
| 74 | 110 |
void GlpkBase::_eraseColId(int i) {
|
| 75 | 111 |
cols.eraseIndex(i); |
| 76 | 112 |
cols.shiftIndices(i); |
| 77 | 113 |
} |
| 78 | 114 |
|
| 79 | 115 |
void GlpkBase::_eraseRowId(int i) {
|
| 80 | 116 |
rows.eraseIndex(i); |
| 81 | 117 |
rows.shiftIndices(i); |
| 82 | 118 |
} |
| 83 | 119 |
|
| 84 | 120 |
void GlpkBase::_getColName(int c, std::string& name) const {
|
| 85 | 121 |
const char *str = glp_get_col_name(lp, c); |
| 86 | 122 |
if (str) name = str; |
| 87 | 123 |
else name.clear(); |
| 88 | 124 |
} |
| 89 | 125 |
|
| 90 | 126 |
void GlpkBase::_setColName(int c, const std::string & name) {
|
| 91 | 127 |
glp_set_col_name(lp, c, const_cast<char*>(name.c_str())); |
| 92 | 128 |
|
| 93 | 129 |
} |
| 94 | 130 |
|
| 95 | 131 |
int GlpkBase::_colByName(const std::string& name) const {
|
| 96 | 132 |
int k = glp_find_col(lp, const_cast<char*>(name.c_str())); |
| 97 | 133 |
return k > 0 ? k : -1; |
| 98 | 134 |
} |
| 99 | 135 |
|
| 100 | 136 |
void GlpkBase::_getRowName(int r, std::string& name) const {
|
| 101 | 137 |
const char *str = glp_get_row_name(lp, r); |
| 102 | 138 |
if (str) name = str; |
| 103 | 139 |
else name.clear(); |
| 104 | 140 |
} |
| 105 | 141 |
|
| 106 | 142 |
void GlpkBase::_setRowName(int r, const std::string & name) {
|
| 107 | 143 |
glp_set_row_name(lp, r, const_cast<char*>(name.c_str())); |
| 108 | 144 |
|
| 109 | 145 |
} |
| ... | ... |
@@ -9,96 +9,97 @@ |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 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 |
#ifndef LEMON_GLPK_H |
| 20 | 20 |
#define LEMON_GLPK_H |
| 21 | 21 |
|
| 22 | 22 |
///\file |
| 23 | 23 |
///\brief Header of the LEMON-GLPK lp solver interface. |
| 24 | 24 |
///\ingroup lp_group |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/lp_base.h> |
| 27 | 27 |
|
| 28 | 28 |
// forward declaration |
| 29 | 29 |
#if !defined _GLP_PROB && !defined GLP_PROB |
| 30 | 30 |
#define _GLP_PROB |
| 31 | 31 |
#define GLP_PROB |
| 32 | 32 |
typedef struct { double _opaque_prob; } glp_prob;
|
| 33 | 33 |
/* LP/MIP problem object */ |
| 34 | 34 |
#endif |
| 35 | 35 |
|
| 36 | 36 |
namespace lemon {
|
| 37 | 37 |
|
| 38 | 38 |
|
| 39 | 39 |
/// \brief Base interface for the GLPK LP and MIP solver |
| 40 | 40 |
/// |
| 41 | 41 |
/// This class implements the common interface of the GLPK LP and MIP solver. |
| 42 | 42 |
/// \ingroup lp_group |
| 43 | 43 |
class GlpkBase : virtual public LpBase {
|
| 44 | 44 |
protected: |
| 45 | 45 |
|
| 46 | 46 |
typedef glp_prob LPX; |
| 47 | 47 |
glp_prob* lp; |
| 48 | 48 |
|
| 49 | 49 |
GlpkBase(); |
| 50 | 50 |
GlpkBase(const GlpkBase&); |
| 51 | 51 |
virtual ~GlpkBase(); |
| 52 | 52 |
|
| 53 | 53 |
protected: |
| 54 | 54 |
|
| 55 | 55 |
virtual int _addCol(); |
| 56 | 56 |
virtual int _addRow(); |
| 57 |
virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u); |
|
| 57 | 58 |
|
| 58 | 59 |
virtual void _eraseCol(int i); |
| 59 | 60 |
virtual void _eraseRow(int i); |
| 60 | 61 |
|
| 61 | 62 |
virtual void _eraseColId(int i); |
| 62 | 63 |
virtual void _eraseRowId(int i); |
| 63 | 64 |
|
| 64 | 65 |
virtual void _getColName(int col, std::string& name) const; |
| 65 | 66 |
virtual void _setColName(int col, const std::string& name); |
| 66 | 67 |
virtual int _colByName(const std::string& name) const; |
| 67 | 68 |
|
| 68 | 69 |
virtual void _getRowName(int row, std::string& name) const; |
| 69 | 70 |
virtual void _setRowName(int row, const std::string& name); |
| 70 | 71 |
virtual int _rowByName(const std::string& name) const; |
| 71 | 72 |
|
| 72 | 73 |
virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e); |
| 73 | 74 |
virtual void _getRowCoeffs(int i, InsertIterator b) const; |
| 74 | 75 |
|
| 75 | 76 |
virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e); |
| 76 | 77 |
virtual void _getColCoeffs(int i, InsertIterator b) const; |
| 77 | 78 |
|
| 78 | 79 |
virtual void _setCoeff(int row, int col, Value value); |
| 79 | 80 |
virtual Value _getCoeff(int row, int col) const; |
| 80 | 81 |
|
| 81 | 82 |
virtual void _setColLowerBound(int i, Value value); |
| 82 | 83 |
virtual Value _getColLowerBound(int i) const; |
| 83 | 84 |
|
| 84 | 85 |
virtual void _setColUpperBound(int i, Value value); |
| 85 | 86 |
virtual Value _getColUpperBound(int i) const; |
| 86 | 87 |
|
| 87 | 88 |
virtual void _setRowLowerBound(int i, Value value); |
| 88 | 89 |
virtual Value _getRowLowerBound(int i) const; |
| 89 | 90 |
|
| 90 | 91 |
virtual void _setRowUpperBound(int i, Value value); |
| 91 | 92 |
virtual Value _getRowUpperBound(int i) const; |
| 92 | 93 |
|
| 93 | 94 |
virtual void _setObjCoeffs(ExprIterator b, ExprIterator e); |
| 94 | 95 |
virtual void _getObjCoeffs(InsertIterator b) const; |
| 95 | 96 |
|
| 96 | 97 |
virtual void _setObjCoeff(int i, Value obj_coef); |
| 97 | 98 |
virtual Value _getObjCoeff(int i) const; |
| 98 | 99 |
|
| 99 | 100 |
virtual void _setSense(Sense); |
| 100 | 101 |
virtual Sense _getSense() const; |
| 101 | 102 |
|
| 102 | 103 |
virtual void _clear(); |
| 103 | 104 |
|
| 104 | 105 |
virtual void _messageLevel(MessageLevel level); |
| ... | ... |
@@ -898,96 +898,104 @@ |
| 898 | 898 |
value_type value; |
| 899 | 899 |
}; |
| 900 | 900 |
|
| 901 | 901 |
ExprIterator(const std::map<int, Value>::const_iterator& host_it, |
| 902 | 902 |
const _solver_bits::VarIndex& index) |
| 903 | 903 |
: _host_it(host_it), _index(index) {}
|
| 904 | 904 |
|
| 905 | 905 |
reference operator*() {
|
| 906 | 906 |
return std::make_pair(_index(_host_it->first), _host_it->second); |
| 907 | 907 |
} |
| 908 | 908 |
|
| 909 | 909 |
pointer operator->() {
|
| 910 | 910 |
return pointer(operator*()); |
| 911 | 911 |
} |
| 912 | 912 |
|
| 913 | 913 |
ExprIterator& operator++() { ++_host_it; return *this; }
|
| 914 | 914 |
ExprIterator operator++(int) {
|
| 915 | 915 |
ExprIterator tmp(*this); ++_host_it; return tmp; |
| 916 | 916 |
} |
| 917 | 917 |
|
| 918 | 918 |
ExprIterator& operator--() { --_host_it; return *this; }
|
| 919 | 919 |
ExprIterator operator--(int) {
|
| 920 | 920 |
ExprIterator tmp(*this); --_host_it; return tmp; |
| 921 | 921 |
} |
| 922 | 922 |
|
| 923 | 923 |
bool operator==(const ExprIterator& it) const {
|
| 924 | 924 |
return _host_it == it._host_it; |
| 925 | 925 |
} |
| 926 | 926 |
|
| 927 | 927 |
bool operator!=(const ExprIterator& it) const {
|
| 928 | 928 |
return _host_it != it._host_it; |
| 929 | 929 |
} |
| 930 | 930 |
|
| 931 | 931 |
}; |
| 932 | 932 |
|
| 933 | 933 |
protected: |
| 934 | 934 |
|
| 935 | 935 |
//Abstract virtual functions |
| 936 | 936 |
|
| 937 | 937 |
virtual int _addColId(int col) { return cols.addIndex(col); }
|
| 938 | 938 |
virtual int _addRowId(int row) { return rows.addIndex(row); }
|
| 939 | 939 |
|
| 940 | 940 |
virtual void _eraseColId(int col) { cols.eraseIndex(col); }
|
| 941 | 941 |
virtual void _eraseRowId(int row) { rows.eraseIndex(row); }
|
| 942 | 942 |
|
| 943 | 943 |
virtual int _addCol() = 0; |
| 944 | 944 |
virtual int _addRow() = 0; |
| 945 | 945 |
|
| 946 |
virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
|
|
| 947 |
int row = _addRow(); |
|
| 948 |
_setRowCoeffs(row, b, e); |
|
| 949 |
_setRowLowerBound(row, l); |
|
| 950 |
_setRowUpperBound(row, u); |
|
| 951 |
return row; |
|
| 952 |
} |
|
| 953 |
|
|
| 946 | 954 |
virtual void _eraseCol(int col) = 0; |
| 947 | 955 |
virtual void _eraseRow(int row) = 0; |
| 948 | 956 |
|
| 949 | 957 |
virtual void _getColName(int col, std::string& name) const = 0; |
| 950 | 958 |
virtual void _setColName(int col, const std::string& name) = 0; |
| 951 | 959 |
virtual int _colByName(const std::string& name) const = 0; |
| 952 | 960 |
|
| 953 | 961 |
virtual void _getRowName(int row, std::string& name) const = 0; |
| 954 | 962 |
virtual void _setRowName(int row, const std::string& name) = 0; |
| 955 | 963 |
virtual int _rowByName(const std::string& name) const = 0; |
| 956 | 964 |
|
| 957 | 965 |
virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e) = 0; |
| 958 | 966 |
virtual void _getRowCoeffs(int i, InsertIterator b) const = 0; |
| 959 | 967 |
|
| 960 | 968 |
virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e) = 0; |
| 961 | 969 |
virtual void _getColCoeffs(int i, InsertIterator b) const = 0; |
| 962 | 970 |
|
| 963 | 971 |
virtual void _setCoeff(int row, int col, Value value) = 0; |
| 964 | 972 |
virtual Value _getCoeff(int row, int col) const = 0; |
| 965 | 973 |
|
| 966 | 974 |
virtual void _setColLowerBound(int i, Value value) = 0; |
| 967 | 975 |
virtual Value _getColLowerBound(int i) const = 0; |
| 968 | 976 |
|
| 969 | 977 |
virtual void _setColUpperBound(int i, Value value) = 0; |
| 970 | 978 |
virtual Value _getColUpperBound(int i) const = 0; |
| 971 | 979 |
|
| 972 | 980 |
virtual void _setRowLowerBound(int i, Value value) = 0; |
| 973 | 981 |
virtual Value _getRowLowerBound(int i) const = 0; |
| 974 | 982 |
|
| 975 | 983 |
virtual void _setRowUpperBound(int i, Value value) = 0; |
| 976 | 984 |
virtual Value _getRowUpperBound(int i) const = 0; |
| 977 | 985 |
|
| 978 | 986 |
virtual void _setObjCoeffs(ExprIterator b, ExprIterator e) = 0; |
| 979 | 987 |
virtual void _getObjCoeffs(InsertIterator b) const = 0; |
| 980 | 988 |
|
| 981 | 989 |
virtual void _setObjCoeff(int i, Value obj_coef) = 0; |
| 982 | 990 |
virtual Value _getObjCoeff(int i) const = 0; |
| 983 | 991 |
|
| 984 | 992 |
virtual void _setSense(Sense) = 0; |
| 985 | 993 |
virtual Sense _getSense() const = 0; |
| 986 | 994 |
|
| 987 | 995 |
virtual void _clear() = 0; |
| 988 | 996 |
|
| 989 | 997 |
virtual const char* _solverName() const = 0; |
| 990 | 998 |
|
| 991 | 999 |
virtual void _messageLevel(MessageLevel level) = 0; |
| 992 | 1000 |
|
| 993 | 1001 |
//Own protected stuff |
| ... | ... |
@@ -1162,108 +1170,114 @@ |
| 1162 | 1170 |
i.set(addRow()); |
| 1163 | 1171 |
s++; |
| 1164 | 1172 |
} |
| 1165 | 1173 |
return s; |
| 1166 | 1174 |
} |
| 1167 | 1175 |
#endif |
| 1168 | 1176 |
|
| 1169 | 1177 |
///Set a row (i.e a constraint) of the LP |
| 1170 | 1178 |
|
| 1171 | 1179 |
///\param r is the row to be modified |
| 1172 | 1180 |
///\param l is lower bound (-\ref INF means no bound) |
| 1173 | 1181 |
///\param e is a linear expression (see \ref Expr) |
| 1174 | 1182 |
///\param u is the upper bound (\ref INF means no bound) |
| 1175 | 1183 |
void row(Row r, Value l, const Expr &e, Value u) {
|
| 1176 | 1184 |
e.simplify(); |
| 1177 | 1185 |
_setRowCoeffs(rows(id(r)), ExprIterator(e.comps.begin(), cols), |
| 1178 | 1186 |
ExprIterator(e.comps.end(), cols)); |
| 1179 | 1187 |
_setRowLowerBound(rows(id(r)),l - *e); |
| 1180 | 1188 |
_setRowUpperBound(rows(id(r)),u - *e); |
| 1181 | 1189 |
} |
| 1182 | 1190 |
|
| 1183 | 1191 |
///Set a row (i.e a constraint) of the LP |
| 1184 | 1192 |
|
| 1185 | 1193 |
///\param r is the row to be modified |
| 1186 | 1194 |
///\param c is a linear expression (see \ref Constr) |
| 1187 | 1195 |
void row(Row r, const Constr &c) {
|
| 1188 | 1196 |
row(r, c.lowerBounded()?c.lowerBound():-INF, |
| 1189 | 1197 |
c.expr(), c.upperBounded()?c.upperBound():INF); |
| 1190 | 1198 |
} |
| 1191 | 1199 |
|
| 1192 | 1200 |
|
| 1193 | 1201 |
///Get a row (i.e a constraint) of the LP |
| 1194 | 1202 |
|
| 1195 | 1203 |
///\param r is the row to get |
| 1196 | 1204 |
///\return the expression associated to the row |
| 1197 | 1205 |
Expr row(Row r) const {
|
| 1198 | 1206 |
Expr e; |
| 1199 | 1207 |
_getRowCoeffs(rows(id(r)), InsertIterator(e.comps, cols)); |
| 1200 | 1208 |
return e; |
| 1201 | 1209 |
} |
| 1202 | 1210 |
|
| 1203 | 1211 |
///Add a new row (i.e a new constraint) to the LP |
| 1204 | 1212 |
|
| 1205 | 1213 |
///\param l is the lower bound (-\ref INF means no bound) |
| 1206 | 1214 |
///\param e is a linear expression (see \ref Expr) |
| 1207 | 1215 |
///\param u is the upper bound (\ref INF means no bound) |
| 1208 | 1216 |
///\return The created row. |
| 1209 | 1217 |
Row addRow(Value l,const Expr &e, Value u) {
|
| 1210 |
Row r=addRow(); |
|
| 1211 |
row(r,l,e,u); |
|
| 1218 |
Row r; |
|
| 1219 |
e.simplify(); |
|
| 1220 |
r._id = _addRowId(_addRow(l - *e, ExprIterator(e.comps.begin(), cols), |
|
| 1221 |
ExprIterator(e.comps.end(), cols), u - *e)); |
|
| 1212 | 1222 |
return r; |
| 1213 | 1223 |
} |
| 1214 | 1224 |
|
| 1215 | 1225 |
///Add a new row (i.e a new constraint) to the LP |
| 1216 | 1226 |
|
| 1217 | 1227 |
///\param c is a linear expression (see \ref Constr) |
| 1218 | 1228 |
///\return The created row. |
| 1219 | 1229 |
Row addRow(const Constr &c) {
|
| 1220 |
Row r=addRow(); |
|
| 1221 |
row(r,c); |
|
| 1230 |
Row r; |
|
| 1231 |
c.expr().simplify(); |
|
| 1232 |
r._id = _addRowId(_addRow(c.lowerBounded()?c.lowerBound():-INF, |
|
| 1233 |
ExprIterator(c.expr().comps.begin(), cols), |
|
| 1234 |
ExprIterator(c.expr().comps.end(), cols), |
|
| 1235 |
c.upperBounded()?c.upperBound():INF)); |
|
| 1222 | 1236 |
return r; |
| 1223 | 1237 |
} |
| 1224 | 1238 |
///Erase a column (i.e a variable) from the LP |
| 1225 | 1239 |
|
| 1226 | 1240 |
///\param c is the column to be deleted |
| 1227 | 1241 |
void erase(Col c) {
|
| 1228 | 1242 |
_eraseCol(cols(id(c))); |
| 1229 | 1243 |
_eraseColId(cols(id(c))); |
| 1230 | 1244 |
} |
| 1231 | 1245 |
///Erase a row (i.e a constraint) from the LP |
| 1232 | 1246 |
|
| 1233 | 1247 |
///\param r is the row to be deleted |
| 1234 | 1248 |
void erase(Row r) {
|
| 1235 | 1249 |
_eraseRow(rows(id(r))); |
| 1236 | 1250 |
_eraseRowId(rows(id(r))); |
| 1237 | 1251 |
} |
| 1238 | 1252 |
|
| 1239 | 1253 |
/// Get the name of a column |
| 1240 | 1254 |
|
| 1241 | 1255 |
///\param c is the coresponding column |
| 1242 | 1256 |
///\return The name of the colunm |
| 1243 | 1257 |
std::string colName(Col c) const {
|
| 1244 | 1258 |
std::string name; |
| 1245 | 1259 |
_getColName(cols(id(c)), name); |
| 1246 | 1260 |
return name; |
| 1247 | 1261 |
} |
| 1248 | 1262 |
|
| 1249 | 1263 |
/// Set the name of a column |
| 1250 | 1264 |
|
| 1251 | 1265 |
///\param c is the coresponding column |
| 1252 | 1266 |
///\param name The name to be given |
| 1253 | 1267 |
void colName(Col c, const std::string& name) {
|
| 1254 | 1268 |
_setColName(cols(id(c)), name); |
| 1255 | 1269 |
} |
| 1256 | 1270 |
|
| 1257 | 1271 |
/// Get the column by its name |
| 1258 | 1272 |
|
| 1259 | 1273 |
///\param name The name of the column |
| 1260 | 1274 |
///\return the proper column or \c INVALID |
| 1261 | 1275 |
Col colByName(const std::string& name) const {
|
| 1262 | 1276 |
int k = _colByName(name); |
| 1263 | 1277 |
return k != -1 ? Col(cols[k]) : Col(INVALID); |
| 1264 | 1278 |
} |
| 1265 | 1279 |
|
| 1266 | 1280 |
/// Get the name of a row |
| 1267 | 1281 |
|
| 1268 | 1282 |
///\param r is the coresponding row |
| 1269 | 1283 |
///\return The name of the row |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2008 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 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 <lemon/lp_skeleton.h> |
| 20 | 20 |
|
| 21 | 21 |
///\file |
| 22 | 22 |
///\brief A skeleton file to implement LP solver interfaces |
| 23 | 23 |
namespace lemon {
|
| 24 | 24 |
|
| 25 | 25 |
int SkeletonSolverBase::_addCol() |
| 26 | 26 |
{
|
| 27 | 27 |
return ++col_num; |
| 28 | 28 |
} |
| 29 | 29 |
|
| 30 | 30 |
int SkeletonSolverBase::_addRow() |
| 31 | 31 |
{
|
| 32 | 32 |
return ++row_num; |
| 33 | 33 |
} |
| 34 | 34 |
|
| 35 |
int SkeletonSolverBase::_addRow(Value, ExprIterator, ExprIterator, Value) |
|
| 36 |
{
|
|
| 37 |
return ++row_num; |
|
| 38 |
} |
|
| 39 |
|
|
| 35 | 40 |
void SkeletonSolverBase::_eraseCol(int) {}
|
| 36 | 41 |
void SkeletonSolverBase::_eraseRow(int) {}
|
| 37 | 42 |
|
| 38 | 43 |
void SkeletonSolverBase::_getColName(int, std::string &) const {}
|
| 39 | 44 |
void SkeletonSolverBase::_setColName(int, const std::string &) {}
|
| 40 | 45 |
int SkeletonSolverBase::_colByName(const std::string&) const { return -1; }
|
| 41 | 46 |
|
| 42 | 47 |
void SkeletonSolverBase::_getRowName(int, std::string &) const {}
|
| 43 | 48 |
void SkeletonSolverBase::_setRowName(int, const std::string &) {}
|
| 44 | 49 |
int SkeletonSolverBase::_rowByName(const std::string&) const { return -1; }
|
| 45 | 50 |
|
| 46 | 51 |
void SkeletonSolverBase::_setRowCoeffs(int, ExprIterator, ExprIterator) {}
|
| 47 | 52 |
void SkeletonSolverBase::_getRowCoeffs(int, InsertIterator) const {}
|
| 48 | 53 |
|
| 49 | 54 |
void SkeletonSolverBase::_setColCoeffs(int, ExprIterator, ExprIterator) {}
|
| 50 | 55 |
void SkeletonSolverBase::_getColCoeffs(int, InsertIterator) const {}
|
| 51 | 56 |
|
| 52 | 57 |
void SkeletonSolverBase::_setCoeff(int, int, Value) {}
|
| 53 | 58 |
SkeletonSolverBase::Value SkeletonSolverBase::_getCoeff(int, int) const |
| 54 | 59 |
{ return 0; }
|
| 55 | 60 |
|
| 56 | 61 |
void SkeletonSolverBase::_setColLowerBound(int, Value) {}
|
| 57 | 62 |
SkeletonSolverBase::Value SkeletonSolverBase::_getColLowerBound(int) const |
| 58 | 63 |
{ return 0; }
|
| 59 | 64 |
|
| 60 | 65 |
void SkeletonSolverBase::_setColUpperBound(int, Value) {}
|
| 61 | 66 |
SkeletonSolverBase::Value SkeletonSolverBase::_getColUpperBound(int) const |
| 62 | 67 |
{ return 0; }
|
| 63 | 68 |
|
| 64 | 69 |
void SkeletonSolverBase::_setRowLowerBound(int, Value) {}
|
| 65 | 70 |
SkeletonSolverBase::Value SkeletonSolverBase::_getRowLowerBound(int) const |
| 66 | 71 |
{ return 0; }
|
| 67 | 72 |
|
| 68 | 73 |
void SkeletonSolverBase::_setRowUpperBound(int, Value) {}
|
| 69 | 74 |
SkeletonSolverBase::Value SkeletonSolverBase::_getRowUpperBound(int) const |
| 70 | 75 |
{ return 0; }
|
| 71 | 76 |
|
| 72 | 77 |
void SkeletonSolverBase::_setObjCoeffs(ExprIterator, ExprIterator) {}
|
| 73 | 78 |
void SkeletonSolverBase::_getObjCoeffs(InsertIterator) const {};
|
| 74 | 79 |
|
| 75 | 80 |
void SkeletonSolverBase::_setObjCoeff(int, Value) {}
|
| 76 | 81 |
SkeletonSolverBase::Value SkeletonSolverBase::_getObjCoeff(int) const |
| 77 | 82 |
{ return 0; }
|
| 78 | 83 |
|
| 79 | 84 |
void SkeletonSolverBase::_setSense(Sense) {}
|
| 80 | 85 |
SkeletonSolverBase::Sense SkeletonSolverBase::_getSense() const |
| 81 | 86 |
{ return MIN; }
|
| 82 | 87 |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2008 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 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 |
#ifndef LEMON_LP_SKELETON_H |
| 20 | 20 |
#define LEMON_LP_SKELETON_H |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/lp_base.h> |
| 23 | 23 |
|
| 24 | 24 |
///\file |
| 25 | 25 |
///\brief Skeleton file to implement LP/MIP solver interfaces |
| 26 | 26 |
/// |
| 27 | 27 |
///The classes in this file do nothing, but they can serve as skeletons when |
| 28 | 28 |
///implementing an interface to new solvers. |
| 29 | 29 |
namespace lemon {
|
| 30 | 30 |
|
| 31 | 31 |
///A skeleton class to implement LP/MIP solver base interface |
| 32 | 32 |
|
| 33 | 33 |
///This class does nothing, but it can serve as a skeleton when |
| 34 | 34 |
///implementing an interface to new solvers. |
| 35 | 35 |
class SkeletonSolverBase : public virtual LpBase {
|
| 36 | 36 |
int col_num,row_num; |
| 37 | 37 |
|
| 38 | 38 |
protected: |
| 39 | 39 |
|
| 40 | 40 |
SkeletonSolverBase() |
| 41 | 41 |
: col_num(-1), row_num(-1) {}
|
| 42 | 42 |
|
| 43 | 43 |
/// \e |
| 44 | 44 |
virtual int _addCol(); |
| 45 | 45 |
/// \e |
| 46 | 46 |
virtual int _addRow(); |
| 47 | 47 |
/// \e |
| 48 |
virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u); |
|
| 49 |
/// \e |
|
| 48 | 50 |
virtual void _eraseCol(int i); |
| 49 | 51 |
/// \e |
| 50 | 52 |
virtual void _eraseRow(int i); |
| 51 | 53 |
|
| 52 | 54 |
/// \e |
| 53 | 55 |
virtual void _getColName(int col, std::string& name) const; |
| 54 | 56 |
/// \e |
| 55 | 57 |
virtual void _setColName(int col, const std::string& name); |
| 56 | 58 |
/// \e |
| 57 | 59 |
virtual int _colByName(const std::string& name) const; |
| 58 | 60 |
|
| 59 | 61 |
/// \e |
| 60 | 62 |
virtual void _getRowName(int row, std::string& name) const; |
| 61 | 63 |
/// \e |
| 62 | 64 |
virtual void _setRowName(int row, const std::string& name); |
| 63 | 65 |
/// \e |
| 64 | 66 |
virtual int _rowByName(const std::string& name) const; |
| 65 | 67 |
|
| 66 | 68 |
/// \e |
| 67 | 69 |
virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e); |
| 68 | 70 |
/// \e |
| 69 | 71 |
virtual void _getRowCoeffs(int i, InsertIterator b) const; |
| 70 | 72 |
/// \e |
| 71 | 73 |
virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e); |
| 72 | 74 |
/// \e |
| 73 | 75 |
virtual void _getColCoeffs(int i, InsertIterator b) const; |
| 74 | 76 |
|
| 75 | 77 |
/// Set one element of the coefficient matrix |
| 76 | 78 |
virtual void _setCoeff(int row, int col, Value value); |
| 77 | 79 |
|
| 78 | 80 |
/// Get one element of the coefficient matrix |
| 79 | 81 |
virtual Value _getCoeff(int row, int col) const; |
| 80 | 82 |
|
| 81 | 83 |
/// The lower bound of a variable (column) have to be given by an |
| 82 | 84 |
/// extended number of type Value, i.e. a finite number of type |
| 83 | 85 |
/// Value or -\ref INF. |
| 84 | 86 |
virtual void _setColLowerBound(int i, Value value); |
| 85 | 87 |
/// \e |
| 86 | 88 |
|
| 87 | 89 |
/// The lower bound of a variable (column) is an |
| 88 | 90 |
/// extended number of type Value, i.e. a finite number of type |
| 89 | 91 |
/// Value or -\ref INF. |
| 90 | 92 |
virtual Value _getColLowerBound(int i) const; |
| 91 | 93 |
|
| 92 | 94 |
/// The upper bound of a variable (column) have to be given by an |
| 93 | 95 |
/// extended number of type Value, i.e. a finite number of type |
| 94 | 96 |
/// Value or \ref INF. |
| 95 | 97 |
virtual void _setColUpperBound(int i, Value value); |
| ... | ... |
@@ -46,96 +46,109 @@ |
| 46 | 46 |
_col_names = lp._col_names; |
| 47 | 47 |
_col_names_ref = lp._col_names_ref; |
| 48 | 48 |
|
| 49 | 49 |
_row_names = lp._row_names; |
| 50 | 50 |
_row_names_ref = lp._row_names_ref; |
| 51 | 51 |
|
| 52 | 52 |
messageLevel(MESSAGE_NOTHING); |
| 53 | 53 |
} |
| 54 | 54 |
|
| 55 | 55 |
void SoplexLp::_clear_temporals() {
|
| 56 | 56 |
_primal_values.clear(); |
| 57 | 57 |
_dual_values.clear(); |
| 58 | 58 |
} |
| 59 | 59 |
|
| 60 | 60 |
SoplexLp* SoplexLp::newSolver() const {
|
| 61 | 61 |
SoplexLp* newlp = new SoplexLp(); |
| 62 | 62 |
return newlp; |
| 63 | 63 |
} |
| 64 | 64 |
|
| 65 | 65 |
SoplexLp* SoplexLp::cloneSolver() const {
|
| 66 | 66 |
SoplexLp* newlp = new SoplexLp(*this); |
| 67 | 67 |
return newlp; |
| 68 | 68 |
} |
| 69 | 69 |
|
| 70 | 70 |
const char* SoplexLp::_solverName() const { return "SoplexLp"; }
|
| 71 | 71 |
|
| 72 | 72 |
int SoplexLp::_addCol() {
|
| 73 | 73 |
soplex::LPCol c; |
| 74 | 74 |
c.setLower(-soplex::infinity); |
| 75 | 75 |
c.setUpper(soplex::infinity); |
| 76 | 76 |
soplex->addCol(c); |
| 77 | 77 |
|
| 78 | 78 |
_col_names.push_back(std::string()); |
| 79 | 79 |
|
| 80 | 80 |
return soplex->nCols() - 1; |
| 81 | 81 |
} |
| 82 | 82 |
|
| 83 | 83 |
int SoplexLp::_addRow() {
|
| 84 | 84 |
soplex::LPRow r; |
| 85 | 85 |
r.setLhs(-soplex::infinity); |
| 86 | 86 |
r.setRhs(soplex::infinity); |
| 87 | 87 |
soplex->addRow(r); |
| 88 | 88 |
|
| 89 | 89 |
_row_names.push_back(std::string()); |
| 90 | 90 |
|
| 91 | 91 |
return soplex->nRows() - 1; |
| 92 | 92 |
} |
| 93 | 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 |
|
|
| 94 | 107 |
|
| 95 | 108 |
void SoplexLp::_eraseCol(int i) {
|
| 96 | 109 |
soplex->removeCol(i); |
| 97 | 110 |
_col_names_ref.erase(_col_names[i]); |
| 98 | 111 |
_col_names[i] = _col_names.back(); |
| 99 | 112 |
_col_names_ref[_col_names.back()] = i; |
| 100 | 113 |
_col_names.pop_back(); |
| 101 | 114 |
} |
| 102 | 115 |
|
| 103 | 116 |
void SoplexLp::_eraseRow(int i) {
|
| 104 | 117 |
soplex->removeRow(i); |
| 105 | 118 |
_row_names_ref.erase(_row_names[i]); |
| 106 | 119 |
_row_names[i] = _row_names.back(); |
| 107 | 120 |
_row_names_ref[_row_names.back()] = i; |
| 108 | 121 |
_row_names.pop_back(); |
| 109 | 122 |
} |
| 110 | 123 |
|
| 111 | 124 |
void SoplexLp::_eraseColId(int i) {
|
| 112 | 125 |
cols.eraseIndex(i); |
| 113 | 126 |
cols.relocateIndex(i, cols.maxIndex()); |
| 114 | 127 |
} |
| 115 | 128 |
void SoplexLp::_eraseRowId(int i) {
|
| 116 | 129 |
rows.eraseIndex(i); |
| 117 | 130 |
rows.relocateIndex(i, rows.maxIndex()); |
| 118 | 131 |
} |
| 119 | 132 |
|
| 120 | 133 |
void SoplexLp::_getColName(int c, std::string &name) const {
|
| 121 | 134 |
name = _col_names[c]; |
| 122 | 135 |
} |
| 123 | 136 |
|
| 124 | 137 |
void SoplexLp::_setColName(int c, const std::string &name) {
|
| 125 | 138 |
_col_names_ref.erase(_col_names[c]); |
| 126 | 139 |
_col_names[c] = name; |
| 127 | 140 |
if (!name.empty()) {
|
| 128 | 141 |
_col_names_ref.insert(std::make_pair(name, c)); |
| 129 | 142 |
} |
| 130 | 143 |
} |
| 131 | 144 |
|
| 132 | 145 |
int SoplexLp::_colByName(const std::string& name) const {
|
| 133 | 146 |
std::map<std::string, int>::const_iterator it = |
| 134 | 147 |
_col_names_ref.find(name); |
| 135 | 148 |
if (it != _col_names_ref.end()) {
|
| 136 | 149 |
return it->second; |
| 137 | 150 |
} else {
|
| 138 | 151 |
return -1; |
| 139 | 152 |
} |
| 140 | 153 |
} |
| 141 | 154 |
| ... | ... |
@@ -39,96 +39,97 @@ |
| 39 | 39 |
/// \brief Interface for the SOPLEX solver |
| 40 | 40 |
/// |
| 41 | 41 |
/// This class implements an interface for the SoPlex LP solver. |
| 42 | 42 |
/// The SoPlex library is an object oriented lp solver library |
| 43 | 43 |
/// developed at the Konrad-Zuse-Zentrum f�r Informationstechnik |
| 44 | 44 |
/// Berlin (ZIB). You can find detailed information about it at the |
| 45 | 45 |
/// <tt>http://soplex.zib.de</tt> address. |
| 46 | 46 |
class SoplexLp : public LpSolver {
|
| 47 | 47 |
private: |
| 48 | 48 |
|
| 49 | 49 |
soplex::SoPlex* soplex; |
| 50 | 50 |
|
| 51 | 51 |
std::vector<std::string> _col_names; |
| 52 | 52 |
std::map<std::string, int> _col_names_ref; |
| 53 | 53 |
|
| 54 | 54 |
std::vector<std::string> _row_names; |
| 55 | 55 |
std::map<std::string, int> _row_names_ref; |
| 56 | 56 |
|
| 57 | 57 |
private: |
| 58 | 58 |
|
| 59 | 59 |
// these values cannot be retrieved element by element |
| 60 | 60 |
mutable std::vector<Value> _primal_values; |
| 61 | 61 |
mutable std::vector<Value> _dual_values; |
| 62 | 62 |
|
| 63 | 63 |
mutable std::vector<Value> _primal_ray; |
| 64 | 64 |
mutable std::vector<Value> _dual_ray; |
| 65 | 65 |
|
| 66 | 66 |
void _clear_temporals(); |
| 67 | 67 |
|
| 68 | 68 |
public: |
| 69 | 69 |
|
| 70 | 70 |
/// \e |
| 71 | 71 |
SoplexLp(); |
| 72 | 72 |
/// \e |
| 73 | 73 |
SoplexLp(const SoplexLp&); |
| 74 | 74 |
/// \e |
| 75 | 75 |
~SoplexLp(); |
| 76 | 76 |
/// \e |
| 77 | 77 |
virtual SoplexLp* newSolver() const; |
| 78 | 78 |
/// \e |
| 79 | 79 |
virtual SoplexLp* cloneSolver() const; |
| 80 | 80 |
|
| 81 | 81 |
protected: |
| 82 | 82 |
|
| 83 | 83 |
virtual const char* _solverName() const; |
| 84 | 84 |
|
| 85 | 85 |
virtual int _addCol(); |
| 86 | 86 |
virtual int _addRow(); |
| 87 |
virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u); |
|
| 87 | 88 |
|
| 88 | 89 |
virtual void _eraseCol(int i); |
| 89 | 90 |
virtual void _eraseRow(int i); |
| 90 | 91 |
|
| 91 | 92 |
virtual void _eraseColId(int i); |
| 92 | 93 |
virtual void _eraseRowId(int i); |
| 93 | 94 |
|
| 94 | 95 |
virtual void _getColName(int col, std::string& name) const; |
| 95 | 96 |
virtual void _setColName(int col, const std::string& name); |
| 96 | 97 |
virtual int _colByName(const std::string& name) const; |
| 97 | 98 |
|
| 98 | 99 |
virtual void _getRowName(int row, std::string& name) const; |
| 99 | 100 |
virtual void _setRowName(int row, const std::string& name); |
| 100 | 101 |
virtual int _rowByName(const std::string& name) const; |
| 101 | 102 |
|
| 102 | 103 |
virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e); |
| 103 | 104 |
virtual void _getRowCoeffs(int i, InsertIterator b) const; |
| 104 | 105 |
|
| 105 | 106 |
virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e); |
| 106 | 107 |
virtual void _getColCoeffs(int i, InsertIterator b) const; |
| 107 | 108 |
|
| 108 | 109 |
virtual void _setCoeff(int row, int col, Value value); |
| 109 | 110 |
virtual Value _getCoeff(int row, int col) const; |
| 110 | 111 |
|
| 111 | 112 |
virtual void _setColLowerBound(int i, Value value); |
| 112 | 113 |
virtual Value _getColLowerBound(int i) const; |
| 113 | 114 |
virtual void _setColUpperBound(int i, Value value); |
| 114 | 115 |
virtual Value _getColUpperBound(int i) const; |
| 115 | 116 |
|
| 116 | 117 |
virtual void _setRowLowerBound(int i, Value value); |
| 117 | 118 |
virtual Value _getRowLowerBound(int i) const; |
| 118 | 119 |
virtual void _setRowUpperBound(int i, Value value); |
| 119 | 120 |
virtual Value _getRowUpperBound(int i) const; |
| 120 | 121 |
|
| 121 | 122 |
virtual void _setObjCoeffs(ExprIterator b, ExprIterator e); |
| 122 | 123 |
virtual void _getObjCoeffs(InsertIterator b) const; |
| 123 | 124 |
|
| 124 | 125 |
virtual void _setObjCoeff(int i, Value obj_coef); |
| 125 | 126 |
virtual Value _getObjCoeff(int i) const; |
| 126 | 127 |
|
| 127 | 128 |
virtual void _setSense(Sense sense); |
| 128 | 129 |
virtual Sense _getSense() const; |
| 129 | 130 |
|
| 130 | 131 |
virtual SolveExitStatus _solve(); |
| 131 | 132 |
virtual Value _getPrimal(int i) const; |
| 132 | 133 |
virtual Value _getDual(int i) const; |
| 133 | 134 |
|
| 134 | 135 |
virtual Value _getPrimalValue() const; |
0 comments (0 inline)