Modified a bit.
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
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/src/work/athos/lp/lp_solver_glpk.h Tue Mar 22 12:02:29 2005 +0000
2.3 @@ -0,0 +1,517 @@
2.4 +// -*- c++ -*-
2.5 +#ifndef LEMON_LP_SOLVER_GLPK_H
2.6 +#define LEMON_LP_SOLVER_GLPK_H
2.7 +
2.8 +///\ingroup misc
2.9 +///\file
2.10 +
2.11 +// #include <stdio.h>
2.12 +/* #include <stdlib.h> */
2.13 +/* #include <iostream> */
2.14 +/* #include <map> */
2.15 +/* #include <limits> */
2.16 +// #include <stdio>
2.17 +//#include <stdlib>
2.18 +extern "C" {
2.19 +#include "glpk.h"
2.20 +}
2.21 +
2.22 +/* #include <iostream> */
2.23 +/* #include <vector> */
2.24 +/* #include <string> */
2.25 +/* #include <list> */
2.26 +/* #include <memory> */
2.27 +/* #include <utility> */
2.28 +
2.29 +//#include <lemon/invalid.h>
2.30 +//#include <expression.h>
2.31 +#include <lp_solver_base.h>
2.32 +//#include <stp.h>
2.33 +//#include <lemon/max_flow.h>
2.34 +//#include <augmenting_flow.h>
2.35 +//#include <iter_map.h>
2.36 +
2.37 +using std::cout;
2.38 +using std::cin;
2.39 +using std::endl;
2.40 +
2.41 +namespace lemon {
2.42 +
2.43 +
2.44 + template <typename Value>
2.45 + const Value LpSolverBase<Value>::INF=std::numeric_limits<Value>::infinity();
2.46 +
2.47 +
2.48 + /// \brief Wrapper for GLPK solver
2.49 + ///
2.50 + /// This class implements a lemon wrapper for GLPK.
2.51 + class LpGlpk : public LpSolverBase<double> {
2.52 + public:
2.53 + typedef LpSolverBase<double> Parent;
2.54 +
2.55 + public:
2.56 + /// \e
2.57 + LPX* lp;
2.58 +
2.59 + public:
2.60 + /// \e
2.61 + LpGlpk() : Parent(),
2.62 + lp(lpx_create_prob()) {
2.63 + int_row_map.push_back(Row());
2.64 + int_col_map.push_back(Col());
2.65 + lpx_set_int_parm(lp, LPX_K_DUAL, 1);
2.66 + }
2.67 + /// \e
2.68 + ~LpGlpk() {
2.69 + lpx_delete_prob(lp);
2.70 + }
2.71 +
2.72 + //MATRIX INDEPEDENT MANIPULATING FUNCTIONS
2.73 +
2.74 + /// \e
2.75 + void setMinimize() {
2.76 + lpx_set_obj_dir(lp, LPX_MIN);
2.77 + }
2.78 + /// \e
2.79 + void setMaximize() {
2.80 + lpx_set_obj_dir(lp, LPX_MAX);
2.81 + }
2.82 +
2.83 + //LOW LEVEL INTERFACE, MATRIX MANIPULATING FUNCTIONS
2.84 +
2.85 + protected:
2.86 + /// \e
2.87 + int _addCol() {
2.88 + int i=lpx_add_cols(lp, 1);
2.89 + _setColLowerBound(i, -INF);
2.90 + _setColUpperBound(i, INF);
2.91 + return i;
2.92 + }
2.93 + /// \e
2.94 + int _addRow() {
2.95 + int i=lpx_add_rows(lp, 1);
2.96 + return i;
2.97 + }
2.98 + /// \e
2.99 + virtual void _setRowCoeffs(int i,
2.100 + const std::vector<std::pair<int, double> >& coeffs) {
2.101 + int mem_length=1+colNum();
2.102 + int* indices = new int[mem_length];
2.103 + double* doubles = new double[mem_length];
2.104 + int length=0;
2.105 + for (std::vector<std::pair<int, double> >::
2.106 + const_iterator it=coeffs.begin(); it!=coeffs.end(); ++it) {
2.107 + ++length;
2.108 + indices[length]=it->first;
2.109 + doubles[length]=it->second;
2.110 + }
2.111 + lpx_set_mat_row(lp, i, length, indices, doubles);
2.112 + delete [] indices;
2.113 + delete [] doubles;
2.114 + }
2.115 + /// \e
2.116 + virtual void _getRowCoeffs(int i,
2.117 + std::vector<std::pair<int, double> >& coeffs) {
2.118 + int mem_length=1+colNum();
2.119 + int* indices = new int[mem_length];
2.120 + double* doubles = new double[mem_length];
2.121 + int length=lpx_get_mat_row(lp, i, indices, doubles);
2.122 + for (int i=1; i<=length; ++i) {
2.123 + coeffs.push_back(std::make_pair(indices[i], doubles[i]));
2.124 + }
2.125 + delete [] indices;
2.126 + delete [] doubles;
2.127 + }
2.128 + /// \e
2.129 + virtual void _setColCoeffs(int i,
2.130 + const std::vector<std::pair<int, double> >& coeffs) {
2.131 + int mem_length=1+rowNum();
2.132 + int* indices = new int[mem_length];
2.133 + double* doubles = new double[mem_length];
2.134 + int length=0;
2.135 + for (std::vector<std::pair<int, double> >::
2.136 + const_iterator it=coeffs.begin(); it!=coeffs.end(); ++it) {
2.137 + ++length;
2.138 + indices[length]=it->first;
2.139 + doubles[length]=it->second;
2.140 + }
2.141 + lpx_set_mat_col(lp, i, length, indices, doubles);
2.142 + delete [] indices;
2.143 + delete [] doubles;
2.144 + }
2.145 + /// \e
2.146 + virtual void _getColCoeffs(int i,
2.147 + std::vector<std::pair<int, double> >& coeffs) {
2.148 + int mem_length=1+rowNum();
2.149 + int* indices = new int[mem_length];
2.150 + double* doubles = new double[mem_length];
2.151 + int length=lpx_get_mat_col(lp, i, indices, doubles);
2.152 + for (int i=1; i<=length; ++i) {
2.153 + coeffs.push_back(std::make_pair(indices[i], doubles[i]));
2.154 + }
2.155 + delete [] indices;
2.156 + delete [] doubles;
2.157 + }
2.158 + /// \e
2.159 + virtual void _eraseCol(int i) {
2.160 + int cols[2];
2.161 + cols[1]=i;
2.162 + lpx_del_cols(lp, 1, cols);
2.163 + }
2.164 + virtual void _eraseRow(int i) {
2.165 + int rows[2];
2.166 + rows[1]=i;
2.167 + lpx_del_rows(lp, 1, rows);
2.168 + }
2.169 + void _setCoeff(int col, int row, double value) {
2.170 + /// FIXME not yet implemented
2.171 + }
2.172 + double _getCoeff(int col, int row) {
2.173 + /// FIXME not yet implemented
2.174 + return 0.0;
2.175 + }
2.176 + virtual void _setColLowerBound(int i, double lo) {
2.177 + if (lo==INF) {
2.178 + //FIXME error
2.179 + }
2.180 + int b=lpx_get_col_type(lp, i);
2.181 + double up=lpx_get_col_ub(lp, i);
2.182 + if (lo==-INF) {
2.183 + switch (b) {
2.184 + case LPX_FR:
2.185 + case LPX_LO:
2.186 + lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
2.187 + break;
2.188 + case LPX_UP:
2.189 + break;
2.190 + case LPX_DB:
2.191 + case LPX_FX:
2.192 + lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
2.193 + break;
2.194 + default: ;
2.195 + //FIXME error
2.196 + }
2.197 + } else {
2.198 + switch (b) {
2.199 + case LPX_FR:
2.200 + case LPX_LO:
2.201 + lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
2.202 + break;
2.203 + case LPX_UP:
2.204 + case LPX_DB:
2.205 + case LPX_FX:
2.206 + if (lo==up)
2.207 + lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
2.208 + else
2.209 + lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
2.210 + break;
2.211 + default: ;
2.212 + //FIXME error
2.213 + }
2.214 + }
2.215 + }
2.216 + virtual double _getColLowerBound(int i) {
2.217 + int b=lpx_get_col_type(lp, i);
2.218 + switch (b) {
2.219 + case LPX_FR:
2.220 + return -INF;
2.221 + case LPX_LO:
2.222 + return lpx_get_col_lb(lp, i);
2.223 + case LPX_UP:
2.224 + return -INF;
2.225 + case LPX_DB:
2.226 + case LPX_FX:
2.227 + return lpx_get_col_lb(lp, i);
2.228 + default: ;
2.229 + //FIXME error
2.230 + return 0.0;
2.231 + }
2.232 + }
2.233 + virtual void _setColUpperBound(int i, double up) {
2.234 + if (up==-INF) {
2.235 + //FIXME error
2.236 + }
2.237 + int b=lpx_get_col_type(lp, i);
2.238 + double lo=lpx_get_col_lb(lp, i);
2.239 + if (up==INF) {
2.240 + switch (b) {
2.241 + case LPX_FR:
2.242 + case LPX_LO:
2.243 + break;
2.244 + case LPX_UP:
2.245 + lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
2.246 + break;
2.247 + case LPX_DB:
2.248 + case LPX_FX:
2.249 + lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
2.250 + break;
2.251 + default: ;
2.252 + //FIXME error
2.253 + }
2.254 + } else {
2.255 + switch (b) {
2.256 + case LPX_FR:
2.257 + lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
2.258 + case LPX_LO:
2.259 + if (lo==up)
2.260 + lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
2.261 + else
2.262 + lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
2.263 + break;
2.264 + case LPX_UP:
2.265 + lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
2.266 + break;
2.267 + case LPX_DB:
2.268 + case LPX_FX:
2.269 + if (lo==up)
2.270 + lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
2.271 + else
2.272 + lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
2.273 + break;
2.274 + default: ;
2.275 + //FIXME error
2.276 + }
2.277 + }
2.278 + }
2.279 + virtual double _getColUpperBound(int i) {
2.280 + int b=lpx_get_col_type(lp, i);
2.281 + switch (b) {
2.282 + case LPX_FR:
2.283 + case LPX_LO:
2.284 + return INF;
2.285 + case LPX_UP:
2.286 + case LPX_DB:
2.287 + case LPX_FX:
2.288 + return lpx_get_col_ub(lp, i);
2.289 + default: ;
2.290 + //FIXME error
2.291 + return 0.0;
2.292 + }
2.293 + }
2.294 + virtual void _setRowLowerBound(int i, double lo) {
2.295 + if (lo==INF) {
2.296 + //FIXME error
2.297 + }
2.298 + int b=lpx_get_row_type(lp, i);
2.299 + double up=lpx_get_row_ub(lp, i);
2.300 + if (lo==-INF) {
2.301 + switch (b) {
2.302 + case LPX_FR:
2.303 + case LPX_LO:
2.304 + lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
2.305 + break;
2.306 + case LPX_UP:
2.307 + break;
2.308 + case LPX_DB:
2.309 + case LPX_FX:
2.310 + lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
2.311 + break;
2.312 + default: ;
2.313 + //FIXME error
2.314 + }
2.315 + } else {
2.316 + switch (b) {
2.317 + case LPX_FR:
2.318 + case LPX_LO:
2.319 + lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
2.320 + break;
2.321 + case LPX_UP:
2.322 + case LPX_DB:
2.323 + case LPX_FX:
2.324 + if (lo==up)
2.325 + lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
2.326 + else
2.327 + lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
2.328 + break;
2.329 + default: ;
2.330 + //FIXME error
2.331 + }
2.332 + }
2.333 + }
2.334 + virtual double _getRowLowerBound(int i) {
2.335 + int b=lpx_get_row_type(lp, i);
2.336 + switch (b) {
2.337 + case LPX_FR:
2.338 + return -INF;
2.339 + case LPX_LO:
2.340 + return lpx_get_row_lb(lp, i);
2.341 + case LPX_UP:
2.342 + return -INF;
2.343 + case LPX_DB:
2.344 + case LPX_FX:
2.345 + return lpx_get_row_lb(lp, i);
2.346 + default: ;
2.347 + //FIXME error
2.348 + return 0.0;
2.349 + }
2.350 + }
2.351 + virtual void _setRowUpperBound(int i, double up) {
2.352 + if (up==-INF) {
2.353 + //FIXME error
2.354 + }
2.355 + int b=lpx_get_row_type(lp, i);
2.356 + double lo=lpx_get_row_lb(lp, i);
2.357 + if (up==INF) {
2.358 + switch (b) {
2.359 + case LPX_FR:
2.360 + case LPX_LO:
2.361 + break;
2.362 + case LPX_UP:
2.363 + lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
2.364 + break;
2.365 + case LPX_DB:
2.366 + case LPX_FX:
2.367 + lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
2.368 + break;
2.369 + default: ;
2.370 + //FIXME error
2.371 + }
2.372 + } else {
2.373 + switch (b) {
2.374 + case LPX_FR:
2.375 + lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
2.376 + case LPX_LO:
2.377 + if (lo==up)
2.378 + lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
2.379 + else
2.380 + lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
2.381 + break;
2.382 + case LPX_UP:
2.383 + lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
2.384 + break;
2.385 + case LPX_DB:
2.386 + case LPX_FX:
2.387 + if (lo==up)
2.388 + lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
2.389 + else
2.390 + lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
2.391 + break;
2.392 + default: ;
2.393 + //FIXME error
2.394 + }
2.395 + }
2.396 + }
2.397 + virtual double _getRowUpperBound(int i) {
2.398 + int b=lpx_get_row_type(lp, i);
2.399 + switch (b) {
2.400 + case LPX_FR:
2.401 + case LPX_LO:
2.402 + return INF;
2.403 + case LPX_UP:
2.404 + case LPX_DB:
2.405 + case LPX_FX:
2.406 + return lpx_get_row_ub(lp, i);
2.407 + default: ;
2.408 + //FIXME error
2.409 + return 0.0;
2.410 + }
2.411 + }
2.412 + /// \e
2.413 + virtual double _getObjCoeff(int i) {
2.414 + return lpx_get_obj_coef(lp, i);
2.415 + }
2.416 + /// \e
2.417 + virtual void _setObjCoeff(int i, double obj_coef) {
2.418 + lpx_set_obj_coef(lp, i, obj_coef);
2.419 + }
2.420 + public:
2.421 + /// \e
2.422 + void solveSimplex() { lpx_simplex(lp); }
2.423 + /// \e
2.424 + void solvePrimalSimplex() { lpx_simplex(lp); }
2.425 + /// \e
2.426 + void solveDualSimplex() { lpx_simplex(lp); }
2.427 + protected:
2.428 + virtual double _getPrimal(int i) {
2.429 + return lpx_get_col_prim(lp, i);
2.430 + }
2.431 + public:
2.432 + /// \e
2.433 + double getObjVal() { return lpx_get_obj_val(lp); }
2.434 + /// \e
2.435 + int rowNum() const { return lpx_get_num_rows(lp); }
2.436 + /// \e
2.437 + int colNum() const { return lpx_get_num_cols(lp); }
2.438 + /// \e
2.439 + int warmUp() { return lpx_warm_up(lp); }
2.440 + /// \e
2.441 + void printWarmUpStatus(int i) {
2.442 + switch (i) {
2.443 + case LPX_E_OK: cout << "LPX_E_OK" << endl; break;
2.444 + case LPX_E_EMPTY: cout << "LPX_E_EMPTY" << endl; break;
2.445 + case LPX_E_BADB: cout << "LPX_E_BADB" << endl; break;
2.446 + case LPX_E_SING: cout << "LPX_E_SING" << endl; break;
2.447 + }
2.448 + }
2.449 + /// \e
2.450 + int getPrimalStatus() { return lpx_get_prim_stat(lp); }
2.451 + /// \e
2.452 + void printPrimalStatus(int i) {
2.453 + switch (i) {
2.454 + case LPX_P_UNDEF: cout << "LPX_P_UNDEF" << endl; break;
2.455 + case LPX_P_FEAS: cout << "LPX_P_FEAS" << endl; break;
2.456 + case LPX_P_INFEAS: cout << "LPX_P_INFEAS" << endl; break;
2.457 + case LPX_P_NOFEAS: cout << "LPX_P_NOFEAS" << endl; break;
2.458 + }
2.459 + }
2.460 + /// \e
2.461 + int getDualStatus() { return lpx_get_dual_stat(lp); }
2.462 + /// \e
2.463 + void printDualStatus(int i) {
2.464 + switch (i) {
2.465 + case LPX_D_UNDEF: cout << "LPX_D_UNDEF" << endl; break;
2.466 + case LPX_D_FEAS: cout << "LPX_D_FEAS" << endl; break;
2.467 + case LPX_D_INFEAS: cout << "LPX_D_INFEAS" << endl; break;
2.468 + case LPX_D_NOFEAS: cout << "LPX_D_NOFEAS" << endl; break;
2.469 + }
2.470 + }
2.471 + /// Returns the status of the slack variable assigned to row \c row.
2.472 + int getRowStat(const Row& row) {
2.473 + return lpx_get_row_stat(lp, row_iter_map[row]);
2.474 + }
2.475 + /// \e
2.476 + void printRowStatus(int i) {
2.477 + switch (i) {
2.478 + case LPX_BS: cout << "LPX_BS" << endl; break;
2.479 + case LPX_NL: cout << "LPX_NL" << endl; break;
2.480 + case LPX_NU: cout << "LPX_NU" << endl; break;
2.481 + case LPX_NF: cout << "LPX_NF" << endl; break;
2.482 + case LPX_NS: cout << "LPX_NS" << endl; break;
2.483 + }
2.484 + }
2.485 + /// Returns the status of the variable assigned to column \c col.
2.486 + int getColStat(const Col& col) {
2.487 + return lpx_get_col_stat(lp, col_iter_map[col]);
2.488 + }
2.489 + /// \e
2.490 + void printColStatus(int i) {
2.491 + switch (i) {
2.492 + case LPX_BS: cout << "LPX_BS" << endl; break;
2.493 + case LPX_NL: cout << "LPX_NL" << endl; break;
2.494 + case LPX_NU: cout << "LPX_NU" << endl; break;
2.495 + case LPX_NF: cout << "LPX_NF" << endl; break;
2.496 + case LPX_NS: cout << "LPX_NS" << endl; break;
2.497 + }
2.498 + }
2.499 +
2.500 + // MIP
2.501 + /// \e
2.502 + void solveBandB() { lpx_integer(lp); }
2.503 + /// \e
2.504 + void setLP() { lpx_set_class(lp, LPX_LP); }
2.505 + /// \e
2.506 + void setMIP() { lpx_set_class(lp, LPX_MIP); }
2.507 + protected:
2.508 + /// \e
2.509 + void _setColCont(int i) { lpx_set_col_kind(lp, i, LPX_CV); }
2.510 + /// \e
2.511 + void _setColInt(int i) { lpx_set_col_kind(lp, i, LPX_IV); }
2.512 + /// \e
2.513 + double _getMIPPrimal(int i) { return lpx_mip_col_val(lp, i); }
2.514 + };
2.515 +
2.516 + /// @}
2.517 +
2.518 +} //namespace lemon
2.519 +
2.520 +#endif //LEMON_LP_SOLVER_GLPK_H
3.1 --- a/src/work/athos/lp/magic_square.cc Tue Mar 22 11:45:47 2005 +0000
3.2 +++ b/src/work/athos/lp/magic_square.cc Tue Mar 22 12:02:29 2005 +0000
3.3 @@ -3,7 +3,7 @@
3.4 #include <fstream>
3.5
3.6 #include <lemon/time_measure.h>
3.7 -#include <lp_solver_base.h>
3.8 +#include <lp_solver_glpk.h>
3.9
3.10 using std::cout;
3.11 using std::endl;
3.12 @@ -21,7 +21,7 @@
3.13 const double row_sum=(1.0+n*n)*n/2;
3.14 Timer ts;
3.15 ts.reset();
3.16 - typedef LPGLPK LPSolver;
3.17 + typedef LpGlpk LPSolver;
3.18 typedef LPSolver::Col Col;
3.19 LPSolver lp;
3.20 typedef std::map<std::pair<int, int>, Col> Coords;
4.1 --- a/src/work/athos/lp/makefile Tue Mar 22 11:45:47 2005 +0000
4.2 +++ b/src/work/athos/lp/makefile Tue Mar 22 12:02:29 2005 +0000
4.3 @@ -5,7 +5,7 @@
4.4 CXXFLAGS = -g -O2 -W -Wall $(INCLUDEDIRS) -ansi -pedantic
4.5 LDFLAGS = -lglpk#-lcplex -lm -lpthread -lilocplex -L/usr/local/cplex/cplex75/lib/i86_linux2_glibc2.2_gcc3.0/static_mt# -L$(GLPKROOT)/lib
4.6
4.7 -BINARIES = magic_square max_flow_expression expression_test max_flow_by_lp# sample sample2 sample11 sample15
4.8 +BINARIES = magic_square max_flow_expression #expression_test max_flow_by_lp# sample sample2 sample11 sample15
4.9
4.10 #include ../makefile
4.11
5.1 --- a/src/work/athos/lp/max_flow_expression.cc Tue Mar 22 11:45:47 2005 +0000
5.2 +++ b/src/work/athos/lp/max_flow_expression.cc Tue Mar 22 12:02:29 2005 +0000
5.3 @@ -7,7 +7,7 @@
5.4 #include <lemon/list_graph.h>
5.5 #include <lemon/dimacs.h>
5.6 #include <lemon/time_measure.h>
5.7 -#include <lp_solver_base.h>
5.8 +#include <lp_solver_glpk.h>
5.9
5.10 using std::cout;
5.11 using std::endl;
5.12 @@ -16,10 +16,10 @@
5.13 template<typename Edge, typename EdgeIndexMap>
5.14 class PrimalMap {
5.15 protected:
5.16 - LPGLPK* lp;
5.17 + LpGlpk* lp;
5.18 EdgeIndexMap* edge_index_map;
5.19 public:
5.20 - PrimalMap(LPGLPK& _lp, EdgeIndexMap& _edge_index_map) :
5.21 + PrimalMap(LpGlpk& _lp, EdgeIndexMap& _edge_index_map) :
5.22 lp(&_lp), edge_index_map(&_edge_index_map) { }
5.23 double operator[](Edge e) const {
5.24 return lp->getPrimal((*edge_index_map)[e]);
5.25 @@ -43,7 +43,7 @@
5.26 readDimacs(std::cin, g, cap, s, t);
5.27 Timer ts;
5.28
5.29 - typedef LPGLPK LPSolver;
5.30 + typedef LpGlpk LPSolver;
5.31 LPSolver lp;
5.32 lp.setMaximize();
5.33 typedef LPSolver::Col Col;