docplex.mp.conflict_refiner module

class docplex.mp.conflict_refiner.ConflictRefiner(output_processing=None)[source]

Bases: docplex.mp.publish.PublishResultAsDf, object

This class is an abstract algorithm; it operates on interfaces.

A conflict is a set of mutually contradictory constraints and bounds within a model. Given an infeasible model, the conflict refiner can identify conflicting constraints and bounds within it. CPLEX refines an infeasible model by examining elements that can be removed from the conflict to arrive at a minimal conflict.

static display_conflicts(conflicts)[source]

This method displays a formatted representation of the conflicts that are provided.

Parameters:conflicts – An instance of ConflictRefinerResult
refine_conflict(mdl, preferences=None, groups=None, display=False, **kwargs)[source]

Starts the conflict refiner on the model.

Parameters:
  • mdl – The model to be relaxed.
  • preferences – A dictionary defining constraint preferences.
  • groups – A list of ConstraintsGroups.
  • display – a boolean flag (default is True); if True, displays the result at the end.
  • kwargs – Accepts named arguments similar to solve.
Returns:

An object of type ConflictRefinerResut which holds all information about the minimal conflict.

classmethod var_bounds(mdl, pref=4.0, include_infinity_bounds=True)[source]

Returns a list of singleton groups with variable bounds.

This method a list of ConstraintGroup objects, each of which contains a variabel bound. It replicate sthe behavior of the CPLEX interactive optimizer, that is, it returns

  • lower bounds for non-binary variables if different from 0
  • upper bound for non-binary-variables if non-default
For binary variables, bounds are not considered, unless the variable is bound; more precisely:
  • lower bound is included if >= 0.5
  • upper bound is included if <= 0.5
Parameters:
  • mdl – The model being analyzed for conflicts,
  • pref – the preference for variable bounds, the defaut is 4.0
  • include_infinity_bounds – a flag indicating whether infi
Returns:

a list of ConstraintsGroup objects.

class docplex.mp.conflict_refiner.ConflictRefinerResult(conflicts, refined_by=None)[source]

Bases: object

This class contains all conflicts as returned by the conflict refiner.

A conflict refiner result contains a list of named tuples of type TConflictConstraint, the fields of which are:

  • an enumerated value of type docplex.mp.constants.ConflictStatus that indicates the
    conflict status type (Excluded, Possible_member, Member…).
  • the name of the constraint or None if the constraint corresponds to a variable lower or upper bound.
  • a modeling object involved in the conflict:
    can be either a constraint or a wrapper representing a variable upper or lower bound.

New in version 2.11

display()[source]

Displays all conflicts.

display_stats()[source]

Displays statistics on conflicts.

Display show many conflict elements per type.

iter_conflicts()[source]

Returns an iterator on conflicts (named tuples)

Returns:an iterator
number_of_conflicts

This property returns the number of conflicts.

print_information()[source]

Similar as display_stats

refined_by

Returns a string indicating how the conflicts were produced.

  • If the conflicts are created by a program, this field returns None.
  • If the conflicts originated from a local CPLEX run, this method returns ‘cplex_local’.
  • If the conflicts originated from a DOcplexcloud run, this method returns ‘cplex_cloud’.
Returns:A string, or None.
class docplex.mp.conflict_refiner.ConstraintsGroup(preference=1.0, cts=None)[source]

Bases: object

This class is a container for the definition of a group of constraints. A preference for conflict refinement is associated to the group.

Groups may be assigned preference. A group with a higher preference is more likely to be included in the conflict. A negative value specifies that the corresponding group should not be considered in the computation of a conflict. In other words, such groups are not considered part of the model. Groups with a preference of 0 (zero) are always considered to be part of the conflict.

Parameters:preference – A floating-point number that specifies the preference for the group. The higher the number, the higher the preference.
classmethod from_var(dvar, bound_type, pref)[source]

A class method to build a group fromone variable.

Parameters:
  • dvar – The variable whose bound is part of the conflict.
  • bound_type – An enumerated value of type VarBoundType
  • pref – a numerical preference.
Returns:

an instance of ConstraintsGroup.

docplex.mp.conflict_refiner.TConflictConstraint

alias of docplex.mp.conflict_refiner._TConflictConstraint

class docplex.mp.conflict_refiner.VarLbConstraintWrapper(dvar)[source]

Bases: docplex.mp.conflict_refiner.VarBoundWrapper

This class is a wrapper for a model variable and its associated lower bound.

Instances of this class are created by the refine_conflict method when the conflict involves a variable lower bound. Each of these instances is then referenced by a TConflictConstraint namedtuple in the conflict list returned by refine_conflict.

To check whether the lower bound of a variable causes a conflict, wrap the variable and include the resulting constraint in a ConstraintsGroup.

class docplex.mp.conflict_refiner.VarUbConstraintWrapper(dvar)[source]

Bases: docplex.mp.conflict_refiner.VarBoundWrapper

This class is a wrapper for a model variable and its associated upper bound.

Instances of this class are created by the refine_conflict method when the conflict involves a variable upper bound. Each of these instances is then referenced by a TConflictConstraint namedtuple in the conflict list returned by refine_conflict.

To check whether the upper bound of a variable causes a conflict, wrap the variable and include the resulting constraint in a ConstraintsGroup.