COIN-OR::LEMON - Graph Library

Changeset 2366:bfbdded3763a in lemon-0.x for lemon/lp_base.h


Ignore:
Timestamp:
02/16/07 20:11:31 (13 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@3181
Message:

Using const in lp interface
colByName functionality

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/lp_base.h

    r2364 r2366  
    136136
    137137    class ColIt : public Col {
    138       LpSolverBase *_lp;
     138      const LpSolverBase *_lp;
    139139    public:
    140140      ColIt() {}
    141       ColIt(LpSolverBase &lp) : _lp(&lp)
     141      ColIt(const LpSolverBase &lp) : _lp(&lp)
    142142      {
    143143        _lp->cols.firstFix(id);
     
    181181
    182182    class RowIt : public Row {
    183       LpSolverBase *_lp;
     183      const LpSolverBase *_lp;
    184184    public:
    185185      RowIt() {}
    186       RowIt(LpSolverBase &lp) : _lp(&lp)
     186      RowIt(const LpSolverBase &lp) : _lp(&lp)
    187187      {
    188188        _lp->rows.firstFix(id);
     
    736736    virtual int _addCol() = 0;
    737737    virtual int _addRow() = 0;
     738
    738739    virtual void _eraseCol(int col) = 0;
    739740    virtual void _eraseRow(int row) = 0;
    740     virtual void _getColName(int col, std::string & name) = 0;
     741
     742    virtual void _getColName(int col, std::string & name) const = 0;
    741743    virtual void _setColName(int col, const std::string & name) = 0;
     744    virtual int _colByName(const std::string& name) const = 0;
     745
    742746    virtual void _setRowCoeffs(int i, ConstRowIterator b,
    743747                               ConstRowIterator e) = 0;
    744     virtual void _getRowCoeffs(int i, RowIterator b) = 0;
     748    virtual void _getRowCoeffs(int i, RowIterator b) const = 0;
    745749    virtual void _setColCoeffs(int i, ConstColIterator b,
    746750                               ConstColIterator e) = 0;
    747     virtual void _getColCoeffs(int i, ColIterator b) = 0;
     751    virtual void _getColCoeffs(int i, ColIterator b) const = 0;
    748752    virtual void _setCoeff(int row, int col, Value value) = 0;
    749     virtual Value _getCoeff(int row, int col) = 0;
     753    virtual Value _getCoeff(int row, int col) const = 0;
    750754    virtual void _setColLowerBound(int i, Value value) = 0;
    751     virtual Value _getColLowerBound(int i) = 0;
     755    virtual Value _getColLowerBound(int i) const = 0;
    752756    virtual void _setColUpperBound(int i, Value value) = 0;
    753     virtual Value _getColUpperBound(int i) = 0;
     757    virtual Value _getColUpperBound(int i) const = 0;
    754758    virtual void _setRowBounds(int i, Value lower, Value upper) = 0;
    755     virtual void _getRowBounds(int i, Value &lower, Value &upper)=0;
     759    virtual void _getRowBounds(int i, Value &lower, Value &upper) const = 0;
    756760
    757761    virtual void _setObjCoeff(int i, Value obj_coef) = 0;
    758     virtual Value _getObjCoeff(int i) = 0;
     762    virtual Value _getObjCoeff(int i) const = 0;
    759763    virtual void _clearObj()=0;
    760764
    761765    virtual SolveExitStatus _solve() = 0;
    762     virtual Value _getPrimal(int i) = 0;
    763     virtual Value _getDual(int i) = 0;
    764     virtual Value _getPrimalValue() = 0;
    765     virtual bool _isBasicCol(int i) = 0;
    766     virtual SolutionStatus _getPrimalStatus() = 0;
    767     virtual SolutionStatus _getDualStatus() = 0;
    768     ///\todo This could be implemented here, too, using _getPrimalStatus() and
    769     ///_getDualStatus()
    770     virtual ProblemTypes _getProblemType() = 0;
     766    virtual Value _getPrimal(int i) const = 0;
     767    virtual Value _getDual(int i) const = 0;
     768    virtual Value _getPrimalValue() const = 0;
     769    virtual bool _isBasicCol(int i) const = 0;
     770    virtual SolutionStatus _getPrimalStatus() const = 0;
     771    virtual SolutionStatus _getDualStatus() const = 0;
     772    virtual ProblemTypes _getProblemType() const = 0;
    771773
    772774    virtual void _setMax() = 0;
     
    774776   
    775777
    776     virtual bool _isMax() = 0;
     778    virtual bool _isMax() const = 0;
    777779
    778780    //Own protected stuff
     
    878880    ///\param r is the column to get
    879881    ///\return the dual expression associated to the column
    880     DualExpr col(Col c) {
     882    DualExpr col(Col c) const {
    881883      DualExpr e;
    882884      _getColCoeffs(_lpId(c), ColIterator(std::inserter(e, e.end()), *this));
     
    975977    ///\todo Option to control whether a constraint with a single variable is
    976978    ///added or not.
    977     void row(Row r, Value l,const Expr &e, Value u) {
     979    void row(Row r, Value l, const Expr &e, Value u) {
    978980      e.simplify();
    979981      _setRowCoeffs(_lpId(r), ConstRowIterator(e.begin(), *this),
     
    996998    ///\param r is the row to get
    997999    ///\return the expression associated to the row
    998     Expr row(Row r) {
     1000    Expr row(Row r) const {
    9991001      Expr e;
    10001002      _getRowCoeffs(_lpId(r), RowIterator(std::inserter(e, e.end()), *this));
     
    10461048    ///\param c is the coresponding coloumn
    10471049    ///\return The name of the colunm
    1048     std::string colName(Col c){
     1050    std::string colName(Col c) const {
    10491051      std::string name;
    10501052      _getColName(_lpId(c), name);
     
    10561058    ///\param c is the coresponding coloumn
    10571059    ///\param name The name to be given
    1058     void colName(Col c, const std::string& name){
     1060    void colName(Col c, const std::string& name) {
    10591061      _setColName(_lpId(c), name);
    10601062    }
     
    10661068    ///\param val is the new value of the coefficient
    10671069
    1068     void coeff(Row r, Col c, Value val){
     1070    void coeff(Row r, Col c, Value val) {
    10691071      _setCoeff(_lpId(r),_lpId(c), val);
    10701072    }
     
    10761078    ///\return the corresponding coefficient
    10771079
    1078     Value coeff(Row r, Col c){
     1080    Value coeff(Row r, Col c) const {
    10791081      return _getCoeff(_lpId(r),_lpId(c));
    10801082    }
     
    10941096    /// (this might be -\ref INF as well). 
    10951097    ///\return The lower bound for coloumn \t c
    1096     Value colLowerBound(Col c) {
     1098    Value colLowerBound(Col c) const {
    10971099      return _getColLowerBound(_lpId(c));
    10981100    }
     
    11491151    /// (this might be \ref INF as well). 
    11501152    ///\return The upper bound for coloumn \t c
    1151     Value colUpperBound(Col c) {
     1153    Value colUpperBound(Col c) const {
    11521154      return _getColUpperBound(_lpId(c));
    11531155    }
     
    12611263    /// implementation of the setting functions for CPLEX: 
    12621264    /// check out whether this can be done for these functions.
    1263     void getRowBounds(Row c, Value &lower, Value &upper) {
     1265    void getRowBounds(Row c, Value &lower, Value &upper) const {
    12641266      _getRowBounds(_lpId(c),lower, upper);
    12651267    }
     
    12691271
    12701272    ///Get an element of the objective function
    1271     Value objCoeff(Col c) {return _getObjCoeff(_lpId(c)); };
     1273    Value objCoeff(Col c) const { return _getObjCoeff(_lpId(c)); };
    12721274
    12731275    ///Set the objective function
     
    12851287
    12861288    ///\return the objective function as a linear expression of type \ref Expr.
    1287     Expr obj() {
     1289    Expr obj() const {
    12881290      Expr e;
    12891291      for (ColIt it(*this); it != INVALID; ++it) {
     
    13031305
    13041306    ///Query function: is this a maximization problem?
    1305     bool is_max() {return _isMax(); }
     1307    bool is_max() const {return _isMax(); }
    13061308
    13071309    ///Query function: is this a minimization problem?
    1308     bool is_min() {return !is_max(); }
     1310    bool is_min() const {return !is_max(); }
    13091311   
    13101312    ///@}
     
    13311333
    13321334    /// The status of the primal problem (the original LP problem)
    1333     SolutionStatus primalStatus() {
     1335    SolutionStatus primalStatus() const {
    13341336      return _getPrimalStatus();
    13351337    }
    13361338
    13371339    /// The status of the dual (of the original LP) problem
    1338     SolutionStatus dualStatus() {
     1340    SolutionStatus dualStatus() const {
    13391341      return _getDualStatus();
    13401342    }
    13411343
    13421344    ///The type of the original LP problem
    1343     ProblemTypes problemType() {
     1345    ProblemTypes problemType() const {
    13441346      return _getProblemType();
    13451347    }
    13461348
    13471349    ///\e
    1348     Value primal(Col c) { return _getPrimal(_lpId(c)); }
     1350    Value primal(Col c) const { return _getPrimal(_lpId(c)); }
    13491351
    13501352    ///\e
    1351     Value dual(Row r) { return _getDual(_lpId(r)); }
     1353    Value dual(Row r) const { return _getDual(_lpId(r)); }
    13521354
    13531355    ///\e
    1354     bool isBasicCol(Col c) { return _isBasicCol(_lpId(c)); }
     1356    bool isBasicCol(Col c) const { return _isBasicCol(_lpId(c)); }
    13551357
    13561358    ///\e
     
    13611363    ///- \ref NaN if no primal solution is found.
    13621364    ///- The (finite) objective value if an optimal solution is found.
    1363     Value primalValue() { return _getPrimalValue()+obj_const_comp;}
     1365    Value primalValue() const { return _getPrimalValue()+obj_const_comp;}
    13641366    ///@}
    13651367   
     
    13951397    ///
    13961398    ///Gives back the type of the column.
    1397     ColTypes colType(Col c){
     1399    ColTypes colType(Col c) const {
    13981400      return _colType(_lpId(c));
    13991401    }
     
    14131415    ///Gives back the type of the column.
    14141416    ///\return true if the column has integer type and false if not.
    1415     bool integer(Col c){
     1417    bool integer(Col c) const {
    14161418      return (colType(c)==INT);
    14171419    }
    14181420
    14191421    /// The status of the MIP problem
    1420     SolutionStatus mipStatus() {
     1422    SolutionStatus mipStatus() const {
    14211423      return _getMipStatus();
    14221424    }
     
    14241426  protected:
    14251427
    1426     virtual ColTypes _colType(int col) = 0;
     1428    virtual ColTypes _colType(int col) const = 0;
    14271429    virtual void _colType(int col, ColTypes col_type) = 0;
    1428     virtual SolutionStatus _getMipStatus()=0;
     1430    virtual SolutionStatus _getMipStatus() const = 0;
    14291431
    14301432  };
Note: See TracChangeset for help on using the changeset viewer.