Which options to use
The problem is that the "time limit" is not handled by Pyomo (which just connects to a solver), but by the solver itself. Different solvers have different names for "time limit" options. See this StackOverflow post about that. The timelimit
option you're setting above would work for CPLEX, but maybe not for GAMS (see next paragraph).
I happen to use GAMS with Pyomo, and I know that GAMS uses an option called resLim
. This webpage lists all GAMS options. Note that GAMS, like Pyomo, really just interfaces to lower-level solver executables, and some GAMS options depend on which solver you're using. The link above differentiates between "solver-specific" parameters. GAMS seems to do a good job of making this process easy - for example, the CPLEX solver has a timelimit
option, and GAMS will automatically pass your value for the resLim
option as timelimit
if you are calling a CPLEX solver via GAMS. (I believe you can also pass options to GAMS and specify which solver they should apply to in the case of a GAMS solver that uses subsolvers, for example option CPLEX.timelimit=100;
, but I can't find documentation on this).
Passing options (via Pyomo)
Usually to set a solver option, you should use io_options
rather than passing a keyword argument directly to solve
(though that may sometimes work).
io_options=dict(resLim=100)
results = slv.solve(model,tee=True,io_options=io_options)
Note that you may want to put many options for your GAMS solver in a file. This could be helpful if you call many solvers via GAMS, and you want them all to have different options specified, and you don't want this to clutter your Python code. Instead, you can just tell GAMS "check the DICOPT options file for DICOPT options, etc.". Let's say you're using the DICOPT solver via GAMS, and you have dozens of options. You can store them in a file called DICOPT.opt
in your GAMS working directory that looks like this
max_iter 200000
resLim 100
then tell Pyomo to read from the file like this:
io_options = dict(
add_options=["GAMS_MODEL.OptFile=1"],
)
results = slv.solve(model,tee=True,io_options=io_options)
This tells GAMS to look for the correct file (that is, SOLVERNAME.opt
) and read options from it.