Some query functions got implemented, but only for GLPK.
authorathos
Mon, 04 Dec 2006 16:48:13 +0000
changeset 232418fc834761d9
parent 2323 8b18b6fed090
child 2325 d6ec469aa019
Some query functions got implemented, but only for GLPK.
lemon/lp_base.h
lemon/lp_glpk.cc
lemon/lp_glpk.h
lemon/lp_skeleton.cc
lemon/lp_skeleton.h
test/lp_test.cc
     1.1 --- a/lemon/lp_base.h	Mon Dec 04 15:00:24 2006 +0000
     1.2 +++ b/lemon/lp_base.h	Mon Dec 04 16:48:13 2006 +0000
     1.3 @@ -703,12 +703,15 @@
     1.4      virtual void _setRowCoeffs(int i, LpRowIterator b, LpRowIterator e) = 0;
     1.5      virtual void _setColCoeffs(int i, LpColIterator b, LpColIterator e) = 0;
     1.6      virtual void _setCoeff(int row, int col, Value value) = 0;
     1.7 +    virtual Value _getCoeff(int row, int col) = 0;
     1.8 +
     1.9      virtual void _setColLowerBound(int i, Value value) = 0;
    1.10      virtual void _setColUpperBound(int i, Value value) = 0;
    1.11  //     virtual void _setRowLowerBound(int i, Value value) = 0;
    1.12  //     virtual void _setRowUpperBound(int i, Value value) = 0;
    1.13      virtual void _setRowBounds(int i, Value lower, Value upper) = 0;
    1.14      virtual void _setObjCoeff(int i, Value obj_coef) = 0;
    1.15 +    virtual Value _getObjCoeff(int i) = 0;
    1.16      virtual void _clearObj()=0;
    1.17  
    1.18      virtual SolveExitStatus _solve() = 0;
    1.19 @@ -725,6 +728,9 @@
    1.20      virtual void _setMax() = 0;
    1.21      virtual void _setMin() = 0;
    1.22      
    1.23 +
    1.24 +    virtual bool _isMax() = 0;
    1.25 +
    1.26      //Own protected stuff
    1.27      
    1.28      //Constant component of the objective function
    1.29 @@ -1000,6 +1006,16 @@
    1.30        _setCoeff(_lpId(r),_lpId(c), val);
    1.31      }
    1.32  
    1.33 +    /// Get an element of the coefficient matrix of the LP
    1.34 +
    1.35 +    ///\param r is the row of the element in question
    1.36 +    ///\param c is the coloumn of the element in question
    1.37 +    ///\return the corresponding coefficient
    1.38 +
    1.39 +    Value coeff(Row r, Col c){
    1.40 +      return _getCoeff(_lpId(r),_lpId(c));
    1.41 +    }
    1.42 +
    1.43      /// Set the lower bound of a column (i.e a variable)
    1.44  
    1.45      /// The lower bound of a variable (column) has to be given by an 
    1.46 @@ -1171,8 +1187,12 @@
    1.47      
    1.48      ///Set an element of the objective function
    1.49      void objCoeff(Col c, Value v) {_setObjCoeff(_lpId(c),v); };
    1.50 +
    1.51 +    ///Get an element of the objective function
    1.52 +    Value objCoeff(Col c) {return _getObjCoeff(_lpId(c)); };
    1.53 +
    1.54      ///Set the objective function
    1.55 -    
    1.56 +
    1.57      ///\param e is a linear expression of type \ref Expr.
    1.58      ///\bug Is should be called obj()
    1.59      void setObj(Expr e) {
    1.60 @@ -1187,6 +1207,11 @@
    1.61      ///Minimize
    1.62      void min() { _setMin(); }
    1.63  
    1.64 +    ///Query function: is this a maximization problem?
    1.65 +    bool is_max() {return _isMax(); }
    1.66 +
    1.67 +    ///Query function: is this a minimization problem?
    1.68 +    bool is_min() {return !is_max(); }
    1.69      
    1.70      ///@}
    1.71  
     2.1 --- a/lemon/lp_glpk.cc	Mon Dec 04 15:00:24 2006 +0000
     2.2 +++ b/lemon/lp_glpk.cc	Mon Dec 04 16:48:13 2006 +0000
     2.3 @@ -213,6 +213,13 @@
     2.4      }
     2.5    }
     2.6  
     2.7 +  LpGlpk::Value LpGlpk::_getCoeff(int row, int col)
     2.8 +  {
     2.9 +    ///\todo This is not yet implemented!!!
    2.10 +    return 0;
    2.11 +  }
    2.12 +
    2.13 +
    2.14    void LpGlpk::_setColLowerBound(int i, Value lo)
    2.15    {
    2.16      if (lo==INF) {
    2.17 @@ -424,6 +431,11 @@
    2.18      lpx_set_obj_coef(lp, i, obj_coef);
    2.19    }
    2.20  
    2.21 +  LpGlpk::Value LpGlpk::_getObjCoeff(int i){
    2.22 +    //i=0 means the constant term (shift)
    2.23 +    return lpx_get_obj_coef(lp, i);
    2.24 +  }
    2.25 +
    2.26    void LpGlpk::_clearObj()
    2.27    {
    2.28      for (int i=0;i<=lpx_get_num_cols(lp);++i){
    2.29 @@ -551,7 +563,13 @@
    2.30      lpx_set_obj_dir(lp, LPX_MIN);
    2.31    }
    2.32  
    2.33 +  bool LpGlpk::_isMax()
    2.34 +  {
    2.35 +    return (lpx_get_obj_dir(lp)==LPX_MAX);
    2.36 +  }
    2.37 +
    2.38   
    2.39 +
    2.40    void LpGlpk::messageLevel(int m)
    2.41    {
    2.42      lpx_set_int_parm(lp, LPX_K_MSGLEV, m);
     3.1 --- a/lemon/lp_glpk.h	Mon Dec 04 15:00:24 2006 +0000
     3.2 +++ b/lemon/lp_glpk.h	Mon Dec 04 16:48:13 2006 +0000
     3.3 @@ -60,12 +60,15 @@
     3.4      virtual void _setRowCoeffs(int i, LpRowIterator b, LpRowIterator e);
     3.5      virtual void _setColCoeffs(int i, LpColIterator b, LpColIterator e);
     3.6      virtual void _setCoeff(int row, int col, Value value);
     3.7 +    virtual Value _getCoeff(int row, int col);
     3.8 +
     3.9      virtual void _setColLowerBound(int i, Value value);
    3.10      virtual void _setColUpperBound(int i, Value value);
    3.11  //     virtual void _setRowLowerBound(int i, Value value);
    3.12  //     virtual void _setRowUpperBound(int i, Value value);
    3.13      virtual void _setRowBounds(int i, Value lower, Value upper);
    3.14      virtual void _setObjCoeff(int i, Value obj_coef);
    3.15 +    virtual Value _getObjCoeff(int i);
    3.16      virtual void _clearObj();
    3.17  //     virtual void _setObj(int length,
    3.18  //                          int  const * indices, 
    3.19 @@ -91,6 +94,8 @@
    3.20      virtual void _setMax();
    3.21      virtual void _setMin();
    3.22  
    3.23 +    virtual bool _isMax();
    3.24 +
    3.25    public:
    3.26      ///Set the verbosity of the messages
    3.27  
     4.1 --- a/lemon/lp_skeleton.cc	Mon Dec 04 15:00:24 2006 +0000
     4.2 +++ b/lemon/lp_skeleton.cc	Mon Dec 04 16:48:13 2006 +0000
     4.3 @@ -68,6 +68,11 @@
     4.4    {
     4.5    }
     4.6  
     4.7 +  LpSkeleton::Value LpSkeleton::_getCoeff(int, int)
     4.8 +  {
     4.9 +    return 0;
    4.10 +  }
    4.11 +
    4.12  
    4.13    void LpSkeleton::_setColLowerBound(int, Value)
    4.14    {
    4.15 @@ -93,6 +98,10 @@
    4.16    {
    4.17    }
    4.18  
    4.19 +  LpSkeleton::Value LpSkeleton::_getObjCoeff(int i){
    4.20 +    return 0;
    4.21 +  }
    4.22 +
    4.23    void LpSkeleton::_setMax()
    4.24    {
    4.25    }
    4.26 @@ -101,6 +110,12 @@
    4.27    {
    4.28    }
    4.29  
    4.30 +  bool LpSkeleton::_isMax()
    4.31 +  {
    4.32 +    return true;
    4.33 +  }
    4.34 +
    4.35 +
    4.36    void LpSkeleton::_clearObj()
    4.37    {
    4.38    }
     5.1 --- a/lemon/lp_skeleton.h	Mon Dec 04 15:00:24 2006 +0000
     5.2 +++ b/lemon/lp_skeleton.h	Mon Dec 04 16:48:13 2006 +0000
     5.3 @@ -55,6 +55,9 @@
     5.4      /// Set one element of the coefficient matrix
     5.5      virtual void _setCoeff(int row, int col, Value value);
     5.6  
     5.7 +    /// Get one element of the coefficient matrix
     5.8 +    virtual Value _getCoeff(int row, int col);
     5.9 +
    5.10      /// The lower bound of a variable (column) have to be given by an 
    5.11      /// extended number of type Value, i.e. a finite number of type 
    5.12      /// Value or -\ref INF.
    5.13 @@ -91,6 +94,9 @@
    5.14      /// \e
    5.15      virtual void _setObjCoeff(int i, Value obj_coef);
    5.16  
    5.17 +    /// \e
    5.18 +    virtual Value _getObjCoeff(int i);
    5.19 +
    5.20      ///\e
    5.21      
    5.22      ///\bug Wrong interface
    5.23 @@ -134,6 +140,11 @@
    5.24      virtual void _setMin();
    5.25  
    5.26      ///\e
    5.27 +    virtual bool _isMax();
    5.28 +
    5.29 +
    5.30 +
    5.31 +    ///\e
    5.32      virtual bool _isBasicCol(int i);
    5.33  
    5.34      
     6.1 --- a/test/lp_test.cc	Mon Dec 04 15:00:24 2006 +0000
     6.2 +++ b/test/lp_test.cc	Mon Dec 04 16:48:13 2006 +0000
     6.3 @@ -293,6 +293,13 @@
     6.4  
     6.5    lp.max();
     6.6  
     6.7 +
     6.8 +  //Testing the problem retrieving routines
     6.9 +  check(lp.objCoeff(x1)==1,"First term should be 1 in the obj function!");
    6.10 +  check(lp.is_max(),"This is a maximization!");
    6.11 +  check(lp.coeff(upright,x1)==1,"The coefficient in question is 1!");
    6.12 +
    6.13 +
    6.14    //Maximization of x1+x2
    6.15    //over the triangle with vertices (0,0) (0,1) (1,0)
    6.16    double expected_opt=1;