Copy constructor for LpGlpk
authoralpar
Mon, 04 Dec 2006 13:13:14 +0000
changeset 2321e23a610bed51
parent 2320 4e8ecce96b12
child 2322 12c5f99807d8
Copy constructor for LpGlpk
lemon/lp_glpk.cc
lemon/lp_glpk.h
     1.1 --- a/lemon/lp_glpk.cc	Thu Nov 30 16:40:09 2006 +0000
     1.2 +++ b/lemon/lp_glpk.cc	Mon Dec 04 13:13:14 2006 +0000
     1.3 @@ -31,6 +31,37 @@
     1.4      messageLevel(0);
     1.5    }
     1.6    
     1.7 +  LpGlpk::LpGlpk(const LpGlpk &glp) : Parent(glp), 
     1.8 +				      lp(lpx_create_prob()) {
     1.9 +    ///\todo constrol function for this:
    1.10 +    lpx_set_int_parm(lp, LPX_K_DUAL, 1);
    1.11 +    messageLevel(0);
    1.12 +    //Coefficient matrix, row bounds
    1.13 +    lpx_add_rows(lp, lpx_get_num_rows(glp.lp));
    1.14 +    lpx_add_cols(lp, lpx_get_num_cols(glp.lp));
    1.15 +    int len;
    1.16 +    int ind[1+lpx_get_num_cols(glp.lp)];
    1.17 +    Value val[1+lpx_get_num_cols(glp.lp)];
    1.18 +    for (int i=1;i<=lpx_get_num_rows(glp.lp);++i)
    1.19 +      {
    1.20 +	len=lpx_get_mat_row(glp.lp,i,ind,val);
    1.21 +	lpx_set_mat_row(lp, i,len,ind,val);
    1.22 +	lpx_set_row_bnds(lp,i,lpx_get_row_type(glp.lp,i),
    1.23 +			 lpx_get_row_lb(glp.lp,i),lpx_get_row_ub(glp.lp,i));
    1.24 +      }
    1.25 +
    1.26 +    //Objective function, coloumn bounds
    1.27 +    lpx_set_obj_dir(lp, lpx_get_obj_dir(glp.lp));
    1.28 +    //Objectif function's constant term treated separately
    1.29 +    lpx_set_obj_coef(lp,0,lpx_get_obj_coef(glp.lp,0));
    1.30 +    for (int i=1;i<=lpx_get_num_cols(glp.lp);++i)
    1.31 +      {
    1.32 +	lpx_set_obj_coef(lp,i,lpx_get_obj_coef(glp.lp,i));
    1.33 +	lpx_set_col_bnds(lp,i,lpx_get_col_type(glp.lp,i),
    1.34 +			 lpx_get_col_lb(glp.lp,i),lpx_get_col_ub(glp.lp,i));
    1.35 +      }
    1.36 +  }
    1.37 +  
    1.38    LpGlpk::~LpGlpk() {
    1.39      lpx_delete_prob(lp);
    1.40    }
    1.41 @@ -47,7 +78,7 @@
    1.42  
    1.43    LpSolverBase &LpGlpk::_newLp()
    1.44    {
    1.45 -    LpGlpk* newlp=new LpGlpk();
    1.46 +    LpGlpk* newlp=new LpGlpk;
    1.47      return *newlp;
    1.48    }
    1.49    
    1.50 @@ -55,33 +86,7 @@
    1.51  
    1.52    LpSolverBase &LpGlpk::_copyLp()
    1.53    {
    1.54 -    LpGlpk* newlp=new LpGlpk();
    1.55 -
    1.56 -    //Coefficient matrix, row bounds
    1.57 -    lpx_add_rows(newlp->lp, lpx_get_num_rows(lp));
    1.58 -    lpx_add_cols(newlp->lp, lpx_get_num_cols(lp));
    1.59 -    int len;
    1.60 -    int ind[1+lpx_get_num_cols(lp)];
    1.61 -    Value val[1+lpx_get_num_cols(lp)];
    1.62 -    for (int i=1;i<=lpx_get_num_rows(lp);++i){
    1.63 -      len=lpx_get_mat_row(lp,i,ind,val);
    1.64 -      lpx_set_mat_row(newlp->lp, i,len,ind,val);
    1.65 -      lpx_set_row_bnds(newlp->lp,i,lpx_get_row_type(lp,i),
    1.66 -		       lpx_get_row_lb(lp,i),lpx_get_row_ub(lp,i));
    1.67 -    }
    1.68 -
    1.69 -    //Objective function, coloumn bounds
    1.70 -    lpx_set_obj_dir(newlp->lp, lpx_get_obj_dir(lp));
    1.71 -    //Objectif function's constant term treated separately
    1.72 -    lpx_set_obj_coef(newlp->lp,0,lpx_get_obj_coef(lp,0));
    1.73 -    for (int i=1;i<=lpx_get_num_cols(lp);++i){
    1.74 -      lpx_set_obj_coef(newlp->lp,i,lpx_get_obj_coef(lp,i));
    1.75 -      lpx_set_col_bnds(newlp->lp,i,lpx_get_col_type(lp,i),
    1.76 -		       lpx_get_col_lb(lp,i),lpx_get_col_ub(lp,i));
    1.77 -      
    1.78 -      
    1.79 -    }
    1.80 -
    1.81 +    LpGlpk* newlp=new LpGlpk(*this);
    1.82      return *newlp;
    1.83    }
    1.84  
     2.1 --- a/lemon/lp_glpk.h	Thu Nov 30 16:40:09 2006 +0000
     2.2 +++ b/lemon/lp_glpk.h	Mon Dec 04 13:13:14 2006 +0000
     2.3 @@ -44,6 +44,7 @@
     2.4      typedef LpSolverBase Parent;
     2.5      
     2.6      LpGlpk();
     2.7 +    LpGlpk(const LpGlpk &);
     2.8      ~LpGlpk();
     2.9      
    2.10    protected:
    2.11 @@ -108,7 +109,8 @@
    2.12      ///
    2.13      ///The presolver is off by default.
    2.14      void presolver(bool b);
    2.15 -    
    2.16 +
    2.17 +    LPX *lpx() {return lp;}
    2.18    };
    2.19  } //END OF NAMESPACE LEMON
    2.20