tune_c + + . cpp


/ * 2023年版权,Gurobi优狗万app足彩化,LLC * / / *这个例子从文件中读取一个模型和曲调。然后写的最佳参数设置文件和解决模型中使用这些参数。* / # include“gurobi_c + +。h”# include < cmath >使用名称空间性病;int主要(int命令行参数个数,char * argv[]){如果(命令行参数个数< 2){cout < <“用法:tune_c + +文件名”< < endl;返回1;}GRBEnv * env = 0;尝试{env = new GRBEnv ();/ /从文件读取模型GRBModel模型= GRBModel (* env, argv [1]);/ /设置TuneResults参数1模型。集(GRB_IntParam_TuneResults, 1); // Tune the model 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 tuned parameters to a file model.write("tune.prm"); // Solve the model using the tuned parameters model.optimize(); } } catch(GRBException e) { cout << "Error code = " << e.getErrorCode() << endl; cout << e.getMessage() << endl; } catch (...) { cout << "Error during tuning" << endl; } delete env; return 0; }