params_cs.cs.


params_cs.cs.


/ *版权所有2021,Gurobi优狗万app足彩化,LLC * // *使用与型号关联的参数。使用不同的参数,解决了MIP几秒钟。选择具有最小MIP间隙的距离,并且恢复优化直到找到最佳解决方案。* /使用系统;使用gurobi;class params_cs {静态void main(string [] args){if(args.length <1){console.out.writeline(“用法:params_cs filename”);返回;尝试{//读取模型并验证它是mip grbenv ent = new grbenv();grbmodel m = new grbmodel(env,args [0]);if(m.ismip == 0){console.writeline(“模型不是整数程序”); Environment.Exit(1); } // Set a 2 second time limit m.Parameters.TimeLimit = 2.0; // Now solve the model with different values of MIPFocus GRBModel bestModel = new GRBModel(m); bestModel.Optimize(); for (int i = 1; i <= 3; ++i) { m.Reset(); m.Parameters.MIPFocus = i; m.Optimize(); if (bestModel.MIPGap > m.MIPGap) { GRBModel swap = bestModel; bestModel = m; m = swap; } } // Finally, delete the extra model, reset the time limit and // continue to solve the best model to optimality m.Dispose(); bestModel.Parameters.TimeLimit = GRB.INFINITY; bestModel.Optimize(); Console.WriteLine("Solved with MIPFocus: " + bestModel.Parameters.MIPFocus); // Clean up bestModel and environment bestModel.Dispose(); env.Dispose(); } catch (GRBException e) { Console.WriteLine("Error code: " + e.ErrorCode + ". " + e.Message); } } }