MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / generate_clause

Function generate_clause

other/davis_putnam_logemann_loveland.py:123–143  ·  view source on GitHub ↗

| Randomly generate a clause. | All literals have the name Ax, where x is an integer from ``1`` to ``5``.

()

Source from the content-addressed store, hash-verified

121
122
123def generate_clause() -> Clause:
124 """
125 | Randomly generate a clause.
126 | All literals have the name Ax, where x is an integer from ``1`` to ``5``.
127 """
128 literals = []
129 no_of_literals = random.randint(1, 5)
130 base_var = "A"
131 i = 0
132 while i < no_of_literals:
133 var_no = random.randint(1, 5)
134 var_name = base_var + str(var_no)
135 var_complement = random.randint(0, 1)
136 if var_complement == 1:
137 var_name += "'"
138 if var_name in literals:
139 i -= 1
140 else:
141 literals.append(var_name)
142 i += 1
143 return Clause(literals)
144
145
146def generate_formula() -> Formula:

Callers 1

generate_formulaFunction · 0.85

Calls 2

ClauseClass · 0.85
appendMethod · 0.45

Tested by

no test coverage detected