dwavebinarycsp icon indicating copy to clipboard operation
dwavebinarycsp copied to clipboard

Provide True/False as variable inputs for constraints

Open arcondello opened this issue 7 years ago • 0 comments

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'])

arcondello avatar Aug 14 '18 23:08 arcondello