def walk_forall(self, expression: FNode, args: List[FNode]) -> FNode: assert len(args) == 1 free_vars: Set[ 'unified_planning.model.Variable'] = self.env.free_vars_oracle.get_free_variables( args[0]) vars = tuple(var for var in expression.variables() if var in free_vars) if len(vars) == 0: return args[0] return self.manager.Forall(args[0], *vars)
def _help_walk_quantifiers(self, expression: FNode, args: List[FNode]) -> List[FNode]: vars = expression.variables() type_list = [v.type for v in vars] possible_objects: List[List[Object]] = [ list(self._problem.objects_hierarchy(t)) for t in type_list ] #product of n iterables returns a generator of tuples where # every tuple has n elements and the tuples make every possible # combination of 1 item for each iterable. For example: #product([1,2], [3,4], [5,6], [7]) = # (1,3,5,7) (1,3,6,7) (1,4,5,7) (1,4,6,7) (2,3,5,7) (2,3,6,7) (2,4,5,7) (2,4,6,7) subs_results = [] for o in product(*possible_objects): subs: Dict[Expression, Expression] = dict(zip(vars, list(o))) subs_results.append(self._substituter.substitute(args[0], subs)) return subs_results
def walk_operator(self, expression: model.FNode, args: List[proto.Expression]) -> proto.Expression: sub_list = [] sub_list.append( proto.Expression( atom=proto.Atom(symbol=map_operator(expression.node_type)), list=[], kind=proto.ExpressionKind.Value("FUNCTION_SYMBOL"), type="", )) # forall/exists: add the declared variables from the payload to the beginning of the parameter list. if expression.is_exists() or expression.is_forall(): sub_list.extend([ self._protobuf_writer.convert(p) for p in expression.variables() ]) sub_list.extend(args) return proto.Expression( atom=None, list=sub_list, kind=proto.ExpressionKind.Value("FUNCTION_APPLICATION"), type="", )
def walk_exists(self, expression: FNode, args: List[FNode]) -> FNode: assert self._problem is not None assert len(args) == 1 if args[0].is_bool_constant(): if args[0].bool_constant_value(): return self.manager.TRUE() return self.manager.FALSE() vars = expression.variables() type_list = [v.type for v in vars] possible_objects: List[List[Object]] = [ list(self._problem.objects_hierarchy(t)) for t in type_list ] #product of n iterables returns a generator of tuples where # every tuple has n elements and the tuples make every possible # combination of 1 item for each iterable. For example: #product([1,2], [3,4], [5,6], [7]) = # (1,3,5,7) (1,3,6,7) (1,4,5,7) (1,4,6,7) (2,3,5,7) (2,3,6,7) (2,4,5,7) (2,4,6,7) for o in product(*possible_objects): subs: Dict[Expression, Expression] = dict(zip(vars, list(o))) result = self._deep_subs_simplify(args[0], subs) assert result.is_bool_constant() if result.bool_constant_value(): return self.manager.TRUE() return self.manager.FALSE()