dwavesystems / dwavebinarycsp

Map constraint satisfaction problems with binary variables to binary quadratic models.
https://docs.ocean.dwavesys.com/projects/binarycsp/en/latest
Apache License 2.0
20 stars 27 forks source link

Provide True/False as variable inputs for constraints #53

Open arcondello opened 6 years ago

arcondello commented 6 years ago

Application Sometimes I want to create a constraint for which I already know the values for some of the variables. I can create the constraint and then immediately fix the variable after, but it might be nice to do it on creation (also can memory/time).

Proposed Solution I would like to be able to provide boolean values in the place of variables. This would be equivalent to fixing them.

csp = dwavebinarycsp.ConstraintSatisfactionProblem(dwavebinarycsp.BINARY)

def and_gate(in0, in1, out):
    return (in0 and in1) == out

csp.add_constraint(and_gate, ['a', 'b', False])

In this case the constraint would be the identical to

csp = dwavebinarycsp.ConstraintSatisfactionProblem(dwavebinarycsp.BINARY)

def nand(in0, in1):
    return not (in0 and in1)

csp.add_constraint(nand, ['a', 'b'])