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_parseAction():
    test = ["""
    (: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)))
    """]
    iter = parse_lisp_iterator(test)
    action = parse_action_stmt(iter)
    assert action.name == "pick-up"
    assert action.parameters[0].name == "?x"
    assert action.parameters[0].types[0] == "block"
    pre = action.precond.formula
    assert pre.key == 'and'
    assert [c.key for c in pre.children] == ['clear', 'ontable', 'handempty']
    assert pre.children[0].children[0].key.name == '?x'
    assert pre.children[1].children[0].key.name == '?x'
    assert pre.children[2].children == []
    eff = action.effect.formula
    assert eff.key == 'and'
    assert [c.key for c in eff.children] == ['not', 'not', 'not', 'holding']
    assert eff.children[0].children[0].key == 'ontable'
    assert [c.key.name for c in eff.children[0].children[0].children] == ['?x']
示例#3
0
def test_parseInitStmt():
    test = [
        """
    (:INIT (CLEAR C) (CLEAR A H) (CLEAR B) (CLEAR D) (ONTABLE C) (ONTABLE A)
     (ONTABLE B) (ONTABLE D) (HANDEMPTY))"""
    ]
    iter = parse_lisp_iterator(test)
    init = parse_init_stmt(iter)
    assert [p.name for p in init.predicates] == [
        "clear",
        "clear",
        "clear",
        "clear",
        "ontable",
        "ontable",
        "ontable",
        "ontable",
        "handempty",
    ]
    assert [p.parameters for p in init.predicates] == [
        ["c"],
        ["a", "h"],
        ["b"],
        ["d"],
        ["c"],
        ["a"],
        ["b"],
        ["d"],
        [],
    ]
示例#4
0
def test_predList2():
    test = [
        """
    (:predicates (at ?x - (either person aircraft) ?c - city)
             (in ?p - person ?a - aircraft)
             (fuel-level ?a - aircraft ?l - flevel)
             (next ?l1 ?l2 - flevel))
    """
    ]
    iter = parse_lisp_iterator(test)
    pred = parse_predicates_stmt(iter)
    assert [p.name
            for p in pred.predicates] == ["at", "in", "fuel-level", "next"]
    assert [
        p.parameters[0].name for p in pred.predicates if p.parameters != []
    ] == [
        "?x",
        "?p",
        "?a",
        "?l1",
    ]
    assert [
        p.parameters[0].types[0] for p in pred.predicates
        if p.parameters[0].types != None
    ] == ["person", "person", "aircraft", "flevel"]
def test_parseProblemDef():
    test = ["""
    (define (problem logistics-4-1)
    (:domain logistics)
    (:story_objs
      apn1 - airplane
      apt2 apt1 - airport
      pos2 pos1 - location
      cit2 cit1 - city
      tru2 tru1 - truck
      obj23 obj22 obj21 obj13 obj12 obj11 - package)

    (:init (at apn1 apt2) (at tru1 pos1) (at obj11 pos1)
     (at obj12 pos1) (at obj13 pos1) (at tru2 pos2) (at obj21 pos2)
     (at obj22 pos2) (at obj23 pos2) (in-city pos1 cit1) (in-city apt1 cit1)
     (in-city pos2 cit2) (in-city apt2 cit2))

    (:goal (and (at obj12 apt2) (at obj13 apt1) (at obj21 apt2)
                (at obj11 pos2)))
    )
    """]
    iter = parse_lisp_iterator(test)
    prob = parse_problem_def(iter)
    assert prob.name == 'logistics-4-1'
    assert prob.domainName == 'logistics'
    objectsTest(prob.objects)
    predNames = [p.name for p in prob.init.predicates]
    assert len(predNames) == 13
    assert set(predNames) == set(['at', 'in-city'])
示例#6
0
def test_default_pddl_visitor_problem():
    defaultVisitor = pddl_tree_visitor.PDDLVisitor()
    input = _problem_input.split("\n")
    iter = parse_lisp_iterator(input)
    probAST = parse_problem_def(iter)
    # and traverse the AST
    probAST.accept(defaultVisitor)
def test_default_pddl_visitor_problem():
    defaultVisitor = pddl_tree_visitor.PDDLVisitor()
    input = _problem_input.split('\n')
    iter = parse_lisp_iterator(input)
    probAST = parse_problem_def(iter)
    # and traverse the AST
    probAST.accept(defaultVisitor)
示例#8
0
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_parseAction():
    test = ["""
    (: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)))
    """]
    iter = parse_lisp_iterator(test)
    action = parse_action_stmt(iter)
    assert action.name == "pick-up"
    assert action.parameters[0].name == "?x"
    assert action.parameters[0].types[0] == "block"
    pre = action.precond.formula
    assert pre.key == 'and'
    assert [c.key for c in pre.children] == ['clear', 'ontable', 'handempty']
    assert pre.children[0].children[0].key.name == '?x'
    assert pre.children[1].children[0].key.name == '?x'
    assert pre.children[2].children == []
    eff = action.effect.formula
    assert eff.key == 'and'
    assert [c.key for c in eff.children] == ['not', 'not', 'not', 'holding']
    assert eff.children[0].children[0].key == 'ontable'
    assert [c.key.name for c in eff.children[0].children[0].children] == ['?x']
示例#10
0
def test_parseVariableNoTyping():
    test = [" ( ?x)"]
    iter = parse_lisp_iterator(test)
    key = parse_variable(next(iter))
    assert key.name == "?x"
    assert key.typed == False
    assert key.types == None
示例#11
0
def test_parseProblemDef():
    test = ["""
    (define (problem logistics-4-1)
    (:domain logistics)
    (:objects
      apn1 - airplane
      apt2 apt1 - airport
      pos2 pos1 - location
      cit2 cit1 - city
      tru2 tru1 - truck
      obj23 obj22 obj21 obj13 obj12 obj11 - package)

    (:init (at apn1 apt2) (at tru1 pos1) (at obj11 pos1)
     (at obj12 pos1) (at obj13 pos1) (at tru2 pos2) (at obj21 pos2)
     (at obj22 pos2) (at obj23 pos2) (in-city pos1 cit1) (in-city apt1 cit1)
     (in-city pos2 cit2) (in-city apt2 cit2))

    (:goal (and (at obj12 apt2) (at obj13 apt1) (at obj21 apt2)
                (at obj11 pos2)))
    )
    """]
    iter = parse_lisp_iterator(test)
    prob = parse_problem_def(iter)
    assert prob.name == 'logistics-4-1'
    assert prob.domainName == 'logistics'
    objectsTest(prob.objects)
    predNames = [p.name for p in prob.init.predicates]
    assert len(predNames) == 13
    assert set(predNames) == set(['at', 'in-city'])
示例#12
0
def test_parseVariableNoTyping():
    test = [' ( ?x)']
    iter = parse_lisp_iterator(test)
    key = parse_variable(next(iter))
    assert key.name == '?x'
    assert key.typed == False
    assert key.types == None
示例#13
0
def test_parsePredicates():
    test = [
        """
    (:predicates (on ?x - block ?y - block)
               (ontable ?x - block)
               (clear ?x - plane)
               (handempty)
               (holding ?x - block)
               )
    """
    ]
    iter = parse_lisp_iterator(test)
    pred = parse_predicates_stmt(iter)
    assert [p.name for p in pred.predicates
            ] == ['on', 'ontable', 'clear', 'handempty', 'holding']
    assert [
        p.parameters[0].name for p in pred.predicates if p.parameters != []
    ] == ['?x', '?x', '?x', '?x']
    assert [
        p.parameters[0].types[0] for p in pred.predicates
        if p.parameters != []
    ] == ['block', 'block', 'plane', 'block']
    assert [
        p.parameters[1].types[0] for p in pred.predicates
        if len(p.parameters) > 1
    ] == ['block']
def test_parsePredicateMixed():
    test = ['(on ?x - block ?y)']
    iter = parse_lisp_iterator(test)
    pred = parse_predicate(iter)
    assert pred.name == 'on'
    assert [x.name for x in pred.parameters] == ['?x', '?y']
    assert [x.types[0] for x in pred.parameters
            if x.types != None] == ['block']
示例#15
0
def test_parseVariableTyping():
    test = [' ( ?x - block)']
    iter = parse_lisp_iterator(test)
    vlist = parse_typed_var_list(iter)
    assert len(vlist) == 1
    assert vlist[0].name == '?x'
    assert vlist[0].typed == True
    assert vlist[0].types[0] == 'block'
示例#16
0
def test_parseVariableTyping():
    test = [" ( ?x - block)"]
    iter = parse_lisp_iterator(test)
    vlist = parse_typed_var_list(iter)
    assert len(vlist) == 1
    assert vlist[0].name == "?x"
    assert vlist[0].typed == True
    assert vlist[0].types[0] == "block"
示例#17
0
def test_parsePredicateMixed():
    test = ["(on ?x - block ?y)"]
    iter = parse_lisp_iterator(test)
    pred = parse_predicate(iter)
    assert pred.name == "on"
    assert [x.name for x in pred.parameters] == ["?x", "?y"]
    assert [x.types[0] for x in pred.parameters
            if x.types != None] == ["block"]
示例#18
0
def test_parseConstants():
    test = [
        """
    (:constants
                north
                south - direction
                light
                medium
                heavy - airplanetype
                seg_pp_0_60
                seg_ppdoor_0_40
                seg_tww1_0_200
                seg_twe1_0_200
                seg_tww2_0_50
                seg_tww3_0_50
                seg_tww4_0_50
                seg_rww_0_50
                seg_rwtw1_0_10
                seg_rw_0_400
                seg_rwe_0_50
                seg_twe4_0_50
                seg_rwte1_0_10
                seg_twe3_0_50
                seg_twe2_0_50
                seg_rwte2_0_10
                seg_rwtw2_0_10 - segment
                airplane_CFBEG - airplane
    )
    """
    ]
    iter = parse_lisp_iterator(test)
    const = parse_constants_stmt(iter)
    nameList = ['north', 'south', 'light', 'medium', 'heavy']
    nameList += """seg_pp_0_60
                seg_ppdoor_0_40
                seg_tww1_0_200
                seg_twe1_0_200
                seg_tww2_0_50
                seg_tww3_0_50
                seg_tww4_0_50
                seg_rww_0_50
                seg_rwtw1_0_10
                seg_rw_0_400
                seg_rwe_0_50
                seg_twe4_0_50
                seg_rwte1_0_10
                seg_twe3_0_50
                seg_twe2_0_50
                seg_rwte2_0_10
                seg_rwtw2_0_10
                airplane_CFBEG""".split()
    nameList = [n.lower() for n in nameList]
    assert [c.name for c in const] == nameList
    ttest = [c.typeName for c in const][:5]
    assert ttest == [
        'direction', 'direction', 'airplanetype', 'airplanetype',
        'airplanetype'
    ]
示例#19
0
def test_predList4():
    test = ["""
    (:predicates (at ?x - (either person aircraft) ?c - city)
             (in p - person a - aircraft)
             (fuel-level ?a - aircraft ?l - flevel)
             (next ?l1 ?l2 - flevel))
    """]
    iter = parse_lisp_iterator(test)
    with raises(ValueError):
        pred = parse_predicates_stmt(iter)
示例#20
0
def test_predList4():
    test = ["""
    (:predicates (at ?x - (either person aircraft) ?c - city)
             (in p - person a - aircraft)
             (fuel-level ?a - aircraft ?l - flevel)
             (next ?l1 ?l2 - flevel))
    """]
    iter = parse_lisp_iterator(test)
    with raises(ValueError):
        pred = parse_predicates_stmt(iter)
示例#21
0
def test_parseDomainDef():
    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))))
   (:unkownKeyword lksdf)
                   )
    """
    ]
    iter = parse_lisp_iterator(test)
    with raises(ValueError):
        dom = parse_domain_def(iter)
示例#22
0
def test_parseGoalStmt():
    test = ["""(:goal (AND (ON D C) (ON C B) (ON B A)))"""]
    iter = parse_lisp_iterator(test)
    goal = parse_goal_stmt(iter)
    f = goal.formula
    assert f.key == 'and'
    assert [c.key for c in f.children] == ['on', 'on', 'on']
    assert [c2[0].key
            for c2 in [c1.children for c1 in f.children]] == ['d', 'c', 'b']
    assert [c2[1].key
            for c2 in [c1.children for c1 in f.children]] == ['c', 'b', 'a']
示例#23
0
def test_parseGoalStmt():
    test = ["""(:goal (AND (ON D C) (ON C B) (ON B A)))"""]
    iter = parse_lisp_iterator(test)
    goal = parse_goal_stmt(iter)
    f = goal.formula
    assert f.key == "and"
    assert [c.key for c in f.children] == ["on", "on", "on"]
    assert [c2[0].key
            for c2 in [c1.children for c1 in f.children]] == ["d", "c", "b"]
    assert [c2[1].key
            for c2 in [c1.children for c1 in f.children]] == ["c", "b", "a"]
示例#24
0
def test_parseConstants():
    test = ["""
    (:constants
                north
                south - direction
                light
                medium
                heavy - airplanetype
                seg_pp_0_60
                seg_ppdoor_0_40
                seg_tww1_0_200
                seg_twe1_0_200
                seg_tww2_0_50
                seg_tww3_0_50
                seg_tww4_0_50
                seg_rww_0_50
                seg_rwtw1_0_10
                seg_rw_0_400
                seg_rwe_0_50
                seg_twe4_0_50
                seg_rwte1_0_10
                seg_twe3_0_50
                seg_twe2_0_50
                seg_rwte2_0_10
                seg_rwtw2_0_10 - segment
                airplane_CFBEG - airplane
    )
    """]
    iter = parse_lisp_iterator(test)
    const = parse_constants_stmt(iter)
    nameList = ['north', 'south', 'light', 'medium', 'heavy']
    nameList += """seg_pp_0_60
                seg_ppdoor_0_40
                seg_tww1_0_200
                seg_twe1_0_200
                seg_tww2_0_50
                seg_tww3_0_50
                seg_tww4_0_50
                seg_rww_0_50
                seg_rwtw1_0_10
                seg_rw_0_400
                seg_rwe_0_50
                seg_twe4_0_50
                seg_rwte1_0_10
                seg_twe3_0_50
                seg_twe2_0_50
                seg_rwte2_0_10
                seg_rwtw2_0_10
                airplane_CFBEG""".split()
    nameList = [n.lower() for n in nameList]
    assert [c.name for c in const] == nameList
    ttest = [c.typeName for c in const][:5]
    assert ttest == ['direction', 'direction', 'airplanetype', 'airplanetype',
                     'airplanetype']
示例#25
0
def test_parseGoalStmt():
    test = ["""(:goal (AND (ON D C) (ON C B) (ON B A)))"""]
    iter = parse_lisp_iterator(test)
    goal = parse_goal_stmt(iter)
    f = goal.formula
    assert f.key == 'and'
    assert [c.key for c in f.children] == ['on', 'on', 'on']
    assert [c2[0].key
            for c2 in [c1.children for c1 in f.children]] == ['d', 'c', 'b']
    assert [c2[1].key
            for c2 in [c1.children for c1 in f.children]] == ['c', 'b', 'a']
示例#26
0
def test_parseObjectsStmt():
    test = ["""(:objects
      apn1 - airplane
      apt2 apt1 - airport
       pos2 pos1 - location
       cit2 cit1 - city
       tru2 tru1 - truck
       obj23 obj22 obj21 obj13 obj12 obj11 - package)"""]
    iter = parse_lisp_iterator(test)
    objects = parse_objects_stmt(iter)
    objectsTest(objects)
示例#27
0
def test_parseObjectsStmt():
    test = ["""(:story_objs
      apn1 - airplane
      apt2 apt1 - airport
       pos2 pos1 - location
       cit2 cit1 - city
       tru2 tru1 - truck
       obj23 obj22 obj21 obj13 obj12 obj11 - package)"""]
    iter = parse_lisp_iterator(test)
    objects = parse_objects_stmt(iter)
    objectsTest(objects)
示例#28
0
def test_parseDomainDef():
    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))))
   (:unkownKeyword lksdf)
                   )
    """]
    iter = parse_lisp_iterator(test)
    with raises(ValueError):
        dom = parse_domain_def(iter)
示例#29
0
def test_parseInitStmt():
    test = ["""
    (:INIT (CLEAR C) (CLEAR A H) (CLEAR B) (CLEAR D) (ONTABLE C) (ONTABLE A)
     (ONTABLE B) (ONTABLE D) (HANDEMPTY))"""]
    iter = parse_lisp_iterator(test)
    init = parse_init_stmt(iter)
    assert [p.name
            for p in init.predicates] == ['clear', 'clear', 'clear', 'clear',
                                          'ontable', 'ontable', 'ontable',
                                          'ontable', 'handempty']
    assert [p.parameters
            for p in init.predicates] == [['c'], ['a', 'h'], ['b'], ['d'],
                                          ['c'], ['a'], ['b'], ['d'], []]
示例#30
0
def test_parseInitStmt():
    test = ["""
    (:INIT (CLEAR C) (CLEAR A H) (CLEAR B) (CLEAR D) (ONTABLE C) (ONTABLE A)
     (ONTABLE B) (ONTABLE D) (HANDEMPTY))"""]
    iter = parse_lisp_iterator(test)
    init = parse_init_stmt(iter)
    assert [p.name
            for p in init.predicates] == ['clear', 'clear', 'clear', 'clear',
                                          'ontable', 'ontable', 'ontable',
                                          'ontable', 'handempty']
    assert [p.parameters
            for p in init.predicates] == [['c'], ['a', 'h'], ['b'], ['d'],
                                          ['c'], ['a'], ['b'], ['d'], []]
def test_parseFormula():
    test = ['(and (on ?x table) (true) (free ?x))']
    iter = parse_lisp_iterator(test)
    print(iter)
    formula = parse_formula(iter)
    assert formula.key == 'and'
    assert [c.key for c in formula.children] == ['on', 'true', 'free']
    assert [c.key.name for c in formula.children[0].children
            if c.type == TypeVariable] == ['?x']
    assert [c.key for c in formula.children[0].children
            if c.type == TypeConstant] == ['table']
    assert [c.key.name for c in formula.children[2].children
            if c.type == TypeVariable] == ['?x']
    assert [c for c in formula.children[1].children] == []
示例#32
0
def test_parsePredicatesLogistics():
    test = ["""
        (:predicates  (in-city ?loc - place ?city - city)
                (at ?obj - physobj ?loc - place)
                (in ?pkg - package ?veh - vehicle))
    """]
    iter = parse_lisp_iterator(test)
    pred = parse_predicates_stmt(iter)
    assert [p.name for p in pred.predicates] == ['in-city', 'at', 'in']
    assert [p.parameters[0].name
            for p in pred.predicates
            if p.parameters != []] == ['?loc', '?obj', '?pkg']
    assert [p.parameters[0].types[0]
            for p in pred.predicates
            if p.parameters != []] == ['place', 'physobj', 'package']
    def _parse_observations(self,domain,observations_file):
        observations = []
        with open(observations_file, encoding='utf-8') as file:
            for obs in file:
                iter = parse_lisp_iterator(obs)
                act = parse_predicate_instance(self.parser._read_input(obs))
                observations.append(act)

            # iter = self.parser._read_input(file)
            # while not iter.empty():
            #     observations.append()
            # observations = parse_predicate_instance_list(iter)
        # TODO validate parsed actions

        return observations
示例#34
0
def test_parsePredicatesLogistics():
    test = ["""
        (:predicates  (in-city ?loc - place ?city - city)
                (at ?obj - physobj ?loc - place)
                (in ?pkg - package ?veh - vehicle))
    """]
    iter = parse_lisp_iterator(test)
    pred = parse_predicates_stmt(iter)
    assert [p.name for p in pred.predicates] == ['in-city', 'at', 'in']
    assert [p.parameters[0].name
            for p in pred.predicates
            if p.parameters != []] == ['?loc', '?obj', '?pkg']
    assert [p.parameters[0].types[0]
            for p in pred.predicates
            if p.parameters != []] == ['place', 'physobj', 'package']
示例#35
0
def test_predList2():
    test = ["""
    (:predicates (at ?x - (either person aircraft) ?c - city)
             (in ?p - person ?a - aircraft)
             (fuel-level ?a - aircraft ?l - flevel)
             (next ?l1 ?l2 - flevel))
    """]
    iter = parse_lisp_iterator(test)
    pred = parse_predicates_stmt(iter)
    assert [p.name
            for p in pred.predicates] == ['at', 'in', 'fuel-level', 'next']
    assert [p.parameters[0].name for p in pred.predicates
            if p.parameters != []] == ['?x', '?p', '?a', '?l1']
    assert [p.parameters[0].types[0] for p in pred.predicates
            if p.parameters[0].types != None] == ['person', 'person',
                                                   'aircraft', 'flevel']
示例#36
0
def test_predList2():
    test = ["""
    (:predicates (at ?x - (either person aircraft) ?c - city)
             (in ?p - person ?a - aircraft)
             (fuel-level ?a - aircraft ?l - flevel)
             (next ?l1 ?l2 - flevel))
    """]
    iter = parse_lisp_iterator(test)
    pred = parse_predicates_stmt(iter)
    assert [p.name
            for p in pred.predicates] == ['at', 'in', 'fuel-level', 'next']
    assert [p.parameters[0].name for p in pred.predicates
            if p.parameters != []] == ['?x', '?p', '?a', '?l1']
    assert [p.parameters[0].types[0] for p in pred.predicates
            if p.parameters[0].types != None] == ['person', 'person',
                                                   'aircraft', 'flevel']
示例#37
0
def test_parseDomainDef2():
    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)
               )
    (:unkownKeyword lksdf)
    )
    """]
    iter = parse_lisp_iterator(test)
    with raises(ValueError):
        dom = parse_domain_def(iter)
示例#38
0
def test_parseDomainDef2():
    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)
               )
    (:unkownKeyword lksdf)
    )
    """]
    iter = parse_lisp_iterator(test)
    with raises(ValueError):
        dom = parse_domain_def(iter)
示例#39
0
def test_parsePredicates():
    test = ["""
    (:predicates (on ?x - block ?y - block)
               (ontable ?x - block)
               (clear ?x - plane)
               (handempty)
               (holding ?x - block)
               )
    """]
    iter = parse_lisp_iterator(test)
    pred = parse_predicates_stmt(iter)
    assert [p.name for p in pred.predicates] == ['on', 'ontable', 'clear',
                                                   'handempty', 'holding']
    assert [p.parameters[0].name for p in pred.predicates
            if p.parameters != []] == ['?x', '?x', '?x', '?x']
    assert [p.parameters[0].types[0] for p in pred.predicates
            if p.parameters != []] == ['block', 'block', 'plane', 'block']
    assert [p.parameters[1].types[0] for p in pred.predicates
            if len(p.parameters) > 1] == ['block']
示例#40
0
def test_parseFormula():
    test = ["(and (on ?x table) (true) (free ?x))"]
    iter = parse_lisp_iterator(test)
    print(iter)
    formula = parse_formula(iter)
    assert formula.key == "and"
    assert [c.key for c in formula.children] == ["on", "true", "free"]
    assert [
        c.key.name for c in formula.children[0].children
        if c.type == TypeVariable
    ] == ["?x"]
    assert [
        c.key for c in formula.children[0].children if c.type == TypeConstant
    ] == ["table"]
    assert [
        c.key.name for c in formula.children[2].children
        if c.type == TypeVariable
    ] == ["?x"]
    assert [c for c in formula.children[1].children] == []
示例#41
0
def test_parseTypes():
    test = ["""
    (:types truck
          airplane - vehicle
          package
          vehicle - physobj
          airport
          location - place
          city
          place
          physobj - object)
    """]
    iter = parse_lisp_iterator(test)
    types = parse_types_stmt(iter)
    assert [t.name for t in types] == ['truck', 'airplane', 'package',
                                       'vehicle', 'airport', 'location',
                                       'city', 'place', 'physobj']
    assert [t.parent for t in types
            if t.parent != None] == ['vehicle', 'vehicle', 'physobj',
                                     'physobj', 'place', 'place', 'object',
                                     'object', 'object']
示例#42
0
def test_parseTypes():
    test = ["""
    (:types truck
          airplane - vehicle
          package
          vehicle - physobj
          airport
          location - place
          city
          place
          physobj - object)
    """]
    iter = parse_lisp_iterator(test)
    types = parse_types_stmt(iter)
    assert [t.name for t in types] == ['truck', 'airplane', 'package',
                                       'vehicle', 'airport', 'location',
                                       'city', 'place', 'physobj']
    assert [t.parent for t in types
            if t.parent != None] == ['vehicle', 'vehicle', 'physobj',
                                     'physobj', 'place', 'place', 'object',
                                     'object', 'object']
示例#43
0
def test_parsePredicatesLogistics():
    test = [
        """
        (:predicates  (in-city ?loc - place ?city - city)
                (at ?obj - physobj ?loc - place)
                (in ?pkg - package ?veh - vehicle))
    """
    ]
    iter = parse_lisp_iterator(test)
    pred = parse_predicates_stmt(iter)
    assert [p.name for p in pred.predicates] == ["in-city", "at", "in"]
    assert [
        p.parameters[0].name for p in pred.predicates if p.parameters != []
    ] == [
        "?loc",
        "?obj",
        "?pkg",
    ]
    assert [
        p.parameters[0].types[0] for p in pred.predicates
        if p.parameters != []
    ] == ["place", "physobj", "package"]
示例#44
0
def test_parseTypes():
    test = [
        """
    (:types truck
          airplane - vehicle
          package
          vehicle - physobj
          airport
          location - place
          city
          place
          physobj - object)
    """
    ]
    iter = parse_lisp_iterator(test)
    types = parse_types_stmt(iter)
    assert [t.name for t in types] == [
        "truck",
        "airplane",
        "package",
        "vehicle",
        "airport",
        "location",
        "city",
        "place",
        "physobj",
    ]
    assert [t.parent for t in types if t.parent != None] == [
        "vehicle",
        "vehicle",
        "physobj",
        "physobj",
        "place",
        "place",
        "object",
        "object",
        "object",
    ]
示例#45
0
def test_parsePredicates():
    test = [
        """
    (:predicates (on ?x - block ?y - block)
               (ontable ?x - block)
               (clear ?x - plane)
               (handempty)
               (holding ?x - block)
               )
    """
    ]
    iter = parse_lisp_iterator(test)
    pred = parse_predicates_stmt(iter)
    assert [p.name for p in pred.predicates] == [
        "on",
        "ontable",
        "clear",
        "handempty",
        "holding",
    ]
    assert [
        p.parameters[0].name for p in pred.predicates if p.parameters != []
    ] == [
        "?x",
        "?x",
        "?x",
        "?x",
    ]
    assert [
        p.parameters[0].types[0] for p in pred.predicates
        if p.parameters != []
    ] == ["block", "block", "plane", "block"]
    assert [
        p.parameters[1].types[0] for p in pred.predicates
        if len(p.parameters) > 1
    ] == ["block"]
示例#46
0
def test_parseParameters():
    test = ['(:parameters ( ?x - block ?y - foo ?z - block  ))']
    iter = parse_lisp_iterator(test)
    key = parse_parameters(iter)
    varListTest(key)
示例#47
0
def test_parseParameters2():
    test = ['(:predicates ( ?x - block ?y - foo ?z - block  ))']
    iter = parse_lisp_iterator(test)
    with raises(ValueError):
        parse_parameters(iter)
示例#48
0
def test_parseParameters2():
    test = ["(:predicates ( ?x - block ?y - foo ?z - block  ))"]
    iter = parse_lisp_iterator(test)
    with raises(ValueError):
        parse_parameters(iter)
示例#49
0
def test_parseParameters():
    test = ["(:parameters ( ?x - block ?y - foo ?z - block  ))"]
    iter = parse_lisp_iterator(test)
    key = parse_parameters(iter)
    varListTest(key)
示例#50
0
def test_parse_problem_name_fail():
    test = ['(domain test)']
    iter = parse_lisp_iterator(test)
    with raises(ValueError):
        parse_problem_name(iter)
示例#51
0
def test_parse_problem_def_fail():
    test = ['(definiere problem)']
    iter = parse_lisp_iterator(test)
    with raises(ValueError):
        parse_problem_def(iter)
示例#52
0
def test_parse_goal_stmt_fail():
    test = ['(:init ssdfsdf)']
    iter = parse_lisp_iterator(test)
    with raises(ValueError):
        parse_goal_stmt(iter)
示例#53
0
def test_parseVariableList():
    test = [' ( ?x - block ?y - foo ?z - block  )']
    iter = parse_lisp_iterator(test)
    key = parse_typed_var_list(iter)
    varListTest(key)
示例#54
0
def test_parseKeywordComplex():
    test = [' ( :name)']
    iter = parse_lisp_iterator(test)
    key = parse_keyword(next(iter))
    assert key.name == 'name'
示例#55
0
def test_parseRequirements2():
    test = ['(:predicates :name :parameters :foo )']
    iter = parse_lisp_iterator(test)
    with raises(ValueError):
        parse_requirements_stmt(iter)
示例#56
0
def test_parseKeywordList():
    test = ['(:name :parameters :foo )']
    iter = parse_lisp_iterator(test)
    keys = parse_keyword_list(iter)
    assert iter.empty()
    keywordListTest(keys)
示例#57
0
def test_parseRequirements():
    test = ['(:requirements :name :parameters :foo )']
    iter = parse_lisp_iterator(test)
    req = parse_requirements_stmt(iter)
    assert iter.empty()
    keywordListTest(req.keywords)
示例#58
0
def test_parseDomainDef():
    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)))))
    """]
    iter = parse_lisp_iterator(test)
    dom = parse_domain_def(iter)
    assert dom.name == 'blocks'
    assert [key.name
            for key in dom.requirements.keywords] == ['strips', 'typing']
    assert [t.name for t in dom.types] == ['block']
    pred = dom.predicates
    assert [p.name
            for p in pred.predicates] == ['on', 'ontable', 'clear',
                                           'handempty', 'holding']
    assert [p.parameters[0].name
            for p in pred.predicates
            if p.parameters != []] == ['?x', '?x', '?x', '?x']
    assert [p.parameters[0].types[0]
            for p in pred.predicates
            if p.parameters != []] == ['block', 'block', 'block', 'block']
    assert [p.parameters[1].types[0] for p in pred.predicates
            if len(p.parameters) > 1] == ['block']
    assert len(dom.actions) == 4
    action = dom.actions[3]
    assert action.name == 'unstack'
    assert action.parameters[0].name == '?x'
    assert action.parameters[0].types[0] == 'block'
    assert action.parameters[1].name == '?y'
    assert action.parameters[1].types[0] == 'block'
    pre = action.precond.formula
    assert pre.key == 'and'
    assert [c.key for c in pre.children] == ['on', 'clear', 'handempty']
    assert pre.children[0].children[0].key.name == '?x'
    assert pre.children[0].children[1].key.name == '?y'
    assert pre.children[1].children[0].key.name == '?x'
    assert pre.children[2].children == []
    eff = action.effect.formula
    assert eff.key == 'and'
    assert [c.key
            for c in eff.children] == ['holding', 'clear', 'not', 'not', 'not']