I have the following problem in the Anylogic environment. I have a stateChart
and two states: state1
and state2
. When the simulation starts, the system is in state1. Next, I put a button and write:
statechart.fireEvent("B");
traceln(statechart.getActiveSimpleState());
The system issues state A. Which is logical, since the transition has not been made yet and will be performed with an atomic delay. Then I wrote like this:
statechart.fireEvent("B");
event1.restart(0);
And for event1
itself, in the action field:
traceln(statechart.getActiveSimpleState());
The system still outputs state A. This is incomprehensible! After all, events are executed on the FIFO principle, and the transition to state from A to B was caused by me earlier. The only working but "dirty" way to do this is event1 with an atomic delay event1. restart(1e-6);
, but this method does not seem optimal.
Another "bad" way is to stop the model immediately after the fireEvent, take a step (getEngine().step();
), the state changes, and restart it with traceln(statechart.getActiveSimpleState());
. But stopping the model, of course, is undesirable.
Has anyone solved a similar problem and why does .restart(0)
get to the top of the list of events?
The event schedule selection is NOT FIFO. It has been set to LIFO by default since AnyLogic 8.6.0.
However, you can change it yourself via getEngine().setSimultaneousEventsSelectioMode(...)
. Check the description: