0

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.

Drew1
  • 1
  • Hey, welcome to AnyLogic and StackOverflow. 2 things: 1: You have several questions. Split them cleanly into separate issues here on SOF. 2: Clarify your questions, they are too vague. Simplify the problem to something easily understandable ("how can I make 1 agent from Pop. X access another from Pop. Y?"). Some tips on making SOF work for you: https://www.benjamin-schumann.com/blog/2021/4/1/how-to-win-at-anylogic-on-stackoverflow – Benjamin Nov 21 '22 at 07:52

0 Answers0