Changeset 989:38e1d4383262 in lemon-main
- Timestamp:
- 05/06/12 17:18:39 (13 years ago)
- Branch:
- default
- Children:
- 991:a10624ed1997, 1054:c40a9d94442d
- Parents:
- 987:cfbabca1b4e9 (diff), 988:8d281761dea4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Phase:
- public
- Location:
- lemon
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/bits/solver_bits.h
r877 r989 45 45 void clear() { 46 46 first_item = -1; 47 last_item = -1; 47 48 first_free_item = -1; 48 49 items.clear(); -
lemon/bits/solver_bits.h
r988 r989 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 085 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
lemon/cbc.cc
r974 r989 436 436 437 437 _prob = new CoinModel(); 438 rows.clear();439 cols.clear();440 438 } 441 439 -
lemon/cbc.cc
r988 r989 90 90 } 91 91 92 int CbcMip::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) { 93 std::vector<int> indexes; 94 std::vector<Value> values; 95 96 for(ExprIterator it = b; it != e; ++it) { 97 indexes.push_back(it->first); 98 values.push_back(it->second); 99 } 100 101 _prob->addRow(values.size(), &indexes.front(), &values.front(), l, u); 102 return _prob->numberRows() - 1; 103 } 92 104 93 105 void CbcMip::_eraseCol(int i) { -
lemon/clp.cc
r877 r989 438 438 delete _prob; 439 439 _prob = new ClpSimplex(); 440 rows.clear();441 cols.clear();442 440 _col_names_ref.clear(); 443 441 _clear_temporals(); -
lemon/clp.cc
r988 r989 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 085 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 76 76 int ClpLp::_addRow() { 77 77 _prob->addRow(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX); 78 return _prob->numberRows() - 1; 79 } 80 81 int ClpLp::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) { 82 std::vector<int> indexes; 83 std::vector<Value> values; 84 85 for(ExprIterator it = b; it != e; ++it) { 86 indexes.push_back(it->first); 87 values.push_back(it->second); 88 } 89 90 _prob->addRow(values.size(), &indexes.front(), &values.front(), l, u); 78 91 return _prob->numberRows() - 1; 79 92 } -
lemon/cplex.cc
r877 r989 471 471 int status; 472 472 _prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem"); 473 rows.clear();474 cols.clear();475 473 } 476 474 -
lemon/cplex.cc
r988 r989 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 112 112 } 113 113 114 int CplexBase::_addRow(Value lb, ExprIterator b, 115 ExprIterator e, Value ub) { 116 int i = CPXgetnumrows(cplexEnv(), _prob); 117 if (lb == -INF) { 118 const char s = 'L'; 119 CPXnewrows(cplexEnv(), _prob, 1, &ub, &s, 0, 0); 120 } else if (ub == INF) { 121 const char s = 'G'; 122 CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0); 123 } else if (lb == ub){ 124 const char s = 'E'; 125 CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0); 126 } else { 127 const char s = 'R'; 128 double len = ub - lb; 129 CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, &len, 0); 130 } 131 132 std::vector<int> indices; 133 std::vector<int> rowlist; 134 std::vector<Value> values; 135 136 for(ExprIterator it=b; it!=e; ++it) { 137 indices.push_back(it->first); 138 values.push_back(it->second); 139 rowlist.push_back(i); 140 } 141 142 CPXchgcoeflist(cplexEnv(), _prob, values.size(), 143 &rowlist.front(), &indices.front(), &values.front()); 144 145 return i; 146 } 114 147 115 148 void CplexBase::_eraseCol(int i) { … … 455 488 456 489 void CplexBase::_applyMessageLevel() { 457 CPXsetintparam(cplexEnv(), CPX_PARAM_SCRIND, 490 CPXsetintparam(cplexEnv(), CPX_PARAM_SCRIND, 458 491 _message_enabled ? CPX_ON : CPX_OFF); 459 492 } -
lemon/glpk.cc
r877 r989 557 557 void GlpkBase::_clear() { 558 558 glp_erase_prob(lp); 559 rows.clear();560 cols.clear();561 559 } 562 560 -
lemon/glpk.cc
r988 r989 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 57 57 int i = glp_add_rows(lp, 1); 58 58 glp_set_row_bnds(lp, i, GLP_FR, 0.0, 0.0); 59 return i; 60 } 61 62 int GlpkBase::_addRow(Value lo, ExprIterator b, 63 ExprIterator e, Value up) { 64 int i = glp_add_rows(lp, 1); 65 66 if (lo == -INF) { 67 if (up == INF) { 68 glp_set_row_bnds(lp, i, GLP_FR, lo, up); 69 } else { 70 glp_set_row_bnds(lp, i, GLP_UP, lo, up); 71 } 72 } else { 73 if (up == INF) { 74 glp_set_row_bnds(lp, i, GLP_LO, lo, up); 75 } else if (lo != up) { 76 glp_set_row_bnds(lp, i, GLP_DB, lo, up); 77 } else { 78 glp_set_row_bnds(lp, i, GLP_FX, lo, up); 79 } 80 } 81 82 std::vector<int> indexes; 83 std::vector<Value> values; 84 85 indexes.push_back(0); 86 values.push_back(0); 87 88 for(ExprIterator it = b; it != e; ++it) { 89 indexes.push_back(it->first); 90 values.push_back(it->second); 91 } 92 93 glp_set_mat_row(lp, i, values.size() - 1, 94 &indexes.front(), &values.front()); 59 95 return i; 60 96 } -
lemon/lp_base.h
r958 r989 1557 1557 1558 1558 ///Clears the problem 1559 void clear() { _clear(); }1559 void clear() { _clear(); rows.clear(); cols.clear(); } 1560 1560 1561 1561 /// Sets the message level of the solver -
lemon/lp_base.h
r988 r989 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 085 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 83 83 MESSAGE_VERBOSE 84 84 }; 85 85 86 86 87 87 ///The floating point type used by the solver … … 115 115 typedef True LpCol; 116 116 /// Default constructor 117 117 118 118 /// \warning The default constructor sets the Col to an 119 119 /// undefined value. 120 120 Col() {} 121 121 /// Invalid constructor \& conversion. 122 122 123 123 /// This constructor initializes the Col to be invalid. 124 /// \sa Invalid for more details. 124 /// \sa Invalid for more details. 125 125 Col(const Invalid&) : _id(-1) {} 126 126 /// Equality operator … … 147 147 ///Iterator for iterate over the columns of an LP problem 148 148 149 /// Its usage is quite simple, for example you can count the number149 /// Its usage is quite simple, for example, you can count the number 150 150 /// of columns in an LP \c lp: 151 151 ///\code … … 157 157 public: 158 158 /// Default constructor 159 159 160 160 /// \warning The default constructor sets the iterator 161 161 /// to an undefined value. 162 162 ColIt() {} 163 163 /// Sets the iterator to the first Col 164 164 165 165 /// Sets the iterator to the first Col. 166 166 /// … … 170 170 } 171 171 /// Invalid constructor \& conversion 172 172 173 173 /// Initialize the iterator to be invalid. 174 174 /// \sa Invalid for more details. 175 175 ColIt(const Invalid&) : Col(INVALID) {} 176 176 /// Next column 177 177 178 178 /// Assign the iterator to the next column. 179 179 /// … … 210 210 typedef True LpRow; 211 211 /// Default constructor 212 212 213 213 /// \warning The default constructor sets the Row to an 214 214 /// undefined value. 215 215 Row() {} 216 216 /// Invalid constructor \& conversion. 217 217 218 218 /// This constructor initializes the Row to be invalid. 219 /// \sa Invalid for more details. 219 /// \sa Invalid for more details. 220 220 Row(const Invalid&) : _id(-1) {} 221 221 /// Equality operator … … 225 225 bool operator==(Row r) const {return _id == r._id;} 226 226 /// Inequality operator 227 227 228 228 /// \sa operator==(Row r) 229 229 /// … … 242 242 ///Iterator for iterate over the rows of an LP problem 243 243 244 /// Its usage is quite simple, for example you can count the number244 /// Its usage is quite simple, for example, you can count the number 245 245 /// of rows in an LP \c lp: 246 246 ///\code … … 252 252 public: 253 253 /// Default constructor 254 254 255 255 /// \warning The default constructor sets the iterator 256 256 /// to an undefined value. 257 257 RowIt() {} 258 258 /// Sets the iterator to the first Row 259 259 260 260 /// Sets the iterator to the first Row. 261 261 /// … … 265 265 } 266 266 /// Invalid constructor \& conversion 267 267 268 268 /// Initialize the iterator to be invalid. 269 269 /// \sa Invalid for more details. 270 270 RowIt(const Invalid&) : Row(INVALID) {} 271 271 /// Next row 272 272 273 273 /// Assign the iterator to the next row. 274 274 /// … … 348 348 typedef True SolverExpr; 349 349 /// Default constructor 350 350 351 351 /// Construct an empty expression, the coefficients and 352 352 /// the constant component are initialized to zero. … … 449 449 450 450 ///Iterator over the expression 451 452 ///The iterator iterates over the terms of the expression. 453 /// 451 452 ///The iterator iterates over the terms of the expression. 453 /// 454 454 ///\code 455 455 ///double s=0; … … 465 465 466 466 /// Sets the iterator to the first term 467 467 468 468 /// Sets the iterator to the first term of the expression. 469 469 /// … … 482 482 const Value& operator*() const { return _it->second; } 483 483 /// Next term 484 484 485 485 /// Assign the iterator to the next term. 486 486 /// … … 494 494 495 495 /// Const iterator over the expression 496 497 ///The iterator iterates over the terms of the expression. 498 /// 496 497 ///The iterator iterates over the terms of the expression. 498 /// 499 499 ///\code 500 500 ///double s=0; … … 510 510 511 511 /// Sets the iterator to the first term 512 512 513 513 /// Sets the iterator to the first term of the expression. 514 514 /// … … 525 525 526 526 /// Next term 527 527 528 528 /// Assign the iterator to the next term. 529 529 /// … … 674 674 typedef True SolverExpr; 675 675 /// Default constructor 676 676 677 677 /// Construct an empty expression, the coefficients are 678 678 /// initialized to zero. … … 709 709 } 710 710 /// \brief Removes the coefficients which's absolute value does 711 /// not exceed \c epsilon. 711 /// not exceed \c epsilon. 712 712 void simplify(Value epsilon = 0.0) { 713 713 std::map<int, Value>::iterator it=comps.begin(); … … 758 758 759 759 ///Iterator over the expression 760 761 ///The iterator iterates over the terms of the expression. 762 /// 760 761 ///The iterator iterates over the terms of the expression. 762 /// 763 763 ///\code 764 764 ///double s=0; … … 774 774 775 775 /// Sets the iterator to the first term 776 776 777 777 /// Sets the iterator to the first term of the expression. 778 778 /// … … 792 792 793 793 /// Next term 794 794 795 795 /// Assign the iterator to the next term. 796 796 /// … … 804 804 805 805 ///Iterator over the expression 806 807 ///The iterator iterates over the terms of the expression. 808 /// 806 807 ///The iterator iterates over the terms of the expression. 808 /// 809 809 ///\code 810 810 ///double s=0; … … 820 820 821 821 /// Sets the iterator to the first term 822 822 823 823 /// Sets the iterator to the first term of the expression. 824 824 /// … … 835 835 836 836 /// Next term 837 837 838 838 /// Assign the iterator to the next term. 839 839 /// … … 943 943 virtual int _addCol() = 0; 944 944 virtual int _addRow() = 0; 945 946 virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u) { 947 int row = _addRow(); 948 _setRowCoeffs(row, b, e); 949 _setRowLowerBound(row, l); 950 _setRowUpperBound(row, u); 951 return row; 952 } 945 953 946 954 virtual void _eraseCol(int col) = 0; … … 1208 1216 ///\return The created row. 1209 1217 Row addRow(Value l,const Expr &e, Value u) { 1210 Row r=addRow(); 1211 row(r,l,e,u); 1218 Row r; 1219 e.simplify(); 1220 r._id = _addRowId(_addRow(l - *e, ExprIterator(e.comps.begin(), cols), 1221 ExprIterator(e.comps.end(), cols), u - *e)); 1212 1222 return r; 1213 1223 } … … 1218 1228 ///\return The created row. 1219 1229 Row addRow(const Constr &c) { 1220 Row r=addRow(); 1221 row(r,c); 1230 Row r; 1231 c.expr().simplify(); 1232 r._id = _addRowId(_addRow(c.lowerBounded()?c.lowerBound()-*c.expr():-INF, 1233 ExprIterator(c.expr().comps.begin(), cols), 1234 ExprIterator(c.expr().comps.end(), cols), 1235 c.upperBounded()?c.upperBound()-*c.expr():INF)); 1222 1236 return r; 1223 1237 } … … 1804 1818 enum VarStatus { 1805 1819 /// The variable is in the basis 1806 BASIC, 1820 BASIC, 1807 1821 /// The variable is free, but not basic 1808 1822 FREE, 1809 /// The variable has active lower bound 1823 /// The variable has active lower bound 1810 1824 LOWER, 1811 1825 /// The variable has active upper bound … … 1886 1900 } 1887 1901 /// Returns a component of the primal ray 1888 1902 1889 1903 /// The primal ray is solution of the modified primal problem, 1890 1904 /// where we change each finite bound to 0, and we looking for a … … 1920 1934 1921 1935 /// Returns a component of the dual ray 1922 1936 1923 1937 /// The dual ray is solution of the modified primal problem, where 1924 1938 /// we change each finite bound to 0 (i.e. the objective function … … 2062 2076 } 2063 2077 ///The value of the objective function 2064 2078 2065 2079 ///\return 2066 2080 ///- \ref INF or -\ref INF means either infeasibility or unboundedness
Note: See TracChangeset
for help on using the changeset viewer.