# docplex.mp.relaxer module¶

class docplex.mp.relaxer.FunctionalPrioritizer(fn, override=False)[source]
class docplex.mp.relaxer.MappingPrioritizer(priority_mapping, default_priority=Priority<MANDATORY>, override=False)[source]
class docplex.mp.relaxer.MatchNamePrioritizer(priority_for_unnamed=Priority<MANDATORY>, priority_for_non_matches=Priority<MANDATORY>, case_sensitive=False, override=False)[source]
get_priority(ct)[source]

Looks for known priority names inside constraint names.

class docplex.mp.relaxer.NamedPrioritizer(priority=Priority<MEDIUM>, override=False)[source]
class docplex.mp.relaxer.Prioritizer(override=False)[source]

Bases: object

Abstract base class for prioritizers. This class acts like a functor to be called on each model constraint.

class docplex.mp.relaxer.Relaxer(prioritizer='all', verbose=False, precision=1e-05, override=False, **kwargs)[source]

Bases: docplex.mp.publish.PublishResultAsDf, object

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

It takes a prioritizer, which an implementation of ConstraintPrioritizer. 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. 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. 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. 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.
class docplex.mp.relaxer.TOutputTables(Constraint, Priority, Amount)

Bases: tuple

Amount

Alias for field number 2

Constraint

Alias for field number 0

Priority

Alias for field number 1

class docplex.mp.relaxer.UniformPrioritizer(priority=Priority<MEDIUM>, override=False)[source]