Beispiel #1
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"
Beispiel #2
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
Beispiel #3
0
 def services(self):
     import sys
     import time
     servername = self.getDomain()
     platform = self.getName()
     version = str(sys.version)
     the_time = str(time.ctime())
     try:
         search = self.searchService(DfAgentDescription())
     except Exception as e:
         print("Exception: " + str(e))
     servs = {}
     for dad in search:
         for service in dad.getServices():
             if service.getType() not in list(servs.keys()):
                 servs[service.getType()] = []
             new_dad = dad
             new_dad.services = [service]
             s = Service(dad=new_dad)
             servs[service.getType()].append(s)
     self.DEBUG("Services: " + str(servs))
     return "services.pyra", dict(name=platform,
                                  servername=servername,
                                  platform=platform,
                                  version=version,
                                  time=the_time,
                                  services=servs)
Beispiel #4
0
 def setUp(self):
     self.s1 = Service(name="s1",
                       P=["p1", "p2"],
                       Q=["q1", "q2"],
                       inputs=["i1"],
                       outputs=["o1"])
     self.s1_1 = Service(name="s1_1",
                         P=["p1", "p2"],
                         Q=["q1", "q2"],
                         inputs=["i1"],
                         outputs=["o1"])
     self.s2 = Service(name="s2",
                       P=["p3", "p4"],
                       Q=["q3", "q4"],
                       inputs=["o1"],
                       outputs=["o2"])
Beispiel #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
        servername = self.getDomain()
        platform = self.getName()
        version = str(sys.version)
        the_time = str(time.ctime())
        try:
            search = self.searchService(DfAgentDescription())
        except Exception, e:
            print "Exception: " + str(e)
        servs = {}
        for dad in search:
            for service in dad.getServices():
                if service.getType() not in servs.keys():
                    servs[service.getType()] = []
                new_dad = dad
                new_dad.services = [service]
                s = Service(dad=new_dad)
                servs[service.getType()].append(s)
        self.DEBUG("Services: " + str(servs))
        return "services.pyra", dict(name=platform,
                                     servername=servername,
                                     platform=platform,
                                     version=version,
                                     time=the_time,
                                     services=servs)

    @require_login
    def get_roster(self):
        import sys
        import time
        import copy
        servername = self.getDomain()