Space between agents in discrete-event simulation - anylogic

I have a question about space between agents. In my model I have agents generated from a source and then they enter a delay, after the delay the agents go into a a queue with a capacity of 1 but I have a preemption option. The agents that go into the preemption are supposed to move along a circled path (I used a delay block for this) but there should always be a certain space between the agents, e.g. 100 meters. How can I incorporate this in my model to make sure my agents are not too close to each other?

One way you can control the distance between your agents is to move them on a path using a dummy transporter instead of the moveTo block. Transporters allow you to define a minimum distance to obstacle that prevents the agents from getting too close to each other.

Two options if you mean the static queue with agents actually waiting:
1) if your queue size is 500 meters, define the maximum amount of agents allowed in that queue to 6 (so you have 100 meters of distance between each agent)
2) Use the PML settings block from the PML palette and define an initial capacity of animation location equal to 6 (if your queues are 500 meters)... but this applies to all the model, so maybe it won't be good enough.
If you want them to have 100 meters space while they are moving towards their objective through the path that represents the queue, then the answer depends heavily on your model and it cannot be answered with the info provided... you need in this case to control the agent movements adding some logic... but I don't know what logic is suitable for you.

Related

How to i make agents in AnyLogic avoid another moving agent?

I am trying to model an agent based model where a certain agent population of people avoid to get close to a single agent, a random moving VIP.
I have tried to useif (distanceTo(main.vip < restrictedArea)) ;moveTo(uniform(500),uniform(500))
The agent will, most of the time, move to its new random destination through the restricted area which i want to avoid
Either you use the Material-handling library (where the transporters have build-in collision avoidance).
Or you model it youself. For that, you need a cyclic event in your agent that constantly checks the distance to whatever other agent you are interested in. If below some threshold, you tell the agent to move elsewhere.
Note: the first option can be quite slow. The second is not trivial to implement. Less due to coding skills, more because having intelligent collision avoidance algorithms is not trivial

AnyLogic how to set attractor choice to both free and random

Is there a way to make attractor choice both free & random at the same time?
The problem I have with either on it's own is:
When the choice is set to Free - agents are using attractors in very predictable order based on attractor creation.
When the choice is set to Random - more than one agent is using an attractor at the same time, which I don't want.
Solution I found, but don't know how to implement correctly is in the following thread:
AnyLogic Attractor weird behavior
I tried to create an agent type (instead of a class) 'myAttractor' with a boolean variable inside (occupied or not occupied attractor), but I don't know how to assign that agent type to actual attractors within a node - if that is even possible?
Maybe there are other solutions to customise the attractor choice to achieve complete randomness with only one agent per attractor?
Many thanks in advance,
Peter
That is a good question and often a problem on the animation side of things.
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
Here is the setup for the map mapAgentPerAttractor
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
One can see in the bottom node there are only 8 dots available as some agents are on the same attractor...

Custom defined transporters colliding

I've created a simple transporter (think of it like a box on wheels) and I have two separate TransporterFleets that each contain one of these simple transporter agents. In the TransporterFleet blocks I specify a "Min distance to obstacle" = 0.5 meters; however when the simulation runs, the two separate transporters go right over each other from time-to-time.
Note that I have two separate TransporterFleet blocks because each transporter has certain paths that it cannot take.
What can I modify/add so that these transporters will never collide?
i had the same issue and suggestion from AL support was to increase transporters deceleration. If you have default value (1 m/s2) than it could be possible that transportesr cant break fast enough...

AnyLogic Attractor weird behavior

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.
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
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

Is there a way to record when (and how often) Transporters get within a certain distance of each other?

I have an AnyLogic simulation model using trucks and forklifts as agents (Transporter type), and among other things would like to identify each time one of them becomes within a certain distance of another one (example within 5 meters). I will record this count as a variable within the main space of the model. I am using path-guided navigation.
I have seen a method "agentsInRange" which will probably be able to do the trick, but am not sure where to call this from. I assume I should be able to use the AL functionality of "Min distance to obstacle" (TransporterFleet) and "Collision detection timeout" (TransporterControl)?
Thanks in advance!
Since there don't seem to be pre-built functions for this, afaik, the easiest way is to:
add an int variable to your transporter agent type counter
add an event to your transporter type checkCollision that triggers every second or so
in the event, loop across the entire population of transporters and count the number that are closer than X meters (use distanceTo(otherTransporter) and write your own custom code)
add that number to counter
Note that this might be very inefficient computationally as it is quite brute-force. But might be good enough :)