default¶
Syntax¶
Parameters¶
state_name- Optional. The name of a state within the current condition to use as the target of the agent transitions.
Description¶
Important
This is a special action which cannot appear within an if statement or loop!
This action defines the default transition from the current state to a new state. An agent entering the associated state will typically transition to a new state after a defined waiting period. If an agent does not satisfy a transition rule using next_if or next_with_prob, then the agent is transitioned to the default transition state.
If default() is invoked with no arguments, then the current agent will
transition to back into the state that it was already in.
Note
A state can only have one default transition. It cannot be conditionally
defined.
The difference between transition rules¶
There are three types of transition rules:
next_with_prob- Defines a transition with an explicit probabilitynext_if- Defines a transition that applies with 100% probability when its condition is truedefault- Defines the transition that applies when other rules don't apply or for the remaining probability
A state can only have one default transition rule, and it cannot be
conditionally defined. However, multiple next_with_prob and next_if rules
can be defined within a state.
All transition rule probabilities are considered together. For
next_with_prob, the probability is explicitly specified. For next_if, the
probability is 100% when the condition is true, and 0% when false.
If the combined probabilities from all applicable transition rules (including
next_with_prob and next_if) sum to more than 1.0, they are normalized so
that the sum is exactly 1.0. If the probabilities sum to less than 1.0, the
default rule is assigned the remaining probability.
Example: Combined age-based transitions¶
Suppose we have three states A, B, and C, and we are writing transition
rules for state A. If we want agents less than 10 years old to transition
from A to B with probability 0.25 and to state C with probability 0.75
(and all other agents to always transition to state C), we would write:
state A {
age_based_prob = 0
if (age() < 10) {
age_based_prob = 0.25
}
wait(0)
next_with_prob(B, age_based_prob)
default(C)
}
For agents less than 10 years old, the probability of going to state B is
0.25. Because the total probability is less than 1.0, the default transition
rule applies with probability 0.75 = 1.0 - 0.25.
For agents 10 or older, age_based_prob remains 0, so the total probability
equals 0.0. In this case, the default transition rule applies with
probability 1.0.
Missing Default Rule¶
If no default rule is included in a state, the default transition state is
the state itself, so these two snippets are equivalent:
This might lead to unexpected results if a missing default rule is applied. For example:
For all agents over age 10, the above code would lead to an infinite loop back
to state A, which is problematic because we do not wait in this state.
Examples¶
In the following example, the default transition state is MyDefaultState.
state Start {
wait(0)
next_if(CheckEpidemic, is_group_agent(School))
next_if(StudentSchoolOpen, is_member(School))
default(MyDefaultState)
}