def get_solver_clauses(self): # expr = self.state_as_z3_expr if use_ivy_alpha: d = ProgressiveDomain(verbose=True) self.post = d sorts = sorted(set(n.sort for n in self.all_nodes)) concepts = [] for s in sorts: nconcepts = [n.to_concept_space() for n in self.all_nodes] nconcepts.append( (node_concept(s, 'X').atom, SumSpace( [NamedSpace(Literal(1, x)) for x, y in nconcepts]))) nconcepts.append( (xtra_concept(s, 'X', 'Y').atom, SumSpace([ x for n in self.all_nodes for x in n.extra_concepts() ]))) concepts += nconcepts concepts = concepts + self.relation_concepts([ r for r in self.relations if r.name() in self.enabled_relations ]) d.concept_spaces = concepts # # print "concepts: %s" % concepts d.post_init(self.state, [], {}, []) clauses = self.compile_concepts(concepts) # # print "clauses: %s" % clauses else: clauses = self.state # print "graph solver clauses = {}".format(clauses) s_add(self.solver, clauses_to_z3(clauses)) self.solver_clauses = and_clauses(self.solver_clauses, clauses)
def clauses_to_concept(name, clauses): vars = used_variables_clauses(clauses) ps = [ ProductSpace([NamedSpace(~lit) for lit in clause]) for clause in clauses ] ss = ps[0] if len(ps) == 1 else SumSpace(ps) return (Atom(name, vars), ss)
def relation_concepts(self, relations): rcons = [r.to_concept_space() for r in relations] rprods = [ ProductSpace([ NamedSpace(x) for x in [ node_concept(r.sorts[0], 'X'), Literal(1, cs[0]), node_concept(r.sorts[1], 'Y') ] ]) for (r, cs) in zip(relations, rcons) ] rsp = to_atom('__rsp(X,Y)'), SumSpace(rprods) return rcons + [rsp]
def p_expr_sum(p): 'expr : sum' p[0] = SumSpace(p[1])
def to_concept_space(self): rel_lit = self.rel_lit return Atom('__' + rel_lit.atom.rep, rel_lit.atom.args), SumSpace( [NamedSpace(rel_lit), NamedSpace(~rel_lit)])