Esempio n. 1
0
def test_integration1():
    print("Running integration test 1...")

    training_data = {
        Place: [
            (
                {IsPawn('o1'),
                 IsPawn('o2'),
                 IsPawn('o3'),
                 Holding('o1')},
                Place('o1'),
                {Anti(Holding('o1'))},
            ),
            (
                {IsPawn('o1'),
                 IsPawn('o2'),
                 IsPawn('o3'),
                 Holding('o2')},
                Place('o1'),
                set(),
            ),
            (
                {IsPawn('o1'),
                 IsPawn('o2'),
                 IsPawn('o3'),
                 Holding('o2')},
                Place('o2'),
                {Anti(Holding('o2'))},
            ),
        ]
    }

    test_transitions = [
        (
            {IsPawn('o1'),
             IsPawn('o2'),
             IsPawn('o3'),
             Holding('o3')},
            Place('o3'),
            {Anti(Holding('o3'))},
        ),
        (
            {IsPawn('o1'),
             IsPawn('o2'),
             IsPawn('o3'),
             Holding('o1')},
            Place('o3'),
            set(),
        ),
        (
            {IsPawn('o1'),
             IsPawn('o2'),
             IsPawn('o3'),
             Holding('o3')},
            Place('o1'),
            set(),
        ),
    ]

    return run_integration_test(training_data, test_transitions)
Esempio n. 2
0
 def create_ndr_set():
     action = Act0()
     preconditions = [Red("?x"), HandsFree0()]
     effect_probs = [0.8, 0.2]
     effects = [{Anti(HandsFree0())}, {NOISE_OUTCOME}]
     ndr0 = NDR(action, preconditions, effect_probs, effects)
     preconditions = [Red("?x"), Blue("?x")]
     effect_probs = [0.5, 0.4, 0.1]
     effects = [{HandsFree0()}, {Anti(Blue("?x"))}, {NOISE_OUTCOME}]
     ndr1 = NDR(action, preconditions, effect_probs, effects)
     return NDRSet(action, [ndr0, ndr1])
Esempio n. 3
0
def test_ndr():
    def create_ndr():
        action = Act0()
        preconditions = [Red("?x"), HandsFree0()]
        effect_probs = [0.8, 0.2]
        effects = [{Anti(HandsFree0())}, {NOISE_OUTCOME}]
        return NDR(action, preconditions, effect_probs, effects)

    # Test copy
    ndr = create_ndr()
    ndr_copy = ndr.copy()
    ndr.preconditions.remove(HandsFree0())
    assert HandsFree0() not in ndr.preconditions
    assert HandsFree0() in ndr_copy.preconditions
    del ndr.effects[0]
    assert len(ndr.effects) == 1
    assert len(ndr_copy.effects) == 2
    ndr.effect_probs[0] = 1.0
    assert ndr.effect_probs[0] == 1.0
    assert ndr_copy.effect_probs[0] == 0.8

    # Test find substitutions
    ndr = create_ndr()
    state = {Red("block0")}
    action = Act0()
    assert ndr.find_substitutions(state, action) == None
    state = {Red("block0"), HandsFree0(), Blue("block1")}
    action = Act0()
    sigma = ndr.find_substitutions(state, action)
    assert sigma is not None
    assert len(sigma) == 1
    assert sigma[block_type("?x")] == block_type("block0")
    state = {Red("block0"), HandsFree0(), Red("block1")}
    action = Act0()
    assert ndr.find_substitutions(state, action) == None

    # Test find_unique_matching_effect_index
    ndr = create_ndr()
    state = {Red("block0"), HandsFree0(), Blue("block1")}
    action = Act0()
    effects = {Anti(HandsFree0())}
    assert ndr.find_unique_matching_effect_index((state, action, effects)) == 0
    state = {Red("block0"), HandsFree0(), Blue("block1")}
    action = Act0()
    effects = {Anti(HandsFree0()), Blue("block0")}
    assert ndr.find_unique_matching_effect_index((state, action, effects)) == 1

    print("Test NDR passed.")
Esempio n. 4
0
 def get_child_effects(self, effects, ndr_settings=None):
     for i in range(len(effects)-1):
         if NOISE_OUTCOME in effects[i]:
             continue
         for j in range(i+1, len(effects)):
             if NOISE_OUTCOME in effects[j]:
                 continue
             # Check for contradiction
             contradiction = False
             for lit_i in effects[i]:
                 if contradiction:
                     break
                 for lit_j in effects[j]:
                     if Anti(lit_i.predicate) == lit_j:
                         contradiction = True
                         break
             if contradiction:
                 continue
             # Create new set of effects that combines the two
             combined_effects = sorted(set(effects[i]) | set(effects[j]))
             # Get the other effects
             new_effects = []
             for k in range(len(effects)):
                 if k in [i, j]:
                     continue
                 new_effects.append(effects[k])
             # Add the new effect
             new_effects.append(combined_effects)
             yield new_effects
Esempio n. 5
0
 def _compute_effects(state, next_state):
     positive_effects = {e for e in next_state.literals - state.literals}
     negative_effects = {
         Anti(ne)
         for ne in state.literals - next_state.literals
     }
     return positive_effects | negative_effects
Esempio n. 6
0
def construct_effects(obs, next_obs):
    """Convert a next observation into effects
    """
    # This is just for debugging environments where noise outcomes are simulated
    if noiseoutcome() in next_obs.literals:
        return {noiseoutcome()}
    effects = set()
    for lit in next_obs.literals - obs.literals:
        effects.add(lit)
    for lit in obs.literals - next_obs.literals:
        effects.add(Anti(lit))
    return effects
Esempio n. 7
0
def integration_test():
    dir_path = os.path.dirname(os.path.realpath(__file__))
    domain_file = os.path.join(dir_path, 'pddl', 'test_domain.pddl')
    problem_file = os.path.join(dir_path, 'pddl', 'test_domain', 'test_problem.pddl')
    domain = PDDLDomainParser(domain_file)
    problem = PDDLProblemParser(problem_file, domain.domain_name, domain.types,
        domain.predicates)

    ## Check domain
    type1 = Type('type1')
    type2 = Type('type2')

    # Action predicates
    action_pred = Predicate('actionpred', 1, [type1])

    # Predicates
    pred1 = Predicate('pred1', 1, [type1])
    pred2 = Predicate('pred2', 1, [type2])
    pred3 = Predicate('pred3', 1, [type1, type2, type2])
    assert set(domain.predicates.values()) == { pred1, pred2, pred3, action_pred }
    assert domain.actions == { action_pred.name }

    # Operators
    assert len(domain.operators) == 1
    operator1 = Predicate('action1', 4, [type1, type1, type2, type2])
    assert operator1 in domain.operators

    operator = domain.operators[operator1]
    # Operator parameters
    assert len(operator.params) == 4
    assert operator.params[0] == type1('?a')
    assert operator.params[1] == type1('?b')
    assert operator.params[2] == type2('?c')
    assert operator.params[3] == type2('?d')

    # Operator preconditions (set of Literals)
    assert len(operator.preconds.literals) == 4
    assert set(operator.preconds.literals) == { action_pred('?b'), pred1('?b'), 
        pred3('?a', '?c', '?d'), Not(pred2('?c')) }

    # Operator effects (set of Literals)
    assert len(operator.effects.literals) == 3
    assert set(operator.effects.literals) == { Anti(pred2('?d')), pred2('?c'), 
        pred3('?b', '?d', '?c')}

    ## Check problem

    # Objects
    assert set(problem.objects) == {type1('a1'), type1('a2'), type1('b1'),
        type1('b2'), type1('b3'), type2('c1'), type2('c2'), type2('d1'), 
        type2('d2'), type2('d3')}

    # Goal
    assert isinstance(problem.goal, LiteralConjunction)
    assert set(problem.goal.literals) == {pred2('c2'), pred3('b1', 'c1', 'd1')}

    # Init
    assert problem.initial_state == { pred1('b2'), pred2('c1'),
        pred3('a1', 'c1', 'd1'), pred3('a2', 'c2', 'd2'), action_pred('a1'), 
        action_pred('a2'), action_pred('b1'), action_pred('b2')}

    print("Test passed.")
Esempio n. 8
0
 def _parse_into_literal(self, string, params, is_effect=False):
     """Parse the given string (representing either preconditions or effects)
     into a literal. Check against params to make sure typing is correct.
     """
     assert string[0] == "("
     assert string[-1] == ")"
     if string.startswith("(and") and string[4] in (" ", "\n", "("):
         clauses = self._find_all_balanced_expressions(string[4:-1].strip())
         return LiteralConjunction([
             self._parse_into_literal(clause, params, is_effect=is_effect)
             for clause in clauses
         ])
     if string.startswith("(or") and string[3] in (" ", "\n", "("):
         clauses = self._find_all_balanced_expressions(string[3:-1].strip())
         return LiteralDisjunction([
             self._parse_into_literal(clause, params, is_effect=is_effect)
             for clause in clauses
         ])
     if string.startswith("(forall") and string[7] in (" ", "\n", "("):
         new_binding, clause = self._find_all_balanced_expressions(
             string[7:-1].strip())
         new_name, new_type_name = new_binding.strip()[1:-1].split("-")
         new_name = new_name.strip()
         new_type_name = new_type_name.strip()
         assert new_name not in params, "ForAll variable {} already exists".format(
             new_name)
         params[new_name] = self.types[new_type_name]
         result = ForAll(
             self._parse_into_literal(clause, params, is_effect=is_effect),
             TypedEntity(new_name, params[new_name]))
         del params[new_name]
         return result
     if string.startswith("(exists") and string[7] in (" ", "\n", "("):
         new_binding, clause = self._find_all_balanced_expressions(
             string[7:-1].strip())
         if new_binding[1:-1] == "":
             # Handle existential goal with no arguments.
             body = self._parse_into_literal(clause,
                                             params,
                                             is_effect=is_effect)
             return body
         variables = self._parse_objects(new_binding[1:-1])
         for v in variables:
             params[v.name] = v.var_type
         body = self._parse_into_literal(clause,
                                         params,
                                         is_effect=is_effect)
         result = Exists(variables, body)
         for v in variables:
             del params[v.name]
         return result
     if string.startswith("(probabilistic") and string[14] in (" ", "\n",
                                                               "("):
         assert is_effect, "We only support probabilistic effects"
         lits = []
         probs = []
         expr = string[14:-1].strip()
         for match in re.finditer("(\d*\.?\d+)", expr):
             prob = float(match.group())
             subexpr = self._find_balanced_expression(
                 expr[match.end():].strip(), 0)
             lit = self._parse_into_literal(subexpr,
                                            params,
                                            is_effect=is_effect)
             lits.append(lit)
             probs.append(prob)
         return ProbabilisticEffect(lits, probs)
     if string.startswith("(not") and string[4] in (" ", "\n", "("):
         clause = string[4:-1].strip()
         if is_effect:
             return Anti(
                 self._parse_into_literal(clause,
                                          params,
                                          is_effect=is_effect))
         else:
             return Not(
                 self._parse_into_literal(clause,
                                          params,
                                          is_effect=is_effect))
     string = string[1:-1].split()
     pred, args = string[0], string[1:]
     typed_args = []
     # Validate types against the given params dict.
     assert pred in self.predicates, "Predicate {} is not defined".format(
         pred)
     assert self.predicates[pred].arity == len(args), pred
     for i, arg in enumerate(args):
         if arg not in params:
             raise Exception("Argument {} not in params {}".format(
                 arg, params))
         assert arg in params, "Argument {} is not in the params".format(
             arg)
         if isinstance(params, dict):
             typed_arg = TypedEntity(arg, params[arg])
         else:
             typed_arg = params[params.index(arg)]
         typed_args.append(typed_arg)
     return self.predicates[pred](*typed_args)
Esempio n. 9
0
 def _parse_into_literal(self, string, params, is_effect=False):
     """Parse the given string (representing either preconditions or effects)
     into a literal. Check against params to make sure typing is correct.
     """
     assert string[0] == "("
     assert string[-1] == ")"
     if string.startswith("(and") and string[4] in (" ", "\n", "("):
         clauses = self._find_all_balanced_expressions(string[4:-1].strip())
         return LiteralConjunction([
             self._parse_into_literal(clause, params, is_effect=is_effect)
             for clause in clauses
         ])
     if string.startswith("(or") and string[3] in (" ", "\n", "("):
         clauses = self._find_all_balanced_expressions(string[3:-1].strip())
         return LiteralDisjunction([
             self._parse_into_literal(clause, params, is_effect=is_effect)
             for clause in clauses
         ])
     if string.startswith("(forall") and string[7] in (" ", "\n", "("):
         new_binding, clause = self._find_all_balanced_expressions(
             string[7:-1].strip())
         new_name, new_type_name = new_binding.strip()[1:-1].split("-")
         new_name = new_name.strip()
         new_type_name = new_type_name.strip()
         assert new_name not in params, "ForAll variable {} already exists".format(
             new_name)
         params[new_name] = self.types[new_type_name]
         result = ForAll(
             self._parse_into_literal(clause, params, is_effect=is_effect),
             TypedEntity(new_name, params[new_name]))
         del params[new_name]
         return result
     if string.startswith("(exists") and string[7] in (" ", "\n", "("):
         new_binding, clause = self._find_all_balanced_expressions(
             string[7:-1].strip())
         variables = self._parse_objects(new_binding[1:-1])
         for v in variables:
             params[v.name] = v.var_type
         body = self._parse_into_literal(clause,
                                         params,
                                         is_effect=is_effect)
         result = Exists(variables, body)
         for v in variables:
             del params[v.name]
         return result
     if string.startswith("(not") and string[4] in (" ", "\n", "("):
         clause = string[4:-1].strip()
         if is_effect:
             return Anti(
                 self._parse_into_literal(clause,
                                          params,
                                          is_effect=is_effect))
         else:
             return Not(
                 self._parse_into_literal(clause,
                                          params,
                                          is_effect=is_effect))
     string = string[1:-1].split()
     pred, args = string[0], string[1:]
     # Validate types against the given params dict.
     assert pred in self.predicates, "Predicate {} is not defined".format(
         pred)
     assert self.predicates[pred].arity == len(args), pred
     for i, arg in enumerate(args):
         if arg not in params:
             import ipdb
             ipdb.set_trace()
         assert arg in params, "Argument {} is not in the params".format(
             arg)
     return self.predicates[pred](*args)
Esempio n. 10
0
def test_integration6():
    # Minimal noise test
    print("Running integration test 6...")

    training_data = {
        Place: [
            (
                {IsPawn('o1'),
                 IsPawn('o2'),
                 IsPawn('o3'),
                 Holding('o1')},
                Place('o1'),
                {Anti(Holding('o1'))},
            ),
            (
                {IsPawn('o1'),
                 IsPawn('o2'),
                 IsPawn('o3'),
                 Holding('o2')},
                Place('o1'),
                set(),
            ),
            (
                {IsPawn('o1'),
                 IsPawn('o2'),
                 IsPawn('o3'),
                 Holding('o2')},
                Place('o2'),
                {Anti(Holding('o2'))},
            ),
            # repeat
            (
                {IsPawn('o1'),
                 IsPawn('o2'),
                 IsPawn('o3'),
                 Holding('o1')},
                Place('o1'),
                {Anti(Holding('o1'))},
            ),
            (
                {IsPawn('o1'),
                 IsPawn('o2'),
                 IsPawn('o3'),
                 Holding('o2')},
                Place('o1'),
                set(),
            ),
            (
                {IsPawn('o1'),
                 IsPawn('o2'),
                 IsPawn('o3'),
                 Holding('o2')},
                Place('o2'),
                {Anti(Holding('o2'))},
            ),
            # repeat
            (
                {IsPawn('o1'),
                 IsPawn('o2'),
                 IsPawn('o3'),
                 Holding('o1')},
                Place('o1'),
                {Anti(Holding('o1'))},
            ),
            (
                {IsPawn('o1'),
                 IsPawn('o2'),
                 IsPawn('o3'),
                 Holding('o2')},
                Place('o1'),
                set(),
            ),
            (
                {IsPawn('o1'),
                 IsPawn('o2'),
                 IsPawn('o3'),
                 Holding('o2')},
                Place('o2'),
                {Anti(Holding('o2'))},
            ),
            # noise
            (
                {IsPawn('o1'),
                 IsPawn('o2'),
                 IsPawn('o3'),
                 Holding('o1')},
                Place('o1'),
                set(),
            ),
            (
                {IsPawn('o1'),
                 IsPawn('o2'),
                 IsPawn('o3'),
                 Holding('o1')},
                Place('o1'),
                {Anti(Holding('o1')), Anti(IsPawn('o2'))},
            ),
        ]
    }

    test_transitions = [
        (
            {IsPawn('o1'),
             IsPawn('o2'),
             IsPawn('o3'),
             Holding('o3')},
            Place('o3'),
            {Anti(Holding('o3'))},
        ),
        (
            {IsPawn('o1'),
             IsPawn('o2'),
             IsPawn('o3'),
             Holding('o1')},
            Place('o3'),
            set(),
        ),
        (
            {IsPawn('o1'),
             IsPawn('o2'),
             IsPawn('o3'),
             Holding('o3')},
            Place('o1'),
            set(),
        ),
    ]

    return run_integration_test(training_data,
                                test_transitions,
                                expect_deterministic=False)
Esempio n. 11
0
def test_integration5():
    print("Running integration test 5...")

    training_data = {
        TSPMoveTo: [
            ({
                Connected('a', 'b'),
                Connected('b', 'c'),
                Connected('c', 'd'),
                Connected('c', 'b'),
                Connected('d', 'a'),
                Start('a'),
                In('a'),
                Visited('a'),
                Notvisited('b'),
                Notvisited('c'),
                Notvisited('d'),
                Notcomplete('path'),
            }, TSPMoveTo('c'), set()),
            ({
                Connected('a', 'b'),
                Connected('b', 'c'),
                Connected('c', 'd'),
                Connected('c', 'b'),
                Connected('d', 'a'),
                Start('a'),
                In('a'),
                Visited('a'),
                Notvisited('b'),
                Notvisited('c'),
                Notvisited('d'),
                Notcomplete('path'),
            }, TSPMoveTo('b'),
             {Visited('b'),
              In('b'),
              Anti(In('a')),
              Anti(Notvisited('b'))}),
            ({
                Connected('a', 'b'),
                Connected('b', 'c'),
                Connected('c', 'd'),
                Connected('c', 'b'),
                Connected('d', 'a'),
                Start('a'),
                In('b'),
                Visited('a'),
                Visited('b'),
                Notvisited('c'),
                Notvisited('d'),
                Notcomplete('path'),
            }, TSPMoveTo('a'), set()),
            ({
                Connected('a', 'b'),
                Connected('b', 'c'),
                Connected('c', 'd'),
                Connected('c', 'b'),
                Connected('d', 'a'),
                Start('a'),
                In('b'),
                Visited('a'),
                Visited('b'),
                Notvisited('c'),
                Notvisited('d'),
                Notcomplete('path'),
            }, TSPMoveTo('c'),
             {Visited('c'),
              In('c'),
              Anti(In('b')),
              Anti(Notvisited('c'))}),
            ({
                Connected('a', 'b'),
                Connected('b', 'c'),
                Connected('c', 'd'),
                Connected('c', 'b'),
                Connected('d', 'a'),
                Start('a'),
                In('b'),
                Visited('a'),
                Visited('b'),
                Visited('c'),
                Notvisited('d'),
                Notcomplete('path'),
            }, TSPMoveTo('b'), set()),
            # this is a crucial example!
            ({
                Connected('a', 'b'),
                Connected('b', 'c'),
                Connected('c', 'd'),
                Connected('c', 'b'),
                Connected('d', 'a'),
                Start('a'),
                In('c'),
                Visited('a'),
                Visited('b'),
                Visited('c'),
                Notvisited('d'),
                Notcomplete('path'),
            }, TSPMoveTo('b'), set()),
            ({
                Connected('a', 'b'),
                Connected('b', 'c'),
                Connected('c', 'd'),
                Connected('c', 'b'),
                Connected('d', 'a'),
                Start('a'),
                In('d'),
                Visited('a'),
                Visited('b'),
                Visited('c'),
                Visited('d'),
                Notcomplete('path'),
            }, TSPMoveTo('a'), {
                In('a'),
                Anti(In('d')),
                Anti(Notcomplete('path')),
                Complete('path')
            }),
            # different graph
            ({
                Connected('a', 'b'),
                Connected('b', 'c'),
                Connected('c', 'd'),
                Connected('d', 'c'),
                Connected('c', 'e'),
                Connected('e', 'f'),
                Connected('f', 'a'),
                Start('a'),
                In('a'),
                Visited('a'),
                Notvisited('b'),
                Notvisited('c'),
                Notvisited('d'),
                Notvisited('e'),
                Notvisited('f'),
                Notcomplete('path'),
            }, TSPMoveTo('d'), set()),
            ({
                Connected('a', 'b'),
                Connected('b', 'c'),
                Connected('c', 'd'),
                Connected('d', 'c'),
                Connected('c', 'e'),
                Connected('e', 'f'),
                Connected('f', 'a'),
                Start('a'),
                In('a'),
                Visited('a'),
                Notvisited('b'),
                Notvisited('c'),
                Notvisited('d'),
                Notvisited('e'),
                Notvisited('f'),
                Notcomplete('path'),
            }, TSPMoveTo('b'),
             {Visited('b'),
              In('b'),
              Anti(In('a')),
              Anti(Notvisited('b'))}),
            ({
                Connected('a', 'b'),
                Connected('b', 'c'),
                Connected('c', 'd'),
                Connected('d', 'c'),
                Connected('c', 'e'),
                Connected('e', 'f'),
                Connected('f', 'a'),
                Start('a'),
                In('c'),
                Visited('a'),
                Visited('b'),
                Visited('c'),
                Notvisited('d'),
                Notvisited('e'),
                Notvisited('f'),
                Notcomplete('path'),
            }, TSPMoveTo('e'),
             {Visited('e'),
              In('e'),
              Anti(In('c')),
              Anti(Notvisited('e'))}),
            ({
                Connected('a', 'b'),
                Connected('b', 'c'),
                Connected('c', 'd'),
                Connected('d', 'c'),
                Connected('c', 'e'),
                Connected('e', 'f'),
                Connected('f', 'a'),
                Start('a'),
                In('f'),
                Visited('a'),
                Visited('b'),
                Visited('c'),
                Notvisited('d'),
                Visited('e'),
                Visited('f'),
                Notcomplete('path'),
            }, TSPMoveTo('d'), set()),
            # crucial example
            ({
                Connected('a', 'b'),
                Connected('b', 'c'),
                Connected('c', 'd'),
                Connected('d', 'c'),
                Connected('c', 'e'),
                Connected('e', 'f'),
                Connected('f', 'a'),
                Start('a'),
                In('d'),
                Visited('a'),
                Visited('b'),
                Visited('c'),
                Visited('d'),
                Notvisited('e'),
                Notvisited('f'),
                Notcomplete('path'),
            }, TSPMoveTo('c'), set()),
            ({
                Connected('a', 'b'),
                Connected('b', 'c'),
                Connected('c', 'd'),
                Connected('d', 'c'),
                Connected('c', 'e'),
                Connected('e', 'f'),
                Connected('f', 'a'),
                Start('a'),
                In('f'),
                Visited('a'),
                Visited('b'),
                Visited('c'),
                Notvisited('d'),
                Visited('e'),
                Visited('f'),
                Notcomplete('path'),
            }, TSPMoveTo('c'), set()),
            ({
                Connected('a', 'b'),
                Connected('b', 'c'),
                Connected('c', 'd'),
                Connected('d', 'c'),
                Connected('c', 'e'),
                Connected('e', 'f'),
                Connected('f', 'a'),
                Start('a'),
                In('f'),
                Visited('a'),
                Visited('b'),
                Visited('c'),
                Notvisited('d'),
                Visited('e'),
                Visited('f'),
                Notcomplete('path'),
            }, TSPMoveTo('a'), {
                In('a'),
                Anti(In('f')),
                Anti(Notcomplete('path')),
                Complete('path')
            }),
            # different graph
            ({
                Connected('a', 'b'),
                Start('a'),
                In('a'),
                Visited('a'),
                Notvisited('b'),
                Notcomplete('path'),
            }, TSPMoveTo('a'), set()),
            ({
                Connected('a', 'b'),
                Start('a'),
                In('a'),
                Visited('a'),
                Notvisited('b'),
                Notcomplete('path'),
            }, TSPMoveTo('b'),
             {In('b'),
              Anti(In('a')),
              Visited('b'),
              Anti(Notvisited('b'))}),
        ],
    }

    # todo
    test_transitions = []

    return run_integration_test(training_data, test_transitions)
Esempio n. 12
0
 def create_ndr():
     action = Act0()
     preconditions = [Red("?x"), HandsFree0()]
     effect_probs = [0.8, 0.2]
     effects = [{Anti(HandsFree0())}, {NOISE_OUTCOME}]
     return NDR(action, preconditions, effect_probs, effects)
Esempio n. 13
0
def test_integration4():
    print("Running integration test 4...")

    training_data = {
        Pick: [
            ({
                IsPawn('o1'),
                IsPawn('o2'),
                IsRobot('robot'),
                At('o1', 'loc1'),
                At('o2', 'loc2'),
                At('robot', 'loc1'),
                HandsFree('robot'),
            }, Pick('o1'),
             {Holding('o1'),
              Anti(At('o1', 'loc1')),
              Anti(HandsFree('robot'))}),
            ({
                IsPawn('o1'),
                IsPawn('o2'),
                IsRobot('robot'),
                At('o1', 'loc1'),
                At('o2', 'loc2'),
                At('robot', 'loc1'),
                HandsFree('robot'),
            }, Pick('o2'), set()),
            ({
                IsPawn('o1'),
                IsPawn('o2'),
                IsRobot('robot'),
                At('o1', 'loc1'),
                At('o2', 'loc2'),
                At('robot', 'loc2'),
                HandsFree('robot'),
            }, Pick('o2'),
             {Holding('o2'),
              Anti(At('o2', 'loc2')),
              Anti(HandsFree('robot'))}),
            ({
                IsPawn('o1'),
                IsPawn('o2'),
                IsRobot('robot'),
                At('o1', 'loc1'),
                At('o2', 'loc2'),
                At('robot', 'loc2'),
                HandsFree('robot'),
            }, Pick('o1'), set()),
            ({
                IsPawn('o1'),
                IsPawn('o2'),
                IsRobot('robot'),
                At('o1', 'loc1'),
                At('o2', 'loc2'),
                At('robot', 'loc2'),
                HandsFree('robot'),
            }, Pick('robot'), set()),
            # Identical to above, but with monkeys instead of pawns
            ({
                IsMonkey('o1'),
                IsMonkey('o2'),
                IsRobot('robot'),
                At('o1', 'loc1'),
                At('o2', 'loc2'),
                At('robot', 'loc1'),
                HandsFree('robot'),
            }, Pick('o1'),
             {Holding('o1'),
              Anti(At('o1', 'loc1')),
              Anti(HandsFree('robot'))}),
            ({
                IsMonkey('o1'),
                IsMonkey('o2'),
                IsRobot('robot'),
                At('o1', 'loc1'),
                At('o2', 'loc2'),
                At('robot', 'loc1'),
                HandsFree('robot'),
            }, Pick('o2'), set()),
            ({
                IsMonkey('o1'),
                IsMonkey('o2'),
                IsRobot('robot'),
                At('o1', 'loc1'),
                At('o2', 'loc2'),
                At('robot', 'loc2'),
                HandsFree('robot'),
            }, Pick('o2'),
             {Holding('o2'),
              Anti(At('o2', 'loc2')),
              Anti(HandsFree('robot'))}),
            ({
                IsMonkey('o1'),
                IsMonkey('o2'),
                IsRobot('robot'),
                At('o1', 'loc1'),
                At('o2', 'loc2'),
                At('robot', 'loc2'),
                HandsFree('robot'),
            }, Pick('o1'), set()),
            ({
                IsMonkey('o1'),
                IsMonkey('o2'),
                IsRobot('robot'),
                At('o1', 'loc1'),
                At('o2', 'loc2'),
                At('robot', 'loc2'),
                HandsFree('robot'),
            }, Pick('robot'), set()),
        ],
    }

    test_transitions = [
        ({
            IsPawn('o1'),
            IsPawn('o2'),
            IsRobot('robot'),
            At('o1', 'loc1'),
            At('o2', 'loc1'),
            At('robot', 'loc1'),
            HandsFree('robot'),
        }, Pick('o1'),
         {Holding('o1'),
          Anti(At('o1', 'loc1')),
          Anti(HandsFree('robot'))}),
        ({
            IsPawn('o1'),
            IsPawn('o2'),
            At('o1', 'loc1'),
            At('o2', 'loc2'),
            At('robot', 'loc1'),
            HandsFree('robot'),
        }, Pick('o2'), set()),
        ({
            IsPawn('o1'),
            IsPawn('o2'),
            IsRobot('robot'),
            At('o1', 'loc1'),
            At('o2', 'loc1'),
            At('robot', 'loc1'),
            HandsFree('robot'),
        }, Pick('robot'), set()),
    ]

    return run_integration_test(training_data, test_transitions)
Esempio n. 14
0
def test_integration3():
    print("Running integration test 3...")

    training_data = {
        Pick: [
            ({
                IsPawn('o1'),
                IsPawn('o2'),
                IsRobot('robot'),
                At('o1', 'loc1'),
                At('o2', 'loc2'),
                At('robot', 'loc1'),
                HandsFree0(),
            }, Pick('o1'),
             {Holding('o1'),
              Anti(At('o1', 'loc1')),
              Anti(HandsFree0())}),
            ({
                IsPawn('o1'),
                IsPawn('o2'),
                IsRobot('robot'),
                At('o1', 'loc1'),
                At('o2', 'loc2'),
                At('robot', 'loc1'),
                HandsFree0(),
            }, Pick('o2'), set()),
            ({
                IsPawn('o1'),
                IsPawn('o2'),
                IsRobot('robot'),
                At('o1', 'loc1'),
                At('o2', 'loc2'),
                At('robot', 'loc2'),
                HandsFree0(),
            }, Pick('o2'),
             {Holding('o2'),
              Anti(At('o2', 'loc2')),
              Anti(HandsFree0())}),
            ({
                IsPawn('o1'),
                IsPawn('o2'),
                IsRobot('robot'),
                At('o1', 'loc2'),
                At('o2', 'loc2'),
                At('robot', 'loc2'),
                HandsFree0(),
            }, Pick('o2'),
             {Holding('o2'),
              Anti(At('o2', 'loc2')),
              Anti(HandsFree0())}),
            ({
                IsPawn('o1'),
                IsPawn('o2'),
                IsRobot('robot'),
                At('o1', 'loc1'),
                At('o2', 'loc2'),
                At('robot', 'loc2'),
                HandsFree0(),
            }, Pick('o1'), set()),
            ({
                IsPawn('o1'),
                IsPawn('o2'),
                IsRobot('robot'),
                At('o1', 'loc1'),
                At('o2', 'loc2'),
                At('robot', 'loc2'),
                Holding('o3'),
            }, Pick('o2'), set()),
        ],
    }

    test_transitions = [
        ({
            IsPawn('o1'),
            IsPawn('o2'),
            IsRobot('robot'),
            At('o1', 'loc1'),
            At('o2', 'loc1'),
            At('robot', 'loc1'),
            HandsFree0(),
        }, Pick('o1'),
         {Holding('o1'),
          Anti(At('o1', 'loc1')),
          Anti(HandsFree0())}),
        ({
            IsPawn('o1'),
            IsPawn('o2'),
            At('o1', 'loc1'),
            At('o2', 'loc1'),
            At('robot', 'loc1'),
            HandsFree0(),
        }, Pick('o1'), set()),
    ]

    return run_integration_test(training_data, test_transitions)
Esempio n. 15
0
def test_integration2():
    """It was important to add TrimObjects for this test to pass
    """
    print("Running integration test 2...")

    training_data = {
        MoveTo: [
            (
                {
                    At('robot', 'loc1'),
                    At('o1', 'loc2'),
                    IsMonkey('m1'),
                    IsRobot('robot'),
                    IsPawn('o1')
                },
                MoveTo('loc2'),
                {Anti(At('robot', 'loc1')),
                 At('robot', 'loc2')},
            ),
            (
                {
                    At('robot', 'loc1'),
                    At('o1', 'loc2'),
                    At('m1', 'loc1'),
                    IsMonkey('m1'),
                    IsRobot('robot'),
                    IsPawn('o1')
                },
                MoveTo('loc1'),
                set(),
            ),
            (
                {
                    At('robot', 'loc1'),
                    At('o1', 'loc2'),
                    At('m1', 'loc1'),
                    At('o1', 'loc3'),
                    IsMonkey('m1'),
                    IsRobot('robot'),
                    IsPawn('o1')
                },
                MoveTo('loc3'),
                {Anti(At('robot', 'loc1')),
                 At('robot', 'loc3')},
            ),
            (
                {
                    At('robot', 'loc1'),
                    At('o1', 'loc2'),
                    At('m1', 'loc1'),
                    At('o1', 'loc3'),
                    IsMonkey('m1'),
                    IsRobot('robot'),
                    IsMonkey('o1')
                },
                MoveTo('loc3'),
                {Anti(At('robot', 'loc1')),
                 At('robot', 'loc3')},
            ),
            (
                {
                    At('robot', 'loc1'),
                    At('o1', 'loc2'),
                    At('m1', 'loc1'),
                    At('o1', 'loc3'),
                    IsPawn('m1'),
                    IsRobot('robot'),
                    IsPawn('o1')
                },
                MoveTo('loc3'),
                {Anti(At('robot', 'loc1')),
                 At('robot', 'loc3')},
            ),
        ]
    }

    test_transitions = [
        (
            {At('robot', 'loc1'),
             At('o1', 'loc4'),
             IsRobot('robot')},
            MoveTo('loc4'),
            {Anti(At('robot', 'loc1')),
             At('robot', 'loc4')},
        ),
        (
            {At('robot', 'loc1'), At('o1', 'loc4')},
            MoveTo('loc4'),
            set(),
        ),
        (
            {At('m1', 'loc1'),
             At('o1', 'loc4'),
             IsMonkey('m1')},
            MoveTo('loc4'),
            set(),
        ),
    ]

    return run_integration_test(training_data, test_transitions)
Esempio n. 16
0
def test_integration7():
    # Noisy puton test
    print("Running integration test 7...")

    training_data = {
        PutOn: [
            (
                {IsPawn('o1'),
                 IsPawn('o2'),
                 IsPawn('o3'),
                 Holding('o1')},
                PutOn('o2'),
                {Anti(Holding('o1')), On('o1', 'o2')},
            ),
            (
                {IsPawn('o1'),
                 IsPawn('o2'),
                 IsPawn('o3'),
                 Holding('o1')},
                PutOn('o3'),
                {Anti(Holding('o1')), On('o1', 'o3')},
            ),
            (
                {
                    IsPawn('o1'),
                    IsPawn('o2'),
                    IsPawn('o3'),
                    Holding('o1'),
                    On('o2', 'o3')
                },
                PutOn('o2'),
                {Anti(Holding('o1')), On('o1', 'o2')},
            ),
            (
                {
                    IsPawn('o1'),
                    IsPawn('o2'),
                    IsPawn('o3'),
                    Holding('o1'),
                    On('o2', 'o3')
                },
                PutOn('o3'),
                {Anti(Holding('o1')), On('o1', 'o2')},
            ),
            # this is an important one
            (
                {
                    IsPawn('o1'),
                    IsPawn('o2'),
                    IsPawn('o3'),
                    Holding('o1'),
                    On('o2', 'o3')
                },
                PutOn('o3'),
                {Anti(Holding('o1'))},
            ),
            (
                {IsPawn('o1'),
                 IsPawn('o2'),
                 IsPawn('o3'),
                 Holding('o1')},
                PutOn('o1'),
                set(),
            ),
            (
                {IsPawn('o1'),
                 IsPawn('o2'),
                 IsPawn('o3'),
                 Holding('o1')},
                PutOn('o1'),
                {Anti(Holding('o1'))},
            ),
            (
                {IsPawn('o1'),
                 IsPawn('o2'),
                 IsPawn('o3'),
                 Holding('o1')},
                PutOn('o1'),
                {Anti(Holding('o1')), On('o1', 'o3')},
            ),
            (
                {IsPawn('o1'), IsPawn('o2'),
                 IsPawn('o3')},
                PutOn('o2'),
                set(),
            ),
        ]
    }

    test_transitions = [
        (
            {IsPawn('o1'),
             IsPawn('o2'),
             IsPawn('o3'),
             Holding('o2')},
            PutOn('o1'),
            {Anti(Holding('o2')), On('o2', 'o1')},
        ),
        (
            {
                IsPawn('o1'),
                IsPawn('o2'),
                IsPawn('o3'),
                Holding('o2'),
                On('o1', 'o3')
            },
            PutOn('o1'),
            {Anti(Holding('o2')), On('o2', 'o1')},
        ),
        (
            {
                IsPawn('o1'),
                IsPawn('o2'),
                IsPawn('o3'),
                Holding('o1'),
                On('o2', 'o3')
            },
            PutOn('o3'),
            {Anti(Holding('o1'))},
        ),
    ]

    return run_integration_test(training_data,
                                test_transitions,
                                expect_deterministic=False)