Search code examples
simulationanylogic

Check if agent connected to an agent is on the wait block - anylogic


Direct question: how to check if an agent is waiting in the wait block?

More details? below, thank you.


I was following Mr. Felipe's answer to a similar question (this one: Anylogic - Combined multiple items back to original owner )

On step number 4 of his answer, he said " On the passengerWait, on the onEnter action you will check if all the bags connected to the passenger are on the bagWait block... if they are... then you will free (wait.free(agent)) the passenger and the bags "

Do you know how to check this? I have the same problem between single patient and single drug.


Solution

  • I figured out how to do that:

    1. Make a new variable in the Passenger agent and call it variable_IsWaitingForBag
    2. Make a new variable in the Bag agent and call it variable_IsWaitingForPassenger
    3. In onEnter of passengerWait, use the following:
      if(agent.agentLink_myBag.getConnectedAgent().variable_IsWaitingForPassenger)
      {
      passengerWait.free(agent);
      bagWait.free(agent.agentLink_myPassenger.getConnectedAgent());
      }
      agent.variable_IsWaitingForBag=true;
      
    4. Do the opposite in onEnter of the bagWait block