Changes in lemon/lp_base.h [1092:dceba191c00d:1144:760a5f690163] in lemon-main
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/lp_base.h
r1092 r1144 32 32 #include<lemon/bits/solver_bits.h> 33 33 34 #include<lemon/bits/stl_iterators.h> 35 34 36 ///\file 35 37 ///\brief The interface of the LP solver interface. … … 46 48 protected: 47 49 48 _solver_bits::VarIndex rows;49 _solver_bits::VarIndex cols;50 _solver_bits::VarIndex _rows; 51 _solver_bits::VarIndex _cols; 50 52 51 53 public: … … 167 169 ColIt(const LpBase &solver) : _solver(&solver) 168 170 { 169 _solver-> cols.firstItem(_id);171 _solver->_cols.firstItem(_id); 170 172 } 171 173 /// Invalid constructor \& conversion … … 180 182 ColIt &operator++() 181 183 { 182 _solver-> cols.nextItem(_id);184 _solver->_cols.nextItem(_id); 183 185 return *this; 184 186 } 185 187 }; 188 189 /// \brief Gets the collection of the columns of the LP problem. 190 /// 191 /// This function can be used for iterating on 192 /// the columns of the LP problem. It returns a wrapped ColIt, which looks 193 /// like an STL container (by having begin() and end()) 194 /// which you can use in range-based for loops, STL algorithms, etc. 195 /// For example you can write: 196 ///\code 197 /// for(auto c: lp.cols()) 198 /// doSomething(c); 199 ///\endcode 200 LemonRangeWrapper1<ColIt, LpBase> cols() { 201 return LemonRangeWrapper1<ColIt, LpBase>(*this); 202 } 203 186 204 187 205 /// \brief Returns the ID of the column. … … 262 280 RowIt(const LpBase &solver) : _solver(&solver) 263 281 { 264 _solver-> rows.firstItem(_id);282 _solver->_rows.firstItem(_id); 265 283 } 266 284 /// Invalid constructor \& conversion … … 275 293 RowIt &operator++() 276 294 { 277 _solver-> rows.nextItem(_id);295 _solver->_rows.nextItem(_id); 278 296 return *this; 279 297 } 280 298 }; 299 300 /// \brief Gets the collection of the rows of the LP problem. 301 /// 302 /// This function can be used for iterating on 303 /// the rows of the LP problem. It returns a wrapped RowIt, which looks 304 /// like an STL container (by having begin() and end()) 305 /// which you can use in range-based for loops, STL algorithms, etc. 306 /// For example you can write: 307 ///\code 308 /// for(auto c: lp.rows()) 309 /// doSomething(c); 310 ///\endcode 311 LemonRangeWrapper1<RowIt, LpBase> rows() { 312 return LemonRangeWrapper1<RowIt, LpBase>(*this); 313 } 314 281 315 282 316 /// \brief Returns the ID of the row. … … 626 660 ///This data structure represents a column of the matrix, 627 661 ///thas is it strores a linear expression of the dual variables 628 ///(\ref Row "Row"s).662 ///(\ref LpBase::Row "Row"s). 629 663 /// 630 664 ///There are several ways to access and modify the contents of this … … 643 677 ///(This code computes the sum of all coefficients). 644 678 ///- Numbers (<tt>double</tt>'s) 645 ///and variables (\ref Row "Row"s) directly convert to an679 ///and variables (\ref LpBase::Row "Row"s) directly convert to an 646 680 ///\ref DualExpr and the usual linear operations are defined, so 647 681 ///\code … … 935 969 //Abstract virtual functions 936 970 937 virtual int _addColId(int col) { return cols.addIndex(col); }938 virtual int _addRowId(int row) { return rows.addIndex(row); }939 940 virtual void _eraseColId(int col) { cols.eraseIndex(col); }941 virtual void _eraseRowId(int row) { rows.eraseIndex(row); }971 virtual int _addColId(int col) { return _cols.addIndex(col); } 972 virtual int _addRowId(int row) { return _rows.addIndex(row); } 973 974 virtual void _eraseColId(int col) { _cols.eraseIndex(col); } 975 virtual void _eraseRowId(int row) { _rows.eraseIndex(row); } 942 976 943 977 virtual int _addCol() = 0; … … 1004 1038 Value obj_const_comp; 1005 1039 1006 LpBase() : rows(),cols(), obj_const_comp(0) {}1040 LpBase() : _rows(), _cols(), obj_const_comp(0) {} 1007 1041 1008 1042 public: … … 1116 1150 void col(Col c, const DualExpr &e) { 1117 1151 e.simplify(); 1118 _setColCoeffs( cols(id(c)), ExprIterator(e.comps.begin(),rows),1119 ExprIterator(e.comps.end(), rows));1152 _setColCoeffs(_cols(id(c)), ExprIterator(e.comps.begin(), _rows), 1153 ExprIterator(e.comps.end(), _rows)); 1120 1154 } 1121 1155 … … 1126 1160 DualExpr col(Col c) const { 1127 1161 DualExpr e; 1128 _getColCoeffs( cols(id(c)), InsertIterator(e.comps,rows));1162 _getColCoeffs(_cols(id(c)), InsertIterator(e.comps, _rows)); 1129 1163 return e; 1130 1164 } … … 1155 1189 ///\param t can be 1156 1190 ///- a standard STL compatible iterable container with 1157 ///\ref Rowas its \c values_type like1191 ///\ref LpBase::Row "Row" as its \c values_type like 1158 1192 ///\code 1159 1193 ///std::vector<LpBase::Row> … … 1161 1195 ///\endcode 1162 1196 ///- a standard STL compatible iterable container with 1163 ///\ref Rowas its \c mapped_type like1197 ///\ref LpBase::Row "Row" as its \c mapped_type like 1164 1198 ///\code 1165 1199 ///std::map<AnyType,LpBase::Row> … … 1213 1247 void row(Row r, Value l, const Expr &e, Value u) { 1214 1248 e.simplify(); 1215 _setRowCoeffs( rows(id(r)), ExprIterator(e.comps.begin(),cols),1216 ExprIterator(e.comps.end(), cols));1217 _setRowLowerBound( rows(id(r)),l - *e);1218 _setRowUpperBound( rows(id(r)),u - *e);1249 _setRowCoeffs(_rows(id(r)), ExprIterator(e.comps.begin(), _cols), 1250 ExprIterator(e.comps.end(), _cols)); 1251 _setRowLowerBound(_rows(id(r)),l - *e); 1252 _setRowUpperBound(_rows(id(r)),u - *e); 1219 1253 } 1220 1254 … … 1235 1269 Expr row(Row r) const { 1236 1270 Expr e; 1237 _getRowCoeffs( rows(id(r)), InsertIterator(e.comps,cols));1271 _getRowCoeffs(_rows(id(r)), InsertIterator(e.comps, _cols)); 1238 1272 return e; 1239 1273 } … … 1248 1282 Row r; 1249 1283 e.simplify(); 1250 r._id = _addRowId(_addRow(l - *e, ExprIterator(e.comps.begin(), cols),1251 ExprIterator(e.comps.end(), cols), u - *e));1284 r._id = _addRowId(_addRow(l - *e, ExprIterator(e.comps.begin(), _cols), 1285 ExprIterator(e.comps.end(), _cols), u - *e)); 1252 1286 return r; 1253 1287 } … … 1261 1295 c.expr().simplify(); 1262 1296 r._id = _addRowId(_addRow(c.lowerBounded()?c.lowerBound()-*c.expr():-INF, 1263 ExprIterator(c.expr().comps.begin(), cols),1264 ExprIterator(c.expr().comps.end(), cols),1297 ExprIterator(c.expr().comps.begin(), _cols), 1298 ExprIterator(c.expr().comps.end(), _cols), 1265 1299 c.upperBounded()?c.upperBound()-*c.expr():INF)); 1266 1300 return r; … … 1270 1304 ///\param c is the column to be deleted 1271 1305 void erase(Col c) { 1272 _eraseCol( cols(id(c)));1273 _eraseColId( cols(id(c)));1306 _eraseCol(_cols(id(c))); 1307 _eraseColId(_cols(id(c))); 1274 1308 } 1275 1309 ///Erase a row (i.e a constraint) from the LP … … 1277 1311 ///\param r is the row to be deleted 1278 1312 void erase(Row r) { 1279 _eraseRow( rows(id(r)));1280 _eraseRowId( rows(id(r)));1313 _eraseRow(_rows(id(r))); 1314 _eraseRowId(_rows(id(r))); 1281 1315 } 1282 1316 … … 1287 1321 std::string colName(Col c) const { 1288 1322 std::string name; 1289 _getColName( cols(id(c)), name);1323 _getColName(_cols(id(c)), name); 1290 1324 return name; 1291 1325 } … … 1296 1330 ///\param name The name to be given 1297 1331 void colName(Col c, const std::string& name) { 1298 _setColName( cols(id(c)), name);1332 _setColName(_cols(id(c)), name); 1299 1333 } 1300 1334 … … 1305 1339 Col colByName(const std::string& name) const { 1306 1340 int k = _colByName(name); 1307 return k != -1 ? Col( cols[k]) : Col(INVALID);1341 return k != -1 ? Col(_cols[k]) : Col(INVALID); 1308 1342 } 1309 1343 … … 1314 1348 std::string rowName(Row r) const { 1315 1349 std::string name; 1316 _getRowName( rows(id(r)), name);1350 _getRowName(_rows(id(r)), name); 1317 1351 return name; 1318 1352 } … … 1323 1357 ///\param name The name to be given 1324 1358 void rowName(Row r, const std::string& name) { 1325 _setRowName( rows(id(r)), name);1359 _setRowName(_rows(id(r)), name); 1326 1360 } 1327 1361 … … 1332 1366 Row rowByName(const std::string& name) const { 1333 1367 int k = _rowByName(name); 1334 return k != -1 ? Row( rows[k]) : Row(INVALID);1368 return k != -1 ? Row(_rows[k]) : Row(INVALID); 1335 1369 } 1336 1370 … … 1341 1375 ///\param val is the new value of the coefficient 1342 1376 void coeff(Row r, Col c, Value val) { 1343 _setCoeff( rows(id(r)),cols(id(c)), val);1377 _setCoeff(_rows(id(r)),_cols(id(c)), val); 1344 1378 } 1345 1379 … … 1350 1384 ///\return the corresponding coefficient 1351 1385 Value coeff(Row r, Col c) const { 1352 return _getCoeff( rows(id(r)),cols(id(c)));1386 return _getCoeff(_rows(id(r)),_cols(id(c))); 1353 1387 } 1354 1388 … … 1359 1393 /// Value or -\ref INF. 1360 1394 void colLowerBound(Col c, Value value) { 1361 _setColLowerBound( cols(id(c)),value);1395 _setColLowerBound(_cols(id(c)),value); 1362 1396 } 1363 1397 … … 1368 1402 ///\return The lower bound for column \c c 1369 1403 Value colLowerBound(Col c) const { 1370 return _getColLowerBound( cols(id(c)));1404 return _getColLowerBound(_cols(id(c))); 1371 1405 } 1372 1406 … … 1414 1448 /// Value or \ref INF. 1415 1449 void colUpperBound(Col c, Value value) { 1416 _setColUpperBound( cols(id(c)),value);1450 _setColUpperBound(_cols(id(c)),value); 1417 1451 }; 1418 1452 … … 1423 1457 /// \return The upper bound for column \c c 1424 1458 Value colUpperBound(Col c) const { 1425 return _getColUpperBound( cols(id(c)));1459 return _getColUpperBound(_cols(id(c))); 1426 1460 } 1427 1461 … … 1470 1504 /// Value, -\ref INF or \ref INF. 1471 1505 void colBounds(Col c, Value lower, Value upper) { 1472 _setColLowerBound( cols(id(c)),lower);1473 _setColUpperBound( cols(id(c)),upper);1506 _setColLowerBound(_cols(id(c)),lower); 1507 _setColUpperBound(_cols(id(c)),upper); 1474 1508 } 1475 1509 … … 1516 1550 /// Value or -\ref INF. 1517 1551 void rowLowerBound(Row r, Value value) { 1518 _setRowLowerBound( rows(id(r)),value);1552 _setRowLowerBound(_rows(id(r)),value); 1519 1553 } 1520 1554 … … 1525 1559 ///\return The lower bound for row \c r 1526 1560 Value rowLowerBound(Row r) const { 1527 return _getRowLowerBound( rows(id(r)));1561 return _getRowLowerBound(_rows(id(r))); 1528 1562 } 1529 1563 … … 1534 1568 /// Value or -\ref INF. 1535 1569 void rowUpperBound(Row r, Value value) { 1536 _setRowUpperBound( rows(id(r)),value);1570 _setRowUpperBound(_rows(id(r)),value); 1537 1571 } 1538 1572 … … 1543 1577 ///\return The upper bound for row \c r 1544 1578 Value rowUpperBound(Row r) const { 1545 return _getRowUpperBound( rows(id(r)));1579 return _getRowUpperBound(_rows(id(r))); 1546 1580 } 1547 1581 1548 1582 ///Set an element of the objective function 1549 void objCoeff(Col c, Value v) {_setObjCoeff( cols(id(c)),v); };1583 void objCoeff(Col c, Value v) {_setObjCoeff(_cols(id(c)),v); }; 1550 1584 1551 1585 ///Get an element of the objective function 1552 Value objCoeff(Col c) const { return _getObjCoeff( cols(id(c))); };1586 Value objCoeff(Col c) const { return _getObjCoeff(_cols(id(c))); }; 1553 1587 1554 1588 ///Set the objective function … … 1557 1591 /// 1558 1592 void obj(const Expr& e) { 1559 _setObjCoeffs(ExprIterator(e.comps.begin(), cols),1560 ExprIterator(e.comps.end(), cols));1593 _setObjCoeffs(ExprIterator(e.comps.begin(), _cols), 1594 ExprIterator(e.comps.end(), _cols)); 1561 1595 obj_const_comp = *e; 1562 1596 } … … 1568 1602 Expr obj() const { 1569 1603 Expr e; 1570 _getObjCoeffs(InsertIterator(e.comps, cols));1604 _getObjCoeffs(InsertIterator(e.comps, _cols)); 1571 1605 *e = obj_const_comp; 1572 1606 return e; … … 1587 1621 1588 1622 ///Clear the problem 1589 void clear() { _clear(); rows.clear();cols.clear(); }1623 void clear() { _clear(); _rows.clear(); _cols.clear(); } 1590 1624 1591 1625 /// Set the message level of the solver … … 1930 1964 /// Return the primal value of the column. 1931 1965 /// \pre The problem is solved. 1932 Value primal(Col c) const { return _getPrimal( cols(id(c))); }1966 Value primal(Col c) const { return _getPrimal(_cols(id(c))); } 1933 1967 1934 1968 /// Return the primal value of the expression … … 1957 1991 /// \note Some solvers does not provide primal ray calculation 1958 1992 /// functions. 1959 Value primalRay(Col c) const { return _getPrimalRay( cols(id(c))); }1993 Value primalRay(Col c) const { return _getPrimalRay(_cols(id(c))); } 1960 1994 1961 1995 /// Return the dual value of the row … … 1963 1997 /// Return the dual value of the row. 1964 1998 /// \pre The problem is solved. 1965 Value dual(Row r) const { return _getDual( rows(id(r))); }1999 Value dual(Row r) const { return _getDual(_rows(id(r))); } 1966 2000 1967 2001 /// Return the dual value of the dual expression … … 1991 2025 /// \note Some solvers does not provide dual ray calculation 1992 2026 /// functions. 1993 Value dualRay(Row r) const { return _getDualRay( rows(id(r))); }2027 Value dualRay(Row r) const { return _getDualRay(_rows(id(r))); } 1994 2028 1995 2029 /// Return the basis status of the column 1996 2030 1997 2031 /// \see VarStatus 1998 VarStatus colStatus(Col c) const { return _getColStatus( cols(id(c))); }2032 VarStatus colStatus(Col c) const { return _getColStatus(_cols(id(c))); } 1999 2033 2000 2034 /// Return the basis status of the row 2001 2035 2002 2036 /// \see VarStatus 2003 VarStatus rowStatus(Row r) const { return _getRowStatus( rows(id(r))); }2037 VarStatus rowStatus(Row r) const { return _getRowStatus(_rows(id(r))); } 2004 2038 2005 2039 ///The value of the objective function … … 2081 2115 /// 2082 2116 void colType(Col c, ColTypes col_type) { 2083 _setColType( cols(id(c)),col_type);2117 _setColType(_cols(id(c)),col_type); 2084 2118 } 2085 2119 … … 2089 2123 /// 2090 2124 ColTypes colType(Col c) const { 2091 return _getColType( cols(id(c)));2125 return _getColType(_cols(id(c))); 2092 2126 } 2093 2127 ///@} … … 2106 2140 /// Return the value of the row in the solution. 2107 2141 /// \pre The problem is solved. 2108 Value sol(Col c) const { return _getSol( cols(id(c))); }2142 Value sol(Col c) const { return _getSol(_cols(id(c))); } 2109 2143 2110 2144 /// Return the value of the expression in the solution
Note: See TracChangeset
for help on using the changeset viewer.