GhettiG
GhettiG

Reputation: 91

AnyLogic - moving agents between states

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

enter image description here

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"

enter image description here

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

Answers (1)

Felipe
Felipe

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:

randomstuff

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

Related Questions