def convert_goal_constraints(goal_constraints, var_map, axiom_map): goal_literals = [] for con in goal_constraints: for item in con.values: assert not isinstance(item, FreeParameter) and ( not isinstance(item, VarMember) or not any(isinstance(arg, FreeParameter) for arg in item.var)) if con.constraint == Eq: a, b = con.values if is_constant(a) and is_constant(b): if a != b: return None elif isinstance(a, VarMember) and isinstance(b, VarMember): raise NotImplementedError() elif isinstance(a, VarMember) and is_constant(b): goal_literals.append(make_equal_predicate(a, b, var_map)) elif is_constant(a) and isinstance(b, VarMember): goal_literals.append(make_equal_predicate(b, a, var_map)) else: raise ValueError() else: constants = set() for item in con.values: if isinstance(item, VarMember): constants.update(var_args(item.var)) else: constants.add(item) goal_literals.append( get_derived(con, var_map, axiom_map, constants)) return goal_literals
def convert_goal_constraints(goal_constraints, var_map, axiom_map): # NOTE - could use quantifiers here # NOTE - any parameters here would have to be the same across effects goal_literals = [] for con in goal_constraints: for item in con.values: # TODO - later relax this to handle quantification over goals assert not isinstance(item, FreeParameter) and ( not isinstance(item, VarMember) or not any(isinstance(arg, FreeParameter) for arg in item.var)) if con.constraint == Eq: a, b = con.values if is_constant(a) and is_constant(b): if a != b: return None elif isinstance(a, VarMember) and isinstance(b, VarMember): raise NotImplementedError() elif isinstance(a, VarMember) and is_constant(b): goal_literals.append(make_equal_predicate(a, b, var_map)) elif is_constant(a) and isinstance(b, VarMember): goal_literals.append(make_equal_predicate(b, a, var_map)) else: raise ValueError() else: # TODO - could allow constants if a Parameter is used once constants = set() for item in con.values: if isinstance(item, VarMember): constants.update(var_args(item.var)) else: constants.add(item) goal_literals.append( get_derived(con, var_map, axiom_map, constants)) return goal_literals
def get_static_preconditions(constraints, var_map, internal_params, assign_map, axiom_map): static_preconditions = [] for con in constraints: if con.constraint != Eq and con.constraint not in DUMMY_CONSTRAINTS: if all(not isinstance(item, VarMember) or item in internal_params for item in con.values): values = make_con_constants(con) static_preconditions.append( con.constraint.predicate( *[assign_map.get(item, item) for item in values])) else: constants = set() new_values = [] for item in con.values: if not isinstance(item, VarMember) or item in internal_params: new_values.append(assign_map.get(item, item)) constants.add(assign_map.get(item, item)) else: constants.update( assign_map.get(arg, arg) for arg in var_args(item.var)) new_values.append( X(*[assign_map.get(arg, arg) for arg in item.var])) derived = get_derived(con.constraint(*new_values), var_map, axiom_map, constants) if derived not in static_preconditions: static_preconditions.append(derived) return static_preconditions
def get_constraint_parameters(constraints, use_axioms): internal_params = set() for con in constraints: for item in con.values: if isinstance(item, VarMember): for arg in var_args(item.var): if isinstance(arg, FreeParameter): internal_params.add(arg) if item.temp != X or not use_axioms: # No axioms internal_params.add(item) elif isinstance(item, FreeParameter): internal_params.add(item) return internal_params
def get_single_state(constraints): state = {} for con in constraints: if not con.constraint is Eq: raise ValueError( 'Initial state must solely be composed of %s constraints: %s' % (Eq, con)) a, b = con.values assert isinstance(a, VarMember) and is_constant(b) assert not any( isinstance(arg, FreeParameter) for arg in var_args(a.var)) state[a.var] = b return state
def convert_initial_state(initial_state, var_map, expanded_state_vars): initial_atoms = [] initial_variables = set() for con in initial_state: assert con.constraint == Eq a, b = con.values assert isinstance(a, VarMember) and is_constant(b) assert not any( isinstance(arg, FreeParameter) for arg in var_args(a.var)) initial_atoms.append(make_equal_predicate(a, b, var_map)) initial_variables.add(a.var) if initial_variables != expanded_state_vars: raise ValueError(initial_variables - expanded_state_vars, expanded_state_vars - initial_variables) return initial_atoms
def get_static_preconditions(constraints, var_map, internal_params, assign_map, axiom_map): # TODO - for a single axiom, if the parameter size of that one is the same as it would be for the operator, then just keep # NOTE - I could also just keep the equality constraints I suppose... # TODO - hopefully breaking apart preconditions with several elements won't increase the number of operators # TODO - if the set of parameters is the same then just keep it here? static_preconditions = [] for con in constraints: if con.constraint != Eq and con.constraint not in DUMMY_CONSTRAINTS: if all(not isinstance(item, VarMember) or item in internal_params for item in con.values): # Derived only uses current parameters values = make_con_constants(con) static_preconditions.append( con.constraint.predicate( *[assign_map.get(item, item) for item in values])) else: # TODO - I'm not sure I wrapped all the constants quite right here using make_con_constants # TODO - what if some of these are constants. It might not make sense to split constants = set() new_values = [] for item in con.values: if not isinstance(item, VarMember) or item in internal_params: new_values.append(assign_map.get(item, item)) constants.add(assign_map.get(item, item)) else: constants.update( assign_map.get(arg, arg) for arg in var_args(item.var)) new_values.append( X(*[assign_map.get(arg, arg) for arg in item.var])) derived = get_derived(con.constraint(*new_values), var_map, axiom_map, constants) if derived not in static_preconditions: static_preconditions.append(derived) return static_preconditions