Commit 0cd7ef46 by serfrape

Prepare for release in pypi. Migrated from pyson to python-agentspeak.

parent db843562
...@@ -30,7 +30,7 @@ class MasterAgent(BDIAgent): ...@@ -30,7 +30,7 @@ class MasterAgent(BDIAgent):
else: else:
self.agent.bdi.set_belief('tipo', 'inc') self.agent.bdi.set_belief('tipo', 'inc')
except Exception as e: except Exception as e:
print("No belief 'tipo'.", e) self.kill()
class Behav4(TimeoutBehaviour): class Behav4(TimeoutBehaviour):
async def run(self): async def run(self):
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
+!obj2: not tipo(_) +!obj2: not tipo(_)
<- <-
.print("Esperando"); .print("Finishing");
.send("slave_1@localhost", untell, incrementar(2)); .send("slave_1@localhost", untell, incrementar(2));
.send("slave_2@localhost", untell, incrementar(5)); .send("slave_2@localhost", untell, incrementar(5));
.send("slave_1@localhost", untell, decrementar(2)); .send("slave_1@localhost", untell, decrementar(2));
......
...@@ -5,40 +5,38 @@ ...@@ -5,40 +5,38 @@
from setuptools import setup, find_packages from setuptools import setup, find_packages
def parse_requirements(filename):
""" load requirements from a pip requirements file """
lineiter = (line.strip() for line in open(filename))
return [line for line in lineiter if line and not line.startswith("#")]
with open('README.rst') as readme_file: with open('README.rst') as readme_file:
readme = readme_file.read() readme = readme_file.read()
with open('HISTORY.rst') as history_file: with open('HISTORY.rst') as history_file:
history = history_file.read() history = history_file.read()
requirements = ['Click>=6.0', ] requirements = parse_requirements("requirements.txt")
setup_requirements = ['pytest-runner', ] setup_requirements = ['pytest-runner', ]
test_requirements = ['pytest', ] test_requirements = parse_requirements("requirements_dev.txt")
setup( setup(
author="Sergio Frayle Pérez", author="Sergio Frayle Pérez",
author_email='sfp932705@gmail.com', author_email='sfp932705@gmail.com',
classifiers=[ classifiers=[
'Development Status :: 2 - Pre-Alpha', 'Development Status :: 4 - Beta',
'Intended Audience :: Developers', 'Intended Audience :: Developers',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Natural Language :: English', 'Natural Language :: English',
"Programming Language :: Python :: 2",
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.7',
], ],
description="Implement BDI Agents based on the SPADE MAS Platform", description="Plugin for SPADE 3 MAS platform to implement BDI Agents.",
entry_points={
'console_scripts': [
'spade_bdi=spade_bdi.cli:main',
],
},
install_requires=requirements, install_requires=requirements,
license="GNU General Public License v3", license="GNU General Public License v3",
long_description=readme + '\n\n' + history, long_description=readme + '\n\n' + history,
......
...@@ -4,16 +4,16 @@ import json ...@@ -4,16 +4,16 @@ import json
from ast import literal_eval from ast import literal_eval
from loguru import logger from loguru import logger
from collections import deque from collections import deque
import pyson import agentspeak as asp
import pyson.runtime import agentspeak.runtime
import pyson.stdlib import agentspeak.stdlib
from spade.behaviour import CyclicBehaviour from spade.behaviour import CyclicBehaviour
from spade.agent import Agent from spade.agent import Agent
from spade.template import Template from spade.template import Template
from spade.message import Message from spade.message import Message
PERCEPT_TAG = frozenset( PERCEPT_TAG = frozenset(
[pyson.Literal("source", (pyson.Literal("percept"), ))]) [asp.Literal("source", (asp.Literal("percept"), ))])
class BDIAgent(Agent): class BDIAgent(Agent):
...@@ -47,8 +47,8 @@ class BDIAgent(Agent): ...@@ -47,8 +47,8 @@ class BDIAgent(Agent):
self.asl_file = None self.asl_file = None
def set_env(self): def set_env(self):
self.bdi_env = pyson.runtime.Environment() self.bdi_env = asp.runtime.Environment()
self.bdi_actions = pyson.Actions(pyson.stdlib.actions) self.bdi_actions = asp.Actions(asp.stdlib.actions)
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
...@@ -60,14 +60,14 @@ class BDIAgent(Agent): ...@@ -60,14 +60,14 @@ class BDIAgent(Agent):
def add_actions(self): def add_actions(self):
@self.agent.bdi_actions.add(".send", 3) @self.agent.bdi_actions.add(".send", 3)
def _send(agent, term, intention): def _send(agent, term, intention):
receiver = pyson.grounded(term.args[0], intention.scope) receiver = asp.grounded(term.args[0], intention.scope)
ilf = pyson.grounded(term.args[1], intention.scope) ilf = asp.grounded(term.args[1], intention.scope)
if not pyson.is_atom(ilf): if not asp.is_atom(ilf):
return return
ilf_type = ilf.functor ilf_type = ilf.functor
mdata = {"performative": "BDI", mdata = {"performative": "BDI",
"ilf_type": ilf_type, } "ilf_type": ilf_type, }
body = pyson.pyson_str(pyson.freeze( body = asp.asl_str(asp.freeze(
term.args[2], intention.scope, {})) 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))
...@@ -75,7 +75,7 @@ class BDIAgent(Agent): ...@@ -75,7 +75,7 @@ class BDIAgent(Agent):
@self.agent.bdi_actions.add(".custom_action", 1) @self.agent.bdi_actions.add(".custom_action", 1)
def _custom_action(agent, term, intention): def _custom_action(agent, term, intention):
arg_0 = pyson.grounded(term.args[0], intention.scope) arg_0 = asp.grounded(term.args[0], intention.scope)
print(arg_0) print(arg_0)
yield yield
...@@ -83,7 +83,7 @@ class BDIAgent(Agent): ...@@ -83,7 +83,7 @@ class BDIAgent(Agent):
def _a_function(x): def _a_function(x):
return x**4 return x**4
@self.agent.bdi_actions.add_function("literal_function", (pyson.Literal,)) @self.agent.bdi_actions.add_function("literal_function", (asp.Literal,))
def _literal_function(x): def _literal_function(x):
return x return x
...@@ -92,32 +92,32 @@ class BDIAgent(Agent): ...@@ -92,32 +92,32 @@ class BDIAgent(Agent):
new_args = () new_args = ()
for x in args: for x in args:
if type(x) == str: if type(x) == str:
new_args += (pyson.Literal(x),) new_args += (asp.Literal(x),)
else: else:
new_args += (x,) new_args += (x,)
term = pyson.Literal(name, tuple(new_args), PERCEPT_TAG) term = asp.Literal(name, tuple(new_args), PERCEPT_TAG)
found = False found = False
for belief in list(self.agent.bdi_agent.beliefs[term.literal_group()]): for belief in list(self.agent.bdi_agent.beliefs[term.literal_group()]):
if pyson.unifies(term, belief): if asp.unifies(term, belief):
found = True found = True
else: else:
self.agent.bdi_intention_buffer.append((pyson.Trigger.removal, pyson.GoalType.belief, belief, self.agent.bdi_intention_buffer.append((asp.Trigger.removal, asp.GoalType.belief, belief,
pyson.runtime.Intention())) asp.runtime.Intention()))
if not found: if not found:
self.agent.bdi_intention_buffer.append((pyson.Trigger.addition, pyson.GoalType.belief, term, self.agent.bdi_intention_buffer.append((asp.Trigger.addition, asp.GoalType.belief, term,
pyson.runtime.Intention())) asp.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."""
new_args = () new_args = ()
for x in args: for x in args:
if type(x) == str: if type(x) == str:
new_args += (pyson.Literal(x),) new_args += (asp.Literal(x),)
else: else:
new_args += (x,) new_args += (x,)
term = pyson.Literal(name, tuple(new_args), PERCEPT_TAG) term = asp.Literal(name, tuple(new_args), PERCEPT_TAG)
self.agent.bdi_intention_buffer.append((pyson.Trigger.removal, pyson.GoalType.belief, term, self.agent.bdi_intention_buffer.append((asp.Trigger.removal, asp.GoalType.belief, term,
pyson.runtime.Intention())) asp.runtime.Intention()))
def get_belief(self, key, source=False): def get_belief(self, key, source=False):
"""Get an agent's existing belief. The first belief matching """Get an agent's existing belief. The first belief matching
...@@ -186,26 +186,26 @@ class BDIAgent(Agent): ...@@ -186,26 +186,26 @@ class BDIAgent(Agent):
mdata = msg.metadata mdata = msg.metadata
ilf_type = mdata["ilf_type"] ilf_type = mdata["ilf_type"]
if ilf_type == "tell": if ilf_type == "tell":
goal_type = pyson.GoalType.belief goal_type = asp.GoalType.belief
trigger = pyson.Trigger.addition trigger = asp.Trigger.addition
elif ilf_type == "untell": elif ilf_type == "untell":
goal_type = pyson.GoalType.belief goal_type = asp.GoalType.belief
trigger = pyson.Trigger.removal trigger = asp.Trigger.removal
elif ilf_type == "achieve": elif ilf_type == "achieve":
goal_type = pyson.GoalType.achievement goal_type = asp.GoalType.achievement
trigger = pyson.Trigger.addition trigger = asp.Trigger.addition
else: else:
raise pyson.PysonError( raise asp.AslError(
"unknown illocutionary force: %s" % ilf_type) "unknown illocutionary force: %s" % ilf_type)
intention = pyson.runtime.Intention() intention = asp.runtime.Intention()
functor, args = await parse_literal(msg.body) functor, args = await parse_literal(msg.body)
message = pyson.Literal(functor, args) message = asp.Literal(functor, args)
message = pyson.freeze(message, intention.scope, {}) message = asp.freeze(message, intention.scope, {})
tagged_message = message.with_annotation( tagged_message = message.with_annotation(
pyson.Literal("source", (pyson.Literal(str(msg.sender)), ))) asp.Literal("source", (asp.Literal(str(msg.sender)), )))
self.agent.bdi_intention_buffer.append((trigger, goal_type, self.agent.bdi_intention_buffer.append((trigger, goal_type,
tagged_message, intention)) tagged_message, intention))
if self.agent.bdi_intention_buffer: if self.agent.bdi_intention_buffer:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment