def value_from_obj_plan(obj_plan): if not is_plan(obj_plan): return obj_plan value_plan = [] for action in obj_plan: # TODO: I shouldn't need this decomposition any more, right? if isinstance(action, StreamAction): name, inputs, outputs = action new_inputs = params_from_objects(inputs) new_outputs = outputs #if isinstance(new_outputs, collections.Sequence): # TODO: what was this for? new_outputs = params_from_objects(new_outputs) new_action = StreamAction(name, new_inputs, new_outputs) elif isinstance(action, DurativeAction): name, args, start, duration = action name, index = name[:-2], int(name[-1]) if index != 0: continue new_action = DurativeAction(name, tuple(map(param_from_object, args)), start, duration) elif isinstance(action, Action): new_action = transform_action_args( action, param_from_object) # values_from_objects elif isinstance(action, Assignment): new_action = transform_action_args(action, param_from_object) else: raise ValueError(action) value_plan.append(new_action) return value_plan
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 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 get_action(self): return StreamAction(self.external.name, self.input_objects, self.output_objects)