docplex.mp.relaxer module

class docplex.mp.relaxer.IConstraintPrioritizer[source]

Bases: object

Abstract interface for the prioritizer. This class is a functor to be called on each model constraint.

class docplex.mp.relaxer.Relaxer(prioritizer='all', **kwargs)[source]

Bases: object

This class is an abstract algorithm, in the sense that it operates on interfaces.

It takes a prioritizer, which an implementation of IConstraintPrioritizer. For convenience, predefined prioritizer types are accessible through names:

  • all relaxes all constraints using a MEDIUM priority; this is the default.
  • named relaxes all constraints with a user name but not the others.
  • match looks for priority names within constraint names; unnamed constraints are not relaxed.

Note

All predefined prioritizers apply various forms of logic, but, when a constraint has been assigned a priority by the user, this priority is always used. For example, the named prioritizer relaxes all named constraints with MEDIUM, but if an unnamed constraint was assigned a HIGH priority, then HIGH will be used.

get_relaxation(ct)[source]

Returns the infeasibility computed for this constraint.

Parameters:ct – A constraint.
Returns:The amount by which the constraint has been relaxed by the relaxer. The method returns 0 if the constraint has not been relaxed.
is_relaxed(ct)[source]

Returns true if the constraint ct has been relaxed

Parameters:ct – The constraint to check.
Returns:True if the constraint has been relaxed, else False.
iter_relaxations()[source]

Iterates on relaxations.

Relaxations are built as a dictionary with constraints as keys and numeric violations as values, so this iterator returns (ct, violation) pairs.

number_of_relaxations

This property returns the number of relaxations found.

relax(mdl, relax_mode=None, **kwargs)[source]

Runs the relaxation loop.

Parameters:
  • mdl – The model to be relaxed.
  • relax_mode – the relaxation mode. Accept either None (in which case the default mode is used, or an instance of RelaxationMode enumerated type, or a string that can be translated to a relaxation mode.
  • kwargs – Accepts named arguments similar to solve.
Returns:

If the relaxation succeeds, the method returns a solution object, an instance of SolveSolution; otherwise returns None.

relaxations()[source]

Returns a dictionary with all relaxed constraints.

Returns:A dictionary where the keys are the relaxed constraints, and the values are the numerical slacks.
relaxed_objective_value

Returns the objective value of the relaxed solution.

Raises:

DOCplexException

If the relaxation has not been successful.