How to create connections to specific agents and show animate connections for agents in Anylogic - anylogic

I am new to Anylogic and I am trying to do modeling using Anylogic. I'd like to connect 6 types of agents on a GIS environment by a network.
The condition for the connections is as follows:
agent type 1 has 10 agents
agent type 2 has 16 agents
agent type 6 has 20 agents.
I want to connect agent1 with 2 based on the nearest distance. This means that an agent of type 1 is to be connected to the nearest agent of type 2.
Also, I want to connect populations of agent1 with each other.
I used "Link to Agent" for this purpose and animated connections by clicking the "draw line connecting agents" tickbox in the properties. The line connecting among agents isn't shown when I run the model however the results show agents are connected.
Got any suggestions (to show line connecting among agents)?
Thanks.

The "draw line" functionality of the connections generated by link to agents DOES NOT work on a GIS space.
I would call this a bug in AnyLogic.
To draw lines between agents that are connected, you need to code your own thing, which is not very straight forward considering that you can zoom in and zoom out the map, there's no built in functionality in AnyLogic that allows you to do this easily. Sometimes I use Gis Regions as lines to connect agents... But that works fine with static agents...
You can so generate new agents that are lines and define the position based on the map scale, but you can't zoom in or zoom out without breaking the connections.
In other words, you have to be creative depending on what your agents are.

Related

How to set agents speed according to the road they are on?

I am working on a project using Anylogic and i was wondering if there is a way to set the agents speed according to the road they are on.
I am working with the GIS map, where I have some GIS regions which the car agent moves from one region to another through the moveTo() function. For this project I am using the Anylogic default routing provider.
I expected the agents to use the road's speed limits, but I realized they are moving with their "inicial speed" with a constant speed. Does anybody know how to set my cars speed according to the road they are on?
Thanks a lot!!

Agent enters node.closed() and causes runtime exception in Anylogic

I have a rather huge model of a production system in anylogic with two agv fleets, which transport material between stations. My problem is solely with one of the fleets.
My product enters the system through a conveyor, seizes a transport agent, then waits on the agent and then drives off to the first station.
My problem is with the conveyor and my transport agent. After a while of simulating, I get error message and is what the console says.
Now I thoug myself clever:
If the agent is not on the conveyor (or does not care) it might not throw this error. So I put in the "on new transporter" of the transporter fleet an unit.ignoreCollisions(true);
But that did not help.
Then I made a restricted area around the conveyor (on a scale of 1000 % one of rectangles of the grid to small, then exactly the size, then one row of rectangles too big), but it still goes into the restricted area and then throws me this error.
I do not even understand how the agent can (a) care about this (it ignores collisions) and (b) how it can enter the restricted/forbidden area.
Does anyone else experience the same? How did you solve it?

Two agents are missing from the presentation

I have 9 trench agents in my model. When I run the model, I can see that 9 agents are created but I have only 7 agents in the 2D, and 3D presentation. I tried different numbers, and two agents are always missing from the presentation.
Agents are located in a node which has exactly 9 attractors. Please see the pic.
Can Anyone help me to resolve this issue? Thank you.
The problem is I can see that presentation change after a while! Is this usually happen in AnyLogic? Please see the Pic.
Nodes are not used "exclusively", i.e. they do not have a build-in "I am full, no more agents here" capability. They simply define possible agent animation locations.
So in your case, 2 agents are on top of other agents at the same node.
You would need to make those nodes agents themselves with a given capacity. There are many ways to do it (none totally easy), depends on your model setup and what you try to achieve.

How can I control individual pedestrian type agents behavior using statechart in anylogic?

I am trying to do a pedestrian modeling where individual pedestrian agent behavior needs to be controlled. Can I do that using the pedestrian agent's statechart?
Update: Sorry that my initial question wasn't clear enough
main
jaywalker (agent)statechart
runtime screenshot
jaywalker agent from padsource
In the first picture (main) I have a simple pedestrian model where jaywalker (pedestrian agent) moves through 2 road crossing. Initially all the jaywalker agents are in "walking" state & colored yellow (pic: 2), but whenever some agents are near another agent (near means within the triangular shown in jaywalker agent representation), they send the message "HI" to them & socialize. If someone is socialized, then they move from "walker" state to "socializing" state (and turn red) & send messages to others who are within his triangular range("field of vision" triangle). The first 11 socializing is done directly by a message from main (on model startup) & 11 jaywalker agents are receiving it & moving to "socializing" state. The problem is in my graph it's showing the first 11 socializing but during model runtime the agent's color is not changing. Secondly, after those 11 socializing, agents aren't socializing or sending any message to others who are within his triangle.
So, I am confused about how I can make my agents move from one statechart to another while modeling the movement behavior using the pedestrian library. Am I missing any step to connect the pedestrian library & agent statechart?
It looks like you did not tell PedSource to create your custom ped agents of type "JayWalker". Try this:
Delete your population, not needed
Make sure your JayWalker agent type is defined as pedestrians in its properties:
In your PedSource, make sure it creates "JayWalker" agents as below. (You should select JayWalker where my screen selects "MyPed")
Optionally, you can make the PedSource add the created "MyPed" agents to a custom population, but likely not necessary for you.
PS: Please understand that PedSource is creating agents, do not use your population for that. Read some more about PedSource and populations and do some tutorials to understand these basic concepts better :-)

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