Reputation: 91
I'm having trouble with AnyLogic...what I want is to write a code to move an agent to a specified state inside a statechart...how can I do?
I have the following statechart
At the beginning I want to put 1 agent inside Ip...
I have opened some example Models and I have understood that I should write in the "on startup" section in "main"
Insetead of "????" I want to say "go to state Ip"...how can I do???
With the same code I would like also to create a button...is it possible?
Thanks for the support!!!
Upvotes: 1
Views: 667
Reputation: 9421
First of all: to move from one state to the other, there must be a transition between these states.
But if you want to choose a random state in the beginning of the simulation, you need to create a branch in the beginning of your statechart and connect that branch to each one of the different states you have there as you can see in the following image:
I added a variable called randomstuff so in your branch you define the value of the variable
randomstuff=uniform_discr(5);
And in each transition from the branch to a state you do as a condition:
randomstuff==3;
for example for one of the branches... similar with all the other branches
Upvotes: 1