Esempio n. 1
0
def test_generate_planning_files():
    import sys

    #parse domain and problem files
    #sys.argv[1] = domain file sys.argv[2] = problem file
    pddl_parser = parser.Parser(sys.argv[1],sys.argv[2])

    planning_domain = pddl_parser.parse_domain()
    requirements_string = ''
    functions_string = ''
    constants_string = ''

    domain_file_name = os.path.join(grd_defs.gen_files_dir,"new_domain.pddl")
    generate_domain_file(planning_domain,domain_file_name,requirements_string,functions_string,constants_string)
Esempio n. 2
0
def parse_problem_file(problem_file_name,domain_file_name):
    '''
    Create a problem object
    :param problem_file_name:
    :param domain_file_name:
    :return:
    '''

    #generate_domain
    pddl_domain = parse_domain_file(domain_file_name)

    #Create the grounded problem
    pddl_parser = parser.Parser(domain_file_name,problem_file_name)
    print("domain file name:", domain_file_name, " problem file name", problem_file_name)
    planning_problem = pddl_parser.parse_problem(pddl_domain)

    return planning_problem
Esempio n. 3
0
def add_not_allowed_predicates(domain_file_name,action_names,add_action_constraints,cur_grd_task):


        pddl_parser = parser.Parser( domain_file_name )
        planning_domain = pddl_parser.parse_domain()


        for action_name in action_names :
            #add the relevant predicate to the predicate list
            dis_predicate_name = 'not_allowed_%s'%action_name
            action = planning_domain.actions[action_name]
            predicate = pddl.Predicate(dis_predicate_name,action.signature)
            planning_domain.predicates[dis_predicate_name]=predicate

            #add the precondition to the relevant action
            predicate.IsNot = True
            action.precondition.append(predicate)


        if add_action_constraints is True:

            actionsToConstrain_names = action_names#grd_utils.get_constraints_actions(cur_grd_task)
            actionsToConstrain = []
            if actionsToConstrain_names is None:
                actionsToConstrain_names = []
                for action_name in planning_domain.actions.keys():
                    actionsToConstrain.append(planning_domain.actions[action_name])
                    actionsToConstrain_names.append(action_name)
            else:
                for action_name in action_names:#actionsToConstrain_names:
                    actionsToConstrain.append(planning_domain.actions[action_name])

            for constraint_action_def in actionsToConstrain:

                # add predicate to domain
                param_count = len(constraint_action_def.signature)
                #(constrained_obj)
                predicate_name_constraint = 'constraint_%d'%param_count
                signature_full = copy.deepcopy(constraint_action_def.signature)
                for param in constraint_action_def.signature:
                    param_name = '%s-d'%param[0]
                    signature_full.append(('%s'%param_name,('object')))
                predicate_constraint = pddl.Predicate(predicate_name_constraint,signature_full)
                planning_domain.predicates[predicate_name_constraint]=predicate_constraint

                # if act is in the list add the constraints
                realActionsToConstrain_names = grd_utils.get_constraints_actions(cur_grd_task)
                if constraint_action_def.name in realActionsToConstrain_names:
                    # token assignment
                    constraint_action_def.precondition.append(predicate_constraint)

                    # token performed
                    #for act in actionsToConstrain_names:
                    actionsToConstrain_names = grd_utils.get_constraints_actions(cur_grd_task)
                    for act in actionsToConstrain_names:
                        preidcate_name_cur = 'not_allowed_%s'%act
                        signature_dis = []
                        for param in constraint_action_def.signature:
                            param_name = '%s-d'%param[0]
                            signature_dis.append(('%s'%param_name,('%s'%param[1])))
                        predicate_add_dissallow = pddl.Predicate(preidcate_name_cur,signature_dis)
                        constraint_action_def.effect.addlist.add(predicate_add_dissallow)

                    # add constraints params to signature
                    constraint_action_def.signature = copy.deepcopy(signature_full)


        return planning_domain
Esempio n. 4
0
    def initialize_with_files(self,
                              destination_folder_name,
                              domain_file,
                              template_file,
                              hyps_file_name,
                              observability_file_name=None,
                              action_token_file_name=None,
                              poi_hyps_file=None,
                              task_name=None,
                              reciprocal_observability_file_name=None,
                              domain_name=grd_defs.NA):
        '''
        Same as above with files specified instead of tarred folder - initialization includes processing the files and collecting grd relevant information
        :param destination_folder_name:
        :param domain_file:
        :param template_file:
        :param hyps_file_name:
        :param task_name:
        :param observability_file_name: if relevant
        :param action_token_file_name: if relevant
        :return: NA
        '''

        #only if the name has not ben initialized previously
        if task_name == None:
            self.task_name = destination_folder_name.split('/')[-1]
        else:
            self.task_name = task_name

        #assign the relevant file names
        self.destination_folder_name = destination_folder_name
        self.domain_file_name = domain_file
        self.full_domain_file_name = os.path.abspath(
            os.path.join(destination_folder_name, self.domain_file_name))
        self.template_file_name = template_file
        self.full_template_file_name = os.path.abspath(
            os.path.join(destination_folder_name, self.template_file_name))
        self.hyps_file_name = hyps_file_name
        self.full_hyps_file_name = os.path.abspath(
            os.path.join(destination_folder_name, self.hyps_file_name))

        # the benchmark domain (easy-gird etc)
        self.domain_name = grd_utils.get_domain_name(self)

        #load hyps(possible goals) set from hyps.dat file
        self.load_hypotheses(self.full_hyps_file_name)

        #parse the domain file
        pddl_parser = parser.Parser(self.full_domain_file_name)
        self.parsed_pddl_domain = pddl_parser.parse_domain()

        #add a flag indicating if actions costs are specified in the original domain
        if self.parsed_pddl_domain.actionCosts == True:
            self.actionCosts = True
        else:
            self.actionCosts = False

        #if the observability_file_name is included - parse it
        if observability_file_name != None:

            self.are_observables_specified = True
            print('observability_file_name %s' % observability_file_name)
            if grd_defs.NON_OBSERVABILITY_STRING in observability_file_name:
                self.are_observables_specified = False
                print('non observables are specified')

            self.observability_file_name = observability_file_name
            self.full_path_observability_file_name = os.path.abspath(
                os.path.join(destination_folder_name, observability_file_name))

            if self.are_observables_specified:
                self.non_observability_actions_list = self.load_actions(
                    self.full_path_observability_file_name)
            else:
                self.observability_actions_list = self.load_actions(
                    self.full_path_observability_file_name)
                action_list_string = ''
                for op in self.observability_actions_list:
                    action_list_string += ' (%s) ' % op
                self.observability_actions_list_string = action_list_string

        #if the reciprocal_observability_file_name is included - parse it
        if reciprocal_observability_file_name != None and reciprocal_observability_file_name != grd_defs.NA:

            print('reciprocal observability_file_name %s' %
                  reciprocal_observability_file_name)

            self.reciprocal_observability_file_name = reciprocal_observability_file_name
            self.full_path_reciprocal_observability_file_name = os.path.abspath(
                os.path.join(destination_folder_name,
                             reciprocal_observability_file_name))

            self.reciprocal_observability_actions_list = self.load_actions(
                self.full_path_reciprocal_observability_file_name)
            action_list_string = ''
            for op in self.reciprocal_observability_actions_list:
                action_list_string += ' (%s) ' % op
            self.reciprocal_observability_actions_list_string = action_list_string

        #if the action token file name is included - parse it
        if action_token_file_name != None:

            print("action token name is :")
            print(action_token_file_name)

            self.action_tokens_file_name = action_token_file_name
            self.full_action_tokens_file_name = os.path.abspath(
                os.path.join(destination_folder_name, action_token_file_name))

            self.action_tokens_list = self.load_actionsTokens(
                self.full_action_tokens_file_name)
            action_tokens_list_string = ''
            for op in self.action_tokens_list:
                action_tokens_list_string += ' (%s) ' % op
            self.action_tokens_list_string = action_tokens_list_string

        #if the poi_hyps is included - parse it
        if poi_hyps_file != None:
            self.poi_hyps_file_name = poi_hyps_file
            self.full_poi_hyps_file_name = os.path.abspath(
                os.path.join(destination_folder_name, self.poi_hyps_file_name))

            self.poi_hyps_list = self.load_poiHyps(
                self.full_poi_hyps_file_name)
            poi_hyps_list_string = ''
            for hyp in self.poi_hyps_list:
                poi_hyps_list_string += ' (%s) ' % hyp.atoms
            self.poi_hyps_list_string = poi_hyps_list_string
Esempio n. 5
0
def parse_domain_file(domain_file_name):

    #create a PRD domain
    pddl_parser = parser.Parser(domain_file_name)
    planning_domain = pddl_parser.parse_domain()
    return planning_domain