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
a1d9b3f0
Unverified
Commit
a1d9b3f0
authored
Jun 13, 2019
by
Sergio Frayle Pérez
Committed by
GitHub
Jun 13, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request
#1
from javipalanca/master
Refactor. Added some helpers like pause_bdi, resume_bdi. Now the asl …
parents
0cd7ef46
66ff51a8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
152 additions
and
147 deletions
+152
-147
.travis.yml
.travis.yml
+10
-13
AUTHORS.rst
AUTHORS.rst
+1
-1
basic.py
examples/basic.py
+8
-1
control.py
examples/control.py
+41
-29
counter.asl
examples/counter.asl
+16
-17
counter.py
examples/counter.py
+29
-29
master.asl
examples/master.asl
+16
-11
receiver.py
examples/receiver.py
+10
-2
sender.asl
examples/sender.asl
+3
-3
sender.py
examples/sender.py
+11
-2
slave.asl
examples/slave.asl
+4
-4
requirements_dev.txt
requirements_dev.txt
+1
-0
setup.cfg
setup.cfg
+1
-1
bdi.py
spade_bdi/bdi.py
+0
-0
test_spade_bdi.py
tests/test_spade_bdi.py
+0
-30
tox.ini
tox.ini
+1
-4
No files found.
.travis.yml
View file @
a1d9b3f0
...
...
@@ -3,9 +3,6 @@
language
:
python
python
:
-
3.6
-
3.5
-
3.4
-
2.7
# Command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install
:
pip install -U tox-travis
...
...
@@ -17,13 +14,13 @@ script: tox
# create the Github repo and add it to Travis, run the
# following command to finish PyPI deployment setup:
# $ travis encrypt --add deploy.password
deploy
:
provider
:
pypi
distributions
:
sdist bdist_wheel
user
:
sfp932705
password
:
secure
:
PLEASE_REPLACE_ME
on
:
tags
:
true
repo
:
sfp932705/spade_bdi
python
:
3.6
#
deploy:
#
provider: pypi
#
distributions: sdist bdist_wheel
#
user: sfp932705
#
password:
#
secure: PLEASE_REPLACE_ME
#
on:
#
tags: true
#
repo: sfp932705/spade_bdi
#
python: 3.6
AUTHORS.rst
View file @
a1d9b3f0
...
...
@@ -10,4 +10,4 @@ Development Lead
Contributors
------------
None yet. Why not be the first?
* Javi Palanca <jpalanca@gmail.com>
examples/basic.py
View file @
a1d9b3f0
import
argparse
from
spade_bdi.bdi
import
BDIAgent
a
=
BDIAgent
(
"BasicAgent@localhost"
,
"basicpasswd"
,
"basic.asl"
)
parser
=
argparse
.
ArgumentParser
(
description
=
'spade bdi master-server example'
)
parser
.
add_argument
(
'--server'
,
type
=
str
,
default
=
"localhost"
,
help
=
'XMPP server address.'
)
parser
.
add_argument
(
'--password'
,
type
=
str
,
default
=
"bdipassword"
,
help
=
'XMPP password for the agents.'
)
args
=
parser
.
parse_args
()
a
=
BDIAgent
(
"BasicAgent@"
+
args
.
server
,
args
.
password
,
"basic.asl"
)
a
.
start
()
import
time
...
...
examples/control.py
View file @
a1d9b3f0
import
argparse
import
time
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
class
MasterAgent
(
BDIAgent
):
async
def
setup
(
self
):
template
=
Template
(
metadata
=
{
"performative"
:
"BDI"
})
self
.
add_behaviour
(
self
.
BDIBehaviour
(),
template
)
template
=
Template
(
metadata
=
{
"performative"
:
"Modify"
})
self
.
add_behaviour
(
self
.
Modify
(
period
=
5
,
start_at
=
datetime
.
now
()),
template
)
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
)
self
.
add_behaviour
(
self
.
Behav4
(
start_at
=
datetime
.
now
()
+
timedelta
(
seconds
=
11
)),
template
)
class
Modify
(
PeriodicBehaviour
):
async
def
run
(
self
):
...
...
@@ -38,25 +35,40 @@ class MasterAgent(BDIAgent):
self
.
agent
.
bdi
.
remove_belief
(
'tipo'
,
'dec'
)
import
time
def
main
(
server
,
password
):
b
=
BDIAgent
(
"slave_1@{}"
.
format
(
server
),
password
,
"slave.asl"
)
b
.
bdi
.
set_belief
(
"master"
,
"master@{}"
.
format
(
server
))
future
=
b
.
start
()
future
.
result
()
c
=
BDIAgent
(
"slave_2@{}"
.
format
(
server
),
password
,
"slave.asl"
)
c
.
pause_bdi
()
future
=
c
.
start
()
future
.
result
()
a
=
MasterAgent
(
"master@{}"
.
format
(
server
),
password
,
"master.asl"
)
a
.
bdi
.
set_belief
(
"slave1"
,
"slave_1@{}"
.
format
(
server
))
a
.
bdi
.
set_belief
(
"slave2"
,
"slave_2@{}"
.
format
(
server
))
a
.
bdi
.
set_belief
(
'tipo'
,
'dec'
)
future
=
a
.
start
()
future
.
result
()
time
.
sleep
(
5
)
print
(
"Enabling BDI for slave2"
)
c
.
set_asl
(
"slave.asl"
)
c
.
bdi
.
set_belief
(
"master"
,
"master@{}"
.
format
(
server
))
time
.
sleep
(
5
)
print
(
"Disabling BDI for slave2"
)
c
.
pause_bdi
()
if
__name__
==
'__main__'
:
parser
=
argparse
.
ArgumentParser
(
description
=
'spade bdi master-server example'
)
parser
.
add_argument
(
'--server'
,
type
=
str
,
default
=
"localhost"
,
help
=
'XMPP server address.'
)
parser
.
add_argument
(
'--password'
,
type
=
str
,
default
=
"bdipassword"
,
help
=
'XMPP password for the agents.'
)
args
=
parser
.
parse_args
()
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"
)
a
.
bdi
.
set_belief
(
'tipo'
,
'dec'
)
time
.
sleep
(
5
)
print
(
"Enabling BDI for slave2"
)
c
.
set_asl
(
"slave.asl"
)
time
.
sleep
(
5
)
print
(
"Disabling BDI for slave2"
)
c
.
set_asl
(
None
)
try
:
main
(
args
.
server
,
args
.
password
)
except
KeyboardInterrupt
:
print
(
"Exiting..."
)
examples/counter.asl
View file @
a1d9b3f0
co
ntado
r(8).
t
ipo
(dec).
!ini
cio
.
co
unte
r(8).
t
ype
(dec).
!ini
t
.
+!ini
cio
+!ini
t
<-
.print("
Iniciando
....");
.print("
Starting
....");
!obj2.
+!obj2: t
ipo
(inc)
+!obj2: t
ype
(inc)
<-
.print("Incre
mentando
");
?co
ntado
r(X);
-+co
ntado
r(X+1);
.print("Incre
asing
");
?co
unte
r(X);
-+co
unte
r(X+1);
.wait(1000);
!obj2.
+!obj2: t
ipo
(dec)
+!obj2: t
ype
(dec)
<-
.print("Decre
mentando
");
?co
ntado
r(X);
-+co
ntado
r(X-1);
.print("Decre
asing
");
?co
unte
r(X);
-+co
unte
r(X-1);
.wait(1000);
!obj2.
+!obj2: not t
ipo
(_)
+!obj2: not t
ype
(_)
<-
.print("
Esperando
");
.print("
Waiting
");
.wait(1000);
!obj2.
\ No newline at end of file
!obj2.
examples/counter.py
View file @
a1d9b3f0
import
argparse
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
class
CounterAgent
(
BDIAgent
):
async
def
setup
(
self
):
template
=
Template
(
metadata
=
{
"performative"
:
"BDI"
})
self
.
add_behaviour
(
self
.
BDIBehaviour
(),
template
)
template
=
Template
(
metadata
=
{
"performative"
:
"B1"
})
self
.
add_behaviour
(
self
.
Behav1
(
period
=
1
,
start_at
=
datetime
.
now
()),
template
)
self
.
add_behaviour
(
self
.
Behav1
(
period
=
1
,
start_at
=
datetime
.
now
()),
template
)
template
=
Template
(
metadata
=
{
"performative"
:
"B2"
})
self
.
add_behaviour
(
self
.
Behav2
(
period
=
5
,
start_at
=
datetime
.
now
()),
template
)
self
.
add_behaviour
(
self
.
Behav2
(
period
=
5
,
start_at
=
datetime
.
now
()),
template
)
template
=
Template
(
metadata
=
{
"performative"
:
"B3"
})
self
.
add_behaviour
(
self
.
Behav3
(
period
=
10
,
start_at
=
datetime
.
now
()),
template
)
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
)
self
.
add_behaviour
(
self
.
Behav4
(
start_at
=
datetime
.
now
()
+
timedelta
(
seconds
=
60
)),
template
)
class
Behav1
(
PeriodicBehaviour
):
async
def
on_start
(
self
):
self
.
co
ntador
=
self
.
agent
.
bdi
.
get_belief_value
(
"contado
r"
)[
0
]
self
.
co
unter
=
self
.
agent
.
bdi
.
get_belief_value
(
"counte
r"
)[
0
]
async
def
run
(
self
):
if
self
.
contador
!=
self
.
agent
.
bdi
.
get_belief_value
(
"contador"
)[
0
]:
self
.
contador
=
self
.
agent
.
bdi
.
get_belief_value
(
"contador"
)[
0
]
print
(
self
.
agent
.
bdi
.
get_belief
(
"contador"
))
if
self
.
counter
!=
self
.
agent
.
bdi
.
get_belief_value
(
"counter"
)[
0
]:
self
.
counter
=
self
.
agent
.
bdi
.
get_belief_value
(
"counter"
)[
0
]
print
(
self
.
agent
.
bdi
.
get_belief
(
"counter"
))
class
Behav2
(
PeriodicBehaviour
):
async
def
run
(
self
):
self
.
agent
.
bdi
.
set_belief
(
'co
ntado
r'
,
0
)
self
.
agent
.
bdi
.
set_belief
(
'co
unte
r'
,
0
)
class
Behav3
(
PeriodicBehaviour
):
async
def
run
(
self
):
try
:
t
ipo
=
self
.
agent
.
bdi
.
get_belief_value
(
"tipo
"
)[
0
]
if
t
ipo
==
'inc'
:
self
.
agent
.
bdi
.
set_belief
(
't
ipo
'
,
'dec'
)
t
ype
=
self
.
agent
.
bdi
.
get_belief_value
(
"type
"
)[
0
]
if
t
ype
==
'inc'
:
self
.
agent
.
bdi
.
set_belief
(
't
ype
'
,
'dec'
)
else
:
self
.
agent
.
bdi
.
set_belief
(
't
ipo
'
,
'inc'
)
self
.
agent
.
bdi
.
set_belief
(
't
ype
'
,
'inc'
)
except
Exception
as
e
:
print
(
"No belief 't
ipo
'."
)
print
(
"No belief 't
ype
'."
)
class
Behav4
(
TimeoutBehaviour
):
async
def
run
(
self
):
self
.
agent
.
bdi
.
remove_belief
(
'tipo'
,
'inc'
)
self
.
agent
.
bdi
.
remove_belief
(
'tipo'
,
'dec'
)
self
.
agent
.
bdi
.
remove_belief
(
'type'
,
'inc'
)
self
.
agent
.
bdi
.
remove_belief
(
'type'
,
'dec'
)
if
__name__
==
"__main__"
:
parser
=
argparse
.
ArgumentParser
(
description
=
'spade bdi master-server example'
)
parser
.
add_argument
(
'--server'
,
type
=
str
,
default
=
"localhost"
,
help
=
'XMPP server address.'
)
parser
.
add_argument
(
'--password'
,
type
=
str
,
default
=
"bdipassword"
,
help
=
'XMPP password for the agents.'
)
args
=
parser
.
parse_args
()
a
=
CounterAgent
(
"counter@localhost"
,
"bditest"
,
"counter.asl"
)
a
.
start
()
import
time
time
.
sleep
(
1
)
print
(
"started"
)
a
=
CounterAgent
(
"counter@"
+
args
.
server
,
args
.
password
,
"counter.asl"
)
a
.
start
()
import
time
time
.
sleep
(
1
)
print
(
"started"
)
examples/master.asl
View file @
a1d9b3f0
...
...
@@ -6,23 +6,29 @@
!obj2.
+!obj2: tipo(inc)
<-
.send("slave_1@localhost", tell, incrementar(2));
.send("slave_2@localhost", tell, incrementar(5));
<-
?slave1(X);
?slave2(Y);
.send(X, tell, incrementar(2));
.send(Y, tell, incrementar(5));
.wait(2000);
!obj2.
+!obj2: tipo(dec)
<-
.send("slave_1@localhost", tell, decrementar(2));
.send("slave_2@localhost", tell, decrementar(5));
<-
?slave1(X);
?slave2(Y);
.send(X, tell, decrementar(2));
.send(Y, tell, decrementar(5));
.wait(2000);
!obj2.
+!obj2: not tipo(_)
<-
?slave1(X);
?slave2(Y);
.print("Finishing");
.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
.send(X, untell, incrementar(2));
.send(Y, untell, incrementar(5));
.send(X, untell, decrementar(2));
.send(Y, untell, decrementar(5)).
examples/receiver.py
View file @
a1d9b3f0
import
argparse
from
spade_bdi.bdi
import
BDIAgent
a
=
BDIAgent
(
"BDIReceiverAgent@localhost"
,
"receiverpasswd"
,
"receiver.asl"
)
a
.
start
()
if
__name__
==
'__main__'
:
parser
=
argparse
.
ArgumentParser
(
description
=
'spade bdi master-server example'
)
parser
.
add_argument
(
'--server'
,
type
=
str
,
default
=
"localhost"
,
help
=
'XMPP server address.'
)
parser
.
add_argument
(
'--password'
,
type
=
str
,
default
=
"bdipassword"
,
help
=
'XMPP password for the agents.'
)
args
=
parser
.
parse_args
()
a
=
BDIAgent
(
"BDIReceiverAgent@"
+
args
.
server
,
args
.
password
,
"receiver.asl"
)
a
.
start
()
examples/sender.asl
View file @
a1d9b3f0
...
...
@@ -2,6 +2,7 @@
+!start
<-
?receiver(X);
.print("sending a message ...");
.send("BDIReceiverAgent@localhost", achieve, hello("Hello World!"));
.print("sent a message").
\ No newline at end of file
.send(X, achieve, hello("Hello World!"));
.print("sent a message").
examples/sender.py
View file @
a1d9b3f0
import
argparse
from
spade_bdi.bdi
import
BDIAgent
a
=
BDIAgent
(
"BDISenderAgent@localhost"
,
"senderpasswd"
,
"sender.asl"
)
a
.
start
()
if
__name__
==
'__main__'
:
parser
=
argparse
.
ArgumentParser
(
description
=
'spade bdi master-server example'
)
parser
.
add_argument
(
'--server'
,
type
=
str
,
default
=
"localhost"
,
help
=
'XMPP server address.'
)
parser
.
add_argument
(
'--password'
,
type
=
str
,
default
=
"bdipassword"
,
help
=
'XMPP password for the agents.'
)
args
=
parser
.
parse_args
()
a
=
BDIAgent
(
"BDISenderAgent@"
+
args
.
server
,
args
.
password
,
"sender.asl"
)
a
.
bdi
.
set_belief
(
"receiver"
,
"BDIReceiverAgent@"
+
args
.
server
)
a
.
start
()
examples/slave.asl
View file @
a1d9b3f0
contador(0).
+incrementar(Inc)[source(S)]:
.substring("master@localhost",S,R)
+incrementar(Inc)[source(S)]:
master(M) & .substring(M,S,R)
<-
.print("increasing");
?contador(X);
.print(X);
-+contador(X+Inc).
+decrementar(Dec)[source(S)]:
.substring("master@localhost",S,R)
+decrementar(Dec)[source(S)]:
master(M) & .substring(M,S,R)
<-
.print("decreasing");
?contador(X);
.print(X);
-+contador(X-Dec).
-incrementar(Inc)[source(S)]:
.substring("master@localhost",S,R)
-incrementar(Inc)[source(S)]:
master(M) & .substring(M,S,R)
<-
.print("DELETING incrementar BELIEF from an untell message").
-decrementar(Dec)[source(S)]:
.substring("master@localhost",S,R)
-decrementar(Dec)[source(S)]:
master(M) & .substring(M,S,R)
<-
.print("DELETING decrementar BELIEF from an untell message").
requirements_dev.txt
View file @
a1d9b3f0
...
...
@@ -7,6 +7,7 @@ tox==3.5.2
coverage==4.5.1
Sphinx==1.8.1
twine==1.12.1
Click==7.0
pytest==3.8.2
pytest-runner==4.2
setup.cfg
View file @
a1d9b3f0
[bumpversion]
current_version = 0.1.0
commit = True
tag =
Tru
e
tag =
Fals
e
[bumpversion:file:setup.py]
search = version='{current_version}'
...
...
spade_bdi/bdi.py
View file @
a1d9b3f0
This diff is collapsed.
Click to expand it.
tests/test_spade_bdi.py
View file @
a1d9b3f0
...
...
@@ -5,34 +5,4 @@
import
pytest
from
click.testing
import
CliRunner
from
spade_bdi
import
spade_bdi
from
spade_bdi
import
cli
@pytest.fixture
def
response
():
"""Sample pytest fixture.
See more at: http://doc.pytest.org/en/latest/fixture.html
"""
# import requests
# return requests.get('https://github.com/audreyr/cookiecutter-pypackage')
def
test_content
(
response
):
"""Sample pytest test function with the pytest fixture as an argument."""
# from bs4 import BeautifulSoup
# assert 'GitHub' in BeautifulSoup(response.content).title.string
def
test_command_line_interface
():
"""Test the CLI."""
runner
=
CliRunner
()
result
=
runner
.
invoke
(
cli
.
main
)
assert
result
.
exit_code
==
0
assert
'spade_bdi.cli.main'
in
result
.
output
help_result
=
runner
.
invoke
(
cli
.
main
,
[
'--help'
])
assert
help_result
.
exit_code
==
0
assert
'--help Show this message and exit.'
in
help_result
.
output
tox.ini
View file @
a1d9b3f0
[tox]
envlist
=
py
27, py34, py35, py
36, flake8
envlist
=
py36, flake8
[travis]
python
=
3.6:
py36
3.5:
py35
3.4:
py34
2.7:
py27
[testenv:flake8]
basepython
=
python
...
...
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