How to calcucalate the distance agent moved - anylogic

guys
Have the population of trucks in model, moving from city to city. How to calculate the distance, every truck has moved?

There are 2 ways... one very accurate that requires your cities to be agents, and the other less accurate that doesn't require that.
Option 1: (accurate, requires agents)
Your truck is moving from city1 to city2, both are agents and you want to know the distance between city1 and the truck (which is equal to the distance moved)
calculate: city1.distanceByRoute(truck) whenever you need to know the distance moved.
Option 2 (less accurate, doesn't requires agents)
Create a variable called initialTime=time(); (it takes the value time() when the truck starts the journey.
Calculate (time()-iniTime)*truck.getSpeed() whenever you want to know the distance moved.

Related

How to plot distance travelled on graph by agent(s) in Anylogic in Discrete Event Simulation?

Dear Anylogic Experts,
I am trying to calculate the cost based on distance travelled by the agents in GIS environment. Does anyone know how can I calculate this? The final graph function is supposed to look like this: Distance moved by Agent in km or meter multiplied by the Cost per km or meter.
The idea is to see which route will cost how much. The way I have moved agents in via PML. please see picture attached of the process taking place.
there is no default way for this, several options:
Turn on "Model execution logging" and you will get total travelled distance for each agent.
In your MoveTo blocks, log the departure and arrival location (lat/lon) of your agent and use getDistanceGIS(...) to log the total distance from your agent

Netlogo - selecting all turtles at a given distance from a special agent

I have to select and compute the nearest turtle from a fixed point, however i want the distance to be changeable, in the sense that i have a slider and i want to select the nearest turtle with that
given distance from that point.
I've tried many solution, also with the in-radius function, but it does not produce the desired output.
Can anyone help me? thanks in advance.
Enrico, I don't have enough reputation points to comment so I'll post this as an answer. Your question was two weeks ago and you may no longer need an answer.
If the discussion below correctly describes your problem, as well as the generic logic involved in it, you should have enough to be able to write the basic NetLogo model, or to get the basic control structures written and focus on the specific point where you can't figure out the NetLogo syntax to implement the desired functionality. Or perhaps you have code already in place and we just haven't seen it here.
At that point, the wonderful StackOverflow members should be able to help you answer specific questions in a shared context and understanding of what you're trying to do, what code you are using, and what happens when you try to run the model.
Is the following a correct restatement of your problem?
The Situation
The situation is a stage in a theater with multiple rows of seats. People come in one at a time and are always seated in the row nearest the stage that still has at least one empty seat. When that row is full, seating begins in the next row further away from the stage. When all rows are filled, the simulation stops. Within a row that has more than one empty seat, a seat is chosen that is maximizes some measure of collective distance from other seated people, including possibly people in other rows.
Question -- is the theater rectangular with linear rows of seats, or circular with concentric circular rows of seats around the stage?
Design Considerations
The collective-distance-metric calculation can be put into a separate routine and doesn't affect the rest of a basic NetLogo model setup.
Some possible metrics might be:
1) maximize the distance to the nearest seated person in the same row
2) maximize the distance to the nearest seated person in the entire theater
3) maximize the sum of distances to everyone seated in the same row
4) maximize the sum of distances to everyone seated in the entire theater
5) maximize the square root of the sum of squares of distance to everyone
* in the theater who smokes cigars.
Regardless of choice of metric, we will logically always do the same thing:
Pick initial seating arrangement and possibly initial seated persons
Pick the row to work on next
Loop
Pick which row to work on next, or exit if all rows are full
For each empty seat in that row
Find the agent-set of filled-seats that are relevant to the calculation
( say, filled-seats in the same row as the empty seat )
For that agent-set, compute the collective-distance-metric
Then pick the empty seat which generated the maximum collective-distance-metric
Sit there
update global statistics as desired
display statistics as desired
end-loop
NetLogo Implementation
Do what you can and come back with it here.
You might want to make people and seats two different breeds of turtles. You can layout all the seats in "setup" and then add people as you go.
Seats could own variables "row" and "occupied?" It's easy to layout circular rings of turtles using the "layout-circle" function. Maybe make unoccupied seats green circles of size 2, and change them to red when they become occupied.

Netlogo - agent travels along the link

I am modelling another project concerning the warehouse operations. In this particular instance, I have to visualize the warehouse layout of the storage space. I plan to define a number of links as routes where the agents (forklift truck) can travel along with in the warehouse.
For each link, there is a distance associated with. It’s not the link length as the distance but a distance attributes user defined. If I set a forklift truck driving speed, how do I reflect it accurately in the model with the use of command like fd (or forward) and jump. How do I specify the unit of measure in jump or fd in association with the distance defined in the link to ensure the forklift truck is moving in a correct distance per tick given the speed and distance.
A simple demo would be highly appreciated! Great thanks!

Assigning Known/non-random Variables to Turtles and placing turtles in defined positions

Is there a way to create turtles in a NetLogo world, assign them to specific patches so as to achieve some geographic arrangement AND also assign the turtles known values for their variables.
Let's say I want to represent cities as turtles and I want to locate the cities on the NL world with some relation to reality e.g. New York in North east corner, LA in far west corner. I also want to then assign specific variables that I know for each city to the turtles that represent the cities e.g New York has unemployment rate of 85, LA has 12% unemployment, etc.. After which I want to execute my model
How would I go about this in NL?
Thank you!
As I see it, you'll need a file with the data.
Say your file looks like:
NY -15 15
MA 15 15
NM 0 12
Where the first two letters are the name of the state.
Next two set of numbers are desired coordinates in the NL world.
You can save that in a file and read it through NL code.
You can use more than just 3 columns if you want to save more already known-variables.
You might want to use file-read-line.

Least cost path

I have a landscape with several habitats (i.e. polygons with different IDs). Each polygon of habitat is composed of several patches. In addition, each polygon of habitat has an associated cost. I would like to obtain the least cost path between the polygon that contains a turtle and all the polygons that are in buffer of 2 km around the polygon that contains a turtle.
In a first time, I think to use "weighted-distance-to" from NW extension. According to the example associated to this primitive, I should create a link between the polygon that contains a turtle and all the polygons that are in buffer of 2 km, then I should assign a weight value to the link. In the example, each link between two turtles is assigned to one weight value defined by user. In my case, as a link crosses different habitats, is it possible to calculate a weight value equal to cumulative costs along path towards one of polygons that are in buffer of 2 km ?
Thank you very much for your help.
Sound like you could create a cool variant of Dijkstra's shortest path algorithm.
http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
If you keep all generated paths in a TreeSet sorted on length, you pull the current shortest path, extend it with all possible polygons that have not been visited yet, and push these solutions in your TreeSet. If from a polygon you can only move to surrounding polygons at greater or equal costs than the shortest route you found so far you can drop that route. That way you expand only the shortest routes generating a breadth first search for the nearest turtle, while truncating possibilities that will never work.
good luck!