lpmod_cs.cs.


lpmod_cs.cs.


/ *版权所有2021,Gurobi优狗万app足彩化,LLC * // *此示例从文件中读取LP模型并解决它。如果模型可以解决,那么它找到了最小的正变量,将其上限设置为零,并解决模型两种方式:首先具有高级开始,然后没有高级开始(即'从划痕')。* /使用系统;使用gurobi;class lpmod_cs {静态void main(String [] args){if(args.length <1){console.out.writeline(“用法:lpmod_cs filename”);返回;}尝试{//读取模型并确定它是一个lp grbenv ent = new grbenv();grbmodel模型=新grbmodel(env,args [0]);if(model.ismip!= 0){console.writeline(“模型不是线性程序”);环境。(1); } model.Optimize(); int status = model.Status; if ((status == GRB.Status.INF_OR_UNBD) || (status == GRB.Status.INFEASIBLE) || (status == GRB.Status.UNBOUNDED)) { Console.WriteLine("The model cannot be solved because it is " + "infeasible or unbounded"); Environment.Exit(1); } if (status != GRB.Status.OPTIMAL) { Console.WriteLine("Optimization was stopped with status " + status); Environment.Exit(0); } // Find the smallest variable value double minVal = GRB.INFINITY; GRBVar minVar = null; foreach (GRBVar v in model.GetVars()) { double sol = v.X; if ((sol > 0.0001) && (sol < minVal) && (v.LB == 0.0)) { minVal = sol; minVar = v; } } Console.WriteLine("\n*** Setting " + minVar.VarName + " from " + minVal + " to zero ***\n"); minVar.UB = 0.0; // Solve from this starting point model.Optimize(); // Save iteration & time info double warmCount = model.IterCount; double warmTime = model.Runtime; // Reset the model and resolve Console.WriteLine("\n*** Resetting and solving " + "without an advanced start ***\n"); model.Reset(); model.Optimize(); double coldCount = model.IterCount; double coldTime = model.Runtime; Console.WriteLine("\n*** Warm start: " + warmCount + " iterations, " + warmTime + " seconds"); Console.WriteLine("*** Cold start: " + coldCount + " iterations, " + coldTime + " seconds"); // Dispose of model and env model.Dispose(); env.Dispose(); } catch (GRBException e) { Console.WriteLine("Error code: " + e.ErrorCode + ". " + e.Message); } } }