过滤内容
版本
文本搜索
Tune.java
/* Copyright 2023, 狗万app足彩Gurobi Optimization, LLC */ /*这个例子从文件中读取模型并对其进行调优。然后,它将最佳参数设置写入文件,并使用这些参数求解模型。*/导入gurobi.*;public class Tune {public static void main(String[] args) {if (args。长度< 1){System.out。println("Usage: java Tune filename");system . exit (1);} try {GRBEnv env = new GRBEnv();//从文件中读取模型GRBModel model = new GRBModel(env, args[0]);//设置tunerresults参数为1 model.set(GRB.IntParam)。TuneResults, 1);//调整模型model. 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()); } } }