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
0
Issues
0
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
jpalanca
SPADE-BDI
Commits
47d798c5
Commit
47d798c5
authored
May 13, 2019
by
serfrape
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more examples
parent
0e1b0552
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
78 additions
and
68 deletions
+78
-68
.nano.save.swp
examples/.nano.save.swp
+0
-0
basic.asl
examples/basic.asl
+14
-0
basic.py
examples/basic.py
+17
-0
control.py
examples/control.py
+3
-3
counter.asl
examples/counter.asl
+16
-16
counter.py
examples/counter.py
+2
-2
master.asl
examples/master.asl
+0
-0
receiver.asl
examples/receiver.asl
+2
-4
receiver.py
examples/receiver.py
+2
-1
sender.asl
examples/sender.asl
+4
-17
sender.py
examples/sender.py
+1
-13
bdi.py
spade_bdi/bdi.py
+17
-12
No files found.
examples/.nano.save.swp
0 → 100644
View file @
47d798c5
File added
examples/basic.asl
0 → 100644
View file @
47d798c5
!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
examples/basic.py
0 → 100644
View file @
47d798c5
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'
)
examples/control.py
View file @
47d798c5
...
...
@@ -5,7 +5,7 @@ from datetime import datetime
from
spade.agent
import
Agent
class
Boss
Agent
(
BDIAgent
):
class
Master
Agent
(
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"
)
...
...
examples/
ejemplo
.asl
→
examples/
counter
.asl
View file @
47d798c5
...
...
@@ -8,26 +8,26 @@ tipo(dec).
!obj2.
+!obj2: tipo(inc)
<-
.print("Incrementando");
?contador(X);
-+contador(X+1);
.wait(
2
000);
.wait(
1
000);
!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
examples/
ejemplo
.py
→
examples/
counter
.py
View file @
47d798c5
...
...
@@ -5,7 +5,7 @@ from datetime import datetime
from
spade.agent
import
Agent
class
Example
Agent
(
BDIAgent
):
class
Counter
Agent
(
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
)
...
...
examples/
boss
.asl
→
examples/
master
.asl
View file @
47d798c5
File moved
examples/receiver.asl
View file @
47d798c5
+!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
examples/receiver.py
View file @
47d798c5
from
spade_bdi.bdi
import
BDIAgent
a
=
BDIAgent
(
"R
ECEIVERBDIAgent@localhost"
,
"bditest1
"
,
"receiver.asl"
)
a
=
BDIAgent
(
"R
eceiverAgent@localhost"
,
"receiverpasswd
"
,
"receiver.asl"
)
a
.
start
()
examples/sender.asl
View file @
47d798c5
!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
examples/sender.py
View file @
47d798c5
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'
)
spade_bdi/bdi.py
View file @
47d798c5
...
...
@@ -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())
...
...
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