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
ca3bc24a
Commit
ca3bc24a
authored
May 29, 2019
by
serfrape
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow sending messages with variables.
parent
85f38e39
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
16 deletions
+28
-16
bdi.py
spade_bdi/bdi.py
+28
-16
No files found.
spade_bdi/bdi.py
View file @
ca3bc24a
...
@@ -67,8 +67,8 @@ class BDIAgent(Agent):
...
@@ -67,8 +67,8 @@ class BDIAgent(Agent):
ilf_type
=
ilf
.
functor
ilf_type
=
ilf
.
functor
mdata
=
{
"performative"
:
"BDI"
,
mdata
=
{
"performative"
:
"BDI"
,
"ilf_type"
:
ilf_type
,
}
"ilf_type"
:
ilf_type
,
}
body
=
json
.
dumps
({
"functor"
:
str
(
term
.
args
[
2
]
.
functor
),
body
=
pyson
.
pyson_str
(
pyson
.
freeze
(
"args"
:
str
(
term
.
args
[
2
]
.
args
)}
)
term
.
args
[
2
],
intention
.
scope
,
{})
)
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
))
yield
yield
...
@@ -193,7 +193,6 @@ class BDIAgent(Agent):
...
@@ -193,7 +193,6 @@ class BDIAgent(Agent):
if
self
.
agent
.
bdi_enabled
:
if
self
.
agent
.
bdi_enabled
:
msg
=
await
self
.
receive
(
timeout
=
0
)
msg
=
await
self
.
receive
(
timeout
=
0
)
if
msg
:
if
msg
:
received
=
json
.
loads
(
msg
.
body
)
mdata
=
msg
.
metadata
mdata
=
msg
.
metadata
ilf_type
=
mdata
[
"ilf_type"
]
ilf_type
=
mdata
[
"ilf_type"
]
if
ilf_type
==
"tell"
:
if
ilf_type
==
"tell"
:
...
@@ -208,15 +207,13 @@ class BDIAgent(Agent):
...
@@ -208,15 +207,13 @@ class BDIAgent(Agent):
else
:
else
:
raise
pyson
.
PysonError
(
raise
pyson
.
PysonError
(
"unknown illocutionary force:
%
s"
%
ilf_type
)
"unknown illocutionary force:
%
s"
%
ilf_type
)
intention
=
pyson
.
runtime
.
Intention
()
intention
=
pyson
.
runtime
.
Intention
()
args
=
literal_eval
(
received
[
"args"
]
)
functor
,
args
=
await
parse_literal
(
msg
.
body
)
if
args
!=
tuple
():
message
=
pyson
.
Literal
(
functor
,
args
)
message
=
pyson
.
Literal
(
received
[
"functor"
],
args
)
else
:
message
=
pyson
.
Literal
(
received
[
"functor"
])
message
=
pyson
.
freeze
(
message
,
intention
.
scope
,
{})
message
=
pyson
.
freeze
(
message
,
intention
.
scope
,
{})
tagged_message
=
message
.
with_annotation
(
tagged_message
=
message
.
with_annotation
(
pyson
.
Literal
(
"source"
,
(
pyson
.
Literal
(
str
(
msg
.
sender
)),
)))
pyson
.
Literal
(
"source"
,
(
pyson
.
Literal
(
str
(
msg
.
sender
)),
)))
self
.
agent
.
bdi_intention_buffer
.
append
((
trigger
,
goal_type
,
self
.
agent
.
bdi_intention_buffer
.
append
((
trigger
,
goal_type
,
...
@@ -225,15 +222,30 @@ class BDIAgent(Agent):
...
@@ -225,15 +222,30 @@ class BDIAgent(Agent):
# tagged_message, intention)
# tagged_message, intention)
if
self
.
agent
.
bdi_intention_buffer
:
if
self
.
agent
.
bdi_intention_buffer
:
temp_intentions
=
deque
(
self
.
agent
.
bdi_intention_buffer
)
temp_intentions
=
deque
(
self
.
agent
.
bdi_intention_buffer
)
for
i
in
temp_intentions
:
for
trigger
,
goal_type
,
tagged_message
,
intention
in
temp_intentions
:
self
.
agent
.
bdi_agent
.
call
(
i
[
0
],
i
[
1
],
i
[
2
],
i
[
3
])
self
.
agent
.
bdi_agent
.
call
(
trigger
,
goal_type
,
tagged_message
,
intention
)
self
.
agent
.
bdi_agent
.
step
()
self
.
agent
.
bdi_agent
.
step
()
self
.
agent
.
bdi_intention_buffer
.
popleft
()
self
.
agent
.
bdi_intention_buffer
.
popleft
()
else
:
else
:
self
.
agent
.
bdi_agent
.
step
()
self
.
agent
.
bdi_agent
.
step
()
async
def
on_end
(
self
):
"""
async
def
parse_literal
(
msg
):
Coroutine called after the behaviour is done or killed.
functor
=
msg
.
split
(
"("
)[
0
]
"""
if
"("
in
msg
:
pass
args
=
msg
.
split
(
"("
)[
1
]
args
=
args
.
split
(
")"
)[
0
]
args
=
literal_eval
(
args
)
if
not
isinstance
(
args
,
tuple
):
args
=
(
args
,)
new_args
=
[]
for
arg
in
args
:
if
isinstance
(
arg
,
list
):
arg
=
tuple
(
arg
)
new_args
.
append
(
arg
)
args
=
tuple
(
new_args
)
else
:
args
=
None
return
functor
,
args
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