Exemplo n.º 1
0
def retransform_output(names_to_numbers):
    """
    Transform the number-variables-names back into
    the text-variable-names required by our planer.
    """
    logging.debug("Retransforming output")
    numbers_to_names = dict()
    for name, number in names_to_numbers.items():
        numbers_to_names[number] = name

    retransformed = []
    with open(OUTPUT) as file:
        lines = file.readlines()
    if lines[0].startswith("SAT"):
        vars = lines[1].split()
        # Last element is always a zero
        for var in vars[:-1]:
            negation = ""
            if var.startswith("-"):
                negation = "not-"
                var = var[1:]
            var = numbers_to_names.get(int(var))
            # We don't need auxiliary variables
            if var:
                retransformed.append(negation + var)
    tools.remove(OUTPUT)
    return retransformed
Exemplo n.º 2
0
def teardown_module(module):
    """
    teardown any state that was previously setup with a setup_module method.
    """
    for filename in [
            DOMAIN_FILE, PROBLEM_FILE, CORRECT_SOLN_FILE, FALSE_SOLN_FILE
    ]:
        tools.remove(filename)
Exemplo n.º 3
0
def solve_with_minisat():
    """
    Calls minisat with the specified formula, the number of variables
    and the number of clauses.
    Returns the output filename of the minisat computation.
    """
    try:
        logging.debug("Solving with %s" % MINISAT)
        process = subprocess.Popen([MINISAT, INPUT, OUTPUT],
                                   stderr=subprocess.PIPE,
                                   stdout=subprocess.PIPE)
        process.wait()
    except OSError:
        logging.error("Minisat could not be found. "
                      'Please make the executable "%s" available on the path '
                      "(e.g. /usr/bin)." % MINISAT)
        sys.exit(1)
    tools.remove(INPUT)
Exemplo n.º 4
0
def teardown_module(module):
    for filename in (minisat.INPUT, minisat.OUTPUT):
        tools.remove(filename)