dwavebinarycsp.factories.constraint.gates.halfadder_gate#
- halfadder_gate(variables, vartype=Vartype.BINARY, name='HALF_ADDER')[source]#
Half adder.
- Parameters:
variables (list) – Variable labels for the and gate as [in1, in2, sum, carry], where in1, in2 are inputs to be added and sum and ‘carry’ the resultant outputs.
vartype (Vartype, optional, default='BINARY') –
Variable type. Accepted input values:
Vartype.SPIN, ‘SPIN’, {-1, 1}
Vartype.BINARY, ‘BINARY’, {0, 1}
name (str, optional, default='HALF_ADDER') – Name for the constraint.
- Returns:
Constraint that is satisfied when its variables are assigned values that match the valid states of a Boolean half adder.
- Return type:
Constraint(
Constraint
)
Examples
>>> import dwavebinarycsp.factories.constraint.gates as gates >>> csp = dwavebinarycsp.ConstraintSatisfactionProblem(dwavebinarycsp.BINARY) >>> csp.add_constraint(gates.halfadder_gate(['a', 'b', 'total', 'carry'], name='HA1')) >>> csp.check({'a': 1, 'b': 1, 'total': 0, 'carry': 1}) True