How do I use getDistanceTravelled() to track the distance my 5 Transporters have travelled? - anylogic

im new to AnyLogic and Java so bear with me.
My Simulation uses 5 Transporters to transport Agents through a Prodcution (they take different Routes each time). I'm trying to track the Distance each individual Transporter travels until it returns to pick up a new Agent.
I think this is possible with the getDistanceTravelled() Function but I have some Questions on how to use the Function.
How do I identify each Transporter from my transporterFleet?
How do I track the Distance travelled for each Transporter?
How can I reset the Distance travelled when the Transporter has returned to pick up a new
Agent?
How can I store and visualize the Distance travelled for each Transporter ?
This is an example of the blocks im using to simulate one Route for the Transporters.
https://i.stack.imgur.com/XVjwp.png
I'm sorry if this is a lot to ask but I can't seem to get the hang of this Problem. Feel free to ask follow-up Questions if my explanation isn't enough. Any Help is appreciated.
Lars

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 get the distance of the route pedestrian choose

I am using the PedGoTo block in Anylogic pedestrian library to direct pedestrians to the nearest exit (TargetLine). But since there are walls between pedestrians and exits, I can't just calculate straight line distance. In PedGoTo Anylogic official reference guide, it says
In Reach target mode the path is automatically calculated by the library.
I wonder if there's a function to calculate this path like path = getPath(ped, targetLine), and I can get the distance of this route, like path.getDistance()?
Afaik there is no such method. The reason is that the Ped library constantly re-evaluates the path taken and adjusts it based on new conditions.
So if you want to compute the nearest exits, you have to do it manually. Easiest would be to use paths, as Jaco-Ben suggested.
However: This may not actually be a good idea, depending on your actual scenario. In reality, people also do NOT know the nearest exit, typically (unless it is trivial).
PS: Also check the example model on fire exit behavior
I don't think there is an API for the pedestrian library similar to what you have with the GIS map.
You can however record the distance as the pedestrian is traveling - and once you have these distances you can perhaps use them in a future scenario? You will need to manually record all the distances in a separate run and then store the values to be used in a next run.
Here is a simple examplke in case it helps you.
What I would do then is to run this for a number of locations that pedestrians will be at when they need to choose an exit. Store the final distance in a separate txt file with a starting location as the key... and then in the next run of your simulation, you use these distances as an approximation of the distance to the exits and let the pedestrain then decide where to go to based on their current location and shortest distance to the exist...
So for every agent, you find the nearest point you have a distance to exists for and then use that, plus the distance to the exists
This seems like a lot of work... but for now I don't see any other way. Would love to see if anyone gets a better solution!

Finding the shortest path in NetLogo

How to build a NetLogo agent who must try to find the shortest route between all of the given locations whilst also avoiding the given patches as those represent solid impassable objects.
If you google "shortest route algorithm" you'll find many, for example: https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
But you have massively under-specified the problem you are trying to solve. You want a single agent to solve this? Why not a swarm or class of agents? If just one agent why are you using NetLogo as a tool? Are the agents smart? Do they get smarter over time? Can 3 agents work together on exploring the terrain? Does this have to get solved just once or many times?
How much information is available to the agent? The whole world? Just the nearest radius R? Does the agent know in advance what the "given locations" are and what the obstacles are? Does the order in which the given-locations are visited matter?
This could be the classic "travelling salesman" problem, having to visit each of N cities with costs of travel between each pair being given. See https://en.wikipedia.org/wiki/Travelling_salesman_problem
Can the agent find ANY route, and then keep trying to improve it? Or must it work on the first pass? What's the stopping condition? How do you know when the best route you've found is the best possible route?
You should also look at the A* algorithm. https://en.wikipedia.org/wiki/A*_search_algorithm
There's a huge amount of prior work done on solving this class of problem but they're mostly computational -- ie, your agent could simply sit and plug numbers into software and compute an answer and never move. I don't think that's what you had in mind. But what DID you have in mind?

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 :)

Track driven distance of transporters in Anylogic

I have modelled a fleet of AGVs as agents through TransporterFleet and TransportControl blocks.
The AGVs navigate in free space between different conveyors and their home locations.
Is it possible in Anylogic to track the driven distance for each AGV?
The Transporter API includes a getDistanceTravelled() function since version 8.5.2
Try using the "Logging" feature as that typically tracks the distance covered by agents in your model.
If it doesn't work for free-space AGVs, you have to record it manually (recurring event every x time-units)