Commit 47d798c5 by serfrape

Add more examples

parent 0e1b0552
!start.
+!start <-
+car(rojo);
.a_function(3,W);
.print("w =", W);
literal_function(rojo,Y);
.print("Y =", Y);
.custom_action(8);
+truck(azul).
+car(Color)
<- .print("El carro es ",Color).
\ No newline at end of file
from spade_bdi.bdi import BDIAgent
a = BDIAgent("BasicAgent@localhost", "basicpasswd", "basic.asl")
a.start()
import time
time.sleep(1)
a.bdi.set_belief("car", "azul", "big")
a.bdi.print_beliefs()
print("GETTING FIRST CAR BELIEF")
print(a.bdi.get_belief("car"))
a.bdi.print_beliefs()
a.bdi.remove_belief("car", 'azul', "big")
a.bdi.print_beliefs()
print(a.bdi.get_beliefs())
a.bdi.set_belief("car", 'amarillo')
......@@ -5,7 +5,7 @@ from datetime import datetime
from spade.agent import Agent
class BossAgent(BDIAgent):
class MasterAgent(BDIAgent):
async def setup(self):
template = Template(metadata={"performative": "BDI"})
self.add_behaviour(self.BDIBehaviour(), template)
......@@ -30,10 +30,10 @@ future.result()
c = BDIAgent("slave_2@localhost", "bdisimple3")
future = c.start()
future.result()
a = BossAgent("Boss@localhost", "bdiboss")
a = MasterAgent("master@localhost", "bdimaster")
future = a.start()
future.result()
a.set_asl("boss.asl")
a.set_asl("master.asl")
import time
time.sleep(5)
print("Enabling BDI for slave2")
......
......@@ -8,26 +8,26 @@ tipo(dec).
!obj2.
+!obj2: tipo(inc)
<-
.print("Incrementando");
?contador(X);
-+contador(X+1);
.wait(2000);
.wait(1000);
!obj2.
+!obj2: tipo(dec)
<-
.print("Decrementando");
?contador(X);
-+contador(X-1);
.wait(2000);
!obj2.
+!obj2: not tipo(_)
<-
.print("Esperando");
.wait(2000);
!obj2.
\ No newline at end of file
+!obj2: tipo(dec)
<-
.print("Decrementando");
?contador(X);
-+contador(X-1);
.wait(1000);
!obj2.
+!obj2: not tipo(_)
<-
.print("Esperando");
.wait(1000);
!obj2.
\ No newline at end of file
......@@ -5,7 +5,7 @@ from datetime import datetime
from spade.agent import Agent
class ExampleAgent(BDIAgent):
class CounterAgent(BDIAgent):
async def setup(self):
template = Template(metadata={"performative": "BDI"})
self.add_behaviour(self.BDIBehaviour(), template)
......@@ -42,7 +42,7 @@ class ExampleAgent(BDIAgent):
self.agent.bdi.set_belief('tipo', 'inc')
a = ExampleAgent("Agent@localhost", "bditest", "ejemplo.asl")
a = CounterAgent("counter@localhost", "bditest", "counter.asl")
a.start()
import time
time.sleep(1)
......
+!hello(Msg)[source(Sender)] <-
.print("got a message from", Sender, "saying", Msg).
\ No newline at end of file
.print("got a message from", Sender, "saying:\n", Msg).
\ No newline at end of file
from spade_bdi.bdi import BDIAgent
a = BDIAgent("RECEIVERBDIAgent@localhost", "bditest1", "receiver.asl")
a = BDIAgent("ReceiverAgent@localhost", "receiverpasswd", "receiver.asl")
a.start()
!start.
+!start <-
+car(rojo);
//.a_function(3,W);
//.print("w =", W);
//literal_function(rojo,Y);
//.print("Y =", Y);
//.custom_action(8);
.print("sending individual message ...");
.send("RECEIVERBDIAgent@localhost", achieve, hello(15));
.print("sent a message").
+truck(azul).
+car(Color)
<- .print("El carro es ",Color).
\ No newline at end of file
.print("sending a message ...");
.send("ReceiverAgent@localhost", achieve, hello("Hello World!"));
.print("sent a message").
\ No newline at end of file
from spade_bdi.bdi import BDIAgent
a = BDIAgent("BDIAgent@localhost", "bditest", "sender.asl")
a = BDIAgent("SenderAgent@localhost", "senderpasswd", "sender.asl")
a.start()
import time
time.sleep(1)
a.bdi.set_belief("car", "azul", "big")
a.bdi.print_beliefs()
print("GETTING FIRST CAR BELIEF")
print(a.bdi.get_belief("car"))
a.bdi.print_beliefs()
a.bdi.remove_belief("car", 'azul', "big")
a.bdi.print_beliefs()
print(a.bdi.get_beliefs())
a.bdi.set_belief("car", 'amarillo')
......@@ -15,8 +15,6 @@ from .ontology import X, Y, Z
PERCEPT_TAG = frozenset(
[pyson.Literal("source", (pyson.Literal("percept"), ))])
PRECISION_Z = 0.5
PRECISION_X = 0.5
class BDIAgent(Agent):
......@@ -31,16 +29,23 @@ class BDIAgent(Agent):
self.set_env()
super().add_behaviour(behaviour, template)
def set_asl(self, asl):
self.asl_file = asl
if self.asl_file == None:
def set_asl(self, asl_file=None):
if not asl_file:
self.bdi_enabled = False
self.asl_file = None
else:
with open(self.asl_file) as source:
self.bdi_agent = self.bdi_env.build_agent(
source, self.bdi_actions)
self.bdi_agent.name = self.jid
self.bdi_enabled = True
try:
with open(asl_file) as source:
self.bdi_agent = self.bdi_env.build_agent(
source, self.bdi_actions)
self.bdi_agent.name = self.jid
self.bdi_enabled = True
self.asl_file = asl_file
except FileNotFoundError:
logger.info(
"Warning: ASL specified for {} does not exist. Disabling BDI.".format(self.jid))
self.bdi_enabled = False
self.asl_file = None
def set_env(self):
self.bdi_env = pyson.runtime.Environment()
......@@ -87,7 +92,7 @@ class BDIAgent(Agent):
"""Set an agent's belief. If it already exists, updates it."""
new_args = ()
for x in args:
if type(x) == str:
if type(x) == str:
new_args += (pyson.Literal(x),)
else:
new_args += (x,)
......@@ -116,7 +121,7 @@ class BDIAgent(Agent):
else:
new_args += (x,)
term = pyson.Literal(name, tuple(new_args), PERCEPT_TAG)
self.agent.bdi_intention_buffer.append((pyson.Trigger.removal, pyson.GoalType.belief, belief,
self.agent.bdi_intention_buffer.append((pyson.Trigger.removal, pyson.GoalType.belief, term,
pyson.runtime.Intention()))
# self.agent.bdi_agent.call(pyson.Trigger.removal, pyson.GoalType.belief, term,
# pyson.runtime.Intention())
......
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