void glp_init_smcp(glp_smcp parm) { parm.msg_lev = glp_smcp.GLP_MSG_ALL; parm.meth = glp_smcp.GLP_PRIMAL; parm.pricing = glp_smcp.GLP_PT_PSE; parm.r_test = glp_smcp.GLP_RT_HAR; parm.tol_bnd = 1e-7; parm.tol_dj = 1e-7; parm.tol_piv = 1e-10; parm.obj_ll = Double.MinValue; parm.obj_ul = Double.MaxValue; parm.it_lim = Int32.MaxValue; parm.tm_lim = Int32.MaxValue; parm.out_frq = 500; parm.out_dly = 0; parm.presolve = glp_smcp.GLP_OFF; return; }
public bool solveProb() { int num_int = glp_get_num_int(lp); int num_bin = glp_get_num_bin(lp); Console.WriteLine("num_int : " + num_int.ToString()); Console.WriteLine("num_bin : " + num_bin.ToString()); //glp_term_out(GLP_OFF); /* * * ae_max | largest absolute error; * ae_ind | number of row (KKT.PE), column (KKT.DE), or variable (KKT.PB, KKT.DB) with * the largest absolute error; * re_max | largest relative error; * re_ind | number of row (KKT.PE), column (KKT.DE), or variable (KKT.PB, KKT.DB) with * the largest relative error * */ glp_smcp parm = new glp_smcp(); glp_init_smcp(parm); parm.meth = glp_smcp.GLP_DUALP; //parm.presolve = GLP_ON; parm.tm_lim = (int)Program.MAXTIME_SIMPLEX;//time limit of simplex parm.it_lim = 300000; //glp_unscale_prob(lp); glp_scale_prob(lp, GLP_SF_AUTO); // glp_mem_limit(1);//Program.MAXMEMORY_MB); TimeSpan start = new TimeSpan(DateTime.Now.Ticks); simplexReturn = glp_simplex(lp, parm);//glp_interior(lp, null); TimeSpan SimplexEnd = new TimeSpan(DateTime.Now.Ticks); TimeSpan usingtimeSimplex = SimplexEnd.Subtract(start).Duration(); SimplextimeUse = (int)usingtimeSimplex.TotalMilliseconds; #region comment : simplex return valeur /* * 0 The problem instance has been successfully solved. (This code does not necessarily * mean that the solver has found optimal solution. It only means that the solution process was successful.) * GLP_EBOUND Unable to start the search, because some double-bounded variables have incorrect * bounds or some integer variables have non-integer (fractional) bounds. * GLP_EROOT Unable to start the search, because optimal basis for initial LP relaxation is not * provided. (This code may appear only if the presolver is disabled.) * GLP_ENOPFS Unable to start the search, because LP relaxation of the MIP problem instance has no primal feasible solution. * (This code may appear only if the presolver is enabled.) * GLP_ENODFS Unable to start the search, because LP relaxation of the MIP problem instance has * no dual feasible solution. In other word, this code means that if the LP relaxation * has at least one primal feasible solution, its optimal solution is unbounded, so if the MIP problem * has at least one integer feasible solution, its (integer) optimal solution is also unbounded. * (This code may appear only if the presolver is enabled.) * GLP_EFAIL The search was prematurely terminated due to the solver failure. * GLP_EMIPGAP The search was prematurely terminated, because the relative mip gap tolerance has been reached. * GLP_ETMLIM The search was prematurely terminated, because the time limit has been exceeded. * GLP_ESTOP The search was prematurely terminated by application. (This code may appear only if the advanced solver interface is used.) * * */ /*** statusSimplex : * GLP_UNDEF | primal solution is undefined; * GLP_FEAS | primal solution is feasible; * GLP_INFEAS | primal solution is infeasible; * GLP_NOFEAS | no primal feasible solution exists. * */ #endregion int statusSimplex = glp_get_prim_stat(lp); switch (simplexReturn) { case 0: if (statusSimplex == GLP_FEAS) { simplexOK = true; //Console.Out.WriteLine("simplex : solution réalisable"); try { mipSolve(); } catch (Exception) { Console.Out.WriteLine("memoire dépassée de MIP"); //Transaction.Current.Rollback(); } } else { simplexOK = false; //Console.Out.WriteLine("Simplex ne peut pas obtenir une solution réalisable"); } break; case GLP_ETMLIM: this.simplexTimeOverflow = true; //Console.Out.WriteLine("simplex : temps limit dépassée"); if (statusSimplex == GLP_FEAS) { simplexOK = true; //Console.Out.WriteLine("simplex : solution réalisable"); try { mipSolve(); } catch (Exception) { Console.Out.WriteLine("bloc CATCH : memoire dépassée de MIP"); //Transaction.Current.Rollback(); } } else { simplexOK = false; glp_mem_usage(null, null, ref memUse, null); //Console.Out.WriteLine("simplex : pas de solution réalisable"); } break; default: { simplexOK = false; glp_mem_usage(null, null, ref memUse, null); //Console.Out.WriteLine("simplex failure"); break; } } TimeSpan end = new TimeSpan(DateTime.Now.Ticks); TimeSpan usingtime = end.Subtract(start).Duration(); //executeTime = usingtime.ToString(); this.timeUse = usingtime.TotalMilliseconds; return(true); }
static extern int glp_simplex(double *P, glp_smcp parm);