lemon/lp_glpk.cc
changeset 2321 e23a610bed51
parent 2312 07e46cbb7d85
child 2324 18fc834761d9
equal deleted inserted replaced
15:52d1976b9918 16:533d2cca3b59
    29     ///\todo constrol function for this:
    29     ///\todo constrol function for this:
    30     lpx_set_int_parm(lp, LPX_K_DUAL, 1);
    30     lpx_set_int_parm(lp, LPX_K_DUAL, 1);
    31     messageLevel(0);
    31     messageLevel(0);
    32   }
    32   }
    33   
    33   
       
    34   LpGlpk::LpGlpk(const LpGlpk &glp) : Parent(glp), 
       
    35 				      lp(lpx_create_prob()) {
       
    36     ///\todo constrol function for this:
       
    37     lpx_set_int_parm(lp, LPX_K_DUAL, 1);
       
    38     messageLevel(0);
       
    39     //Coefficient matrix, row bounds
       
    40     lpx_add_rows(lp, lpx_get_num_rows(glp.lp));
       
    41     lpx_add_cols(lp, lpx_get_num_cols(glp.lp));
       
    42     int len;
       
    43     int ind[1+lpx_get_num_cols(glp.lp)];
       
    44     Value val[1+lpx_get_num_cols(glp.lp)];
       
    45     for (int i=1;i<=lpx_get_num_rows(glp.lp);++i)
       
    46       {
       
    47 	len=lpx_get_mat_row(glp.lp,i,ind,val);
       
    48 	lpx_set_mat_row(lp, i,len,ind,val);
       
    49 	lpx_set_row_bnds(lp,i,lpx_get_row_type(glp.lp,i),
       
    50 			 lpx_get_row_lb(glp.lp,i),lpx_get_row_ub(glp.lp,i));
       
    51       }
       
    52 
       
    53     //Objective function, coloumn bounds
       
    54     lpx_set_obj_dir(lp, lpx_get_obj_dir(glp.lp));
       
    55     //Objectif function's constant term treated separately
       
    56     lpx_set_obj_coef(lp,0,lpx_get_obj_coef(glp.lp,0));
       
    57     for (int i=1;i<=lpx_get_num_cols(glp.lp);++i)
       
    58       {
       
    59 	lpx_set_obj_coef(lp,i,lpx_get_obj_coef(glp.lp,i));
       
    60 	lpx_set_col_bnds(lp,i,lpx_get_col_type(glp.lp,i),
       
    61 			 lpx_get_col_lb(glp.lp,i),lpx_get_col_ub(glp.lp,i));
       
    62       }
       
    63   }
       
    64   
    34   LpGlpk::~LpGlpk() {
    65   LpGlpk::~LpGlpk() {
    35     lpx_delete_prob(lp);
    66     lpx_delete_prob(lp);
    36   }
    67   }
    37   
    68   
    38   int LpGlpk::_addCol() { 
    69   int LpGlpk::_addCol() { 
    45   ///\e
    76   ///\e
    46 
    77 
    47 
    78 
    48   LpSolverBase &LpGlpk::_newLp()
    79   LpSolverBase &LpGlpk::_newLp()
    49   {
    80   {
    50     LpGlpk* newlp=new LpGlpk();
    81     LpGlpk* newlp=new LpGlpk;
    51     return *newlp;
    82     return *newlp;
    52   }
    83   }
    53   
    84   
    54   ///\e
    85   ///\e
    55 
    86 
    56   LpSolverBase &LpGlpk::_copyLp()
    87   LpSolverBase &LpGlpk::_copyLp()
    57   {
    88   {
    58     LpGlpk* newlp=new LpGlpk();
    89     LpGlpk* newlp=new LpGlpk(*this);
    59 
       
    60     //Coefficient matrix, row bounds
       
    61     lpx_add_rows(newlp->lp, lpx_get_num_rows(lp));
       
    62     lpx_add_cols(newlp->lp, lpx_get_num_cols(lp));
       
    63     int len;
       
    64     int ind[1+lpx_get_num_cols(lp)];
       
    65     Value val[1+lpx_get_num_cols(lp)];
       
    66     for (int i=1;i<=lpx_get_num_rows(lp);++i){
       
    67       len=lpx_get_mat_row(lp,i,ind,val);
       
    68       lpx_set_mat_row(newlp->lp, i,len,ind,val);
       
    69       lpx_set_row_bnds(newlp->lp,i,lpx_get_row_type(lp,i),
       
    70 		       lpx_get_row_lb(lp,i),lpx_get_row_ub(lp,i));
       
    71     }
       
    72 
       
    73     //Objective function, coloumn bounds
       
    74     lpx_set_obj_dir(newlp->lp, lpx_get_obj_dir(lp));
       
    75     //Objectif function's constant term treated separately
       
    76     lpx_set_obj_coef(newlp->lp,0,lpx_get_obj_coef(lp,0));
       
    77     for (int i=1;i<=lpx_get_num_cols(lp);++i){
       
    78       lpx_set_obj_coef(newlp->lp,i,lpx_get_obj_coef(lp,i));
       
    79       lpx_set_col_bnds(newlp->lp,i,lpx_get_col_type(lp,i),
       
    80 		       lpx_get_col_lb(lp,i),lpx_get_col_ub(lp,i));
       
    81       
       
    82       
       
    83     }
       
    84 
       
    85     return *newlp;
    90     return *newlp;
    86   }
    91   }
    87 
    92 
    88   int LpGlpk::_addRow() { 
    93   int LpGlpk::_addRow() { 
    89     int i=lpx_add_rows(lp, 1);
    94     int i=lpx_add_rows(lp, 1);