Agents

The abce.Agent class is the basic class for creating your agents. It automatically handles the possession of goods of an agent. In order to produce/transforme goods you also need to subclass the abce.Firm or to create a consumer the abce.Household.

For detailed documentation on:

Trading, see Trade

Logging and data creation, see Observing agents.

Messaging between agents, see Messaging.

class abce.Agent(id, group, trade_logging, database, logger, random_seed, start_round, num_managers)[source]

Bases: abce.database.Database, abce.networklogger.NetworkLogger, trade.Trade, abce.messaging.Messaging

Every agent has to inherit this class. It connects the agent to the simulation and to other agent. The abce.Trade, abce.Database and abce.Messaging classes are included. You can enhance an agent, by also inheriting from abce.Firm. abce.FirmMultiTechnologies or abce.Household.

For example:

class Household(abce.Agent, abce.Household):
    def init(self, simulation_parameters, agent_parameters):
        self.num_firms = simulation_parameters['num_firms']
        self.type = agent_parameters['type']
        ...

    def selling(self):
        for i in range(self.num_firms):
            self.sell('firm', i, 'good', quantity=1, price=1)

    ...
aggregate()[source]

use in action list to create data

create(good, quantity)[source]

creates quantity of the good out of nothing

Use create with care, as long as you use it only for labor and natural resources your model is macro-economically complete.

Args:
‘good’: is the name of the good quantity: number
create_agent(AgentClass, group_name, parameters=None, agent_parameters=None)[source]

create a new agent.

Args:

AgentClass:
the class of agent to create. (can be the same class as the creating agent)
‘group_name’:
the name of the group the agent should belong to
parameters:
a dictionary of parameters
agent_parameters:
a dictionary of parameters

Example:

self.create_agent(BeerFirm, 'beerfirm',
                  parameters=self.parameters,
                  agent_parameters={'creation': self.round + 1})
create_timestructured(good, quantity)[source]

creates quantity of the time structured good out of nothing. For example:

self.creat_timestructured('capital', [10,20,30])

Creates capital. 10 units are 2 years old 20 units are 1 year old and 30 units are new.

It can alse be used with a quantity instead of an array. In this case the amount is equally split on the years.:

self.creat_timestructured('capital', 60)

In this case 20 units are 2 years old 20 units are 1 year old and 20 units are new.

Args:
‘good’:
is the name of the good
quantity:
an arry or number
date()[source]

If ABCE is run in calendar mode (via abce.Simulation.declare_calendar()), date shows the current date.:

self.date().day self.date().month self.date().year self.date().weekday() # the weekday as a number Monday being 0 self.date().toordinal() #

The date works like python’s date object

delete_agent(group_name, id, quite=True)[source]

This deletes an agent, an agent can delete itself. There are two ways of deleting an agent. By default, quite is set to True, all future messages to this agent are deleted. If quite is set to False agents are completely deleted. This makes the simulation faster, but if messages are send to this agents the simulation stops.

Args:

group_name:
group name of the agent
id:
the id of the agent to be deleted
quite:
whether the agent deletes incomming messages.
destroy(good, quantity=None)[source]

destroys quantity of the good. If quantity is omitted destroys all

Args:

'good':
    is the name of the good
quantity (optional):
    number

Raises:

NotEnoughGoods: when goods are insufficient
group = None

self.group returns the agents group or type READ ONLY!

id = None

self.id returns the agents id READ ONLY

init(parameters, agent_parameters)[source]

This method is called when the agents are build. It can be overwritten by the user, to initialize the agents. parameters and agent_parameters are the parameters given in abce.Simulation.build_agents()

name = None

self.name returns the agents name, which is the group name and the id seperated by ‘_’ e.G. “household_12” READ ONLY!

panel()[source]

use in action list to create panel data

possession(good)[source]

returns how much of good an agent possesses.

Returns:
A number.

possession does not return a dictionary for self.log(...), you can use self.possessions([...]) (plural) with self.log.

Example:

if self.possession(‘money’) < 1:
self.financial_crisis = True
if not(is_positive(self.possession(‘money’)):
self.bancrupcy = True
possessions()[source]

returns all possessions

round = None

self.round returns the current round in the simulation READ ONLY!