Welcome to ABM’s documentation!¶
agent-based-modelling¶
agentframework module¶
-
class
agentframework.
Agent
(env, agents, x, y)¶ Bases:
object
An Agent takes a random walk through a two-dimensional environment.
-
environment
¶ The environment in which the Agent is moving. A list of equal-length lists of integers.
-
env_height
¶ The height of the environment.
-
env_width
¶ The width of the environment.
-
y
¶ Integer. The Agent’s y-coordinate within the environment.
-
x
¶ Integer. The Agent’s x-coordinate within the environment.
-
distance_between
(agent)¶ Find Euclidean distance between this Agent and another Agent.
Parameters: agent – Another Agent.
-
eat
()¶ Define an agent’s eating of resource from environment.
-
move
()¶ Move agent with random unit-sized step in each of two dimensions.
-
-
class
agentframework.
Environment
(file)¶ Bases:
object
Transforms a CSV file into a 2-d environment with which an agent can interact.
-
env
¶ A list of equal-length lists of integers representing grass in a field.
-
-
class
agentframework.
Fox
(env, agents, x, y)¶ Bases:
agentframework.Agent
TODO: A Fox is an Agent that hunts rabbits and eats them.
-
class
agentframework.
Rabbit
(env, agents, x, y, lifespan)¶ Bases:
agentframework.Agent
A Rabbit is an Agent that eats grass, reproduces, ages, and dies.
-
die
()¶ When a Rabbit dies, it is removed from the list of living Rabbits.
-
eat
()¶ A Rabbit eats just like an Agent, but dies if it runs out of energy.
-
get_older
()¶ Rabbits age; and when their age exceeds their lifespan, they die.
-
mate
(range)¶ Mature female rabbits become pregnant whenever male is in range, and then give birth after ten steps.
Parameters: range – Integer. Distance within which Rabbits mate.
-
move
()¶ Rabbit moves just like an Agent, but uses energy to do so.
-
gui module¶
-
gui.
run
()¶ Runs the Graphical User Interface.
-
gui.
update
(frame_number)¶ Updates the visualization for matplotlib.
read_cmd module¶
This module reads parameters for the model from the command line, and defines the default parameters if none are specified.
-
read_cmd.
parameters
(cmd_line_input)¶ Read parameters defined from command line, or return with defaults if no explicit parameters set.
Parameters: cmd_line_input – List of strings read from command line by sys.argv. Return: Tuple (num_of_agents, lifespan, neighbourhood, num_of_iterations, animate)
run_model module¶
An agent-based model demonstrating population dynamics of mating rabbits.
This file is intended to be the main script run from the command line.
-
run_model.
create_rabbits
(environment, num_of_rabbits, coordinates, lifespan)¶ Make new Rabbits, and return them in a list.
Parameters: - environment – A list of equal-length lists of integers representing quantities of grass in a field.
- num_of_rabbits – An integer specifying how many rabbits will be created.
- coordinates – A list of dicts including “x” and “y” values.
- lifespan –
An integer specifying at what age these new rabbits will die.
- Return:
- A list of Rabbits.
-
run_model.
my_timer
(process)¶ Decorator function to time the process.
-
run_model.
rabbits_interact
(rabbits, neighbourhood=10)¶ Shuffle the rabbits and then make them interact.
Parameters: - rabbits – List of Rabbits.
- neighbourhood – Integer representing distance at which Rabbits will mate.
-
run_model.
run_model
()¶
-
run_model.
save_data
(environment, rabbits)¶ Saves data generated by running the model.
Write environment to CSV file, and Agent data to text file, and test data to CSV file.
Parameters: - environment – A list of equal-length lists of integers representing quantities of grass in a field.
- rabbits – List of Rabbits.
visualize module¶
-
visualize.
show_plot
(environment, rabbits, neighbourhood, num_of_iterations)¶ Shows animated plot of rabbits’ movements.
Parameters: - environment – A list of equal-length lists of integers representing quantities of grass in a field.
- rabbits – List of Rabbits.
- neighbourhood – Integer representing distance at which Rabbits will mate.
- num_of_iterations – Integer. Maximum repetitions of agent interactions.