0
votes

I am simulating a distribution system in AnyLogic where products are transported with different vehicles around the world.

At the beginning the products are produced in one of many plants. Each product owns a variable v_destination1 (String) taht shows the next destination.

The agents (products) are in the agent type "plant", more specifically in a queue block. I want to write a code which calls a vehicle to enter the plant and pickup products. The difficulty is that the code must contain the following condition:
- the vehicle is called, if there are a minimum of 10 products with the same destination (variable v_destination1) in the queue block
These product agent should leave the queue block and enter a pickup block.

I have the following ideas but i dont know how to continue:

1.1 Creating a collection (c_waitingTruck) with all product that are in the queue
1.2 int count (c_waitingTruck, p -> p.v_destination1 ... --> Here I dont know how to write the correct condition
1.3 if (count >= 10) Checking if die minimum of 10 products is reached.

2.1 Creating a collection (c_waitingTruck) with all product that are in the queue
2.2 filter (c_waitingTruck, c -> c.v_destination1 ... --> same as in 1.2
2.3 if (filter.size() >= 10) {

Can someone help me? I would be really glad for any advice.

1

1 Answers

0
votes

Don't use a queue, use a wait block called wait. In the on enter of the wait block, check if the amount is satistifed

List <Product> products=findAll(wait,a->a.v_destination1.equals(agent.v_destination1);
if(products.size()>=10){
    //call truck, however you do that
   // then release your products into the queue that comes before the pickup block
    for(Product p : products){
        wait.free(p);
    }
}

I didn't test this code, so it might have an error, but that's the idea at least