0
13
0
| ... | ... |
@@ -73,48 +73,60 @@ |
| 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 |
} |
| ... | ... |
@@ -41,48 +41,49 @@ |
| 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 |
| ... | ... |
@@ -57,48 +57,61 @@ |
| 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 |
} |
| ... | ... |
@@ -54,48 +54,49 @@ |
| 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 |
| ... | ... |
@@ -90,48 +90,81 @@ |
| 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; |
| ... | ... |
@@ -72,48 +72,49 @@ |
| 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 |
| ... | ... |
@@ -38,48 +38,84 @@ |
| 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); |
| ... | ... |
@@ -33,48 +33,49 @@ |
| 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 |
| ... | ... |
@@ -922,48 +922,56 @@ |
| 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; |
| ... | ... |
@@ -1186,60 +1194,66 @@ |
| 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); |
| ... | ... |
@@ -11,48 +11,53 @@ |
| 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; }
|
| ... | ... |
@@ -24,48 +24,50 @@ |
| 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); |
| ... | ... |
@@ -70,48 +70,61 @@ |
| 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()); |
| ... | ... |
@@ -63,48 +63,49 @@ |
| 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 |
|
0 comments (0 inline)