tune_c.c


/ * 2023年版权,Gurobi优狗万app足彩化,LLC * / / *这个例子从文件中读取一个模型和曲调。然后写的最佳参数设置文件和解决模型中使用这些参数。* / # include < stdlib。h > # include < stdio。h > # include <数学。h > # include " gurobi_c。h“int主要(int命令行参数个数,char * argv []) {GRBenv * env =零;GRBmodel *模型=零;int tuneresultcount;int错误= 0;如果(命令行参数个数< 2){流(stderr,“用法:tune_c文件名\ n”);退出(1); } /* Create environment */ error = GRBloadenv(&env, "tune_c.log"); if (error) goto QUIT; /* Read model from file */ error = GRBreadmodel(env, argv[1], &model); if (error) goto QUIT; /* Set the TuneResults parameter to 1 */ error = GRBsetintparam(GRBgetenv(model), GRB_INT_PAR_TUNERESULTS, 1); if (error) goto QUIT; /* Tune the model */ error = GRBtunemodel(model); if (error) goto QUIT; /* Get the number of tuning results */ error = GRBgetintattr(model, GRB_INT_ATTR_TUNE_RESULTCOUNT, &tuneresultcount); if (error) goto QUIT; if (tuneresultcount > 0) { /* Load the best tuned parameters into the model's environment */ error = GRBgettuneresult(model, 0); if (error) goto QUIT; /* Write tuned parameters to a file */ error = GRBwrite(model, "tune.prm"); if (error) goto QUIT; /* Solve the model using the tuned parameters */ error = GRBoptimize(model); if (error) goto QUIT; } QUIT: /* Error reporting */ if (error) { printf("ERROR: %s\n", GRBgeterrormsg(env)); exit(1); } /* Free model */ GRBfreemodel(model); /* Free environment */ GRBfreeenv(env); return 0; }