Exemple #1
0
def problem_to_dict(domain_file_path, problem_path):
    (dom, prob) = pddl.parseDomainAndProblem(domain_file_path, problem_path)
    # create dictionary of the objects
    obj_dict = {}
    for object in prob.objects.args:
        obj_type = object.arg_type.lower()
        obj_name = object.arg_name.lower()
        if obj_type in obj_dict.keys():
            obj_dict[obj_type].append(obj_name)
        else:
            obj_dict[obj_type] = [obj_name]

    # create dictionary of the init predicates
    init_predic_dict = {}
    for predic in prob.initialstate:
        predic_name = predic.subformulas[0].name.lower()
        args = []
        for typed_arg in predic.subformulas[0].args.args:
            args.append(typed_arg.arg_name.lower())

        if predic_name in init_predic_dict.keys():
            init_predic_dict[predic_name].append(args)
        else:
            init_predic_dict[predic_name] = [args]

    # create goal
    goal_dict = {}
    for goal in prob.goal.subformulas:
        goal_pred_name = goal.subformulas[0].name.lower()
        args = []
        for typed_arg in goal.subformulas[0].args.args:
            args.append(typed_arg.arg_name.lower())

        if goal_pred_name in goal_dict.keys():
            goal_dict[goal_pred_name].append(args)
        else:
            goal_dict[goal_pred_name] = [args]

    # create dictionary of domain predicates
    dom_predic_dict = {}
    for predic in dom.predicates:
        predic_name = predic.name.lower()
        args = []
        for typed_arg in predic.args.args:
            args.append(typed_arg.arg_name.lower())

        if predic_name in dom_predic_dict.keys():
            dom_predic_dict[predic_name].append(args)
        else:
            dom_predic_dict[predic_name] = [args]

    # get objects list
    dom_object_types = [arg.arg_name.lower() for arg in dom.types.args]

    return obj_dict, init_predic_dict, goal_dict, dom_predic_dict, dom_object_types
Exemple #2
0
def gen_problem_sub_problems(domain_file_path, problem_file_path,
                             plan_file_path, new_problems_path):
    (dom, prob) = pddl.parseDomainAndProblem(domain_file_path,
                                             problem_file_path)

    # create partial name path using path for problems and name of the given problem
    name_of_problem_file = problem_file_path.split(r'/')[-1]
    name_of_problem_file_wo_pddl = name_of_problem_file.split('.')[0]
    partial_new_problems_name = os.path.join(new_problems_path,
                                             name_of_problem_file_wo_pddl)

    # create actions list using the plan file
    plan_actions = getActionsByArgs(plan_file_path)
    if len(plan_actions) == 0:
        return plan_actions
    subproblem_paths = flow(dom, prob, plan_actions, partial_new_problems_name)
    return subproblem_paths
Exemple #3
0
def main():
    if len(sys.argv) < 4:
        print("Usage: pddl.py <domain> <problem> <new_domain> <new_problem>")
        return

    domainfile = sys.argv[1]
    problemfile = sys.argv[2]
    
    (dom,prob) = pddl.parseDomainAndProblem(domainfile, problemfile)

    new_domain = sys.argv[3]
    new_problem = sys.argv[4]
    
    nd = open(new_domain, 'w')
    nd.write(dom.asPDDL())
    nd.close()
    
    np = open(new_problem, 'w')
    np.write(prob.asPDDL())
    np.close()
Exemple #4
0
def main():
    if len(sys.argv) < 4:
        print("Usage: pddl.py <domain> <problem> <new_domain> <new_problem>")
        return

    domainfile = sys.argv[1]
    problemfile = sys.argv[2]

    (dom, prob) = pddl.parseDomainAndProblem(domainfile, problemfile)

    new_domain = sys.argv[3]
    new_problem = sys.argv[4]

    nd = open(new_domain, 'w')
    nd.write(dom.asPDDL())
    nd.close()

    np = open(new_problem, 'w')
    np.write(prob.asPDDL())
    np.close()
def adjust_til(domain_path, problem_path, adjustment, adjusted_problem_path):
    (_, problem) = pddl.parseDomainAndProblem(domain_path, problem_path)
    adjust_pddl_til(problem, adjustment)

    with open(adjusted_problem_path, 'w') as adjusted_problem:
        adjusted_problem.write(problem.asPDDL())