Search code examples
simulationanylogic

RESOURCE specifications and tracking of agent


I need to solve a problem, which due to my lack of Java training I can't solve. What is the code to write to trace the agent who took a resource? Let me explain better...I have a series of rooms, each agent who enters the structure takes a room which he keeps for his entire stay, and I would like to see in real-time, which rooms are occupied and by which agent. How can I do this? Thank you


Solution

  • You can simply save the resource seized to the agent and vice versa using variables, in the seize block.

    Here is a simple example

    I have a Person and a RoomResource agent, each with a variable of the other's type.

    enter image description here

    In this very simple flow chart with a source that creates persons, and a seize connected to a resource pool of RoomResource agents, and the resource units live in a population called roomResource.

    enter image description here

    You simply specify the following in the seize block

    agent.room = unit;
    unit.agent = agent;
    

    enter image description here

    You will see that agent represents the agent in the block, and unit represents the unit being seized from the resource pool

    enter image description here

    Now you can visually use this for your agents

    enter image description here

    Now you can see what Person occupies which room and which room is used for each person by accessing the variable