#!/usr/bin/env python3# Copyright 2025, Gurobi Optimization, LLC# Solve a model with different values of the Method parameter;# show which value gives the shortest solve time.importsysimportgurobipyasgpfromgurobipyimportGRBiflen(sys.argv)<2:print("Usage: lpmethod.py filename")sys.exit(0)# Read modelm=gp.read(sys.argv[1])# Solve the model with different values of MethodbestTime=m.Params.TimeLimitbestMethod=-1foriinrange(3):m.reset()m.Params.Method=im.optimize()ifm.Status==GRB.OPTIMAL:bestTime=m.RuntimebestMethod=i# Reduce the TimeLimit parameter to save time with other methodsm.Params.TimeLimit=bestTime# Report which method was fastestifbestMethod==-1:print("Unable to solve this model")else:print(f"Solved in{bestTime:g} seconds with Method{bestMethod}")
Help and Feedback