コード例 #1
0
 def check_statement_condition_accepts_value(self, statement_type: type):
     condition = Condition(False)
     statement = statement_type(action="",
                                effect=Condition(False),
                                condition=condition,
                                duration=2)
     self.assertEqual(statement.condition, condition)
コード例 #2
0
 def test_conditional_releases(self):
     statement = parsing.statement.parse(
         "Use releases broken if unlucky by lol")
     broken, unlucky = sympy.symbols("broken,unlucky")
     self.assertEqual(
         Releases(action="Use",
                  effect=Condition(broken),
                  condition=Condition(unlucky),
                  agent="lol"), statement)
コード例 #3
0
 def test_conditional_causes(self):
     statement = parsing.statement.parse(
         "Charge causes charged if plugged_in by Teddy")
     charged, plugged_in = sympy.symbols("charged,plugged_in")
     self.assertEqual(
         Causes(action="Charge",
                effect=Condition(charged),
                condition=Condition(plugged_in),
                agent="Teddy"), statement)
コード例 #4
0
 def test_conditional_releases(self):
     statement = parsing.statement.parse(
         "Use releases broken if unlucky during 14")
     broken, unlucky = sympy.symbols("broken,unlucky")
     self.assertEqual(
         statement,
         Releases(action="Use",
                  effect=Condition(broken),
                  condition=Condition(unlucky),
                  duration=14))
コード例 #5
0
 def test_conditional_causes(self):
     statement = parsing.statement.parse(
         "Charge causes charged if plugged_in during 6")
     charged, plugged_in = sympy.symbols("charged,plugged_in")
     self.assertEqual(
         statement,
         Causes(action="Charge",
                effect=Condition(charged),
                condition=Condition(plugged_in),
                duration=6))
コード例 #6
0
 def join_statement_by_and(self, statement1: Statement,
                           statement2: Statement,
                           is_causes: bool) -> Statement:
     if is_causes:
         return Causes(action=statement1.action,
                       effect=Condition(
                           And(statement1.effect.formula,
                               statement2.effect.formula)),
                       duration=statement1.duration)
     else:
         return Releases(action=statement1.action,
                         effect=Condition(
                             And(statement1.effect.formula,
                                 statement2.effect.formula)),
                         duration=statement1.duration)
コード例 #7
0
 def create_tautology_from_statements(self, statement1: Statement,
                                      statement2: Statement) -> Statement:
     return Releases(action=statement1.action,
                     effect=Condition(
                         Or(statement1.effect.formula,
                            Not(statement2.effect.formula))),
                     duration=statement1.duration,
                     agent=statement1.agent)
コード例 #8
0
ファイル: test_scenario.py プロジェクト: vozhyk-/krar-project
    def test_test(self):
        scenario = parsing.scenario.parse_file("example/scenario.txt")

        self.assertEqual(len(scenario.observations), 2)

        alive, loaded, hidden = sympy.symbols("alive,loaded,hidden")
        self.assertEqual(scenario.observations[0], Observation(
            begin_time=0,
            condition=Condition(alive & ~loaded & hidden)))
        self.assertEqual(scenario.observations[1], Observation(
            begin_time=2,
            condition=Condition(alive & ~loaded & ~hidden)))

        self.assertEqual(len(scenario.action_occurrences), 2)
        self.assertEqual(scenario.action_occurrences[0],
                         ActionOccurrence(name="Load", begin_time=1, duration=2))
        self.assertEqual(scenario.action_occurrences[1],
                         ActionOccurrence(name="Shoot", begin_time=3, duration=1))
コード例 #9
0
    def test_parse_example(self):
        description = parsing.domain_description.parse_file("example/lib.adl3")

        self.assertEqual(len(description.statements), 5)

        alive, loaded, hidden = sympy.symbols("alive,loaded,hidden")
        self.assertTrue(isinstance(description.statements[0], Releases))
        self.assertEqual(
            description.statements[0],
            Releases(action="Load", effect=Condition(loaded), duration=2))
        self.assertTrue(isinstance(description.statements[1], Releases))
        self.assertEqual(
            description.statements[1],
            Releases(action="Load", effect=Condition(~hidden), duration=1))
        self.assertTrue(isinstance(description.statements[2], Causes))
        self.assertEqual(
            description.statements[2],
            Causes(action="Shoot", effect=Condition(~loaded), duration=1))
        self.assertTrue(isinstance(description.statements[3], Causes))
        self.assertEqual(
            description.statements[3],
            Causes(action="Shoot",
                   effect=Condition(~alive),
                   condition=Condition(~hidden & loaded),
                   duration=1))
        self.assertTrue(isinstance(description.statements[4], ImpossibleIf))
        self.assertEqual(
            description.statements[4],
            ImpossibleIf(action="Shoot", condition=Condition(~loaded)))
コード例 #10
0
    def test_parse_example(self):
        os.chdir(os.path.dirname(os.path.abspath(__file__)))
        description = parsing.domain_description.parse_file(
            "../example/lib.adl3")

        self.assertEqual(len(description.statements), 5)

        alive, loaded, hidden = sympy.symbols("alive,loaded,hidden")
        #####
        self.assertTrue(isinstance(description.statements[0], Causes))
        self.assertEqual(
            Causes(action="load", effect=Condition(loaded), agent="hunter"),
            description.statements[0])
        #####
        self.assertTrue(isinstance(description.statements[1], Causes))
        self.assertEqual(
            Causes(action="shoot", effect=Condition(~loaded), agent="hunter"),
            description.statements[1])
        #####
        self.assertTrue(isinstance(description.statements[2], Causes))
        self.assertEqual(
            Causes(action="shoot",
                   effect=Condition(~alive),
                   condition=Condition(loaded & ~hidden),
                   agent="hunter"), description.statements[2])
        #####
        self.assertTrue(isinstance(description.statements[3], Releases))
        self.assertEqual(
            Releases(action="escape", effect=Condition(hidden),
                     agent="turkey"), description.statements[3])
        #####
        self.assertTrue(isinstance(description.statements[4], Triggers))
        self.assertEqual(
            Triggers(action="escape", condition=Condition(loaded)),
            description.statements[4])
コード例 #11
0
 def test_unconditional_releases(self):
     statement = parsing.statement.parse("Use releases broken during 14")
     broken = sympy.symbols("broken")
     self.assertEqual(
         statement,
         Releases(action="Use", effect=Condition(broken), duration=14))
コード例 #12
0
def parse(input: str) -> Condition:
    return Condition(sympy_parser.parse_expr(input))
コード例 #13
0
ファイル: condition.py プロジェクト: matrackif/krar-project
def parse(input: str) -> Union[Condition, bool]:
    if input is None:
        return True
    return Condition(sympy_parser.parse_expr(input))
コード例 #14
0
 def test_triggers(self):
     statement = parsing.statement.parse("detonate triggers explosion")
     detonate = sympy.symbols("detonate")
     self.assertEqual(
         Triggers(action="explosion", condition=Condition(detonate)),
         statement)
コード例 #15
0
 def test_unconditional_releases(self):
     statement = parsing.statement.parse("Use releases broken by lol")
     broken = sympy.symbols("broken")
     self.assertEqual(
         Releases(action="Use", effect=Condition(broken), agent="lol"),
         statement)
コード例 #16
0
 def test_unconditional_causes(self):
     statement = parsing.statement.parse("Charge causes charged during 6")
     charged = sympy.symbols("charged")
     self.assertEqual(
         statement,
         Causes(action="Charge", effect=Condition(charged), duration=6))
コード例 #17
0
 def test_unconditional_causes(self):
     statement = parsing.statement.parse("Charge causes charged by Kuba")
     charged = sympy.symbols("charged")
     self.assertEqual(
         Causes(action="Charge", effect=Condition(charged), agent="Kuba"),
         statement)
コード例 #18
0
 def check_statement_condition_defaults_to_true(self, statement_type: type):
     statement = statement_type(action="",
                                effect=Condition(False),
                                duration=2)
     self.assertEqual(statement.condition, True)