src/lemon/lp_glpk.cc
changeset 1321 bc3a4c498eb2
parent 1314 9269c76551cf
child 1326 85f1c483279e
     1.1 --- a/src/lemon/lp_glpk.cc	Fri Apr 08 05:36:16 2005 +0000
     1.2 +++ b/src/lemon/lp_glpk.cc	Fri Apr 08 06:33:11 2005 +0000
     1.3 @@ -24,169 +24,178 @@
     1.4  
     1.5  namespace lemon {
     1.6  
     1.7 -    /// \e
     1.8 -    int LpGlpk::_addCol() { 
     1.9 -	int i=lpx_add_cols(lp, 1);
    1.10 -	_setColLowerBound(i, -INF);
    1.11 -	_setColUpperBound(i, INF);
    1.12 -	return i;
    1.13 +  LpGlpk::LpGlpk() : Parent(), 
    1.14 +		     lp(lpx_create_prob()) {
    1.15 +    ///\todo constrol function for this:
    1.16 +    lpx_set_int_parm(lp, LPX_K_DUAL, 1);
    1.17 +    messageLevel(0);
    1.18 +  }
    1.19 +  
    1.20 +  LpGlpk::~LpGlpk() {
    1.21 +    lpx_delete_prob(lp);
    1.22 +  }
    1.23 +  
    1.24 +  int LpGlpk::_addCol() { 
    1.25 +    int i=lpx_add_cols(lp, 1);
    1.26 +    _setColLowerBound(i, -INF);
    1.27 +    _setColUpperBound(i, INF);
    1.28 +    return i;
    1.29 +  }
    1.30 +
    1.31 +  int LpGlpk::_addRow() { 
    1.32 +    int i=lpx_add_rows(lp, 1);
    1.33 +    return i;
    1.34 +  }
    1.35 +
    1.36 +  
    1.37 +  void LpGlpk::_setRowCoeffs(int i, 
    1.38 +			     int length,
    1.39 +			     const int   * indices, 
    1.40 +			     const Value   * values )
    1.41 +  {
    1.42 +    lpx_set_mat_row(lp, i, length,
    1.43 +		    const_cast<int * >(indices) ,
    1.44 +		    const_cast<Value * >(values));
    1.45 +  }
    1.46 +  
    1.47 +  void LpGlpk::_setColCoeffs(int i, 
    1.48 +			     int length,
    1.49 +			     const int   * indices, 
    1.50 +			     const Value   * values)
    1.51 +  {
    1.52 +    lpx_set_mat_col(lp, i, length,
    1.53 +		    const_cast<int * >(indices),
    1.54 +		    const_cast<Value * >(values));
    1.55 +  }
    1.56 +  
    1.57 +  void LpGlpk::_setColLowerBound(int i, Value lo)
    1.58 +  {
    1.59 +    if (lo==INF) {
    1.60 +      //FIXME error
    1.61 +    }
    1.62 +    int b=lpx_get_col_type(lp, i);
    1.63 +    double up=lpx_get_col_ub(lp, i);	
    1.64 +    if (lo==-INF) {
    1.65 +      switch (b) {
    1.66 +      case LPX_FR:
    1.67 +      case LPX_LO:
    1.68 +	lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
    1.69 +	break;
    1.70 +      case LPX_UP:
    1.71 +	break;
    1.72 +      case LPX_DB:
    1.73 +      case LPX_FX:
    1.74 +	lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
    1.75 +	break;
    1.76 +      default: ;
    1.77 +	//FIXME error
    1.78 +      }
    1.79 +    } else {
    1.80 +      switch (b) {
    1.81 +      case LPX_FR:
    1.82 +      case LPX_LO:
    1.83 +	lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
    1.84 +	break;
    1.85 +      case LPX_UP:	  
    1.86 +      case LPX_DB:
    1.87 +      case LPX_FX:
    1.88 +	if (lo==up) 
    1.89 +	  lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
    1.90 +	else 
    1.91 +	  lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
    1.92 +	break;
    1.93 +      default: ;
    1.94 +	//FIXME error
    1.95 +      }
    1.96      }
    1.97  
    1.98 -    /// \e
    1.99 -    int LpGlpk::_addRow() { 
   1.100 -	int i=lpx_add_rows(lp, 1);
   1.101 -	return i;
   1.102 +  }
   1.103 +  
   1.104 +  void LpGlpk::_setColUpperBound(int i, Value up)
   1.105 +  {
   1.106 +    if (up==-INF) {
   1.107 +      //FIXME error
   1.108      }
   1.109 -
   1.110 -  
   1.111 -    void LpGlpk::_setRowCoeffs(int i, 
   1.112 -			       int length,
   1.113 -			       const int   * indices, 
   1.114 -			       const Value   * values )
   1.115 -    {
   1.116 -      lpx_set_mat_row(lp, i, length,
   1.117 -		      const_cast<int * >(indices) ,
   1.118 -		      const_cast<Value * >(values));
   1.119 -    }
   1.120 -  
   1.121 -    void LpGlpk::_setColCoeffs(int i, 
   1.122 -			       int length,
   1.123 -			       const int   * indices, 
   1.124 -			       const Value   * values)
   1.125 -    {
   1.126 -      lpx_set_mat_col(lp, i, length,
   1.127 -		      const_cast<int * >(indices),
   1.128 -		      const_cast<Value * >(values));
   1.129 -    }
   1.130 -  
   1.131 -    void LpGlpk::_setColLowerBound(int i, Value lo)
   1.132 -    {
   1.133 -      if (lo==INF) {
   1.134 +    int b=lpx_get_col_type(lp, i);
   1.135 +    double lo=lpx_get_col_lb(lp, i);
   1.136 +    if (up==INF) {
   1.137 +      switch (b) {
   1.138 +      case LPX_FR:
   1.139 +      case LPX_LO:
   1.140 +	break;
   1.141 +      case LPX_UP:
   1.142 +	lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
   1.143 +	break;
   1.144 +      case LPX_DB:
   1.145 +      case LPX_FX:
   1.146 +	lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
   1.147 +	break;
   1.148 +      default: ;
   1.149  	//FIXME error
   1.150        }
   1.151 -      int b=lpx_get_col_type(lp, i);
   1.152 -      double up=lpx_get_col_ub(lp, i);	
   1.153 -      if (lo==-INF) {
   1.154 -	switch (b) {
   1.155 -	case LPX_FR:
   1.156 -	case LPX_LO:
   1.157 -	  lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
   1.158 -	  break;
   1.159 -	case LPX_UP:
   1.160 -	  break;
   1.161 -	case LPX_DB:
   1.162 -	case LPX_FX:
   1.163 -	  lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
   1.164 -	  break;
   1.165 -	default: ;
   1.166 -	  //FIXME error
   1.167 -	}
   1.168 -      } else {
   1.169 -	switch (b) {
   1.170 -	case LPX_FR:
   1.171 -	case LPX_LO:
   1.172 -	  lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
   1.173 -	  break;
   1.174 -	case LPX_UP:	  
   1.175 -	case LPX_DB:
   1.176 -	case LPX_FX:
   1.177 -	  if (lo==up) 
   1.178 -	    lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
   1.179 -	  else 
   1.180 -	    lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
   1.181 -	  break;
   1.182 -	default: ;
   1.183 -	  //FIXME error
   1.184 -	}
   1.185 -      }
   1.186 -
   1.187 -    }
   1.188 -  
   1.189 -    void LpGlpk::_setColUpperBound(int i, Value up)
   1.190 -    {
   1.191 -      if (up==-INF) {
   1.192 +    } else {
   1.193 +      switch (b) {
   1.194 +      case LPX_FR:
   1.195 +	lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
   1.196 +	break;
   1.197 +      case LPX_UP:
   1.198 +	lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
   1.199 +	break;
   1.200 +      case LPX_LO:
   1.201 +      case LPX_DB:
   1.202 +      case LPX_FX:
   1.203 +	if (lo==up) 
   1.204 +	  lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
   1.205 +	else 
   1.206 +	  lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
   1.207 +	break;
   1.208 +      default: ;
   1.209  	//FIXME error
   1.210        }
   1.211 -      int b=lpx_get_col_type(lp, i);
   1.212 -      double lo=lpx_get_col_lb(lp, i);
   1.213 -      if (up==INF) {
   1.214 -	switch (b) {
   1.215 -	case LPX_FR:
   1.216 -	case LPX_LO:
   1.217 -	  break;
   1.218 -	case LPX_UP:
   1.219 -	  lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
   1.220 -	  break;
   1.221 -	case LPX_DB:
   1.222 -	case LPX_FX:
   1.223 -	  lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
   1.224 -	  break;
   1.225 -	default: ;
   1.226 -	  //FIXME error
   1.227 -	}
   1.228 -      } else {
   1.229 -	switch (b) {
   1.230 -	case LPX_FR:
   1.231 -	  lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
   1.232 -	  break;
   1.233 -	case LPX_UP:
   1.234 -	  lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
   1.235 -	  break;
   1.236 -	case LPX_LO:
   1.237 -	case LPX_DB:
   1.238 -	case LPX_FX:
   1.239 -	  if (lo==up) 
   1.240 -	    lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
   1.241 -	  else 
   1.242 -	    lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
   1.243 -	  break;
   1.244 -	default: ;
   1.245 -	  //FIXME error
   1.246 -	}
   1.247 +    }
   1.248 +  }
   1.249 +  
   1.250 +  void LpGlpk::_setRowLowerBound(int i, Value lo)
   1.251 +  {
   1.252 +    if (lo==INF) {
   1.253 +      //FIXME error
   1.254 +    }
   1.255 +    int b=lpx_get_row_type(lp, i);
   1.256 +    double up=lpx_get_row_ub(lp, i);	
   1.257 +    if (lo==-INF) {
   1.258 +      switch (b) {
   1.259 +      case LPX_FR:
   1.260 +      case LPX_LO:
   1.261 +	lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
   1.262 +	break;
   1.263 +      case LPX_UP:
   1.264 +	break;
   1.265 +      case LPX_DB:
   1.266 +      case LPX_FX:
   1.267 +	lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
   1.268 +	break;
   1.269 +      default: ;
   1.270 +	//FIXME error
   1.271 +      }
   1.272 +    } else {
   1.273 +      switch (b) {
   1.274 +      case LPX_FR:
   1.275 +      case LPX_LO:
   1.276 +	lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
   1.277 +	break;
   1.278 +      case LPX_UP:	  
   1.279 +      case LPX_DB:
   1.280 +      case LPX_FX:
   1.281 +	if (lo==up) 
   1.282 +	  lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
   1.283 +	else 
   1.284 +	  lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
   1.285 +	break;
   1.286 +      default: ;
   1.287 +	//FIXME error
   1.288        }
   1.289      }
   1.290 -  
   1.291 -    void LpGlpk::_setRowLowerBound(int i, Value lo)
   1.292 -    {
   1.293 -      if (lo==INF) {
   1.294 -	//FIXME error
   1.295 -      }
   1.296 -      int b=lpx_get_row_type(lp, i);
   1.297 -      double up=lpx_get_row_ub(lp, i);	
   1.298 -      if (lo==-INF) {
   1.299 -	switch (b) {
   1.300 -	case LPX_FR:
   1.301 -	case LPX_LO:
   1.302 -	  lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
   1.303 -	  break;
   1.304 -	case LPX_UP:
   1.305 -	  break;
   1.306 -	case LPX_DB:
   1.307 -	case LPX_FX:
   1.308 -	  lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
   1.309 -	  break;
   1.310 -	default: ;
   1.311 -	  //FIXME error
   1.312 -	}
   1.313 -      } else {
   1.314 -	switch (b) {
   1.315 -	case LPX_FR:
   1.316 -	case LPX_LO:
   1.317 -	  lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
   1.318 -	  break;
   1.319 -	case LPX_UP:	  
   1.320 -	case LPX_DB:
   1.321 -	case LPX_FX:
   1.322 -	  if (lo==up) 
   1.323 -	    lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
   1.324 -	  else 
   1.325 -	    lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
   1.326 -	  break;
   1.327 -	default: ;
   1.328 -	  //FIXME error
   1.329 -	}
   1.330 -      }
   1.331 -    }
   1.332 +  }
   1.333    
   1.334    void LpGlpk::_setRowUpperBound(int i, Value up)
   1.335    {
   1.336 @@ -290,12 +299,19 @@
   1.337  
   1.338    void LpGlpk::_setMax()
   1.339    {
   1.340 -      lpx_set_obj_dir(lp, LPX_MAX);
   1.341 -   }
   1.342 +    lpx_set_obj_dir(lp, LPX_MAX);
   1.343 +  }
   1.344 +
   1.345    void LpGlpk::_setMin()
   1.346    {
   1.347 -      lpx_set_obj_dir(lp, LPX_MIN);
   1.348 -   }
   1.349 +    lpx_set_obj_dir(lp, LPX_MIN);
   1.350 +  }
   1.351 +
   1.352 + 
   1.353 +  void LpGlpk::messageLevel(int m)
   1.354 +  {
   1.355 +    lpx_set_int_parm(lp, LPX_K_MSGLEV, m);
   1.356 +  }
   1.357  
   1.358   
   1.359  } //END OF NAMESPACE LEMON