Defining Agents

Agents are the central component of FLAME GPU simulations, and are directly equivalent to agent-based modelling agents. However, they can also be used to represent other things such as scalar fields across the environment. Agents are represented by an AgentDescription object

Defining a New Agent Type

FLAMEGPU2 agents are associated with a particular model. As such they are created via a ModelDescription object and are initialised with a name:

# Create a new agent called 'predator' associated the model 'model'
predator = model.newAgent("predator")

Agent Variables

Agent variables should be used to store data which is unique to each instance of an agent, for example, each individual predator in a predator-prey simulation would have its own position and hunger level. Each variable has a name and a type. For a complete list of supported types, see TODO: reference page for available types.

Agent ID

All agents have a built in id variable. This is a number which uniquely identifies this agent. Each agent will automatically be assigned an ID when the simulation starts or the agent is birthed. There is currently no way to change the ID of an agent. The agent ID variable is of type id_t which is an unsigned int by default, but can be redefined if more IDs are required.

User Defined Variables

# Create two new floating point variables, x and y
predator.newVariableFloat("x")
predator.newVariableFloat("y")

# Create a new integer variable, hungerLevel
predator.newVariableInt("hungerLevel")

Agent Array Variables

Array variables can also be defined by providing a name and array length:

# Create an array variable called exampleArray which is an array of 3 integers
predator.newVariableArrayInt("exampleArray", 3)

Agent States

Agent states are usually used to group sets of behaviours. For example, a predator in a predator-prey simulation may have a resting state and a hunting state. All newly defined agent types will have a default state, but you can add additional states if you wish to. States can be defined through the AgentDescription object:

# Create two new states, resting and hunting
predator.newState("resting")
predator.newState("hunting")

Full Example Code From This Page

# Create a new agent called 'predator' associated the model 'model'
predator = model.newAgent("predator")

# Create two new floating point variables, x and y
predator.newVariableFloat("x")
predator.newVariableFloat("y")

# Create a new integer variable, hungerLevel
predator.newVariableInt("hungerLevel")

# Create an array variable called exampleArray which is an array of 3 integers
predator.newVariableArrayInt("exampleArray", 3)

# Create two new states, resting and hunting
predator.newState("resting")
predator.newState("hunting")

More Info