tune_c + + . cpp


tune_c + + . cpp


/* Copyright 2021, 狗万app足彩Gurobi Optimization, LLC */ /*这个例子从一个文件中读取一个模型并调优它。然后,它将最佳参数设置写入文件,并使用这些参数解决模型。*/ #include "gurobi_c++.h" #include  using namespace std;int main(int argc, char *argv[]) {if (argc < 2) {cout << "Usage: tune_c++ filename" << endl;返回1;} GRBEnv *env = 0;try {env = new GRBEnv();//从文件中读取GRBModel model = GRBModel(*env, argv[1]);//设置TuneResults参数为1个模型。集(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 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; }