/* Copyright 2025, Gurobi Optimization, LLC *//* Solve a model with different values of the Method parameter; show which value gives the shortest solve time. */usingSystem;usingGurobi;classlpmethod_cs{staticvoidMain(string[]args){if(args.Length<1){Console.Out.WriteLine("Usage: lpmethod_cs filename");return;}try{// Read modelGRBEnvenv=newGRBEnv();GRBModelmodel=newGRBModel(env,args[0]);// Solve the model with different values of MethodintbestMethod=-1;doublebestTime=model.Parameters.TimeLimit;for(inti=0;i<=2;++i){model.Reset();model.Parameters.Method=i;model.Optimize();if(model.Status==GRB.Status.OPTIMAL){bestTime=model.Runtime;bestMethod=i;// Reduce the TimeLimit parameter to save time// with other methodsmodel.Parameters.TimeLimit=bestTime;}}// Report which method was fastestif(bestMethod==-1){Console.WriteLine("Unable to solve this model");}else{Console.WriteLine("Solved in "+bestTime+" seconds with Method: "+bestMethod);}// Dispose of model and envmodel.Dispose();env.Dispose();}catch(GRBExceptione){Console.WriteLine("Error code: "+e.ErrorCode+". "+e.Message);}}}
Help and Feedback