Search code examples
simulationanylogicagent-based-modeling

How do I use enter and exit blocks in Anylogic for transferring agents across agent types and their respective flow diagrams?


I am currently working on a simulation model of a battery swapping station.

So, In my model I have declared charger as an agent type with its own parameter and a flow diagram and the "main" has 2 flow diagrams (total 3).

I have 2 sets of enter and exit blocks, one of them is for sending the fully charged battery from "main flow diagram" to "Charger flow diagram" and the other set sends a discharged battery from the "charger flow diagram" to the "main flow diagram".

I have added 5 charger agents in my main flow diagram with name Spot_1, Spot_2...., I want to access these enter-exit blocks of both main and charger. Initially I tried to access them in the main diagram only , but was unsuccessful(Syntax: Spot_1.enter.take(this)). Then I constructed a statechart in the "Car" agent type and tried to access these blocks from there but was not able to do so.

current syntax that are showing error: main.Old_Battery_In.take(this); main.Check_for_Availability.isBlocked() == false ; main.Spot_1.New_Battery_In.take (this);

I am also adding an image that has the statechart and the codeenter image description here

Old_Battery_In is an enter block in main, Check_for_Availability is a hold block in main, New_Battery_In is an enter block in charger

Please, can anyone suggest a solution


Solution

  • To be able to access a block in main from an Agent Type, you need to have a population of that type in main, even if empty. Drag and drop the "Agent" element from the Agent palette to main, choose the type that is trying to access main and make it initially empty. After that, if you run again, main should become accessible.