Search code examples
anylogic

How can I include variation in Source Agent Size in anylogic?


I am trying a create a model where I need to introduce a source (Lets call it customer). There will be three categories of customer

Category 1: Only 1 customer will enter at a probability of 50%

Category 2: 3 customers will arrive at a probability of 25%

Category 3: 5 customers will arrive at a probability of 25%

I havent started creating the model, so I cannot share a screenshot.


Solution

    1. Set the source to "on call of inject()" method.
    2. Setup an event that triggers whenever needed.
    3. In the event action code, you can use this code:

    if (randomTrue(0.5) { // 50 % overall
        mySource.inject(1);
    } else if (randomTrue(0.5) { // next 25% 
        mySource.inject(3);
    } else {
        mySource.inject(5); // remaining 25 %
    }