Agents¶
The abcEconomics.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 abcEconomics.Firm or
to create a consumer the abcEconomics.Household.
For detailed documentation on:
Trading, see Trader
Logging and data creation, see Observing agents and logging.
Messaging between agents, see Messenger.
-
class
abcEconomics.Agent(id, agent_parameters, simulation_parameters, name=None)[source]¶ Bases:
abcEconomics.logger.logger.Logger,abcEconomics.agents.trader.Trader,abcEconomics.agents.messenger.Messenger,abcEconomics.agents.goods.GoodsEvery agent has to inherit this class. It connects the agent to the simulation and to other agent. The
abcEconomics.Trade,abcEconomics.LoggerandabcEconomics.Messengerclasses are included. An agent can also inheriting fromabcEconomics.Firm,abcEconomics.FirmMultiTechnologiesorabcEconomics.Householdclasses.Every method can return parameters to the simulation.
For example:
class Household(abcEconomics.Agent, abcEconomics.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) ... def return_quantity_of_good(self): return['good'] ... simulation = Simulation() households = Simulation.build_agents(household, 'household', parameters={...}, agent_parameters=[{'type': 'a'}, {'type': 'b'}]) for r in range(10): simulation.advance_round(r) households.selling() print(households.return_quantity_of_good())
-
group= None¶ self.group returns the agents group or type READ ONLY!
-
id= None¶ self.name returns the agents name, which is the group name and the id
-
init()[source]¶ This method is called when the agents are build. It can be overwritten by the user, to initialize the agents. Parameters are the parameters given to
abcEconomics.Simulation.build_agents().Example:
class Student(abcEconomics.Agent): def init(self, rounds, age, lazy, school_size): self.rounds = rounds self.age = age self.lazy = lazy self.school_size = school_size def say(self): print('I am', self.age ' years old and go to a school that is ', self.school_size') def main(): sim = Simulation() students = sim.build_agents(Student, 'student', agent_parameters=[{'age': 12, lazy: True}, {'age': 12, lazy: True}, {'age': 13, lazy: False}, {'age': 14, lazy: True}], rounds=50, school_size=990)
-
time= None¶ self.time, contains the time set with simulation.advance_round(time) you can set time to anything you want an integer or (12, 30, 21, 09, 1979) or ‘monday’
-