Conditional Behaviours

Agent Function Conditions

When defining agent functions the initial and end states for the executing agent must be specified. Following this, all agents in the specified initial state will execute the agent function and move to the end state. In order to allow agents in the same state to diverge an agent function condition must be added to the function.

Agent function conditions are executed by all agents before the main agent function, and must return either true or false. Agents which return true pass the function and continue to execute the agent function and transition to the end state.

Within agent function conditions a reduced read-only FGPU Device API is available. This only permits reading agent variables, reading environment variables and random number generation.

Example definition:

// This agent function condition only allows agents who's 'x' variable equals '1' to progress
    return FLAMEGPU->getVariable<int>("x") == 1;
// A model is defined
ModelDescription m("model");
// It contains an agent with 'variable 'x' and two states 'foo' and 'bar'
AgentDescription &a = m.newAgent("agent");
// The agent has an agent function which transitions agents from state 'foo' to 'bar'
AgentFunctionDescription &af1 = a.newFunction("example_function", ExampleFn);
// Only agents that pass function condition 'x_is_1' may execute the function and transition