1.1 --- a/src/work/athos/lp/lp_solver_base.h Tue Mar 22 11:45:47 2005 +0000
1.2 +++ b/src/work/athos/lp/lp_solver_base.h Tue Mar 22 12:02:29 2005 +0000
1.3 @@ -12,9 +12,6 @@
1.4 #include <limits>
1.5 // #include <stdio>
1.6 //#include <stdlib>
1.7 -extern "C" {
1.8 -#include "glpk.h"
1.9 -}
1.10
1.11 #include <iostream>
1.12 #include <vector>
1.13 @@ -199,7 +196,7 @@
1.14 \nosubgrouping
1.15 */
1.16 template <typename _Value>
1.17 - class LPSolverBase {
1.18 + class LpSolverBase {
1.19
1.20 /*! @name Uncategorized functions and types (public members)
1.21 */
1.22 @@ -232,14 +229,14 @@
1.23 /// \e
1.24 const int INVALID_CLASS;
1.25 /// \e
1.26 - static const _Value INF;
1.27 + static const Value INF;
1.28 public:
1.29 /// \e
1.30 - LPSolverBase() : row_iter_map(2),
1.31 + LpSolverBase() : row_iter_map(2),
1.32 col_iter_map(2),
1.33 VALID_CLASS(0), INVALID_CLASS(1) { }
1.34 /// \e
1.35 - virtual ~LPSolverBase() { }
1.36 + virtual ~LpSolverBase() { }
1.37 //@}
1.38
1.39 /*! @name Medium level interface (public members)
1.40 @@ -272,7 +269,7 @@
1.41 //SOLUTION RETRIEVING
1.42
1.43 /// \e
1.44 - virtual _Value getObjVal() = 0;
1.45 + virtual Value getObjVal() = 0;
1.46
1.47 //OTHER FUNCTIONS
1.48
1.49 @@ -321,75 +318,75 @@
1.50 virtual void _eraseRow(int i) = 0;
1.51 /// \e
1.52 virtual void _setRowCoeffs(int i,
1.53 - const std::vector<std::pair<int, _Value> >& coeffs) = 0;
1.54 + const std::vector<std::pair<int, Value> >& coeffs) = 0;
1.55 /// \e
1.56 /// This routine modifies \c coeffs only by the \c push_back method.
1.57 virtual void _getRowCoeffs(int i,
1.58 - std::vector<std::pair<int, _Value> >& coeffs) = 0;
1.59 + std::vector<std::pair<int, Value> >& coeffs) = 0;
1.60 /// \e
1.61 virtual void _setColCoeffs(int i,
1.62 - const std::vector<std::pair<int, _Value> >& coeffs) = 0;
1.63 + const std::vector<std::pair<int, Value> >& coeffs) = 0;
1.64 /// \e
1.65 /// This routine modifies \c coeffs only by the \c push_back method.
1.66 virtual void _getColCoeffs(int i,
1.67 - std::vector<std::pair<int, _Value> >& coeffs) = 0;
1.68 + std::vector<std::pair<int, Value> >& coeffs) = 0;
1.69 /// \e
1.70 - virtual void _setCoeff(int col, int row, _Value value) = 0;
1.71 + virtual void _setCoeff(int col, int row, Value value) = 0;
1.72 /// \e
1.73 - virtual _Value _getCoeff(int col, int row) = 0;
1.74 + virtual Value _getCoeff(int col, int row) = 0;
1.75 // public:
1.76 // /// \e
1.77 // enum Bound { FREE, LOWER, UPPER, DOUBLE, FIXED };
1.78 protected:
1.79 /// \e
1.80 /// The lower bound of a variable (column) have to be given by an
1.81 - /// extended number of type _Value, i.e. a finite number of type
1.82 - /// _Value or -INF.
1.83 - virtual void _setColLowerBound(int i, _Value value) = 0;
1.84 + /// extended number of type Value, i.e. a finite number of type
1.85 + /// Value or -INF.
1.86 + virtual void _setColLowerBound(int i, Value value) = 0;
1.87 /// \e
1.88 /// The lower bound of a variable (column) is an
1.89 - /// extended number of type _Value, i.e. a finite number of type
1.90 - /// _Value or -INF.
1.91 - virtual _Value _getColLowerBound(int i) = 0;
1.92 + /// extended number of type Value, i.e. a finite number of type
1.93 + /// Value or -INF.
1.94 + virtual Value _getColLowerBound(int i) = 0;
1.95 /// \e
1.96 /// The upper bound of a variable (column) have to be given by an
1.97 - /// extended number of type _Value, i.e. a finite number of type
1.98 - /// _Value or INF.
1.99 - virtual void _setColUpperBound(int i, _Value value) = 0;
1.100 + /// extended number of type Value, i.e. a finite number of type
1.101 + /// Value or INF.
1.102 + virtual void _setColUpperBound(int i, Value value) = 0;
1.103 /// \e
1.104 /// The upper bound of a variable (column) is an
1.105 - /// extended number of type _Value, i.e. a finite number of type
1.106 - /// _Value or INF.
1.107 - virtual _Value _getColUpperBound(int i) = 0;
1.108 + /// extended number of type Value, i.e. a finite number of type
1.109 + /// Value or INF.
1.110 + virtual Value _getColUpperBound(int i) = 0;
1.111 /// \e
1.112 /// The lower bound of a linear expression (row) have to be given by an
1.113 - /// extended number of type _Value, i.e. a finite number of type
1.114 - /// _Value or -INF.
1.115 - virtual void _setRowLowerBound(int i, _Value value) = 0;
1.116 + /// extended number of type Value, i.e. a finite number of type
1.117 + /// Value or -INF.
1.118 + virtual void _setRowLowerBound(int i, Value value) = 0;
1.119 /// \e
1.120 /// The lower bound of a linear expression (row) is an
1.121 - /// extended number of type _Value, i.e. a finite number of type
1.122 - /// _Value or -INF.
1.123 - virtual _Value _getRowLowerBound(int i) = 0;
1.124 + /// extended number of type Value, i.e. a finite number of type
1.125 + /// Value or -INF.
1.126 + virtual Value _getRowLowerBound(int i) = 0;
1.127 /// \e
1.128 /// The upper bound of a linear expression (row) have to be given by an
1.129 - /// extended number of type _Value, i.e. a finite number of type
1.130 - /// _Value or INF.
1.131 - virtual void _setRowUpperBound(int i, _Value value) = 0;
1.132 + /// extended number of type Value, i.e. a finite number of type
1.133 + /// Value or INF.
1.134 + virtual void _setRowUpperBound(int i, Value value) = 0;
1.135 /// \e
1.136 /// The upper bound of a linear expression (row) is an
1.137 - /// extended number of type _Value, i.e. a finite number of type
1.138 - /// _Value or INF.
1.139 - virtual _Value _getRowUpperBound(int i) = 0;
1.140 + /// extended number of type Value, i.e. a finite number of type
1.141 + /// Value or INF.
1.142 + virtual Value _getRowUpperBound(int i) = 0;
1.143 /// \e
1.144 - virtual void _setObjCoeff(int i, _Value obj_coef) = 0;
1.145 + virtual void _setObjCoeff(int i, Value obj_coef) = 0;
1.146 /// \e
1.147 - virtual _Value _getObjCoeff(int i) = 0;
1.148 + virtual Value _getObjCoeff(int i) = 0;
1.149
1.150 //SOLUTION RETRIEVING
1.151
1.152 /// \e
1.153 - virtual _Value _getPrimal(int i) = 0;
1.154 + virtual Value _getPrimal(int i) = 0;
1.155 //@}
1.156
1.157 /*! @name High level interface (public members)
1.158 @@ -457,58 +454,58 @@
1.159 int_row_map.erase(int_row_map.begin()+rows[1]);
1.160 }
1.161 /// \e
1.162 - void setCoeff(Col col, Row row, _Value value) {
1.163 + void setCoeff(Col col, Row row, Value value) {
1.164 _setCoeff(col_iter_map[col], row_iter_map[row], value);
1.165 }
1.166 /// \e
1.167 - _Value getCoeff(Col col, Row row) {
1.168 + Value getCoeff(Col col, Row row) {
1.169 return _getCoeff(col_iter_map[col], row_iter_map[row], value);
1.170 }
1.171 /// \e
1.172 - void setColLowerBound(Col col, _Value lo) {
1.173 + void setColLowerBound(Col col, Value lo) {
1.174 _setColLowerBound(col_iter_map[col], lo);
1.175 }
1.176 /// \e
1.177 - _Value getColLowerBound(Col col) {
1.178 + Value getColLowerBound(Col col) {
1.179 return _getColLowerBound(col_iter_map[col]);
1.180 }
1.181 /// \e
1.182 - void setColUpperBound(Col col, _Value up) {
1.183 + void setColUpperBound(Col col, Value up) {
1.184 _setColUpperBound(col_iter_map[col], up);
1.185 }
1.186 /// \e
1.187 - _Value getColUpperBound(Col col) {
1.188 + Value getColUpperBound(Col col) {
1.189 return _getColUpperBound(col_iter_map[col]);
1.190 }
1.191 /// \e
1.192 - void setRowLowerBound(Row row, _Value lo) {
1.193 + void setRowLowerBound(Row row, Value lo) {
1.194 _setRowLowerBound(row_iter_map[row], lo);
1.195 }
1.196 /// \e
1.197 - _Value getRowLowerBound(Row row) {
1.198 + Value getRowLowerBound(Row row) {
1.199 return _getRowLowerBound(row_iter_map[row]);
1.200 }
1.201 /// \e
1.202 - void setRowUpperBound(Row row, _Value up) {
1.203 + void setRowUpperBound(Row row, Value up) {
1.204 _setRowUpperBound(row_iter_map[row], up);
1.205 }
1.206 /// \e
1.207 - _Value getRowUpperBound(Row row) {
1.208 + Value getRowUpperBound(Row row) {
1.209 return _getRowUpperBound(row_iter_map[row]);
1.210 }
1.211 /// \e
1.212 - void setObjCoeff(const Col& col, _Value obj_coef) {
1.213 + void setObjCoeff(const Col& col, Value obj_coef) {
1.214 _setObjCoeff(col_iter_map[col], obj_coef);
1.215 }
1.216 /// \e
1.217 - _Value getObjCoeff(const Col& col) {
1.218 + Value getObjCoeff(const Col& col) {
1.219 return _getObjCoeff(col_iter_map[col]);
1.220 }
1.221
1.222 //SOLUTION RETRIEVING FUNCTIONS
1.223
1.224 /// \e
1.225 - _Value getPrimal(const Col& col) {
1.226 + Value getPrimal(const Col& col) {
1.227 return _getPrimal(col_iter_map[col]);
1.228 }
1.229
1.230 @@ -522,17 +519,17 @@
1.231 //EXPRESSION TYPES
1.232
1.233 /// \e
1.234 - typedef Expr<Col, _Value> Expression;
1.235 + typedef Expr<Col, Value> Expression;
1.236 /// \e
1.237 - typedef Expr<Row, _Value> DualExpression;
1.238 + typedef Expr<Row, Value> DualExpression;
1.239 /// \e
1.240 - typedef Constr<Col, _Value> Constraint;
1.241 + typedef Constr<Col, Value> Constraint;
1.242
1.243 //MATRIX MANIPULATING FUNCTIONS
1.244
1.245 /// \e
1.246 void setRowCoeffs(Row row, const Expression& expr) {
1.247 - std::vector<std::pair<int, _Value> > row_coeffs;
1.248 + std::vector<std::pair<int, Value> > row_coeffs;
1.249 for(typename Expression::Data::const_iterator i=expr.data.begin();
1.250 i!=expr.data.end(); ++i) {
1.251 row_coeffs.push_back(std::make_pair
1.252 @@ -557,16 +554,16 @@
1.253 /// \e
1.254 /// This routine modifies \c expr by only adding to it.
1.255 void getRowCoeffs(Row row, Expression& expr) {
1.256 - std::vector<std::pair<int, _Value> > row_coeffs;
1.257 + std::vector<std::pair<int, Value> > row_coeffs;
1.258 _getRowCoeffs(row_iter_map[row], row_coeffs);
1.259 - for(typename std::vector<std::pair<int, _Value> >::const_iterator
1.260 + for(typename std::vector<std::pair<int, Value> >::const_iterator
1.261 i=row_coeffs.begin(); i!=row_coeffs.end(); ++i) {
1.262 expr+= (*i).second*int_col_map[(*i).first];
1.263 }
1.264 }
1.265 /// \e
1.266 void setColCoeffs(Col col, const DualExpression& expr) {
1.267 - std::vector<std::pair<int, _Value> > col_coeffs;
1.268 + std::vector<std::pair<int, Value> > col_coeffs;
1.269 for(typename DualExpression::Data::const_iterator i=expr.data.begin();
1.270 i!=expr.data.end(); ++i) {
1.271 col_coeffs.push_back(std::make_pair
1.272 @@ -577,9 +574,9 @@
1.273 /// \e
1.274 /// This routine modifies \c expr by only adding to it.
1.275 void getColCoeffs(Col col, DualExpression& expr) {
1.276 - std::vector<std::pair<int, _Value> > col_coeffs;
1.277 + std::vector<std::pair<int, Value> > col_coeffs;
1.278 _getColCoeffs(col_iter_map[col], col_coeffs);
1.279 - for(typename std::vector<std::pair<int, _Value> >::const_iterator
1.280 + for(typename std::vector<std::pair<int, Value> >::const_iterator
1.281 i=col_coeffs.begin(); i!=col_coeffs.end(); ++i) {
1.282 expr+= (*i).second*int_row_map[(*i).first];
1.283 }
1.284 @@ -620,7 +617,7 @@
1.285 /// \e
1.286 virtual void _setColInt(int i) = 0;
1.287 /// \e
1.288 - virtual _Value _getMIPPrimal(int i) = 0;
1.289 + virtual Value _getMIPPrimal(int i) = 0;
1.290 public:
1.291 /// \e
1.292 void setColCont(Col col) {
1.293 @@ -631,485 +628,11 @@
1.294 _setColInt(col_iter_map[col]);
1.295 }
1.296 /// \e
1.297 - _Value getMIPPrimal(Col col) {
1.298 + Value getMIPPrimal(Col col) {
1.299 return _getMIPPrimal(col_iter_map[col]);
1.300 }
1.301 //@}
1.302 };
1.303 -
1.304 - template <typename _Value>
1.305 - const _Value LPSolverBase<_Value>::INF=std::numeric_limits<_Value>::infinity();
1.306 -
1.307 -
1.308 - /// \brief Wrapper for GLPK solver
1.309 - ///
1.310 - /// This class implements a lemon wrapper for GLPK.
1.311 - class LPGLPK : public LPSolverBase<double> {
1.312 - public:
1.313 - typedef LPSolverBase<double> Parent;
1.314 -
1.315 - public:
1.316 - /// \e
1.317 - LPX* lp;
1.318 -
1.319 - public:
1.320 - /// \e
1.321 - LPGLPK() : Parent(),
1.322 - lp(lpx_create_prob()) {
1.323 - int_row_map.push_back(Row());
1.324 - int_col_map.push_back(Col());
1.325 - lpx_set_int_parm(lp, LPX_K_DUAL, 1);
1.326 - }
1.327 - /// \e
1.328 - ~LPGLPK() {
1.329 - lpx_delete_prob(lp);
1.330 - }
1.331 -
1.332 - //MATRIX INDEPEDENT MANIPULATING FUNCTIONS
1.333 -
1.334 - /// \e
1.335 - void setMinimize() {
1.336 - lpx_set_obj_dir(lp, LPX_MIN);
1.337 - }
1.338 - /// \e
1.339 - void setMaximize() {
1.340 - lpx_set_obj_dir(lp, LPX_MAX);
1.341 - }
1.342 -
1.343 - //LOW LEVEL INTERFACE, MATRIX MANIPULATING FUNCTIONS
1.344 -
1.345 - protected:
1.346 - /// \e
1.347 - int _addCol() {
1.348 - int i=lpx_add_cols(lp, 1);
1.349 - _setColLowerBound(i, -INF);
1.350 - _setColUpperBound(i, INF);
1.351 - return i;
1.352 - }
1.353 - /// \e
1.354 - int _addRow() {
1.355 - int i=lpx_add_rows(lp, 1);
1.356 - return i;
1.357 - }
1.358 - /// \e
1.359 - virtual void _setRowCoeffs(int i,
1.360 - const std::vector<std::pair<int, double> >& coeffs) {
1.361 - int mem_length=1+colNum();
1.362 - int* indices = new int[mem_length];
1.363 - double* doubles = new double[mem_length];
1.364 - int length=0;
1.365 - for (std::vector<std::pair<int, double> >::
1.366 - const_iterator it=coeffs.begin(); it!=coeffs.end(); ++it) {
1.367 - ++length;
1.368 - indices[length]=it->first;
1.369 - doubles[length]=it->second;
1.370 - }
1.371 - lpx_set_mat_row(lp, i, length, indices, doubles);
1.372 - delete [] indices;
1.373 - delete [] doubles;
1.374 - }
1.375 - /// \e
1.376 - virtual void _getRowCoeffs(int i,
1.377 - std::vector<std::pair<int, double> >& coeffs) {
1.378 - int mem_length=1+colNum();
1.379 - int* indices = new int[mem_length];
1.380 - double* doubles = new double[mem_length];
1.381 - int length=lpx_get_mat_row(lp, i, indices, doubles);
1.382 - for (int i=1; i<=length; ++i) {
1.383 - coeffs.push_back(std::make_pair(indices[i], doubles[i]));
1.384 - }
1.385 - delete [] indices;
1.386 - delete [] doubles;
1.387 - }
1.388 - /// \e
1.389 - virtual void _setColCoeffs(int i,
1.390 - const std::vector<std::pair<int, double> >& coeffs) {
1.391 - int mem_length=1+rowNum();
1.392 - int* indices = new int[mem_length];
1.393 - double* doubles = new double[mem_length];
1.394 - int length=0;
1.395 - for (std::vector<std::pair<int, double> >::
1.396 - const_iterator it=coeffs.begin(); it!=coeffs.end(); ++it) {
1.397 - ++length;
1.398 - indices[length]=it->first;
1.399 - doubles[length]=it->second;
1.400 - }
1.401 - lpx_set_mat_col(lp, i, length, indices, doubles);
1.402 - delete [] indices;
1.403 - delete [] doubles;
1.404 - }
1.405 - /// \e
1.406 - virtual void _getColCoeffs(int i,
1.407 - std::vector<std::pair<int, double> >& coeffs) {
1.408 - int mem_length=1+rowNum();
1.409 - int* indices = new int[mem_length];
1.410 - double* doubles = new double[mem_length];
1.411 - int length=lpx_get_mat_col(lp, i, indices, doubles);
1.412 - for (int i=1; i<=length; ++i) {
1.413 - coeffs.push_back(std::make_pair(indices[i], doubles[i]));
1.414 - }
1.415 - delete [] indices;
1.416 - delete [] doubles;
1.417 - }
1.418 - /// \e
1.419 - virtual void _eraseCol(int i) {
1.420 - int cols[2];
1.421 - cols[1]=i;
1.422 - lpx_del_cols(lp, 1, cols);
1.423 - }
1.424 - virtual void _eraseRow(int i) {
1.425 - int rows[2];
1.426 - rows[1]=i;
1.427 - lpx_del_rows(lp, 1, rows);
1.428 - }
1.429 - void _setCoeff(int col, int row, double value) {
1.430 - /// FIXME not yet implemented
1.431 - }
1.432 - double _getCoeff(int col, int row) {
1.433 - /// FIXME not yet implemented
1.434 - return 0.0;
1.435 - }
1.436 - virtual void _setColLowerBound(int i, double lo) {
1.437 - if (lo==INF) {
1.438 - //FIXME error
1.439 - }
1.440 - int b=lpx_get_col_type(lp, i);
1.441 - double up=lpx_get_col_ub(lp, i);
1.442 - if (lo==-INF) {
1.443 - switch (b) {
1.444 - case LPX_FR:
1.445 - case LPX_LO:
1.446 - lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
1.447 - break;
1.448 - case LPX_UP:
1.449 - break;
1.450 - case LPX_DB:
1.451 - case LPX_FX:
1.452 - lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
1.453 - break;
1.454 - default: ;
1.455 - //FIXME error
1.456 - }
1.457 - } else {
1.458 - switch (b) {
1.459 - case LPX_FR:
1.460 - case LPX_LO:
1.461 - lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
1.462 - break;
1.463 - case LPX_UP:
1.464 - case LPX_DB:
1.465 - case LPX_FX:
1.466 - if (lo==up)
1.467 - lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
1.468 - else
1.469 - lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
1.470 - break;
1.471 - default: ;
1.472 - //FIXME error
1.473 - }
1.474 - }
1.475 - }
1.476 - virtual double _getColLowerBound(int i) {
1.477 - int b=lpx_get_col_type(lp, i);
1.478 - switch (b) {
1.479 - case LPX_FR:
1.480 - return -INF;
1.481 - case LPX_LO:
1.482 - return lpx_get_col_lb(lp, i);
1.483 - case LPX_UP:
1.484 - return -INF;
1.485 - case LPX_DB:
1.486 - case LPX_FX:
1.487 - return lpx_get_col_lb(lp, i);
1.488 - default: ;
1.489 - //FIXME error
1.490 - return 0.0;
1.491 - }
1.492 - }
1.493 - virtual void _setColUpperBound(int i, double up) {
1.494 - if (up==-INF) {
1.495 - //FIXME error
1.496 - }
1.497 - int b=lpx_get_col_type(lp, i);
1.498 - double lo=lpx_get_col_lb(lp, i);
1.499 - if (up==INF) {
1.500 - switch (b) {
1.501 - case LPX_FR:
1.502 - case LPX_LO:
1.503 - break;
1.504 - case LPX_UP:
1.505 - lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
1.506 - break;
1.507 - case LPX_DB:
1.508 - case LPX_FX:
1.509 - lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
1.510 - break;
1.511 - default: ;
1.512 - //FIXME error
1.513 - }
1.514 - } else {
1.515 - switch (b) {
1.516 - case LPX_FR:
1.517 - lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
1.518 - case LPX_LO:
1.519 - if (lo==up)
1.520 - lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
1.521 - else
1.522 - lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
1.523 - break;
1.524 - case LPX_UP:
1.525 - lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
1.526 - break;
1.527 - case LPX_DB:
1.528 - case LPX_FX:
1.529 - if (lo==up)
1.530 - lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
1.531 - else
1.532 - lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
1.533 - break;
1.534 - default: ;
1.535 - //FIXME error
1.536 - }
1.537 - }
1.538 - }
1.539 - virtual double _getColUpperBound(int i) {
1.540 - int b=lpx_get_col_type(lp, i);
1.541 - switch (b) {
1.542 - case LPX_FR:
1.543 - case LPX_LO:
1.544 - return INF;
1.545 - case LPX_UP:
1.546 - case LPX_DB:
1.547 - case LPX_FX:
1.548 - return lpx_get_col_ub(lp, i);
1.549 - default: ;
1.550 - //FIXME error
1.551 - return 0.0;
1.552 - }
1.553 - }
1.554 - virtual void _setRowLowerBound(int i, double lo) {
1.555 - if (lo==INF) {
1.556 - //FIXME error
1.557 - }
1.558 - int b=lpx_get_row_type(lp, i);
1.559 - double up=lpx_get_row_ub(lp, i);
1.560 - if (lo==-INF) {
1.561 - switch (b) {
1.562 - case LPX_FR:
1.563 - case LPX_LO:
1.564 - lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
1.565 - break;
1.566 - case LPX_UP:
1.567 - break;
1.568 - case LPX_DB:
1.569 - case LPX_FX:
1.570 - lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
1.571 - break;
1.572 - default: ;
1.573 - //FIXME error
1.574 - }
1.575 - } else {
1.576 - switch (b) {
1.577 - case LPX_FR:
1.578 - case LPX_LO:
1.579 - lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
1.580 - break;
1.581 - case LPX_UP:
1.582 - case LPX_DB:
1.583 - case LPX_FX:
1.584 - if (lo==up)
1.585 - lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
1.586 - else
1.587 - lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
1.588 - break;
1.589 - default: ;
1.590 - //FIXME error
1.591 - }
1.592 - }
1.593 - }
1.594 - virtual double _getRowLowerBound(int i) {
1.595 - int b=lpx_get_row_type(lp, i);
1.596 - switch (b) {
1.597 - case LPX_FR:
1.598 - return -INF;
1.599 - case LPX_LO:
1.600 - return lpx_get_row_lb(lp, i);
1.601 - case LPX_UP:
1.602 - return -INF;
1.603 - case LPX_DB:
1.604 - case LPX_FX:
1.605 - return lpx_get_row_lb(lp, i);
1.606 - default: ;
1.607 - //FIXME error
1.608 - return 0.0;
1.609 - }
1.610 - }
1.611 - virtual void _setRowUpperBound(int i, double up) {
1.612 - if (up==-INF) {
1.613 - //FIXME error
1.614 - }
1.615 - int b=lpx_get_row_type(lp, i);
1.616 - double lo=lpx_get_row_lb(lp, i);
1.617 - if (up==INF) {
1.618 - switch (b) {
1.619 - case LPX_FR:
1.620 - case LPX_LO:
1.621 - break;
1.622 - case LPX_UP:
1.623 - lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
1.624 - break;
1.625 - case LPX_DB:
1.626 - case LPX_FX:
1.627 - lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
1.628 - break;
1.629 - default: ;
1.630 - //FIXME error
1.631 - }
1.632 - } else {
1.633 - switch (b) {
1.634 - case LPX_FR:
1.635 - lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
1.636 - case LPX_LO:
1.637 - if (lo==up)
1.638 - lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
1.639 - else
1.640 - lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
1.641 - break;
1.642 - case LPX_UP:
1.643 - lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
1.644 - break;
1.645 - case LPX_DB:
1.646 - case LPX_FX:
1.647 - if (lo==up)
1.648 - lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
1.649 - else
1.650 - lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
1.651 - break;
1.652 - default: ;
1.653 - //FIXME error
1.654 - }
1.655 - }
1.656 - }
1.657 - virtual double _getRowUpperBound(int i) {
1.658 - int b=lpx_get_row_type(lp, i);
1.659 - switch (b) {
1.660 - case LPX_FR:
1.661 - case LPX_LO:
1.662 - return INF;
1.663 - case LPX_UP:
1.664 - case LPX_DB:
1.665 - case LPX_FX:
1.666 - return lpx_get_row_ub(lp, i);
1.667 - default: ;
1.668 - //FIXME error
1.669 - return 0.0;
1.670 - }
1.671 - }
1.672 - /// \e
1.673 - virtual double _getObjCoeff(int i) {
1.674 - return lpx_get_obj_coef(lp, i);
1.675 - }
1.676 - /// \e
1.677 - virtual void _setObjCoeff(int i, double obj_coef) {
1.678 - lpx_set_obj_coef(lp, i, obj_coef);
1.679 - }
1.680 - public:
1.681 - /// \e
1.682 - void solveSimplex() { lpx_simplex(lp); }
1.683 - /// \e
1.684 - void solvePrimalSimplex() { lpx_simplex(lp); }
1.685 - /// \e
1.686 - void solveDualSimplex() { lpx_simplex(lp); }
1.687 - protected:
1.688 - virtual double _getPrimal(int i) {
1.689 - return lpx_get_col_prim(lp, i);
1.690 - }
1.691 - public:
1.692 - /// \e
1.693 - double getObjVal() { return lpx_get_obj_val(lp); }
1.694 - /// \e
1.695 - int rowNum() const { return lpx_get_num_rows(lp); }
1.696 - /// \e
1.697 - int colNum() const { return lpx_get_num_cols(lp); }
1.698 - /// \e
1.699 - int warmUp() { return lpx_warm_up(lp); }
1.700 - /// \e
1.701 - void printWarmUpStatus(int i) {
1.702 - switch (i) {
1.703 - case LPX_E_OK: cout << "LPX_E_OK" << endl; break;
1.704 - case LPX_E_EMPTY: cout << "LPX_E_EMPTY" << endl; break;
1.705 - case LPX_E_BADB: cout << "LPX_E_BADB" << endl; break;
1.706 - case LPX_E_SING: cout << "LPX_E_SING" << endl; break;
1.707 - }
1.708 - }
1.709 - /// \e
1.710 - int getPrimalStatus() { return lpx_get_prim_stat(lp); }
1.711 - /// \e
1.712 - void printPrimalStatus(int i) {
1.713 - switch (i) {
1.714 - case LPX_P_UNDEF: cout << "LPX_P_UNDEF" << endl; break;
1.715 - case LPX_P_FEAS: cout << "LPX_P_FEAS" << endl; break;
1.716 - case LPX_P_INFEAS: cout << "LPX_P_INFEAS" << endl; break;
1.717 - case LPX_P_NOFEAS: cout << "LPX_P_NOFEAS" << endl; break;
1.718 - }
1.719 - }
1.720 - /// \e
1.721 - int getDualStatus() { return lpx_get_dual_stat(lp); }
1.722 - /// \e
1.723 - void printDualStatus(int i) {
1.724 - switch (i) {
1.725 - case LPX_D_UNDEF: cout << "LPX_D_UNDEF" << endl; break;
1.726 - case LPX_D_FEAS: cout << "LPX_D_FEAS" << endl; break;
1.727 - case LPX_D_INFEAS: cout << "LPX_D_INFEAS" << endl; break;
1.728 - case LPX_D_NOFEAS: cout << "LPX_D_NOFEAS" << endl; break;
1.729 - }
1.730 - }
1.731 - /// Returns the status of the slack variable assigned to row \c row.
1.732 - int getRowStat(const Row& row) {
1.733 - return lpx_get_row_stat(lp, row_iter_map[row]);
1.734 - }
1.735 - /// \e
1.736 - void printRowStatus(int i) {
1.737 - switch (i) {
1.738 - case LPX_BS: cout << "LPX_BS" << endl; break;
1.739 - case LPX_NL: cout << "LPX_NL" << endl; break;
1.740 - case LPX_NU: cout << "LPX_NU" << endl; break;
1.741 - case LPX_NF: cout << "LPX_NF" << endl; break;
1.742 - case LPX_NS: cout << "LPX_NS" << endl; break;
1.743 - }
1.744 - }
1.745 - /// Returns the status of the variable assigned to column \c col.
1.746 - int getColStat(const Col& col) {
1.747 - return lpx_get_col_stat(lp, col_iter_map[col]);
1.748 - }
1.749 - /// \e
1.750 - void printColStatus(int i) {
1.751 - switch (i) {
1.752 - case LPX_BS: cout << "LPX_BS" << endl; break;
1.753 - case LPX_NL: cout << "LPX_NL" << endl; break;
1.754 - case LPX_NU: cout << "LPX_NU" << endl; break;
1.755 - case LPX_NF: cout << "LPX_NF" << endl; break;
1.756 - case LPX_NS: cout << "LPX_NS" << endl; break;
1.757 - }
1.758 - }
1.759 -
1.760 - // MIP
1.761 - /// \e
1.762 - void solveBandB() { lpx_integer(lp); }
1.763 - /// \e
1.764 - void setLP() { lpx_set_class(lp, LPX_LP); }
1.765 - /// \e
1.766 - void setMIP() { lpx_set_class(lp, LPX_MIP); }
1.767 - protected:
1.768 - /// \e
1.769 - void _setColCont(int i) { lpx_set_col_kind(lp, i, LPX_CV); }
1.770 - /// \e
1.771 - void _setColInt(int i) { lpx_set_col_kind(lp, i, LPX_IV); }
1.772 - /// \e
1.773 - double _getMIPPrimal(int i) { return lpx_mip_col_val(lp, i); }
1.774 - };
1.775 -
1.776 - /// @}
1.777
1.778 } //namespace lemon
1.779