def main():

    # para troca de mensagens esparsas entre leiloeiro e compradores
    f = Filter()
    f.performative = ACLMessage.INFORM

    agents = list()
    port = int(argv[1]) 

    logger = Logger()

    # criando objeto a ser leiloado
    objeto = ObjetoLeiloado('Vaso Antigo', 40)

    # criando agente leiloeiro
    agente_leiloeiro = AgenteLeiloeiro(
        AID(name=f'leiloeiro@localhost:{port}'),f, objeto, logger)
    agents.append(agente_leiloeiro)  

    port += 1
    numero_de_compradores=3

    for i in range(numero_de_compradores):
        # criando agentes compradores
        agent_dinheiro = randint(100,1000)
        agente_comprador = AgenteComprador(AID(name=f'comprador_{i}@localhost:{port+i}'), f, logger,agent_dinheiro)
        agents.append(agente_comprador)

    start_loop(agents)
def main():
    agents = []
    name = input("Enter name of User 1: ")
    aid1 = AID(name='{}@localhost:{}'.format(name, 20000))
    name = input("Enter name of User 2: ")
    aid2 = AID(name='{}@localhost:{}'.format(name, 20001))

    agents.append(ChatAgent(aid1, aid2, start=True))
    agents.append(ChatAgent(aid2, aid1))
    start_loop(agents)
示例#3
0
def main():

    c = 0
    agents_list = list()
    port = argv[1]

    goal_keeper = 'goalkeeper_{}@localhost:{}'.format(port, port)
    time_agent = agents.GoalKeeper(AID(name=goal_keeper))
    agents_list.append(time_agent)

    port =int(port)+ 1000
    winger1 = 'winger_{}@localhost:{}'.format(port, port)
    time_agent = agents.BallReceivingWinger(AID(name=winger1))
    agents_list.append(time_agent)
    
    
    participants = list()
    agent_name = 'attacker{}@localhost:{}'.format(port - 100, port - 100)
    participants.append(agent_name)
    agente_part_1 = Attacker(AID(name=agent_name), uniform(100.0, 500.0))
    agents_list.append(agente_part_1)

    agent_name = 'defender{}@localhost:{}'.format(port + 100, port + 100)
    participants.append(agent_name)
    agente_part_2 = Defender(AID(name=agent_name), uniform(100.0, 500.0))
    agents_list.append(agente_part_2)

    agent_name = 'Winger{}@localhost:{}'.format(port+99, port+99)
    agente_init_1 = PassingWinger(AID(name=agent_name), participants)
    agents_list.append(agente_init_1)


    agent_name = 'Striker_{}@localhost:{}'.format(port+2, port+2)
    participants.append(agent_name)
    agent_pub_1 = Striker(AID(name=agent_name))
    agents_list.append(agent_pub_1)

    msg = ACLMessage(ACLMessage.SUBSCRIBE)
    msg.set_protocol(ACLMessage.FIPA_SUBSCRIBE_PROTOCOL)
    msg.set_content('Goal!!')
    msg.add_receiver(agent_pub_1.aid)
    k = 10
    agent_name = 'Crowd_20010@localhost:20010'
    participants.append(agent_name)
    agent_sub_1 = Crowd(AID(name=agent_name), msg)
    agents_list.append(agent_sub_1)

    agent_name = 'Crowd_19990@localhost:19990'
    agent_sub_2 = Crowd(AID(name=agent_name), msg)
    agents_list.append(agent_sub_2)

    print("Starting match")
    start_loop(agents_list)
示例#4
0
def main():

    caminho = __initializeWorld__(False)

    agentes = list()
    
    agent_sensor = Sensors(AID(name='sensor'),caminho)
    agente_autonomo = AgenteSistemaAutonomo(AID(name='autonomo'))
    agente_conforto = AgenteSistemaConforto(AID(name='conforto'))
    
    agentes.append(agent_sensor)
    agentes.append(agente_autonomo)
    agentes.append(agente_conforto)

    start_loop(agentes)
def main():

    c = 0
    agents_list = list()
    port = argv[1]

    goal_keeper = 'goalkeeper_{}@localhost:{}'.format(port, port)
    time_agent = agents.GoalKeeper(AID(name=goal_keeper))
    agents_list.append(time_agent)

    port = int(port) + 1000
    winger1 = 'winger_{}@localhost:{}'.format(port, port)
    time_agent = agents.Winger(AID(name=winger1))
    agents_list.append(time_agent)

    port = int(port) + 1000
    winger2 = 'winger_{}@localhost:{}'.format(port, port)
    time_agent = agents.Winger(AID(name=winger2))
    agents_list.append(time_agent)

    port = int(port) + 1000
    attacker = 'attacker_{}@localhost:{}'.format(port, port)
    time_agent = agents.Striker(AID(name=attacker))
    agents_list.append(time_agent)

    port = int(port) + 1000
    defender = 'enemy_defender_{}@localhost:{}'.format(port, port)
    time_agent = agents.Defender(AID(name=defender))
    agents_list.append(time_agent)

    port = int(port) + 1000
    scorer = 'scorer_{}@localhost:{}'.format(port, port)
    time_agent = agents.Scorer(AID(name=scorer))
    agents_list.append(time_agent)

    print("Starting match")
    start_loop(agents_list)
示例#6
0
		message = ACLMessage(ACLMessage.INFORM)
		message.add_receiver(self.agent.receiver)
		message.set_content('Message #%d' % self.counter)
		self.send(message)
		self.counter += 1
		display_message(self.agent, 'Message sent to receiver.')



# Receiver Agent
class ReceiverAgent(Agent):
	def __init__(self, name, sender):
		super().__init__(name)
		self.sender = sender # Gets the local name of sender

	def setup(self):
		self.add_behaviour(ReceiveMessage(self))

class ReceiveMessage(CyclicBehaviour):
	def action(self):
		message = self.read()
		if message.sender.getLocalName() == self.agent.sender:
			display_message(self.agent, 'This is:  %s.' % message.content)



if __name__ == '__main__':
	receiver = ReceiverAgent('receiver', 'sender')
	sender = SenderAgent('sender', receiver.aid)
	start_loop([receiver, sender])
示例#7
0
from pade.acl.aid import AID
from pade.acl.messages import ACLMessage
from pade.behaviours.types import CyclicBehaviour, TickerBehaviour
from pade.core.agent import Agent
from pade.misc.utility import display, start_loop


class BlockerAgent(Agent):
    def setup(self):
        self.add_behaviour(BlockBehaviour(self))


class BlockBehaviour(CyclicBehaviour):
    def action(self):
        message = self.read()
        display(self.agent, 'Running my behaviour...')


if __name__ == '__main__':
    start_loop([BlockerAgent('blocker', ignore_ams=False)])
示例#8
0
        sequential.add_subbehaviour(Count1_10(self))
        sequential.add_subbehaviour(Count11_20(self))
        sequential.add_subbehaviour(Count21_30(self))
        # Adding 'sequential' into agent
        self.add_behaviour(sequential)


# Behaviour that counts from 1 to 10
class Count1_10(OneShotBehaviour):
    def action(self):
        for num in range(1, 11):
            display(self.agent, num)


# Behaviour that counts from 11 to 20
class Count11_20(OneShotBehaviour):
    def action(self):
        for num in range(11, 21):
            display(self.agent, num)


# Behaviour that counts from 21 to 30
class Count21_30(OneShotBehaviour):
    def action(self):
        for num in range(21, 31):
            display(self.agent, num)


if __name__ == '__main__':
    start_loop([SequentialAgent('seq')])
示例#9
0
from pade.behaviours.types import OneShotBehaviour
from pade.core.agent import Agent
from pade.misc.utility import display_message, start_loop

# Defining the HelloWorldAgent (inherits from Agent class)
class HelloWorldAgent(Agent):

	# This method will execute at agent startup
	def setup(self):
		# It adds the 'SayHello' behaviour in the agent
		self.add_behaviour(SayHello(self))


# Defining the SayHello behaviour
class SayHello(OneShotBehaviour):

	# This method executes the main actions of SayHello behaviour
	def action(self):
		# It shows a message, with date/hour information, in console
		display_message(self.agent, 'Hello world!')


# It starts the agent HelloWorldAgent with PADE
if __name__ == '__main__':
	# Defining a HelloWorldAgent object
	helloagent = HelloWorldAgent('hello')
	# Creating a list with agents that will be executed
	agents_list = [helloagent]
	# Passing the agent list to main loop of PADE
	start_loop(agents_list)
示例#10
0
from pade.behaviours.types import TickerBehaviour
from pade.core.agent import Agent
from pade.misc.utility import display_message, start_loop

'''
This example presents two different TickerBehaviour
running in paralell and in an alternating way
'''

class TicTacAgent(Agent):
	def setup(self):
		self.add_behaviour(TicBehaviour(self, 1))
		self.add_behaviour(TacBehaviour(self, 1))

class TicBehaviour(TickerBehaviour):
	def on_tick(self):
		display_message(self.agent, 'Tic')

class TacBehaviour(TickerBehaviour):
	def on_tick(self):
		display_message(self.agent, 'Tac')

if __name__ == '__main__':
	start_loop([TicTacAgent('tictac')])
示例#11
0
            display(self.agent, num)
            self.wait(
                1)  # I put this so that we can see the behaviours blocking
        self.unlock()  # Here ends the critical section (releases the lock)


# Behaviour that counts from 11 to 20
class Count11_20(OneShotBehaviour):
    def action(self):
        self.lock()
        display(self.agent, 'Now, I will count from 11 to 20 slowly:')
        for num in range(11, 21):
            display(self.agent, num)
            self.wait(1)
        self.unlock()


# Behaviour that counts from 21 to 30
class Count21_30(OneShotBehaviour):
    def action(self):
        self.lock()
        display(self.agent, 'Now, I will count from 21 to 30 slowly:')
        for num in range(21, 31):
            display(self.agent, num)
            self.wait(1)
        self.unlock()


if __name__ == '__main__':
    start_loop([Sequential('seq')])
示例#12
0
		self.add_behaviour(Count(self))


class Count(SimpleBehaviour):
	# Defining initial parameters to behaviour
	def __init__(self, agent):
		# This call to superclass is needed, passing the agent
		super().__init__(agent)
		# Defining counting variable
		self.counter = 1

	def action(self):
		display(self.agent, 'Counting #%d' % self.counter)
		self.counter += 1

	# This method indicates when the behaviour finishes.
	def done(self):
		if self.counter > 10:
			# The behaviour will dies when True is returned
			return True
		return False

	# This method is executed when the behaviour dies x_x
	def on_end(self):
		display(self.agent, 'Counting finished.')



if __name__ == '__main__':
	start_loop([CounterAgent('counter')])
        message.set_protocol(ACLMessage.FIPA_REQUEST_PROTOCOL)
        message.add_receiver(AID(name='ouvinte'))
        message.set_content('Ola, eu estou aqui!')

        self.behaviours.append(SenderComportamento(self, message))

        self.behaviours.append(ComportTemporal(self, 5.0, message))


class Listener(Agent):
    def __init__(self, aid):

        super(Listener, self).__init__(aid=aid, debug=False)

        self.behaviours.append(ListenerComportamento(self))


if __name__ == '__main__':

    agentes = list()

    sender_nome = 'sender@localhost:9000'
    sender = Sender(AID(name=sender_nome))
    agentes.append(sender)

    listener_nome = 'destinatario@localhost:9001'
    listener = Listener(AID(name=listener_nome))
    agentes.append(listener)

    start_loop(agentes)
示例#14
0
        self.call_later(4.0, self.send_message)

    def send_message(self):
        message = ACLMessage(ACLMessage.INFORM)
        message.set_protocol(ACLMessage.FIPA_REQUEST_PROTOCOL)
        message.add_receiver(self.recieverAgent)
        self.add_all_agents(message.receivers)
        nextn = self.n + 1
        text = "Give me the {}th prime number".format(nextn)
        display_message(self.aid.localname, "Sending message to next agent\n")
        msg = {"n": nextn, "text": text}
        message.set_content(msg)
        self.send(message)

    def add_all_agents(self, receivers):
        for receiver in receivers:
            self.agentInstance.table[receiver.localname] = receiver


if __name__ == "__main__":
    SieveOfEratosthenes()
    agentlist = []
    n = int(input("Enter the value of n: "))

    for i in range(1, 5):
        agentlist.append(FriendAgent(AIDArray[i], AIDArray[(i + 1) % 5]))

    agentlist.append(FriendAgent(AIDArray[0], AIDArray[1], n))

    start_loop(agentlist)
示例#15
0
from pade.behaviours.types import CyclicBehaviour
from pade.core.agent import Agent
from pade.misc.utility import display_message, start_loop


class TicTacAgent(Agent):
    def setup(self):
        self.add_behaviour(NoiseBehaviour(self))


class NoiseBehaviour(CyclicBehaviour):
    def action(self):
        display_message(self.agent, 'Tic-tac!')
        self.wait(1)  # The behaviour will sleep by 1 second


if __name__ == '__main__':
    tic = TicTacAgent('tictac')
    start_loop([tic])
示例#16
0
		super().__init__(name)
		self.ping = ping_aid # Gets the ping AID

	def setup(self):
		self.add_behaviour(PongTurn(self))

class PongTurn(CyclicBehaviour):
	def action(self):
		if self.agent.has_messages():
			message = self.agent.read()
			if message.sender == self.agent.ping:
				# Preparing a reply to 'ping'
				reply = message.create_reply()
				reply.set_content('PONG')
				display_message(self.agent, 'Turn: %s' % message.content)
				self.wait(0.5)
				# Sending the reply
				self.send(reply)


# ==== Starting main loop of PADE ====

if __name__ == '__main__':
	ping_aid = AID('ping') # Creates an AID for ping
	pong_aid = AID('pong') # Creates an AID for pong
	# Creates a PingAgent using the AID ping_aid and passing the address (AID) of PongAgent (pong_aid)
	ping = PingAgent(ping_aid, pong_aid)
	# Creates a PongAgent using the AID pong_aid and passing the address (AID) of PingAgent (ping_aid)
	pong = PongAgent(pong_aid, ping_aid)
	start_loop([ping, pong])
示例#17
0
from pade.misc.utility import display_message, start_loop
from pade.core.agent import Agent
from pade.acl.aid import AID
from sys import argv

class AgenteHelloWorld(Agent):
    def __init__(self, aid):
        super(AgenteHelloWorld, self).__init__(aid=aid)
        display_message(self.aid.localname, 'Hello World!')


if __name__ == '__main__':

    agents_per_process = 3
    c = 0
    agents = list()
    for i in range(agents_per_process):
        port = int(argv[1]) + c
        agent_name = 'agente_hello_{}@localhost:{}'.format(port, port)
        agente_hello = AgenteHelloWorld(AID(name=agent_name))
        agents.append(agente_hello)
        c += 1000

    start_loop(agents)Hello
示例#18
0
from pade.acl.aid import AID
from pade.acl.messages import ACLMessage
from pade.core.agent import Agent
from pade.misc.utility import display_message, start_loop
from pade.fmi import FmiAdapter


class FMIAgent(Agent):
    def __init__(self, aid, debug=False):
        super().__init__(aid, debug)
        self.fmi_adapter = FmiAdapter(self, self.on_message)
        self.behaviours.append(self.fmi_adapter)

    def on_message(self, message: ACLMessage):
        content = json.loads(message.content)
        display_message(self.aid.name, content)

        reply = message.create_reply()
        reply.set_content(
            json.dumps({
                'outputVariable':
                content['inputVariable'] * 2 + 2 * content['current_time']
            }))
        self.fmi_adapter.inform(reply)


if __name__ == "__main__":
    agent = FMIAgent(AID('fmi-agent@localhost:12345'))

    start_loop([agent])
示例#19
0
                if self.debug:
                    display_message(self.aid.name, 'Message stored')

        self.messages_buffer = dict()
        self.buffer_control = True

    @inlineCallbacks
    def register_message_in_db(self, sql_act):
        yield TWISTED_ENGINE.execute(sql_act)

    def react(self, message):
        super(Sniffer, self).react(message)
        if 'ams' not in message.sender.name:
            content = loads(message.content)
            if content['ref'] == 'MESSAGE':
                _message = content['message']
                if self.messages_buffer.get(message.sender.name) == None:
                    self.messages_buffer[message.sender.name] = [_message]
                else:
                    messages = self.messages_buffer[message.sender.name]
                    messages.append(_message) 

                if self.buffer_control:
                    #reactor.callLater(0.0000001, self.handle_store_messages)
                    reactor.callLater(5.0, self.handle_store_messages)
                    self.buffer_control = False

if __name__ == '__main__':
    sniffer = Sniffer(port=sys.argv[1])
    start_loop([sniffer])
示例#20
0
        say_biscoito = SayBiscoito(self)
        say_bolacha = SayBolacha(self)
        # Passing the same lock object to behaviours
        say_bolacha.add_lock(lock)
        say_biscoito.add_lock(lock)
        # Adding the behaviours in the agent
        self.add_behaviour(say_biscoito)
        self.add_behaviour(say_bolacha)


class SayBiscoito(CyclicBehaviour):
    def action(self):
        self.lock()  # Starts the critical section
        for _ in range(5):  # The agent will hold the lock by 5 prints
            display(self.agent, 'The correct name is "BISCOITO".')
            self.wait(0.5)
        self.unlock()  # Ends the critical section


class SayBolacha(CyclicBehaviour):
    def action(self):
        self.lock()
        # Here the agent will hold the lock only by 1 print, and
        # release it right away
        display(self.agent, '"BOLACHA" is the correct name.')
        self.unlock()


if __name__ == '__main__':
    start_loop([MutualExclusionAgent('mea')])
示例#21
0
#!coding=utf-8
from pade.misc.utility import start_loop
from sys import argv
from pade.acl.aid import AID
# Agents files
from colector import ColectorAgent
from classifier import ClassifierAgent

if __name__ == '__main__':
    agents_per_process = 1
    # c = 0
    agents = list()

    colector_name = 'colector'
    colector = ColectorAgent(AID(name=colector_name))
    agents.append(colector)

    for i in range(agents_per_process):
        # port = int(argv[1]) + c
        classifier_name = 'classifier{}'.format(i)
        classifier = ClassifierAgent(AID(name=classifier_name))
        agents.append(classifier)

        # c += 1000

    start_loop(agents)
 def run(self):
     self._loop_started = True
     start_loop(self.agents)