Tania Furcha
Tania Furcha

Reputation: 3

Sequentially generating multiple agents in AnyLogic

How to genarate agents in the block "source"? For instance,first one agent, than the two agents, the three agents, than again the one agents, the two, the three and so on.

Upvotes: 0

Views: 664

Answers (1)

Felipe
Felipe

Reputation: 9431

I think there are many ways to do this... But strictly subjected to your question I will propose 2 solutions:

SOLUTION 1
You can use the function inject. You can choose arrivals defined by "calls of inject() function. inject source

Then you can use an event that runs every second for example and create a variable called arrivals as an int with initial value 1

In the event then you can do:

source.inject(arrivals);
if(arrivals==3){
    arrivals=1;
}else{
    arrivals++;
}

SOLUTION 2
If you don't want to use an event, you can do it directly in the source, choosing Arrivals defined by rate (or something else) and check on "multiple agents per arrivals" where you will use the variable arrivals on "agents per arrivals". You will create another varialbe arrivalsCounter that will start with 1 and will be an int.

Then you can use the following code:

if(arrivalsCount==arrivals){
    if(arrivals==3)
        arrivals=1;
    else
        arrivals++;
    arrivalsCount=1;
}else{
     arrivalsCount++;
}

This is the image of the source configuration for your reference:

enter image description here

Upvotes: 1

Related Questions