lemon/lp_base.h
changeset 1141 a037254714b3
parent 1092 dceba191c00d
child 1144 760a5f690163
equal deleted inserted replaced
20:162d03c876d4 21:5bacace54e72
    29 #include<lemon/assert.h>
    29 #include<lemon/assert.h>
    30 
    30 
    31 #include<lemon/core.h>
    31 #include<lemon/core.h>
    32 #include<lemon/bits/solver_bits.h>
    32 #include<lemon/bits/solver_bits.h>
    33 
    33 
       
    34 #include<lemon/bits/stl_iterators.h>
       
    35 
    34 ///\file
    36 ///\file
    35 ///\brief The interface of the LP solver interface.
    37 ///\brief The interface of the LP solver interface.
    36 ///\ingroup lp_group
    38 ///\ingroup lp_group
    37 namespace lemon {
    39 namespace lemon {
    38 
    40 
    43   ///\ingroup lp_group
    45   ///\ingroup lp_group
    44   class LpBase {
    46   class LpBase {
    45 
    47 
    46   protected:
    48   protected:
    47 
    49 
    48     _solver_bits::VarIndex rows;
    50     _solver_bits::VarIndex _rows;
    49     _solver_bits::VarIndex cols;
    51     _solver_bits::VarIndex _cols;
    50 
    52 
    51   public:
    53   public:
    52 
    54 
    53     ///Possible outcomes of an LP solving procedure
    55     ///Possible outcomes of an LP solving procedure
    54     enum SolveExitStatus {
    56     enum SolveExitStatus {
   164 
   166 
   165       /// Sets the iterator to the first Col.
   167       /// Sets the iterator to the first Col.
   166       ///
   168       ///
   167       ColIt(const LpBase &solver) : _solver(&solver)
   169       ColIt(const LpBase &solver) : _solver(&solver)
   168       {
   170       {
   169         _solver->cols.firstItem(_id);
   171         _solver->_cols.firstItem(_id);
   170       }
   172       }
   171       /// Invalid constructor \& conversion
   173       /// Invalid constructor \& conversion
   172 
   174 
   173       /// Initialize the iterator to be invalid.
   175       /// Initialize the iterator to be invalid.
   174       /// \sa Invalid for more details.
   176       /// \sa Invalid for more details.
   177 
   179 
   178       /// Assign the iterator to the next column.
   180       /// Assign the iterator to the next column.
   179       ///
   181       ///
   180       ColIt &operator++()
   182       ColIt &operator++()
   181       {
   183       {
   182         _solver->cols.nextItem(_id);
   184         _solver->_cols.nextItem(_id);
   183         return *this;
   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     LemonRangeWrapper1<ColIt, LpBase> cols() {
       
   200       return LemonRangeWrapper1<ColIt, LpBase>(*this);
       
   201     }
       
   202 
   186 
   203 
   187     /// \brief Returns the ID of the column.
   204     /// \brief Returns the ID of the column.
   188     static int id(const Col& col) { return col._id; }
   205     static int id(const Col& col) { return col._id; }
   189     /// \brief Returns the column with the given ID.
   206     /// \brief Returns the column with the given ID.
   190     ///
   207     ///
   259 
   276 
   260       /// Sets the iterator to the first Row.
   277       /// Sets the iterator to the first Row.
   261       ///
   278       ///
   262       RowIt(const LpBase &solver) : _solver(&solver)
   279       RowIt(const LpBase &solver) : _solver(&solver)
   263       {
   280       {
   264         _solver->rows.firstItem(_id);
   281         _solver->_rows.firstItem(_id);
   265       }
   282       }
   266       /// Invalid constructor \& conversion
   283       /// Invalid constructor \& conversion
   267 
   284 
   268       /// Initialize the iterator to be invalid.
   285       /// Initialize the iterator to be invalid.
   269       /// \sa Invalid for more details.
   286       /// \sa Invalid for more details.
   272 
   289 
   273       /// Assign the iterator to the next row.
   290       /// Assign the iterator to the next row.
   274       ///
   291       ///
   275       RowIt &operator++()
   292       RowIt &operator++()
   276       {
   293       {
   277         _solver->rows.nextItem(_id);
   294         _solver->_rows.nextItem(_id);
   278         return *this;
   295         return *this;
   279       }
   296       }
   280     };
   297     };
       
   298     
       
   299     /// \brief Gets the collection of the rows of the LP problem.
       
   300     ///
       
   301     /// This function can be used for iterating on
       
   302     /// the rows of the LP problem. It returns a wrapped RowIt, which looks
       
   303     /// 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     ///\code
       
   307     /// for(auto c: lp.rows())
       
   308     ///   doSomething(c);
       
   309     LemonRangeWrapper1<RowIt, LpBase> rows() {
       
   310       return LemonRangeWrapper1<RowIt, LpBase>(*this);
       
   311     }
       
   312     
   281 
   313 
   282     /// \brief Returns the ID of the row.
   314     /// \brief Returns the ID of the row.
   283     static int id(const Row& row) { return row._id; }
   315     static int id(const Row& row) { return row._id; }
   284     /// \brief Returns the row with the given ID.
   316     /// \brief Returns the row with the given ID.
   285     ///
   317     ///
   932 
   964 
   933   protected:
   965   protected:
   934 
   966 
   935     //Abstract virtual functions
   967     //Abstract virtual functions
   936 
   968 
   937     virtual int _addColId(int col) { return cols.addIndex(col); }
   969     virtual int _addColId(int col) { return _cols.addIndex(col); }
   938     virtual int _addRowId(int row) { return rows.addIndex(row); }
   970     virtual int _addRowId(int row) { return _rows.addIndex(row); }
   939 
   971 
   940     virtual void _eraseColId(int col) { cols.eraseIndex(col); }
   972     virtual void _eraseColId(int col) { _cols.eraseIndex(col); }
   941     virtual void _eraseRowId(int row) { rows.eraseIndex(row); }
   973     virtual void _eraseRowId(int row) { _rows.eraseIndex(row); }
   942 
   974 
   943     virtual int _addCol() = 0;
   975     virtual int _addCol() = 0;
   944     virtual int _addRow() = 0;
   976     virtual int _addRow() = 0;
   945 
   977 
   946     virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
   978     virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
  1001     //Own protected stuff
  1033     //Own protected stuff
  1002 
  1034 
  1003     //Constant component of the objective function
  1035     //Constant component of the objective function
  1004     Value obj_const_comp;
  1036     Value obj_const_comp;
  1005 
  1037 
  1006     LpBase() : rows(), cols(), obj_const_comp(0) {}
  1038     LpBase() : _rows(), _cols(), obj_const_comp(0) {}
  1007 
  1039 
  1008   public:
  1040   public:
  1009 
  1041 
  1010     ///Unsupported file format exception
  1042     ///Unsupported file format exception
  1011     class UnsupportedFormatError : public Exception
  1043     class UnsupportedFormatError : public Exception
  1113     ///\param c is the column to be modified
  1145     ///\param c is the column to be modified
  1114     ///\param e is a dual linear expression (see \ref DualExpr)
  1146     ///\param e is a dual linear expression (see \ref DualExpr)
  1115     ///a better one.
  1147     ///a better one.
  1116     void col(Col c, const DualExpr &e) {
  1148     void col(Col c, const DualExpr &e) {
  1117       e.simplify();
  1149       e.simplify();
  1118       _setColCoeffs(cols(id(c)), ExprIterator(e.comps.begin(), rows),
  1150       _setColCoeffs(_cols(id(c)), ExprIterator(e.comps.begin(), _rows),
  1119                     ExprIterator(e.comps.end(), rows));
  1151                     ExprIterator(e.comps.end(), _rows));
  1120     }
  1152     }
  1121 
  1153 
  1122     ///Get a column (i.e a dual constraint) of the LP
  1154     ///Get a column (i.e a dual constraint) of the LP
  1123 
  1155 
  1124     ///\param c is the column to get
  1156     ///\param c is the column to get
  1125     ///\return the dual expression associated to the column
  1157     ///\return the dual expression associated to the column
  1126     DualExpr col(Col c) const {
  1158     DualExpr col(Col c) const {
  1127       DualExpr e;
  1159       DualExpr e;
  1128       _getColCoeffs(cols(id(c)), InsertIterator(e.comps, rows));
  1160       _getColCoeffs(_cols(id(c)), InsertIterator(e.comps, _rows));
  1129       return e;
  1161       return e;
  1130     }
  1162     }
  1131 
  1163 
  1132     ///Add a new column to the LP
  1164     ///Add a new column to the LP
  1133 
  1165 
  1210     ///\param l is lower bound (-\ref INF means no bound)
  1242     ///\param l is lower bound (-\ref INF means no bound)
  1211     ///\param e is a linear expression (see \ref Expr)
  1243     ///\param e is a linear expression (see \ref Expr)
  1212     ///\param u is the upper bound (\ref INF means no bound)
  1244     ///\param u is the upper bound (\ref INF means no bound)
  1213     void row(Row r, Value l, const Expr &e, Value u) {
  1245     void row(Row r, Value l, const Expr &e, Value u) {
  1214       e.simplify();
  1246       e.simplify();
  1215       _setRowCoeffs(rows(id(r)), ExprIterator(e.comps.begin(), cols),
  1247       _setRowCoeffs(_rows(id(r)), ExprIterator(e.comps.begin(), _cols),
  1216                     ExprIterator(e.comps.end(), cols));
  1248                     ExprIterator(e.comps.end(), _cols));
  1217       _setRowLowerBound(rows(id(r)),l - *e);
  1249       _setRowLowerBound(_rows(id(r)),l - *e);
  1218       _setRowUpperBound(rows(id(r)),u - *e);
  1250       _setRowUpperBound(_rows(id(r)),u - *e);
  1219     }
  1251     }
  1220 
  1252 
  1221     ///Set a row (i.e a constraint) of the LP
  1253     ///Set a row (i.e a constraint) of the LP
  1222 
  1254 
  1223     ///\param r is the row to be modified
  1255     ///\param r is the row to be modified
  1232 
  1264 
  1233     ///\param r is the row to get
  1265     ///\param r is the row to get
  1234     ///\return the expression associated to the row
  1266     ///\return the expression associated to the row
  1235     Expr row(Row r) const {
  1267     Expr row(Row r) const {
  1236       Expr e;
  1268       Expr e;
  1237       _getRowCoeffs(rows(id(r)), InsertIterator(e.comps, cols));
  1269       _getRowCoeffs(_rows(id(r)), InsertIterator(e.comps, _cols));
  1238       return e;
  1270       return e;
  1239     }
  1271     }
  1240 
  1272 
  1241     ///Add a new row (i.e a new constraint) to the LP
  1273     ///Add a new row (i.e a new constraint) to the LP
  1242 
  1274 
  1245     ///\param u is the upper bound (\ref INF means no bound)
  1277     ///\param u is the upper bound (\ref INF means no bound)
  1246     ///\return The created row.
  1278     ///\return The created row.
  1247     Row addRow(Value l,const Expr &e, Value u) {
  1279     Row addRow(Value l,const Expr &e, Value u) {
  1248       Row r;
  1280       Row r;
  1249       e.simplify();
  1281       e.simplify();
  1250       r._id = _addRowId(_addRow(l - *e, ExprIterator(e.comps.begin(), cols),
  1282       r._id = _addRowId(_addRow(l - *e, ExprIterator(e.comps.begin(), _cols),
  1251                                 ExprIterator(e.comps.end(), cols), u - *e));
  1283                                 ExprIterator(e.comps.end(), _cols), u - *e));
  1252       return r;
  1284       return r;
  1253     }
  1285     }
  1254 
  1286 
  1255     ///Add a new row (i.e a new constraint) to the LP
  1287     ///Add a new row (i.e a new constraint) to the LP
  1256 
  1288 
  1258     ///\return The created row.
  1290     ///\return The created row.
  1259     Row addRow(const Constr &c) {
  1291     Row addRow(const Constr &c) {
  1260       Row r;
  1292       Row r;
  1261       c.expr().simplify();
  1293       c.expr().simplify();
  1262       r._id = _addRowId(_addRow(c.lowerBounded()?c.lowerBound()-*c.expr():-INF,
  1294       r._id = _addRowId(_addRow(c.lowerBounded()?c.lowerBound()-*c.expr():-INF,
  1263                                 ExprIterator(c.expr().comps.begin(), cols),
  1295                                 ExprIterator(c.expr().comps.begin(), _cols),
  1264                                 ExprIterator(c.expr().comps.end(), cols),
  1296                                 ExprIterator(c.expr().comps.end(), _cols),
  1265                                 c.upperBounded()?c.upperBound()-*c.expr():INF));
  1297                                 c.upperBounded()?c.upperBound()-*c.expr():INF));
  1266       return r;
  1298       return r;
  1267     }
  1299     }
  1268     ///Erase a column (i.e a variable) from the LP
  1300     ///Erase a column (i.e a variable) from the LP
  1269 
  1301 
  1270     ///\param c is the column to be deleted
  1302     ///\param c is the column to be deleted
  1271     void erase(Col c) {
  1303     void erase(Col c) {
  1272       _eraseCol(cols(id(c)));
  1304       _eraseCol(_cols(id(c)));
  1273       _eraseColId(cols(id(c)));
  1305       _eraseColId(_cols(id(c)));
  1274     }
  1306     }
  1275     ///Erase a row (i.e a constraint) from the LP
  1307     ///Erase a row (i.e a constraint) from the LP
  1276 
  1308 
  1277     ///\param r is the row to be deleted
  1309     ///\param r is the row to be deleted
  1278     void erase(Row r) {
  1310     void erase(Row r) {
  1279       _eraseRow(rows(id(r)));
  1311       _eraseRow(_rows(id(r)));
  1280       _eraseRowId(rows(id(r)));
  1312       _eraseRowId(_rows(id(r)));
  1281     }
  1313     }
  1282 
  1314 
  1283     /// Get the name of a column
  1315     /// Get the name of a column
  1284 
  1316 
  1285     ///\param c is the coresponding column
  1317     ///\param c is the coresponding column
  1286     ///\return The name of the colunm
  1318     ///\return The name of the colunm
  1287     std::string colName(Col c) const {
  1319     std::string colName(Col c) const {
  1288       std::string name;
  1320       std::string name;
  1289       _getColName(cols(id(c)), name);
  1321       _getColName(_cols(id(c)), name);
  1290       return name;
  1322       return name;
  1291     }
  1323     }
  1292 
  1324 
  1293     /// Set the name of a column
  1325     /// Set the name of a column
  1294 
  1326 
  1295     ///\param c is the coresponding column
  1327     ///\param c is the coresponding column
  1296     ///\param name The name to be given
  1328     ///\param name The name to be given
  1297     void colName(Col c, const std::string& name) {
  1329     void colName(Col c, const std::string& name) {
  1298       _setColName(cols(id(c)), name);
  1330       _setColName(_cols(id(c)), name);
  1299     }
  1331     }
  1300 
  1332 
  1301     /// Get the column by its name
  1333     /// Get the column by its name
  1302 
  1334 
  1303     ///\param name The name of the column
  1335     ///\param name The name of the column
  1304     ///\return the proper column or \c INVALID
  1336     ///\return the proper column or \c INVALID
  1305     Col colByName(const std::string& name) const {
  1337     Col colByName(const std::string& name) const {
  1306       int k = _colByName(name);
  1338       int k = _colByName(name);
  1307       return k != -1 ? Col(cols[k]) : Col(INVALID);
  1339       return k != -1 ? Col(_cols[k]) : Col(INVALID);
  1308     }
  1340     }
  1309 
  1341 
  1310     /// Get the name of a row
  1342     /// Get the name of a row
  1311 
  1343 
  1312     ///\param r is the coresponding row
  1344     ///\param r is the coresponding row
  1313     ///\return The name of the row
  1345     ///\return The name of the row
  1314     std::string rowName(Row r) const {
  1346     std::string rowName(Row r) const {
  1315       std::string name;
  1347       std::string name;
  1316       _getRowName(rows(id(r)), name);
  1348       _getRowName(_rows(id(r)), name);
  1317       return name;
  1349       return name;
  1318     }
  1350     }
  1319 
  1351 
  1320     /// Set the name of a row
  1352     /// Set the name of a row
  1321 
  1353 
  1322     ///\param r is the coresponding row
  1354     ///\param r is the coresponding row
  1323     ///\param name The name to be given
  1355     ///\param name The name to be given
  1324     void rowName(Row r, const std::string& name) {
  1356     void rowName(Row r, const std::string& name) {
  1325       _setRowName(rows(id(r)), name);
  1357       _setRowName(_rows(id(r)), name);
  1326     }
  1358     }
  1327 
  1359 
  1328     /// Get the row by its name
  1360     /// Get the row by its name
  1329 
  1361 
  1330     ///\param name The name of the row
  1362     ///\param name The name of the row
  1331     ///\return the proper row or \c INVALID
  1363     ///\return the proper row or \c INVALID
  1332     Row rowByName(const std::string& name) const {
  1364     Row rowByName(const std::string& name) const {
  1333       int k = _rowByName(name);
  1365       int k = _rowByName(name);
  1334       return k != -1 ? Row(rows[k]) : Row(INVALID);
  1366       return k != -1 ? Row(_rows[k]) : Row(INVALID);
  1335     }
  1367     }
  1336 
  1368 
  1337     /// Set an element of the coefficient matrix of the LP
  1369     /// Set an element of the coefficient matrix of the LP
  1338 
  1370 
  1339     ///\param r is the row of the element to be modified
  1371     ///\param r is the row of the element to be modified
  1340     ///\param c is the column of the element to be modified
  1372     ///\param c is the column of the element to be modified
  1341     ///\param val is the new value of the coefficient
  1373     ///\param val is the new value of the coefficient
  1342     void coeff(Row r, Col c, Value val) {
  1374     void coeff(Row r, Col c, Value val) {
  1343       _setCoeff(rows(id(r)),cols(id(c)), val);
  1375       _setCoeff(_rows(id(r)),_cols(id(c)), val);
  1344     }
  1376     }
  1345 
  1377 
  1346     /// Get an element of the coefficient matrix of the LP
  1378     /// Get an element of the coefficient matrix of the LP
  1347 
  1379 
  1348     ///\param r is the row of the element
  1380     ///\param r is the row of the element
  1349     ///\param c is the column of the element
  1381     ///\param c is the column of the element
  1350     ///\return the corresponding coefficient
  1382     ///\return the corresponding coefficient
  1351     Value coeff(Row r, Col c) const {
  1383     Value coeff(Row r, Col c) const {
  1352       return _getCoeff(rows(id(r)),cols(id(c)));
  1384       return _getCoeff(_rows(id(r)),_cols(id(c)));
  1353     }
  1385     }
  1354 
  1386 
  1355     /// Set the lower bound of a column (i.e a variable)
  1387     /// Set the lower bound of a column (i.e a variable)
  1356 
  1388 
  1357     /// The lower bound of a variable (column) has to be given by an
  1389     /// The lower bound of a variable (column) has to be given by an
  1358     /// extended number of type Value, i.e. a finite number of type
  1390     /// extended number of type Value, i.e. a finite number of type
  1359     /// Value or -\ref INF.
  1391     /// Value or -\ref INF.
  1360     void colLowerBound(Col c, Value value) {
  1392     void colLowerBound(Col c, Value value) {
  1361       _setColLowerBound(cols(id(c)),value);
  1393       _setColLowerBound(_cols(id(c)),value);
  1362     }
  1394     }
  1363 
  1395 
  1364     /// Get the lower bound of a column (i.e a variable)
  1396     /// Get the lower bound of a column (i.e a variable)
  1365 
  1397 
  1366     /// This function returns the lower bound for column (variable) \c c
  1398     /// This function returns the lower bound for column (variable) \c c
  1367     /// (this might be -\ref INF as well).
  1399     /// (this might be -\ref INF as well).
  1368     ///\return The lower bound for column \c c
  1400     ///\return The lower bound for column \c c
  1369     Value colLowerBound(Col c) const {
  1401     Value colLowerBound(Col c) const {
  1370       return _getColLowerBound(cols(id(c)));
  1402       return _getColLowerBound(_cols(id(c)));
  1371     }
  1403     }
  1372 
  1404 
  1373     ///\brief Set the lower bound of  several columns
  1405     ///\brief Set the lower bound of  several columns
  1374     ///(i.e variables) at once
  1406     ///(i.e variables) at once
  1375     ///
  1407     ///
  1411 
  1443 
  1412     /// The upper bound of a variable (column) has to be given by an
  1444     /// The upper bound of a variable (column) has to be given by an
  1413     /// extended number of type Value, i.e. a finite number of type
  1445     /// extended number of type Value, i.e. a finite number of type
  1414     /// Value or \ref INF.
  1446     /// Value or \ref INF.
  1415     void colUpperBound(Col c, Value value) {
  1447     void colUpperBound(Col c, Value value) {
  1416       _setColUpperBound(cols(id(c)),value);
  1448       _setColUpperBound(_cols(id(c)),value);
  1417     };
  1449     };
  1418 
  1450 
  1419     /// Get the upper bound of a column (i.e a variable)
  1451     /// Get the upper bound of a column (i.e a variable)
  1420 
  1452 
  1421     /// This function returns the upper bound for column (variable) \c c
  1453     /// This function returns the upper bound for column (variable) \c c
  1422     /// (this might be \ref INF as well).
  1454     /// (this might be \ref INF as well).
  1423     /// \return The upper bound for column \c c
  1455     /// \return The upper bound for column \c c
  1424     Value colUpperBound(Col c) const {
  1456     Value colUpperBound(Col c) const {
  1425       return _getColUpperBound(cols(id(c)));
  1457       return _getColUpperBound(_cols(id(c)));
  1426     }
  1458     }
  1427 
  1459 
  1428     ///\brief Set the upper bound of  several columns
  1460     ///\brief Set the upper bound of  several columns
  1429     ///(i.e variables) at once
  1461     ///(i.e variables) at once
  1430     ///
  1462     ///
  1467     /// The lower and the upper bounds of
  1499     /// The lower and the upper bounds of
  1468     /// a variable (column) have to be given by an
  1500     /// a variable (column) have to be given by an
  1469     /// extended number of type Value, i.e. a finite number of type
  1501     /// extended number of type Value, i.e. a finite number of type
  1470     /// Value, -\ref INF or \ref INF.
  1502     /// Value, -\ref INF or \ref INF.
  1471     void colBounds(Col c, Value lower, Value upper) {
  1503     void colBounds(Col c, Value lower, Value upper) {
  1472       _setColLowerBound(cols(id(c)),lower);
  1504       _setColLowerBound(_cols(id(c)),lower);
  1473       _setColUpperBound(cols(id(c)),upper);
  1505       _setColUpperBound(_cols(id(c)),upper);
  1474     }
  1506     }
  1475 
  1507 
  1476     ///\brief Set the lower and the upper bound of several columns
  1508     ///\brief Set the lower and the upper bound of several columns
  1477     ///(i.e variables) at once
  1509     ///(i.e variables) at once
  1478     ///
  1510     ///
  1513 
  1545 
  1514     /// The lower bound of a constraint (row) has to be given by an
  1546     /// The lower bound of a constraint (row) has to be given by an
  1515     /// extended number of type Value, i.e. a finite number of type
  1547     /// extended number of type Value, i.e. a finite number of type
  1516     /// Value or -\ref INF.
  1548     /// Value or -\ref INF.
  1517     void rowLowerBound(Row r, Value value) {
  1549     void rowLowerBound(Row r, Value value) {
  1518       _setRowLowerBound(rows(id(r)),value);
  1550       _setRowLowerBound(_rows(id(r)),value);
  1519     }
  1551     }
  1520 
  1552 
  1521     /// Get the lower bound of a row (i.e a constraint)
  1553     /// Get the lower bound of a row (i.e a constraint)
  1522 
  1554 
  1523     /// This function returns the lower bound for row (constraint) \c c
  1555     /// This function returns the lower bound for row (constraint) \c c
  1524     /// (this might be -\ref INF as well).
  1556     /// (this might be -\ref INF as well).
  1525     ///\return The lower bound for row \c r
  1557     ///\return The lower bound for row \c r
  1526     Value rowLowerBound(Row r) const {
  1558     Value rowLowerBound(Row r) const {
  1527       return _getRowLowerBound(rows(id(r)));
  1559       return _getRowLowerBound(_rows(id(r)));
  1528     }
  1560     }
  1529 
  1561 
  1530     /// Set the upper bound of a row (i.e a constraint)
  1562     /// Set the upper bound of a row (i.e a constraint)
  1531 
  1563 
  1532     /// The upper bound of a constraint (row) has to be given by an
  1564     /// The upper bound of a constraint (row) has to be given by an
  1533     /// extended number of type Value, i.e. a finite number of type
  1565     /// extended number of type Value, i.e. a finite number of type
  1534     /// Value or -\ref INF.
  1566     /// Value or -\ref INF.
  1535     void rowUpperBound(Row r, Value value) {
  1567     void rowUpperBound(Row r, Value value) {
  1536       _setRowUpperBound(rows(id(r)),value);
  1568       _setRowUpperBound(_rows(id(r)),value);
  1537     }
  1569     }
  1538 
  1570 
  1539     /// Get the upper bound of a row (i.e a constraint)
  1571     /// Get the upper bound of a row (i.e a constraint)
  1540 
  1572 
  1541     /// This function returns the upper bound for row (constraint) \c c
  1573     /// This function returns the upper bound for row (constraint) \c c
  1542     /// (this might be -\ref INF as well).
  1574     /// (this might be -\ref INF as well).
  1543     ///\return The upper bound for row \c r
  1575     ///\return The upper bound for row \c r
  1544     Value rowUpperBound(Row r) const {
  1576     Value rowUpperBound(Row r) const {
  1545       return _getRowUpperBound(rows(id(r)));
  1577       return _getRowUpperBound(_rows(id(r)));
  1546     }
  1578     }
  1547 
  1579 
  1548     ///Set an element of the objective function
  1580     ///Set an element of the objective function
  1549     void objCoeff(Col c, Value v) {_setObjCoeff(cols(id(c)),v); };
  1581     void objCoeff(Col c, Value v) {_setObjCoeff(_cols(id(c)),v); };
  1550 
  1582 
  1551     ///Get an element of the objective function
  1583     ///Get an element of the objective function
  1552     Value objCoeff(Col c) const { return _getObjCoeff(cols(id(c))); };
  1584     Value objCoeff(Col c) const { return _getObjCoeff(_cols(id(c))); };
  1553 
  1585 
  1554     ///Set the objective function
  1586     ///Set the objective function
  1555 
  1587 
  1556     ///\param e is a linear expression of type \ref Expr.
  1588     ///\param e is a linear expression of type \ref Expr.
  1557     ///
  1589     ///
  1558     void obj(const Expr& e) {
  1590     void obj(const Expr& e) {
  1559       _setObjCoeffs(ExprIterator(e.comps.begin(), cols),
  1591       _setObjCoeffs(ExprIterator(e.comps.begin(), _cols),
  1560                     ExprIterator(e.comps.end(), cols));
  1592                     ExprIterator(e.comps.end(), _cols));
  1561       obj_const_comp = *e;
  1593       obj_const_comp = *e;
  1562     }
  1594     }
  1563 
  1595 
  1564     ///Get the objective function
  1596     ///Get the objective function
  1565 
  1597 
  1566     ///\return the objective function as a linear expression of type
  1598     ///\return the objective function as a linear expression of type
  1567     ///Expr.
  1599     ///Expr.
  1568     Expr obj() const {
  1600     Expr obj() const {
  1569       Expr e;
  1601       Expr e;
  1570       _getObjCoeffs(InsertIterator(e.comps, cols));
  1602       _getObjCoeffs(InsertIterator(e.comps, _cols));
  1571       *e = obj_const_comp;
  1603       *e = obj_const_comp;
  1572       return e;
  1604       return e;
  1573     }
  1605     }
  1574 
  1606 
  1575 
  1607 
  1584 
  1616 
  1585     ///Set the sense to maximization
  1617     ///Set the sense to maximization
  1586     void min() { _setSense(MIN); }
  1618     void min() { _setSense(MIN); }
  1587 
  1619 
  1588     ///Clear the problem
  1620     ///Clear the problem
  1589     void clear() { _clear(); rows.clear(); cols.clear(); }
  1621     void clear() { _clear(); _rows.clear(); _cols.clear(); }
  1590 
  1622 
  1591     /// Set the message level of the solver
  1623     /// Set the message level of the solver
  1592     void messageLevel(MessageLevel level) { _messageLevel(level); }
  1624     void messageLevel(MessageLevel level) { _messageLevel(level); }
  1593 
  1625 
  1594     /// Write the problem to a file in the given format
  1626     /// Write the problem to a file in the given format
  1927 
  1959 
  1928     /// Return the primal value of the column
  1960     /// Return the primal value of the column
  1929 
  1961 
  1930     /// Return the primal value of the column.
  1962     /// Return the primal value of the column.
  1931     /// \pre The problem is solved.
  1963     /// \pre The problem is solved.
  1932     Value primal(Col c) const { return _getPrimal(cols(id(c))); }
  1964     Value primal(Col c) const { return _getPrimal(_cols(id(c))); }
  1933 
  1965 
  1934     /// Return the primal value of the expression
  1966     /// Return the primal value of the expression
  1935 
  1967 
  1936     /// Return the primal value of the expression, i.e. the dot
  1968     /// Return the primal value of the expression, i.e. the dot
  1937     /// product of the primal solution and the expression.
  1969     /// product of the primal solution and the expression.
  1954     /// primal problem.
  1986     /// primal problem.
  1955     ///
  1987     ///
  1956     /// \pre The problem is solved and the dual problem is infeasible.
  1988     /// \pre The problem is solved and the dual problem is infeasible.
  1957     /// \note Some solvers does not provide primal ray calculation
  1989     /// \note Some solvers does not provide primal ray calculation
  1958     /// functions.
  1990     /// functions.
  1959     Value primalRay(Col c) const { return _getPrimalRay(cols(id(c))); }
  1991     Value primalRay(Col c) const { return _getPrimalRay(_cols(id(c))); }
  1960 
  1992 
  1961     /// Return the dual value of the row
  1993     /// Return the dual value of the row
  1962 
  1994 
  1963     /// Return the dual value of the row.
  1995     /// Return the dual value of the row.
  1964     /// \pre The problem is solved.
  1996     /// \pre The problem is solved.
  1965     Value dual(Row r) const { return _getDual(rows(id(r))); }
  1997     Value dual(Row r) const { return _getDual(_rows(id(r))); }
  1966 
  1998 
  1967     /// Return the dual value of the dual expression
  1999     /// Return the dual value of the dual expression
  1968 
  2000 
  1969     /// Return the dual value of the dual expression, i.e. the dot
  2001     /// Return the dual value of the dual expression, i.e. the dot
  1970     /// product of the dual solution and the dual expression.
  2002     /// product of the dual solution and the dual expression.
  1988     /// dual problem.
  2020     /// dual problem.
  1989     ///
  2021     ///
  1990     /// \pre The problem is solved and the primal problem is infeasible.
  2022     /// \pre The problem is solved and the primal problem is infeasible.
  1991     /// \note Some solvers does not provide dual ray calculation
  2023     /// \note Some solvers does not provide dual ray calculation
  1992     /// functions.
  2024     /// functions.
  1993     Value dualRay(Row r) const { return _getDualRay(rows(id(r))); }
  2025     Value dualRay(Row r) const { return _getDualRay(_rows(id(r))); }
  1994 
  2026 
  1995     /// Return the basis status of the column
  2027     /// Return the basis status of the column
  1996 
  2028 
  1997     /// \see VarStatus
  2029     /// \see VarStatus
  1998     VarStatus colStatus(Col c) const { return _getColStatus(cols(id(c))); }
  2030     VarStatus colStatus(Col c) const { return _getColStatus(_cols(id(c))); }
  1999 
  2031 
  2000     /// Return the basis status of the row
  2032     /// Return the basis status of the row
  2001 
  2033 
  2002     /// \see VarStatus
  2034     /// \see VarStatus
  2003     VarStatus rowStatus(Row r) const { return _getRowStatus(rows(id(r))); }
  2035     VarStatus rowStatus(Row r) const { return _getRowStatus(_rows(id(r))); }
  2004 
  2036 
  2005     ///The value of the objective function
  2037     ///The value of the objective function
  2006 
  2038 
  2007     ///\return
  2039     ///\return
  2008     ///- \ref INF or -\ref INF means either infeasibility or unboundedness
  2040     ///- \ref INF or -\ref INF means either infeasibility or unboundedness
  2078     ///Sets the type of the given column to the given type
  2110     ///Sets the type of the given column to the given type
  2079 
  2111 
  2080     ///Sets the type of the given column to the given type.
  2112     ///Sets the type of the given column to the given type.
  2081     ///
  2113     ///
  2082     void colType(Col c, ColTypes col_type) {
  2114     void colType(Col c, ColTypes col_type) {
  2083       _setColType(cols(id(c)),col_type);
  2115       _setColType(_cols(id(c)),col_type);
  2084     }
  2116     }
  2085 
  2117 
  2086     ///Gives back the type of the column.
  2118     ///Gives back the type of the column.
  2087 
  2119 
  2088     ///Gives back the type of the column.
  2120     ///Gives back the type of the column.
  2089     ///
  2121     ///
  2090     ColTypes colType(Col c) const {
  2122     ColTypes colType(Col c) const {
  2091       return _getColType(cols(id(c)));
  2123       return _getColType(_cols(id(c)));
  2092     }
  2124     }
  2093     ///@}
  2125     ///@}
  2094 
  2126 
  2095     ///\name Obtain the Solution
  2127     ///\name Obtain the Solution
  2096 
  2128 
  2103 
  2135 
  2104     /// Return the value of the row in the solution
  2136     /// Return the value of the row in the solution
  2105 
  2137 
  2106     ///  Return the value of the row in the solution.
  2138     ///  Return the value of the row in the solution.
  2107     /// \pre The problem is solved.
  2139     /// \pre The problem is solved.
  2108     Value sol(Col c) const { return _getSol(cols(id(c))); }
  2140     Value sol(Col c) const { return _getSol(_cols(id(c))); }
  2109 
  2141 
  2110     /// Return the value of the expression in the solution
  2142     /// Return the value of the expression in the solution
  2111 
  2143 
  2112     /// Return the value of the expression in the solution, i.e. the
  2144     /// Return the value of the expression in the solution, i.e. the
  2113     /// dot product of the solution and the expression.
  2145     /// dot product of the solution and the expression.