# dwavebinarycsp.factories.csp.sat.random_2in4sat¶

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

Random two-in-four (2-in-4) constraint satisfaction problem.

Parameters: num_variables (integer) – Number of variables (at least four). 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. CSP that is satisfied when its variables are assigned values that satisfy a two-in-four satisfiability problem.

Examples

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

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