Expression transformations (cpmpy.transformations)
Transformations are used by solvers to convert (high-level) CPMpy expressions into the low-level constraints they support.
Typical users never need to use these functions directly.
CPMpy’s transformations selectively rewrite only those constraint expressions that a solver does not support. While solvers can use any transformation they need, lower-level solvers largely reuse those of higher-level ones, creating a waterfall pattern:
The rest of this documentation is for solver developers and other advanced users. Make sure you read Adding a new solver first.
A transformation can not modify expressions in-place but in that case should create and return new expression objects (copy-on-write). In this way, the expressions prior to the transformation remain intact, and could be used for other purposes too.
List of submodules
Input and output to transformations are always CPMpy expressions, so transformations can be chained and called multiple times, as needed. While there is no fixed ordering, the following ordering corresponds to the waterfall:
Getting and printing variables in the model or expression. |
|
Normalize a toplevel list, or simplify Boolean expressions. |
|
Transforms partial functions into total functions. |
|
Decompose global constraints not supported by the solver. |
|
Transformations dealing with negations (used by other transformations). |
|
Flattening a model (or individual constraints) into 'flat normal form'. |
|
Transformations that rewrite reified constraints as needed. |
|
Transforms non-equality comparisons into equality comparisons as needed. |
|
Transforms flat constraints into linear constraints. |
|
Transform constraints to Conjunctive Normal Form (i.e. an and of or`s of literals, i.e. Boolean variables or their negation, e.g. from `x xor y to (x or ~y) and (~x or y)) using a back-end encoding library and its transformation pipeline. |