def action_update(self, domain, pvars): lhs, rhs = self.args n = lhs.rep # Handle the hierarchical case if n in domain.hierarchy: asgns = [ postfix_atoms_ast(self, Atom(x, [])) for x in domain.hierarchy[n] ] res = unzip_append( [asgn.action_update(domain, pvars) for asgn in asgns]) return res # If the lhs application is partial, make it total by adding parameters xtra = len(lhs.rep.sort.dom) - len(lhs.args) if xtra < 0: raise IvyError(self, "too many parameters in assignment to " + lhs.rep) if xtra > 0: extend = sym_placeholders(lhs.rep)[-xtra:] extend = variables_distinct_list_ast(extend, self) # get unused variables lhs = add_parameters_ast(lhs, extend) # Assignment of individual to a boolean is a special case if is_individual_ast(rhs) and not is_individual_ast(lhs): rhs = eq_atom(extend[-1], add_parameters_ast(rhs, extend[0:-1])) else: rhs = add_parameters_ast(rhs, extend) type_check(domain, rhs) if is_individual_ast(lhs) != is_individual_ast(rhs): # print type(lhs.rep) # print str(lhs.rep) # print type(lhs.rep.sort) # print "lhs: %s: %s" % (lhs,type(lhs)) # print "rhs: %s: %s" % (rhs,type(rhs)) raise IvyError(self, "sort mismatch in assignment to {}".format(lhs.rep)) new_n = new(n) args = lhs.args dlhs = new_n(*sym_placeholders(n)) vs = dlhs.args eqs = [ eq_atom(v, a) for (v, a) in zip(vs, args) if not isinstance(a, Variable) ] rn = dict( (a.rep, v) for v, a in zip(vs, args) if isinstance(a, Variable)) drhs = substitute_ast(rhs, rn) if eqs: drhs = Ite(And(*eqs), drhs, n(*dlhs.args)) new_clauses = Clauses([], [Definition(dlhs, drhs)]) # print "assign new_clauses = {}".format(new_clauses) return SemActionValue([n], new_clauses, false_clauses())
def action_update(self, domain, pvars): type_check(domain, self.args[0]) check_can_assert(self.args[0], self) # print type(self.args[0]) if iu.new_assert_impl.get(): return assert_action(self.args[0]) else: cl = formula_to_clauses(dual_formula(self.args[0])) return SemActionValue([], true_clauses(), cl)
def int_update(self, domain, pvars): inst = self.args[0] if hasattr(domain, 'macros'): im = instantiate_macro(inst, domain.macros) # print "im: {}".format(im) if im: # print im res = im.compile().int_update(domain, pvars) ## print "res: {}".format(res) return res if inst.relname in domain.schemata: clauses = domain.schemata[inst.relname].get_instance(inst.args) return SemActionValue([], clauses, false_clauses()) raise IvyError(inst, "instantiation of undefined: {}".format(inst.relname))
def int_update(self, domain, in_scope): (updated, clauses, pre) = self.action_update(domain, in_scope).comps # instantiate the update axioms for u in domain.updates: updated, transrel, precond = u.get_update_axioms(updated, self).comps # TODO: do something with the precondition # if transrel: ## print "updated: {}".format(updated) ## print "update from axiom: %s" % transrel clauses = and_clauses(clauses, transrel) pre = or_clauses(pre, precond) ## print "update clauses: %s" % clauses res = SemActionValue(updated, clauses, pre) return res
def get_update_axioms(self, updated, action): # print "get_update_axioms: {}, {}".format(map(str,updated),action) for x in updated: if x in self.dependencies.symbols: updated = updated + [ y for y in self.defines.symbols if y not in updated ] try: precond, postcond = next( y for y in (p.match(action) for p in self.patterns.args) if y != None) except StopIteration: raise IvyError(action, 'No matching update axiom for ' + str(x)) postcond = state_to_action( SemStateValue(updated, postcond, precond)) # print "update axioms: {}, {}, {}".format(map(str,postcond[0]),postcond[1],postcond[2]) return SemActionValue(updated, postcond.trans, precond) return null_update()
def action_update(self, domain, pvars): lhs = type_ast(domain, self.args[0]) n = lhs.rep new_n = new(n) args = lhs.args vs = [Variable("X%d" % i, s) for i, s in enumerate(n.sort.dom)] eqs = [ eq_atom(v, a) for (v, a) in zip(vs, args) if not isinstance(a, Variable) ] if is_atom(lhs): clauses = And( *([Or(Not(Atom(new_n, vs)), Atom(n, vs), eq) for eq in eqs] + [Or(Atom(new_n, vs), Not(Atom(n, vs)), eq) for eq in eqs])) elif is_individual_ast(lhs.rep): clauses = And(*[ Or(eq_atom(type(lhs)(new_n, vs), type(lhs)(n, vs)), eq) for eq in eqs ]) else: # TODO: ??? clauses = And() clauses = formula_to_clauses(clauses) return SemActionValue([n], clauses, false_clauses())
def action_update(self, domain, pvars): lit = self.args[0] n = lit.atom.relname new_n = new(n) args = lit.atom.args vs = sym_placeholders(n) eqs = [ Atom(equals, [v, a]) for (v, a) in zip(vs, args) if not isinstance(a, Variable) ] new_clauses = And(*([ Or(sign(lit.polarity, Atom(new_n, vs)), sign(1 - lit.polarity, Atom(n, vs))), sign(lit.polarity, Atom(new_n, args)) ] + [ Or(*([sign(0, Atom(new_n, vs)), sign(1, Atom(n, vs))] + [eq])) for eq in eqs ] + [ Or(*([sign(1, Atom(new_n, vs)), sign(0, Atom(n, vs))] + [eq])) for eq in eqs ])) new_clauses = formula_to_clauses(new_clauses) return SemActionValue([n], new_clauses, false_clauses())
def int_update(self, domain, pvars): result = SemActionValue([], false_clauses(), false_clauses()) for a in self.args: result = join_action(result, a.int_update(domain, pvars), domain.relations) return result
def action_update(self, domain, pvars): type_check(domain, self.args[0]) check_can_assume(self.args[0], self) return SemActionValue([], formula_to_clauses_tseitin(self.args[0]), false_clauses())
def get_update_axioms(self, updated, action): defines = self.defn.args[0].rep if defines not in updated and any(x in self.dependencies for x in updated): updated.append(defines) return SemActionValue(updated, true_clauses(), false_clauses())