docplex.mp.conflict_refiner module¶
-
class
docplex.mp.conflict_refiner.
ConflictRefiner
[source]¶ Bases:
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 – A list of TConflictConstraint
namedtuples, one that was returned by the refine_conflict() method.
-
refine_conflict
(mdl, preferences=None, groups=None, **kwargs)[source]¶ Starts the conflict refiner on the model.
If CPLEX is available, the conflict refinement operation will be performed using the native CPLEX. If CPLEX is not available, the conflict refinement operation will be started on DOcplexcloud. The DOcplexcloud connection parameters are checked in the following order:
- If
kwargs
contains validurl
andkey
values, they are used. - If
kwargs
contains acontext
and that context contains a validsolver.docloud.url
andsolver.docloud.key
values, those values are used. Other attributes ofsolver.docloud
can also be used. Seedocplex.mp.context.Context
. - Finally, the model’s attribute
context
is used. Thiscontext
is set at model creation time.
If CPLEX is not available and the model has no valid credentials, an error is raised, because there is no way to perform the conflict refinement.
Note that if the
url
andkey
parameters are present and the values of the parameters are not in the ignored url or key list, the conflict refinement operation will be started on DOcplexcloud even if CPLEX is available.Example:
# forces the conflict refiner on DOcplexcloud with the specified url and keys crefiner.refine_conflict(url='https://foo.com', key='bar')
Example:
# set some DOcplexcloud credentials, but depend on another # method to decide if conflict refiner is local or not ctx.solver.docloud.url = 'https://foo.com' ctx.solver.docloud.key = 'bar' agent = 'local' if method_that_decides_if_solve_is_local() or 'docloud' crefiner.conflict_refiner(context=ctx, agent=agent)
Parameters: - mdl – The model to be relaxed.
- preferences – A dictionary defining constraint preferences.
- groups – A list of ConstraintsGroups.
- kwargs – Accepts named arguments similar to solve.
Returns: A list of
TConflictConstraint
namedtuples, each tuple corresponding to a constraint that is involved in the conflict. The fields of theTConflictConstraint
namedtuple are:- the name of the constraint or None if the constraint corresponds to a variable lower or upper bound.
- a reference to the constraint or to a wrapper representing a Var upper or lower bound.
- a
docplex.mp.constants.ConflictStatus
object that indicates the conflict status type (Excluded, Possible_member, Member...).
This list is empty if no conflict is found by the conflict refiner.
- If
-
static
-
class
docplex.mp.conflict_refiner.
ConstraintsGroup
(preference=1.0)[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.
-
docplex.mp.conflict_refiner.
TConflictConstraint
¶ alias of
_TConflictConstraint
-
class
docplex.mp.conflict_refiner.
VarLbConstraintWrapper
(var)[source]¶ Bases:
object
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 aTConflictConstraint
namedtuple in the conflict list returned byrefine_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
(var)[source]¶ Bases:
object
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 aTConflictConstraint
namedtuple in the conflict list returned byrefine_conflict
.To check whether the upper bound of a variable causes a conflict, wrap the variable and include the resulting constraint in a ConstraintsGroup.