Exemplo n.º 1
0
 def test(state):
     # TODO: action parameters don't depend on the state
     # TODO: counter for how many times the action has been remapped
     if not hasattr(action_instance.action, 'attachments'):
         return True
     for literal, stream in action_instance.action.attachments.items():
         param_from_inp = remap_certified(literal, stream)
         input_objects = tuple(
             obj_from_pddl(action_instance.var_mapping[param_from_inp[inp]])
             for inp in stream.inputs)
         stream_instance = get_fluent_instance(
             stream, input_objects, state)  # Output automatically cached
         results = stream_instance.first_results(num=1)
         #results = stream_instance.all_results()
         failure = not results
         if literal.negated != failure:
             return False
         #args = action_instance.name.strip('()').split(' ')
         #idx_from_param = {p.name: i for i, p in enumerate(action_instance.action.parameters)}
         param_from_out = remap_certified(literal, stream)
         result = results[0]  # Arbitrary
         out_from_obj = invert_dict(result.get_mapping())
         for obj in result.output_objects:
             param = param_from_out[out_from_obj[obj]]
             action_instance.var_mapping[param] = obj.pddl
             # idx = idx_from_param[param]
             # args[1+idx] = obj.pddl
         #action_instance.name = '({})'.format(' '.join(args))
     return True
Exemplo n.º 2
0
 def test(state):
     if state in fd_action_from_state:
         return True
     #new_instance = action_instance
     new_instance = copy.deepcopy(action_instance)
     if not hasattr(action_instance.action, 'attachments'):
         fd_action_from_state[state] = new_instance
         return True
     for literal, stream in new_instance.action.attachments.items():
         param_from_inp = remap_certified(literal, stream)
         input_objects = tuple(
             obj_from_pddl(new_instance.var_mapping[param_from_inp[inp]])
             for inp in stream.inputs)
         stream_instance = get_fluent_instance(
             stream, input_objects, state)  # Output automatically cached
         results = stream_instance.first_results(num=1)
         #results = stream_instance.all_results()
         failure = not results
         if literal.negated != failure:
             return False
         #args = action_instance.name.strip('()').split(' ')
         #idx_from_param = {p.name: i for i, p in enumerate(action_instance.action.parameters)}
         param_from_out = remap_certified(literal, stream)
         result = results[0]  # Arbitrary
         out_from_obj = invert_dict(result.mapping)
         for obj in result.output_objects:
             param = param_from_out[out_from_obj[obj]]
             new_instance.var_mapping[param] = obj.pddl
             # idx = idx_from_param[param]
             # args[1+idx] = obj.pddl
         #action_instance.name = '({})'.format(' '.join(args))
     fd_action_from_state[state] = new_instance
     return True