Search code examples
anylogic

remove agent from assembler queue part


I have a problem with my code in Anylogic. I would like to remove/delete the agents in the assembler with a button. If the agents are in the delay part of the assembler I can remove them (that's where my code works). However, the agents that are in the queue contains part of the assembler are not deleted. I used the following code in my button's action field, but when I click the button, the stocks in the queue part of the assembler remain. Does anyone know a solution for this?

Picture of my model in Anylogic

My code to remove/delete the agents from the queue part of the assembler:

while(Lager_Oberteile.size() > 0) {
      Agent agent = Lager_Oberteile.removeFirst();
}
while(Lager_Plättchen.size() > 0) {
      Agent agent = Lager_Plättchen.removeFirst();
}

if (Klebestation.queueSize(1) > 0) {
     Agent agent = Klebestation.queueGet(1, 0);
     Klebestation.remove(agent);  
}    
if (Klebestation.queueSize(2) > 0) {
     Agent agent = Klebestation.queueGet(2, 0);
     Klebestation.remove(agent);       
} 

if (Klebestation.delaySize() == 1) {
     Agent agent = Klebestation.delayGet(0);
     Klebestation.remove(agent);
}

offene_Aufträge = 0;
Stopp1.unblock();
Stopp2.unblock();

Solution

  • You can remove all agents in the queue using:

    int numAgents = assembler.queue1.size();
    for (int i=0; i<numAgents; i++) {
        assembler.queue1.remove(0);
    }
    

    You may be confused because the visual counter will not jump back to zero: enter image description here

    However, this only shows how many agents have entered that queue. You can always test such things with tracelns:

    enter image description here

    So use the code for all 5 queues and you are good.