def extract(self, domain, problem): # Parser parser = PDDL_Parser() parser.parse_domain(domain) parser.parse_problem(problem) state = list(parser.state) self.objects = dict(parser.objects) # Updating incorrect parsed types: self.update_types_objects(parser.types) self.gen_new_predicates(parser.actions) #self.predicates = parser.predicates #Adding No-op to the actions: parser.actions.append(ap('noop', [], [], [], [], [], [], [])) self.actions = parser.actions #for action in self.actions: # print(action) # Initial state gate, ASSUMING no negative initial conditions: self.gen_initial_state(state) #print(goal_pos, goal_not) self.gen_goal_state(parser.positive_goals, parser.negative_goals)
def extract(self, domain, problem): # Parser parser = PDDL_Parser() parser.parse_domain(domain) parser.parse_problem(problem) for constant_list in parser.constants: temp_constants = [] while(constant_list): cur_constant = constant_list.pop(0) if (cur_constant == '-'): constant_type = constant_list.pop(0) if constant_type not in parser.objects: parser.objects[constant_type] = temp_constants else: parser.objects[constant_type].extend(temp_constants) else: temp_constants.append(cur_constant) state = list(parser.state) self.objects = dict(parser.objects) # Updating incorrect parsed types: self.update_types_objects(parser.types) self.gen_new_predicates(parser.actions) #self.predicates = parser.predicates #Adding No-op to the actions: parser.actions.append(ap('noop', [], [], [], [], [], [], [])) self.actions = parser.actions #for action in self.actions: # print(action) # Initial state gate, ASSUMING no negative initial conditions: self.gen_initial_state(state) #print(goal_pos, goal_not) self.gen_goal_state(parser.positive_goals, parser.negative_goals)
def gen_predicate_split_action_list(self): for action in self.actions: # Noop handled separately: if (action.name == 'noop'): continue temp_parameter_dict, max_parameter_length = self.get_unique_parameters(action) parameter_type_dict = self.gen_action_parameter_type_dict(action) #print("paramete_type_dict",parameter_type_dict) #print("paramete_dict",temp_parameter_dict) for i in range(max_parameter_length+1): if i in temp_parameter_dict.keys(): for temp_parameter in temp_parameter_dict[i]: # Generating new positive preconditions after splitting: new_positive_preconditions = [] for pos_pre in action.positive_preconditions: pos_pre_param = list(pos_pre[1:]) if (temp_parameter == pos_pre_param): new_positive_preconditions.append(pos_pre[0]) # Generating new negative preconditions after splitting: new_negative_preconditions = [] for neg_pre in action.negative_preconditions: neg_pre_param = list(neg_pre[1:]) if (temp_parameter == neg_pre_param): new_negative_preconditions.append(neg_pre[0]) # Generating new add effects after splitting: new_add_effects = [] for add_eff in action.add_effects: add_eff_param = list(add_eff[1:]) if (temp_parameter == add_eff_param): new_add_effects.append(add_eff[0]) # Generating new del effects after splitting: new_del_effects = [] for del_eff in action.del_effects: del_eff_param = list(del_eff[1:]) if (temp_parameter == del_eff_param): new_del_effects.append(del_eff[0]) untouched_predicates = [] all_untouched_predicates = [] # Generating parameter type: cur_parameter_type = [] for cur_parameter in temp_parameter: cur_parameter_type.append(parameter_type_dict[cur_parameter]) # Generating untouched clauses after splitting: for predicate in self.predicate_dict[i]: predicate_values = list(self.predicates[predicate].values()) flag = 1 for j in range(i): if (cur_parameter_type[j] != predicate_values[j]): flag = 0 break if (flag): all_untouched_predicates.append(predicate) if predicate not in new_add_effects and predicate not in new_del_effects: untouched_predicates.append(predicate) self.predicate_split_action_list.append(ap(action.name, [i, temp_parameter], new_positive_preconditions, new_negative_preconditions, new_add_effects, new_del_effects, untouched_predicates, all_untouched_predicates)) else: untouched_predicates = [] all_untouched_predicates = [] # Generating untouched clauses after splitting: for predicate in self.predicate_dict[i]: predicate_values = list(self.predicates[predicate].values()) all_untouched_predicates.append(predicate) untouched_predicates.append(predicate) # If parameter is non-empty, here might be the problem: self.predicate_split_action_list.append(ap(action.name, [i, []], [], [], [], [], untouched_predicates, all_untouched_predicates)) # Handling noop operation: self.predicate_split_action_list.append(ap(self.actions[-1].name, [0, []], [], [], [], [], list(self.predicates), list(self.predicates)))