7.4 Setting solver parameters

MOSEK comes with a large number of parameters that allows the user to tune the behavior of the optimizer. The typical settings which can be changed with solver parameters include:

  • choice of the optimizer for linear problems,
  • choice of primal/dual solver,
  • turning presolve on/off,
  • turning heuristics in the mixed-integer optimizer on/off,
  • level of multi-threading,
  • feasibility tolerances,
  • solver termination criteria,
  • behaviour of the license manager,

and more. All parameters have default settings which will be suitable for most typical users.

The API reference contains:

Setting parameters

Each parameter is identified by a unique name. There are three types of parameters depending on the values they take:

  • Integer parameters. They take either either simple integer values or values from an enumeration provided for readability and compatibility of the code. Set with Task.putintparam.
  • Double (floating point) parameters. Set with Task.putdouparam.
  • String parameters. Set with Task.putstrparam.

There are also parameter setting functions which operate fully on symbolic strings containing command-line style names of parameters and their values. See the example below. The optimizer will try to convert the given argument to the exact expected type, and will error if that fails.

If an incorrect value is provided then the parameter is left unchanged.

For example, the following piece of code sets up parameters which choose and tune the interior point optimizer before solving a problem.

Listing 15 Parameter setting example. Click here to download.
        # Set log level (integer parameter)
        task.putintparam(mosek.iparam.log, 1)
        # Select interior-point optimizer... (integer parameter)
        task.putintparam(mosek.iparam.optimizer, mosek.optimizertype.intpnt)
        # ... without basis identification (integer parameter)
        task.putintparam(mosek.iparam.intpnt_basis, mosek.basindtype.never)
        # Set relative gap tolerance (double parameter)
        task.putdouparam(mosek.dparam.intpnt_co_tol_rel_gap, 1.0e-7)

        # The same using explicit string names 
        task.putparam     ("MSK_DPAR_INTPNT_CO_TOL_REL_GAP", "1.0e-7")
        task.putnadouparam("MSK_DPAR_INTPNT_CO_TOL_REL_GAP",  1.0e-7 )

        # Incorrect value
        try:
            task.putdouparam(mosek.dparam.intpnt_co_tol_rel_gap, -1.0)
        except:
            print('Wrong parameter value') 

Reading parameter values

The functions Task.getintparam, Task.getdouparam, Task.getstrparam can be used to inspect the current value of a parameter, for example:

        param = task.getdouparam(mosek.dparam.intpnt_co_tol_rel_gap)
        print('Current value for parameter intpnt_co_tol_rel_gap = {}'.format(param))