Skip to content

Decompose before simplify_boolean for Xor #747

@ThomSerg

Description

@ThomSerg

The transformation of the following model fails for gurobi:

cp.Xor([cp.BoolVal(True), cp.BoolVal(True), p])
...
File "/cw/dtailocal/thomass/cpmpy_fuzzing/.fuzz/targets/cpmpy/cpmpy/transformations/linearize.py", line 599, in canonical_comparison
    assert not is_num(lhs), f"lhs cannot be an integer at this point! Got {lhs}."
           ^^^^^^^^^^^^^^^
AssertionError: lhs cannot be an integer at this point! Got 2.

The xor could have been simplified to ~cp.Xor[cp.BoolVal(True), p] or even further to p. Instead it first goes through decompose_in_tree resulting in ((boolval(True)) + (boolval(True)) == 1) + (p) == 1 (we use recursive sums as decomposition for xor). This will eventually lead to the expression (1 + 1 == 1), resulting in the above error.

This could benefit from a normalisation before decompose?

(somewhat linked to #703 since again Xor is a special global and thus currently does not have an implementation in simplify_boolean)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions