[Lemon-commits] [lemon_svn] athos: r1733 - hugo/trunk/src/work/athos/lp

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:47:14 CET 2006


Author: athos
Date: Mon Apr  4 16:45:23 2005
New Revision: 1733

Modified:
   hugo/trunk/src/work/athos/lp/lp_glpk.cc

Log:
Now one can solve an lp problem.

Modified: hugo/trunk/src/work/athos/lp/lp_glpk.cc
==============================================================================
--- hugo/trunk/src/work/athos/lp/lp_glpk.cc	(original)
+++ hugo/trunk/src/work/athos/lp/lp_glpk.cc	Mon Apr  4 16:45:23 2005
@@ -188,71 +188,98 @@
       }
     }
   
-    void LpGlpk::_setRowUpperBound(int i, Value up)
-    {
-      if (up==-INF) {
+  void LpGlpk::_setRowUpperBound(int i, Value up)
+  {
+    if (up==-INF) {
+      //FIXME error
+    }
+    int b=lpx_get_row_type(lp, i);
+    double lo=lpx_get_row_lb(lp, i);
+    if (up==INF) {
+      switch (b) {
+      case LPX_FR:
+      case LPX_LO:
+	break;
+      case LPX_UP:
+	lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
+	break;
+      case LPX_DB:
+      case LPX_FX:
+	lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
+	break;
+      default: ;
 	//FIXME error
       }
-      int b=lpx_get_row_type(lp, i);
-      double lo=lpx_get_row_lb(lp, i);
-      if (up==INF) {
-	switch (b) {
-	case LPX_FR:
-	case LPX_LO:
-	  break;
-	case LPX_UP:
-	  lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
-	  break;
-	case LPX_DB:
-	case LPX_FX:
-	  lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
-	  break;
-	default: ;
-	  //FIXME error
-	}
-      } else {
-	switch (b) {
-	case LPX_FR:
-	  lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
-	  break;
-	case LPX_UP:
-	  lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
-	  break;
-	case LPX_LO:
-	case LPX_DB:
-	case LPX_FX:
-	  if (lo==up) 
-	    lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
-	  else 
-	    lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
-	  break;
-	default: ;
-	  //FIXME error
-	}
+    } else {
+      switch (b) {
+      case LPX_FR:
+	lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
+	break;
+      case LPX_UP:
+	lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
+	break;
+      case LPX_LO:
+      case LPX_DB:
+      case LPX_FX:
+	if (lo==up) 
+	  lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
+	else 
+	  lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
+	break;
+      default: ;
+	//FIXME error
       }
     }
+  }
   
-    void LpGlpk::_setObjCoeff(int i, Value obj_coef)
-    {
-      lpx_set_obj_coef(lp, i, obj_coef);
-    }
+  void LpGlpk::_setObjCoeff(int i, Value obj_coef)
+  {
+    lpx_set_obj_coef(lp, i, obj_coef);
+  }
 
 
   LpGlpk::SolutionStatus LpGlpk::_solve()
   {
-    return SOLVED;
+    int i=  lpx_simplex(lp);
+    switch (i) {
+    case LPX_E_OK: 
+      return SOLVED;
+      break;
+    default:
+      return UNSOLVED;
+    }
   }
 
   LpGlpk::Value LpGlpk::_getPrimal(int i)
   {
-    return 0;
+    return lpx_get_col_prim(lp,i);
   }
   
+ 
   LpGlpk::SolutionType LpGlpk::_getPrimalType()
   {
-    return OPTIMAL;
+    int stat=  lpx_get_status(lp);
+    switch (stat) {
+    case LPX_UNDEF://Undefined (no solve has been run yet)
+      return UNDEFINED;
+      break;
+    case LPX_NOFEAS://There is no feasible solution (primal, I guess)
+    case LPX_INFEAS://Infeasible 
+      return INFEASIBLE;
+      break;
+    case LPX_UNBND://Unbounded
+      return INFINITE;
+      break;
+    case LPX_FEAS://Feasible
+2      return FEASIBLE;
+      break;
+    case LPX_OPT://Feasible
+      return OPTIMAL;
+      break;
+    default: ;
+      //FIXME error
+    }
   }
-  
 
 
 } //END OF NAMESPACE LEMON



More information about the Lemon-commits mailing list