Home > front end >  Anylogic: While(true) Function for Wait Block
Anylogic: While(true) Function for Wait Block

Time:05-25

Hi I'm trying to simulate an Assembly Station, therefor i would like to coordinate the release of my material with a wait block. My process includes following steps:

3 Different Paths: Source --> Seize Transporter ---> Move ---> Wait Block ---> release ---> Assembler (See screenshot)

Model

I would like to release my Agent in their wait blocks when all agents arrived in their Blocks. The Problem that i'm facing right now is, that all 3 agents arrive on different times. For example Agent one is arriving After 10 min in the waitblock1, Agent 2 and 3 After 5min in the block 2 and 3. So Agent1 should check if the other agents arrived in their Blocks and then be released. Also Agent 2 and 3 should act the same, so that all 3 agents are released at the same time.

Therefor i added for example in the wait block 1 a while(true) loop to proof if there is an Agent in the wait block 2 and 3 and then release the Agent in the current wait block. From my logic i would add this code also to the wait block 2 and 3 so that finally all agents will be released

The code is in the "on Enter" Field of the "waitblock":

while(true) {if(wait1.size()>0 &wait2.size()>0)wait.free(agent);}

If I run the Model i get follwing error code: "Unreachable Code". To be honest i'm new in using Java but i would say the code should be right? Maybe my Methode to comparise the wait Blocks and release the agents is wrong. Anyway i would be glade if someone could help :)

thanks in Advance

CodePudding user response:

Put the the condition into the while() or add a break statement

while(wait1.size()>0 &wait2.size()>0)
   ; 
wait.free(agent);

Otherwise the loop will never end and code after be unreachable

CodePudding user response:

this is not how you do it, you can't use while(true) unless you run that in an independent thread

Also the and operator is written && and not &

so on the on enter of every block make a function, and on that function you will do the following more or less:

if(wait1.size()>0 && wait2.size()>0 && wait.size()>0){
     wait.free(wait.get(0));
     wait1.free(wait1.get(0));
     wait2.free(wait2.get(0));
}
 
  • Related