0

So I have a series of GIS points on a map and Truck agents travel from point to point at random. There's a series of arbitrary non-overlapping regions within the map (akin to county or state). I'm trying to track which GIS Region the Truck is in as it travels from point to point.

My approach is to have a GIS Region variable within the Truck agent called county and follow the logic here: How to set regions as a parameter in an agent in anylogic

But rather than have it in the On startup field, have it in the On step field. So it would be as such

county = main.map.searchFirstRegion(address);

I am receiving these error states

main cannot be resolved
address cannot be resolved to a variable

Any clue how to troubleshoot? Very green to AnyLogic so if I'm overlooking something simple, please let me know.

BONUS:
Additionally, if I have each GIS Region is an agent, say County. I'm unsure how I could calculate an agent variable that comprises the summation of all Truck agents currently in that GIS Region (i.e. Truck count in County or Total freight weight in County).

  • Hey, welcome to SOF. Your main question is great, thx. However, avoid asking "bonus" questions, i.e. several questions in 1. On SOF, you can ask lots of questions but each should be separate, this works like a knowledge base, see https://benjamin-schumann.com/blog/anylogic-stackoverflow – Benjamin Aug 08 '23 at 19:00

1 Answers1

0

You did not use code-complete and rather just pasted code, this will always throw unexpected errors. Yours is telling you "I have you idea what you mean by main".

Probably your Trucks are not embedded in a Main agent type, it all depends on your specific model hierarchy. This should help: https://anylogic.help/advanced/code/access.html#where-am-i-and-how-do-i-get-to

Benjamin
  • 10,603
  • 3
  • 16
  • 28
  • The Truck agents are being created from a Source on the Main canvas. I'm unsure how to map the hierarchy since the agents are created as the model runs. Do I create a population agent "Trucks" and then somehow add each Truck to the population as it creates, then remove when it goes to the sink? – Jack Nelson Aug 08 '23 at 19:46
  • yes, check the example models and step-by-step tutorials like the Supply-chain GIS one – Benjamin Aug 09 '23 at 05:23