def pddl_from_instance(instance): action = instance.action args = [ instance.var_mapping[p.name] for p in action.parameters[:action.num_external_parameters] ] return Action(action.name, args)
def make_exact_skeleton(world, plan): # TODO: spend more effort on samples that were previously discovered # TODO: possibly reuse the kinematic solutions as seeds #arg_from_id = {} var_from_id = {} count_from_prefix = {} skeleton = [] for name, args in plan: new_args = [] for idx, arg in enumerate(args): #arg_from_id[id(arg)] = arg if test_reusable(world, name, idx, arg): new_args.append(arg) else: key = id(arg) if key not in var_from_id: if is_optimistic(arg): var_from_id[key] = '?{}'.format( arg[len(OPT_PREFIX):]) # WILD else: prefix = str(arg)[:2].lower() # 'w' num = next( count_from_prefix.setdefault(prefix, count())) var_from_id[key] = '?{}{}'.format(prefix, num) new_args.append(var_from_id[key]) skeleton.append(Action(name, new_args)) #print(skeleton[-1]) #for i, var in sorted(var_from_id.items(), key=lambda pair: pair[-1]): # print(arg_from_id[i], var) # TODO: could fall back on wild if this fails # TODO: this fails for placing (due to carry_conf / rest_conf disagreement) return skeleton
def transform_action_args(action, fn): if isinstance(action, Action): name, args = action return Action(name, tuple(map(fn, args))) elif isinstance(action, DurativeAction): name, args, start, duration = action return DurativeAction(name, tuple(map(fn, args)), start, duration) elif isinstance(action, StreamAction): name, inputs, outputs = action return StreamAction(name, tuple(map(fn, inputs)), tuple(map(fn, outputs))) elif isinstance(action, Assignment): args, = action return Assignment(tuple(map(fn, args))) raise NotImplementedError(action)
def make_wild_skeleton(world, plan): # Can always constrain grasps and selected poses # Could store previous values to suggest new ones # Recover skeleton # Save parameters that shouldn't change # And keep their evaluations # If all args the same skeleton = [] for name, args in plan: new_args = [ arg if test_reusable(world, name, index, arg) else WILD for index, arg in enumerate(args) ] skeleton.append(Action(name, new_args)) #print(len(skeleton), skeleton[-1]) return skeleton
def transform_action_args(action, fn): if isinstance(action, Action): name, args = action return Action(name, tuple(map(fn, args))) elif isinstance(action, DurativeAction): action = temporal_from_sequential(action) if action is None: return None name, args, start, duration = action return DurativeAction(name, tuple(map(fn, args)), start, duration) elif isinstance(action, StreamAction): name, inputs, outputs = action return StreamAction(name, tuple(map(fn, inputs)), tuple(map(fn, outputs))) elif isinstance(action, FunctionAction): name, inputs = action return FunctionAction(name, tuple(map(fn, inputs))) elif isinstance(action, Assignment): args, = action return Assignment(tuple(map(fn, args))) raise NotImplementedError(action)
def transform_action_args(action, fn): if isinstance(action, Action): name, args = action return Action(name, tuple(map(fn, args))) elif isinstance(action, DurativeAction): name, args, start, duration = action #name, index = name[:-2], int(name[-1]) #if index != 0: # TODO: what was this for? # return None return DurativeAction(name, tuple(map(fn, args)), start, duration) elif isinstance(action, StreamAction): name, inputs, outputs = action return StreamAction(name, tuple(map(fn, inputs)), tuple(map(fn, outputs))) elif isinstance(action, FunctionAction): name, inputs = action return FunctionAction(name, tuple(map(fn, inputs))) elif isinstance(action, Assignment): args, = action return Assignment(tuple(map(fn, args))) raise NotImplementedError(action)
def parse_action(line): entries = line.strip('( )').split(' ') name = entries[0] args = tuple(entries[1:]) return Action(name, args)
def transform_action_args(action, fn): if isinstance(action, DurativeAction): name, args, start, duration = action return DurativeAction(name, tuple(map(fn, args)), start, duration) name, args = action return Action(name, tuple(map(fn, args)))