COIN-OR::LEMON - Graph Library

Changeset 2366:bfbdded3763a in lemon-0.x


Ignore:
Timestamp:
02/16/07 20:11:31 (17 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

Location:
lemon
Files:
13 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  };
  • lemon/lp_cplex.cc

    r2364 r2366  
    8585  }
    8686 
    87   void LpCplex::_getColName(int col, std::string &name)
     87  void LpCplex::_getColName(int col, std::string &name) const
    8888  {
    8989    ///\bug Untested
     
    108108    CPXchgcolname(env, lp, 1, &col, names);   
    109109  }
     110
     111  int LpCplex::_colByName(const std::string& name) const
     112  {
     113    int index;
     114    if (CPXgetcolindex(env, lp,
     115                       const_cast<char*>(name.c_str()), &index) == 0) {
     116      return index;
     117    }
     118    return -1;
     119  }
    110120 
    111121  ///\warning Data at index 0 is ignored in the arrays.
     
    126136  }
    127137
    128   void LpSoplex::_getRowCoeffs(int i, RowIterator b) {
     138  void LpSoplex::_getRowCoeffs(int i, RowIterator b) const {
    129139    /// \todo implement
    130140  }
     
    146156  }
    147157
    148   void LpSoplex::_getColCoeffs(int i, ColIterator b) {
     158  void LpSoplex::_getColCoeffs(int i, ColIterator b) const {
    149159    /// \todo implement
    150160  }
     
    155165  }
    156166
    157   LpCplex::Value LpCplex::_getCoeff(int row, int col)
     167  LpCplex::Value LpCplex::_getCoeff(int row, int col) const
    158168  {
    159169    LpCplex::Value value;
     
    174184  }
    175185
    176   LpCplex::Value LpCplex::_getColLowerBound(int i)
     186  LpCplex::Value LpCplex::_getColLowerBound(int i) const
    177187  {
    178188    LpCplex::Value x;
     
    192202  }
    193203
    194   LpCplex::Value LpCplex::_getColUpperBound(int i)
     204  LpCplex::Value LpCplex::_getColUpperBound(int i) const
    195205  {
    196206    LpCplex::Value x;
     
    271281//   }
    272282 
    273   void LpCplex::_getRowBounds(int i, Value &lb, Value &ub)
     283  void LpCplex::_getRowBounds(int i, Value &lb, Value &ub) const
    274284  {
    275285    char sense;
     
    303313  }
    304314
    305   LpCplex::Value LpCplex::_getObjCoeff(int i)
     315  LpCplex::Value LpCplex::_getObjCoeff(int i) const
    306316  {
    307317    Value x;
     
    368378  }
    369379
    370   LpCplex::Value LpCplex::_getPrimal(int i)
     380  LpCplex::Value LpCplex::_getPrimal(int i) const
    371381  {
    372382    Value x;
     
    375385  }
    376386
    377   LpCplex::Value LpCplex::_getDual(int i)
     387  LpCplex::Value LpCplex::_getDual(int i) const
    378388  {
    379389    Value y;
     
    382392  }
    383393 
    384   LpCplex::Value LpCplex::_getPrimalValue()
     394  LpCplex::Value LpCplex::_getPrimalValue() const
    385395  {
    386396    Value objval;
     
    391401    return objval;
    392402  }
    393   bool LpCplex::_isBasicCol(int i) {
     403  bool LpCplex::_isBasicCol(int i) const
     404  {
    394405    int cstat[CPXgetnumcols(env, lp)];
    395406    CPXgetbase(env, lp, cstat, NULL);
     
    459470// Description: Method for linear optimization.
    460471// Determines which algorithm is used when CPXlpopt() (or "optimize" in the Interactive Optimizer) is called. Currently the behavior of the "Automatic" setting is that CPLEX simply invokes the dual simplex method, but this capability may be expanded in the future so that CPLEX chooses the method based on problem characteristics
    461   //Hulye cplex
    462472  void statusSwitch(CPXENVptr env,int& stat){
    463473#if CPX_VERSION < 900
     
    476486  }
    477487
    478   LpCplex::SolutionStatus LpCplex::_getPrimalStatus()
     488  LpCplex::SolutionStatus LpCplex::_getPrimalStatus() const
    479489  {
    480490    //Unboundedness not treated well: the following is from cplex 9.0 doc
     
    559569// CPX_STAT_UNBOUNDED
    560570
    561   LpCplex::SolutionStatus LpCplex::_getDualStatus()
     571  LpCplex::SolutionStatus LpCplex::_getDualStatus() const
    562572  {
    563573    int stat = CPXgetstat(env, lp);
     
    588598  }
    589599
    590   LpCplex::ProblemTypes LpCplex::_getProblemType()
     600  LpCplex::ProblemTypes LpCplex::_getProblemType() const
    591601  {
    592602    int stat = CPXgetstat(env, lp);
     
    628638   }
    629639
    630   bool LpCplex::_isMax()
     640  bool LpCplex::_isMax() const
    631641  {
    632642    if (CPXgetobjsen(env, lp)==CPX_MAX)
  • lemon/lp_cplex.h

    r2364 r2366  
    6161    virtual void _eraseCol(int i);
    6262    virtual void _eraseRow(int i);
    63     virtual void _getColName(int col,       std::string & name);
     63    virtual void _getColName(int col, std::string & name) const;
    6464    virtual void _setColName(int col, const std::string & name);
     65    virtual int _colByName(const std::string& name) const;
    6566    virtual void _setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e);
    66     virtual void _getRowCoeffs(int i, RowIterator b);
     67    virtual void _getRowCoeffs(int i, RowIterator b) const;
    6768    virtual void _setColCoeffs(int i, ConstColIterator b, ConstColIterator e);
    68     virtual void _getColCoeffs(int i, ColIterator b);
     69    virtual void _getColCoeffs(int i, ColIterator b) const;
    6970    virtual void _setCoeff(int row, int col, Value value);
    70     virtual Value _getCoeff(int row, int col);
     71    virtual Value _getCoeff(int row, int col) const;
    7172
    7273    virtual void _setColLowerBound(int i, Value value);
    73     virtual Value _getColLowerBound(int i);
     74    virtual Value _getColLowerBound(int i) const;
    7475    virtual void _setColUpperBound(int i, Value value);
    75     virtual Value _getColUpperBound(int i);
     76    virtual Value _getColUpperBound(int i) const;
    7677
    7778//     virtual void _setRowLowerBound(int i, Value value);
    7879//     virtual void _setRowUpperBound(int i, Value value);
    7980    virtual void _setRowBounds(int i, Value lower, Value upper);
    80     virtual void _getRowBounds(int i, Value &lb, Value &ub);
     81    virtual void _getRowBounds(int i, Value &lb, Value &ub) const;
    8182    virtual void _setObjCoeff(int i, Value obj_coef);
    82     virtual Value _getObjCoeff(int i);
     83    virtual Value _getObjCoeff(int i) const;
    8384    virtual void _clearObj();
    8485
    8586   
    8687    virtual SolveExitStatus _solve();
    87     virtual Value _getPrimal(int i);
    88     virtual Value _getDual(int i);
    89     virtual Value _getPrimalValue();
    90     virtual bool _isBasicCol(int i);
     88    virtual Value _getPrimal(int i) const;
     89    virtual Value _getDual(int i) const;
     90    virtual Value _getPrimalValue() const;
     91    virtual bool _isBasicCol(int i) const;
    9192   
    92     virtual SolutionStatus _getPrimalStatus();
    93     virtual SolutionStatus _getDualStatus();
    94     virtual ProblemTypes _getProblemType();
     93    virtual SolutionStatus _getPrimalStatus() const;
     94    virtual SolutionStatus _getDualStatus() const;
     95    virtual ProblemTypes _getProblemType() const;
    9596
    9697   
     
    9899    virtual void _setMin();
    99100
    100     virtual bool _isMax();
     101    virtual bool _isMax() const;
    101102
    102103  };
  • lemon/lp_glpk.cc

    r2364 r2366  
    3838    cols = _lp_bits::LpId(1);
    3939    lp = lpx_create_prob();
     40    lpx_create_index(lp);
    4041    ///\todo control function for this:
    4142    lpx_set_int_parm(lp, LPX_K_DUAL, 1);
     
    113114  }
    114115
    115   void LpGlpk::_getColName(int col, std::string & name)
     116  void LpGlpk::_getColName(int col, std::string & name) const
    116117  {
    117118   
     
    126127
    127128  }
     129
     130  int LpGlpk::_colByName(const std::string& name) const
     131  {
     132    int k = lpx_find_col(lp, const_cast<char*>(name.c_str()));
     133    return k > 0 ? k : -1;
     134  }
     135
    128136 
    129137  void LpGlpk::_setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e)
     
    143151  }
    144152
    145   void LpGlpk::_getRowCoeffs(int i, RowIterator b)
     153  void LpGlpk::_getRowCoeffs(int i, RowIterator b) const
    146154  {
    147155    int length = lpx_get_mat_row(lp, i, 0, 0);
     
    174182  }
    175183
    176   void LpGlpk::_getColCoeffs(int i, ColIterator b)
     184  void LpGlpk::_getColCoeffs(int i, ColIterator b) const
    177185  {
    178186    int length = lpx_get_mat_col(lp, i, 0, 0);
     
    248256  }
    249257
    250   LpGlpk::Value LpGlpk::_getCoeff(int row, int col)
     258  LpGlpk::Value LpGlpk::_getCoeff(int row, int col) const
    251259  {
    252260
     
    313321  }
    314322
    315   LpGlpk::Value LpGlpk::_getColLowerBound(int i)
     323  LpGlpk::Value LpGlpk::_getColLowerBound(int i) const
    316324  {
    317325    int b=lpx_get_col_type(lp, i);
     
    370378  }
    371379
    372   LpGlpk::Value LpGlpk::_getColUpperBound(int i)
     380  LpGlpk::Value LpGlpk::_getColUpperBound(int i) const
    373381  {
    374382    int b=lpx_get_col_type(lp, i);
     
    415423  }
    416424
    417   void LpGlpk::_getRowBounds(int i, Value &lb, Value &ub)
     425  void LpGlpk::_getRowBounds(int i, Value &lb, Value &ub) const
    418426  {
    419427
     
    445453  }
    446454
    447   LpGlpk::Value LpGlpk::_getObjCoeff(int i){
     455  LpGlpk::Value LpGlpk::_getObjCoeff(int i) const {
    448456    //i=0 means the constant term (shift)
    449457    return lpx_get_obj_coef(lp, i);
     
    473481  }
    474482
    475   LpGlpk::Value LpGlpk::_getPrimal(int i)
     483  LpGlpk::Value LpGlpk::_getPrimal(int i) const
    476484  {
    477485    return lpx_get_col_prim(lp,i);
    478486  }
    479487
    480   LpGlpk::Value LpGlpk::_getDual(int i)
     488  LpGlpk::Value LpGlpk::_getDual(int i) const
    481489  {
    482490    return lpx_get_row_dual(lp,i);
    483491  }
    484492 
    485   LpGlpk::Value LpGlpk::_getPrimalValue()
     493  LpGlpk::Value LpGlpk::_getPrimalValue() const
    486494  {
    487495    return lpx_get_obj_val(lp);
    488496  }
    489   bool LpGlpk::_isBasicCol(int i) {
     497  bool LpGlpk::_isBasicCol(int i) const
     498  {
    490499    return (lpx_get_col_stat(lp, i)==LPX_BS);
    491500  }
    492501 
    493502 
    494   LpGlpk::SolutionStatus LpGlpk::_getPrimalStatus()
     503  LpGlpk::SolutionStatus LpGlpk::_getPrimalStatus() const
    495504  {
    496505    int stat=  lpx_get_status(lp);
     
    513522  }
    514523
    515   LpGlpk::SolutionStatus LpGlpk::_getDualStatus()
    516   {
    517 //     std::cout<<"Itt megy: "<<lpx_get_dual_stat(lp)<<std::endl;
    518 //     std::cout<<"Itt a primal: "<<lpx_get_prim_stat(lp)<<std::endl;
    519 
     524  LpGlpk::SolutionStatus LpGlpk::_getDualStatus() const
     525  {
    520526    switch (lpx_get_dual_stat(lp)) {
    521527    case LPX_D_UNDEF://Undefined (no solve has been run yet)
     
    539545  }
    540546
    541   LpGlpk::ProblemTypes LpGlpk::_getProblemType()
     547  LpGlpk::ProblemTypes LpGlpk::_getProblemType() const
    542548  {
    543549      //int stat=  lpx_get_status(lp);
     
    566572  }
    567573
    568   bool LpGlpk::_isMax()
     574  bool LpGlpk::_isMax() const
    569575  {
    570576    return (lpx_get_obj_dir(lp)==LPX_MAX);
  • lemon/lp_glpk.h

    r2364 r2366  
    5656    virtual void _eraseCol(int i);
    5757    virtual void _eraseRow(int i);
    58     virtual void _getColName(int col,       std::string & name);
     58    virtual void _getColName(int col, std::string & name) const;
    5959    virtual void _setColName(int col, const std::string & name);
     60    virtual int _colByName(const std::string& name) const;
    6061    virtual void _setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e);
    61     virtual void _getRowCoeffs(int i, RowIterator b);
     62    virtual void _getRowCoeffs(int i, RowIterator b) const;
    6263    virtual void _setColCoeffs(int i, ConstColIterator b, ConstColIterator e);
    63     virtual void _getColCoeffs(int i, ColIterator b);
     64    virtual void _getColCoeffs(int i, ColIterator b) const;
    6465    virtual void _setCoeff(int row, int col, Value value);
    65     virtual Value _getCoeff(int row, int col);
     66    virtual Value _getCoeff(int row, int col) const;
    6667
    6768    virtual void _setColLowerBound(int i, Value value);
    68     virtual Value _getColLowerBound(int i);
     69    virtual Value _getColLowerBound(int i) const;
    6970    virtual void _setColUpperBound(int i, Value value);
    70     virtual Value _getColUpperBound(int i);
     71    virtual Value _getColUpperBound(int i) const;
    7172
    72 //     virtual void _setRowLowerBound(int i, Value value);
    73 //     virtual void _setRowUpperBound(int i, Value value);
    7473    virtual void _setRowBounds(int i, Value lower, Value upper);
    75     virtual void _getRowBounds(int i, Value &lb, Value &ub);
     74    virtual void _getRowBounds(int i, Value &lb, Value &ub) const;
    7675    virtual void _setObjCoeff(int i, Value obj_coef);
    77     virtual Value _getObjCoeff(int i);
     76    virtual Value _getObjCoeff(int i) const;
    7877    virtual void _clearObj();
    79 //     virtual void _setObj(int length,
    80 //                          int  const * indices,
    81 //                          Value  const * values ) = 0;
    8278
    8379    ///\e
     
    8682    ///
    8783    virtual SolveExitStatus _solve();
    88     virtual Value _getPrimal(int i);
    89     virtual Value _getDual(int i);
    90     virtual Value _getPrimalValue();
    91     virtual bool _isBasicCol(int i);
     84    virtual Value _getPrimal(int i) const;
     85    virtual Value _getDual(int i) const;
     86    virtual Value _getPrimalValue() const;
     87    virtual bool _isBasicCol(int i) const;
    9288    ///\e
    9389   
    9490    ///\todo It should be clarified
    9591    ///
    96     virtual SolutionStatus _getPrimalStatus();
    97     virtual SolutionStatus _getDualStatus();
    98     virtual ProblemTypes _getProblemType();
     92    virtual SolutionStatus _getPrimalStatus() const;
     93    virtual SolutionStatus _getDualStatus() const;
     94    virtual ProblemTypes _getProblemType() const;
    9995
    10096    virtual void _setMax();
    10197    virtual void _setMin();
    10298
    103     virtual bool _isMax();
     99    virtual bool _isMax() const;
    104100
    105101  public:
  • lemon/lp_skeleton.cc

    r2364 r2366  
    5151  }
    5252
    53   void LpSkeleton::_getColName(int, std::string &) {
     53  void LpSkeleton::_getColName(int, std::string &) const {
    5454  }
    5555 
     
    5757  void LpSkeleton::_setColName(int, const std::string &) {
    5858  }
     59
     60  int LpSkeleton::_colByName(const std::string&) const { return -1; }
    5961 
    6062 
     
    6264  }
    6365
    64   void LpSkeleton::_getRowCoeffs(int, RowIterator) {
     66  void LpSkeleton::_getRowCoeffs(int, RowIterator) const {
    6567  }
    6668 
     
    6870  }
    6971
    70   void LpSkeleton::_getColCoeffs(int, ColIterator) {
     72  void LpSkeleton::_getColCoeffs(int, ColIterator) const {
    7173  }
    7274
     
    7577  }
    7678
    77   LpSkeleton::Value LpSkeleton::_getCoeff(int, int)
     79  LpSkeleton::Value LpSkeleton::_getCoeff(int, int) const
    7880  {
    7981    return 0;
     
    8587  }
    8688 
    87   LpSkeleton::Value LpSkeleton::_getColLowerBound(int)
     89  LpSkeleton::Value LpSkeleton::_getColLowerBound(int) const
    8890  {
    8991    return 0;
     
    9496  }
    9597
    96   LpSkeleton::Value LpSkeleton::_getColUpperBound(int)
     98  LpSkeleton::Value LpSkeleton::_getColUpperBound(int) const
    9799  {
    98100    return 0;
     
    111113  }
    112114
    113   void LpSkeleton::_getRowBounds(int, Value&, Value&)
     115  void LpSkeleton::_getRowBounds(int, Value&, Value&) const
    114116  {
    115117  }
     
    119121  }
    120122
    121   LpSkeleton::Value LpSkeleton::_getObjCoeff(int){
     123  LpSkeleton::Value LpSkeleton::_getObjCoeff(int) const
     124  {
    122125    return 0;
    123126  }
     
    131134  }
    132135
    133   bool LpSkeleton::_isMax()
     136  bool LpSkeleton::_isMax() const
    134137  {
    135138    return true;
     
    146149  }
    147150
    148   LpSkeleton::Value LpSkeleton::_getPrimal(int)
     151  LpSkeleton::Value LpSkeleton::_getPrimal(int) const
    149152  {
    150153    return 0;
    151154  }
    152155 
    153   LpSkeleton::Value LpSkeleton::_getDual(int)
     156  LpSkeleton::Value LpSkeleton::_getDual(int) const
    154157  {
    155158    return 0;
    156159  }
    157160 
    158   LpSkeleton::Value LpSkeleton::_getPrimalValue()
     161  LpSkeleton::Value LpSkeleton::_getPrimalValue() const
    159162  {
    160163    return 0;
    161164  }
    162165 
    163   LpSkeleton::SolutionStatus LpSkeleton::_getPrimalStatus()
     166  LpSkeleton::SolutionStatus LpSkeleton::_getPrimalStatus() const
    164167  {
    165168    return UNDEFINED;
    166169  }
    167170
    168   LpSkeleton::SolutionStatus LpSkeleton::_getDualStatus()
     171  LpSkeleton::SolutionStatus LpSkeleton::_getDualStatus() const
    169172  {
    170173    return UNDEFINED;
    171174  }
    172175
    173   LpSkeleton::ProblemTypes LpSkeleton::_getProblemType()
     176  LpSkeleton::ProblemTypes LpSkeleton::_getProblemType() const
    174177  {
    175178    return UNKNOWN;
    176179  }
    177180
    178   bool LpSkeleton::_isBasicCol(int)
     181  bool LpSkeleton::_isBasicCol(int) const
    179182  {
    180183    return true;
  • lemon/lp_skeleton.h

    r2364 r2366  
    4545    virtual void _eraseRow(int i);
    4646    /// \e
    47     virtual void _getColName(int col, std::string & name);
     47    virtual void _getColName(int col, std::string & name) const;
    4848    /// \e
    4949    virtual void _setColName(int col, const std::string & name);
     50    /// \e
     51    virtual int _colByName(const std::string& name) const;
    5052
    5153    /// \e
    5254    virtual void _setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e);
    5355    /// \e
    54     virtual void _getRowCoeffs(int i, RowIterator b);
     56    virtual void _getRowCoeffs(int i, RowIterator b) const;
    5557    /// \e
    5658    virtual void _setColCoeffs(int i, ConstColIterator b, ConstColIterator e);
    5759    /// \e
    58     virtual void _getColCoeffs(int i, ColIterator b);
     60    virtual void _getColCoeffs(int i, ColIterator b) const;
    5961   
    6062    /// Set one element of the coefficient matrix
     
    6264
    6365    /// Get one element of the coefficient matrix
    64     virtual Value _getCoeff(int row, int col);
     66    virtual Value _getCoeff(int row, int col) const;
    6567
    6668    /// The lower bound of a variable (column) have to be given by an
     
    7375    /// extended number of type Value, i.e. a finite number of type
    7476    /// Value or -\ref INF.
    75     virtual Value _getColLowerBound(int i);
     77    virtual Value _getColLowerBound(int i) const;
    7678
    7779    /// The upper bound of a variable (column) have to be given by an
     
    8486    /// extended number of type Value, i.e. a finite number of type
    8587    /// Value or \ref INF.
    86     virtual Value _getColUpperBound(int i);
     88    virtual Value _getColUpperBound(int i) const;
    8789
    8890//     /// The lower bound of a linear expression (row) have to be given by an
     
    109111    /// extended numbers of type Value, i.e.  finite numbers of type
    110112    /// Value, -\ref INF or \ref INF.
    111     virtual void _getRowBounds(int i, Value &lb, Value &ub);
     113    virtual void _getRowBounds(int i, Value &lb, Value &ub) const;
    112114    /// \e
    113115
     
    119121
    120122    /// \e
    121     virtual Value _getObjCoeff(int i);
     123    virtual Value _getObjCoeff(int i) const;
    122124
    123125    ///\e
     
    131133    ///\bug Wrong interface
    132134    ///
    133     virtual Value _getPrimal(int i);
     135    virtual Value _getPrimal(int i) const;
    134136
    135137    ///\e
     
    137139    ///\bug Wrong interface
    138140    ///
    139     virtual Value _getDual(int i);
     141    virtual Value _getDual(int i) const;
    140142
    141143    ///\e
     
    143145    ///\bug Wrong interface
    144146    ///
    145     virtual Value _getPrimalValue();
     147    virtual Value _getPrimalValue() const;
    146148
    147149    ///\e
     
    149151    ///\bug Wrong interface
    150152    ///
    151     virtual SolutionStatus _getPrimalStatus();
     153    virtual SolutionStatus _getPrimalStatus() const;
    152154
    153155    ////e
    154     virtual SolutionStatus _getDualStatus();
     156    virtual SolutionStatus _getDualStatus() const;
    155157
    156158
    157159    ///\e
    158     virtual ProblemTypes _getProblemType();
     160    virtual ProblemTypes _getProblemType() const;
    159161
    160162    ///\e
     
    164166
    165167    ///\e
    166     virtual bool _isMax();
     168    virtual bool _isMax() const;
    167169
    168170
    169171
    170172    ///\e
    171     virtual bool _isBasicCol(int i);
     173    virtual bool _isBasicCol(int i) const;
    172174
    173175   
  • lemon/lp_soplex.cc

    r2364 r2366  
    9191  }
    9292 
    93   void LpSoplex::_getColName(int col, std::string &name) {
     93  void LpSoplex::_getColName(int col, std::string &name) const {
    9494    name = colNames[col];
    9595  }
    9696 
    9797  void LpSoplex::_setColName(int col, const std::string &name) {
     98    invColNames.erase(colNames[col]);
    9899    colNames[col] = name;
     100    if (!name.empty()) {
     101      invColNames.insert(std::make_pair(name, col));
     102    }
     103  }
     104
     105  int LpSoplex::_colByName(const std::string& name) const {
     106    std::map<std::string, int>::const_iterator it =
     107      invColNames.find(name);
     108    if (it != invColNames.end()) {
     109      return it->second;
     110    } else {
     111      return -1;
     112    }
    99113  }
    100114 
     
    110124  }
    111125
    112   void LpSoplex::_getRowCoeffs(int i, RowIterator b) {
     126  void LpSoplex::_getRowCoeffs(int i, RowIterator b) const {
    113127    const soplex::SVector& vec = soplex->rowVector(i);
    114128    for (int k = 0; k < vec.size(); ++k) {
     
    128142  }
    129143
    130   void LpSoplex::_getColCoeffs(int i, ColIterator b) {
     144  void LpSoplex::_getColCoeffs(int i, ColIterator b) const {
    131145    const soplex::SVector& vec = soplex->colVector(i);
    132146    for (int k = 0; k < vec.size(); ++k) {
     
    141155  }
    142156
    143   LpSoplex::Value LpSoplex::_getCoeff(int i, int j) {
     157  LpSoplex::Value LpSoplex::_getCoeff(int i, int j) const {
    144158    return soplex->rowVector(i)[j];
    145159  }
     
    150164  }
    151165 
    152   LpSoplex::Value LpSoplex::_getColLowerBound(int i) {
     166  LpSoplex::Value LpSoplex::_getColLowerBound(int i) const {
    153167    double value = soplex->lower(i);
    154168    return value != -soplex::infinity ? value : -INF;
     
    160174  }
    161175
    162   LpSoplex::Value LpSoplex::_getColUpperBound(int i) {
     176  LpSoplex::Value LpSoplex::_getColUpperBound(int i) const {
    163177    double value = soplex->upper(i);
    164178    return value != soplex::infinity ? value : INF;
     
    170184    solved = false;
    171185  }
    172   void LpSoplex::_getRowBounds(int i, Value &lower, Value &upper) {
     186  void LpSoplex::_getRowBounds(int i, Value &lower, Value &upper) const {
    173187    lower = soplex->lhs(i);
    174188    if (lower == -soplex::infinity) lower = -INF;
     
    182196  }
    183197
    184   LpSoplex::Value LpSoplex::_getObjCoeff(int i) {
     198  LpSoplex::Value LpSoplex::_getObjCoeff(int i) const {
    185199    return soplex->obj(i);
    186200  }
     
    213227  }
    214228
    215   LpSoplex::Value LpSoplex::_getPrimal(int i) {
     229  LpSoplex::Value LpSoplex::_getPrimal(int i) const {
    216230    return primal_value[i];
    217231  }
    218232
    219   LpSoplex::Value LpSoplex::_getDual(int i) {
     233  LpSoplex::Value LpSoplex::_getDual(int i) const {
    220234    return dual_value[i];
    221235  }
    222236 
    223   LpSoplex::Value LpSoplex::_getPrimalValue() {
     237  LpSoplex::Value LpSoplex::_getPrimalValue() const {
    224238    return soplex->objValue();
    225239  }
    226240
    227   bool LpSoplex::_isBasicCol(int i) {
     241  bool LpSoplex::_isBasicCol(int i) const {
    228242    return soplex->getBasisColStatus(i) == soplex::SPxSolver::BASIC;
    229243  } 
    230244
    231   LpSoplex::SolutionStatus LpSoplex::_getPrimalStatus() {
     245  LpSoplex::SolutionStatus LpSoplex::_getPrimalStatus() const {
    232246    if (!solved) return UNDEFINED;
    233247    switch (soplex->status()) {
     
    243257  }
    244258
    245   LpSoplex::SolutionStatus LpSoplex::_getDualStatus() {
     259  LpSoplex::SolutionStatus LpSoplex::_getDualStatus() const {
    246260    if (!solved) return UNDEFINED;
    247261    switch (soplex->status()) {
     
    255269  }
    256270
    257   LpSoplex::ProblemTypes LpSoplex::_getProblemType() {
     271  LpSoplex::ProblemTypes LpSoplex::_getProblemType() const {
    258272    if (!solved) return UNKNOWN;
    259273    switch (soplex->status()) {
     
    275289    solved = false;
    276290  }
    277   bool LpSoplex::_isMax() {
     291  bool LpSoplex::_isMax() const {
    278292    return soplex->spxSense() == soplex::SPxSolver::MAXIMIZE;
    279293  }
  • lemon/lp_soplex.h

    r2364 r2366  
    3535namespace lemon {
    3636
     37  /// \ingroup gen_opt_group
     38  ///
    3739  /// \brief Interface for the SOPLEX solver
    3840  ///
    39   /// This class implements an interface for the SOPLEX LP solver.
     41  /// This class implements an interface for the SoPlex LP solver.
     42  /// The SoPlex library is an object oriented lp solver library
     43  /// developed at the Konrad-Zuse-Zentrum für Informationstechnik
     44  /// Berlin (ZIB). You can find detailed information about it at the
     45  /// <tt>http://soplex.zib.de</tt> address.
    4046  class LpSoplex :virtual public LpSolverBase {
    4147  protected:
     
    4753
    4854    std::vector<std::string> colNames;
     55    std::map<std::string, int> invColNames;
    4956
    5057    std::vector<Value> primal_value;
     
    7178    virtual void _eraseCol(int i);
    7279    virtual void _eraseRow(int i);
    73     virtual void _getColName(int col, std::string & name);
     80    virtual void _getColName(int col, std::string & name) const;
    7481    virtual void _setColName(int col, const std::string & name);
     82    virtual int _colByName(const std::string& name) const;
    7583    virtual void _setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e);
    76     virtual void _getRowCoeffs(int i, RowIterator b);
     84    virtual void _getRowCoeffs(int i, RowIterator b) const;
    7785    virtual void _setColCoeffs(int i, ConstColIterator b, ConstColIterator e);
    78     virtual void _getColCoeffs(int i, ColIterator b);
     86    virtual void _getColCoeffs(int i, ColIterator b) const;
    7987    virtual void _setCoeff(int row, int col, Value value);
    80     virtual Value _getCoeff(int row, int col);
     88    virtual Value _getCoeff(int row, int col) const;
    8189    virtual void _setColLowerBound(int i, Value value);
    82     virtual Value _getColLowerBound(int i);
     90    virtual Value _getColLowerBound(int i) const;
    8391    virtual void _setColUpperBound(int i, Value value);
    84     virtual Value _getColUpperBound(int i);
     92    virtual Value _getColUpperBound(int i) const;
    8593    virtual void _setRowBounds(int i, Value lower, Value upper);
    86     virtual void _getRowBounds(int i, Value &lower, Value &upper);
     94    virtual void _getRowBounds(int i, Value &lower, Value &upper) const;
    8795    virtual void _setObjCoeff(int i, Value obj_coef);
    88     virtual Value _getObjCoeff(int i);
     96    virtual Value _getObjCoeff(int i) const;
    8997    virtual void _clearObj();
    9098   
    9199    virtual SolveExitStatus _solve();
    92     virtual Value _getPrimal(int i);
    93     virtual Value _getDual(int i);
    94     virtual Value _getPrimalValue();
    95     virtual bool _isBasicCol(int i);
     100    virtual Value _getPrimal(int i) const;
     101    virtual Value _getDual(int i) const;
     102    virtual Value _getPrimalValue() const;
     103    virtual bool _isBasicCol(int i) const;
    96104   
    97     virtual SolutionStatus _getPrimalStatus();
    98     virtual SolutionStatus _getDualStatus();
    99     virtual ProblemTypes _getProblemType();
     105    virtual SolutionStatus _getPrimalStatus() const;
     106    virtual SolutionStatus _getDualStatus() const;
     107    virtual ProblemTypes _getProblemType() const;
    100108
    101109   
    102110    virtual void _setMax();
    103111    virtual void _setMin();
    104     virtual bool _isMax();
     112    virtual bool _isMax() const;
    105113
    106114  };
  • lemon/mip_cplex.cc

    r2267 r2366  
    5959  }
    6060 
    61   MipCplex::ColTypes MipCplex::_colType(int i){
     61  MipCplex::ColTypes MipCplex::_colType(int i) const {
    6262   
    6363    char ctype[1];
     
    8686
    8787
    88   LpCplex::SolutionStatus MipCplex::_getMipStatus(){
     88  LpCplex::SolutionStatus MipCplex::_getMipStatus() const {
    8989
    9090    int stat = CPXgetstat(env, lp);
     
    120120  } 
    121121
    122   MipCplex::Value MipCplex::_getPrimal(int i){
     122  MipCplex::Value MipCplex::_getPrimal(int i) const {
    123123    Value x;
    124124    CPXgetmipx(env, lp, &x, i, i);
     
    126126  }
    127127 
    128   MipCplex::Value MipCplex::_getPrimalValue(){
     128  MipCplex::Value MipCplex::_getPrimalValue() const {
    129129    Value objval;
    130130    status = CPXgetmipobjval(env, lp, &objval);
  • lemon/mip_cplex.h

    r2219 r2366  
    4848  protected:
    4949 
    50     virtual ColTypes _colType(int col);
     50    virtual ColTypes _colType(int col) const;
    5151    virtual void _colType(int col, ColTypes col_type);
    5252   
    5353    virtual LpCplex::SolveExitStatus _solve();
    54     virtual LpCplex::SolutionStatus _getMipStatus();
    55     virtual ParentLp::Value _getPrimal(int i);
    56     virtual ParentLp::Value _getPrimalValue();
     54    virtual LpCplex::SolutionStatus _getMipStatus() const;
     55    virtual ParentLp::Value _getPrimal(int i) const;
     56    virtual ParentLp::Value _getPrimalValue() const;
    5757  };
    5858
  • lemon/mip_glpk.cc

    r2267 r2366  
    4141  }
    4242 
    43   MipGlpk::ColTypes MipGlpk::_colType(int i){
     43  MipGlpk::ColTypes MipGlpk::_colType(int i) const {
    4444    switch (lpx_get_col_kind(lp,i)){
    4545    case LPX_IV:
     
    5353  }
    5454 
    55   LpGlpk::SolveExitStatus MipGlpk::_solve(){
     55  LpGlpk::SolveExitStatus MipGlpk::_solve() {
    5656    int result = lpx_simplex(lp);
    5757    //
     
    7272
    7373
    74   LpGlpk::SolutionStatus MipGlpk::_getMipStatus(){
     74  LpGlpk::SolutionStatus MipGlpk::_getMipStatus() const {
    7575
    7676    if (lpx_get_status(lp)==LPX_OPT){
     
    101101  } 
    102102
    103   MipGlpk::Value MipGlpk::_getPrimal(int i){
     103  MipGlpk::Value MipGlpk::_getPrimal(int i) const {
    104104    return lpx_mip_col_val(lp,i);
    105105  }
    106106 
    107   MipGlpk::Value MipGlpk::_getPrimalValue(){
     107  MipGlpk::Value MipGlpk::_getPrimalValue() const {
    108108    return lpx_mip_obj_val(lp);
    109109  }
  • lemon/mip_glpk.h

    r2218 r2366  
    4646  protected:
    4747 
    48     virtual ColTypes _colType(int col);
     48    virtual ColTypes _colType(int col) const;
    4949    virtual void _colType(int col, ColTypes col_type);
    5050   
    5151    virtual LpGlpk::SolveExitStatus _solve();
    52     virtual LpGlpk::SolutionStatus _getMipStatus();
    53     virtual ParentLp::Value _getPrimal(int i);
    54     virtual ParentLp::Value _getPrimalValue();
     52    virtual LpGlpk::SolutionStatus _getMipStatus() const;
     53    virtual ParentLp::Value _getPrimal(int i) const;
     54    virtual ParentLp::Value _getPrimalValue() const;
    5555  };
    5656
Note: See TracChangeset for help on using the changeset viewer.