Movatterモバイル変換


[0]ホーム

URL:


ContentsMenuExpandLight modeDark modeAuto light/dark mode
Gurobi Example Tour
Light LogoDark Logo
Gurobi
Back to top

Lpmethod Examples#

This section includes source code for all of the Gurobi lpmethod examples.The same source code can be found in theexamples directory of theGurobi distribution.

/* Copyright 2025, Gurobi Optimization, LLC *//* Solve a model with different values of the Method parameter;   show which value gives the shortest solve time. */#include<assert.h>#include<stdlib.h>#include<stdio.h>#include"gurobi_c.h"intmain(intargc,char*argv[]){GRBenv*env=NULL,*menv;GRBmodel*m=NULL;interror=0;inti;intoptimstatus;intbestMethod=-1;doublebestTime;if(argc<2){fprintf(stderr,"Usage: lpmethod_c filename\n");exit(1);}error=GRBloadenv(&env,"lpmethod.log");if(error)gotoQUIT;/* Read model */error=GRBreadmodel(env,argv[1],&m);if(error)gotoQUIT;menv=GRBgetenv(m);assert(menv!=NULL);error=GRBgetdblparam(menv,"TimeLimit",&bestTime);if(error)gotoQUIT;/* Solve the model with different values of Method */for(i=0;i<=2;++i){error=GRBreset(m,0);if(error)gotoQUIT;error=GRBsetintparam(menv,"Method",i);if(error)gotoQUIT;error=GRBoptimize(m);if(error)gotoQUIT;error=GRBgetintattr(m,"Status",&optimstatus);if(error)gotoQUIT;if(optimstatus==GRB_OPTIMAL){error=GRBgetdblattr(m,"Runtime",&bestTime);if(error)gotoQUIT;bestMethod=i;/* Reduce the TimeLimit parameter to save time         with other methods */error=GRBsetdblparam(menv,"TimeLimit",bestTime);if(error)gotoQUIT;}}/* Report which method was fastest */if(bestMethod==-1){printf("Unable to solve this model\n");}else{printf("Solved in %f seconds with Method: %i\n",bestTime,bestMethod);}QUIT:/* Error reporting */if(error){printf("ERROR: %s\n",GRBgeterrormsg(env));exit(1);}/* Free model */GRBfreemodel(m);/* Free environment */GRBfreeenv(env);return0;}

Help and Feedback


[8]
ページ先頭

©2009-2025 Movatter.jp