if
Optionally execute an action or transition based on a given predicate.
Synopsis
if (predicate) then . . .
Description
The agent executes the given action or transition when the given predicate evaluates to
\(1\) (true
). The predicate is evaluated with respect to the current agent, and in
this manner an if
statement allows individual agents to behave
differently within the same state.
Options
predicate
An expression that evaluates to true or false (\(1\) or \(0\)).
Examples
In this example state, the statements are evaluated based on the agent’s age.
The final value of x
will be \(11\) for agents 10 yrs old or younger,
and \(21\) for all other agents.
state MyStateName {
if (age <= 10) then x = 10
if (age > 10) then then x = 20
x = x + 1
...
}
Here are some examples with if
in transition statements.
These states are taken from the SCHOOL
condition in the
school-closure
example that is discussed in the FRED Tutorials Documentation.
state Start {
wait(0)
if (is_group_agent(School)) then next(CheckEpidemic)
if (is_member(School)) then next(StudentSchoolOpen)
default(Excluded)
}
state CheckEpidemic {
wait(0)
if (school_closure_policy == LOCAL_CLOSURE) then next(CheckLocalEpidemic)
if (school_closure_policy == GLOBAL_CLOSURE) then next(CheckGlobalEpidemic)
default(CheckCalendar)
}