COIN-OR::LEMON - Graph Library

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/lp_base.h

    r1092 r1144  
    3232#include<lemon/bits/solver_bits.h>
    3333
     34#include<lemon/bits/stl_iterators.h>
     35
    3436///\file
    3537///\brief The interface of the LP solver interface.
     
    4648  protected:
    4749
    48     _solver_bits::VarIndex rows;
    49     _solver_bits::VarIndex cols;
     50    _solver_bits::VarIndex _rows;
     51    _solver_bits::VarIndex _cols;
    5052
    5153  public:
     
    167169      ColIt(const LpBase &solver) : _solver(&solver)
    168170      {
    169         _solver->cols.firstItem(_id);
     171        _solver->_cols.firstItem(_id);
    170172      }
    171173      /// Invalid constructor \& conversion
     
    180182      ColIt &operator++()
    181183      {
    182         _solver->cols.nextItem(_id);
     184        _solver->_cols.nextItem(_id);
    183185        return *this;
    184186      }
    185187    };
     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
    186204
    187205    /// \brief Returns the ID of the column.
     
    262280      RowIt(const LpBase &solver) : _solver(&solver)
    263281      {
    264         _solver->rows.firstItem(_id);
     282        _solver->_rows.firstItem(_id);
    265283      }
    266284      /// Invalid constructor \& conversion
     
    275293      RowIt &operator++()
    276294      {
    277         _solver->rows.nextItem(_id);
     295        _solver->_rows.nextItem(_id);
    278296        return *this;
    279297      }
    280298    };
     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   
    281315
    282316    /// \brief Returns the ID of the row.
     
    626660    ///This data structure represents a column of the matrix,
    627661    ///thas is it strores a linear expression of the dual variables
    628     ///(\ref Row "Row"s).
     662    ///(\ref LpBase::Row "Row"s).
    629663    ///
    630664    ///There are several ways to access and modify the contents of this
     
    643677    ///(This code computes the sum of all coefficients).
    644678    ///- Numbers (<tt>double</tt>'s)
    645     ///and variables (\ref Row "Row"s) directly convert to an
     679    ///and variables (\ref LpBase::Row "Row"s) directly convert to an
    646680    ///\ref DualExpr and the usual linear operations are defined, so
    647681    ///\code
     
    935969    //Abstract virtual functions
    936970
    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); }
    942976
    943977    virtual int _addCol() = 0;
     
    10041038    Value obj_const_comp;
    10051039
    1006     LpBase() : rows(), cols(), obj_const_comp(0) {}
     1040    LpBase() : _rows(), _cols(), obj_const_comp(0) {}
    10071041
    10081042  public:
     
    11161150    void col(Col c, const DualExpr &e) {
    11171151      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));
    11201154    }
    11211155
     
    11261160    DualExpr col(Col c) const {
    11271161      DualExpr e;
    1128       _getColCoeffs(cols(id(c)), InsertIterator(e.comps, rows));
     1162      _getColCoeffs(_cols(id(c)), InsertIterator(e.comps, _rows));
    11291163      return e;
    11301164    }
     
    11551189    ///\param t can be
    11561190    ///- a standard STL compatible iterable container with
    1157     ///\ref Row as its \c values_type like
     1191    ///\ref LpBase::Row "Row" as its \c values_type like
    11581192    ///\code
    11591193    ///std::vector<LpBase::Row>
     
    11611195    ///\endcode
    11621196    ///- a standard STL compatible iterable container with
    1163     ///\ref Row as its \c mapped_type like
     1197    ///\ref LpBase::Row "Row" as its \c mapped_type like
    11641198    ///\code
    11651199    ///std::map<AnyType,LpBase::Row>
     
    12131247    void row(Row r, Value l, const Expr &e, Value u) {
    12141248      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);
    12191253    }
    12201254
     
    12351269    Expr row(Row r) const {
    12361270      Expr e;
    1237       _getRowCoeffs(rows(id(r)), InsertIterator(e.comps, cols));
     1271      _getRowCoeffs(_rows(id(r)), InsertIterator(e.comps, _cols));
    12381272      return e;
    12391273    }
     
    12481282      Row r;
    12491283      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));
    12521286      return r;
    12531287    }
     
    12611295      c.expr().simplify();
    12621296      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),
    12651299                                c.upperBounded()?c.upperBound()-*c.expr():INF));
    12661300      return r;
     
    12701304    ///\param c is the column to be deleted
    12711305    void erase(Col c) {
    1272       _eraseCol(cols(id(c)));
    1273       _eraseColId(cols(id(c)));
     1306      _eraseCol(_cols(id(c)));
     1307      _eraseColId(_cols(id(c)));
    12741308    }
    12751309    ///Erase a row (i.e a constraint) from the LP
     
    12771311    ///\param r is the row to be deleted
    12781312    void erase(Row r) {
    1279       _eraseRow(rows(id(r)));
    1280       _eraseRowId(rows(id(r)));
     1313      _eraseRow(_rows(id(r)));
     1314      _eraseRowId(_rows(id(r)));
    12811315    }
    12821316
     
    12871321    std::string colName(Col c) const {
    12881322      std::string name;
    1289       _getColName(cols(id(c)), name);
     1323      _getColName(_cols(id(c)), name);
    12901324      return name;
    12911325    }
     
    12961330    ///\param name The name to be given
    12971331    void colName(Col c, const std::string& name) {
    1298       _setColName(cols(id(c)), name);
     1332      _setColName(_cols(id(c)), name);
    12991333    }
    13001334
     
    13051339    Col colByName(const std::string& name) const {
    13061340      int k = _colByName(name);
    1307       return k != -1 ? Col(cols[k]) : Col(INVALID);
     1341      return k != -1 ? Col(_cols[k]) : Col(INVALID);
    13081342    }
    13091343
     
    13141348    std::string rowName(Row r) const {
    13151349      std::string name;
    1316       _getRowName(rows(id(r)), name);
     1350      _getRowName(_rows(id(r)), name);
    13171351      return name;
    13181352    }
     
    13231357    ///\param name The name to be given
    13241358    void rowName(Row r, const std::string& name) {
    1325       _setRowName(rows(id(r)), name);
     1359      _setRowName(_rows(id(r)), name);
    13261360    }
    13271361
     
    13321366    Row rowByName(const std::string& name) const {
    13331367      int k = _rowByName(name);
    1334       return k != -1 ? Row(rows[k]) : Row(INVALID);
     1368      return k != -1 ? Row(_rows[k]) : Row(INVALID);
    13351369    }
    13361370
     
    13411375    ///\param val is the new value of the coefficient
    13421376    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);
    13441378    }
    13451379
     
    13501384    ///\return the corresponding coefficient
    13511385    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)));
    13531387    }
    13541388
     
    13591393    /// Value or -\ref INF.
    13601394    void colLowerBound(Col c, Value value) {
    1361       _setColLowerBound(cols(id(c)),value);
     1395      _setColLowerBound(_cols(id(c)),value);
    13621396    }
    13631397
     
    13681402    ///\return The lower bound for column \c c
    13691403    Value colLowerBound(Col c) const {
    1370       return _getColLowerBound(cols(id(c)));
     1404      return _getColLowerBound(_cols(id(c)));
    13711405    }
    13721406
     
    14141448    /// Value or \ref INF.
    14151449    void colUpperBound(Col c, Value value) {
    1416       _setColUpperBound(cols(id(c)),value);
     1450      _setColUpperBound(_cols(id(c)),value);
    14171451    };
    14181452
     
    14231457    /// \return The upper bound for column \c c
    14241458    Value colUpperBound(Col c) const {
    1425       return _getColUpperBound(cols(id(c)));
     1459      return _getColUpperBound(_cols(id(c)));
    14261460    }
    14271461
     
    14701504    /// Value, -\ref INF or \ref INF.
    14711505    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);
    14741508    }
    14751509
     
    15161550    /// Value or -\ref INF.
    15171551    void rowLowerBound(Row r, Value value) {
    1518       _setRowLowerBound(rows(id(r)),value);
     1552      _setRowLowerBound(_rows(id(r)),value);
    15191553    }
    15201554
     
    15251559    ///\return The lower bound for row \c r
    15261560    Value rowLowerBound(Row r) const {
    1527       return _getRowLowerBound(rows(id(r)));
     1561      return _getRowLowerBound(_rows(id(r)));
    15281562    }
    15291563
     
    15341568    /// Value or -\ref INF.
    15351569    void rowUpperBound(Row r, Value value) {
    1536       _setRowUpperBound(rows(id(r)),value);
     1570      _setRowUpperBound(_rows(id(r)),value);
    15371571    }
    15381572
     
    15431577    ///\return The upper bound for row \c r
    15441578    Value rowUpperBound(Row r) const {
    1545       return _getRowUpperBound(rows(id(r)));
     1579      return _getRowUpperBound(_rows(id(r)));
    15461580    }
    15471581
    15481582    ///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); };
    15501584
    15511585    ///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))); };
    15531587
    15541588    ///Set the objective function
     
    15571591    ///
    15581592    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));
    15611595      obj_const_comp = *e;
    15621596    }
     
    15681602    Expr obj() const {
    15691603      Expr e;
    1570       _getObjCoeffs(InsertIterator(e.comps, cols));
     1604      _getObjCoeffs(InsertIterator(e.comps, _cols));
    15711605      *e = obj_const_comp;
    15721606      return e;
     
    15871621
    15881622    ///Clear the problem
    1589     void clear() { _clear(); rows.clear(); cols.clear(); }
     1623    void clear() { _clear(); _rows.clear(); _cols.clear(); }
    15901624
    15911625    /// Set the message level of the solver
     
    19301964    /// Return the primal value of the column.
    19311965    /// \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))); }
    19331967
    19341968    /// Return the primal value of the expression
     
    19571991    /// \note Some solvers does not provide primal ray calculation
    19581992    /// functions.
    1959     Value primalRay(Col c) const { return _getPrimalRay(cols(id(c))); }
     1993    Value primalRay(Col c) const { return _getPrimalRay(_cols(id(c))); }
    19601994
    19611995    /// Return the dual value of the row
     
    19631997    /// Return the dual value of the row.
    19641998    /// \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))); }
    19662000
    19672001    /// Return the dual value of the dual expression
     
    19912025    /// \note Some solvers does not provide dual ray calculation
    19922026    /// functions.
    1993     Value dualRay(Row r) const { return _getDualRay(rows(id(r))); }
     2027    Value dualRay(Row r) const { return _getDualRay(_rows(id(r))); }
    19942028
    19952029    /// Return the basis status of the column
    19962030
    19972031    /// \see VarStatus
    1998     VarStatus colStatus(Col c) const { return _getColStatus(cols(id(c))); }
     2032    VarStatus colStatus(Col c) const { return _getColStatus(_cols(id(c))); }
    19992033
    20002034    /// Return the basis status of the row
    20012035
    20022036    /// \see VarStatus
    2003     VarStatus rowStatus(Row r) const { return _getRowStatus(rows(id(r))); }
     2037    VarStatus rowStatus(Row r) const { return _getRowStatus(_rows(id(r))); }
    20042038
    20052039    ///The value of the objective function
     
    20812115    ///
    20822116    void colType(Col c, ColTypes col_type) {
    2083       _setColType(cols(id(c)),col_type);
     2117      _setColType(_cols(id(c)),col_type);
    20842118    }
    20852119
     
    20892123    ///
    20902124    ColTypes colType(Col c) const {
    2091       return _getColType(cols(id(c)));
     2125      return _getColType(_cols(id(c)));
    20922126    }
    20932127    ///@}
     
    21062140    ///  Return the value of the row in the solution.
    21072141    /// \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))); }
    21092143
    21102144    /// Return the value of the expression in the solution
Note: See TracChangeset for help on using the changeset viewer.