Beispiel #1
0
 def __init__(self):
     super().__init__()
     self.solver = minisolvers.MinisatSolver()
     self.nameMap = dict()
     self.nVar = 0
     self.pushSolver = minisolvers.MinisatSolver()
     self.pushNVar = 0
     self.pushClauses = list()
Beispiel #2
0
    def _generate_iclause_pair(self, n_vars):
        solver = minisolvers.MinisatSolver()
        for i in range(n_vars):
            solver.new_var(dvar=True)

        iclauses = []

        while True:
            k_base = 1 if random.random() < self.p_k_2 else 2
            k = k_base + np.random.geometric(self.p_geo)
            iclause = self._generate_k_iclause(n_vars, k)

            solver.add_clause(iclause)
            is_sat = solver.solve()
            if is_sat:
                iclauses.append(iclause)
            else:
                break

        iclause_unsat = iclause
        iclause_sat = [-iclause_unsat[0]] + iclause_unsat[1:]

        unsat_clauses = iclauses.copy()
        unsat_clauses.append(iclause_unsat)

        iclauses.append(iclause_sat)

        return unsat_clauses, iclauses
Beispiel #3
0
def gen_iclause_pair(n, iclauses, p_k_2, p_geo):
    #    min_n = 10
    #    max_n = min_n
    #    n = random.randint(min_n, max_n)
    #    n = n_vars

    solver = minisolvers.MinisatSolver()
    for i in range(n):
        solver.new_var(dvar=True)

    for iclause in iclauses:
        solver.add_clause(iclause)

    is_sat = solver.solve()

    if is_sat:
        print("Converting SAT to unSAT")
        while True:
            k_base = 1 if random.random() < p_k_2 else 2
            k = k_base + np.random.geometric(p_geo)
            iclause = generate_k_iclause(n, k)
            solver.add_clause(iclause)
            is_sat = solver.solve()
            if is_sat:
                iclauses.append(iclause)
            else:
                print("Conversion Done")
                break
        iclause_unsat = iclause
        iclauses.append(iclause_unsat)
    return n, iclauses, p_k_2, p_geo
Beispiel #4
0
 def push(self):
     self.pushSolver = self.solver
     self.solver = minisolvers.MinisatSolver()
     for i in range(self.nVar):
         self.solver.new_var()
     for i in self.clauses:
         self.solver.add_clause(i)
     self.pushNVar = self.nVar
     self.pushClauses = self.clauses.copy()
Beispiel #5
0
def miniSatUse():
    S = minisolvers.MinisatSolver()
    for i in range(3):
        S.new_var()
    for clause in [1], [-1, 2], [-1, 2, 3], [1], [1]:
        S.add_clause(clause)
    while S.solve():
        print(list(S.get_model()))
        S.block_model()
Beispiel #6
0
def solve_sat(n_vars, iclauses):
    solver = minisolvers.MinisatSolver()
    for i in range(n_vars):
        solver.new_var(dvar=True)
    for iclause in iclauses:
        solver.add_clause(iclause)
    is_sat = solver.solve()
    stats = solver.get_stats()
    return is_sat, stats
Beispiel #7
0
 def run_new_sat(self, iclauses):
     S = minisolvers.MinisatSolver()
     for _ in range(self.sizes[0] + self.sizes[1]):
         S.new_var()
     for c in iclauses:
         S.add_clause(c)
     if S.solve():
         return True, list(S.get_model())
     else:
         return False, None
Beispiel #8
0
def gen_iclause_pair(args, n):
    solver = minisolvers.MinisatSolver()
    for i in range(n):
        solver.new_var(dvar=True)

    iclauses = []

    while True:
        k_base = 1 if random.random() < args.p_k_2 else 2
        k = k_base + np.random.geometric(args.p_geo)
        iclause = generate_k_iclause(n, k)

        solver.add_clause(iclause)
        is_sat = solver.solve()
        if is_sat:
            iclauses.append(iclause)
        else:
            break

    iclause_unsat = iclause
    iclause_sat = [-iclause_unsat[0]] + iclause_unsat[1:]
    return n, iclauses, iclause_unsat, iclause_sat
Beispiel #9
0
    def __init__(self, specs, sizes, filename):
        # specs: list of size 2. For example: [2, 3] means each clause has 2 forall vars first, then 3 exists vars.
        # sizes: list of size 2. For example: [8, 10] means the problem has 8 forall vars and 10 exists vars.
        # filename: the file name of the 2QBF problem
        self.specs = specs
        self.sizes = sizes
        _, self.iclauses = parse_dimacs(filename)
        self.temp_filename = self.get_temp_filename(filename)
        self.steps = 0

        # set up the SAT solver for counter examples
        self.omega = minisolvers.MinisatSolver()
        # self.omega = SharpSAT()
        # add all forall vars
        for _ in range(sizes[0]):
            self.omega.new_var()
        # add all clause vars (Cz) and the clauses to constraint that (Cz == false of clause c)
        self.Cz_list = []
        for c in self.iclauses:
            self.omega.new_var()
            Cz = self.omega.nvars()
            self.Cz_list.append(Cz)
            for Cc in c[:specs[0]]:
                self.omega.add_clause([-Cz, -Cc])