| Randomly generate a clause. | All literals have the name Ax, where x is an integer from ``1`` to ``5``.
()
| 121 | |
| 122 | |
| 123 | def 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 | |
| 146 | def generate_formula() -> Formula: |
no test coverage detected