Exemplo n.º 1
0
class BDIFlora2TestCase(BDIPrologTestCase, unittest.TestCase):
    def setUp(self):
        self.a = BDIAgent("bdi_flora2@" + host, "secret")
        self.a.kb.configure("Flora2")
        #self.a.setDebugToScreen()
        self.a.start()
        self.set_up()
Exemplo n.º 2
0
class BDIECLiPSeTestCase(BDIPrologTestCase, unittest.TestCase):
    def setUp(self):
	self.a = BDIAgent("bdi_eclipse@" + host, "secret")
	self.a.kb.configure("ECLiPSe")
        #self.a.setDebugToScreen()
        self.a.start()
	self.set_up()
Exemplo n.º 3
0
class BDIECLiPSeTestCase(BDIPrologTestCase, unittest.TestCase):
    def setUp(self):
        self.a = BDIAgent("bdi_eclipse@" + host, "secret")
        self.a.kb.configure("ECLiPSe")
        #self.a.setDebugToScreen()
        self.a.start()
        self.set_up()
Exemplo n.º 4
0
class BDIFlora2TestCase(BDIPrologTestCase, unittest.TestCase):
    def setUp(self):
	self.a = BDIAgent("bdi_flora2@" + host, "secret")
	self.a.kb.configure("Flora2")
        #self.a.setDebugToScreen()
        self.a.start()
	self.set_up()
Exemplo n.º 5
0
    def setUp(self):

        self.a = BDIAgent("bdi@" + host, "secret")
        #self.a.setDebugToScreen()
        self.a.start()

        self.s1 = spade.DF.Service(name="s1",
                                   owner=self.a.getAID(),
                                   inputs=["Value"],
                                   outputs=["Myoutput1"],
                                   P=["Var(Value,0,Int)"],
                                   Q=["Var(Myoutput1,1,Int)"])
        self.s2 = spade.DF.Service(name="s2",
                                   owner=self.a.getAID(),
                                   inputs=["Myoutput1"],
                                   outputs=["Myoutput2"],
                                   P=["Var(Myoutput1,1,Int)"],
                                   Q=["Var(Myoutput2,2,Int)"])
        self.s3 = spade.DF.Service(name="s3",
                                   owner=self.a.getAID(),
                                   inputs=["Value3"],
                                   outputs=["Myoutput3"],
                                   P=["Var(Value3,3,Int)"],
                                   Q=["Var(Myoutput3,4,Int)"])
        self.s4 = spade.DF.Service(name="s4",
                                   owner=self.a.getAID(),
                                   inputs=["Myoutput3"],
                                   outputs=["Myoutput4"],
                                   P=["Var(Myoutput3,4,Int)"],
                                   Q=["Var(Myoutput4,5,Int)"])

        time.sleep(1)
Exemplo n.º 6
0
    def setUp(self):

        self.a = BDIAgent("bdi@" + host, "secret")
        #self.a.setDebugToScreen()
        self.a.start()

        self.s1 = spade.DF.Service(name="s1", owner=self.a.getAID(), inputs=["Value"], outputs=["Myoutput1"], P=["Var(Value,0,Int)"], Q=["Var(Myoutput1,1,Int)"])
        self.s2 = spade.DF.Service(name="s2", owner=self.a.getAID(), inputs=["Myoutput1"], outputs=["Myoutput2"], P=["Var(Myoutput1,1,Int)"], Q=["Var(Myoutput2,2,Int)"])
        self.s3 = spade.DF.Service(name="s3", owner=self.a.getAID(), inputs=["Value3"], outputs=["Myoutput3"], P=["Var(Value3,3,Int)"], Q=["Var(Myoutput3,4,Int)"])
        self.s4 = spade.DF.Service(name="s4", owner=self.a.getAID(), inputs=["Myoutput3"], outputs=["Myoutput4"], P=["Var(Myoutput3,4,Int)"], Q=["Var(Myoutput4,5,Int)"])

        time.sleep(1)
Exemplo n.º 7
0
class PlanTestCase(unittest.TestCase):

    def setUp(self):

        self.a = BDIAgent("bdi@" + host, "secret")
        self.a.start()

    def tearDown(self):
        self.a.stop()
        del self.a

    def testAddBelieve(self):
        self.a.addBelieve(expr("Value(TestValue)"))

        self.assertTrue(self.a.askBelieve("Value(TestValue)"))

    def testAddGoal(self):
        g = Goal("Value(2)")
        self.a.addGoal(g)

        self.assertEqual(len(self.a.bdiBehav.goals), 1)
        self.assertEqual(self.a.bdiBehav.goals[0].expression, "Value(2)")
Exemplo n.º 8
0
class PlanTestCase(unittest.TestCase):
    def setUp(self):

        self.a = BDIAgent("bdi@" + host, "secret")
        self.a.start()
        #self.a.setDebugToScreen()

    def tearDown(self):
        self.a.stop()
        del self.a

    def testAddBelieve(self):
        self.a.addBelieve(expr("Value(TestValue)"))

        self.assertTrue(self.a.askBelieve("Value(TestValue)"))

    def testAddGoal(self):
        g = Goal("Value(2)")
        self.a.addGoal(g)

        self.assertEqual(len(self.a.bdiBehav.goals), 1)
        self.assertEqual(self.a.bdiBehav.goals[0].expression, "Value(2)")
Exemplo n.º 9
0
import unittest
sys.path.append('../..')
sys.path.append('..')

import spade
from spade.bdi import Goal
from spade.Agent import BDIAgent

def MygoalCompletedCB(goal):
    global goalCompleted
    goalCompleted = True


host = "127.0.0.1"

a = BDIAgent("clientbdi@"+host,"secret")
a.setDebugToScreen()
a.start()

goalCompleted=False

a.saveFact("Value",0)

a.setGoalCompletedCB(MygoalCompletedCB)

a.addGoal(Goal("Var(Myoutput2,2,Int)"))

import time
counter = 0
while not goalCompleted and counter<10:
    time.sleep(1)
Exemplo n.º 10
0
class BDITestCase(unittest.TestCase):

    def setUp(self):

        self.a = BDIAgent("bdi@" + host, "secret")
        #self.a.setDebugToScreen()
        self.a.start()

        self.s1 = spade.DF.Service(name="s1", owner=self.a.getAID(), inputs=["Value"], outputs=["Myoutput1"], P=["Var(Value,0,Int)"], Q=["Var(Myoutput1,1,Int)"])
        self.s2 = spade.DF.Service(name="s2", owner=self.a.getAID(), inputs=["Myoutput1"], outputs=["Myoutput2"], P=["Var(Myoutput1,1,Int)"], Q=["Var(Myoutput2,2,Int)"])
        self.s3 = spade.DF.Service(name="s3", owner=self.a.getAID(), inputs=["Value3"], outputs=["Myoutput3"], P=["Var(Value3,3,Int)"], Q=["Var(Myoutput3,4,Int)"])
        self.s4 = spade.DF.Service(name="s4", owner=self.a.getAID(), inputs=["Myoutput3"], outputs=["Myoutput4"], P=["Var(Myoutput3,4,Int)"], Q=["Var(Myoutput4,5,Int)"])

        time.sleep(1)

    def tearDown(self):
        s = spade.DF.Service()
        s.setOwner(self.a.getAID())
        self.a.deregisterService(s)
        self.a.stop()
        del self.a

    def testAddPlan(self):

        self.a.registerService(self.s1, s1_method)
        self.a.registerService(self.s2, s2_method)

        self.a.bdiBehav.discover()
        result = self.a.addPlan(inputs=["Value"], outputs=["Myoutput2"], P=["Var(Value,0,Int)"], Q=["Var(Myoutput2,2,Int)"], services=["s1", "s2"])

        self.assertTrue(result)

    def goalCompletedCB(self, goal):
        self.goalCompleted = True

    def testSimpleGoalCompleted(self):

        self.goalCompleted = False
        self.a.registerService(self.s1, s1_method)

        self.a.saveFact("Value", 0)

        self.a.setGoalCompletedCB(self.goalCompletedCB)

        self.a.addGoal(Goal("Var(Myoutput1,1,Int)"))

        counter = 0
        while not self.goalCompleted and counter < 10:
            time.sleep(1)
            counter += 1

        self.assertTrue(self.goalCompleted)
        self.assertTrue(self.a.askBelieve("Var(Myoutput1,1,Int)"))
        assert self.a.getFact("Myoutput1") == 1

    def testGoalCompleted_withPlan(self):

        self.goalCompleted = False
        self.a.registerService(self.s1, s1_method)
        self.a.registerService(self.s2, s2_method)

        self.a.saveFact("Value", 0)

        self.a.setGoalCompletedCB(self.goalCompletedCB)

        self.a.addGoal(Goal("Var(Myoutput2,2,Int)"))

        counter = 0
        while not self.goalCompleted and counter < 10:
            time.sleep(1)
            counter += 1

        self.assertTrue(self.goalCompleted)
        self.assertTrue(self.a.askBelieve("Var(Myoutput2,2,Int)"))
        assert self.a.getFact("Myoutput2") == 2

    def serviceCompletedCB(self, service):
        s = service.getName()
        if s == "s1":
                self.s1Completed = True
        if s == "s2":
                self.s2Completed = True
        if s == "s3":
                self.s3Completed = True
        if s == "s4":
                self.s4Completed = True

    def testMultiGoalCompleted(self):
        self.s1Completed = False
        self.s3Completed = False

        self.a.registerService(self.s1, s1_method)
        self.a.registerService(self.s3, s3_method)

        self.a.saveFact("Value", 0)
        self.a.saveFact("Value3", 3)

        self.a.setServiceCompletedCB(self.serviceCompletedCB)

        self.a.addGoal(Goal("Var(Myoutput3,4,Int)"))
        self.a.addGoal(Goal("Var(Myoutput1,1,Int)"))

        counter = 0
        while counter < 10 and (self.s1Completed is False or self.s3Completed is False):
            time.sleep(1)
            counter += 1

        self.assertTrue(self.s1Completed)
        self.assertTrue(self.s3Completed)
        self.assertTrue(self.a.askBelieve("Var(Myoutput1,1,Int)"))
        assert self.a.getFact("Myoutput1") == 1
        self.assertTrue(self.a.askBelieve("Var(Myoutput3,4,Int)"))
        assert self.a.getFact("Myoutput3") == 4

    def testMultiGoalCompleted_withMultiServices(self):
        self.s2Completed = False
        self.s4Completed = False

        self.a.registerService(self.s1, s1_method)
        self.a.registerService(self.s2, s2_method)
        self.a.registerService(self.s3, s3_method)
        self.a.registerService(self.s4, s4_method)

        self.a.saveFact("Value", 0)
        self.a.saveFact("Value3", 3)

        self.a.setServiceCompletedCB(self.serviceCompletedCB)

        self.a.addGoal(Goal("Var(Myoutput2,2,Int)"))
        self.a.addGoal(Goal("Var(Myoutput4,5,Int)"))

        counter = 0
        while counter < 10 and (self.s2Completed is False or self.s4Completed is False):
            time.sleep(1)
            counter += 1

        self.assertTrue(self.s2Completed)
        self.assertTrue(self.s4Completed)
        self.assertTrue(self.a.askBelieve("Var(Myoutput2,2,Int)"))
        assert self.a.getFact("Myoutput2") == 2
        self.assertTrue(self.a.askBelieve("Var(Myoutput4,5,Int)"))
        assert self.a.getFact("Myoutput4") == 5
Exemplo n.º 11
0
    def setUp(self):
	self.a = BDIAgent("bdi_flora2@" + host, "secret")
	self.a.kb.configure("Flora2")
        #self.a.setDebugToScreen()
        self.a.start()
	self.set_up()
Exemplo n.º 12
0
    def setUp(self):

        self.a = BDIAgent("bdi@" + host, "secret")
        self.a.start()
Exemplo n.º 13
0
    def setUp(self):
	self.a = BDIAgent("bdi_eclipse@" + host, "secret")
	self.a.kb.configure("ECLiPSe")
        #self.a.setDebugToScreen()
        self.a.start()
	self.set_up()
Exemplo n.º 14
0
 def setUp(self):
     self.a = BDIAgent("bdi_eclipse@" + host, "secret")
     self.a.kb.configure("ECLiPSe")
     #self.a.setDebugToScreen()
     self.a.start()
     self.set_up()
Exemplo n.º 15
0
    def setUp(self):

        self.a = BDIAgent("bdi@" + host, "secret")
        self.a.start()
Exemplo n.º 16
0
from spade.DF import Service
from spade.Agent import BDIAgent


def s1_method(Value):
    return {"O1": 1}


def s2_method(Myoutput1):
    return {"O2": 2}

def goalCompletedCB(Goal):
    agent.goalCompleted = True


agent = BDIAgent("[email protected]", "secret")

s1 = Service(name="s1", owner=agent.getAID(), inputs=["Value"], outputs=["O1"], P=["Var(Value,0,Int)"],
             Q=["Var(O1,1,Int)"])
s2 = Service(name="s2", owner=agent.getAID(), inputs=["O1"], outputs=["O2"], P=["Var(O1,1,Int)"],
             Q=["Var(O2,2,Int)"])

agent.registerService(s1, s1_method)
agent.registerService(s2, s2_method)

agent.goalCompleted = False

agent.saveFact("Value", 0)

agent.setGoalCompletedCB(goalCompletedCB)
Exemplo n.º 17
0
 def setUp(self):
     self.a = BDIAgent("bdi_flora2@" + host, "secret")
     self.a.kb.configure("Flora2")
     #self.a.setDebugToScreen()
     self.a.start()
     self.set_up()
Exemplo n.º 18
0
class BDITestCase(unittest.TestCase):
    def setUp(self):

        self.a = BDIAgent("bdi@" + host, "secret")
        #self.a.setDebugToScreen()
        self.a.start()

        self.s1 = spade.DF.Service(name="s1",
                                   owner=self.a.getAID(),
                                   inputs=["Value"],
                                   outputs=["Myoutput1"],
                                   P=["Var(Value,0,Int)"],
                                   Q=["Var(Myoutput1,1,Int)"])
        self.s2 = spade.DF.Service(name="s2",
                                   owner=self.a.getAID(),
                                   inputs=["Myoutput1"],
                                   outputs=["Myoutput2"],
                                   P=["Var(Myoutput1,1,Int)"],
                                   Q=["Var(Myoutput2,2,Int)"])
        self.s3 = spade.DF.Service(name="s3",
                                   owner=self.a.getAID(),
                                   inputs=["Value3"],
                                   outputs=["Myoutput3"],
                                   P=["Var(Value3,3,Int)"],
                                   Q=["Var(Myoutput3,4,Int)"])
        self.s4 = spade.DF.Service(name="s4",
                                   owner=self.a.getAID(),
                                   inputs=["Myoutput3"],
                                   outputs=["Myoutput4"],
                                   P=["Var(Myoutput3,4,Int)"],
                                   Q=["Var(Myoutput4,5,Int)"])

        time.sleep(1)

    def tearDown(self):
        s = spade.DF.Service()
        s.setOwner(self.a.getAID())
        self.a.deregisterService(s)
        self.a.stop()
        del self.a

    def testAddPlan(self):

        self.a.registerService(self.s1, s1_method)
        self.a.registerService(self.s2, s2_method)

        self.a.bdiBehav.discover()
        result = self.a.addPlan(inputs=["Value"],
                                outputs=["Myoutput2"],
                                P=["Var(Value,0,Int)"],
                                Q=["Var(Myoutput2,2,Int)"],
                                services=["s1", "s2"])

        self.assertTrue(result)

    def goalCompletedCB(self, goal):
        self.goalCompleted = True

    def testSimpleGoalCompleted(self):

        self.goalCompleted = False
        self.a.registerService(self.s1, s1_method)

        self.a.saveFact("Value", 0)

        self.a.setGoalCompletedCB(self.goalCompletedCB)

        self.a.addGoal(Goal("Var(Myoutput1,1,Int)"))

        counter = 0
        while not self.goalCompleted and counter < 10:
            time.sleep(1)
            counter += 1

        self.assertTrue(self.goalCompleted)
        self.assertTrue(self.a.askBelieve("Var(Myoutput1,1,Int)"))
        assert self.a.getFact("Myoutput1") == 1

    def testGoalCompleted_withPlan(self):

        self.goalCompleted = False
        self.a.registerService(self.s1, s1_method)
        self.a.registerService(self.s2, s2_method)

        self.a.saveFact("Value", 0)

        self.a.setGoalCompletedCB(self.goalCompletedCB)

        self.a.addGoal(Goal("Var(Myoutput2,2,Int)"))

        counter = 0
        while not self.goalCompleted and counter < 10:
            time.sleep(1)
            counter += 1

        self.assertTrue(self.goalCompleted)
        self.assertTrue(self.a.askBelieve("Var(Myoutput2,2,Int)"))
        assert self.a.getFact("Myoutput2") == 2

    def serviceCompletedCB(self, service):
        s = service.getName()
        if s == "s1":
            self.s1Completed = True
        if s == "s2":
            self.s2Completed = True
        if s == "s3":
            self.s3Completed = True
        if s == "s4":
            self.s4Completed = True

    def testMultiGoalCompleted(self):
        self.s1Completed = False
        self.s3Completed = False

        self.a.registerService(self.s1, s1_method)
        self.a.registerService(self.s3, s3_method)

        self.a.saveFact("Value", 0)
        self.a.saveFact("Value3", 3)

        self.a.setServiceCompletedCB(self.serviceCompletedCB)

        self.a.addGoal(Goal("Var(Myoutput3,4,Int)"))
        self.a.addGoal(Goal("Var(Myoutput1,1,Int)"))

        counter = 0
        while counter < 10 and (self.s1Completed is False
                                or self.s3Completed is False):
            time.sleep(1)
            counter += 1

        self.assertTrue(self.s1Completed)
        self.assertTrue(self.s3Completed)
        self.assertTrue(self.a.askBelieve("Var(Myoutput1,1,Int)"))
        assert self.a.getFact("Myoutput1") == 1
        self.assertTrue(self.a.askBelieve("Var(Myoutput3,4,Int)"))
        assert self.a.getFact("Myoutput3") == 4

    def testMultiGoalCompleted_withMultiServices(self):
        self.s2Completed = False
        self.s4Completed = False

        self.a.registerService(self.s1, s1_method)
        self.a.registerService(self.s2, s2_method)
        self.a.registerService(self.s3, s3_method)
        self.a.registerService(self.s4, s4_method)

        self.a.saveFact("Value", 0)
        self.a.saveFact("Value3", 3)

        self.a.setServiceCompletedCB(self.serviceCompletedCB)

        self.a.addGoal(Goal("Var(Myoutput2,2,Int)"))
        self.a.addGoal(Goal("Var(Myoutput4,5,Int)"))

        counter = 0
        while counter < 10 and (self.s2Completed is False
                                or self.s4Completed is False):
            time.sleep(1)
            counter += 1

        self.assertTrue(self.s2Completed)
        self.assertTrue(self.s4Completed)
        self.assertTrue(self.a.askBelieve("Var(Myoutput2,2,Int)"))
        assert self.a.getFact("Myoutput2") == 2
        self.assertTrue(self.a.askBelieve("Var(Myoutput4,5,Int)"))
        assert self.a.getFact("Myoutput4") == 5
Exemplo n.º 19
0
the agent "BDIAgent".
You need to be running a SPADE platform on the same host
'''


import os
import sys
import time
sys.path.append('..'+os.sep+'trunk')
sys.path.append('..')
from spade.bdi import *
from spade.DF import Service
from spade.Agent import BDIAgent
from spade.tbcbp import *

agent = BDIAgent("[email protected]", "secret")
#agent.setDebugToScreen()
agent.addBelieve(expr("Value(0)"))
g = Goal(expr("Value(2)"))

class Serv1(Service):

    def run(self):
        print "Service 1 running"
        self.addBelieve(expr("Value(1)"))


class Serv2(Service):
    def run(self):
        print "Service 2 running"
        self.addBelieve(expr("Value(2)"))
Exemplo n.º 20
0
sys.path.append('../..')
sys.path.append('..')

import spade
from spade.bdi import Goal
from spade.Agent import BDIAgent


def MygoalCompletedCB(goal):
    global goalCompleted
    goalCompleted = True


host = "127.0.0.1"

a = BDIAgent("clientbdi@" + host, "secret")
a.setDebugToScreen()
a.start()

goalCompleted = False

a.saveFact("Value", 0)

a.setGoalCompletedCB(MygoalCompletedCB)

a.addGoal(Goal("Var(Myoutput2,2,Int)"))

import time
counter = 0
while not goalCompleted and counter < 10:
    time.sleep(1)