Changeset 2366:bfbdded3763a in lemon-0.x
- Timestamp:
- 02/16/07 20:11:31 (17 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@3181
- Location:
- lemon
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/lp_base.h
r2364 r2366 136 136 137 137 class ColIt : public Col { 138 LpSolverBase *_lp;138 const LpSolverBase *_lp; 139 139 public: 140 140 ColIt() {} 141 ColIt( LpSolverBase &lp) : _lp(&lp)141 ColIt(const LpSolverBase &lp) : _lp(&lp) 142 142 { 143 143 _lp->cols.firstFix(id); … … 181 181 182 182 class RowIt : public Row { 183 LpSolverBase *_lp;183 const LpSolverBase *_lp; 184 184 public: 185 185 RowIt() {} 186 RowIt( LpSolverBase &lp) : _lp(&lp)186 RowIt(const LpSolverBase &lp) : _lp(&lp) 187 187 { 188 188 _lp->rows.firstFix(id); … … 736 736 virtual int _addCol() = 0; 737 737 virtual int _addRow() = 0; 738 738 739 virtual void _eraseCol(int col) = 0; 739 740 virtual void _eraseRow(int row) = 0; 740 virtual void _getColName(int col, std::string & name) = 0; 741 742 virtual void _getColName(int col, std::string & name) const = 0; 741 743 virtual void _setColName(int col, const std::string & name) = 0; 744 virtual int _colByName(const std::string& name) const = 0; 745 742 746 virtual void _setRowCoeffs(int i, ConstRowIterator b, 743 747 ConstRowIterator e) = 0; 744 virtual void _getRowCoeffs(int i, RowIterator b) = 0;748 virtual void _getRowCoeffs(int i, RowIterator b) const = 0; 745 749 virtual void _setColCoeffs(int i, ConstColIterator b, 746 750 ConstColIterator e) = 0; 747 virtual void _getColCoeffs(int i, ColIterator b) = 0;751 virtual void _getColCoeffs(int i, ColIterator b) const = 0; 748 752 virtual void _setCoeff(int row, int col, Value value) = 0; 749 virtual Value _getCoeff(int row, int col) = 0;753 virtual Value _getCoeff(int row, int col) const = 0; 750 754 virtual void _setColLowerBound(int i, Value value) = 0; 751 virtual Value _getColLowerBound(int i) = 0;755 virtual Value _getColLowerBound(int i) const = 0; 752 756 virtual void _setColUpperBound(int i, Value value) = 0; 753 virtual Value _getColUpperBound(int i) = 0;757 virtual Value _getColUpperBound(int i) const = 0; 754 758 virtual void _setRowBounds(int i, Value lower, Value upper) = 0; 755 virtual void _getRowBounds(int i, Value &lower, Value &upper) =0;759 virtual void _getRowBounds(int i, Value &lower, Value &upper) const = 0; 756 760 757 761 virtual void _setObjCoeff(int i, Value obj_coef) = 0; 758 virtual Value _getObjCoeff(int i) = 0;762 virtual Value _getObjCoeff(int i) const = 0; 759 763 virtual void _clearObj()=0; 760 764 761 765 virtual SolveExitStatus _solve() = 0; 762 virtual Value _getPrimal(int i) = 0; 763 virtual Value _getDual(int i) = 0; 764 virtual Value _getPrimalValue() = 0; 765 virtual bool _isBasicCol(int i) = 0; 766 virtual SolutionStatus _getPrimalStatus() = 0; 767 virtual SolutionStatus _getDualStatus() = 0; 768 ///\todo This could be implemented here, too, using _getPrimalStatus() and 769 ///_getDualStatus() 770 virtual ProblemTypes _getProblemType() = 0; 766 virtual Value _getPrimal(int i) const = 0; 767 virtual Value _getDual(int i) const = 0; 768 virtual Value _getPrimalValue() const = 0; 769 virtual bool _isBasicCol(int i) const = 0; 770 virtual SolutionStatus _getPrimalStatus() const = 0; 771 virtual SolutionStatus _getDualStatus() const = 0; 772 virtual ProblemTypes _getProblemType() const = 0; 771 773 772 774 virtual void _setMax() = 0; … … 774 776 775 777 776 virtual bool _isMax() = 0;778 virtual bool _isMax() const = 0; 777 779 778 780 //Own protected stuff … … 878 880 ///\param r is the column to get 879 881 ///\return the dual expression associated to the column 880 DualExpr col(Col c) {882 DualExpr col(Col c) const { 881 883 DualExpr e; 882 884 _getColCoeffs(_lpId(c), ColIterator(std::inserter(e, e.end()), *this)); … … 975 977 ///\todo Option to control whether a constraint with a single variable is 976 978 ///added or not. 977 void row(Row r, Value l, const Expr &e, Value u) {979 void row(Row r, Value l, const Expr &e, Value u) { 978 980 e.simplify(); 979 981 _setRowCoeffs(_lpId(r), ConstRowIterator(e.begin(), *this), … … 996 998 ///\param r is the row to get 997 999 ///\return the expression associated to the row 998 Expr row(Row r) {1000 Expr row(Row r) const { 999 1001 Expr e; 1000 1002 _getRowCoeffs(_lpId(r), RowIterator(std::inserter(e, e.end()), *this)); … … 1046 1048 ///\param c is the coresponding coloumn 1047 1049 ///\return The name of the colunm 1048 std::string colName(Col c) {1050 std::string colName(Col c) const { 1049 1051 std::string name; 1050 1052 _getColName(_lpId(c), name); … … 1056 1058 ///\param c is the coresponding coloumn 1057 1059 ///\param name The name to be given 1058 void colName(Col c, const std::string& name) {1060 void colName(Col c, const std::string& name) { 1059 1061 _setColName(_lpId(c), name); 1060 1062 } … … 1066 1068 ///\param val is the new value of the coefficient 1067 1069 1068 void coeff(Row r, Col c, Value val) {1070 void coeff(Row r, Col c, Value val) { 1069 1071 _setCoeff(_lpId(r),_lpId(c), val); 1070 1072 } … … 1076 1078 ///\return the corresponding coefficient 1077 1079 1078 Value coeff(Row r, Col c) {1080 Value coeff(Row r, Col c) const { 1079 1081 return _getCoeff(_lpId(r),_lpId(c)); 1080 1082 } … … 1094 1096 /// (this might be -\ref INF as well). 1095 1097 ///\return The lower bound for coloumn \t c 1096 Value colLowerBound(Col c) {1098 Value colLowerBound(Col c) const { 1097 1099 return _getColLowerBound(_lpId(c)); 1098 1100 } … … 1149 1151 /// (this might be \ref INF as well). 1150 1152 ///\return The upper bound for coloumn \t c 1151 Value colUpperBound(Col c) {1153 Value colUpperBound(Col c) const { 1152 1154 return _getColUpperBound(_lpId(c)); 1153 1155 } … … 1261 1263 /// implementation of the setting functions for CPLEX: 1262 1264 /// check out whether this can be done for these functions. 1263 void getRowBounds(Row c, Value &lower, Value &upper) {1265 void getRowBounds(Row c, Value &lower, Value &upper) const { 1264 1266 _getRowBounds(_lpId(c),lower, upper); 1265 1267 } … … 1269 1271 1270 1272 ///Get an element of the objective function 1271 Value objCoeff(Col c) {return _getObjCoeff(_lpId(c)); };1273 Value objCoeff(Col c) const { return _getObjCoeff(_lpId(c)); }; 1272 1274 1273 1275 ///Set the objective function … … 1285 1287 1286 1288 ///\return the objective function as a linear expression of type \ref Expr. 1287 Expr obj() {1289 Expr obj() const { 1288 1290 Expr e; 1289 1291 for (ColIt it(*this); it != INVALID; ++it) { … … 1303 1305 1304 1306 ///Query function: is this a maximization problem? 1305 bool is_max() {return _isMax(); }1307 bool is_max() const {return _isMax(); } 1306 1308 1307 1309 ///Query function: is this a minimization problem? 1308 bool is_min() {return !is_max(); }1310 bool is_min() const {return !is_max(); } 1309 1311 1310 1312 ///@} … … 1331 1333 1332 1334 /// The status of the primal problem (the original LP problem) 1333 SolutionStatus primalStatus() {1335 SolutionStatus primalStatus() const { 1334 1336 return _getPrimalStatus(); 1335 1337 } 1336 1338 1337 1339 /// The status of the dual (of the original LP) problem 1338 SolutionStatus dualStatus() {1340 SolutionStatus dualStatus() const { 1339 1341 return _getDualStatus(); 1340 1342 } 1341 1343 1342 1344 ///The type of the original LP problem 1343 ProblemTypes problemType() {1345 ProblemTypes problemType() const { 1344 1346 return _getProblemType(); 1345 1347 } 1346 1348 1347 1349 ///\e 1348 Value primal(Col c) { return _getPrimal(_lpId(c)); }1350 Value primal(Col c) const { return _getPrimal(_lpId(c)); } 1349 1351 1350 1352 ///\e 1351 Value dual(Row r) { return _getDual(_lpId(r)); }1353 Value dual(Row r) const { return _getDual(_lpId(r)); } 1352 1354 1353 1355 ///\e 1354 bool isBasicCol(Col c) { return _isBasicCol(_lpId(c)); }1356 bool isBasicCol(Col c) const { return _isBasicCol(_lpId(c)); } 1355 1357 1356 1358 ///\e … … 1361 1363 ///- \ref NaN if no primal solution is found. 1362 1364 ///- The (finite) objective value if an optimal solution is found. 1363 Value primalValue() { return _getPrimalValue()+obj_const_comp;}1365 Value primalValue() const { return _getPrimalValue()+obj_const_comp;} 1364 1366 ///@} 1365 1367 … … 1395 1397 /// 1396 1398 ///Gives back the type of the column. 1397 ColTypes colType(Col c) {1399 ColTypes colType(Col c) const { 1398 1400 return _colType(_lpId(c)); 1399 1401 } … … 1413 1415 ///Gives back the type of the column. 1414 1416 ///\return true if the column has integer type and false if not. 1415 bool integer(Col c) {1417 bool integer(Col c) const { 1416 1418 return (colType(c)==INT); 1417 1419 } 1418 1420 1419 1421 /// The status of the MIP problem 1420 SolutionStatus mipStatus() {1422 SolutionStatus mipStatus() const { 1421 1423 return _getMipStatus(); 1422 1424 } … … 1424 1426 protected: 1425 1427 1426 virtual ColTypes _colType(int col) = 0;1428 virtual ColTypes _colType(int col) const = 0; 1427 1429 virtual void _colType(int col, ColTypes col_type) = 0; 1428 virtual SolutionStatus _getMipStatus() =0;1430 virtual SolutionStatus _getMipStatus() const = 0; 1429 1431 1430 1432 }; -
lemon/lp_cplex.cc
r2364 r2366 85 85 } 86 86 87 void LpCplex::_getColName(int col, std::string &name) 87 void LpCplex::_getColName(int col, std::string &name) const 88 88 { 89 89 ///\bug Untested … … 108 108 CPXchgcolname(env, lp, 1, &col, names); 109 109 } 110 111 int LpCplex::_colByName(const std::string& name) const 112 { 113 int index; 114 if (CPXgetcolindex(env, lp, 115 const_cast<char*>(name.c_str()), &index) == 0) { 116 return index; 117 } 118 return -1; 119 } 110 120 111 121 ///\warning Data at index 0 is ignored in the arrays. … … 126 136 } 127 137 128 void LpSoplex::_getRowCoeffs(int i, RowIterator b) {138 void LpSoplex::_getRowCoeffs(int i, RowIterator b) const { 129 139 /// \todo implement 130 140 } … … 146 156 } 147 157 148 void LpSoplex::_getColCoeffs(int i, ColIterator b) {158 void LpSoplex::_getColCoeffs(int i, ColIterator b) const { 149 159 /// \todo implement 150 160 } … … 155 165 } 156 166 157 LpCplex::Value LpCplex::_getCoeff(int row, int col) 167 LpCplex::Value LpCplex::_getCoeff(int row, int col) const 158 168 { 159 169 LpCplex::Value value; … … 174 184 } 175 185 176 LpCplex::Value LpCplex::_getColLowerBound(int i) 186 LpCplex::Value LpCplex::_getColLowerBound(int i) const 177 187 { 178 188 LpCplex::Value x; … … 192 202 } 193 203 194 LpCplex::Value LpCplex::_getColUpperBound(int i) 204 LpCplex::Value LpCplex::_getColUpperBound(int i) const 195 205 { 196 206 LpCplex::Value x; … … 271 281 // } 272 282 273 void LpCplex::_getRowBounds(int i, Value &lb, Value &ub) 283 void LpCplex::_getRowBounds(int i, Value &lb, Value &ub) const 274 284 { 275 285 char sense; … … 303 313 } 304 314 305 LpCplex::Value LpCplex::_getObjCoeff(int i) 315 LpCplex::Value LpCplex::_getObjCoeff(int i) const 306 316 { 307 317 Value x; … … 368 378 } 369 379 370 LpCplex::Value LpCplex::_getPrimal(int i) 380 LpCplex::Value LpCplex::_getPrimal(int i) const 371 381 { 372 382 Value x; … … 375 385 } 376 386 377 LpCplex::Value LpCplex::_getDual(int i) 387 LpCplex::Value LpCplex::_getDual(int i) const 378 388 { 379 389 Value y; … … 382 392 } 383 393 384 LpCplex::Value LpCplex::_getPrimalValue() 394 LpCplex::Value LpCplex::_getPrimalValue() const 385 395 { 386 396 Value objval; … … 391 401 return objval; 392 402 } 393 bool LpCplex::_isBasicCol(int i) { 403 bool LpCplex::_isBasicCol(int i) const 404 { 394 405 int cstat[CPXgetnumcols(env, lp)]; 395 406 CPXgetbase(env, lp, cstat, NULL); … … 459 470 // Description: Method for linear optimization. 460 471 // Determines which algorithm is used when CPXlpopt() (or "optimize" in the Interactive Optimizer) is called. Currently the behavior of the "Automatic" setting is that CPLEX simply invokes the dual simplex method, but this capability may be expanded in the future so that CPLEX chooses the method based on problem characteristics 461 //Hulye cplex462 472 void statusSwitch(CPXENVptr env,int& stat){ 463 473 #if CPX_VERSION < 900 … … 476 486 } 477 487 478 LpCplex::SolutionStatus LpCplex::_getPrimalStatus() 488 LpCplex::SolutionStatus LpCplex::_getPrimalStatus() const 479 489 { 480 490 //Unboundedness not treated well: the following is from cplex 9.0 doc … … 559 569 // CPX_STAT_UNBOUNDED 560 570 561 LpCplex::SolutionStatus LpCplex::_getDualStatus() 571 LpCplex::SolutionStatus LpCplex::_getDualStatus() const 562 572 { 563 573 int stat = CPXgetstat(env, lp); … … 588 598 } 589 599 590 LpCplex::ProblemTypes LpCplex::_getProblemType() 600 LpCplex::ProblemTypes LpCplex::_getProblemType() const 591 601 { 592 602 int stat = CPXgetstat(env, lp); … … 628 638 } 629 639 630 bool LpCplex::_isMax() 640 bool LpCplex::_isMax() const 631 641 { 632 642 if (CPXgetobjsen(env, lp)==CPX_MAX) -
lemon/lp_cplex.h
r2364 r2366 61 61 virtual void _eraseCol(int i); 62 62 virtual void _eraseRow(int i); 63 virtual void _getColName(int col, std::string & name);63 virtual void _getColName(int col, std::string & name) const; 64 64 virtual void _setColName(int col, const std::string & name); 65 virtual int _colByName(const std::string& name) const; 65 66 virtual void _setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e); 66 virtual void _getRowCoeffs(int i, RowIterator b) ;67 virtual void _getRowCoeffs(int i, RowIterator b) const; 67 68 virtual void _setColCoeffs(int i, ConstColIterator b, ConstColIterator e); 68 virtual void _getColCoeffs(int i, ColIterator b) ;69 virtual void _getColCoeffs(int i, ColIterator b) const; 69 70 virtual void _setCoeff(int row, int col, Value value); 70 virtual Value _getCoeff(int row, int col) ;71 virtual Value _getCoeff(int row, int col) const; 71 72 72 73 virtual void _setColLowerBound(int i, Value value); 73 virtual Value _getColLowerBound(int i) ;74 virtual Value _getColLowerBound(int i) const; 74 75 virtual void _setColUpperBound(int i, Value value); 75 virtual Value _getColUpperBound(int i) ;76 virtual Value _getColUpperBound(int i) const; 76 77 77 78 // virtual void _setRowLowerBound(int i, Value value); 78 79 // virtual void _setRowUpperBound(int i, Value value); 79 80 virtual void _setRowBounds(int i, Value lower, Value upper); 80 virtual void _getRowBounds(int i, Value &lb, Value &ub) ;81 virtual void _getRowBounds(int i, Value &lb, Value &ub) const; 81 82 virtual void _setObjCoeff(int i, Value obj_coef); 82 virtual Value _getObjCoeff(int i) ;83 virtual Value _getObjCoeff(int i) const; 83 84 virtual void _clearObj(); 84 85 85 86 86 87 virtual SolveExitStatus _solve(); 87 virtual Value _getPrimal(int i) ;88 virtual Value _getDual(int i) ;89 virtual Value _getPrimalValue() ;90 virtual bool _isBasicCol(int i) ;88 virtual Value _getPrimal(int i) const; 89 virtual Value _getDual(int i) const; 90 virtual Value _getPrimalValue() const; 91 virtual bool _isBasicCol(int i) const; 91 92 92 virtual SolutionStatus _getPrimalStatus() ;93 virtual SolutionStatus _getDualStatus() ;94 virtual ProblemTypes _getProblemType() ;93 virtual SolutionStatus _getPrimalStatus() const; 94 virtual SolutionStatus _getDualStatus() const; 95 virtual ProblemTypes _getProblemType() const; 95 96 96 97 … … 98 99 virtual void _setMin(); 99 100 100 virtual bool _isMax() ;101 virtual bool _isMax() const; 101 102 102 103 }; -
lemon/lp_glpk.cc
r2364 r2366 38 38 cols = _lp_bits::LpId(1); 39 39 lp = lpx_create_prob(); 40 lpx_create_index(lp); 40 41 ///\todo control function for this: 41 42 lpx_set_int_parm(lp, LPX_K_DUAL, 1); … … 113 114 } 114 115 115 void LpGlpk::_getColName(int col, std::string & name) 116 void LpGlpk::_getColName(int col, std::string & name) const 116 117 { 117 118 … … 126 127 127 128 } 129 130 int LpGlpk::_colByName(const std::string& name) const 131 { 132 int k = lpx_find_col(lp, const_cast<char*>(name.c_str())); 133 return k > 0 ? k : -1; 134 } 135 128 136 129 137 void LpGlpk::_setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e) … … 143 151 } 144 152 145 void LpGlpk::_getRowCoeffs(int i, RowIterator b) 153 void LpGlpk::_getRowCoeffs(int i, RowIterator b) const 146 154 { 147 155 int length = lpx_get_mat_row(lp, i, 0, 0); … … 174 182 } 175 183 176 void LpGlpk::_getColCoeffs(int i, ColIterator b) 184 void LpGlpk::_getColCoeffs(int i, ColIterator b) const 177 185 { 178 186 int length = lpx_get_mat_col(lp, i, 0, 0); … … 248 256 } 249 257 250 LpGlpk::Value LpGlpk::_getCoeff(int row, int col) 258 LpGlpk::Value LpGlpk::_getCoeff(int row, int col) const 251 259 { 252 260 … … 313 321 } 314 322 315 LpGlpk::Value LpGlpk::_getColLowerBound(int i) 323 LpGlpk::Value LpGlpk::_getColLowerBound(int i) const 316 324 { 317 325 int b=lpx_get_col_type(lp, i); … … 370 378 } 371 379 372 LpGlpk::Value LpGlpk::_getColUpperBound(int i) 380 LpGlpk::Value LpGlpk::_getColUpperBound(int i) const 373 381 { 374 382 int b=lpx_get_col_type(lp, i); … … 415 423 } 416 424 417 void LpGlpk::_getRowBounds(int i, Value &lb, Value &ub) 425 void LpGlpk::_getRowBounds(int i, Value &lb, Value &ub) const 418 426 { 419 427 … … 445 453 } 446 454 447 LpGlpk::Value LpGlpk::_getObjCoeff(int i) {455 LpGlpk::Value LpGlpk::_getObjCoeff(int i) const { 448 456 //i=0 means the constant term (shift) 449 457 return lpx_get_obj_coef(lp, i); … … 473 481 } 474 482 475 LpGlpk::Value LpGlpk::_getPrimal(int i) 483 LpGlpk::Value LpGlpk::_getPrimal(int i) const 476 484 { 477 485 return lpx_get_col_prim(lp,i); 478 486 } 479 487 480 LpGlpk::Value LpGlpk::_getDual(int i) 488 LpGlpk::Value LpGlpk::_getDual(int i) const 481 489 { 482 490 return lpx_get_row_dual(lp,i); 483 491 } 484 492 485 LpGlpk::Value LpGlpk::_getPrimalValue() 493 LpGlpk::Value LpGlpk::_getPrimalValue() const 486 494 { 487 495 return lpx_get_obj_val(lp); 488 496 } 489 bool LpGlpk::_isBasicCol(int i) { 497 bool LpGlpk::_isBasicCol(int i) const 498 { 490 499 return (lpx_get_col_stat(lp, i)==LPX_BS); 491 500 } 492 501 493 502 494 LpGlpk::SolutionStatus LpGlpk::_getPrimalStatus() 503 LpGlpk::SolutionStatus LpGlpk::_getPrimalStatus() const 495 504 { 496 505 int stat= lpx_get_status(lp); … … 513 522 } 514 523 515 LpGlpk::SolutionStatus LpGlpk::_getDualStatus() 516 { 517 // std::cout<<"Itt megy: "<<lpx_get_dual_stat(lp)<<std::endl; 518 // std::cout<<"Itt a primal: "<<lpx_get_prim_stat(lp)<<std::endl; 519 524 LpGlpk::SolutionStatus LpGlpk::_getDualStatus() const 525 { 520 526 switch (lpx_get_dual_stat(lp)) { 521 527 case LPX_D_UNDEF://Undefined (no solve has been run yet) … … 539 545 } 540 546 541 LpGlpk::ProblemTypes LpGlpk::_getProblemType() 547 LpGlpk::ProblemTypes LpGlpk::_getProblemType() const 542 548 { 543 549 //int stat= lpx_get_status(lp); … … 566 572 } 567 573 568 bool LpGlpk::_isMax() 574 bool LpGlpk::_isMax() const 569 575 { 570 576 return (lpx_get_obj_dir(lp)==LPX_MAX); -
lemon/lp_glpk.h
r2364 r2366 56 56 virtual void _eraseCol(int i); 57 57 virtual void _eraseRow(int i); 58 virtual void _getColName(int col, std::string & name);58 virtual void _getColName(int col, std::string & name) const; 59 59 virtual void _setColName(int col, const std::string & name); 60 virtual int _colByName(const std::string& name) const; 60 61 virtual void _setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e); 61 virtual void _getRowCoeffs(int i, RowIterator b) ;62 virtual void _getRowCoeffs(int i, RowIterator b) const; 62 63 virtual void _setColCoeffs(int i, ConstColIterator b, ConstColIterator e); 63 virtual void _getColCoeffs(int i, ColIterator b) ;64 virtual void _getColCoeffs(int i, ColIterator b) const; 64 65 virtual void _setCoeff(int row, int col, Value value); 65 virtual Value _getCoeff(int row, int col) ;66 virtual Value _getCoeff(int row, int col) const; 66 67 67 68 virtual void _setColLowerBound(int i, Value value); 68 virtual Value _getColLowerBound(int i) ;69 virtual Value _getColLowerBound(int i) const; 69 70 virtual void _setColUpperBound(int i, Value value); 70 virtual Value _getColUpperBound(int i) ;71 virtual Value _getColUpperBound(int i) const; 71 72 72 // virtual void _setRowLowerBound(int i, Value value);73 // virtual void _setRowUpperBound(int i, Value value);74 73 virtual void _setRowBounds(int i, Value lower, Value upper); 75 virtual void _getRowBounds(int i, Value &lb, Value &ub) ;74 virtual void _getRowBounds(int i, Value &lb, Value &ub) const; 76 75 virtual void _setObjCoeff(int i, Value obj_coef); 77 virtual Value _getObjCoeff(int i) ;76 virtual Value _getObjCoeff(int i) const; 78 77 virtual void _clearObj(); 79 // virtual void _setObj(int length,80 // int const * indices,81 // Value const * values ) = 0;82 78 83 79 ///\e … … 86 82 /// 87 83 virtual SolveExitStatus _solve(); 88 virtual Value _getPrimal(int i) ;89 virtual Value _getDual(int i) ;90 virtual Value _getPrimalValue() ;91 virtual bool _isBasicCol(int i) ;84 virtual Value _getPrimal(int i) const; 85 virtual Value _getDual(int i) const; 86 virtual Value _getPrimalValue() const; 87 virtual bool _isBasicCol(int i) const; 92 88 ///\e 93 89 94 90 ///\todo It should be clarified 95 91 /// 96 virtual SolutionStatus _getPrimalStatus() ;97 virtual SolutionStatus _getDualStatus() ;98 virtual ProblemTypes _getProblemType() ;92 virtual SolutionStatus _getPrimalStatus() const; 93 virtual SolutionStatus _getDualStatus() const; 94 virtual ProblemTypes _getProblemType() const; 99 95 100 96 virtual void _setMax(); 101 97 virtual void _setMin(); 102 98 103 virtual bool _isMax() ;99 virtual bool _isMax() const; 104 100 105 101 public: -
lemon/lp_skeleton.cc
r2364 r2366 51 51 } 52 52 53 void LpSkeleton::_getColName(int, std::string &) {53 void LpSkeleton::_getColName(int, std::string &) const { 54 54 } 55 55 … … 57 57 void LpSkeleton::_setColName(int, const std::string &) { 58 58 } 59 60 int LpSkeleton::_colByName(const std::string&) const { return -1; } 59 61 60 62 … … 62 64 } 63 65 64 void LpSkeleton::_getRowCoeffs(int, RowIterator) {66 void LpSkeleton::_getRowCoeffs(int, RowIterator) const { 65 67 } 66 68 … … 68 70 } 69 71 70 void LpSkeleton::_getColCoeffs(int, ColIterator) {72 void LpSkeleton::_getColCoeffs(int, ColIterator) const { 71 73 } 72 74 … … 75 77 } 76 78 77 LpSkeleton::Value LpSkeleton::_getCoeff(int, int) 79 LpSkeleton::Value LpSkeleton::_getCoeff(int, int) const 78 80 { 79 81 return 0; … … 85 87 } 86 88 87 LpSkeleton::Value LpSkeleton::_getColLowerBound(int) 89 LpSkeleton::Value LpSkeleton::_getColLowerBound(int) const 88 90 { 89 91 return 0; … … 94 96 } 95 97 96 LpSkeleton::Value LpSkeleton::_getColUpperBound(int) 98 LpSkeleton::Value LpSkeleton::_getColUpperBound(int) const 97 99 { 98 100 return 0; … … 111 113 } 112 114 113 void LpSkeleton::_getRowBounds(int, Value&, Value&) 115 void LpSkeleton::_getRowBounds(int, Value&, Value&) const 114 116 { 115 117 } … … 119 121 } 120 122 121 LpSkeleton::Value LpSkeleton::_getObjCoeff(int){ 123 LpSkeleton::Value LpSkeleton::_getObjCoeff(int) const 124 { 122 125 return 0; 123 126 } … … 131 134 } 132 135 133 bool LpSkeleton::_isMax() 136 bool LpSkeleton::_isMax() const 134 137 { 135 138 return true; … … 146 149 } 147 150 148 LpSkeleton::Value LpSkeleton::_getPrimal(int) 151 LpSkeleton::Value LpSkeleton::_getPrimal(int) const 149 152 { 150 153 return 0; 151 154 } 152 155 153 LpSkeleton::Value LpSkeleton::_getDual(int) 156 LpSkeleton::Value LpSkeleton::_getDual(int) const 154 157 { 155 158 return 0; 156 159 } 157 160 158 LpSkeleton::Value LpSkeleton::_getPrimalValue() 161 LpSkeleton::Value LpSkeleton::_getPrimalValue() const 159 162 { 160 163 return 0; 161 164 } 162 165 163 LpSkeleton::SolutionStatus LpSkeleton::_getPrimalStatus() 166 LpSkeleton::SolutionStatus LpSkeleton::_getPrimalStatus() const 164 167 { 165 168 return UNDEFINED; 166 169 } 167 170 168 LpSkeleton::SolutionStatus LpSkeleton::_getDualStatus() 171 LpSkeleton::SolutionStatus LpSkeleton::_getDualStatus() const 169 172 { 170 173 return UNDEFINED; 171 174 } 172 175 173 LpSkeleton::ProblemTypes LpSkeleton::_getProblemType() 176 LpSkeleton::ProblemTypes LpSkeleton::_getProblemType() const 174 177 { 175 178 return UNKNOWN; 176 179 } 177 180 178 bool LpSkeleton::_isBasicCol(int) 181 bool LpSkeleton::_isBasicCol(int) const 179 182 { 180 183 return true; -
lemon/lp_skeleton.h
r2364 r2366 45 45 virtual void _eraseRow(int i); 46 46 /// \e 47 virtual void _getColName(int col, std::string & name) ;47 virtual void _getColName(int col, std::string & name) const; 48 48 /// \e 49 49 virtual void _setColName(int col, const std::string & name); 50 /// \e 51 virtual int _colByName(const std::string& name) const; 50 52 51 53 /// \e 52 54 virtual void _setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e); 53 55 /// \e 54 virtual void _getRowCoeffs(int i, RowIterator b) ;56 virtual void _getRowCoeffs(int i, RowIterator b) const; 55 57 /// \e 56 58 virtual void _setColCoeffs(int i, ConstColIterator b, ConstColIterator e); 57 59 /// \e 58 virtual void _getColCoeffs(int i, ColIterator b) ;60 virtual void _getColCoeffs(int i, ColIterator b) const; 59 61 60 62 /// Set one element of the coefficient matrix … … 62 64 63 65 /// Get one element of the coefficient matrix 64 virtual Value _getCoeff(int row, int col) ;66 virtual Value _getCoeff(int row, int col) const; 65 67 66 68 /// The lower bound of a variable (column) have to be given by an … … 73 75 /// extended number of type Value, i.e. a finite number of type 74 76 /// Value or -\ref INF. 75 virtual Value _getColLowerBound(int i) ;77 virtual Value _getColLowerBound(int i) const; 76 78 77 79 /// The upper bound of a variable (column) have to be given by an … … 84 86 /// extended number of type Value, i.e. a finite number of type 85 87 /// Value or \ref INF. 86 virtual Value _getColUpperBound(int i) ;88 virtual Value _getColUpperBound(int i) const; 87 89 88 90 // /// The lower bound of a linear expression (row) have to be given by an … … 109 111 /// extended numbers of type Value, i.e. finite numbers of type 110 112 /// Value, -\ref INF or \ref INF. 111 virtual void _getRowBounds(int i, Value &lb, Value &ub) ;113 virtual void _getRowBounds(int i, Value &lb, Value &ub) const; 112 114 /// \e 113 115 … … 119 121 120 122 /// \e 121 virtual Value _getObjCoeff(int i) ;123 virtual Value _getObjCoeff(int i) const; 122 124 123 125 ///\e … … 131 133 ///\bug Wrong interface 132 134 /// 133 virtual Value _getPrimal(int i) ;135 virtual Value _getPrimal(int i) const; 134 136 135 137 ///\e … … 137 139 ///\bug Wrong interface 138 140 /// 139 virtual Value _getDual(int i) ;141 virtual Value _getDual(int i) const; 140 142 141 143 ///\e … … 143 145 ///\bug Wrong interface 144 146 /// 145 virtual Value _getPrimalValue() ;147 virtual Value _getPrimalValue() const; 146 148 147 149 ///\e … … 149 151 ///\bug Wrong interface 150 152 /// 151 virtual SolutionStatus _getPrimalStatus() ;153 virtual SolutionStatus _getPrimalStatus() const; 152 154 153 155 ////e 154 virtual SolutionStatus _getDualStatus() ;156 virtual SolutionStatus _getDualStatus() const; 155 157 156 158 157 159 ///\e 158 virtual ProblemTypes _getProblemType() ;160 virtual ProblemTypes _getProblemType() const; 159 161 160 162 ///\e … … 164 166 165 167 ///\e 166 virtual bool _isMax() ;168 virtual bool _isMax() const; 167 169 168 170 169 171 170 172 ///\e 171 virtual bool _isBasicCol(int i) ;173 virtual bool _isBasicCol(int i) const; 172 174 173 175 -
lemon/lp_soplex.cc
r2364 r2366 91 91 } 92 92 93 void LpSoplex::_getColName(int col, std::string &name) {93 void LpSoplex::_getColName(int col, std::string &name) const { 94 94 name = colNames[col]; 95 95 } 96 96 97 97 void LpSoplex::_setColName(int col, const std::string &name) { 98 invColNames.erase(colNames[col]); 98 99 colNames[col] = name; 100 if (!name.empty()) { 101 invColNames.insert(std::make_pair(name, col)); 102 } 103 } 104 105 int LpSoplex::_colByName(const std::string& name) const { 106 std::map<std::string, int>::const_iterator it = 107 invColNames.find(name); 108 if (it != invColNames.end()) { 109 return it->second; 110 } else { 111 return -1; 112 } 99 113 } 100 114 … … 110 124 } 111 125 112 void LpSoplex::_getRowCoeffs(int i, RowIterator b) {126 void LpSoplex::_getRowCoeffs(int i, RowIterator b) const { 113 127 const soplex::SVector& vec = soplex->rowVector(i); 114 128 for (int k = 0; k < vec.size(); ++k) { … … 128 142 } 129 143 130 void LpSoplex::_getColCoeffs(int i, ColIterator b) {144 void LpSoplex::_getColCoeffs(int i, ColIterator b) const { 131 145 const soplex::SVector& vec = soplex->colVector(i); 132 146 for (int k = 0; k < vec.size(); ++k) { … … 141 155 } 142 156 143 LpSoplex::Value LpSoplex::_getCoeff(int i, int j) {157 LpSoplex::Value LpSoplex::_getCoeff(int i, int j) const { 144 158 return soplex->rowVector(i)[j]; 145 159 } … … 150 164 } 151 165 152 LpSoplex::Value LpSoplex::_getColLowerBound(int i) {166 LpSoplex::Value LpSoplex::_getColLowerBound(int i) const { 153 167 double value = soplex->lower(i); 154 168 return value != -soplex::infinity ? value : -INF; … … 160 174 } 161 175 162 LpSoplex::Value LpSoplex::_getColUpperBound(int i) {176 LpSoplex::Value LpSoplex::_getColUpperBound(int i) const { 163 177 double value = soplex->upper(i); 164 178 return value != soplex::infinity ? value : INF; … … 170 184 solved = false; 171 185 } 172 void LpSoplex::_getRowBounds(int i, Value &lower, Value &upper) {186 void LpSoplex::_getRowBounds(int i, Value &lower, Value &upper) const { 173 187 lower = soplex->lhs(i); 174 188 if (lower == -soplex::infinity) lower = -INF; … … 182 196 } 183 197 184 LpSoplex::Value LpSoplex::_getObjCoeff(int i) {198 LpSoplex::Value LpSoplex::_getObjCoeff(int i) const { 185 199 return soplex->obj(i); 186 200 } … … 213 227 } 214 228 215 LpSoplex::Value LpSoplex::_getPrimal(int i) {229 LpSoplex::Value LpSoplex::_getPrimal(int i) const { 216 230 return primal_value[i]; 217 231 } 218 232 219 LpSoplex::Value LpSoplex::_getDual(int i) {233 LpSoplex::Value LpSoplex::_getDual(int i) const { 220 234 return dual_value[i]; 221 235 } 222 236 223 LpSoplex::Value LpSoplex::_getPrimalValue() {237 LpSoplex::Value LpSoplex::_getPrimalValue() const { 224 238 return soplex->objValue(); 225 239 } 226 240 227 bool LpSoplex::_isBasicCol(int i) {241 bool LpSoplex::_isBasicCol(int i) const { 228 242 return soplex->getBasisColStatus(i) == soplex::SPxSolver::BASIC; 229 243 } 230 244 231 LpSoplex::SolutionStatus LpSoplex::_getPrimalStatus() {245 LpSoplex::SolutionStatus LpSoplex::_getPrimalStatus() const { 232 246 if (!solved) return UNDEFINED; 233 247 switch (soplex->status()) { … … 243 257 } 244 258 245 LpSoplex::SolutionStatus LpSoplex::_getDualStatus() {259 LpSoplex::SolutionStatus LpSoplex::_getDualStatus() const { 246 260 if (!solved) return UNDEFINED; 247 261 switch (soplex->status()) { … … 255 269 } 256 270 257 LpSoplex::ProblemTypes LpSoplex::_getProblemType() {271 LpSoplex::ProblemTypes LpSoplex::_getProblemType() const { 258 272 if (!solved) return UNKNOWN; 259 273 switch (soplex->status()) { … … 275 289 solved = false; 276 290 } 277 bool LpSoplex::_isMax() {291 bool LpSoplex::_isMax() const { 278 292 return soplex->spxSense() == soplex::SPxSolver::MAXIMIZE; 279 293 } -
lemon/lp_soplex.h
r2364 r2366 35 35 namespace lemon { 36 36 37 /// \ingroup gen_opt_group 38 /// 37 39 /// \brief Interface for the SOPLEX solver 38 40 /// 39 /// This class implements an interface for the SOPLEX LP solver. 41 /// This class implements an interface for the SoPlex LP solver. 42 /// The SoPlex library is an object oriented lp solver library 43 /// developed at the Konrad-Zuse-Zentrum für Informationstechnik 44 /// Berlin (ZIB). You can find detailed information about it at the 45 /// <tt>http://soplex.zib.de</tt> address. 40 46 class LpSoplex :virtual public LpSolverBase { 41 47 protected: … … 47 53 48 54 std::vector<std::string> colNames; 55 std::map<std::string, int> invColNames; 49 56 50 57 std::vector<Value> primal_value; … … 71 78 virtual void _eraseCol(int i); 72 79 virtual void _eraseRow(int i); 73 virtual void _getColName(int col, std::string & name) ;80 virtual void _getColName(int col, std::string & name) const; 74 81 virtual void _setColName(int col, const std::string & name); 82 virtual int _colByName(const std::string& name) const; 75 83 virtual void _setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e); 76 virtual void _getRowCoeffs(int i, RowIterator b) ;84 virtual void _getRowCoeffs(int i, RowIterator b) const; 77 85 virtual void _setColCoeffs(int i, ConstColIterator b, ConstColIterator e); 78 virtual void _getColCoeffs(int i, ColIterator b) ;86 virtual void _getColCoeffs(int i, ColIterator b) const; 79 87 virtual void _setCoeff(int row, int col, Value value); 80 virtual Value _getCoeff(int row, int col) ;88 virtual Value _getCoeff(int row, int col) const; 81 89 virtual void _setColLowerBound(int i, Value value); 82 virtual Value _getColLowerBound(int i) ;90 virtual Value _getColLowerBound(int i) const; 83 91 virtual void _setColUpperBound(int i, Value value); 84 virtual Value _getColUpperBound(int i) ;92 virtual Value _getColUpperBound(int i) const; 85 93 virtual void _setRowBounds(int i, Value lower, Value upper); 86 virtual void _getRowBounds(int i, Value &lower, Value &upper) ;94 virtual void _getRowBounds(int i, Value &lower, Value &upper) const; 87 95 virtual void _setObjCoeff(int i, Value obj_coef); 88 virtual Value _getObjCoeff(int i) ;96 virtual Value _getObjCoeff(int i) const; 89 97 virtual void _clearObj(); 90 98 91 99 virtual SolveExitStatus _solve(); 92 virtual Value _getPrimal(int i) ;93 virtual Value _getDual(int i) ;94 virtual Value _getPrimalValue() ;95 virtual bool _isBasicCol(int i) ;100 virtual Value _getPrimal(int i) const; 101 virtual Value _getDual(int i) const; 102 virtual Value _getPrimalValue() const; 103 virtual bool _isBasicCol(int i) const; 96 104 97 virtual SolutionStatus _getPrimalStatus() ;98 virtual SolutionStatus _getDualStatus() ;99 virtual ProblemTypes _getProblemType() ;105 virtual SolutionStatus _getPrimalStatus() const; 106 virtual SolutionStatus _getDualStatus() const; 107 virtual ProblemTypes _getProblemType() const; 100 108 101 109 102 110 virtual void _setMax(); 103 111 virtual void _setMin(); 104 virtual bool _isMax() ;112 virtual bool _isMax() const; 105 113 106 114 }; -
lemon/mip_cplex.cc
r2267 r2366 59 59 } 60 60 61 MipCplex::ColTypes MipCplex::_colType(int i) {61 MipCplex::ColTypes MipCplex::_colType(int i) const { 62 62 63 63 char ctype[1]; … … 86 86 87 87 88 LpCplex::SolutionStatus MipCplex::_getMipStatus() {88 LpCplex::SolutionStatus MipCplex::_getMipStatus() const { 89 89 90 90 int stat = CPXgetstat(env, lp); … … 120 120 } 121 121 122 MipCplex::Value MipCplex::_getPrimal(int i) {122 MipCplex::Value MipCplex::_getPrimal(int i) const { 123 123 Value x; 124 124 CPXgetmipx(env, lp, &x, i, i); … … 126 126 } 127 127 128 MipCplex::Value MipCplex::_getPrimalValue() {128 MipCplex::Value MipCplex::_getPrimalValue() const { 129 129 Value objval; 130 130 status = CPXgetmipobjval(env, lp, &objval); -
lemon/mip_cplex.h
r2219 r2366 48 48 protected: 49 49 50 virtual ColTypes _colType(int col) ;50 virtual ColTypes _colType(int col) const; 51 51 virtual void _colType(int col, ColTypes col_type); 52 52 53 53 virtual LpCplex::SolveExitStatus _solve(); 54 virtual LpCplex::SolutionStatus _getMipStatus() ;55 virtual ParentLp::Value _getPrimal(int i) ;56 virtual ParentLp::Value _getPrimalValue() ;54 virtual LpCplex::SolutionStatus _getMipStatus() const; 55 virtual ParentLp::Value _getPrimal(int i) const; 56 virtual ParentLp::Value _getPrimalValue() const; 57 57 }; 58 58 -
lemon/mip_glpk.cc
r2267 r2366 41 41 } 42 42 43 MipGlpk::ColTypes MipGlpk::_colType(int i) {43 MipGlpk::ColTypes MipGlpk::_colType(int i) const { 44 44 switch (lpx_get_col_kind(lp,i)){ 45 45 case LPX_IV: … … 53 53 } 54 54 55 LpGlpk::SolveExitStatus MipGlpk::_solve() {55 LpGlpk::SolveExitStatus MipGlpk::_solve() { 56 56 int result = lpx_simplex(lp); 57 57 // … … 72 72 73 73 74 LpGlpk::SolutionStatus MipGlpk::_getMipStatus() {74 LpGlpk::SolutionStatus MipGlpk::_getMipStatus() const { 75 75 76 76 if (lpx_get_status(lp)==LPX_OPT){ … … 101 101 } 102 102 103 MipGlpk::Value MipGlpk::_getPrimal(int i) {103 MipGlpk::Value MipGlpk::_getPrimal(int i) const { 104 104 return lpx_mip_col_val(lp,i); 105 105 } 106 106 107 MipGlpk::Value MipGlpk::_getPrimalValue() {107 MipGlpk::Value MipGlpk::_getPrimalValue() const { 108 108 return lpx_mip_obj_val(lp); 109 109 } -
lemon/mip_glpk.h
r2218 r2366 46 46 protected: 47 47 48 virtual ColTypes _colType(int col) ;48 virtual ColTypes _colType(int col) const; 49 49 virtual void _colType(int col, ColTypes col_type); 50 50 51 51 virtual LpGlpk::SolveExitStatus _solve(); 52 virtual LpGlpk::SolutionStatus _getMipStatus() ;53 virtual ParentLp::Value _getPrimal(int i) ;54 virtual ParentLp::Value _getPrimalValue() ;52 virtual LpGlpk::SolutionStatus _getMipStatus() const; 53 virtual ParentLp::Value _getPrimal(int i) const; 54 virtual ParentLp::Value _getPrimalValue() const; 55 55 }; 56 56
Note: See TracChangeset
for help on using the changeset viewer.