Exemple #1
0
    def prepare_input(self, fname):
        input = CnfReader.from_file(fname)
        self.num_vars = input.num_vars
        self.num_clauses = input.num_clauses
        self.clauses = input.clauses
        self.var_clause_dict = defaultdict(set)

        return cnf2primal(input.num_vars, input.clauses, self.var_clause_dict)
Exemple #2
0
 def prepare_input(self, fname):
     input = CnfReader.from_file(fname)
     self.num_vars = input.num_vars
     self.num_clauses = input.num_clauses
     self.clauses = input.clauses
     self.projected = list(input.projected)
     self.var_clause_dict = defaultdict(set)
     #logger.debug("{} vars, {}={} clauses", input.num_vars, input.num_clauses, len(input.clauses))
     num_vars, edges, adj = cnf2primal(input.num_vars, input.clauses, self.var_clause_dict, True)
     return self.abstr.abstract(num_vars,edges,adj,self.projected)
Exemple #3
0
    def prepare_input(self, fname):
        input = CnfReader.from_file(fname)
        self.num_vars = input.num_vars
        self.num_clauses = input.num_clauses
        self.clauses = input.clauses
        self.projected = input.projected
        self.var_clause_dict = defaultdict(set)

        num_vars, edges = cnf2primal(input.num_vars, input.clauses, self.var_clause_dict)
        # Create clique over projected variables
        for a in self.projected:
            for b in self.projected:
                if a < b:
                    edges.add((a,b))
        return (num_vars, edges)
Exemple #4
0
 def preprocess(self):
     global cfg
     if "preprocessor" not in cfg["nesthdb"]:
         return # True, num_vars, vars, len(clauses), clauses, None
     cfg_prep = cfg["nesthdb"]["preprocessor"]
     preprocessor = [cfg_prep["path"]]
     if "args" in cfg_prep:
         preprocessor.extend(cfg_prep["args"].split(' '))
     self.active_process = ppmc = subprocess.Popen(preprocessor,stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
     clauses,proj_vars,num_vars,mapping,rev_mapping = normalize_cnf(self.formula.clauses, self.projected, True)
     StreamWriter(ppmc.stdin).write_cnf(self.formula.num_vars,clauses,normalize=False)
     ppmc.stdin.close()
     input = CnfReader.from_stream(ppmc.stdout,silent=True)
     ppmc.wait()
     ppmc.stdout.close()
     self.active_process = None
     if not input.error:
         self.maybe_sat = input.maybe_sat
         if not input.done:
             # fix corner case, where input.vars contains not all of range(1,input.max_vars+1)
             clauses, vars, proj_vars = denormalize_cnf(input.clauses,input.vars,proj_vars,rev_mapping)
             self.formula = Formula(vars,clauses)
             self.projected = proj_vars.intersection(vars)
             # remove single_clause_proj_vars, they are not needed/relevant and only waste resources!
             # consequently, these variables are treated as if they were never there, no 2 ** correction!
             _, singles, _ = denormalize_cnf((),input.single_vars,(),rev_mapping)
             self.projected_orig = self.projected_orig.difference(singles)
         else:
             # set models to 1 if instance was sat
             if len(self.projected) == 0:
                 self.models = 1
             # use result if instance was #sat
             elif self.projected.intersection(self.formula.vars) == self.formula.vars:
                 self.models = input.models
             # dont use result if instance was pmc
             else:
                 pass
     else:
         logger.debug("Pre-processor failed... ignoring result")
Exemple #5
0
def read_input(fname):
    input = CnfReader.from_file(fname)
    return input.num_vars, input.vars, input.num_clauses, input.clauses, input.projected
Exemple #6
0
 def from_file(cls, fname):
     input = CnfReader.from_file(fname)
     # uncomment the following line for sharpsat solving
     #input.projected = set(range(1,input.num_vars+1)) - input.single_vars		#sharpsat!
     return cls(input.vars, input.clauses, input.projected)
Exemple #7
0
 def sharpsat_from_file(cls, fname):
     input = CnfReader.from_file(fname)
     return cls(input.vars, input.clauses, set(range(1,input.num_vars+1)) - input.single_vars)
Exemple #8
0
 def from_file(cls, fname):
     input = CnfReader.from_file(fname)
     return cls(input.vars, input.clauses, input.projected)