def _time_shift_forward(self, active_pm, script, backward=False): """ Next situation synthesis :param active_pm: meaning of active situation :param script: meaning of active action :param backward: planning style :return: """ next_situation = Sign(st.SIT_PREFIX + str(st.SIT_COUNTER)) self.world_model[next_situation.name] = next_situation pm = next_situation.add_meaning() st.SIT_COUNTER += 1 copied = {} for event in active_pm.cause: for es in self._applicable_events(script, effect=backward): if event.resonate('meaning', es): break else: pm.add_event(event.copy(pm, 'meaning', 'meaning', copied)) for event in self._applicable_events(script, effect=not backward): pm.add_event(event.copy(pm, 'meaning', 'meaning', copied)) pm = pm.copy('meaning', 'image') global_situation = self.world_model['situation'] global_cm = global_situation.add_image() connector = global_cm.add_feature(pm) next_situation.add_out_image(connector) return pm
def save_plan(self, start, finish, actions, plan_name): # Creating plan action for further use if not plan_name: plan_name = 'plan_' + self.name if not start.sign.meanings: scm = start.copy('image', 'meaning') start.sign.add_meaning(scm) for con in start.sign.out_meanings.copy(): if con.in_sign.name == plan_name: start.sign.out_meanings.remove(con) if not finish.sign.meanings: fcm = finish.copy('image', 'meaning') finish.sign.add_meaning(fcm) for con in finish.sign.out_meanings.copy(): if con.in_sign.name == plan_name: finish.sign.out_meanings.remove(con) plan_sign = Sign(plan_name + self.name) plan_mean = plan_sign.add_meaning() connector = plan_mean.add_feature(start.sign.meanings[1]) start.sign.add_out_meaning(connector) conn = plan_mean.add_feature(finish.sign.meanings[1], effect=True) finish.sign.add_out_meaning(conn) self.signs[plan_sign.name] = plan_sign # Adding Sequence of actions to plan image plan_image = plan_sign.add_image() for act in actions: im = act.sign.add_image() connector = plan_image.add_feature(im) act.sign.add_out_image(connector) # Adding scenario vs partly concrete actions to the plan sign scenario = self.scenario_builder(start, finish, actions) plan_signif = plan_sign.add_significance() for act in scenario: connector = plan_signif.add_feature(act) act.sign.add_out_significance(connector) return [plan_sign, start.sign, finish.sign]
def ground(problem, plagent, exp_signs=None): # ground I and They domain = problem.domain I_sign = Sign("I") obj_means[I_sign] = I_sign.add_meaning() obj_signifs[I_sign] = I_sign.add_significance() signs[I_sign.name] = I_sign They_sign = Sign("They") obj_means[They_sign] = They_sign.add_meaning() obj_signifs[They_sign] = They_sign.add_significance() signs[They_sign.name] = They_sign for type, stype in domain['types']: stype_sign = __add_sign(stype) stype_signif = stype_sign.add_significance() type_sign = __add_sign(type) connector = stype_signif.add_feature(obj_signifs[type_sign], zero_out=True) type_sign.add_out_significance(connector) for obj, type in problem.objects: obj_sign = __add_sign(obj) obj_means[obj_sign] = obj_sign.add_meaning() type_sign = signs[type] tp_signif = type_sign.add_significance() connector = tp_signif.add_feature(obj_signifs[obj_sign], zero_out=True) obj_sign.add_out_significance(connector) if obj_sign.name == plagent: connector = obj_signifs[obj_sign].add_feature(obj_signifs[I_sign], zero_out=True) I_sign.add_out_significance(connector) obj_means[obj_sign] = obj_sign.add_meaning() others = set() for id in range(1, len(signs['agent'].significances) + 1): other_ag = signs['agent'].significances[id].get_signs() if signs[plagent] not in other_ag: others |= other_ag for subagent in others: if subagent.name != plagent: if not They_sign in subagent.significances[1].get_signs(): signif = obj_signifs[They_sign] if signif.is_empty(): They_signif = signif else: They_signif = They_sign.add_significance() connector = subagent.significances[1].add_feature( They_signif, zero_out=True) They_sign.add_out_significance(connector) obj_means[subagent] = subagent.add_meaning() for predicate in domain['predicates']: _ground_predicate(predicate.name, predicate.signature) for action in domain['actions']: _ground_action(action.name, action.parameters, action.preconditions, action.effect, problem.constraints, plagent) for task in domain['tasks']: __add_sign(task.name, False) methods = sorted(domain['methods'], key=lambda method: len(method.subtasks)) for method in methods: __ground_method(method.parameters, method.subtasks, method.ordering, method.task, domain, 2) # Ground Init start = __add_sign('*start %s*' % str(problem.name), False) sit_im = start.add_image() for predicate in problem.init: pred_im = _ground_htn_predicate(predicate.name, predicate.signature, plagent) connector = sit_im.add_feature(pred_im) pred_im.sign.add_out_image(connector) sit_im.copy('image', 'meaning') # Ground htns to meanings goal = None subtasks = [] for htn in problem.htns: htn_name = 'htn_' + str(problem.htns.index(htn)) htn_sign = __add_sign(htn_name, False) htn_mean = htn_sign.add_meaning() for task in htn.ordering: subtask = htn.subtasks[task] cm = __ground_htn_subtask(subtask[0], subtask[1], domain) connector = htn_mean.add_feature(cm) cm.sign.add_out_meaning(connector) subtasks.append(htn_sign) from mapmulti.grounding.pddl_grounding import signify_connection signify_connection(signs) return Task(problem.name, signs, start, goal, subtasks)
def save_plan(self, start, finish, actions, plan_name, subplans=None): # Creating plan action for further use if not plan_name: plan_name = 'plan_' + self.name if not start.sign.meanings: scm = start.copy('image', 'meaning') start.sign.add_meaning(scm) if not finish.sign.meanings: fcm = finish.copy('image', 'meaning') finish.sign.add_meaning(fcm) plan_sign = Sign(plan_name) plan_mean = plan_sign.add_meaning() connector = plan_mean.add_feature(start.sign.meanings[1]) start.sign.add_out_meaning(connector) conn = plan_mean.add_feature(finish.sign.meanings[1], effect=True) finish.sign.add_out_meaning(conn) self.signs[plan_sign.name] = plan_sign # Adding Sequence of actions to plan image plan_image = plan_sign.add_image() iter = -1 if not subplans: for act in actions: im = act[2].sign.add_image() connector = plan_image.add_feature(im) act[2].sign.add_out_image( connector ) # add connector to plan_sign threw images to out_image else: # ots = {subplans.index(it): range(it[1], it[2]+1) for it in subplans} # for act in actions: # iter += 1 # flag = False # for index, value in ots.items(): # if iter == value[0]: # if subplans[index][0].images: # im = subplans[index][0].images[1] # else: # im = subplans[index][0].add_image() # connector = plan_image.add_feature(im) # subplans[index][0].add_out_image(connector) # flag = True # break # elif iter in value: # flag = True # break # if flag: # continue # else: # im = act[2].sign.add_image() # connector = plan_image.add_feature(im) # act[2].sign.add_out_image(connector) for sub in subplans: if sub[2].sign.images: connector = plan_image.add_feature(sub[2].sign.images[1]) else: they_im = sub[2].sign.add_image() connector = plan_image.add_feature(they_im) sub[2].sign.add_out_image( connector ) # add connector to plan_sign threw images to out_image # Adding scenario vs partly concrete actions to the plan sign scenario = self.scenario_builder(start, finish, actions) plan_signif = plan_sign.add_significance() for act in scenario: connector = plan_signif.add_feature(act) act.sign.add_out_significance(connector) return [plan_sign, start.sign, finish.sign]
def create_subplan(subplan, agent, signs, plan_sit, plan_map, start=False): elem_acts_im = [] if agent == 'I': ag_sign = I_obj[0] whose = agent else: ag_sign = signs[agent] whose = 'They' act_st = subplan[0] if isinstance(act_st[-1], dict): descr1 = act_st[-1] else: descr1 = act_st[-1][0] # Remake situations coze they could be synthesized by other agent act_sit_start, act_map_start, size = create_situation( descr1, ag_sign, whose) if agent == 'I': I_sign = signs['I'] I_im = I_sign.add_image() act_sit_start.replace('image', ag_sign, I_im) plan_map.append(act_map_start.sign) act_fn = subplan[-1] if isinstance(act_fn[-1], dict): logging.debug('cant find goal sit for subplan') descr2 = act_fn[-1] else: descr2 = act_fn[-1][1] # Change goal sit size ag_x = descr1['objects'][ag_sign.name]['x'] ag_y = descr1['objects'][ag_sign.name]['y'] for el in subplan: if el[1] == 'Clarify': new_size = (size[2] - size[0]) // 6 size = [ ag_x - new_size, ag_y - new_size, ag_x + new_size, ag_y + new_size ] elif el[1] == 'Abstract': new_size = size[2] - size[0] size = [ size[0] - new_size, size[1] - new_size, size[2] + new_size, size[3] + new_size ] act_sit_finish, act_map_finish, _ = create_situation( descr2, ag_sign, whose, size) plan_map.append(act_map_finish.sign) if agent == 'I': I_sign = signs['I'] I_im = I_sign.add_image() act_sit_finish.replace('image', ag_sign, I_im) active_sit_start_mean = act_sit_start.copy('image', 'meaning') plan_sit.append(act_sit_start.sign) active_sit_finish_mean = act_sit_finish.copy('image', 'meaning') plan_sit.append(act_sit_finish.sign) global SUBPLAN_COUNTER SUBPLAN_COUNTER += 1 if agent != 'I': plan_sign = Sign(SUBPLAN_PREFIX + 'they_' + agent + '_' + str(SUBPLAN_COUNTER)) plan_mean = plan_sign.add_meaning() connector = plan_mean.add_feature(active_sit_start_mean) active_sit_start_mean.sign.add_out_meaning(connector) conn = plan_mean.add_feature(active_sit_finish_mean, effect=True) active_sit_finish_mean.sign.add_out_meaning(conn) signs[plan_sign.name] = plan_sign else: plan_sign = Sign(SUBPLAN_PREFIX + 'I_' + str(SUBPLAN_COUNTER)) plan_mean = plan_sign.add_meaning() connector = plan_mean.add_feature(active_sit_start_mean) active_sit_start_mean.sign.add_out_meaning(connector) conn = plan_mean.add_feature(active_sit_finish_mean, effect=True) active_sit_finish_mean.sign.add_out_meaning(conn) plan_image = plan_sign.add_image() for act in subplan: act_sign = self.signs[act[1]] im = act_sign.add_image() connector = plan_image.add_feature(im) act_sign.add_out_image(connector) elem_acts_im.append(im) signs[plan_sign.name] = plan_sign ## changing start and finish if start == True: self.start_situation = act_sit_start self.start_map = act_map_start self.goal_situation = act_sit_finish self.goal_map = act_map_finish return [ act_sit_start, plan_sign.name, plan_mean, act_st[3], (None, None), (act_map_start, None), (descr1, descr2) ], signs, plan_sit, plan_map, elem_acts_im
def ground(problem, plagent, exp_signs=None): domain = problem.domain actions = domain.actions.values() predicates = domain.predicates.values() constraints = problem.constraints # Objects objects = problem.objects objects.update(domain.constants) logging.debug('Objects:\n%s' % objects) # Remove old type_map if exp_signs: objects = _update_exp_signs(exp_signs, objects) # Create a map from types to objects type_map = _create_type_map(objects) logging.debug("Type to object map:\n%s" % type_map) # Create type subtype map subtype_map = _create_subtype(domain.types) obj_signifs = {} # add agents, because on significances they have a inner link to I and They signs obj_means = {} # Check logic in exp if exp_signs: signs = exp_signs I_sign = signs['I'] They_sign = signs['They'] obj_means[I_sign] = I_sign.meanings[1] obj_signifs[I_sign] = I_sign.significances[1] obj_means[They_sign] = They_sign.meanings[1] obj_signifs[They_sign] = They_sign.significances[1] signs['situation'] = exp_signs['situation'] else: signs = {} I_sign = Sign("I") obj_means[I_sign] = I_sign.add_meaning() obj_signifs[I_sign] = I_sign.add_significance() signs[I_sign.name] = I_sign They_sign = Sign("They") obj_means[They_sign] = They_sign.add_meaning() obj_signifs[They_sign] = They_sign.add_significance() signs[They_sign.name] = They_sign signs['situation'] = Sign('situation') for obj in objects: obj_sign = Sign(obj) obj_signifs[obj_sign] = obj_sign.add_significance() signs[obj] = obj_sign if obj_sign.name == plagent: connector = obj_signifs[obj_sign].add_feature(obj_signifs[I_sign], zero_out=True) I_sign.add_out_significance(connector) obj_means[obj_sign] = obj_sign.add_meaning() for tp, objects in type_map.items(): if exp_signs: tp_sign = signs[tp.name] else: tp_sign = Sign(tp.name) for obj in objects: obj_signif = obj_signifs[signs[obj]] tp_signif = tp_sign.add_significance() connector = tp_signif.add_feature(obj_signif, zero_out=True) signs[obj].add_out_significance(connector) if not exp_signs: signs[tp.name] = tp_sign others = set() for id in range(1, len(signs['agent'].significances) + 1): other_ag = signs['agent'].significances[id].get_signs() if signs[plagent] not in other_ag: others |= other_ag for subagent in others: if subagent.name != plagent: if not They_sign in subagent.significances[1].get_signs(): signif = obj_signifs[They_sign] if signif.is_empty(): They_signif = signif else: They_signif = They_sign.add_significance() connector = subagent.significances[1].add_feature( They_signif, zero_out=True) They_sign.add_out_significance(connector) obj_means[subagent] = subagent.add_meaning() if not exp_signs: updated_predicates = _update_predicates(predicates, actions) signify_predicates(predicates, updated_predicates, signs, subtype_map, domain.constants) signify_actions(actions, constraints, signs, plagent, obj_means, obj_signifs) signify_connection(signs) start_situation, pms = _define_situation('*start*', problem.initial_state, signs, 'image') goal_situation, pms = _define_situation('*finish*', problem.goal, signs, 'image') # if problem.name.startswith("blocks"): # list_signs = task_signs(problem) # _expand_situation_ma_blocks(goal_situation, signs, pms, list_signs) # For task return MaPlanningTask(problem.name, signs, start_situation, goal_situation)
def spatial_ground(problem, plagent, agents, exp_signs=None, backward = False): global signs initial_state = problem.initial_state initial_state.update(problem.map) goal_state = problem.goal_state goal_state.update(problem.map) # Prepare states to plagent init_state = {key: value for key, value in deepcopy(initial_state).items() if key != plagent} init_state['I'] = initial_state[plagent] init_state['objects']['I'] = init_state['objects'].pop(plagent) go_state = {key: value for key, value in deepcopy(goal_state).items() if key != plagent} go_state['I'] = goal_state[plagent] go_state['objects']['I'] = go_state['objects'].pop(plagent) agents.remove(plagent) agents.append('I') obj_signifs = {} obj_means = {} # Create agents and communications agent_type = None types = problem.domain['types'] roles = problem.domain['roles'] if exp_signs: signs, types = ut._clear_model(exp_signs, signs, types) signs, roles = ut._clear_model(exp_signs, signs, roles) I_sign = exp_signs['I'] signs['I'] = I_sign They_sign = exp_signs['They'] signs['They'] = They_sign Clarify = exp_signs['Clarify'] signs['Clarify'] = Clarify Abstract = exp_signs['Abstract'] signs['Abstract'] = Abstract signs['situation'] = exp_signs['situation'] else: I_sign = Sign("I") They_sign = Sign("They") obj_means[I_sign] = I_sign.add_meaning() obj_signifs[I_sign] = I_sign.add_significance() signs[I_sign.name] = I_sign obj_means[They_sign] = They_sign.add_meaning() obj_signifs[They_sign] = They_sign.add_significance() signs[They_sign.name] = They_sign Clarify = Sign('Clarify') signs[Clarify.name] = Clarify Abstract = Sign('Abstract') signs[Abstract.name] = Abstract signs['situation'] = Sign('situation') # ground types for type_name, smaller in types.items(): if not type_name in signs and not exp_signs: type_sign = Sign(type_name) signs[type_name] = type_sign else: if exp_signs: type_sign = exp_signs[type_name] else: type_sign = signs[type_name] if smaller: for obj in smaller: if not obj in signs: obj_sign = Sign(obj) signs[obj] = obj_sign else: obj_sign = signs[obj] obj_signif = obj_sign.add_significance() obj_signifs[obj_sign] = obj_signif tp_signif = type_sign.add_significance() connector = tp_signif.add_feature(obj_signif, zero_out=True) obj_sign.add_out_significance(connector) # Assign I to agent if obj_sign.name == plagent: connector = obj_signif.add_feature(obj_signifs[I_sign], zero_out=True) I_sign.add_out_significance(connector) agent_type = type_name else: obj_signifs[type_sign] = type_sign.add_significance() # Assign other agents others = {signs[ag] for ag in agents if ag != 'I'} for subagent in others: if not They_sign in subagent.significances[1].get_signs(): signif = obj_signifs[They_sign] if signif.is_empty(): They_signif = signif else: They_signif = They_sign.add_significance() connector = subagent.significances[1].add_feature(They_signif, zero_out=True) They_sign.add_out_significance(connector) obj_means[subagent] = subagent.add_meaning() # Signify roles for role_name, smaller in roles.items(): role_sign = Sign(role_name) signs[role_name] = role_sign for object in smaller: obj_sign = signs[object] obj_signif = obj_sign.significances[1] role_signif = role_sign.add_significance() connector = role_signif.add_feature(obj_signif, zero_out=True) obj_sign.add_out_significance(connector) if object == agent_type: agent_type = role_name # Find and signify walls if exp_signs: if not 'wall' in signs: signs['wall'] = exp_signs['wall'] ws = signs['wall'] views = [] if ws.images: for num, im in ws.images.items(): if len(im.cause): for view in im.cause[0].coincidences: if view.view: views.append(view.view) if 'wall' in problem.map: for wall in problem.map['wall']: if wall not in views: cimage = ws.add_image() cimage.add_feature(wall, effect=False, view = True) else: logging.warning('There are no walls around! Check your task!!!') sys.exit(1) # Ground predicates and actions if not exp_signs: ut._ground_predicates(problem.domain['predicates'], signs) ut._ground_actions(problem.domain['actions'], obj_means, problem.constraints, signs, agents, agent_type) else: #TODO check if new action or predicate variation appeared in new task for pred in problem.domain['predicates'].copy(): if pred in exp_signs: signs[pred] = exp_signs[pred] problem.domain['predicates'].pop(pred) for act in problem.domain['actions'].copy(): if act in exp_signs: signs[act] = exp_signs[act] problem.domain['actions'].pop(act) ut._ground_predicates(problem.domain['predicates'], signs) ut._ground_actions(problem.domain['actions'], obj_means, problem.constraints, signs, agents, agent_type) #Copy all experience subplans and plans for sname, sign in exp_signs.items(): if sname not in signs: signs[sname] = sign # Define start situation maps = {} if backward: maps[0] = problem.goal_state else: maps[0] = problem.initial_state ms = maps[0].pop('map-size') walls = maps[0].pop('wall') static_map = {'map-size': ms, 'wall': walls} # Create maps and situations for planning agents regions_struct = ut.get_struct() additions = [] additions.extend([maps, regions_struct, static_map]) cells = {} agent_state = {} for agent in agents: region_map, cell_map_start, cell_location, near_loc, cell_coords, size, cl_lv_init = ut.signs_markup(init_state, static_map, agent) agent_state_start = ut.state_prediction(signs[agent], init_state, signs) start_situation = ut.define_situation('*start-sit*-'+agent, cell_map_start, problem.initial_state['conditions'], agent_state_start, signs) start_map = ut.define_map('*start-map*-'+agent, region_map, cell_location, near_loc, regions_struct, signs) ut.state_fixation(start_situation, cell_coords, signs, 'cell') # Define goal situation region_map, cell_map_goal, cell_location, near_loc, cell_coords, size, cl_lv_goal = ut.signs_markup(go_state, static_map, agent) agent_state_finish = ut.state_prediction(signs[agent], go_state, signs) goal_situation = ut.define_situation('*goal-sit*-'+agent, cell_map_goal, problem.goal_state['conditions'], agent_state_finish, signs) goal_map = ut.define_map('*goal-map*-'+agent, region_map, cell_location, near_loc, regions_struct, signs) ut.state_fixation(goal_situation, cell_coords, signs, 'cell') #fixation map map_size = ut.scale(ms) rmap = [0, 0, map_size[0], map_size[1]] region_location, _ = ut.locater('region-', rmap, initial_state['objects'], walls) ut.state_fixation(start_map, region_location, signs, 'region') ut.signify_connection(signs) if agent == 'I': additions[0][0][plagent]['cl_lv_init'] = cl_lv_init additions[0][0][plagent]['cl_lv_goal'] = cl_lv_goal else: additions[0][0][agent]['cl_lv_init'] = cl_lv_init additions[0][0][agent]['cl_lv_goal'] = cl_lv_goal if backward: cell_map_goal['cell-4'] = {plagent} cells[agent] = {0:cell_map_goal} else: cell_map_start['cell-4'] = {plagent} cells[agent] = {0: cell_map_start} agent_state[agent] = {'start-sit':start_situation.sign, 'goal-sit': goal_situation.sign, 'start-map':start_map.sign, 'goal-map': goal_map.sign} additions.insert(2, cells) return SpTask(problem.name, signs, agent_state, additions, problem.initial_state, {key:value for key, value in problem.goal_state.items() if key not in static_map}, static_map, plagent)
def ground(problem, agent, exp_signs=None): domain = problem.domain actions = domain.actions.values() predicates = domain.predicates.values() # Objects objects = problem.objects objects.update(domain.constants) logging.debug('Objects:\n%s' % objects) # Remove old type_map if exp_signs: objects = _update_exp_signs(exp_signs, objects) # Create a map from types to objects type_map = _create_type_map(objects) logging.debug("Type to object map:\n%s" % type_map) # Create type subtype map subtype_map = _create_subtype(domain.types) obj_signifs = {} obj_means = {} # Check logic in exp if exp_signs: signs = exp_signs I_sign = signs['I'] obj_means[I_sign] = I_sign.meanings[1] obj_signifs[I_sign] = I_sign.significances[1] else: signs = {} I_sign = Sign("I") obj_means[I_sign] = I_sign.add_meaning() obj_signifs[I_sign] = I_sign.add_significance() signs[I_sign.name] = I_sign signs['situation'] = Sign('situation') for obj in objects: obj_sign = Sign(obj) obj_signifs[obj] = obj_sign.add_significance() signs[obj] = obj_sign if obj_sign.name == agent: connector = obj_signifs[obj].add_feature(obj_signifs[I_sign], zero_out=True) I_sign.add_out_significance(connector) for tp, objects in type_map.items(): if exp_signs: tp_sign = signs[tp.name] else: tp_sign = Sign(tp.name) for obj in objects: obj_signif = obj_signifs[obj] tp_signif = tp_sign.add_significance() connector = tp_signif.add_feature(obj_signif, zero_out=True) signs[obj].add_out_significance(connector) if not exp_signs: signs[tp.name] = tp_sign if not exp_signs: updated_predicates = _update_predicates(predicates, actions) signify_predicates(predicates, updated_predicates, signs, subtype_map, domain.constants) agent_roles = {} pred_names = {pred.name for pred in predicates} if agent: agent_role_cms = signs[agent].spread_up_activity_obj( 'significance', 3) roles = { cm.sign for cm in agent_role_cms if cm.sign.name not in pred_names } agent_roles[signs[agent]] = roles signify_actions(actions, signs, obj_means, agent_roles) start_situation, pms = _define_situation('*start*', problem.initial_state, signs, 'image') goal_situation, pms = _define_situation('*finish*', problem.goal, signs, 'image') return Task(problem.name, signs, start_situation, goal_situation)
def ground(problem, plagent, exp_signs=None): domain = problem.domain # ground I and They I_sign = Sign("I") obj_means[I_sign] = I_sign.add_meaning() obj_signifs[I_sign] = I_sign.add_significance() signs[I_sign.name] = I_sign They_sign = Sign("They") obj_means[They_sign] = They_sign.add_meaning() obj_signifs[They_sign] = They_sign.add_significance() signs[They_sign.name] = They_sign situation = Sign('situation') signs['situation'] = situation for type, stype in domain['types']: stype_sign = __add_sign(stype) stype_signif = stype_sign.add_significance() type_sign = __add_sign(type) connector = stype_signif.add_feature(obj_signifs[type_sign], zero_out=True) type_sign.add_out_significance(connector) for obj, type in problem.objects: obj_sign = __add_sign(obj) obj_means[obj_sign] = obj_sign.add_meaning() type_sign = signs[type] tp_signif = type_sign.add_significance() connector = tp_signif.add_feature(obj_signifs[obj_sign], zero_out=True) obj_sign.add_out_significance(connector) if obj_sign.name == plagent: connector = obj_signifs[obj_sign].add_feature(obj_signifs[I_sign], zero_out=True) I_sign.add_out_significance(connector) obj_means[obj_sign] = obj_sign.add_meaning() for predicate in domain['predicates']: _ground_predicate(predicate.name, predicate.signature) for action in domain['actions']: _ground_action(action.name, action.parameters, action.preconditions, action.effect, plagent=plagent) for task in domain['tasks']: __add_sign(task.name, False) methods = sorted(domain['methods'], key=lambda method: len(method.subtasks)) for method in methods: __ground_method(method.parameters, method.subtasks, method.ordering, method.task, domain, 2) #Ground Init start = __add_sign('*start %s*' % str(problem.name), False) sit_im = start.add_image() for predicate in problem.init: pred_im = _ground_htn_predicate(predicate.name, predicate.signature, plagent) connector = sit_im.add_feature(pred_im) pred_im.sign.add_out_image(connector) sit_im.copy('image', 'meaning') global_cm = situation.add_image() connector = global_cm.add_feature(sit_im) getattr(start, 'add_out_image')(connector) #Ground htns to meanings goal = None subtasks = [] for htn in problem.htns: htn_name = 'htn_' + str(problem.htns.index(htn)) htn_sign = __add_sign(htn_name, False) htn_mean = htn_sign.add_meaning() for task in htn.ordering: subtask = htn.subtasks[task] cm = __ground_htn_subtask(subtask[0], subtask[1], problem) connector = htn_mean.add_feature(cm) cm.sign.add_out_meaning(connector) subtasks.append(htn_sign) return Task(problem.name, signs, start, goal, subtasks)