Search code examples
javaanylogic

How to batch agents with similar parameters with different batch size?


I have an agent called products, and in this agent, I assigned a parameter called sp; in the simulation, I have the same agent with a different sp range from 1 to 5. I want to batch the agents with the same sp in the same batch, depending on the sp. So if I have 200 agents, 49 of them with sp equals 1, I would like to batch them in 4 batches since the batch size for this sp is 10, and the left 9 agents wait till next cycle, and for sp equals 2, I have 33 agents, and the batch size is 7, I would like to batch them in 4 batches and the left 5 agents wait till next cycle, and so on.

I really appreciate any help you can provide.

here is my last question, which is similar to this question: Anylogic: how to Batch agents with similar parameters?


Solution

  • follow the same logic as the answer from the previous question with a wait block followed by a batch block... on the on enter of the wait block you need to check if the conditions to batch are met...

    List <Product> sameSpProducts=findAll(self,s->s.sp==agent.sp);
    if(agent.sp==1 && sameSpProducts.size()==10){
        theBatchBlock.set_batchSize(10);
        for(Product p : sameSpProducts){
           self.free(p);
        }
    }
    

    same for all the others sp values... you can make this more efficient by having an array with the sp values and looping through that array (same as answered in the previous question)... this represents the general ideal