dwavebinarycsp.ConstraintSatisfactionProblem.check#
- ConstraintSatisfactionProblem.check(solution)[source]#
Check that a solution satisfies all of the constraints.
- Parameters:
solution (container) – An assignment of values for the variables in the constraint satisfaction problem.
- Returns:
True if the solution satisfies all of the constraints; False otherwise.
- Return type:
Examples
This example creates a binary-valued constraint satisfaction problem, adds two logic gates implementing Boolean constraints, \(c = a \wedge b\) and \(d = a \oplus c\), and verifies that the combined problem is satisfied for a given assignment.
>>> import dwavebinarycsp.factories.constraint.gates as gates >>> csp = dwavebinarycsp.ConstraintSatisfactionProblem(dwavebinarycsp.BINARY) >>> csp.add_constraint(gates.and_gate(['a', 'b', 'c'])) # add an AND gate >>> csp.add_constraint(gates.xor_gate(['a', 'c', 'd'])) # add an XOR gate >>> csp.check({'a': 1, 'b': 0, 'c': 0, 'd': 1}) True