Modifications to the interface: colType() functions, though I left the old integer() functions, too.
authorathos
Mon, 17 Jul 2006 11:56:17 +0000
changeset 2148ab368e0ab662
parent 2147 63d293ff1bef
child 2149 b437bdee6fd0
Modifications to the interface: colType() functions, though I left the old integer() functions, too.
demo/mip_demo.cc
lemon/lp_base.h
lemon/mip_glpk.cc
lemon/mip_glpk.h
     1.1 --- a/demo/mip_demo.cc	Mon Jul 17 09:31:41 2006 +0000
     1.2 +++ b/demo/mip_demo.cc	Mon Jul 17 11:56:17 2006 +0000
     1.3 @@ -9,7 +9,7 @@
     1.4  
     1.5     Mip ilp;
     1.6  
     1.7 -    
     1.8 +
     1.9    typedef Mip::Row Row;
    1.10    typedef Mip::Col Col;
    1.11    
     2.1 --- a/lemon/lp_base.h	Mon Jul 17 09:31:41 2006 +0000
     2.2 +++ b/lemon/lp_base.h	Mon Jul 17 11:56:17 2006 +0000
     2.3 @@ -1158,31 +1158,58 @@
     2.4    };  
     2.5  
     2.6  
     2.7 -  ///Common base class for ILP solvers
     2.8 +  ///Common base class for MIP solvers
     2.9    ///\todo Much more docs
    2.10    ///\ingroup gen_opt_group
    2.11    class MipSolverBase : virtual public LpSolverBase{
    2.12    public:
    2.13  
    2.14 -    ///Set the type of the given Col to integer or remove that property.
    2.15 +    ///Possible variable (coloumn) types (e.g. real, integer, binary etc.)
    2.16 +    enum ColTypes {
    2.17 +      ///Continuous variable
    2.18 +      REAL = 0,
    2.19 +      ///Integer variable
    2.20 +      INTEGER = 1
    2.21 +      ///\todo No support for other types yet.
    2.22 +    };
    2.23 +
    2.24 +    ///Sets the type of the given coloumn to the given type
    2.25      ///
    2.26 -    ///Set the type of the given Col to integer or remove that property.
    2.27 -    void integer(Col c, bool enable) {
    2.28 -      _integer(cols.floatingId(c.id),enable);
    2.29 +    ///Sets the type of the given coloumn to the given type.
    2.30 +    void colType(Col c, ColTypes col_type) {
    2.31 +      _colType(cols.floatingId(c.id),col_type);
    2.32      }
    2.33  
    2.34      ///Gives back the type of the column.
    2.35      ///
    2.36      ///Gives back the type of the column.
    2.37 +    ColTypes colType(Col c){
    2.38 +      return _colType(cols.floatingId(c.id));
    2.39 +    }
    2.40 +
    2.41 +    ///Sets the type of the given Col to integer or remove that property.
    2.42 +    ///
    2.43 +    ///Sets the type of the given Col to integer or remove that property.
    2.44 +    void integer(Col c, bool enable) {
    2.45 +      if (enable)
    2.46 +	colType(c,INTEGER);
    2.47 +      else
    2.48 +	colType(c,REAL);
    2.49 +    }
    2.50 +
    2.51 +    ///Gives back whether the type of the column is integer or not.
    2.52 +    ///
    2.53 +    ///Gives back the type of the column.
    2.54      ///\return true if the column has integer type and false if not.
    2.55      bool integer(Col c){
    2.56 -      return _integer(cols.floatingId(c.id));
    2.57 +      return (colType(c)==INTEGER);
    2.58      }
    2.59  
    2.60    protected:
    2.61  
    2.62 -    virtual bool _integer(int col) = 0;
    2.63 -    virtual void _integer(int col, bool enable) = 0;
    2.64 +    virtual ColTypes _colType(int col) = 0;
    2.65 +    virtual void _colType(int col, ColTypes col_type) = 0;
    2.66 +
    2.67    };
    2.68    
    2.69    ///\relates LpSolverBase::Expr
     3.1 --- a/lemon/mip_glpk.cc	Mon Jul 17 09:31:41 2006 +0000
     3.2 +++ b/lemon/mip_glpk.cc	Mon Jul 17 11:56:17 2006 +0000
     3.3 @@ -29,20 +29,30 @@
     3.4    MipGlpk::MipGlpk() {
     3.5      lpx_set_class(lp,LPX_MIP);
     3.6    }
     3.7 -  
     3.8 -  void MipGlpk::_integer(int i, bool enable){
     3.9 -    if(enable){
    3.10 -      lpx_set_col_kind(lp,i,LPX_IV);
    3.11 -    }else{
    3.12 -      lpx_set_col_kind(lp,i,LPX_CV);
    3.13 +
    3.14 +  void MipGlpk::_colType(int i, ColTypes col_type){
    3.15 +    switch (col_type){
    3.16 +      case INTEGER:
    3.17 +	lpx_set_col_kind(lp,i,LPX_IV);
    3.18 +	break;
    3.19 +      case REAL:
    3.20 +	lpx_set_col_kind(lp,i,LPX_CV);
    3.21 +	break;
    3.22 +      default:
    3.23 +        //FIXME problem
    3.24      }
    3.25    }
    3.26    
    3.27 -  bool MipGlpk::_integer(int i){
    3.28 -    if(LPX_IV == lpx_get_col_kind(lp,i)){
    3.29 -      return true;
    3.30 +  ColTypes MipGlpk::_colType(int i){
    3.31 +    switch (lpx_get_col_kind(lp,i)){
    3.32 +    case LPX_IV:
    3.33 +      return INTEGER;//Or binary
    3.34 +    case LPX_CV:
    3.35 +      return REAL;
    3.36 +    default:
    3.37 +      return REAL;//Error!
    3.38      }
    3.39 -    return false;
    3.40 +    
    3.41    }
    3.42    
    3.43    LpGlpk::SolveExitStatus MipGlpk::_solve(){
     4.1 --- a/lemon/mip_glpk.h	Mon Jul 17 09:31:41 2006 +0000
     4.2 +++ b/lemon/mip_glpk.h	Mon Jul 17 11:56:17 2006 +0000
     4.3 @@ -45,8 +45,8 @@
     4.4      
     4.5    protected:
     4.6    
     4.7 -    virtual void _integer(int c, bool enable);
     4.8 -    virtual bool _integer(int c);
     4.9 +    virtual ColTypes _colType(int col);
    4.10 +    virtual void _colType(int col, ColTypes col_type);
    4.11      
    4.12      virtual LpGlpk::SolveExitStatus _solve();
    4.13      virtual ParentLp::Value _getPrimal(int i);