COIN-OR::LEMON - Graph Library

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/lp_base.h

    r1130 r1092  
    3232#include<lemon/bits/solver_bits.h>
    3333
    34 #include<lemon/bits/stl_iterators.h>
    35 
    3634///\file
    3735///\brief The interface of the LP solver interface.
     
    4846  protected:
    4947
    50     _solver_bits::VarIndex _rows;
    51     _solver_bits::VarIndex _cols;
     48    _solver_bits::VarIndex rows;
     49    _solver_bits::VarIndex cols;
    5250
    5351  public:
     
    169167      ColIt(const LpBase &solver) : _solver(&solver)
    170168      {
    171         _solver->_cols.firstItem(_id);
     169        _solver->cols.firstItem(_id);
    172170      }
    173171      /// Invalid constructor \& conversion
     
    182180      ColIt &operator++()
    183181      {
    184         _solver->_cols.nextItem(_id);
     182        _solver->cols.nextItem(_id);
    185183        return *this;
    186184      }
    187185    };
    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 
    203186
    204187    /// \brief Returns the ID of the column.
     
    279262      RowIt(const LpBase &solver) : _solver(&solver)
    280263      {
    281         _solver->_rows.firstItem(_id);
     264        _solver->rows.firstItem(_id);
    282265      }
    283266      /// Invalid constructor \& conversion
     
    292275      RowIt &operator++()
    293276      {
    294         _solver->_rows.nextItem(_id);
     277        _solver->rows.nextItem(_id);
    295278        return *this;
    296279      }
    297280    };
    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    
    313281
    314282    /// \brief Returns the ID of the row.
     
    967935    //Abstract virtual functions
    968936
    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); }
    974942
    975943    virtual int _addCol() = 0;
     
    10361004    Value obj_const_comp;
    10371005
    1038     LpBase() : _rows(), _cols(), obj_const_comp(0) {}
     1006    LpBase() : rows(), cols(), obj_const_comp(0) {}
    10391007
    10401008  public:
     
    11481116    void col(Col c, const DualExpr &e) {
    11491117      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));
    11521120    }
    11531121
     
    11581126    DualExpr col(Col c) const {
    11591127      DualExpr e;
    1160       _getColCoeffs(_cols(id(c)), InsertIterator(e.comps, _rows));
     1128      _getColCoeffs(cols(id(c)), InsertIterator(e.comps, rows));
    11611129      return e;
    11621130    }
     
    12451213    void row(Row r, Value l, const Expr &e, Value u) {
    12461214      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);
    12511219    }
    12521220
     
    12671235    Expr row(Row r) const {
    12681236      Expr e;
    1269       _getRowCoeffs(_rows(id(r)), InsertIterator(e.comps, _cols));
     1237      _getRowCoeffs(rows(id(r)), InsertIterator(e.comps, cols));
    12701238      return e;
    12711239    }
     
    12801248      Row r;
    12811249      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));
    12841252      return r;
    12851253    }
     
    12931261      c.expr().simplify();
    12941262      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),
    12971265                                c.upperBounded()?c.upperBound()-*c.expr():INF));
    12981266      return r;
     
    13021270    ///\param c is the column to be deleted
    13031271    void erase(Col c) {
    1304       _eraseCol(_cols(id(c)));
    1305       _eraseColId(_cols(id(c)));
     1272      _eraseCol(cols(id(c)));
     1273      _eraseColId(cols(id(c)));
    13061274    }
    13071275    ///Erase a row (i.e a constraint) from the LP
     
    13091277    ///\param r is the row to be deleted
    13101278    void erase(Row r) {
    1311       _eraseRow(_rows(id(r)));
    1312       _eraseRowId(_rows(id(r)));
     1279      _eraseRow(rows(id(r)));
     1280      _eraseRowId(rows(id(r)));
    13131281    }
    13141282
     
    13191287    std::string colName(Col c) const {
    13201288      std::string name;
    1321       _getColName(_cols(id(c)), name);
     1289      _getColName(cols(id(c)), name);
    13221290      return name;
    13231291    }
     
    13281296    ///\param name The name to be given
    13291297    void colName(Col c, const std::string& name) {
    1330       _setColName(_cols(id(c)), name);
     1298      _setColName(cols(id(c)), name);
    13311299    }
    13321300
     
    13371305    Col colByName(const std::string& name) const {
    13381306      int k = _colByName(name);
    1339       return k != -1 ? Col(_cols[k]) : Col(INVALID);
     1307      return k != -1 ? Col(cols[k]) : Col(INVALID);
    13401308    }
    13411309
     
    13461314    std::string rowName(Row r) const {
    13471315      std::string name;
    1348       _getRowName(_rows(id(r)), name);
     1316      _getRowName(rows(id(r)), name);
    13491317      return name;
    13501318    }
     
    13551323    ///\param name The name to be given
    13561324    void rowName(Row r, const std::string& name) {
    1357       _setRowName(_rows(id(r)), name);
     1325      _setRowName(rows(id(r)), name);
    13581326    }
    13591327
     
    13641332    Row rowByName(const std::string& name) const {
    13651333      int k = _rowByName(name);
    1366       return k != -1 ? Row(_rows[k]) : Row(INVALID);
     1334      return k != -1 ? Row(rows[k]) : Row(INVALID);
    13671335    }
    13681336
     
    13731341    ///\param val is the new value of the coefficient
    13741342    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);
    13761344    }
    13771345
     
    13821350    ///\return the corresponding coefficient
    13831351    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)));
    13851353    }
    13861354
     
    13911359    /// Value or -\ref INF.
    13921360    void colLowerBound(Col c, Value value) {
    1393       _setColLowerBound(_cols(id(c)),value);
     1361      _setColLowerBound(cols(id(c)),value);
    13941362    }
    13951363
     
    14001368    ///\return The lower bound for column \c c
    14011369    Value colLowerBound(Col c) const {
    1402       return _getColLowerBound(_cols(id(c)));
     1370      return _getColLowerBound(cols(id(c)));
    14031371    }
    14041372
     
    14461414    /// Value or \ref INF.
    14471415    void colUpperBound(Col c, Value value) {
    1448       _setColUpperBound(_cols(id(c)),value);
     1416      _setColUpperBound(cols(id(c)),value);
    14491417    };
    14501418
     
    14551423    /// \return The upper bound for column \c c
    14561424    Value colUpperBound(Col c) const {
    1457       return _getColUpperBound(_cols(id(c)));
     1425      return _getColUpperBound(cols(id(c)));
    14581426    }
    14591427
     
    15021470    /// Value, -\ref INF or \ref INF.
    15031471    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);
    15061474    }
    15071475
     
    15481516    /// Value or -\ref INF.
    15491517    void rowLowerBound(Row r, Value value) {
    1550       _setRowLowerBound(_rows(id(r)),value);
     1518      _setRowLowerBound(rows(id(r)),value);
    15511519    }
    15521520
     
    15571525    ///\return The lower bound for row \c r
    15581526    Value rowLowerBound(Row r) const {
    1559       return _getRowLowerBound(_rows(id(r)));
     1527      return _getRowLowerBound(rows(id(r)));
    15601528    }
    15611529
     
    15661534    /// Value or -\ref INF.
    15671535    void rowUpperBound(Row r, Value value) {
    1568       _setRowUpperBound(_rows(id(r)),value);
     1536      _setRowUpperBound(rows(id(r)),value);
    15691537    }
    15701538
     
    15751543    ///\return The upper bound for row \c r
    15761544    Value rowUpperBound(Row r) const {
    1577       return _getRowUpperBound(_rows(id(r)));
     1545      return _getRowUpperBound(rows(id(r)));
    15781546    }
    15791547
    15801548    ///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); };
    15821550
    15831551    ///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))); };
    15851553
    15861554    ///Set the objective function
     
    15891557    ///
    15901558    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));
    15931561      obj_const_comp = *e;
    15941562    }
     
    16001568    Expr obj() const {
    16011569      Expr e;
    1602       _getObjCoeffs(InsertIterator(e.comps, _cols));
     1570      _getObjCoeffs(InsertIterator(e.comps, cols));
    16031571      *e = obj_const_comp;
    16041572      return e;
     
    16191587
    16201588    ///Clear the problem
    1621     void clear() { _clear(); _rows.clear(); _cols.clear(); }
     1589    void clear() { _clear(); rows.clear(); cols.clear(); }
    16221590
    16231591    /// Set the message level of the solver
     
    19621930    /// Return the primal value of the column.
    19631931    /// \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))); }
    19651933
    19661934    /// Return the primal value of the expression
     
    19891957    /// \note Some solvers does not provide primal ray calculation
    19901958    /// functions.
    1991     Value primalRay(Col c) const { return _getPrimalRay(_cols(id(c))); }
     1959    Value primalRay(Col c) const { return _getPrimalRay(cols(id(c))); }
    19921960
    19931961    /// Return the dual value of the row
     
    19951963    /// Return the dual value of the row.
    19961964    /// \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))); }
    19981966
    19991967    /// Return the dual value of the dual expression
     
    20231991    /// \note Some solvers does not provide dual ray calculation
    20241992    /// functions.
    2025     Value dualRay(Row r) const { return _getDualRay(_rows(id(r))); }
     1993    Value dualRay(Row r) const { return _getDualRay(rows(id(r))); }
    20261994
    20271995    /// Return the basis status of the column
    20281996
    20291997    /// \see VarStatus
    2030     VarStatus colStatus(Col c) const { return _getColStatus(_cols(id(c))); }
     1998    VarStatus colStatus(Col c) const { return _getColStatus(cols(id(c))); }
    20311999
    20322000    /// Return the basis status of the row
    20332001
    20342002    /// \see VarStatus
    2035     VarStatus rowStatus(Row r) const { return _getRowStatus(_rows(id(r))); }
     2003    VarStatus rowStatus(Row r) const { return _getRowStatus(rows(id(r))); }
    20362004
    20372005    ///The value of the objective function
     
    21132081    ///
    21142082    void colType(Col c, ColTypes col_type) {
    2115       _setColType(_cols(id(c)),col_type);
     2083      _setColType(cols(id(c)),col_type);
    21162084    }
    21172085
     
    21212089    ///
    21222090    ColTypes colType(Col c) const {
    2123       return _getColType(_cols(id(c)));
     2091      return _getColType(cols(id(c)));
    21242092    }
    21252093    ///@}
     
    21382106    ///  Return the value of the row in the solution.
    21392107    /// \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))); }
    21412109
    21422110    /// Return the value of the expression in the solution
Note: See TracChangeset for help on using the changeset viewer.