How to communicate variables between agent populations in AnyLogic? - anylogic

I have two populations of agents (only one of which I want to control) and I want to program one agent's actions based on the distance to the agents in the other population. I can get the location of each agent in their own population by using getX() and getY(). However, once these values are stored in a variable, they are not able to be communicated to a different population. Also, using distanceTo (agent other) does not seem to work for agents in a different population. Another issue I am having is how to call up location information for a specific agent (i.e., agent 1 in a population of X agents). When I print the agent names during a model simulation run, I see the agents listed as root.agent[0], etc., however, this syntax does not seem to work for calling up that specific agent when trying to code specific actions based on that agent (i.e., when this agent is so close, do something).
I tried storing locations using getX() and getY() into separate variables. Then using those variables to perform distance calculations. However, these variables, when stored in agent1 agent type, they cannot be communicated to agent2 agent type for variable use. I tried this for distanceTo() as well and got similar errors. I also try calling root.agents[0], root.agent[0] and agent[0] to use for distance calculations (both in and out of that agent's agent type) and get errors for "variable root not recognized" and "variable agent not recognized."
I understand this may be a beginning level programming question, but I cannot find literature on how to solve this problem in AnyLogic help sites online, nor have I been able to find a specific tutorial that works with this type of issue. Thank you for the help.

Related

Can a transporter follow an 'material' agent into another agent?

I have an material agent that is moved from the Main agent to inside another agent (simulating a room). I can send the material agent using the Exit and Enter blocks. The 'room' agent contains a network that the material agent is being sent to.
The material agent is initially being moved in Main using a Transporter. However I'm not able to get this Transporter to follow the material agent into the room agent. The main questions is - is it possible to send a Transporter into another agent? Or does it need to remain in the agent that the Transporter Fleet is located?
Thank you.
I will correct benjamin by saying that with setEnvironment you can't do it since that's a function that is called on the agent initialization.
Instead of setEnvironment,something you do normally is to send the agent to a new population (which is the way you dynamically change environment), but it doesn't work with transporters
My answer would be that you can't do it since transporters who follow paths are defined as strict AGVs and can only move on their initial network and you can't change the network, unlike other agents.
But i'm always a bit suspicious of myself when i say something is not possible...
This should be possible with some setEnvironment() calls.
However, it is not a good setup. Think of reality: your rooms are spatially all part of the same environment: your flat (or factory or whatever). Moving from 1 room to the next does not mean you change your flat. You stay in the same environment.
You should setup your room agents like that as well: their spatial representation should reside in Main (or whatever agent they are embedded in).
Use a parameter of type ShapeRectangle or similar in your Room agent to define which rectangle (or else) represents the spatial aspect of the room.
Then, the flow chart blocks in the Room agent simply refer to that parameter for their spatial needs.

how to custom drop-off block according to agent type

Using previous pick-up blocks, i have an container agent with two different agent types inside (Myagent and Myagent1). I want to insert two different drop-off blocks,the first for Myagent and the second for Myagent1. the problem is which element type i should choose for the drop-off block. For example, if i chose Myagent, it would give me error because of Myagent1:
If i chose Agent then:
Both the agent have a parameter named cc.
(I read other answers on the forum like Drop-off specific custom agents using drop-off block in anylogic, but i still have this error).
thanks for the help.
The best option here is to create a parent agent type that has 'cc' property and have the two types of agents inherit from it as described here. Also as a side note, you should probably take care to name the agents and properties with something meaningful as it will help to understand the model and explain it should you need to ask for help in the future.

AnyLogic if condition selectOutput

I'm modelling a manufacturing line in anylogic. Two agents are being processed and transported via the same conveyor. Both Agents need to spend diffent delay times in a service station. Because of that i added two parallel services and now i want to sort the agents arriving on the conveyor to their corrosponding service stations.
flowchart
Agent1 needs to go to service and Agent2 to serviceT.
I assigned parameters to both Agents, Agent1 has the boolean parameter "S" set to true and Agent2 the same parameter set to false.
To sort the Agents in the selectOutput block i typed in the if condition agent.S == true as seen in the next screenshot.
selectOutput
Anylogic prompts following error: "Unresolved compilation problem: S cannot be resolved or is not a field"
What can i do about this?
Thank you!
I would like to answer this question in two parts:
Instead of using a selectOutput to model different delay times for the SAME station, it would be more reasonable to have only ONE service representing that ONE station. To model different times, set the delay time equal to agent.S where S is the delay time for each agent.
Regardless of whether you choose what I suggested or what you are already using, you will still get the same error. The reason for this error is most likely that you haven't specified the agent type going through the select output properly. In fact, if you look at the image of the select output properties you shared, under the "Advanced" tab, the agent type is set as the default type Agent. Make sure to replace that by the agent type that contains the parameter S.

How to compare conditions of an agent with all connected agents in statechart

I am working on my thesis associated with modeling farmers' behaviors in a river basin. I am having 6
agents that contain different populations of farmers. These farmers have been located on the GIS map as the environment (main) in anylogic. I also defined the connection between populations of 6 agents by coding on the main startup and using "Link to Agent". Now, I'd like to define agents' behaviors through statecharts. But I have some difficulties. I have to compare the income of each farmer to the income of all connected farmers. How can I do that? What I have tried to define condition transition and write (for example if the income of each farmer is less than the income of all connected farmers in its network then do specific action):
IncomeT<ALL_CONNECTED.IncomeT
but it didn't work. Got any suggestions?
Thanks.
not quite clear who is your agent for which you are designing your state chart. Is it some entity (say Area) which contains a population of farmers? If yes, then why would you connect/link one Area to another? If you agent is a famer (which is not how you described it, but seems logical) then you would just store (and update) "minimum population income" in some variable and compare individual income with that stored value.
Alternatively you can use min() function. More on that: https://help.anylogic.com/index.jsp?topic=%2Fcom.anylogic.help%2Fhtml%2Fdata%2Fcollections-statistics-api.html

Anylogic wearhouse - how to combine two agents to create one final agent

Good afternoon to everyone,
I have a problem with the software AnyLogic. I have to do a program that is able to combine two agents (two different semifinished) to create one final agent (final product). The problem is that the two semifinished have different production time, so I need a function that is able to accept one agent (the first semifinished), than to wait for the second agent and at the end to generate one final agent from the previous two agents (semifinished). How it's possible to do this? I have already tried with the function "Combine" without any success.
You need to use the "Assember" object from the process library. Speciy how many agents of type A and B you need (1 each in your case). The assember will create a new agent type (you need to specify it) from the 2 incoming agents once it has got 1 of each.
Also check the help on the Assembler, you can do lots of fine-tuning with it.
cheers