Commit 00928232 by serfrape

Adjust compatibility with spade 3.1.0 and add examples

parent 54799e60
!start.
type(dec).
+!start <-
-start;
!obj2.
+!obj2: type(inc) <-
.send("slave_1@localhost", tell, incrementar(0));
.send("slave_2@localhost", tell, incrementar(0));
.wait(2000);
!obj2.
+!obj2: type(dec) <-
.send("slave_1@localhost", tell, decrementar(0));
.send("slave_2@localhost", tell, decrementar(0));
.wait(2000);
!obj2.
\ No newline at end of file
from spade_bdi.bdi import BDIAgent
from spade.template import Template
from spade.behaviour import PeriodicBehaviour
from datetime import datetime
from spade.agent import Agent
class BossAgent(BDIAgent):
async def setup(self):
template = Template(metadata={"performative": "BDI"})
self.add_behaviour(self.BDIBehaviour(), template)
template = Template(metadata={"performative": "Modify"})
self.add_behaviour(self.Modify(
period=5, start_at=datetime.now()), template)
class Modify(PeriodicBehaviour):
async def run(self):
tipo = self.agent.bdi.get_belief_value("type")[0]
if tipo == 'inc':
self.agent.bdi.set_belief('type', 'dec')
else:
self.agent.bdi.set_belief('type', 'inc')
b = BDIAgent("slave_1@localhost", "bdisimple", "slave.asl")
b.start()
c = BDIAgent("slave_2@localhost", "bdisimple3", "slave.asl")
c.start()
a = BossAgent("Boss@localhost", "bdiboss", "boss.asl")
a.start()
print("started")
...@@ -6,7 +6,7 @@ from spade.agent import Agent ...@@ -6,7 +6,7 @@ from spade.agent import Agent
class ExampleAgent(BDIAgent): class ExampleAgent(BDIAgent):
def setup(self): async def setup(self):
template = Template(metadata={"performative": "BDI"}) template = Template(metadata={"performative": "BDI"})
self.add_behaviour(self.BDIBehaviour(), template) self.add_behaviour(self.BDIBehaviour(), template)
template = Template(metadata={"performative": "B1"}) template = Template(metadata={"performative": "B1"})
...@@ -38,8 +38,8 @@ class ExampleAgent(BDIAgent): ...@@ -38,8 +38,8 @@ class ExampleAgent(BDIAgent):
tipo = self.agent.bdi.get_belief_value("tipo")[0] tipo = self.agent.bdi.get_belief_value("tipo")[0]
if tipo == 'inc': if tipo == 'inc':
self.agent.bdi.set_belief('tipo', 'dec') self.agent.bdi.set_belief('tipo', 'dec')
# else: else:
# self.agent.bdi.set_belief('tipo', 'inc') self.agent.bdi.set_belief('tipo', 'inc')
a = ExampleAgent("Agent@localhost", "bditest", "ejemplo.asl") a = ExampleAgent("Agent@localhost", "bditest", "ejemplo.asl")
......
contador(0).
+incrementar(Inc) <-
.print("increasing");
?contador(X);
-+contador(X+1);
-incrementar(_).
+decrementar(Dec) <-
.print("decreasing");
?contador(X);
-+contador(X+1);
-decrementar(_).
...@@ -16,7 +16,7 @@ PERCEPT_TAG = frozenset( ...@@ -16,7 +16,7 @@ PERCEPT_TAG = frozenset(
class BDIAgent(Agent): class BDIAgent(Agent):
def setup(self): async def setup(self):
template = Template(metadata={"performative": "BDI"}) template = Template(metadata={"performative": "BDI"})
self.add_behaviour(self.BDIBehaviour(), template) self.add_behaviour(self.BDIBehaviour(), template)
...@@ -24,6 +24,7 @@ class BDIAgent(Agent): ...@@ -24,6 +24,7 @@ class BDIAgent(Agent):
# print("OVERRIDEN") # print("OVERRIDEN")
if type(behaviour) == self.BDIBehaviour: if type(behaviour) == self.BDIBehaviour:
self.bdi = behaviour self.bdi = behaviour
# print("ADDING BDI BEHAVIOUR")
super().add_behaviour(behaviour, template) super().add_behaviour(behaviour, template)
def __init__(self, jid, password, asl, *args, **kwargs): def __init__(self, jid, password, asl, *args, **kwargs):
...@@ -46,7 +47,7 @@ class BDIAgent(Agent): ...@@ -46,7 +47,7 @@ class BDIAgent(Agent):
"args": str(term.args[2].args)}) "args": str(term.args[2].args)})
msg = Message(to=receiver, body=body, metadata=mdata) msg = Message(to=receiver, body=body, metadata=mdata)
self.agent.submit(self.send(msg)) self.agent.submit(self.send(msg))
print("SENT!!!") # print("SENT!!!")
yield yield
@self.actions.add(".custom_action", 1) @self.actions.add(".custom_action", 1)
...@@ -155,6 +156,7 @@ class BDIAgent(Agent): ...@@ -155,6 +156,7 @@ class BDIAgent(Agent):
with open(self.agent.asl_file) as source: with open(self.agent.asl_file) as source:
self.bdi_agent = self.env.build_agent( self.bdi_agent = self.env.build_agent(
source, self.actions) source, self.actions)
self.bdi_agent.name = self.agent.jid
async def run(self): async def run(self):
""" """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment