lemon/lp_base.h
changeset 2366 bfbdded3763a
parent 2364 3a5e67bd42d2
child 2368 6b2e8b734ae7
     1.1 --- a/lemon/lp_base.h	Fri Feb 16 15:57:48 2007 +0000
     1.2 +++ b/lemon/lp_base.h	Fri Feb 16 19:11:31 2007 +0000
     1.3 @@ -135,10 +135,10 @@
     1.4      };
     1.5  
     1.6      class ColIt : public Col {
     1.7 -      LpSolverBase *_lp;
     1.8 +      const LpSolverBase *_lp;
     1.9      public:
    1.10        ColIt() {}
    1.11 -      ColIt(LpSolverBase &lp) : _lp(&lp)
    1.12 +      ColIt(const LpSolverBase &lp) : _lp(&lp)
    1.13        {
    1.14          _lp->cols.firstFix(id);
    1.15        }
    1.16 @@ -180,10 +180,10 @@
    1.17      };
    1.18  
    1.19      class RowIt : public Row {
    1.20 -      LpSolverBase *_lp;
    1.21 +      const LpSolverBase *_lp;
    1.22      public:
    1.23        RowIt() {}
    1.24 -      RowIt(LpSolverBase &lp) : _lp(&lp)
    1.25 +      RowIt(const LpSolverBase &lp) : _lp(&lp)
    1.26        {
    1.27          _lp->rows.firstFix(id);
    1.28        }
    1.29 @@ -735,45 +735,47 @@
    1.30  
    1.31      virtual int _addCol() = 0;
    1.32      virtual int _addRow() = 0; 
    1.33 +
    1.34      virtual void _eraseCol(int col) = 0;
    1.35      virtual void _eraseRow(int row) = 0;
    1.36 -    virtual void _getColName(int col, std::string & name) = 0;
    1.37 +
    1.38 +    virtual void _getColName(int col, std::string & name) const = 0;
    1.39      virtual void _setColName(int col, const std::string & name) = 0;
    1.40 +    virtual int _colByName(const std::string& name) const = 0;
    1.41 +
    1.42      virtual void _setRowCoeffs(int i, ConstRowIterator b, 
    1.43                                 ConstRowIterator e) = 0;
    1.44 -    virtual void _getRowCoeffs(int i, RowIterator b) = 0;
    1.45 +    virtual void _getRowCoeffs(int i, RowIterator b) const = 0;
    1.46      virtual void _setColCoeffs(int i, ConstColIterator b, 
    1.47                                 ConstColIterator e) = 0;
    1.48 -    virtual void _getColCoeffs(int i, ColIterator b) = 0;
    1.49 +    virtual void _getColCoeffs(int i, ColIterator b) const = 0;
    1.50      virtual void _setCoeff(int row, int col, Value value) = 0;
    1.51 -    virtual Value _getCoeff(int row, int col) = 0;
    1.52 +    virtual Value _getCoeff(int row, int col) const = 0;
    1.53      virtual void _setColLowerBound(int i, Value value) = 0;
    1.54 -    virtual Value _getColLowerBound(int i) = 0;
    1.55 +    virtual Value _getColLowerBound(int i) const = 0;
    1.56      virtual void _setColUpperBound(int i, Value value) = 0;
    1.57 -    virtual Value _getColUpperBound(int i) = 0;
    1.58 +    virtual Value _getColUpperBound(int i) const = 0;
    1.59      virtual void _setRowBounds(int i, Value lower, Value upper) = 0;
    1.60 -    virtual void _getRowBounds(int i, Value &lower, Value &upper)=0;
    1.61 +    virtual void _getRowBounds(int i, Value &lower, Value &upper) const = 0;
    1.62  
    1.63      virtual void _setObjCoeff(int i, Value obj_coef) = 0;
    1.64 -    virtual Value _getObjCoeff(int i) = 0;
    1.65 +    virtual Value _getObjCoeff(int i) const = 0;
    1.66      virtual void _clearObj()=0;
    1.67  
    1.68      virtual SolveExitStatus _solve() = 0;
    1.69 -    virtual Value _getPrimal(int i) = 0;
    1.70 -    virtual Value _getDual(int i) = 0;
    1.71 -    virtual Value _getPrimalValue() = 0;
    1.72 -    virtual bool _isBasicCol(int i) = 0;
    1.73 -    virtual SolutionStatus _getPrimalStatus() = 0;
    1.74 -    virtual SolutionStatus _getDualStatus() = 0;
    1.75 -    ///\todo This could be implemented here, too, using _getPrimalStatus() and
    1.76 -    ///_getDualStatus()
    1.77 -    virtual ProblemTypes _getProblemType() = 0;
    1.78 +    virtual Value _getPrimal(int i) const = 0;
    1.79 +    virtual Value _getDual(int i) const = 0;
    1.80 +    virtual Value _getPrimalValue() const = 0;
    1.81 +    virtual bool _isBasicCol(int i) const = 0;
    1.82 +    virtual SolutionStatus _getPrimalStatus() const = 0;
    1.83 +    virtual SolutionStatus _getDualStatus() const = 0;
    1.84 +    virtual ProblemTypes _getProblemType() const = 0;
    1.85  
    1.86      virtual void _setMax() = 0;
    1.87      virtual void _setMin() = 0;
    1.88      
    1.89  
    1.90 -    virtual bool _isMax() = 0;
    1.91 +    virtual bool _isMax() const = 0;
    1.92  
    1.93      //Own protected stuff
    1.94      
    1.95 @@ -877,7 +879,7 @@
    1.96  
    1.97      ///\param r is the column to get
    1.98      ///\return the dual expression associated to the column
    1.99 -    DualExpr col(Col c) {
   1.100 +    DualExpr col(Col c) const {
   1.101        DualExpr e;
   1.102        _getColCoeffs(_lpId(c), ColIterator(std::inserter(e, e.end()), *this));
   1.103        return e;
   1.104 @@ -974,7 +976,7 @@
   1.105      ///a better one.
   1.106      ///\todo Option to control whether a constraint with a single variable is
   1.107      ///added or not.
   1.108 -    void row(Row r, Value l,const Expr &e, Value u) {
   1.109 +    void row(Row r, Value l, const Expr &e, Value u) {
   1.110        e.simplify();
   1.111        _setRowCoeffs(_lpId(r), ConstRowIterator(e.begin(), *this),
   1.112                      ConstRowIterator(e.end(), *this));
   1.113 @@ -995,7 +997,7 @@
   1.114  
   1.115      ///\param r is the row to get
   1.116      ///\return the expression associated to the row
   1.117 -    Expr row(Row r) {
   1.118 +    Expr row(Row r) const {
   1.119        Expr e;
   1.120        _getRowCoeffs(_lpId(r), RowIterator(std::inserter(e, e.end()), *this));
   1.121        return e;
   1.122 @@ -1045,7 +1047,7 @@
   1.123      
   1.124      ///\param c is the coresponding coloumn 
   1.125      ///\return The name of the colunm
   1.126 -    std::string colName(Col c){
   1.127 +    std::string colName(Col c) const {
   1.128        std::string name;
   1.129        _getColName(_lpId(c), name);
   1.130        return name;
   1.131 @@ -1055,7 +1057,7 @@
   1.132      
   1.133      ///\param c is the coresponding coloumn 
   1.134      ///\param name The name to be given
   1.135 -    void colName(Col c, const std::string& name){
   1.136 +    void colName(Col c, const std::string& name) {
   1.137        _setColName(_lpId(c), name);
   1.138      }
   1.139      
   1.140 @@ -1065,7 +1067,7 @@
   1.141      ///\param c is the coloumn of the element to be modified
   1.142      ///\param val is the new value of the coefficient
   1.143  
   1.144 -    void coeff(Row r, Col c, Value val){
   1.145 +    void coeff(Row r, Col c, Value val) {
   1.146        _setCoeff(_lpId(r),_lpId(c), val);
   1.147      }
   1.148  
   1.149 @@ -1075,7 +1077,7 @@
   1.150      ///\param c is the coloumn of the element in question
   1.151      ///\return the corresponding coefficient
   1.152  
   1.153 -    Value coeff(Row r, Col c){
   1.154 +    Value coeff(Row r, Col c) const {
   1.155        return _getCoeff(_lpId(r),_lpId(c));
   1.156      }
   1.157  
   1.158 @@ -1093,7 +1095,7 @@
   1.159      /// This function returns the lower bound for column (variable) \t c
   1.160      /// (this might be -\ref INF as well).  
   1.161      ///\return The lower bound for coloumn \t c
   1.162 -    Value colLowerBound(Col c) {
   1.163 +    Value colLowerBound(Col c) const {
   1.164        return _getColLowerBound(_lpId(c));
   1.165      }
   1.166      
   1.167 @@ -1148,7 +1150,7 @@
   1.168      /// This function returns the upper bound for column (variable) \t c
   1.169      /// (this might be \ref INF as well).  
   1.170      ///\return The upper bound for coloumn \t c
   1.171 -    Value colUpperBound(Col c) {
   1.172 +    Value colUpperBound(Col c) const {
   1.173        return _getColUpperBound(_lpId(c));
   1.174      }
   1.175  
   1.176 @@ -1260,7 +1262,7 @@
   1.177      /// lower and the upper bound because we had problems with the 
   1.178      /// implementation of the setting functions for CPLEX:  
   1.179      /// check out whether this can be done for these functions.
   1.180 -    void getRowBounds(Row c, Value &lower, Value &upper) {
   1.181 +    void getRowBounds(Row c, Value &lower, Value &upper) const {
   1.182        _getRowBounds(_lpId(c),lower, upper);
   1.183      }
   1.184  
   1.185 @@ -1268,7 +1270,7 @@
   1.186      void objCoeff(Col c, Value v) {_setObjCoeff(_lpId(c),v); };
   1.187  
   1.188      ///Get an element of the objective function
   1.189 -    Value objCoeff(Col c) {return _getObjCoeff(_lpId(c)); };
   1.190 +    Value objCoeff(Col c) const { return _getObjCoeff(_lpId(c)); };
   1.191  
   1.192      ///Set the objective function
   1.193  
   1.194 @@ -1284,7 +1286,7 @@
   1.195      ///Get the objective function
   1.196  
   1.197      ///\return the objective function as a linear expression of type \ref Expr.
   1.198 -    Expr obj() {
   1.199 +    Expr obj() const {
   1.200        Expr e;
   1.201        for (ColIt it(*this); it != INVALID; ++it) {
   1.202          double c = objCoeff(it);
   1.203 @@ -1302,10 +1304,10 @@
   1.204      void min() { _setMin(); }
   1.205  
   1.206      ///Query function: is this a maximization problem?
   1.207 -    bool is_max() {return _isMax(); }
   1.208 +    bool is_max() const {return _isMax(); }
   1.209  
   1.210      ///Query function: is this a minimization problem?
   1.211 -    bool is_min() {return !is_max(); }
   1.212 +    bool is_min() const {return !is_max(); }
   1.213      
   1.214      ///@}
   1.215  
   1.216 @@ -1330,28 +1332,28 @@
   1.217      ///@{
   1.218  
   1.219      /// The status of the primal problem (the original LP problem)
   1.220 -    SolutionStatus primalStatus() {
   1.221 +    SolutionStatus primalStatus() const {
   1.222        return _getPrimalStatus();
   1.223      }
   1.224  
   1.225      /// The status of the dual (of the original LP) problem 
   1.226 -    SolutionStatus dualStatus() {
   1.227 +    SolutionStatus dualStatus() const {
   1.228        return _getDualStatus();
   1.229      }
   1.230  
   1.231      ///The type of the original LP problem
   1.232 -    ProblemTypes problemType() {
   1.233 +    ProblemTypes problemType() const {
   1.234        return _getProblemType();
   1.235      }
   1.236  
   1.237      ///\e
   1.238 -    Value primal(Col c) { return _getPrimal(_lpId(c)); }
   1.239 +    Value primal(Col c) const { return _getPrimal(_lpId(c)); }
   1.240  
   1.241      ///\e
   1.242 -    Value dual(Row r) { return _getDual(_lpId(r)); }
   1.243 +    Value dual(Row r) const { return _getDual(_lpId(r)); }
   1.244  
   1.245      ///\e
   1.246 -    bool isBasicCol(Col c) { return _isBasicCol(_lpId(c)); }
   1.247 +    bool isBasicCol(Col c) const { return _isBasicCol(_lpId(c)); }
   1.248  
   1.249      ///\e
   1.250  
   1.251 @@ -1360,7 +1362,7 @@
   1.252      /// of the primal problem, depending on whether we minimize or maximize.
   1.253      ///- \ref NaN if no primal solution is found.
   1.254      ///- The (finite) objective value if an optimal solution is found.
   1.255 -    Value primalValue() { return _getPrimalValue()+obj_const_comp;}
   1.256 +    Value primalValue() const { return _getPrimalValue()+obj_const_comp;}
   1.257      ///@}
   1.258      
   1.259    };  
   1.260 @@ -1394,7 +1396,7 @@
   1.261      ///Gives back the type of the column.
   1.262      ///
   1.263      ///Gives back the type of the column.
   1.264 -    ColTypes colType(Col c){
   1.265 +    ColTypes colType(Col c) const {
   1.266        return _colType(_lpId(c));
   1.267      }
   1.268  
   1.269 @@ -1412,20 +1414,20 @@
   1.270      ///
   1.271      ///Gives back the type of the column.
   1.272      ///\return true if the column has integer type and false if not.
   1.273 -    bool integer(Col c){
   1.274 +    bool integer(Col c) const {
   1.275        return (colType(c)==INT);
   1.276      }
   1.277  
   1.278      /// The status of the MIP problem
   1.279 -    SolutionStatus mipStatus() {
   1.280 +    SolutionStatus mipStatus() const {
   1.281        return _getMipStatus();
   1.282      }
   1.283  
   1.284    protected:
   1.285  
   1.286 -    virtual ColTypes _colType(int col) = 0;
   1.287 +    virtual ColTypes _colType(int col) const = 0;
   1.288      virtual void _colType(int col, ColTypes col_type) = 0;
   1.289 -    virtual SolutionStatus _getMipStatus()=0;
   1.290 +    virtual SolutionStatus _getMipStatus() const = 0;
   1.291  
   1.292    };
   1.293