docplex.mp.params.parameters module

class docplex.mp.params.parameters.BoolParameter(group, short_name, cpx_name, param_key, description, default_value)[source]

Bases: docplex.mp.params.parameters.Parameter

accept_value(value)[source]

Checks if new_value is an accepted value for the parameter.

Parameters:new_value – The candidate value.
Returns:True if acceptable, else False.
Return type:Boolean
class docplex.mp.params.parameters.IntParameter(group, short_name, cpx_name, param_key, description, default_value, min_value=None, max_value=None, sync=False)[source]

Bases: docplex.mp.params.parameters.Parameter

accept_value(new_value)[source]

Checks if new_value is an accepted value for the parameter.

Parameters:new_value – The candidate value.
Returns:True if acceptable, else False.
Return type:Boolean
class docplex.mp.params.parameters.NumParameter(group, short_name, cpx_name, param_key, description, default_value, min_value=None, max_value=None)[source]

Bases: docplex.mp.params.parameters.Parameter

A numeric parameter can take any floating-point value in the range of [min,max] values.

accept_value(new_value)[source]

Checks if new_value is an accepted value for the parameter.

Parameters:new_value – The candidate value.
Returns:True if acceptable, else False.
Return type:Boolean
class docplex.mp.params.parameters.Parameter(group, short_name, cpx_name, param_key, description, default_value)[source]

Bases: object

Base class for all parameters.

This class is not meant to be instantiated but subclassed.

accept_value(new_value)[source]

Checks if new_value is an accepted value for the parameter.

Parameters:new_value – The candidate value.
Returns:True if acceptable, else False.
Return type:Boolean
cpx_id

Returns the CPLEX integer code of the parameter. See the CPLEX Reference Manual for more information.

Returns:An integer code.
cpx_name

Returns the CPLEX name of the parameter. This string is the CPLEX reference name which is used in CPLEX Reference Manual.

Examples

parameters.mip.tolerances.mipgap has the name CPX_PARAM_EPGAP in CPLEX

Return type:string
default_value

Returns the default value of the parameter. This value can be numeric or a string, depending on the parameter type.

Examples

parameters.workdir has default value “.” parameters.optimalitytarget has default value 0 parameters.mip.tolerances.mipgap has default value of 0.0001

Returns:The default value.
description

Returns a string describing the parameter.

Return type:string
get()[source]

Returns the current value of the parameter.

is_default()[source]

Checks if the current value of the parameter equals its default.

Returns:True if the current value of the parameter equals its default.
Return type:Boolean
is_nondefault()[source]

Checks if the current value of the parameter does not equal its default.

Returns:True if the current value of the parameter differs from its default.
Return type:Boolean
qualified_name

Returns a hierarchical name string for the parameter.

The qualified name reflects the location of the parameter in the parameter hierarchy. The qualified name of a parameter is guaranteed to be unique.

Examples

parameters.mip.tolerances.mipgap -> mip.tolerances.mipgap

Returns:A unique name that reflects the parameter location in the hierarchy.
Return type:string
reset()[source]

Resets the parameter value to its default.

set(new_value)[source]

Changes the value of the parameter to new_value.

This method checks that the new value has the proper type and is valid. Numeric parameters often specify a valid range with a minimum and a maximum value.

If the value is valid, the current value of the parameter is changed, otherwise an exception is raised.

Parameters:new_value – The new value for the parameter.
Raises:An exception if the value is not valid.
to_string()[source]

Converts the parameter to a string.

This method is used in the __str__ method to convert a parameter to a string.

Return type:string
class docplex.mp.params.parameters.ParameterGroup(name, parent_group=None)[source]

Bases: object

A group of parameters.

Note

This class is not meant to be instantiated by users. Models come with a full hierarchy of parameters with groups as nodes.

clone()[source]
Returns:A deep copy of the parameter group.
generate_nondefault_params()[source]

A generator function that returns all non-default parameters.

This generator function traverses the group and its subgroup tree, yielding those parameters with a non-default value, one at a time. A parameter is non-default when its value differs from the default.

Returns:A generator object.
generate_params()[source]

A generator function that traverses all parameters.

The generator yields all parameters from the group and also from its subgroups, recursively. When called from the root parameter group, it returns all parameters.

Returns:A generator object.
is_root()[source]

Checks whether the group is the root group, in other words, has no parent group.

Returns:True if the group is the root group.
Return type:Boolean
iter_params()[source]

Iterates over the group’s own parameters.

Returns:A iterator over directparameters belonging to the group, not including sub-groups.
name

This property returns the name of the group.

Note

Parameter group names are always lowercase.

number_of_params

This property returns the number of parameters in the group, not including subgroups.

number_of_subgroups

This property returns the number of subgroups of the group, non-recursively.

parent_group

This property returns the parent group (an instance of ParameterGroup), or None for the root group.

qualified_name(sep='.', include_root=True)[source]

Computes a string with all the parents of the parameters.

Example

parameter mip.mip_cuts.Cover returns “mip.mip_cuts.Covers”.

Parameters:
  • sep (string) – The separator string. Default is “.”.
  • include_root (flag) – True if the root name is included.
Returns:

A string representation of the parameter hierarchy.

Return type:

string

reset(recursive=False)[source]

Resets all parameters in the group.

Parameters:recursive (Boolean) – If True, also resets the subgroups.
total_number_of_params()[source]

Includes all parameters of subgroups recursively.

Returns:The total number of parameters inside the group.
Return type:integer
class docplex.mp.params.parameters.PositiveIntParameter(group, short_name, cpx_name, param_key, description, default_value, max_value=None)[source]

Bases: docplex.mp.params.parameters.IntParameter

class docplex.mp.params.parameters.RootParameterGroup(name, cplex_version)[source]

Bases: docplex.mp.params.parameters.ParameterGroup

The root parameter group (there should be only one instance at the root of the tree).

export_prm(out, overload_params=None)[source]

Exports parameters to an output stream in PRM format.

This method writes non-default parameters in CPLEX PRM syntax. In addition to non-default parameters, some parameters can be forced to be printed with a specific value by passing a dictionary with Parameter objects as keys and values as arguments. These values are used in the print operation, but will not be kept, and the values of parameters will not be changed. Passing None as overload_params will disable this functionality, and only non-default parameters are printed.

Parameters:
  • out – The output stream, typically a filename.
  • overload_params – A dictionary of overloaded values for certain parameters. This dictionary is of the form {param: value} the printed PRM file will use overloaded values for those parameters present in the dictionary.
export_prm_to_string(overload_params=None)[source]

Exports non-default parameters in PRM format to a string.

The logic of overload is the same as in export_prm(). A parameter is written if either it is a key on overload_params, or it has a non-default value. This allows merging non-default parameters with temporary parameter values.

Parameters:overload_params – A dictionary of overloaded values, possibly None.

Note

This method has no side effects on the parameters.

Returns:A string in CPLEX PRM format.
Return type:string
is_root()[source]

Checks whether the group is the root group, in other words, has no parent group.

Returns:True if the group is the root group.
Return type:Boolean
print_info_to_stream(output, overload_params=None, print_defaults=False, indent_level=0)[source]

Writes parameters to an output stream.

This method writes non-default parameters in a human readable syntax. In addition to non-default parameters, some parameters can be forced to be printed with a specific value by passing a dictionary with Parameter objects as keys and values as arguments. These values are used in the print operation but not be kept, and the values of parameters will not be changed. Passing None as overload_params will disable this functionality, and only non-default parameters are printed.

Parameters:
  • output – The output stream.
  • overload_params – A dictionary of overloaded values for certain parameters. This dictionary is of the form {param: value}.
print_info_to_string(overload_params=None, print_defaults=False)[source]

Writes parameters in readable format to a string.

The logic of overload is the same as in export_prm(). A parameter is written if either it is a key on overload_params, or it has a non-default value. This allows merging non-default params with temporary parameter values.

Parameters:overload_params – A dictionary of overloaded values, possibly None.

Note

This method has no side effects on the parameters.

Returns:A string.
qualified_name(sep='.', include_root=True)[source]

Computes a string with all the parents of the parameters.

Example

parameter mip.mip_cuts.Cover returns “mip.mip_cuts.Covers”.

Parameters:
  • sep (string) – The separator string. Default is “.”.
  • include_root (flag) – True if the root name is included.
Returns:

A string representation of the parameter hierarchy.

Return type:

string

class docplex.mp.params.parameters.StrParameter(group, short_name, cpx_name, param_key, description, default_value)[source]

Bases: docplex.mp.params.parameters.Parameter

accept_value(new_value)[source]

Checks if new_value is an accepted value for the parameter.

Parameters:new_value – The candidate value.
Returns:True if acceptable, else False.
Return type:Boolean
to_string()[source]

Converts the parameter to a string.

This method is used in the __str__ method to convert a parameter to a string.

Return type:string