Is it possible to add multiple agents at once to a population in Anylogic?

56 Views Asked by At

I am new to Anylogic. I am building an agent-based model of product delivery. I created a population of agents "trucks", initially empty. The maximum number of trucks available is 5. However, at a given day not all of them may be available (truck broken, driver ill etc.). So I want to add a certain (random from 1 to 5) number of agents (trucks) to the population. Agents will be created at the beginning of a day, and destroyed at the end of a day (so that next day I have another number of trucks available). How can I achieve that? The function "add_trucks()" seems to add only one agent.

I drew a statechart of a truck. Entry point action: add_trucks(uniform_discr(1,5)). Exit point: remove_trucks(this). But I do not have any single truck at the beginning.

1

There are 1 best solutions below

0
Felipe On
int numTrucks=uniform_discr(1,5);
 for(int i=0;i<numTrucks;i++){
       add_trucks();
    }