State represents a location of control with a particular set of reactions to conditions and/or events. A state can be either simple or, if it contains other states, composite. Control always resides in one of simple states, but the current set of reactions is a union of those of the current simple state and of all composite states containing it – i.e., a transition exiting any of these states may be taken.
Demo model: Statechart for Generic Resource Open the model page in AnyLogic Cloud. There you can run the model or download it (by clicking Model source files).
To draw a state
- Drag the State element from the Statechart palette onto the diagram of agent.
- In some cases (especially when you want to draw a composite state) it is more convenient to use drawing mode. To activate it, double-click the State element in the palette. Its icon will turn into . Now you can draw a state of the required size simply by dragging in the diagram.
- General
-
Name – The name of the state. The name is used to identify the state within the statechart.
Show name – If selected, the name of the state is displayed on a presentation diagram.
Ignore – If selected, the state is excluded from the model.
Fill color – Sets the fill color for the state. Click inside the control and choose a color from the set of most used ones, or choose some custom color using the Colors dialog box.
Entry action – Here you can type Java code to be executed when the statechart enters the state.
Exit action – Here you can type Java code to be executed when the statechart exits the state.
- Working with state programmatically
-
Function Description T getContainerState() Returns the upper level state of the current state or null if this state is at the topmost level (has no container state). Set<T> getFullState() Returns the unordered set containing this state and all composite states (if any) containing the current state.
Statechart<T> getStatechart(Agent agent) Returns the statechart for the given agent that owns the current state. Returns null if the agent has no statechart with the current state.
agent - the agent that owns the current state.Set<T> getStatesInside() Returns the unordered set of all states (both simple and composite) contained inside the current state. boolean isSimpleState() Returns true if the current state is a simple state; returns false if the current state is a composite state.
-
How can we improve this article?
-