Convert reification constraints (cpmpy.transformations.reification)
Transformations that rewrite reified constraints as needed.
There are three types of reification (BV=BoolVar, BE=BoolExpr):
|
single implication, from var to expression |
|
single implication, from expression to var |
|
full reification / double implication (e.g. |
Using logical operations, they can be decomposed and rewritten to each other.
This file implements:
transforms all reifications to |
|
transforms all reifications to |
|
rewrites reifications not supported by a solver to ones that are |
- cpmpy.transformations.reification.only_implies(constraints, csemap=None)[source]
Transforms all reifications to
BV -> BEformMore specifically:
BV0 -> BV2 == BV3 :: BV0 -> (BV2->BV3 & BV3->BV2) :: BV0 -> (BV2->BV3) & BV0 -> (BV3->BV2) :: BV0 -> (~BV2|BV3) & BV0 -> (~BV3|BV2) BV == BE :: ~BV -> ~BE, BV -> BEAssumes all constraints are in ‘flat normal form’ and all reifications have a variable in lhs. Hence, only apply AFTER
flatten_constraint()andonly_bv_reifies().
- cpmpy.transformations.reification.reify_rewrite(constraints, supported=frozenset({}), csemap=None)[source]
Rewrites reified constraints not natively supported by a solver, to a version that uses standard constraints and reification over equalities between variables.
Input is expected to be in Flat Normal Form without unsupported globals present. (so after
flatten_constraint()anddecompose_global()) Output will also be in Flat Normal FormBoolean expressions
and,or, and->and comparison expressionIV1==IV2are assumed to support reification (actually currently all comparisons <op> in {‘==’, ‘!=’, ‘<=’, ‘<’, ‘>=’, ‘>’},IV1 <op> IV2are assumed to support reificationBV -> (IV1 <op> IV2))- Parameters:
supported – a (frozen)set of expression names that support reification in the solver, including supported ‘Left Hand Side (LHS)’ expressions in reified comparisons, e.g.
BV -> (LHS == V)