manbet体育手机客户端


feasopt_cs.cs.


/ *版权所有2019,Gurobi优狗万app足彩化,LLC * // *此示例从文件中读取MIP模型,将人工变量添加到每个约束,然后最大限度地减少人工变量的总和。具有目标零的解决方案对应于输入模型的可行解决方案。我们还可以使用Feasrelax功能来进行。在此示例中,我们使用Minrelax = 1,即优化返回的模型找到最小化原始目标的解决方案,而是仅来自最小化人工变量的总和的解决方案中。* /使用gurobi;使用系统;类feasopt_cs {静态void main(String [] args){if(args.length <1){console.out.writeline(“用法:feasopt_cs filename”);返回;试试{grbenv env = new grbenv();grbmodel feasmodel = new grbmodel(env,args [0]); // Create a copy to use FeasRelax feature later */ GRBModel feasmodel1 = new GRBModel(feasmodel); // Clear objective feasmodel.SetObjective(new GRBLinExpr()); // Add slack variables GRBConstr[] c = feasmodel.GetConstrs(); for (int i = 0; i < c.Length; ++i) { char sense = c[i].Sense; if (sense != '>') { GRBConstr[] constrs = new GRBConstr[] { c[i] }; double[] coeffs = new double[] { -1 }; feasmodel.AddVar(0.0, GRB.INFINITY, 1.0, GRB.CONTINUOUS, constrs, coeffs, "ArtN_" + c[i].ConstrName); } if (sense != '<') { GRBConstr[] constrs = new GRBConstr[] { c[i] }; double[] coeffs = new double[] { 1 }; feasmodel.AddVar(0.0, GRB.INFINITY, 1.0, GRB.CONTINUOUS, constrs, coeffs, "ArtP_" + c[i].ConstrName); } } // Optimize modified model feasmodel.Optimize(); feasmodel.Write("feasopt.lp"); // Use FeasRelax feature */ feasmodel1.FeasRelax(GRB.FEASRELAX_LINEAR, true, false, true); feasmodel1.Write("feasopt1.lp"); feasmodel1.Optimize(); // Dispose of model and env feasmodel1.Dispose(); feasmodel.Dispose(); env.Dispose(); } catch (GRBException e) { Console.WriteLine("Error code: " + e.ErrorCode + ". " + e.Message); } } }