def get_problem_from_segment(hr, segment, domain, objects, start_agent_symbols, end_agent_symbols): ''' Infer problem from dataset, human prediction can differ from the goal here, which the robot has to adapt to solve this problem ''' init_pred = hr.get_object_predicates(segment, 0, predicting=False) init_pred = [p for p in init_pred if p[1] in objects] final_pred = hr.get_object_predicates(segment, segment[2] - segment[1], predicting=False) final_pred = [p for p in final_pred if p[1] in objects] # resolve human-carry predicate for p in final_pred: if p[0] == 'human-carry': final_pred.remove(p) final_pred.append(('on', p[1], 'table')) # assume on table at the end for p in init_pred: if p[0] == 'human-carry': for pr in final_pred: if p[1] == pr[1]: init_pred.remove(p) init_pred.append(pr) break # init problem problem = Problem() problem.name = str(segment) problem.domain_name = domain.name problem.objects = {'object': objects, 'location': domain.constants['location']} problem.state = frozenset_of_tuples(init_pred).union(start_agent_symbols) problem.positive_goals = [frozenset_of_tuples(final_pred).union(end_agent_symbols)] problem.negative_goals = [frozenset()] return problem
def parse_problem(problem_filename): tokens = PDDLParser.scan_tokens(problem_filename) if tokens.pop(0) == 'define': problem = Problem() for group in tokens: t = group.pop(0) if t == 'problem': problem.name = group[0] elif t == ':domain': problem.domain_name = group[0] elif t == ':requirements': pass # Ignore requirements in problem, parse them in the domain elif t == ':objects': problem.objects = PDDLParser.parse_hierarchy(group, t) elif t == ':init': problem.state = frozenset_of_tuples(group) elif t == ':goal': positive_goals, negative_goals = PDDLParser.parse_goal(group[0]) problem.positive_goals = [frozenset_of_tuples(goal) for goal in positive_goals] problem.negative_goals = [frozenset_of_tuples(goal) for goal in negative_goals] else: problem.extensions = PDDLParser.parse_problem_extended(group, t) else: raise Exception('File ' + problem_filename + ' does not match problem pattern') return problem
def __init__(self, **kwargs): self.name = kwargs.get('name', 'unknown') self.parameters = kwargs.get('parameters', []) self.positive_preconditions = frozenset_of_tuples(kwargs.get('positive_preconditions', [])) self.negative_preconditions = frozenset_of_tuples(kwargs.get('negative_preconditions', [])) self.add_effects = frozenset_of_tuples(kwargs.get('add_effects', [])) self.del_effects = frozenset_of_tuples(kwargs.get('del_effects', [])) self.extensions = kwargs.get('extensions', {})
def symbolic_state(self): symbols = [] if not self.couplings: symbols.append(['free', self.name]) else: for obj in self.couplings: symbols.append(['carry', self.name, obj.name]) return self.init_symbol.union(frozenset_of_tuples(symbols))
def parse_action(group): name = group.pop(0) if type(name) is not str: raise Exception('Action without name definition') action = Action(name=name) while group: t = group.pop(0) if t == ':parameters': action.parameters = PDDLParser.parse_action_parameters(group.pop(0), name) elif t == ':precondition': positive_preconditions, negative_preconditions = PDDLParser.split_predicates(group.pop(0), name, ' preconditions') action.positive_preconditions, action.negative_preconditions = frozenset_of_tuples(positive_preconditions), frozenset_of_tuples(negative_preconditions) elif t == ':effect': add_effects, del_effects = PDDLParser.split_predicates(group.pop(0), name, ' effects') action.add_effects, action.del_effects = frozenset_of_tuples(add_effects), frozenset_of_tuples(del_effects) else: action.extensions[t] = PDDLParser.parse_action_extended(group.pop(0), t) return action
def __init__(self, **kwargs): super(DurativeAction, self).__init__(**kwargs) self.duration = kwargs.get('duration', None) # could be a function or a number self.start_positive_preconditions = frozenset_of_tuples(kwargs.get('start_positive_preconditions', [])) self.start_negative_preconditions = frozenset_of_tuples(kwargs.get('start_negative_preconditions', [])) self.end_positive_preconditions = frozenset_of_tuples(kwargs.get('end_positive_preconditions', [])) self.end_negative_preconditions = frozenset_of_tuples(kwargs.get('end_negative_preconditions', [])) self.start_add_effects = frozenset_of_tuples(kwargs.get('start_add_effects', [])) self.start_del_effects = frozenset_of_tuples(kwargs.get('start_del_effects', [])) self.end_add_effects = frozenset_of_tuples(kwargs.get('end_add_effects', [])) self.end_del_effects = frozenset_of_tuples(kwargs.get('end_del_effects', []))
def __init__(self, **kwargs): origin = np.asarray(kwargs.get('origin', np.zeros(2))) radius = np.asarray(kwargs.get('radius', 0.2)) self.name = kwargs.get('name', 'robot') self.init_symbol = frozenset_of_tuples(kwargs.get('init_symbol', [])) self.kinematic_map = LinearTranslation(origin) self.paths = [] self.couplings = { } # hold objects. TODO: replace by a kinematic tree later if robot is more complex. super(Robot, self).__init__(origin=origin, radius=radius)
def parse_durative_action(group): name = group.pop(0) if type(name) is not str: raise Exception('Action without name definition') action = DurativeAction(name=name) while group: t = group.pop(0) if t == ':parameters': action.parameters = PDDLParser.parse_action_parameters(group.pop(0), name) elif t == ':duration': action.duration = group.pop(0)[2] elif t == ':precondition': start_positive, start_negative, end_positive, end_negative = PDDLParser.split_durative_predicates(group.pop(0), name, ' preconditions') action.start_positive_preconditions, action.start_negative_preconditions = frozenset_of_tuples(start_positive), frozenset_of_tuples(start_negative) action.end_positive_preconditions, action.end_negative_preconditions = frozenset_of_tuples(end_positive), frozenset_of_tuples(end_negative) elif t == ':effect': start_positive, start_negative, end_positive, end_negative = PDDLParser.split_durative_predicates(group.pop(0), name, ' effects') action.start_add_effects, action.start_del_effects = frozenset_of_tuples(start_positive), frozenset_of_tuples(start_negative) action.end_add_effects, action.end_del_effects = frozenset_of_tuples(end_positive), frozenset_of_tuples(end_negative) else: action.extensions[t] = PDDLParser.parse_action_extended(group.pop(0), t) return action