Anylogic Network - Agent not following path - anylogic

I have a layout defined for agents to move from one rectangular node to another, based on a list in a database. So for example, agent 1 will go to 'lane' 701, then on to 702, etc.
The layout looks like this:
example of layout
The agents move enter from the top left, along the x to the end of that row, then down to the bottom and out to the right, visiting the 'lanes' on their way.
However, I've noticed that one agent has its first lane in the bottom right so rather than following the path across and then down, it's using the shortest distance and moving on the diagonal straight to the lane in the corner:
movement behaviour
Is there something in the software that I can set to strictly follow the paths set? I cannot work out why the agent is breaking the path so I can only assume it's something I am missing.

in the first place, your agent is doing this diagonal probably because you have 2 different networks... if your destination is not in the current network, then the agent will use the shortest distance to the destination, which seems to be your case.
On the other hand, you can't control how the agents move on your network, and it will always take the shortest path or some optimized option... in order to make them follow the path you want, you need to generate intermediary destinations.

Related

Stop at point on Path closest to given (x, y) point while staying on Network

In my model, I require my agents to go through a layout and stop adjacent to a given object. For now, I have used a series of moveTo blocks alongside code that returns the relative (x, y) coordinates that are adjacent of my objective object.
Given that I will be working to simulate an irregular layout, I want to use a Network - I am however running into issues.
According to AnyLogic's "Agents movement inside and outside network" page, in order to use Network paths, either the start or the end point of the agent's movement must be within the Network.
I have created a Rectangular Node, where my moving agents are first initiated. Then, I have them go though a moveTo block with an (x, y, z) destination. For the (x, y) coordinates, I am using Network.getNearestPath(objectiveObjectX, objectiveObjectY, 0.0, pointOnNearestPath).
The desired result would be the agent going through:
Initial Position > objectiveObject 1 > objectiveObject 2 > objectiveObject 3 > Initial Position
With all movement staying on the Network.
However, the actual result is that my agents simply ignore the existence of the Network. My agent populations exist within the Main alongside my Network, so that isn't the issue.
I can somewhat understand why going from objectiveObject to another objectiveObject doesn't follow the path, as neither the start or end destination are nodes, but even the initial movement does not function, and I do not understand why - as it begins in a node and ends in an (x, y, z) position, which is one of the scenarios covered in AnyLogic's aforementioned agent movement page.
How would I achieve my desired results? Would I have to go through the tedious exercise of creating Nodes at every single one of my destination points?
Thank you.

Keeping agent in the same location when using gotoPopulation

I have a population of agents (containers) inside another agent (ship). This is required so that the containers will move with the ship. Once the ship docks, I want the containers to change from the population in 'ship' to the population in 'main' . When I use the following
gotoPopulation(main.containers_main);
to send a container agent to a population of containers in main, the container will move to 0,0 in the main environment.
The above code is placed in the container agent.
Is there a way to change an agent's population but keep it in the same location?
Thanks
I don't think so. As for agents, there is no "same position", they are always relative to something (previously relative to Ship, now to main).
But you can manually position them at the same (apparent) position by:
getting the container's relative position on main while still in Ship: getX() + ship.getX() (same for Y, assuming ship is embedded in Main and container in Ship) --> store briefly as double myPosX
move to new population on main as you do above
set "new" pos relative to Main: setX(myPosX)
It sounds cumbersome but makes sense, once you understand that embedded agent positions are always relative to their parent. Remove the parent and you need to account for adjusted the relative position to keep them in the (seemingly) "same" position

Anylogic - Change direction of the path during runtime

is it possible to change the direction of the path in the PaletteRack during the simulation run ?
Background : we have special aisles (PaletteRack) in our warehouse simulation, where we want to allow transporters to enter only from one direction - e.g. block the entrance from the opposite direction and after the transporter leave the aisle unblock that entrance again
You cant change the direction of path in runtime unfortunately. Path network (incl. all paths directions) is kind of a rigid thing that is not modifiable after model start. But there is a workaround - use two restricted areas on both ends of the aisle. To implement the rules for entering those areas will require a bit of coding. Short example: area1 should be open for all transporters (if its the end from which entrance is allowed), but area2 should only allow entrance for those transporters which are already inside the aisle.

Running a SUMO simulation on a sub-graph of a road network

I am using SUMO to simulate the LuST scenario from https://github.com/lcodeca/LuSTScenario. However, since the scenario is rather large, I would like to start with a simulation constrained to region of interest. Is there a straight forward way to select such a region and have vehicles only simulated in that part of the map?
You can crop the network either using netedit by selecting the region of interest (change to select mode and then draw a rectangle holding the shift key), then inverting the selection (invert button) and deleting the rest. Or if you already know the boundaries or the edges you want to keep you can use for instance with netconvert --keep-edges.in-boundary minX,minY,maxX,maxY -s large.net.xml -o small.net.xml. See here for more netconvert options.
The next step is cutting the routes, which usually means a call like this:
$SUMO_HOME/tools/route/cutRoutes.py small.net.xml large.rou.xml --routes-output small.rou.xml --orig-net large.net.xml
This will not only remove the edges but also try to adapt departure times.

A* manhattan distance

I searched for the algorithm/pseudocode of A* I followed it and coded it. I used Manhattan distance for h(n). ( f(n) = g(n) + h(n) )
And this is the result,
This always happen when there are no walls blocking the way, but when I put a lot of walls, it seems that it's taking the shortest path. Is this one the shortest path? I mean why is it not like this one below?
This one is also A* Manhattan, and they have the same size (19x19). This is from http://qiao.github.com/PathFinding.js/visual/
Both paths have the same manhattan distance. Therefore, it is implementation dependant which path is chosen. To tell why this specific part was chosen, we would have to look at the code of this specific A* implementation.
Hint: Every path from a source to a target cell that uses only Von Neumann neighborhood(i.e., does not walk diagonally) and does not take a step into the "wrong" direction (i.e., never walks up or left in your example) has the same manhattan distance. So, if you are in New York, it doesn't matter which crossroads you take to reach a certain place in Manhattan :)
With the manhattan distance the first one is a shortest path. It simply counts the number of horizontal and vertical steps taken. If you want something that looks more like a shortest path in the euclidian distance you can try changing your algorithm so that when it has the choice to move horizontally or vertically at one point it chooses the horizontal one if the horizontal distance is bigger than the vertical one and vice versa.
You need to cast a line of sight (pythagorean/euclidean) from starting point to every point(of the manhattan/A* result) until finish. If casting a line to a certain point is blocked/hidden by the obstacle, you use the previous point casted and start casting another line from that blocked point then forward until finish.
A Blocked point is when a point is hidden by the line-of-sight of the initial point of the segment/line.
So It's like:
First Line: Start--------->S+N(before blocked point)
Second/Middle Line/s:Blocked Point---------->S+N(before another blocked point) repeat again(new line/segment) until it established a line-of-sight to the goal.
Last Line:Blocked Point------------->Goal
Connect all lines and you've got a much shorter shortest path.
You can execute again, but in reverse to add another accuracy so the line of sight will begin at the goal until start.