示例#1
0
def gen_heuristic_test(dom,
                       prob,
                       search_class,
                       heuristic_class,
                       h_values_plan,
                       plan_length=None):
    parser = Parser('')
    parser.domInput = dom
    parser.probInput = prob

    domain = parser.parse_domain(False)
    problem = parser.parse_problem(domain, False)

    task = grounding.ground(problem)

    heuristic = heuristic_class(task)
    plan = search_class(task, heuristic)
    if plan_length:
        assert len(plan) == plan_length
    # run through plan and validate heuristic value
    # the true_h_values are taken from fast downward with astar and lm cut
    # heuristic
    computed_h_values = list(_gen_h_values(task.initial_state, plan,
                                           heuristic))
    assert h_values_plan == computed_h_values
示例#2
0
def test_lm_cut_blocksworld_initial_state():
    parser = Parser("")
    parser.domInput = blocks_dom
    parser.probInput = blocks_problem_1

    domain = parser.parse_domain(False)
    problem = parser.parse_problem(domain, False)

    task = grounding.ground(problem)

    heuristic = LmCutHeuristic(task)
    h_val = heuristic(make_root_node(task.initial_state))
    assert h_val == 6.0
示例#3
0
def test_lm_cut_blocksworld_initial_state():
    parser = Parser('')
    parser.domInput = blocks_dom
    parser.probInput = blocks_problem_1

    domain = parser.parse_domain(False)
    problem = parser.parse_problem(domain, False)

    task = grounding.ground(problem)

    heuristic = LmCutHeuristic(task)
    h_val = heuristic(make_root_node(task.initial_state))
    assert h_val == 6.
def gen_heuristic_test(dom, prob, search_class, heuristic_class, h_values_plan,
                       plan_length=None):
    parser = Parser('')
    parser.domInput = dom
    parser.probInput = prob

    domain = parser.parse_domain(False)
    problem = parser.parse_problem(domain, False)

    task = grounding.ground(problem)

    heuristic = heuristic_class(task)
    plan = search_class(task, heuristic)
    if plan_length:
        assert len(plan) == plan_length
    # run through plan and validate heuristic value
    # the true_h_values are taken from fast downward with astar and lm cut
    # heuristic
    computed_h_values = list(_gen_h_values(task.initial_state, plan, heuristic))
    assert h_values_plan == computed_h_values
                   (not (on ?x ?y)))))
"""

_problem_input = """(define (problem BLOCKS-5-0)
(:domain BLOCKS)
(:story_objs B E A C D - block)
(:INIT (CLEAR D) (CLEAR C) (ONTABLE D) (ONTABLE A) (ON C E) (ON E B) (ON B A)
 (HANDEMPTY))
(:goal (AND (ON A E) (ON E B) (ON B D) (ON D C)))
)
"""

_parser = Parser('')

_parser.domInput = _domain_input
_parser.probInput = _problem_input

_domain = _parser.parse_domain(False)
_problem = _parser.parse_problem(_domain, False)


def test_default_pddl_visitor_domain():
    defaultVisitor = pddl_tree_visitor.PDDLVisitor()
    input = _domain_input.split('\n')
    iter = parse_lisp_iterator(input)
    domAST = parse_domain_def(iter)
    # and traverse the AST
    domAST.accept(defaultVisitor)


def test_default_pddl_visitor_problem():
示例#6
0
                   (not (on ?x ?y)))))
"""

_problem_input = """(define (problem BLOCKS-5-0)
(:domain BLOCKS)
(:objects B E A C D - block)
(:INIT (CLEAR D) (CLEAR C) (ONTABLE D) (ONTABLE A) (ON C E) (ON E B) (ON B A)
 (HANDEMPTY))
(:goal (AND (ON A E) (ON E B) (ON B D) (ON D C)))
)
"""

_parser = Parser("")

_parser.domInput = _domain_input
_parser.probInput = _problem_input

_domain = _parser.parse_domain(False)
_problem = _parser.parse_problem(_domain, False)


def test_default_pddl_visitor_domain():
    defaultVisitor = pddl_tree_visitor.PDDLVisitor()
    input = _domain_input.split("\n")
    iter = parse_lisp_iterator(input)
    domAST = parse_domain_def(iter)
    # and traverse the AST
    domAST.accept(defaultVisitor)


def test_default_pddl_visitor_problem():
def test_writer_complex():
    test = [
        """
        (define (domain BLOCKS)
      (:requirements :strips :typing)
      (:types block)
      (:predicates (on ?x - block ?y - block)
                   (ontable ?x - block)
                   (clear ?x - block)
                   (handempty)
                   (holding ?x - block)
                   )

      (:action pick-up
                 :parameters (?x - block)
                 :precondition (and (clear ?x) (ontable ?x) (handempty))
                 :effect
                 (and (not (ontable ?x))
                       (not (clear ?x))
                       (not (handempty))
                       (holding ?x)))

      (:action put-down
                 :parameters (?x - block)
                 :precondition (holding ?x)
                 :effect
                 (and (not (holding ?x))
                       (clear ?x)
                       (handempty)
                       (ontable ?x)))
      (:action stack
                 :parameters (?x - block ?y - block)
                 :precondition (and (holding ?x) (clear ?y))
                 :effect
                 (and (not (holding ?x))
                       (not (clear ?y))
                       (clear ?x)
                       (handempty)
                       (on ?x ?y)))
      (:action unstack
                 :parameters (?x - block ?y - block)
                 :precondition (and (on ?x ?y) (clear ?x) (handempty))
                 :effect
                 (and (holding ?x)
                       (clear ?y)
                       (not (clear ?x))
                       (not (handempty))
                       (not (on ?x ?y)))))
        """, """
                (define (problem BLOCKS-4-0)
                (:domain BLOCKS)
                (:objects D B A C - block)
                (:INIT (CLEAR C) (CLEAR A) (CLEAR B) (CLEAR D) (ONTABLE C) (ONTABLE A)
                (ONTABLE B) (ONTABLE D) (HANDEMPTY))
                (:goal (AND (ON D C) (ON C B) (ON B A)))
                )
                """
    ]
    parser = Parser(None)
    parser.domInput = test[0]
    parser.probInput = test[1]
    domain = parser.parse_domain(False)
    problem = parser.parse_problem(domain, False)
    writer = PDDLWriter()
    domain_string = writer.write_domain(domain)
    # print(domain_string)
    parser.domInput = domain_string
    domain = parser.parse_domain(False)  # Checking if our output is valid pddl
    assert domain is not None
    # print(writer.write_domain(domain))
    # assert domain_string == writer.write_domain(domain)
    print(writer.write_problem(problem))