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
0e1b0552
Commit
0e1b0552
authored
Apr 16, 2019
by
serfrape
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create the bdi intentions buffer
Setting and removing of beliefs will be sent to the intention buffer, and on the BDIBehaviour the env step is called as many times as needed.
parent
d8c66903
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
9 deletions
+25
-9
bdi.py
spade_bdi/bdi.py
+25
-9
No files found.
spade_bdi/bdi.py
View file @
0e1b0552
...
@@ -3,6 +3,7 @@ import asyncio
...
@@ -3,6 +3,7 @@ import asyncio
import
json
import
json
from
ast
import
literal_eval
from
ast
import
literal_eval
from
loguru
import
logger
from
loguru
import
logger
from
collections
import
deque
import
pyson
import
pyson
import
pyson.runtime
import
pyson.runtime
import
pyson.stdlib
import
pyson.stdlib
...
@@ -48,6 +49,7 @@ class BDIAgent(Agent):
...
@@ -48,6 +49,7 @@ class BDIAgent(Agent):
def
__init__
(
self
,
jid
,
password
,
asl
=
None
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
jid
,
password
,
asl
=
None
,
*
args
,
**
kwargs
):
self
.
asl_file
=
asl
self
.
asl_file
=
asl
self
.
bdi_enabled
=
False
self
.
bdi_enabled
=
False
self
.
bdi_intention_buffer
=
deque
()
super
()
.
__init__
(
jid
,
password
,
*
args
,
**
kwargs
)
super
()
.
__init__
(
jid
,
password
,
*
args
,
**
kwargs
)
class
BDIBehaviour
(
CyclicBehaviour
):
class
BDIBehaviour
(
CyclicBehaviour
):
...
@@ -95,11 +97,15 @@ class BDIAgent(Agent):
...
@@ -95,11 +97,15 @@ class BDIAgent(Agent):
if
pyson
.
unifies
(
term
,
belief
):
if
pyson
.
unifies
(
term
,
belief
):
found
=
True
found
=
True
else
:
else
:
self
.
agent
.
bdi_agent
.
call
(
pyson
.
Trigger
.
removal
,
pyson
.
GoalType
.
belief
,
belief
,
self
.
agent
.
bdi_intention_buffer
.
append
((
pyson
.
Trigger
.
removal
,
pyson
.
GoalType
.
belief
,
belief
,
pyson
.
runtime
.
Intention
())
pyson
.
runtime
.
Intention
()))
# self.agent.bdi_agent.call(pyson.Trigger.removal, pyson.GoalType.belief, belief,
# pyson.runtime.Intention())
if
not
found
:
if
not
found
:
self
.
agent
.
bdi_agent
.
call
(
pyson
.
Trigger
.
addition
,
pyson
.
GoalType
.
belief
,
term
,
self
.
agent
.
bdi_intention_buffer
.
append
((
pyson
.
Trigger
.
addition
,
pyson
.
GoalType
.
belief
,
term
,
pyson
.
runtime
.
Intention
())
pyson
.
runtime
.
Intention
()))
# self.agent.bdi_agent.call(pyson.Trigger.addition, pyson.GoalType.belief, term,
# pyson.runtime.Intention())
def
remove_belief
(
self
,
name
,
*
args
):
def
remove_belief
(
self
,
name
,
*
args
):
"""Remove an existing agent's belief."""
"""Remove an existing agent's belief."""
...
@@ -110,8 +116,10 @@ class BDIAgent(Agent):
...
@@ -110,8 +116,10 @@ class BDIAgent(Agent):
else
:
else
:
new_args
+=
(
x
,)
new_args
+=
(
x
,)
term
=
pyson
.
Literal
(
name
,
tuple
(
new_args
),
PERCEPT_TAG
)
term
=
pyson
.
Literal
(
name
,
tuple
(
new_args
),
PERCEPT_TAG
)
self
.
agent
.
bdi_agent
.
call
(
pyson
.
Trigger
.
removal
,
pyson
.
GoalType
.
belief
,
term
,
self
.
agent
.
bdi_intention_buffer
.
append
((
pyson
.
Trigger
.
removal
,
pyson
.
GoalType
.
belief
,
belief
,
pyson
.
runtime
.
Intention
())
pyson
.
runtime
.
Intention
()))
# self.agent.bdi_agent.call(pyson.Trigger.removal, pyson.GoalType.belief, term,
# pyson.runtime.Intention())
def
get_belief
(
self
,
key
,
pyson_format
=
False
):
def
get_belief
(
self
,
key
,
pyson_format
=
False
):
"""Get an agent's existing belief. The first belief matching
"""Get an agent's existing belief. The first belief matching
...
@@ -207,9 +215,17 @@ class BDIAgent(Agent):
...
@@ -207,9 +215,17 @@ class BDIAgent(Agent):
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_agent
.
call
(
trigger
,
goal_type
,
self
.
agent
.
bdi_intention_buffer
.
append
((
trigger
,
goal_type
,
tagged_message
,
intention
)
tagged_message
,
intention
))
self
.
agent
.
bdi_agent
.
step
()
# self.agent.bdi_agent.call(trigger, goal_type,
# tagged_message, intention)
if
self
.
agent
.
bdi_intention_buffer
:
for
i
in
self
.
agent
.
bdi_intention_buffer
:
self
.
agent
.
bdi_agent
.
call
(
i
[
0
],
i
[
1
],
i
[
2
],
i
[
3
])
self
.
agent
.
bdi_agent
.
step
()
self
.
agent
.
bdi_intention_buffer
=
deque
()
else
:
self
.
agent
.
bdi_agent
.
step
()
async
def
on_end
(
self
):
async
def
on_end
(
self
):
"""
"""
...
...
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