Now one can solve an lp problem.
authorathos
Mon, 04 Apr 2005 14:45:23 +0000
changeset 1298d1ca90316b59
parent 1297 fde0d12545c1
child 1299 e2545ef5d7d8
Now one can solve an lp problem.
src/work/athos/lp/lp_glpk.cc
     1.1 --- a/src/work/athos/lp/lp_glpk.cc	Mon Apr 04 10:13:33 2005 +0000
     1.2 +++ b/src/work/athos/lp/lp_glpk.cc	Mon Apr 04 14:45:23 2005 +0000
     1.3 @@ -188,71 +188,98 @@
     1.4        }
     1.5      }
     1.6    
     1.7 -    void LpGlpk::_setRowUpperBound(int i, Value up)
     1.8 -    {
     1.9 -      if (up==-INF) {
    1.10 +  void LpGlpk::_setRowUpperBound(int i, Value up)
    1.11 +  {
    1.12 +    if (up==-INF) {
    1.13 +      //FIXME error
    1.14 +    }
    1.15 +    int b=lpx_get_row_type(lp, i);
    1.16 +    double lo=lpx_get_row_lb(lp, i);
    1.17 +    if (up==INF) {
    1.18 +      switch (b) {
    1.19 +      case LPX_FR:
    1.20 +      case LPX_LO:
    1.21 +	break;
    1.22 +      case LPX_UP:
    1.23 +	lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
    1.24 +	break;
    1.25 +      case LPX_DB:
    1.26 +      case LPX_FX:
    1.27 +	lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
    1.28 +	break;
    1.29 +      default: ;
    1.30  	//FIXME error
    1.31        }
    1.32 -      int b=lpx_get_row_type(lp, i);
    1.33 -      double lo=lpx_get_row_lb(lp, i);
    1.34 -      if (up==INF) {
    1.35 -	switch (b) {
    1.36 -	case LPX_FR:
    1.37 -	case LPX_LO:
    1.38 -	  break;
    1.39 -	case LPX_UP:
    1.40 -	  lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
    1.41 -	  break;
    1.42 -	case LPX_DB:
    1.43 -	case LPX_FX:
    1.44 -	  lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
    1.45 -	  break;
    1.46 -	default: ;
    1.47 -	  //FIXME error
    1.48 -	}
    1.49 -      } else {
    1.50 -	switch (b) {
    1.51 -	case LPX_FR:
    1.52 -	  lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
    1.53 -	  break;
    1.54 -	case LPX_UP:
    1.55 -	  lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
    1.56 -	  break;
    1.57 -	case LPX_LO:
    1.58 -	case LPX_DB:
    1.59 -	case LPX_FX:
    1.60 -	  if (lo==up) 
    1.61 -	    lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
    1.62 -	  else 
    1.63 -	    lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
    1.64 -	  break;
    1.65 -	default: ;
    1.66 -	  //FIXME error
    1.67 -	}
    1.68 +    } else {
    1.69 +      switch (b) {
    1.70 +      case LPX_FR:
    1.71 +	lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
    1.72 +	break;
    1.73 +      case LPX_UP:
    1.74 +	lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
    1.75 +	break;
    1.76 +      case LPX_LO:
    1.77 +      case LPX_DB:
    1.78 +      case LPX_FX:
    1.79 +	if (lo==up) 
    1.80 +	  lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
    1.81 +	else 
    1.82 +	  lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
    1.83 +	break;
    1.84 +      default: ;
    1.85 +	//FIXME error
    1.86        }
    1.87      }
    1.88 +  }
    1.89    
    1.90 -    void LpGlpk::_setObjCoeff(int i, Value obj_coef)
    1.91 -    {
    1.92 -      lpx_set_obj_coef(lp, i, obj_coef);
    1.93 -    }
    1.94 +  void LpGlpk::_setObjCoeff(int i, Value obj_coef)
    1.95 +  {
    1.96 +    lpx_set_obj_coef(lp, i, obj_coef);
    1.97 +  }
    1.98  
    1.99  
   1.100    LpGlpk::SolutionStatus LpGlpk::_solve()
   1.101    {
   1.102 -    return SOLVED;
   1.103 +    int i=  lpx_simplex(lp);
   1.104 +    switch (i) {
   1.105 +    case LPX_E_OK: 
   1.106 +      return SOLVED;
   1.107 +      break;
   1.108 +    default:
   1.109 +      return UNSOLVED;
   1.110 +    }
   1.111    }
   1.112  
   1.113    LpGlpk::Value LpGlpk::_getPrimal(int i)
   1.114    {
   1.115 -    return 0;
   1.116 +    return lpx_get_col_prim(lp,i);
   1.117    }
   1.118    
   1.119 + 
   1.120    LpGlpk::SolutionType LpGlpk::_getPrimalType()
   1.121    {
   1.122 -    return OPTIMAL;
   1.123 +    int stat=  lpx_get_status(lp);
   1.124 +    switch (stat) {
   1.125 +    case LPX_UNDEF://Undefined (no solve has been run yet)
   1.126 +      return UNDEFINED;
   1.127 +      break;
   1.128 +    case LPX_NOFEAS://There is no feasible solution (primal, I guess)
   1.129 +    case LPX_INFEAS://Infeasible 
   1.130 +      return INFEASIBLE;
   1.131 +      break;
   1.132 +    case LPX_UNBND://Unbounded
   1.133 +      return INFINITE;
   1.134 +      break;
   1.135 +    case LPX_FEAS://Feasible
   1.136 +2      return FEASIBLE;
   1.137 +      break;
   1.138 +    case LPX_OPT://Feasible
   1.139 +      return OPTIMAL;
   1.140 +      break;
   1.141 +    default: ;
   1.142 +      //FIXME error
   1.143 +    }
   1.144    }
   1.145 -  
   1.146  
   1.147  
   1.148  } //END OF NAMESPACE LEMON