Пример #1
0
def solve(problem):
    "Return a satisfying assignment for problem, or None if impossible."
    variables = sat.problem_variables(problem)
    for env in gen_assignments(variables):
        if sat.seems_consistent(problem, env):
            return env
    return None
Пример #2
0
def solve(problem):
    "Return a satisfying assignment for problem, or None if impossible."
    variables = sat.problem_variables(problem)
    for env in gen_assignments(variables):
        if sat.seems_consistent(problem, env):
            return env
    return None
Пример #3
0
def solve(problem):
    "Return a satisfying assignment for problem, or None if impossible."
    env = {}
    index = build_index(problem)
    return solving(index, env,
                   sat.problem_variables(problem),
                   on_update(problem, env, []))
Пример #4
0
    def show(self, coloring=False):
        "Display the board."

        def write(color, s):
            if coloring: set_color(color)
            sys.stdout.write(s)

        def present(v, clause):
            color = (satisfied if self.clause_is_satisfied(clause) else unsatisfied)
            pos, neg = v in clause, -v in clause
            if not pos and not neg:
                write(color, '.')
            elif self.env[v] is None:
                write(color, 'O*'[pos])
            else:
                write(color, 'O*'[self.env[v] == pos])

        for v in sat.problem_variables(self.problem):
            write(other, self.name_of_variable(v) + ' ')
            for clause in self.problem:
                present(v, clause)
            write(other, ' ' + self.name_of_variable(v))
            write(other, '\r\n')
        write(other, '')
Пример #5
0
def solve(problem):
    "Return a satisfying assignment for problem, or None if impossible."
    return solving(problem, {}, sat.problem_variables(problem))
Пример #6
0
def solve(problem):
    "Return a satisfying assignment for problem, or None if impossible."
    index, unit_literals = build_index(problem)
    if index == 'contradiction': return None
    return solving(index, {}, sat.problem_variables(problem), unit_literals)
Пример #7
0
def solve(problem):
    "Return a satisfying assignment for problem, or None if impossible."
    env = {}
    index = build_index(problem)
    return solving(index, env, sat.problem_variables(problem),
                   on_update(problem, env, []))
Пример #8
0
def solve(problem):
    "Return a satisfying assignment for problem, or None if impossible."
    return solving(problem, {}, sat.problem_variables(problem))
Пример #9
0
def solve(problem):
    "Return a satisfying assignment for problem, or None if impossible."
    global index, model
    index, model = {}, {}
    if not make_index(problem): return None
    return model if solving(sat.problem_variables(problem)) else None
Пример #10
0
 def __init__(self, problem):
     self.problem = problem
     variables = sat.problem_variables(problem)
     self.env = dict((v, False) for v in variables)
     self.labels = ('1234567890' + string.ascii_uppercase)[:len(variables)]
Пример #11
0
def solve(problem):
    "Return a satisfying assignment for problem, or None if impossible."
    global index, model
    index, model = {}, {}
    if not make_index(problem): return None
    return model if solving(sat.problem_variables(problem)) else None