filter_agents¶
Syntax¶
Parameters¶
agent-list- A list expression that evaluates to a list of agent ids.
test- A boolean expression used to evaluated the current agent against the given list of agents.
Returns¶
Returns a list of agents from the agent-list list that satisfies the test argument.
Description¶
This action filters the given agent-list using the provided test expression.
In the test expression, agent properties refer to the evaluating agent while
the special variable "_" refers to the evaluated agent from the given list.
For example, the test expression age < ask(_,age) would compare the
evaluating agent's age against the age of each agent in the list.
If multiple tests are desired, conditions can be chained together using the &
character.
It is an error if the given list contains a number that is not an agent ID.
Examples¶
The following line sets the variable my_older_opposite_sex_friends to the list of agents in the current agent's School that are older than and have the opposite sex of the current agent.
my_older_opposite_sex_friends = filter_agents(members(School), age < ask(_,age) & sex != ask(_,sex))