How do I specify options for a solver?

You can specify option settings for a particular solver through the AMPL option command. Since all solvers provide default settings for their options, this is necessary only when your problem requires certain nondefault settings in order to be solved successfully, or when certain settings yield improved performance or solution accuracy.

The available options are somewhat different for each solver. To see a listing of options for a particular solver, go to our Solvers page, then click on the solver’s name. Our newer MP library interface also provides standard names for many common solver options; learn more in our Features Guide for MP-based AMPL solvers.

To specify solver options using an option statement, the general form is

option <solver-name>_options <option-string>;

where <solver-name> is replaced by the name of the solver you are using, and <option-string> is a space-separated list of the desired options (delimited by ' or " characters). For example:

option cplex_options 'relax scale=1';
option gurobi_options "lim:nodes=10000 mip:gap=1e-3 tech:writemodel=power.lp";

Most options consist of an option identifier, an = sign, and a
value that may be a number or a character string. For some solvers, there are also a few options specified by only an identifier, like relax above.

Solver option settings can easily become longer than one readable line. In such cases you can continue the option list over multiple lines by placing a \ character at the end of each line, as in:

option cplex_options 'crash=0 dual \
   feasibility=1.0e-8 scale=1 \
   lpiterlim=100';

Or you can write a series of individually quoted strings, which will be concatenated automatically by AMPL, as in:

option cplex_options "crash=0 dual"
   " feasibility=1.0e-8 scale=1"
   " lpiterlim=100";

If you use the latter approach, be sure to include spaces at the beginning or end of the individual strings, so that the identifiers will be separated by spaces when all of the strings are concatenated.

Sometimes you will want to add solver options to the list you are currently using. If you simply execute another option <solver-name>_options command, however, you will overwrite the existing option settings. Instead, use the following form to specify the existing option string followed by the option to be added:

option cplex_options $cplex_options
   ' optimality=1.0e-8';

(The $ character followed by an option name represents the current value of the option.)

To specify solver options in AMPL’s Python API, use the setOption method:

ampl.setOption('gurobi_options','lim:nodes=10000 mip:gap=1e-3')

(Similar methods are used for setting options in other AMPL API languages including C++, C#, Java, MATLAB, and R.)