Reputation: 2213
My understanding is that attractors within nodes should have a capacity of 1, in the sense that in a 3D animation, there should only be one agent per attractor. When I run the model, I am seeing two agent shapes on the same attractor while other attractors are empty.
Is this normal behavior? Is there a way to prevent this from happening?
Note that this is not happening all the time, but as the model is running, sometimes agents go to empty attractors, while other times they go to one that already has an agent.
Upvotes: 2
Views: 723
Reputation: 3975
One option is to create a collection, simple ArrayList will do, of all the attractors
Then in the Process Modelling Block (PML) where you setup the attractor you have a function that returns an Attractor. I supply the agent here so that we can keep track of what agent is sent to which attractor so that we can put the attractor back into the available pile once the agent leaves the attractor location.
Here is the getAttractor function
It gets a random available attractor and then also saves the agent that is taking it to a map
If you want to free the attractor you can simple call this at any point that the attractor is freed
attractorsAvailable.add(mapAgentPerAttractor.get(agent));
mapAgentPerAttractor.remove(agent);
Here is the final result as well as a comparison where we are replciating the problem you described
Upvotes: 2
Reputation: 9421
this is totally possible... and how to avoid depends on your model in particular.
The attractors ONLY define where your agents are going to be inside a node, and there's no rule that states that you can't have many agents in the same attractor.
AnyLogic sends the agents to the attractors in the order in which they are created, and if you have 10 attractors and 10 agents initially went to the attractors if agent 3 leaves the attractor, the next agent will not go to attractor 3, instead it will go to attractor 1, then the next one will go to attractor 2, following the same order...
If you want to avoid it in general, you should specify explicitly to what attractor your agent should go.
What i do is i create a class and i associate it to that attractor and set up a variable that defines if the attractor is occupied or not...
Then you need to create additional logic to send the agents somewhere else if all the attractors are occupied
Upvotes: 1