Tune.java


Tune.java


/* Copyright 2021, 狗万app足彩Gurobi Optimization, LLC */ /*这个例子从一个文件中读取一个模型并调优它。然后,它将最佳参数设置写入文件,并使用这些参数解决模型。* /进口gurobi。*;public class Tune {public static void main(String[] args);length < 1) {System.out. length = 1;println("Usage: java Tune filename");system . exit (1);} try {GRBEnv env = new GRBEnv();//从文件中读取GRBModel model = new GRBModel(env, args[0]);//设置TuneResults参数为1 model.set(GRB.IntParam.);TuneResults, 1);//调整模型模型。Tune (); // Get the number of tuning results int resultcount = model.get(GRB.IntAttr.TuneResultCount); if (resultcount > 0) { // Load the tuned parameters into the model's environment model.getTuneResult(0); // Write the tuned parameters to a file model.write("tune.prm"); // Solve the model using the tuned parameters model.optimize(); } // Dispose of model and environment model.dispose(); env.dispose(); } catch (GRBException e) { System.out.println("Error code: " + e.getErrorCode() + ". " + e.getMessage()); } } }