Messaging

This is the agent’s facility to send and receive messages. Messages can either be sent to an individual with messaging.Messaging.message() or to a group with messaging.Messaging.message_to_group(). The receiving agent can either get all messages with messaging.Messaging.get_messages_all() or messages with a specific topic with messaging.Messaging.get_messages().

class abce.messaging.Messaging[source]

Bases: object

get_messages(topic='m')[source]

self.messages() returns all new messages send with message() (topic=’m’). The order is randomized. self.messages(topic) returns all messages with a topic.

A message is a string with the message. You can also retrieve the sender by message.sender_group and message.sender_id and view the topic with ‘message.topic’. (see example)

If you are sending a float or an integer you need to access the message content with message.content instead of only message.

! if you want to recieve a float or an int, you must msg.content

Returns a message object:
msg.content:
returns the message content string, int, float, …
msg:
returns also the message content, but only as a string
sender_group:
returns the group name of the sender
sender_id:
returns the id of the sender
topic:
returns the topic

Example:

... agent_01 ...
self.messages('firm_01', 'potential_buyers', 'hello message')

... firm_01 - one subround later ...
potential_buyers = get_messages('potential_buyers')
for msg in potential_buyers:
   print('message: ', msg)
   print('message: ', msg.content)
   print('group name: ', msg.sender_group)
   print('sender id: ', msg.sender_id)
   print('topic: ', msg.topic)
get_messages_all()[source]

returns all messages irregardless of the topic, in a dictionary by topic

A message is a string with the message. You can also retrieve the sender by message.sender_group and message.sender_id and view the topic with ‘message.topic’. (see example)

If you are sending a float or an integer you need to access the message content with message.content instead of only message.

message(receiver_group, receiver_id, topic, content)[source]
send(receiver, topic, content)[source]

sends a message to agent. Agents receive it at the beginning of next round with get_messages() or get_messages_all().

Args:

receiver:
    The name of the receiving agent a tuple (group, id).
    e.G. ('firm', 15)

topic:
    string, with which this message can be received

content:
    string, dictionary or class, that is send.

Example:

... household_01 ...
self.message('firm', 01, 'quote_sell', {'good':'BRD', 'quantity': 5})

... firm_01 - one subround later ...
requests = self.get_messages('quote_sell')
for req in requests:
    self.sell(req.sender, req.good, reg.quantity, self.price[req.good])

Example2:

self.message('firm', 01, 'm', "hello my message")