Exemple #1
0
def main(argv):
    #print(argv)

    search_type = argv[0]
    domain_path = argv[1]
    problem_path = argv[2]

    TYPES = ['-dfs', '-bfs']

    if search_type not in TYPES:
        print('Not valid search', search_type)
        print('VALID SEARCH : -dfs, -bfs')
        return
    else:
        search_type = TYPES.index(search_type)
        #print(search_type)

        #domain = PDDLParser.parse("pddl/blocksworld/domain.pddl")
        #problem = PDDLParser.parse("pddl/blocksworld/problems/probBLOCKS-04-0.pddl")

        domain = PDDLParser.parse(domain_path)
        problem = PDDLParser.parse(problem_path)

        plan = search(search_type, domain, problem)
        print_policy(plan)

    return
 def test_mtp_domain(self):
     test_domain_string = '(define (domain no_running_1)(:requirements :typing)(:types  cell)(:constants c0 c1 c2 - cell)(:predicates(at ?c - cell)(adj ?o - cell ?d - cell)(broken)(scratch)(end)(act)(l_d3)(e_d3)(eff_d3_walk)(eff_d3_run)(l_d2)(e_d2)(eff_d2_walk)(eff_d2_run)(l_d1)(e_d1)(eff_d1_walk)(eff_d1_run)(u_walk)(u_run))(:action continue_d3 :parameters ():precondition (and  (not (act)) (l_d3) (not (eff_d3_walk)) (not (eff_d3_run)) (not (eff_d2_walk)) (not (eff_d2_run)) (not (eff_d1_walk)) (not (eff_d1_run)) (or (e_d3))):effect (and (act) (not (e_d3)) (not (e_d2)) (not (e_d1))))(:action continue_d2 :parameters ():precondition (and  (not (act)) (l_d2) (not (eff_d3_walk)) (not (eff_d3_run)) (not (eff_d2_walk)) (not (eff_d2_run)) (not (eff_d1_walk)) (not (eff_d1_run)) (or (e_d3) (e_d2))):effect (and (act) (not (e_d3)) (not (e_d2)) (not (e_d1))))(:action continue_d1 :parameters ():precondition (and  (not (act)) (l_d1) (not (eff_d3_walk)) (not (eff_d3_run)) (not (eff_d2_walk)) (not (eff_d2_run)) (not (eff_d1_walk)) (not (eff_d1_run)) (or (e_d3) (e_d2) (e_d1))):effect (and (act) (not (e_d3)) (not (e_d2)) (not (e_d1))))(:action degrade_d3_d2 :parameters ():precondition (and  (not (act)) (l_d3) (e_d2) (not (eff_d3_walk)) (not (eff_d3_run)) (not (eff_d2_walk)) (not (eff_d2_run)) (not (eff_d1_walk)) (not (eff_d1_run))):effect (and (act) (l_d2) (not (l_d3)) (not (e_d3)) (not (e_d2)) (not (e_d1))))(:action degrade_d3_d1 :parameters ():precondition (and  (not (act)) (l_d3) (e_d1) (not (eff_d3_walk)) (not (eff_d3_run)) (not (eff_d2_walk)) (not (eff_d2_run)) (not (eff_d1_walk)) (not (eff_d1_run))):effect (and (act) (l_d1) (not (l_d3)) (not (e_d3)) (not (e_d2)) (not (e_d1))))(:action degrade_d2_d1 :parameters ():precondition (and  (not (act)) (l_d2) (e_d1) (not (eff_d3_walk)) (not (eff_d3_run)) (not (eff_d2_walk)) (not (eff_d2_run)) (not (eff_d1_walk)) (not (eff_d1_run))):effect (and (act) (l_d1) (not (l_d2)) (not (e_d3)) (not (e_d2)) (not (e_d1))))(:action walk_unfair_ :parameters ():precondition (and  (act) (u_walk)):effect (oneof (and (eff_d3_walk) (not (act))) (and (eff_d2_walk) (not (act))) (and (eff_d1_walk) (not (act)))))(:action walk_d3 :parameters (?o - cell ?d - cell):precondition (and  (at ?o) (adj ?o ?d) (not (broken)) (l_d3) (act) (not (u_walk)) (not (u_run))):effect (oneof (and (not (at ?o)) (at ?d)) (u_walk)))(:action walk_d2 :parameters (?o - cell ?d - cell):precondition (and  (at ?o) (adj ?o ?d) (not (broken)) (l_d2) (act) (not (u_walk)) (not (u_run))):effect (oneof (and (not (at ?o)) (at ?d)) (and (not (at ?o)) (at ?d) (scratch)) (u_walk)))(:action walk_d1 :parameters (?o - cell ?d - cell):precondition (and  (at ?o) (adj ?o ?d) (not (broken)) (l_d1) (act) (not (u_walk)) (not (u_run))):effect (oneof (and (not (at ?o)) (at ?d)) (and (not (at ?o)) (at ?d) (scratch)) (scratch)))(:action walk_eff_d3_explained_by_d3 :parameters (?o - cell ?d - cell):precondition (and  (at ?o) (adj ?o ?d) (not (broken)) (eff_d3_walk)):effect (and (not (at ?o)) (at ?d) (e_d3) (not (eff_d3_walk)) (not (act)) (not (u_walk))))(:action walk_eff_d2_explained_by_d3 :parameters (?o - cell ?d - cell):precondition (and  (at ?o) (adj ?o ?d) (not (broken)) (eff_d2_walk) (scratch)):effect (and (not (at ?o)) (at ?d) (scratch) (e_d3) (not (eff_d2_walk)) (not (act)) (not (u_walk))))(:action walk_eff_d2_explained_by_d2 :parameters (?o - cell ?d - cell):precondition (and  (at ?o) (adj ?o ?d) (not (broken)) (eff_d2_walk) (or (not (scratch)))):effect (and (not (at ?o)) (at ?d) (scratch) (e_d2) (not (eff_d2_walk)) (not (act)) (not (u_walk))))(:action walk_eff_d1_explained_by_d3 :parameters (?o - cell ?d - cell):precondition (and  (at ?o) (adj ?o ?d) (not (broken)) (eff_d1_walk) (scratch) (not (at ?o)) (at ?d)):effect (and (scratch) (e_d3) (not (eff_d1_walk)) (not (act)) (not (u_walk))))(:action walk_eff_d1_explained_by_d2 :parameters (?o - cell ?d - cell):precondition (and  (at ?o) (adj ?o ?d) (not (broken)) (eff_d1_walk) (not (at ?o)) (at ?d) (or (not (scratch)) (at ?o) (not (at ?d)))):effect (and (scratch) (e_d2) (not (eff_d1_walk)) (not (act)) (not (u_walk))))(:action walk_eff_d1_explained_by_d1 :parameters (?o - cell ?d - cell):precondition (and  (at ?o) (adj ?o ?d) (not (broken)) (eff_d1_walk) (or (not (scratch)) (at ?o) (not (at ?d))) (or (at ?o) (not (at ?d)))):effect (and (scratch) (e_d1) (not (eff_d1_walk)) (not (act)) (not (u_walk))))(:action run_unfair_ :parameters ():precondition (and  (act) (u_run)):effect (oneof (and (eff_d3_run) (not (act))) (and (eff_d2_run) (not (act))) (and (eff_d1_run) (not (act)))))(:action run_d3 :parameters ():precondition (and  (at c2) (not (broken)) (l_d3) (act) (not (u_walk)) (not (u_run))):effect (oneof (and (not (at c2)) (at c0)) (u_run)))(:action run_d2 :parameters ():precondition (and  (at c2) (not (broken)) (l_d2) (act) (not (u_walk)) (not (u_run))):effect (oneof (and (not (at c2)) (at c0)) (and (not (at c2)) (at c0) (scratch)) (u_run)))(:action run_d1 :parameters ():precondition (and  (at c2) (not (broken)) (l_d1) (act) (not (u_walk)) (not (u_run))):effect (oneof (and (not (at c2)) (at c0)) (and (not (at c2)) (at c0) (scratch)) (broken)))(:action run_eff_d3_explained_by_d3 :parameters ():precondition (and  (at c2) (not (broken)) (eff_d3_run)):effect (and (not (at c2)) (at c0) (e_d3) (not (eff_d3_run)) (not (act)) (not (u_run))))(:action run_eff_d2_explained_by_d3 :parameters ():precondition (and  (at c2) (not (broken)) (eff_d2_run) (scratch)):effect (and (not (at c2)) (at c0) (scratch) (e_d3) (not (eff_d2_run)) (not (act)) (not (u_run))))(:action run_eff_d2_explained_by_d2 :parameters ():precondition (and  (at c2) (not (broken)) (eff_d2_run) (or (not (scratch)))):effect (and (not (at c2)) (at c0) (scratch) (e_d2) (not (eff_d2_run)) (not (act)) (not (u_run))))(:action run_eff_d1_explained_by_d3 :parameters ():precondition (and  (at c2) (not (broken)) (eff_d1_run) (broken) (not (at c2)) (at c0)):effect (and (broken) (e_d3) (not (eff_d1_run)) (not (act)) (not (u_run))))(:action run_eff_d1_explained_by_d2 :parameters ():precondition (and  (at c2) (not (broken)) (eff_d1_run) (broken) (not (at c2)) (at c0) (scratch) (or (not (broken)) (at c2) (not (at c0)))):effect (and (broken) (e_d2) (not (eff_d1_run)) (not (act)) (not (u_run))))(:action run_eff_d1_explained_by_d1 :parameters ():precondition (and  (at c2) (not (broken)) (eff_d1_run) (or (not (broken)) (at c2) (not (at c0))) (or (not (broken)) (at c2) (not (at c0)) (not (scratch)))):effect (and (broken) (e_d1) (not (eff_d1_run)) (not (act)) (not (u_run))))(:action check_goal_d3 :parameters ():precondition (and  (at c0) (not (scratch)) (not (broken)) (l_d3) (act)):effect (end))(:action check_goal_d2 :parameters ():precondition (and  (at c0) (not (broken)) (l_d2) (act)):effect (end))(:action check_goal_d1 :parameters ():precondition (and  (at c2) (not (broken)) (l_d1) (act)):effect (end)))'
     problem = PDDLParser.parse(
         'labeled-pddl/no-running/labeled-problem.pddl')
     domain = PDDLParser.parse(
         'labeled-pddl/no-running/labeled-domain.pddl')
     domain_models_hierarchy, goal_statement = multi_tier_compilation_problem(
         problem, 'pddl/mtp-example/mtp-problem.pddl')
     multi_tier_compilation_domain(domain, domain_models_hierarchy,
                                   goal_statement,
                                   'pddl/mtp-example/mtp-domain.pddl')
     with open('pddl/mtp-example/mtp-domain.pddl', 'r') as infile:
         aux = infile.read().strip().replace('\n', '').replace('\t', '')
     infile.close()
     new_domain_string = ''.join(aux)
     self.assertEqual(test_domain_string, new_domain_string,
                      "Should be equal")
Exemple #3
0
def main(argv):

    path_domain = argv[0]
    path_problem = argv[1]

    global heuristics_type
    heuristics_type = argv[2]

    domain = PDDLParser.parse(path_domain)
    problem = PDDLParser.parse(path_problem)

    domainR = relaxProblem(domain)

    V = {}
    H = {}

    lrtdp(domain, problem, 0.0, H, V)
 def test_mtp_problem(self):
     test_problem_string = '(define (problem p1)(:domain no_running_1)(:init(at c2)(adj c2 c1)(adj c1 c0)(adj c0 c1)(adj c1 c2)(act)(l_d3))(:goal (and (end))))'
     problem = PDDLParser.parse(
         'labeled-pddl/no-running/labeled-problem.pddl')
     multi_tier_compilation_problem(problem,
                                    'pddl/mtp-example/mtp-problem.pddl')
     with open('pddl/mtp-example/mtp-problem.pddl', 'r') as infile:
         aux = infile.read().strip().replace('\n', '').replace('\t', '')
     infile.close()
     new_problem_string = ''.join(aux)
     self.assertEqual(test_problem_string, new_problem_string,
                      "Should be equal")
 def test_print_problem_labeled(self):
     test_problem_string = '(define (problem p1)\n\t(:domain no_running_1)\n\t(:init\n\t\t(at c2)\n\t\t(adj c2 c1)\n\t\t(adj c1 c0)\n\t\t(adj c0 c1)\n\t\t(adj c1 c2))\n\t(:goal (and \n\t\t(d3 (and (at c0) (not (scratch)) (not (broken))))\n\t\t(d2 (and (at c0) (not (broken))))\n\t\t(d1 (and (at c2) (not (broken))))\n\t\t))\n)'
     problem = PDDLParser.parse(
         'labeled-pddl/no-running/labeled-problem.pddl')
     new_problem_string = repr(problem)
     self.assertEqual(test_problem_string, new_problem_string)
 def test_print_domain_labeled(self):
     test_domain_string = '(define (domain no_running_1)\n\t(:requirements :typing)\n\t(:types \n\t\t cell\n\t)\n\t(:constants \n\t\tc0 c1 c2 - cell\n\t)\n\t(:predicates\n\t\t(at ?c - cell)\n\t\t(adj ?o - cell ?d - cell)\n\t\t(broken)\n\t\t(scratch)\n\t)\n\t(:action walk \n\t\t:parameters (?o - cell ?d - cell)\n\t\t:precondition (and  (at ?o) (adj ?o ?d) (not (broken)))\n\t\t:effect (oneof (d3 (and (not (at ?o)) (at ?d)))\n\t\t (d2 (and (not (at ?o)) (at ?d) (scratch)))\n\t\t (d1 (and (scratch)))\n\t\t)\n\t)\n\t(:action run \n\t\t:parameters ()\n\t\t:precondition (and  (at c2) (not (broken)))\n\t\t:effect (oneof (d3 (and (not (at c2)) (at c0)))\n\t\t (d2 (and (not (at c2)) (at c0) (scratch)))\n\t\t (d1 (and (broken)))\n\t\t)\n\t)\n)'
     domain = PDDLParser.parse(
         'labeled-pddl/no-running/labeled-domain.pddl')
     new_domain_string = repr(domain)
     self.assertEqual(test_domain_string, new_domain_string)
 def test_print_problem_probabilistic(self):
     test_problem_string = '(define (problem tireworld-01)\n\t(:domain triangle-tire)\n\t(:objects x01y05 x02y04 x01y03 x03y03 x02y02 x01y01 - location)\n\t(:init\n\t\t(road x01y01 x01y03)\n\t\t(road x01y01 x02y02)\n\t\t(road x01y03 x01y05)\n\t\t(road x01y03 x02y04)\n\t\t(road x02y02 x01y03)\n\t\t(road x02y02 x03y03)\n\t\t(road x02y04 x01y05)\n\t\t(road x03y03 x02y04)\n\t\t(spare-in x02y02)\n\t\t(spare-in x02y04)\n\t\t(spare-in x03y03)\n\t\t(vehicle-at x01y01)\n\t\t(not-flattire)\n\t\t(hasspare))\n\t(:goal (and \n\t\t(vehicle-at x01y05)))\n)'
     problem = PDDLParser.parse(
         'pddl/triangle-tireworld/problems/p01.ppddl')
     new_problem_string = repr(problem)
     self.assertEqual(test_problem_string, new_problem_string)
 def test_print_domain_probabilistic(self):
     test_domain_string = '(define (domain triangle-tire)\n\t(:requirements :typing :strips :probabilistic-effects)\n\t(:types \n\t\t location\n\t)\n\t(:predicates\n\t\t(road ?from - location ?to - location)\n\t\t(spare-in ?loc - location)\n\t\t(vehicle-at ?loc - location)\n\t\t(not-flattire)\n\t\t(hasspare)\n\t)\n\t(:action move-car \n\t\t:parameters (?from - location ?to - location)\n\t\t:precondition (and  (vehicle-at ?from) (road ?from ?to) (not-flattire))\n\t\t:effect (and (vehicle-at ?to) (not (vehicle-at ?from)) (not (not-flattire)))\n\t)\n\t(:action load-tire \n\t\t:parameters (?loc - location)\n\t\t:precondition (and  (vehicle-at ?loc) (spare-in ?loc))\n\t\t:effect (and (hasspare) (not (spare-in ?loc)))\n\t)\n\t(:action change-tire \n\t\t:parameters ()\n\t\t:precondition (and  (hasspare))\n\t\t:effect (and (not (hasspare)) (not-flattire))\n\t)\n)'
     domain = PDDLParser.parse('pddl/triangle-tireworld/domain.ppddl')
     new_domain_string = repr(domain)
     self.assertEqual(test_domain_string, new_domain_string)
 def test_print_problem_strips(self):
     test_problem_string = '(define (problem blocks-4-0)\n\t(:domain blocks)\n\t(:objects d b a c - block)\n\t(:init\n\t\t(clear c)\n\t\t(clear a)\n\t\t(clear b)\n\t\t(clear d)\n\t\t(ontable c)\n\t\t(ontable a)\n\t\t(ontable b)\n\t\t(ontable d)\n\t\t(handempty))\n\t(:goal (and \n\t\t(on d c)\n\t\t(on c b)\n\t\t(on b a)))\n)'
     problem = PDDLParser.parse(
         'pddl/blocksworld/problems/probBLOCKS-04-0.pddl')
     new_domain_string = repr(problem)
     self.assertEqual(test_problem_string, new_domain_string)
Exemple #10
0
        '--multi-tier-compilation',
        action='store_true',
        default=False,
        help='translate labeled PDDL to MTD and MTP (default: %(default)s)')

    args = vars(
        parser.parse_args())  # vars returns a dictionary of the arguments

    if args['out_problem']:
        args['print_problem'] = True
    if args['out_domain']:
        args['print_domain'] = True
    #print(args)  # just print the options that will be used

    # Parse the domain and problem given, build data structures
    domain = PDDLParser.parse(args['domain-problem'][0])
    # print("==========> Domain parsed into memory....")

    problem = None
    if type(domain) is tuple:  # the first file contained both domain + problem
        problem = domain[1]
        domain = domain[0]

    if len(args['domain-problem']
           ) == 2:  # two files have been given: domain and problem
        problem = PDDLParser.parse(args['domain-problem'][1])
        # print("==========> Problem parsed into memory....")

    if args['multi_tier_compilation']:
        # We extract the hierarchy from the problem definition just because it is easier
        # and is useful when compiling the domain
Exemple #11
0
def main(argv):
    #print(argv)

    search_type = argv[0]

    domain_path = argv[1]
    problem_path = argv[2]

    #print(len(argv))
    heuristic_type = 'None'
    if len(argv) > 3:
        heuristic_command = argv[3]
        heuristic_type = argv[4]

    TYPES_SEARCH = ['-dfs', '-bfs', '-A*']
    TYPER_HEURISTIC = ['-h_add', '-h_max', '-h_ff']

    if search_type not in TYPES_SEARCH:
        print('Not valid search', search_type)
        print('VALID SEARCH : -dfs, -bfs, -A*')
        return

    if len(argv) > 3:
        if heuristic_type not in TYPER_HEURISTIC:
            print('Not valid search', search_type)
            print('VALID HEURISTIC : -h_add, -h_max, -h_ff')
            return

        if heuristic_command != 'H':
            print('Not valid command')
            print('Valid commad for heuristic: H')

    domain = PDDLParser.parse(domain_path)
    problem = PDDLParser.parse(problem_path)

    P = Planner(domain)
    P.setProblem(problem)

    if search_type == '-dfs':
        P.setFrontier(queue.LifoQueue())

    if search_type == '-bfs':
        P.setFrontier(queue.Queue())

    if search_type == '-A*':
        P.setFrontier(queue.PriorityQueue())

        if heuristic_type == '-h_add':
            P.setHeuristic(P.h_add)
        if heuristic_type == '-h_max':
            P.setHeuristic(P.h_max)
        if heuristic_type == '-h_ff':
            P.setHeuristic(P.h_ff)
    #print(search_type)

    #domain = PDDLParser.parse("pddl/blocksworld/domain.pddl")
    #problem = PDDLParser.parse("pddl/blocksworld/problems/probBLOCKS-04-0.pddl")

    [
        Plan, Time, Cost, HeuristicTime, StVisited, Expanded, BrachFactor,
        Penetrancy
    ] = P.search()

    #print(search_type, heuristic_type, domain_path, problem_path, elapsed_time)
    #print("-----------------------------------------")
    #print("Time of Planner",Time)
    #print("-----------------------------------------")
    #print("Cost of solution",Cost)
    #print("-----------------------------------------")
    #print("Time of Heuristic",HeuristicTime)
    #print("-----------------------------------------")
    #print("Visited States",StVisited)
    #print("-----------------------------------------")
    #print("Expanded States",Expanded)
    #print("-----------------------------------------")
    #print("Branch Factor",BrachFactor)
    #print("-----------------------------------------")
    #print("Penetrancy",Penetrancy)
    #print("-----------------------------------------")
    #print("Plan")
    #print("-----------------------------------------")
    #P.print_policy(Plan)
    #print("-----------------------------------------")

    print(
        '#',
        '%20s' % 'Name',
        '%10s' % 'Time',
        '%10s' % 'Cost',
        '%10s' % 'Hrst-Time',
        '%10s' % 'st-Visited',
        '%10s' % 'st-Expnded',
        '%10s' % 'brch-Fact',
        '%10s' % 'Penetrancy',
    )

    base = os.path.basename(problem_path)

    print(' ', '% 20s' % os.path.splitext(base)[0], '% 10.3f' % Time,
          '% 10.0f' % Cost, '% 10.3f' % HeuristicTime, '% 10.0f' % StVisited,
          '% 10.0f' % Expanded, '% 10.3f' % BrachFactor,
          '% 10.3f' % Penetrancy)

    return
Exemple #12
0
    problem.add_to_init('open', ['1', '2'])
    # print(problem.init)

    problem.add_to_goal('open', ['3', '4'])
    # print(problem.goal)



if __name__ == '__main__':
    usage = 'python3 main.py <DOMAIN> <INSTANCE>'
    description = 'pypddl-parser is a PDDL parser built on top of ply.'
    parser = argparse.ArgumentParser(usage=usage, description=description)

    parser.add_argument('domain',  type=str, help='path to PDDL domain file')
    parser.add_argument('problem', type=str, help='path to PDDL problem file')

    args = parser.parse_args()

    domain  = PDDLParser.parse(args.domain)
    problem = PDDLParser.parse(args.problem)

    ## Pretty-printing of domain and problem
    # print(domain)
    # print(problem)

    # test modifications to domain and problem
    add_to_domain(domain)
    add_to_problem(problem)

    # print(repr(domain))
    print(repr(problem))
Exemple #13
0
from planner import Planner
import queue
from pddlparser import PDDLParser

domain = PDDLParser.parse('pddl/robot/domain.pddl')

#problems rooms

problem_path = [
    '/home/milton/Documentos/parser-pddl/python/EP03/pddl/robot/rooms/problem01.pddl',
    '/home/milton/Documentos/parser-pddl/python/EP03/pddl/robot/rooms/problem02.pddl',
    '/home/milton/Documentos/parser-pddl/python/EP03/pddl/robot/rooms/problem03.pddl',
    '/home/milton/Documentos/parser-pddl/python/EP03/pddl/robot/rooms/problem04.pddl',
    '/home/milton/Documentos/parser-pddl/python/EP03/pddl/robot/rooms/problem05.pddl',
    '/home/milton/Documentos/parser-pddl/python/EP03/pddl/robot/rooms/problem06.pddl',
    '/home/milton/Documentos/parser-pddl/python/EP03/pddl/robot/rooms/problem07.pddl',
    '/home/milton/Documentos/parser-pddl/python/EP03/pddl/robot/rooms/problem08.pddl',
    '/home/milton/Documentos/parser-pddl/python/EP03/pddl/robot/rooms/problem09.pddl',
    '/home/milton/Documentos/parser-pddl/python/EP03/pddl/robot/rooms/problem10.pddl',
    '/home/milton/Documentos/parser-pddl/python/EP03/pddl/robot/rooms/problem11.pddl',
    '/home/milton/Documentos/parser-pddl/python/EP03/pddl/robot/rooms/problem12.pddl',
    '/home/milton/Documentos/parser-pddl/python/EP03/pddl/robot/rooms/problem13.pddl',
    '/home/milton/Documentos/parser-pddl/python/EP03/pddl/robot/rooms/problem14.pddl',
    '/home/milton/Documentos/parser-pddl/python/EP03/pddl/robot/rooms/problem15.pddl',
    '/home/milton/Documentos/parser-pddl/python/EP03/pddl/robot/rooms/problem16.pddl',
    '/home/milton/Documentos/parser-pddl/python/EP03/pddl/robot/rooms/problem17.pddl',
    '/home/milton/Documentos/parser-pddl/python/EP03/pddl/robot/rooms/problem18.pddl',
    '/home/milton/Documentos/parser-pddl/python/EP03/pddl/robot/rooms/problem19.pddl',
    '/home/milton/Documentos/parser-pddl/python/EP03/pddl/robot/rooms/problem20.pddl',
    '/home/milton/Documentos/parser-pddl/python/EP03/pddl/robot/rooms/problem21.pddl',
    '/home/milton/Documentos/parser-pddl/python/EP03/pddl/robot/rooms/problem22.pddl',
Exemple #14
0
import argparse
from pddlparser import PDDLParser
from util import *

domain = PDDLParser.parse('pddl/tetris-opt14-strips/domain.pddl')
problem = PDDLParser.parse('pddl/tetris-opt14-strips/p01-10.pddl')



def foo():

	def sub_foo():
		print("sub_foo")


	sub_foo()


foo()



d = relaxProblem(domain)


for action in d.operators:

	for eff in action.effects:
		print(eff)
	print("------------------------")
 def test_print_domain_oneof_or(self):
     test_domain_string = '(define (domain no_running_1)\n\t(:requirements :typing)\n\t(:types \n\t\t cell\n\t)\n\t(:constants \n\t\tc0 c1 c2 - cell\n\t)\n\t(:predicates\n\t\t(at ?c - cell)\n\t\t(adj ?o - cell ?d - cell)\n\t\t(broken)\n\t\t(scratch)\n\t\t(end)\n\t\t(act)\n\t\t(l_d3)\n\t\t(e_d3)\n\t\t(eff_d3_walk)\n\t\t(eff_d3_run)\n\t\t(l_d2)\n\t\t(e_d2)\n\t\t(eff_d2_walk)\n\t\t(eff_d2_run)\n\t\t(l_d1)\n\t\t(e_d1)\n\t\t(eff_d1_walk)\n\t\t(eff_d1_run)\n\t\t(u_walk)\n\t\t(u_run)\n\t)\n\t(:action continue_d3 \n\t\t:parameters ()\n\t\t:precondition (and  (not (act)) (l_d3) (not (eff_d3_walk)) (not (eff_d3_run)) (not (eff_d2_walk)) (not (eff_d2_run)) (not (eff_d1_walk)) (not (eff_d1_run)) (or (e_d3)))\n\t\t:effect (and (act) (not (e_d3)) (not (e_d2)) (not (e_d1)))\n\t)\n\t(:action continue_d2 \n\t\t:parameters ()\n\t\t:precondition (and  (not (act)) (l_d2) (not (eff_d3_walk)) (not (eff_d3_run)) (not (eff_d2_walk)) (not (eff_d2_run)) (not (eff_d1_walk)) (not (eff_d1_run)) (or (e_d3) (e_d2)))\n\t\t:effect (and (act) (not (e_d3)) (not (e_d2)) (not (e_d1)))\n\t)\n\t(:action continue_d1 \n\t\t:parameters ()\n\t\t:precondition (and  (not (act)) (l_d1) (not (eff_d3_walk)) (not (eff_d3_run)) (not (eff_d2_walk)) (not (eff_d2_run)) (not (eff_d1_walk)) (not (eff_d1_run)) (or (e_d3) (e_d2) (e_d1)))\n\t\t:effect (and (act) (not (e_d3)) (not (e_d2)) (not (e_d1)))\n\t)\n\t(:action degrade_d3_d2 \n\t\t:parameters ()\n\t\t:precondition (and  (not (act)) (l_d3) (e_d2) (not (eff_d3_walk)) (not (eff_d3_run)) (not (eff_d2_walk)) (not (eff_d2_run)) (not (eff_d1_walk)) (not (eff_d1_run)))\n\t\t:effect (and (act) (l_d2) (not (l_d3)) (not (e_d3)) (not (e_d2)) (not (e_d1)))\n\t)\n\t(:action degrade_d3_d1 \n\t\t:parameters ()\n\t\t:precondition (and  (not (act)) (l_d3) (e_d1) (not (eff_d3_walk)) (not (eff_d3_run)) (not (eff_d2_walk)) (not (eff_d2_run)) (not (eff_d1_walk)) (not (eff_d1_run)))\n\t\t:effect (and (act) (l_d1) (not (l_d3)) (not (e_d3)) (not (e_d2)) (not (e_d1)))\n\t)\n\t(:action degrade_d2_d1 \n\t\t:parameters ()\n\t\t:precondition (and  (not (act)) (l_d2) (e_d1) (not (eff_d3_walk)) (not (eff_d3_run)) (not (eff_d2_walk)) (not (eff_d2_run)) (not (eff_d1_walk)) (not (eff_d1_run)))\n\t\t:effect (and (act) (l_d1) (not (l_d2)) (not (e_d3)) (not (e_d2)) (not (e_d1)))\n\t)\n\t(:action walk_unfair_ \n\t\t:parameters ()\n\t\t:precondition (and  (act) (u_walk))\n\t\t:effect (oneof (and (eff_d3_walk) (not (act))) (and (eff_d2_walk) (not (act))) (and (eff_d1_walk) (not (act))))\n\t)\n\t(:action walk_d3 \n\t\t:parameters (?o - cell ?d - cell)\n\t\t:precondition (and  (at ?o) (adj ?o ?d) (not (broken)) (l_d3) (act) (not (u_walk)) (not (u_run)))\n\t\t:effect (oneof (and (not (at ?o)) (at ?d)) (u_walk))\n\t)\n\t(:action walk_d2 \n\t\t:parameters (?o - cell ?d - cell)\n\t\t:precondition (and  (at ?o) (adj ?o ?d) (not (broken)) (l_d2) (act) (not (u_walk)) (not (u_run)))\n\t\t:effect (oneof (and (not (at ?o)) (at ?d)) (and (not (at ?o)) (at ?d) (scratch)) (u_walk))\n\t)\n\t(:action walk_d1 \n\t\t:parameters (?o - cell ?d - cell)\n\t\t:precondition (and  (at ?o) (adj ?o ?d) (not (broken)) (l_d1) (act) (not (u_walk)) (not (u_run)))\n\t\t:effect (oneof (and (not (at ?o)) (at ?d)) (and (not (at ?o)) (at ?d) (scratch)) (scratch))\n\t)\n\t(:action walk_eff_d3_explained_by_d3 \n\t\t:parameters (?o - cell ?d - cell)\n\t\t:precondition (and  (at ?o) (adj ?o ?d) (not (broken)) (eff_d3_walk))\n\t\t:effect (and (not (at ?o)) (at ?d) (e_d3) (not (eff_d3_walk)) (not (act)) (not (u_walk)))\n\t)\n\t(:action walk_eff_d2_explained_by_d3 \n\t\t:parameters (?o - cell ?d - cell)\n\t\t:precondition (and  (at ?o) (adj ?o ?d) (not (broken)) (eff_d2_walk) (scratch))\n\t\t:effect (and (not (at ?o)) (at ?d) (scratch) (e_d3) (not (eff_d2_walk)) (not (act)) (not (u_walk)))\n\t)\n\t(:action walk_eff_d2_explained_by_d2 \n\t\t:parameters (?o - cell ?d - cell)\n\t\t:precondition (and  (at ?o) (adj ?o ?d) (not (broken)) (eff_d2_walk) (or (not (scratch))))\n\t\t:effect (and (not (at ?o)) (at ?d) (scratch) (e_d2) (not (eff_d2_walk)) (not (act)) (not (u_walk)))\n\t)\n\t(:action walk_eff_d1_explained_by_d3 \n\t\t:parameters (?o - cell ?d - cell)\n\t\t:precondition (and  (at ?o) (adj ?o ?d) (not (broken)) (eff_d1_walk) (scratch) (not (at ?o)) (at ?d))\n\t\t:effect (and (scratch) (e_d3) (not (eff_d1_walk)) (not (act)) (not (u_walk)))\n\t)\n\t(:action walk_eff_d1_explained_by_d2 \n\t\t:parameters (?o - cell ?d - cell)\n\t\t:precondition (and  (at ?o) (adj ?o ?d) (not (broken)) (eff_d1_walk) (not (at ?o)) (at ?d) (or (not (scratch)) (at ?o) (not (at ?d))))\n\t\t:effect (and (scratch) (e_d2) (not (eff_d1_walk)) (not (act)) (not (u_walk)))\n\t)\n\t(:action walk_eff_d1_explained_by_d1 \n\t\t:parameters (?o - cell ?d - cell)\n\t\t:precondition (and  (at ?o) (adj ?o ?d) (not (broken)) (eff_d1_walk) (or (not (scratch)) (at ?o) (not (at ?d))) (or (at ?o) (not (at ?d))))\n\t\t:effect (and (scratch) (e_d1) (not (eff_d1_walk)) (not (act)) (not (u_walk)))\n\t)\n\t(:action run_unfair_ \n\t\t:parameters ()\n\t\t:precondition (and  (act) (u_run))\n\t\t:effect (oneof (and (eff_d3_run) (not (act))) (and (eff_d2_run) (not (act))) (and (eff_d1_run) (not (act))))\n\t)\n\t(:action run_d3 \n\t\t:parameters ()\n\t\t:precondition (and  (at c2) (not (broken)) (l_d3) (act) (not (u_walk)) (not (u_run)))\n\t\t:effect (oneof (and (not (at c2)) (at c0)) (u_run))\n\t)\n\t(:action run_d2 \n\t\t:parameters ()\n\t\t:precondition (and  (at c2) (not (broken)) (l_d2) (act) (not (u_walk)) (not (u_run)))\n\t\t:effect (oneof (and (not (at c2)) (at c0)) (and (not (at c2)) (at c0) (scratch)) (u_run))\n\t)\n\t(:action run_d1 \n\t\t:parameters ()\n\t\t:precondition (and  (at c2) (not (broken)) (l_d1) (act) (not (u_walk)) (not (u_run)))\n\t\t:effect (oneof (and (not (at c2)) (at c0)) (and (not (at c2)) (at c0) (scratch)) (broken))\n\t)\n\t(:action run_eff_d3_explained_by_d3 \n\t\t:parameters ()\n\t\t:precondition (and  (at c2) (not (broken)) (eff_d3_run))\n\t\t:effect (and (not (at c2)) (at c0) (e_d3) (not (eff_d3_run)) (not (act)) (not (u_run)))\n\t)\n\t(:action run_eff_d2_explained_by_d3 \n\t\t:parameters ()\n\t\t:precondition (and  (at c2) (not (broken)) (eff_d2_run) (scratch))\n\t\t:effect (and (not (at c2)) (at c0) (scratch) (e_d3) (not (eff_d2_run)) (not (act)) (not (u_run)))\n\t)\n\t(:action run_eff_d2_explained_by_d2 \n\t\t:parameters ()\n\t\t:precondition (and  (at c2) (not (broken)) (eff_d2_run) (or (not (scratch))))\n\t\t:effect (and (not (at c2)) (at c0) (scratch) (e_d2) (not (eff_d2_run)) (not (act)) (not (u_run)))\n\t)\n\t(:action run_eff_d1_explained_by_d3 \n\t\t:parameters ()\n\t\t:precondition (and  (at c2) (not (broken)) (eff_d1_run) (broken) (not (at c2)) (at c0))\n\t\t:effect (and (broken) (e_d3) (not (eff_d1_run)) (not (act)) (not (u_run)))\n\t)\n\t(:action run_eff_d1_explained_by_d2 \n\t\t:parameters ()\n\t\t:precondition (and  (at c2) (not (broken)) (eff_d1_run) (broken) (not (at c2)) (at c0) (scratch) (or (not (broken)) (at c2) (not (at c0))))\n\t\t:effect (and (broken) (e_d2) (not (eff_d1_run)) (not (act)) (not (u_run)))\n\t)\n\t(:action run_eff_d1_explained_by_d1 \n\t\t:parameters ()\n\t\t:precondition (and  (at c2) (not (broken)) (eff_d1_run) (or (not (broken)) (at c2) (not (at c0))) (or (not (broken)) (at c2) (not (at c0)) (not (scratch))))\n\t\t:effect (and (broken) (e_d1) (not (eff_d1_run)) (not (act)) (not (u_run)))\n\t)\n\t(:action check_goal_d3 \n\t\t:parameters ()\n\t\t:precondition (and  (at c0) (not (scratch)) (not (broken)) (l_d3) (act))\n\t\t:effect (end)\n\t)\n\t(:action check_goal_d2 \n\t\t:parameters ()\n\t\t:precondition (and  (at c0) (not (broken)) (l_d2) (act))\n\t\t:effect (end)\n\t)\n\t(:action check_goal_d1 \n\t\t:parameters ()\n\t\t:precondition (and  (at c2) (l_d1) (act))\n\t\t:effect (end)\n\t)\n)'
     domain = PDDLParser.parse('labeled-pddl/no-running/mtp-domain.pddl')
     new_domain_string = repr(domain)
     self.assertEqual(test_domain_string, new_domain_string)
 def test_print_domain_strips(self):
     test_domain_string = '(define (domain blocks)\n\t(:requirements :strips :typing :equality)\n\t(:types \n\t\t\t\tblock block1 - superblock\n objects1 objects2\n\t)\n\t(:constants \n\t\ta b c - block\n\t)\n\t(:predicates\n\t\t(on ?x - block ?y - block)\n\t\t(ontable ?x - block)\n\t\t(clear ?x - block)\n\t\t(handempty)\n\t\t(holding ?x - block)\n\t)\n\t(:action pick-up \n\t\t:parameters (?x - block)\n\t\t:precondition (and  (clear ?x) (ontable ?x) (handempty))\n\t\t:effect (and (not (ontable ?x)) (not (clear ?x)) (not (handempty)) (holding ?x))\n\t)\n\t(:action put-down \n\t\t:parameters (?x - block)\n\t\t:precondition (and  (holding ?x))\n\t\t:effect (and (not (holding ?x)) (clear ?x) (handempty) (ontable ?x))\n\t)\n\t(:action stack \n\t\t:parameters (?x - block ?y - block)\n\t\t:precondition (and  (not (= ?x ?y)) (holding ?x) (clear ?y))\n\t\t:effect (and (not (holding ?x)) (not (clear ?y)) (clear ?x) (handempty) (on ?x ?y))\n\t)\n\t(:action unstack \n\t\t:parameters (?x - block ?y - block)\n\t\t:precondition (and  (not (= ?x ?y)) (on ?x ?y) (clear ?x) (handempty))\n\t\t:effect (and (holding ?x) (clear ?y) (not (clear ?x)) (not (handempty)) (not (on ?x ?y)))\n\t)\n)'
     domain = PDDLParser.parse('pddl/blocksworld/domain.pddl')
     new_domain_string = repr(domain)
     self.assertEqual(test_domain_string, new_domain_string)
 def test_print_domain_conditional_effects(self):
     test_domain_string = '(define (domain ce)\n\t(:requirements :strips :typing :equality)\n\t(:predicates\n\t\t(p)\n\t\t(q)\n\t\t(r)\n\t\t(s)\n\t)\n\t(:action ce1 \n\t\t:parameters ()\n\t\t:precondition (and  (p))\n\t\t:effect (and (not (p)) (when (and (q))(and (s)))\n\t)\n)'
     domain = PDDLParser.parse('pddl/conditional_effects/domain.pddl')
     new_domain_string = repr(domain)
     self.assertEqual(test_domain_string, new_domain_string)
Exemple #18
0
                            if p not in H:
                                H[str(p)] = math.inf

                            H[str(p)] = min(H[str(p)], 1 + sum(to_sum))

            if U_before == U:
                #print('fixed point')
                break

        return max([H[p] for p in current_state])


#SINGLE TEST
#SET PATH TO OTHERS PROBLEMS!

domain = PDDLParser.parse('pddl/robot/domain.pddl')
problem = PDDLParser.parse('pddl/robot/boxes/problem05.pddl')

#TO RUN A PROBLEM
#1. CREATE A PLANNER WITH A DOMAIN
#2. SET PROBLEM TO THE PLANNER
#3. SET HEURISTIC TO THE PLANNER,(DEFAULT HEURISTIC THAT RETURN 0)
#4. SET FRONTIER(STACK, QUEUE OR PRIORITY QUEUE)
#5. RUN PLANNER

#EXAMPLE

P = Planner(domain)
P.setProblem(problem)

#PLANNER WITH HEURISTIC H_ADD, USING A PRIORITY QUEUE#