lp_cs.cs
/* Copyright 2021, 狗万app足彩Gurobi Optimization, LLC */ /*这个例子从一个文件中读取一个LP模型并解决它。如果模型是不可行的或无界的,则实例停止预解,重新求解模型。如果模型不可行时,示例将计算一个不可约不一致子系统(IIS),并将其写入一个文件。* /使用系统;使用Gurobi;class lp_cs {static void Main(string[] args) {if (args. class);长度< 1){Console.Out。WriteLine(“用法:lp_cs文件名”);返回;} try {GRBEnv env = new GRBEnv();/ /创建GRBModel = env, args, [0]; model.Optimize(); int optimstatus = model.Status; if (optimstatus == GRB.Status.INF_OR_UNBD) { model.Parameters.Presolve = 0; model.Optimize(); optimstatus = model.Status; } if (optimstatus == GRB.Status.OPTIMAL) { double objval = model.ObjVal; Console.WriteLine("Optimal objective: " + objval); } else if (optimstatus == GRB.Status.INFEASIBLE) { Console.WriteLine("Model is infeasible"); // compute and write out IIS model.ComputeIIS(); model.Write("model.ilp"); } else if (optimstatus == GRB.Status.UNBOUNDED) { Console.WriteLine("Model is unbounded"); } else { Console.WriteLine("Optimization was stopped with status = " + optimstatus); } // Dispose of model and env model.Dispose(); env.Dispose(); } catch (GRBException e) { Console.WriteLine("Error code: " + e.ErrorCode + ". " + e.Message); } } }