Params.java


Params.java


/* Copyright 2021, 狗万app足彩Gurobi Optimization, LLC */ /*使用与模型相关的参数。用不同的参数集求解一个MIP,只需几秒钟。选择MIP间隙最小的那个,继续优化,直到找到最优解。* /进口gurobi。*;public class Params {public static void main(String[] args);length < 1) {System.out. length = 1;println("Usage: java Params filename");system . exit (1);} try{//读取模型并验证它是一个MIP GRBEnv env = new GRBEnv();/ /创建GRBModel对象if (m.get(GRB.IntAttr.IsMIP) == 0) {System.out. ismip;println(“模型不是一个整数程序”); System.exit(1); } // Set a 2 second time limit m.set(GRB.DoubleParam.TimeLimit, 2); // 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.set(GRB.IntParam.MIPFocus, i); m.optimize(); if (bestModel.get(GRB.DoubleAttr.MIPGap) > m.get(GRB.DoubleAttr.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.set(GRB.DoubleParam.TimeLimit, GRB.INFINITY); bestModel.optimize(); System.out.println("Solved with MIPFocus: " + bestModel.get(GRB.IntParam.MIPFocus)); } catch (GRBException e) { System.out.println("Error code: " + e.getErrorCode() + ". " + e.getMessage()); } } }