Implemented virtual functions of class LpCplex.
authorathos
Wed, 14 Feb 2007 13:50:25 +0000
changeset 2361f2ef1aa8189a
parent 2360 72c7075ad5ba
child 2362 eb37b9774ef6
Implemented virtual functions of class LpCplex.
lemon/lp_cplex.cc
lemon/lp_cplex.h
     1.1 --- a/lemon/lp_cplex.cc	Mon Feb 12 17:54:36 2007 +0000
     1.2 +++ b/lemon/lp_cplex.cc	Wed Feb 14 13:50:25 2007 +0000
     1.3 @@ -147,6 +147,13 @@
     1.4      CPXchgcoef(env, lp, row, col, value);
     1.5    }
     1.6  
     1.7 +  LpCplex::Value LpCplex::_getCoeff(int row, int col) 
     1.8 +  {
     1.9 +    LpCplex::Value value;
    1.10 +    CPXgetcoef(env, lp, row, col, &value);
    1.11 +    return value;
    1.12 +  }
    1.13 +
    1.14    void LpCplex::_setColLowerBound(int i, Value value)
    1.15    {
    1.16      int indices[1];
    1.17 @@ -158,6 +165,13 @@
    1.18      status = CPXchgbds(env, lp, 1, indices, lu, bd);
    1.19   
    1.20    }
    1.21 +
    1.22 +  LpCplex::Value LpCplex::_getColLowerBound(int i)
    1.23 +  {
    1.24 +    LpCplex::Value x;
    1.25 +    CPXgetlb (env, lp, &x, i, i);
    1.26 +    return x;
    1.27 +  }
    1.28    
    1.29    void LpCplex::_setColUpperBound(int i, Value value)
    1.30    {
    1.31 @@ -170,6 +184,13 @@
    1.32      status = CPXchgbds(env, lp, 1, indices, lu, bd);
    1.33    }
    1.34  
    1.35 +  LpCplex::Value LpCplex::_getColUpperBound(int i)
    1.36 +  {
    1.37 +    LpCplex::Value x;
    1.38 +    CPXgetub (env, lp, &x, i, i);
    1.39 +    return x;
    1.40 +  }
    1.41 +
    1.42    //This will be easier to implement
    1.43    void LpCplex::_setRowBounds(int i, Value lb, Value ub)
    1.44    {
    1.45 @@ -242,11 +263,45 @@
    1.46  // //     status = CPXchgcoef(env, lp, i, -2, value_rng);
    1.47  //   }
    1.48    
    1.49 +  void LpCplex::_getRowBounds(int i, Value &lb, Value &ub)
    1.50 +  {
    1.51 +    char sense;
    1.52 +    CPXgetsense(env, lp, &sense,i,i);
    1.53 +    lb=-INF;
    1.54 +    ub=INF;
    1.55 +    switch (sense)
    1.56 +      {
    1.57 +      case 'L':
    1.58 +	CPXgetcoef(env, lp, i, -1, &ub);
    1.59 +	break;
    1.60 +      case 'G':
    1.61 +	CPXgetcoef(env, lp, i, -1, &lb);
    1.62 +	break;
    1.63 +      case 'E':
    1.64 +	CPXgetcoef(env, lp, i, -1, &lb);
    1.65 +	ub=lb;
    1.66 +	break;
    1.67 +      case 'R':
    1.68 +	CPXgetcoef(env, lp, i, -1, &lb);
    1.69 +	Value x;
    1.70 +	CPXgetcoef(env, lp, i, -2, &x);
    1.71 +	ub=lb+x;
    1.72 +	break;
    1.73 +      }
    1.74 +  }
    1.75 +
    1.76    void LpCplex::_setObjCoeff(int i, Value obj_coef)
    1.77    {
    1.78      CPXchgcoef(env, lp, -1, i, obj_coef);
    1.79    }
    1.80  
    1.81 +  LpCplex::Value LpCplex::_getObjCoeff(int i)
    1.82 +  {
    1.83 +    Value x;
    1.84 +    CPXgetcoef(env, lp, -1, i, &x);
    1.85 +    return x;
    1.86 +  }
    1.87 +
    1.88    void LpCplex::_clearObj()
    1.89    {
    1.90      for (int i=0;i< CPXgetnumcols(env, lp);++i){
    1.91 @@ -564,6 +619,14 @@
    1.92    {
    1.93      CPXchgobjsen(env, lp, CPX_MIN);
    1.94     }
    1.95 +
    1.96 +  bool LpCplex::_isMax()
    1.97 +  {
    1.98 +    if (CPXgetobjsen(env, lp)==CPX_MAX)
    1.99 +      return true;
   1.100 +    else
   1.101 +      return false;
   1.102 +  }
   1.103    
   1.104  } //namespace lemon
   1.105  
     2.1 --- a/lemon/lp_cplex.h	Mon Feb 12 17:54:36 2007 +0000
     2.2 +++ b/lemon/lp_cplex.h	Wed Feb 14 13:50:25 2007 +0000
     2.3 @@ -55,6 +55,7 @@
     2.4      virtual LpSolverBase &_newLp();
     2.5      virtual LpSolverBase &_copyLp();
     2.6  
     2.7 +
     2.8      virtual int _addCol();
     2.9      virtual int _addRow();
    2.10      virtual void _eraseCol(int i);
    2.11 @@ -64,14 +65,21 @@
    2.12      virtual void _setRowCoeffs(int i, LpRowIterator b, LpRowIterator e);
    2.13      virtual void _setColCoeffs(int i, LpColIterator b, LpColIterator e);
    2.14      virtual void _setCoeff(int row, int col, Value value);
    2.15 +    virtual Value _getCoeff(int row, int col);
    2.16 +
    2.17      virtual void _setColLowerBound(int i, Value value);
    2.18 +    virtual Value _getColLowerBound(int i);
    2.19      virtual void _setColUpperBound(int i, Value value);
    2.20 +    virtual Value _getColUpperBound(int i);
    2.21 +
    2.22  //     virtual void _setRowLowerBound(int i, Value value);
    2.23  //     virtual void _setRowUpperBound(int i, Value value);
    2.24      virtual void _setRowBounds(int i, Value lower, Value upper);
    2.25 +    virtual void _getRowBounds(int i, Value &lb, Value &ub);
    2.26      virtual void _setObjCoeff(int i, Value obj_coef);
    2.27 +    virtual Value _getObjCoeff(int i);
    2.28      virtual void _clearObj();
    2.29 -    ///\e
    2.30 +
    2.31      
    2.32      virtual SolveExitStatus _solve();
    2.33      virtual Value _getPrimal(int i);
    2.34 @@ -87,6 +95,8 @@
    2.35      virtual void _setMax();
    2.36      virtual void _setMin();
    2.37  
    2.38 +    virtual bool _isMax();
    2.39 +
    2.40    };
    2.41  } //END OF NAMESPACE LEMON
    2.42