예제 #1
0
    def testComposePlan1CaseNoInputs(self):
        tbcbp = TBCBP()
        s1 = Service(P=["P(P1)", "P(P2)"], Q=["Q(Q1)"], inputs=["i1"], outputs=["o1"], name="s1")
        tbcbp.registerService(s1)

        kb0 = KB()
        kb0.tell("P(P1)")
        kb0.tell("P(P2)")
        # Missing kb0.set("i1", 1024)

        g = Goal("Q(Q1)")

        plan = tbcbp.composePlan(Goal=g, kb=kb0)

        assert plan is None
예제 #2
0
    def testPlanMatchesInKB(self):
        tbcbp = TBCBP()
        case1 = Case(P=["P(P1)", "P(P2)"], Q=["Q(Q1)", "Q(Q2)"], inputs=["i1"], outputs=["o1"], services=["s1"])
        kb0 = KB()
        kb0.tell("P(P1)")
        kb0.tell("P(P2)")
        kb0.set("i1", 1024)

        self.assertTrue(tbcbp.planMatchesInKB(case1, kb0))

        case2 = Case(P=["P(P3)", "P(P2)"], Q=["q1", "q2"], inputs=["i1"], outputs=["o1"], services=["s1"])
        self.assertFalse(tbcbp.planMatchesInKB(case2, kb0))

        case3 = Case(P=["P(P1)", "P(P2)"], Q=["q1", "q2"], inputs=["i2"], outputs=["o1"], services=["s1"])
        self.assertFalse(tbcbp.planMatchesInKB(case3, kb0))
예제 #3
0
    def testComposePlan1Case(self):
        tbcbp = TBCBP()
        s1 = Service(P=["P(P1)", "P(P2)"], Q=["Q(Q1)"], inputs=["i1"], outputs=["o1"], name="s1")
        tbcbp.registerService(s1)

        kb0 = KB()
        kb0.tell("P(P1)")
        kb0.tell("P(P2)")
        kb0.set("i1", 1024)

        g = Goal("Q(Q1)")

        plan = tbcbp.composePlan(Goal=g, kb=kb0)

        assert plan is not None
        assert plan.getQ() == ["Q(Q1)"]
        assert plan.getP() == ["P(P1)", "P(P2)"]
        assert len(plan) == 1
예제 #4
0
    def testComposePlanNoCases(self):
        tbcbp = TBCBP()
        kb0 = KB()

        g = Goal("Q(Q1)")

        plan = tbcbp.composePlan(Goal=g, kb=kb0)

        assert plan is None
예제 #5
0
    def testComposePlan1CaseNoInputs(self):
        tbcbp = TBCBP()
        s1 = Service(P=["P(P1)", "P(P2)"],
                     Q=["Q(Q1)"],
                     inputs=["i1"],
                     outputs=["o1"],
                     name="s1")
        tbcbp.registerService(s1)

        kb0 = KB()
        kb0.tell("P(P1)")
        kb0.tell("P(P2)")
        #Missing kb0.set("i1", 1024)

        g = Goal("Q(Q1)")

        plan = tbcbp.composePlan(Goal=g, kb=kb0)

        assert plan is None
예제 #6
0
    def testComposePlanBestQoS(self):
        tbcbp = TBCBP()
        s1 = Service(P=["P(P1)", "P(P2)"],
                     Q=["Q(Q1)", "Q(Q2)"],
                     inputs=["i1"],
                     outputs=["o1"],
                     name="s1")
        s2 = Service(P=["P(P3)", "P(P4)"],
                     Q=["Q(Q3)"],
                     inputs=["o1"],
                     outputs=["o2"],
                     name="s2")
        s3 = Service(P=["P(P3)", "P(P4)"],
                     Q=["Q(Q3)"],
                     inputs=["o1"],
                     outputs=["o2"],
                     name="s3")

        tbcbp.registerService(s1, time=1, QoS=1)
        tbcbp.registerService(s2, time=1, QoS=1)
        tbcbp.registerService(s3, time=1, QoS=100)

        kb0 = KB()
        kb0.tell("P(P1)")
        kb0.tell("P(P2)")
        kb0.set("i1", 1024)

        g = Goal("Q(Q3)")

        plan = tbcbp.composePlan(Goal=g, kb=kb0, use_rl=False)

        for s in plan.getServices():
            assert s in ["s1", "s3"]
            assert s != "s2"
예제 #7
0
    def testComposePlan2Cases(self):
        tbcbp = TBCBP()
        s1 = Service(P=["P(P1)", "P(P2)"],
                     Q=["Q(Q1)", "Q(Q2)"],
                     inputs=["i1"],
                     outputs=["o1"],
                     name="s1")
        s2 = Service(P=["P(P3)", "P(P4)"],
                     Q=["Q(Q3)"],
                     inputs=["o1"],
                     outputs=["o2"],
                     name="s2")
        tbcbp.registerService(s1)
        tbcbp.registerService(s2)

        kb0 = KB()
        kb0.tell("P(P1)")
        kb0.tell("P(P2)")
        kb0.set("i1", 1024)

        g = Goal("Q(Q3)")

        plan = tbcbp.composePlan(Goal=g, kb=kb0)

        assert plan is not None
        assert plan.getQ() == ["Q(Q3)"]
        assert plan.getP() == ["P(P1)", "P(P2)"]
        assert len(plan) == 2
예제 #8
0
    def testPlanMatchesInKB(self):
        tbcbp = TBCBP()
        case1 = Case(P=["P(P1)", "P(P2)"],
                     Q=["Q(Q1)", "Q(Q2)"],
                     inputs=["i1"],
                     outputs=["o1"],
                     services=["s1"])
        kb0 = KB()
        kb0.tell("P(P1)")
        kb0.tell("P(P2)")
        kb0.set("i1", 1024)

        self.assertTrue(tbcbp.planMatchesInKB(case1, kb0))

        case2 = Case(P=["P(P3)", "P(P2)"],
                     Q=["q1", "q2"],
                     inputs=["i1"],
                     outputs=["o1"],
                     services=["s1"])
        self.assertFalse(tbcbp.planMatchesInKB(case2, kb0))

        case3 = Case(P=["P(P1)", "P(P2)"],
                     Q=["q1", "q2"],
                     inputs=["i2"],
                     outputs=["o1"],
                     services=["s1"])
        self.assertFalse(tbcbp.planMatchesInKB(case3, kb0))
예제 #9
0
    def testComposePlanBestQoS(self):
        tbcbp = TBCBP()
        s1 = Service(P=["P(P1)", "P(P2)"], Q=["Q(Q1)", "Q(Q2)"], inputs=["i1"], outputs=["o1"], name="s1")
        s2 = Service(P=["P(P3)", "P(P4)"], Q=["Q(Q3)"], inputs=["o1"], outputs=["o2"], name="s2")
        s3 = Service(P=["P(P3)", "P(P4)"], Q=["Q(Q3)"], inputs=["o1"], outputs=["o2"], name="s3")

        tbcbp.registerService(s1, time=1, QoS=1)
        tbcbp.registerService(s2, time=1, QoS=1)
        tbcbp.registerService(s3, time=1, QoS=100)

        kb0 = KB()
        kb0.tell("P(P1)")
        kb0.tell("P(P2)")
        kb0.set("i1", 1024)

        g = Goal("Q(Q3)")

        plan = tbcbp.composePlan(Goal=g, kb=kb0, use_rl=False)

        for s in plan.getServices():
            assert s in ["s1", "s3"]
            assert s != "s2"
예제 #10
0
    def setUp(self):

        self.kb = KB()
예제 #11
0
class factsTestCase(unittest.TestCase):

    def setUp(self):

        self.kb = KB()

    def tearDown(self):
        pass

    def testInteger(self):
        self.kb.set("varname1", 1234)
        var = self.kb.get("varname1")
        assert var == 1234
        assert isinstance(var, types.IntType)

    def testString(self):
        self.kb.set("varname2", "TestString")
        var = self.kb.get("varname2")
        assert var == "teststring"
        assert isinstance(var, types.StringType)

    def testFloat(self):
        self.kb.set("varname3", 1234.5678)
        var = self.kb.get("varname3")
        assert var == 1234.5678
        assert isinstance(var, types.FloatType)

    def testList(self):
        self.kb.set("varname4", [1, 2, 3, 4])
        var = self.kb.get("varname4")
        assert var == [1, 2, 3, 4]
        assert isinstance(var, types.ListType)

    def testListWithMultipleTypes(self):
        self.kb.set("varname5", [1, 2, 3.4, "5", [6, 7]])
        var = self.kb.get("varname5")
        assert var == [1, 2, 3.4, "5", [6, 7]]
        assert isinstance(var, types.ListType)

    def testDict(self):
        self.kb.set("varname6", {'a': 123, 'b': 456, 789: "c"})
        var = self.kb.get("varname6")
        assert var == {'a': 123, 'b': 456, 789: "c"}
        assert isinstance(var, types.DictType)

    def testDictWithComplexTypes(self):
        self.kb.set("varname7", {'a': [123.25], 'b': [4, 5, 6], 789: {'a': 1, 'b': 2}})
        var = self.kb.get("varname7")
        assert var == {'a': [123.25], 'b': [4, 5, 6], 789: {'a': 1, 'b': 2}}
        assert isinstance(var, types.DictType)

    def testKeyNotString(self):
        self.assertRaises(KBNameNotString, self.kb.set, 123, "newvalue")

    def testValueNotKnown(self):
        class A:
            pass
        self.assertRaises(KBValueNotKnown, self.kb.set, "varname8", A())
예제 #12
0
    def setUp(self):

        self.kb = KB()
예제 #13
0
class factsTestCase(unittest.TestCase):
    def setUp(self):

        self.kb = KB()

    def tearDown(self):
        pass

    def testInteger(self):
        self.kb.set("varname1", 1234)
        var = self.kb.get("varname1")
        assert var == 1234
        assert isinstance(var, types.IntType)

    def testString(self):
        self.kb.set("varname2", "TestString")
        var = self.kb.get("varname2")
        assert var == "teststring"
        assert isinstance(var, types.StringType)

    def testFloat(self):
        self.kb.set("varname3", 1234.5678)
        var = self.kb.get("varname3")
        assert var == 1234.5678
        assert isinstance(var, types.FloatType)

    def testList(self):
        self.kb.set("varname4", [1, 2, 3, 4])
        var = self.kb.get("varname4")
        assert var == [1, 2, 3, 4]
        assert isinstance(var, types.ListType)

    def testListWithMultipleTypes(self):
        self.kb.set("varname5", [1, 2, 3.4, "5", [6, 7]])
        var = self.kb.get("varname5")
        assert var == [1, 2, 3.4, "5", [6, 7]]
        assert isinstance(var, types.ListType)

    def testDict(self):
        self.kb.set("varname6", {'a': 123, 'b': 456, 789: "c"})
        var = self.kb.get("varname6")
        assert var == {'a': 123, 'b': 456, 789: "c"}
        assert isinstance(var, types.DictType)

    def testDictWithComplexTypes(self):
        self.kb.set("varname7", {
            'a': [123.25],
            'b': [4, 5, 6],
            789: {
                'a': 1,
                'b': 2
            }
        })
        var = self.kb.get("varname7")
        assert var == {'a': [123.25], 'b': [4, 5, 6], 789: {'a': 1, 'b': 2}}
        assert isinstance(var, types.DictType)

    def testKeyNotString(self):
        self.assertRaises(KBNameNotString, self.kb.set, 123, "newvalue")

    def testValueNotKnown(self):
        class A:
            pass

        self.assertRaises(KBValueNotKnown, self.kb.set, "varname8", A())