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¶
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, 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 using next and default¶
Transition rule probabilities for next depend on the prob clause at the end
of each rule (with a default clause of prob(1), or 100%). If the
probabilities 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.
Suppose we have three states A, B, and C, and we are writing transition
rules for state A. Suppose we want to have agents less than 10 years old
transition from A to B with probability 0.25 and to state C with
probability 0.75 (i.e. all other agents should always transition to state C).
The preferred code for this situation would be:
If an agent less than 10 years old is in state A then the if() statement is
the only qualifying transition rule, so the tentative probability of going to
state B is set to 0.25. Because the total probability is less than 1.0, the
default next state rule applies, and the probability of going to C is set
to 0.75 = 1.0 - 0.25.
If an agent 10 or older is in state A then there are no qualifying transition
rules, so the total probability equals 0.0; In this case the default
transition rule applies and sets the probability of going to state C to 1.0 =
1.0 - 0.0.
The following code would lead to incorrect results:
Things work fine for agents 10 or older, but if an agent less than 10 years old
is in state A then both transition rules apply. The if statement sets
the tentative probability of going to state B to 0.25. The next statement
sets the tentative probability of going to C to 1.0. The Total is 1.25 = 0.25
+ 1.0, so the probabilities are normalized to
and
which are not the desired results.
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 rules is applied. For example, consider this snippet:
For all agents over age 10, the above code would lead to an infinite loop back
to state A, which is probelmatic because we do not wait in this state.
Examples¶
In the following example, the default transition state is MyDefaultState.
state Start {
wait(0)
if (is_group_agent(School)) then next(CheckEpidemic)
if (is_member(School)) then next(StudentSchoolOpen)
default(MyDefaultState)
}