Convert boolean expressions to cnf (cpmpy.transformations.to_cnf)
Meta-transformation for obtaining a CNF from a list of constraints.
Converts the logical constraints into disjuctions using the tseitin transform,
including flattening global constraints that are is_bool() and not in supported.
Note
The transformation is no longer used by the SAT solvers, and may be outdated.
Check CPM_pysat.transform for an up-to-date alternative.
Other constraints are copied verbatim so this transformation can also be used in non-pure CNF settings.
The implementation first converts the list of constraints to Flat Normal Form, this already flattens subexpressions using auxiliary variables.
What is then left to do is to tseitin encode the following into CNF:
BVwith BV aBoolVar(orNegBoolView)or([BV])constraintand([BV])constraintBE != BVwithBE :: BV|or()|and()|BV!=BV|BV==BV|BV->BVBE == BVBE -> BVBV -> BE
- cpmpy.transformations.to_cnf.flat2cnf(constraints)[source]
Converts from Flat Normal Form all logical constraints into Conjunctive Normal Form, including flattening global constraints that are
is_bool()and not in supported.What is now left to do is to tseitin encode:
BVwith BV aBoolVar(orNegBoolView)or([BV])constraintand([BV])constraintBE != BVwithBE :: BV|or()|and()|BV!=BV|BV==BV|BV->BVBE == BVBE -> BVBV -> BE
We do it in a principled way for each of the cases. (in)equalities get transformed into implications, everything is modular.
- Parameters:
constraints – list[Expression] or Operator