Search code examples
anylogicagent-based-modelingstatechart

Checking agents in a Seize Block


I wonder how I can trigger a conditional state chart transition (located in an agent, Patient) by checking if a queue (located in Main in a Seize Block) contains patients with a certain characteristic (p_contaminated, boolean parameter here should be true in order for the transition to trigger). I.e., if the queue contains one Patient with p_contaminated = true, the statement should yield true in order to trigger the transition.

Picture showing the Main chart and the Patient chart. Emphasizing (with red) the mentioned Seize Block and the conditional transition that is wanted to be triggered


Solution

  • Do not use conditional transitions, ever. They have some quirks (not bugs but easy to work in unexpected ways if you are no crack) and can deteriorate your model performance massively.

    You can always replace them with message-based transitions.

    In your case, have setup as below: enter image description here

    every x seconds, leave Treatment with a timeout transition. Check your patient queue in AnyPatientFound and if true, move to GoToHallway, else return to Treatment

    AnyPatientFound should call a boolean function anyPatientContaimated that loops through all patients in your queue and returns true if any is contaminated, else false.