def test_dnf_b():

    # how many ways for 3 of these to be true?
    symbs = symbols("a,b,c,d,e,f")
    microstates = []
    for microstate in combinations(symbs, 2):
        microstates.append(cnf.AND(microstate))
    expr = cnf.OR(microstates)

    dnf_equivalence(expr, symbs)
def test_to_satfmt_singletons():

    symbs = symbols("A,B,C")
    a, b, c = symbs
    expr = cnf.AND([a, b | c])

    mapper = satbridge.SymbolMapper(symbs)
    ints = satbridge.expr_to_satfmt(expr, mapper)

    assert ints == [[1], [2, 3]]
Beispiel #3
0
def satfmt_to_expr(int_list, mapper, strings=None):
    """
    Takes a list of integers like pycosat needs, return a sympy expression
    """

    # build expr
    clauses = []
    for clause in int_list:
        clauses.append(cnf.OR(map(mapper.to_symb, clause)))
    expr = cnf.AND(clauses)

    return expr
def test_to_satfmt():

    symbs = symbols("A,B,C,D,E,F,G")
    expr = cnf.AND([
        cnf.OR(symbols("A,B,C")),
        cnf.OR(symbols("D,E,F")),
        ~Symbol("D") | ~Symbol("G"),
    ])

    mapper = satbridge.SymbolMapper(symbs)
    ints = satbridge.expr_to_satfmt(expr, mapper)

    assert ints == [[1, 2, 3], [4, 5, 6], [-4, -7]]
def test_tofrom_expr():

    symbs = symbols("A,B,C,D,E,F,G")
    expr = cnf.AND([
        cnf.OR(symbols("A,B,C")),
        cnf.OR(symbols("D,E,F")),
        ~Symbol("D") | ~Symbol("G"),
    ])

    mapper = satbridge.SymbolMapper(symbs)
    ints = satbridge.expr_to_satfmt(expr, mapper)
    sameexpr = satbridge.satfmt_to_expr(ints, mapper)

    assert expr == sameexpr
    def get_solns(func):

        # make expression
        before = time()
        cnf_clauses = func(expr)

        # find solutions
        solutions = []
        for sat_out in itersolve(cnf_clauses):
            true_only = list(filter(lambda x: x > 0, sat_out))
            if true_only:
                expr_out = cnf.AND(list(map(mapper.to_symb, true_only)))
                solutions.append(expr_out)

        after = time()
        return solutions, after - before