In Anylogic: coordinates of an embedded agent inside an embedded agent - coordinates

How can I get the coordinates of an embedded agent that is inside another embedded agent ?
For example:
I have 2 agents : agent1 and agent2.
Agent 2 is embedded in agent 1.
Agent 1 is embedded in main and rotated.
In main how can I get the coordinates of agent2 the same as the animation of agent2 is shown?
thank you,
Anat.
All the function I found returned the coordinate of the agent relative to it's space agent.

Coordinates are always relative to your parent agent by design. So you need to manually add them up, as Yossi suggested:
double posX_Agent2 = agent1.getX() + agent2.getX();
Same goes for rotations.

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 Network - Agent not following path

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.

How to make pedestrians appear at AreaNode with attractors from a pedSource

I am working on an evacuation project for a floor and would like to create a distribution of pedestrians from the pedSource block. These pedestrians will already appear in an area when I run the simulation. I want to obtain a fixed number of pedestrians in one area while the rest is distributed to other areas.
I have made a collection of areas that pedestrians will appear using allLocations (area, area1, area2 and OfficeArea). The event is triggered by an event and using a delay block. The max amount of pedestrians at the given floor is 100
Image of block flowchart
Image of floor layout plan
This is the code I tried where pedestrians would appear in the areas:
allLocations.get(uniform_discr(0, allLocations.size()-1))
I expect a fixed 10 number of pedestrians in the office area and positioned where I set the attractors, but the actual result shows more than 10 number of pedestrians and do not appear at the set attractor.
Image of actual result
Setting an attractor as a target for pedestrians is according to the documentation only working for the blocks pedWait and pedGoTo (I could actually only get it to work with pedWait, not with pedGoTo). Therefore you cannot initialize agents directly onto attractors using the initial location or the jumpTo() function.
You have several options as a workaround:
Extract the x,y coordinates of the attractor, and use the type point(x,y) to define the initial location or the location for the jumpTo()
Instead of using (graphical) attractors consider just defining points by code directly
Use very small individual areas instead of one large area with attractors
Use a pedWait block in your process flow and let your pedestrians 'walk' to their initial positions. Give the model a short time until everybody is on the desired location before starting your evacuation. You can also run the model in super fast mode during this initial phase, so that it will barely be visible.

Specifying location of agents that are generated within an agent that is placed on GIS map

So in this model I have several hospital-agents that are placed randomly in an area. These hospitals contains a process flow and at some point in this process flow a new agent 'Bones' is generated, using a split block. The location of these Bones-agents is correctly specified by setting it equal to the (x,y) coordinates of the hospital.
Now I want to make the model more realistic by placing the hospitals in actual location in a GIS map. I did this with success. However, now I need to re-specify the location of the Bones-agents. At the moment of generating the first Bones-agent, I get the follow error:
root.Hospital1.splitblock:
Error when trying to initialize new agent
Caused by: root.Hospital2:
This agent is already defined as agent living in space 'Continuous, based on
GIS map' and can't have behaviour for space 'Continuous'This agent is already
defined as agent living in space 'Continuous, based on GIS map' and can't
have behaviour for space 'Continuous'
What do I need to do to make this work? I have tried setting the location of the Bones-agent equal to the longitude and latitude of the hospital agent with a function:
double longitude = getLongitude();
return longitude;
I did the same for het latitude. I then inputted these functions in the 'latitude' fields of the split block.
When you develop a model, you have to choose what kind of space you will use. Remember that all the canvas in which you put agents, and the map and stuff is based on a scale, so you can't mix a map with elements that are created with the space markup (with space markup i mean nodes, paths, rectangular nodes etc).
So the bones agents should also be placed in the map... It seems that you are not doing that, and you are probably placing the bones agent using the space markup.
But it's possible to do this of course, but you have to do it in another agent. Create a new agent called continuousSpace for instance, and place your bones agents there.
After that you will have to create a navigation button using viewAreas (from the presentation palette) to move from one agent to the other (meaning from the gis space to the markup space).
Otherwise, you can also place the bonesagents in the gis space (in the map) and it will also work.
Good luck :)