Search code examples
anylogic

Run a Machine only if another machine is not working and Vice a Versa


Below is my Model. I have machines M1 & M2. My Model

Below is my use case;

  • M1 must work, only when M2 is not working
  • M2 must work, only when M1 is not working
  • M1 & M2 can not operate at the same time

To achieve the above use case i wrote the below code with logic, if M2 is busy, i want to stop M1 and vice versa.

Code Block;

"On Enter" of M1;

if (M2.Busy()) { M1.suspend(); }

and

"On Enter" of M2;

if (M1.Busy()) { M2.suspend(); }

Unfortunately, the code ends up in the error, Busy() and Suspend() is undefined.

Any help on this will be appreciated.

Thanks in advance!


Solution

  • instead of a queue use a wait block.

    source->w1->m1->w2->m2

    in w1 and w2 on enter

    if(m2.size()==0 && m1.size()==0) w1.free(agent);
    

    in m1 and m2 on at exit, assuming m2 is priority, otherwise change the order

    if(w2.size()>0) w2.free(w2.get(0));
    else if(w1.size()>0) w1.free(w1.get(0));