dwavebinarycsp.ConstraintSatisfactionProblem.add_variable

ConstraintSatisfactionProblem.add_variable(v)[source]

Add a variable.

Parameters:v (variable) – Variable in the constraint satisfaction problem. May be of any type that can be a dict key.

Examples

This example adds two variables, one of which is already used in a constraint of the constraint satisfaction problem.

>>> import operator
>>> csp = dwavebinarycsp.ConstraintSatisfactionProblem(dwavebinarycsp.SPIN)
>>> csp.add_constraint(operator.eq, ['a', 'b'])
>>> csp.add_variable('a')  # does nothing, already added as part of the constraint
>>> csp.add_variable('c')
>>> csp.check({'a': -1, 'b': -1, 'c': 1})
True
>>> csp.check({'a': -1, 'b': -1, 'c': -1})
True