def gen_assignments(variables): if not variables: yield {} else: v, variables = variables[0], variables[1:] for env in gen_assignments(variables): yield assign(v, False, env) yield assign(v, True, env)
def solving(problem, env, variables): "Try to extend a consistent assignment for problem to a satisfying one." if not sat.seems_consistent(problem, env): return None if not variables: return env choice = choose_unit_literal(problem, env, variables) if choice is not None: v, value, variables = choice return solving(problem, assign(v, value, env), variables) v, variables = variables[0], variables[1:] for value in (False, True): result = solving(problem, assign(v, value, env), variables) if result is not None: return result return None
def solving(index, env, variables): "Try to extend a consistent assignment for problem to a satisfying one." if index is 'contradiction': return None if not variables: return env v, variables = variables[0], variables[1:] for value in (False, True): new_env = assign(v, value, env) result = solving(on_update(index, new_env, v if value else -v), new_env, variables) if result is not None: return result return None
def assume(index, env, variables, unit_literals, v, value): env = assign(v, value, env) return solving(index, env, variables, on_update(index, v if value else -v, env, unit_literals))
def assume(index, env, variables, unit_literals, v, value): env = assign(v, value, env) return solving( index, env, variables, on_update(index.get(v if value else -v, ()), env, unit_literals))