Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SPADE-BDI
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
serfrape
SPADE-BDI
Commits
9df8a2dc
Commit
9df8a2dc
authored
Jun 12, 2019
by
serfrape
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extend the examples
parent
ca3bc24a
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
106 additions
and
51 deletions
+106
-51
control.py
examples/control.py
+25
-6
counter.asl
examples/counter.asl
+13
-13
counter.py
examples/counter.py
+18
-5
master.asl
examples/master.asl
+25
-15
receiver.asl
examples/receiver.asl
+3
-1
sender.asl
examples/sender.asl
+6
-5
slave.asl
examples/slave.asl
+16
-6
No files found.
examples/control.py
View file @
9df8a2dc
from
spade_bdi.bdi
import
BDIAgent
from
spade.template
import
Template
from
spade.behaviour
import
PeriodicBehaviour
from
spade.behaviour
import
TimeoutBehaviour
from
datetime
import
datetime
from
datetime
import
timedelta
from
spade.agent
import
Agent
...
...
@@ -14,27 +16,44 @@ class MasterAgent(BDIAgent):
self
.
add_behaviour
(
self
.
Modify
(
period
=
5
,
start_at
=
datetime
.
now
()),
template
)
template
=
Template
(
metadata
=
{
"performative"
:
"Ending"
})
self
.
add_behaviour
(
self
.
Behav4
(
start_at
=
datetime
.
now
()
+
timedelta
(
seconds
=
11
)),
template
)
class
Modify
(
PeriodicBehaviour
):
async
def
run
(
self
):
if
self
.
agent
.
bdi_enabled
:
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'
)
try
:
tipo
=
self
.
agent
.
bdi
.
get_belief_value
(
"tipo"
)[
0
]
if
tipo
==
'inc'
:
self
.
agent
.
bdi
.
set_belief
(
'tipo'
,
'dec'
)
else
:
self
.
agent
.
bdi
.
set_belief
(
'tipo'
,
'inc'
)
except
Exception
as
e
:
print
(
"No belief 'tipo'."
,
e
)
class
Behav4
(
TimeoutBehaviour
):
async
def
run
(
self
):
self
.
agent
.
bdi
.
remove_belief
(
'tipo'
,
'inc'
)
self
.
agent
.
bdi
.
remove_belief
(
'tipo'
,
'dec'
)
import
time
b
=
BDIAgent
(
"slave_1@localhost"
,
"bdisimple"
,
"slave.asl"
)
future
=
b
.
start
()
future
.
result
()
c
=
BDIAgent
(
"slave_2@localhost"
,
"bdisimple3"
)
future
=
c
.
start
()
future
.
result
()
a
=
MasterAgent
(
"master@localhost"
,
"bdimaster"
)
future
=
a
.
start
()
future
.
result
()
a
.
set_asl
(
"master.asl"
)
import
time
a
.
bdi
.
set_belief
(
'tipo'
,
'dec'
)
time
.
sleep
(
5
)
print
(
"Enabling BDI for slave2"
)
c
.
set_asl
(
"slave.asl"
)
...
...
examples/counter.asl
View file @
9df8a2dc
...
...
@@ -3,9 +3,9 @@ tipo(dec).
!inicio.
+!inicio
<-
.print("Iniciando....");
!obj2.
<-
.print("Iniciando....");
!obj2.
+!obj2: tipo(inc)
...
...
@@ -18,16 +18,16 @@ tipo(dec).
+!obj2: tipo(dec)
<-
.print("Decrementando");
?contador(X);
-+contador(X-1);
.wait(1000);
!obj2.
<-
.print("Decrementando");
?contador(X);
-+contador(X-1);
.wait(1000);
!obj2.
+!obj2: not tipo(_)
<-
.print("Esperando");
<-
.print("Esperando");
.wait(1000);
!obj2.
\ No newline at end of file
!obj2.
\ No newline at end of file
examples/counter.py
View file @
9df8a2dc
from
spade_bdi.bdi
import
BDIAgent
from
spade.template
import
Template
from
spade.behaviour
import
PeriodicBehaviour
from
spade.behaviour
import
TimeoutBehaviour
from
datetime
import
datetime
from
datetime
import
timedelta
from
spade.agent
import
Agent
...
...
@@ -18,6 +20,9 @@ class CounterAgent(BDIAgent):
template
=
Template
(
metadata
=
{
"performative"
:
"B3"
})
self
.
add_behaviour
(
self
.
Behav3
(
period
=
10
,
start_at
=
datetime
.
now
()),
template
)
template
=
Template
(
metadata
=
{
"performative"
:
"B4"
})
self
.
add_behaviour
(
self
.
Behav4
(
start_at
=
datetime
.
now
()
+
timedelta
(
seconds
=
60
)),
template
)
class
Behav1
(
PeriodicBehaviour
):
async
def
on_start
(
self
):
...
...
@@ -35,11 +40,19 @@ class CounterAgent(BDIAgent):
class
Behav3
(
PeriodicBehaviour
):
async
def
run
(
self
):
tipo
=
self
.
agent
.
bdi
.
get_belief_value
(
"tipo"
)[
0
]
if
tipo
==
'inc'
:
self
.
agent
.
bdi
.
set_belief
(
'tipo'
,
'dec'
)
else
:
self
.
agent
.
bdi
.
set_belief
(
'tipo'
,
'inc'
)
try
:
tipo
=
self
.
agent
.
bdi
.
get_belief_value
(
"tipo"
)[
0
]
if
tipo
==
'inc'
:
self
.
agent
.
bdi
.
set_belief
(
'tipo'
,
'dec'
)
else
:
self
.
agent
.
bdi
.
set_belief
(
'tipo'
,
'inc'
)
except
Exception
as
e
:
print
(
"No belief 'tipo'."
)
class
Behav4
(
TimeoutBehaviour
):
async
def
run
(
self
):
self
.
agent
.
bdi
.
remove_belief
(
'tipo'
,
'inc'
)
self
.
agent
.
bdi
.
remove_belief
(
'tipo'
,
'dec'
)
a
=
CounterAgent
(
"counter@localhost"
,
"bditest"
,
"counter.asl"
)
...
...
examples/master.asl
View file @
9df8a2dc
!start.
type(dec).
+!start <-
-start;
!obj2.
+!start
<-
-start;
!obj2.
+!obj2: type(inc) <-
.send("slave_1@localhost", tell, incrementar(0));
.send("slave_2@localhost", tell, incrementar(0));
.wait(2000);
!obj2.
+!obj2: tipo(inc)
<-
.send("slave_1@localhost", tell, incrementar(2));
.send("slave_2@localhost", tell, incrementar(5));
.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
+!obj2: tipo(dec)
<-
.send("slave_1@localhost", tell, decrementar(2));
.send("slave_2@localhost", tell, decrementar(5));
.wait(2000);
!obj2.
+!obj2: not tipo(_)
<-
.print("Esperando");
.send("slave_1@localhost", untell, incrementar(2));
.send("slave_2@localhost", untell, incrementar(5));
.send("slave_1@localhost", untell, decrementar(2));
.send("slave_2@localhost", untell, decrementar(5)).
\ No newline at end of file
examples/receiver.asl
View file @
9df8a2dc
+!hello(Msg)[source(Sender)] <-
+!hello(Msg)[source(Sender)]
<-
.print("got a message from", Sender, "saying:\n", Msg).
\ No newline at end of file
examples/sender.asl
View file @
9df8a2dc
!start.
+!start <-
.print("sending a message ...");
.send("BDIReceiverAgent@localhost", achieve, hello("Hello World!"));
.print("sent a message").
\ No newline at end of file
+!start
<-
.print("sending a message ...");
.send("BDIReceiverAgent@localhost", achieve, hello("Hello World!"));
.print("sent a message").
\ No newline at end of file
examples/slave.asl
View file @
9df8a2dc
contador(0).
+incrementar(Inc) <-
+incrementar(Inc)[source(S)]: .substring("master@localhost",S,R)
<-
.print("increasing");
?contador(X);
-+contador(X+1
);
-
incrementar(_
).
.print(X
);
-
+contador(X+Inc
).
+decrementar(Dec) <-
+decrementar(Dec)[source(S)]: .substring("master@localhost",S,R)
<-
.print("decreasing");
?contador(X);
-+contador(X-1);
-decrementar(_).
.print(X);
-+contador(X-Dec).
-incrementar(Inc)[source(S)]: .substring("master@localhost",S,R)
<-
.print("DELETING incrementar BELIEF from an untell message").
-decrementar(Dec)[source(S)]: .substring("master@localhost",S,R)
<-
.print("DELETING decrementar BELIEF from an untell message").
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment