dwavebinarycsp.Constraint.from_configurations#
- classmethod Constraint.from_configurations(configurations, variables, vartype, name=None)[source]#
Construct a constraint from valid configurations.
- Parameters:
configurations (iterable[tuple]) – Valid configurations of the variables. Each configuration is a tuple of variable assignments ordered by
variables
.variables (iterable) – Iterable of variable labels.
vartype (
Vartype
/str/set) –Variable type for the constraint. Accepted input values:
name (string, optional, default='Constraint') – Name for the constraint.
Examples
This example creates a constraint that variables a and b are not equal.
>>> const = dwavebinarycsp.Constraint.from_configurations([(0, 1), (1, 0)], ... ['a', 'b'], dwavebinarycsp.BINARY) >>> print(const.name) Constraint >>> (0, 0) in const.configurations # Order matches variables: a,b False
This example creates a constraint based on specified valid configurations that represents an OR gate for spin variables.
>>> const = dwavebinarycsp.Constraint.from_configurations( ... [(-1, -1, -1), (1, -1, 1), (1, 1, -1), (1, 1, 1)], ... ['y', 'x1', 'x2'], ... dwavebinarycsp.SPIN, name='or_spin') >>> print(const.name) or_spin >>> (1, 1, -1) in const.configurations # Order matches variables: y,x1,x2 True