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"
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
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))
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
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
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