dwavebinarycsp.factories.csp.sat.random_xorsat

random_xorsat(num_variables, num_clauses, vartype=<Vartype.BINARY: frozenset({0, 1})>, satisfiable=True)[source]

Random XOR constraint satisfaction problem.

Parameters:
  • num_variables (integer) – Number of variables (at least three).
  • num_clauses (integer) – Number of constraints that together constitute the constraint satisfaction problem.
  • vartype (Vartype, optional, default='BINARY') –

    Variable type. Accepted input values:

    • Vartype.SPIN, ‘SPIN’, {-1, 1}
    • Vartype.BINARY, ‘BINARY’, {0, 1}
  • satisfiable (bool, optional, default=True) – True if the CSP can be satisfied.
Returns:

CSP that is satisfied when its variables are assigned values that satisfy a XOR satisfiability problem.

Return type:

CSP (ConstraintSatisfactionProblem)

Examples

This example creates a CSP with 5 variables and two random constraints and checks whether a particular assignment of variables satisifies it.

>>> import dwavebinarycsp.factories as sat
>>> csp = sat.random_xorsat(5, 2)
>>> csp.constraints    # doctest: +SKIP
[Constraint.from_configurations(frozenset({(1, 0, 0), (1, 1, 1), (0, 1, 0), (0, 0, 1)}), (4, 3, 0),
 Vartype.BINARY, name='XOR (0 flipped)'),
 Constraint.from_configurations(frozenset({(1, 1, 0), (0, 1, 1), (0, 0, 0), (1, 0, 1)}), (2, 0, 4),
 Vartype.BINARY, name='XOR (2 flipped) (0 flipped)')]
>>> csp.check({0: 1, 1: 0, 2: 0, 3: 1, 4: 1})       # doctest: +SKIP
True