Changes in lemon/lp_base.h [1130:0759d974de81:1092:dceba191c00d] in lemon-main
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/lp_base.h
r1130 r1092 32 32 #include<lemon/bits/solver_bits.h> 33 33 34 #include<lemon/bits/stl_iterators.h>35 36 34 ///\file 37 35 ///\brief The interface of the LP solver interface. … … 48 46 protected: 49 47 50 _solver_bits::VarIndex _rows;51 _solver_bits::VarIndex _cols;48 _solver_bits::VarIndex rows; 49 _solver_bits::VarIndex cols; 52 50 53 51 public: … … 169 167 ColIt(const LpBase &solver) : _solver(&solver) 170 168 { 171 _solver-> _cols.firstItem(_id);169 _solver->cols.firstItem(_id); 172 170 } 173 171 /// Invalid constructor \& conversion … … 182 180 ColIt &operator++() 183 181 { 184 _solver-> _cols.nextItem(_id);182 _solver->cols.nextItem(_id); 185 183 return *this; 186 184 } 187 185 }; 188 189 /// \brief Gets the collection of the columns of the LP problem.190 ///191 /// This function can be used for iterating on192 /// the columns of the LP problem. It returns a wrapped ColIt, which looks193 /// 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 ///\code197 /// for(auto c: lp.cols())198 /// doSomething(c);199 LemonRangeWrapper1<ColIt, LpBase> cols() {200 return LemonRangeWrapper1<ColIt, LpBase>(*this);201 }202 203 186 204 187 /// \brief Returns the ID of the column. … … 279 262 RowIt(const LpBase &solver) : _solver(&solver) 280 263 { 281 _solver-> _rows.firstItem(_id);264 _solver->rows.firstItem(_id); 282 265 } 283 266 /// Invalid constructor \& conversion … … 292 275 RowIt &operator++() 293 276 { 294 _solver-> _rows.nextItem(_id);277 _solver->rows.nextItem(_id); 295 278 return *this; 296 279 } 297 280 }; 298 299 /// \brief Gets the collection of the rows of the LP problem.300 ///301 /// This function can be used for iterating on302 /// the rows of the LP problem. It returns a wrapped RowIt, which looks303 /// like an STL container (by having begin() and end())304 /// which you can use in range-based for loops, STL algorithms, etc.305 /// For example you can write:306 ///\code307 /// for(auto c: lp.rows())308 /// doSomething(c);309 LemonRangeWrapper1<RowIt, LpBase> rows() {310 return LemonRangeWrapper1<RowIt, LpBase>(*this);311 }312 313 281 314 282 /// \brief Returns the ID of the row. … … 967 935 //Abstract virtual functions 968 936 969 virtual int _addColId(int col) { return _cols.addIndex(col); }970 virtual int _addRowId(int row) { return _rows.addIndex(row); }971 972 virtual void _eraseColId(int col) { _cols.eraseIndex(col); }973 virtual void _eraseRowId(int row) { _rows.eraseIndex(row); }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); } 974 942 975 943 virtual int _addCol() = 0; … … 1036 1004 Value obj_const_comp; 1037 1005 1038 LpBase() : _rows(), _cols(), obj_const_comp(0) {}1006 LpBase() : rows(), cols(), obj_const_comp(0) {} 1039 1007 1040 1008 public: … … 1148 1116 void col(Col c, const DualExpr &e) { 1149 1117 e.simplify(); 1150 _setColCoeffs( _cols(id(c)), ExprIterator(e.comps.begin(), _rows),1151 ExprIterator(e.comps.end(), _rows));1118 _setColCoeffs(cols(id(c)), ExprIterator(e.comps.begin(), rows), 1119 ExprIterator(e.comps.end(), rows)); 1152 1120 } 1153 1121 … … 1158 1126 DualExpr col(Col c) const { 1159 1127 DualExpr e; 1160 _getColCoeffs( _cols(id(c)), InsertIterator(e.comps, _rows));1128 _getColCoeffs(cols(id(c)), InsertIterator(e.comps, rows)); 1161 1129 return e; 1162 1130 } … … 1245 1213 void row(Row r, Value l, const Expr &e, Value u) { 1246 1214 e.simplify(); 1247 _setRowCoeffs( _rows(id(r)), ExprIterator(e.comps.begin(), _cols),1248 ExprIterator(e.comps.end(), _cols));1249 _setRowLowerBound( _rows(id(r)),l - *e);1250 _setRowUpperBound( _rows(id(r)),u - *e);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); 1251 1219 } 1252 1220 … … 1267 1235 Expr row(Row r) const { 1268 1236 Expr e; 1269 _getRowCoeffs( _rows(id(r)), InsertIterator(e.comps, _cols));1237 _getRowCoeffs(rows(id(r)), InsertIterator(e.comps, cols)); 1270 1238 return e; 1271 1239 } … … 1280 1248 Row r; 1281 1249 e.simplify(); 1282 r._id = _addRowId(_addRow(l - *e, ExprIterator(e.comps.begin(), _cols),1283 ExprIterator(e.comps.end(), _cols), u - *e));1250 r._id = _addRowId(_addRow(l - *e, ExprIterator(e.comps.begin(), cols), 1251 ExprIterator(e.comps.end(), cols), u - *e)); 1284 1252 return r; 1285 1253 } … … 1293 1261 c.expr().simplify(); 1294 1262 r._id = _addRowId(_addRow(c.lowerBounded()?c.lowerBound()-*c.expr():-INF, 1295 ExprIterator(c.expr().comps.begin(), _cols),1296 ExprIterator(c.expr().comps.end(), _cols),1263 ExprIterator(c.expr().comps.begin(), cols), 1264 ExprIterator(c.expr().comps.end(), cols), 1297 1265 c.upperBounded()?c.upperBound()-*c.expr():INF)); 1298 1266 return r; … … 1302 1270 ///\param c is the column to be deleted 1303 1271 void erase(Col c) { 1304 _eraseCol( _cols(id(c)));1305 _eraseColId( _cols(id(c)));1272 _eraseCol(cols(id(c))); 1273 _eraseColId(cols(id(c))); 1306 1274 } 1307 1275 ///Erase a row (i.e a constraint) from the LP … … 1309 1277 ///\param r is the row to be deleted 1310 1278 void erase(Row r) { 1311 _eraseRow( _rows(id(r)));1312 _eraseRowId( _rows(id(r)));1279 _eraseRow(rows(id(r))); 1280 _eraseRowId(rows(id(r))); 1313 1281 } 1314 1282 … … 1319 1287 std::string colName(Col c) const { 1320 1288 std::string name; 1321 _getColName( _cols(id(c)), name);1289 _getColName(cols(id(c)), name); 1322 1290 return name; 1323 1291 } … … 1328 1296 ///\param name The name to be given 1329 1297 void colName(Col c, const std::string& name) { 1330 _setColName( _cols(id(c)), name);1298 _setColName(cols(id(c)), name); 1331 1299 } 1332 1300 … … 1337 1305 Col colByName(const std::string& name) const { 1338 1306 int k = _colByName(name); 1339 return k != -1 ? Col( _cols[k]) : Col(INVALID);1307 return k != -1 ? Col(cols[k]) : Col(INVALID); 1340 1308 } 1341 1309 … … 1346 1314 std::string rowName(Row r) const { 1347 1315 std::string name; 1348 _getRowName( _rows(id(r)), name);1316 _getRowName(rows(id(r)), name); 1349 1317 return name; 1350 1318 } … … 1355 1323 ///\param name The name to be given 1356 1324 void rowName(Row r, const std::string& name) { 1357 _setRowName( _rows(id(r)), name);1325 _setRowName(rows(id(r)), name); 1358 1326 } 1359 1327 … … 1364 1332 Row rowByName(const std::string& name) const { 1365 1333 int k = _rowByName(name); 1366 return k != -1 ? Row( _rows[k]) : Row(INVALID);1334 return k != -1 ? Row(rows[k]) : Row(INVALID); 1367 1335 } 1368 1336 … … 1373 1341 ///\param val is the new value of the coefficient 1374 1342 void coeff(Row r, Col c, Value val) { 1375 _setCoeff( _rows(id(r)),_cols(id(c)), val);1343 _setCoeff(rows(id(r)),cols(id(c)), val); 1376 1344 } 1377 1345 … … 1382 1350 ///\return the corresponding coefficient 1383 1351 Value coeff(Row r, Col c) const { 1384 return _getCoeff( _rows(id(r)),_cols(id(c)));1352 return _getCoeff(rows(id(r)),cols(id(c))); 1385 1353 } 1386 1354 … … 1391 1359 /// Value or -\ref INF. 1392 1360 void colLowerBound(Col c, Value value) { 1393 _setColLowerBound( _cols(id(c)),value);1361 _setColLowerBound(cols(id(c)),value); 1394 1362 } 1395 1363 … … 1400 1368 ///\return The lower bound for column \c c 1401 1369 Value colLowerBound(Col c) const { 1402 return _getColLowerBound( _cols(id(c)));1370 return _getColLowerBound(cols(id(c))); 1403 1371 } 1404 1372 … … 1446 1414 /// Value or \ref INF. 1447 1415 void colUpperBound(Col c, Value value) { 1448 _setColUpperBound( _cols(id(c)),value);1416 _setColUpperBound(cols(id(c)),value); 1449 1417 }; 1450 1418 … … 1455 1423 /// \return The upper bound for column \c c 1456 1424 Value colUpperBound(Col c) const { 1457 return _getColUpperBound( _cols(id(c)));1425 return _getColUpperBound(cols(id(c))); 1458 1426 } 1459 1427 … … 1502 1470 /// Value, -\ref INF or \ref INF. 1503 1471 void colBounds(Col c, Value lower, Value upper) { 1504 _setColLowerBound( _cols(id(c)),lower);1505 _setColUpperBound( _cols(id(c)),upper);1472 _setColLowerBound(cols(id(c)),lower); 1473 _setColUpperBound(cols(id(c)),upper); 1506 1474 } 1507 1475 … … 1548 1516 /// Value or -\ref INF. 1549 1517 void rowLowerBound(Row r, Value value) { 1550 _setRowLowerBound( _rows(id(r)),value);1518 _setRowLowerBound(rows(id(r)),value); 1551 1519 } 1552 1520 … … 1557 1525 ///\return The lower bound for row \c r 1558 1526 Value rowLowerBound(Row r) const { 1559 return _getRowLowerBound( _rows(id(r)));1527 return _getRowLowerBound(rows(id(r))); 1560 1528 } 1561 1529 … … 1566 1534 /// Value or -\ref INF. 1567 1535 void rowUpperBound(Row r, Value value) { 1568 _setRowUpperBound( _rows(id(r)),value);1536 _setRowUpperBound(rows(id(r)),value); 1569 1537 } 1570 1538 … … 1575 1543 ///\return The upper bound for row \c r 1576 1544 Value rowUpperBound(Row r) const { 1577 return _getRowUpperBound( _rows(id(r)));1545 return _getRowUpperBound(rows(id(r))); 1578 1546 } 1579 1547 1580 1548 ///Set an element of the objective function 1581 void objCoeff(Col c, Value v) {_setObjCoeff( _cols(id(c)),v); };1549 void objCoeff(Col c, Value v) {_setObjCoeff(cols(id(c)),v); }; 1582 1550 1583 1551 ///Get an element of the objective function 1584 Value objCoeff(Col c) const { return _getObjCoeff( _cols(id(c))); };1552 Value objCoeff(Col c) const { return _getObjCoeff(cols(id(c))); }; 1585 1553 1586 1554 ///Set the objective function … … 1589 1557 /// 1590 1558 void obj(const Expr& e) { 1591 _setObjCoeffs(ExprIterator(e.comps.begin(), _cols),1592 ExprIterator(e.comps.end(), _cols));1559 _setObjCoeffs(ExprIterator(e.comps.begin(), cols), 1560 ExprIterator(e.comps.end(), cols)); 1593 1561 obj_const_comp = *e; 1594 1562 } … … 1600 1568 Expr obj() const { 1601 1569 Expr e; 1602 _getObjCoeffs(InsertIterator(e.comps, _cols));1570 _getObjCoeffs(InsertIterator(e.comps, cols)); 1603 1571 *e = obj_const_comp; 1604 1572 return e; … … 1619 1587 1620 1588 ///Clear the problem 1621 void clear() { _clear(); _rows.clear(); _cols.clear(); }1589 void clear() { _clear(); rows.clear(); cols.clear(); } 1622 1590 1623 1591 /// Set the message level of the solver … … 1962 1930 /// Return the primal value of the column. 1963 1931 /// \pre The problem is solved. 1964 Value primal(Col c) const { return _getPrimal( _cols(id(c))); }1932 Value primal(Col c) const { return _getPrimal(cols(id(c))); } 1965 1933 1966 1934 /// Return the primal value of the expression … … 1989 1957 /// \note Some solvers does not provide primal ray calculation 1990 1958 /// functions. 1991 Value primalRay(Col c) const { return _getPrimalRay( _cols(id(c))); }1959 Value primalRay(Col c) const { return _getPrimalRay(cols(id(c))); } 1992 1960 1993 1961 /// Return the dual value of the row … … 1995 1963 /// Return the dual value of the row. 1996 1964 /// \pre The problem is solved. 1997 Value dual(Row r) const { return _getDual( _rows(id(r))); }1965 Value dual(Row r) const { return _getDual(rows(id(r))); } 1998 1966 1999 1967 /// Return the dual value of the dual expression … … 2023 1991 /// \note Some solvers does not provide dual ray calculation 2024 1992 /// functions. 2025 Value dualRay(Row r) const { return _getDualRay( _rows(id(r))); }1993 Value dualRay(Row r) const { return _getDualRay(rows(id(r))); } 2026 1994 2027 1995 /// Return the basis status of the column 2028 1996 2029 1997 /// \see VarStatus 2030 VarStatus colStatus(Col c) const { return _getColStatus( _cols(id(c))); }1998 VarStatus colStatus(Col c) const { return _getColStatus(cols(id(c))); } 2031 1999 2032 2000 /// Return the basis status of the row 2033 2001 2034 2002 /// \see VarStatus 2035 VarStatus rowStatus(Row r) const { return _getRowStatus( _rows(id(r))); }2003 VarStatus rowStatus(Row r) const { return _getRowStatus(rows(id(r))); } 2036 2004 2037 2005 ///The value of the objective function … … 2113 2081 /// 2114 2082 void colType(Col c, ColTypes col_type) { 2115 _setColType( _cols(id(c)),col_type);2083 _setColType(cols(id(c)),col_type); 2116 2084 } 2117 2085 … … 2121 2089 /// 2122 2090 ColTypes colType(Col c) const { 2123 return _getColType( _cols(id(c)));2091 return _getColType(cols(id(c))); 2124 2092 } 2125 2093 ///@} … … 2138 2106 /// Return the value of the row in the solution. 2139 2107 /// \pre The problem is solved. 2140 Value sol(Col c) const { return _getSol( _cols(id(c))); }2108 Value sol(Col c) const { return _getSol(cols(id(c))); } 2141 2109 2142 2110 /// Return the value of the expression in the solution
Note: See TracChangeset
for help on using the changeset viewer.