0

I currently have a two populations of agents. One for customers and one for service trucks. There are multiple customers and trucks and their initial location is being determined via an imported excel database with lat/long coordinates.

I would like to have the trucks service customers as needed (ideally at specific times throughout the day). However, I would like to create a set of multiple regions that would enclose my customers. The service trucks would then be assigned a region and only address customers that fall within their region. I have a statechart that currently exists to enable trucks service customers, however, I'm not sure how to tied in the different regions to the agents. I believe once I have the region information tied to the agent, I should be able to update the statechart to handle the updated logic.

So, given I have multiple regions, how can assign a region to the customer (ensuring that the customer actually lies within the boundary of the region) and then assign different regions to the trucks and have them only address those customers.

The program being used is Anylogic.

Logicky
  • 1
  • 1

1 Answers1

0

On creation of your customer agents, make them check which region they are in (using myRegion.contains(lat, lon) with your agent coordinates). You need to loop through all GIS regions as they may overlap, of course.

Store the region found in a variable in your agent (set it to the type GISRegion).

Now, you can assign your trucks specific regions as well (same approach) and only make them go to agents of the same region

Benjamin
  • 10,603
  • 3
  • 16
  • 28
  • Benjamin, thank you for the feedback. I created two variables (one on each actor; customer & truck) and on each agent On Startup I just have a simple if statement that checks the region on main contains the actor coordinates and then if true assigns that region to the variable (I'll tackle looping later). However, I'm now struggling in my statemachine for my truck actor. In my transition I have written if ( gisRegionLightTruck == main.customers.gisRegionCustomer ) moveTo(main.customers.random()); However, I get the error that gisRegionCustomer cannot be resolved – Logicky May 25 '22 at 02:31
  • Probably needs `main.gisRegionCustomer`. Understand how model hierarchy and navigating around it with code works, see https://anylogic.help/advanced/code/access.html#where-am-i-and-how-do-i-get-to – Benjamin May 25 '22 at 04:58
  • Thank you for the link Benjamin. That will not work for me since my gisRegionCustomer is located in my Customer agent. If my understanding is correct, I would need to route to that variable (while in the Truck agent) via main.customers.gisRegionCustomer (which I have done). Should I pull both of my variables that are storing the GISRegion information to my Main agent (removing it from my Customer and Truck agents)? However, in that case, getLatitude/getLongitude will not work due to referencing the population of agents instead of a singular agent. Though it's possible I did not format correct. – Logicky May 25 '22 at 14:47
  • really depends, anything is possible. This is OOP so you should design the architecture as it would be in reality (where a truck knows stuff about itself and a customer knows stuff about itself). – Benjamin May 26 '22 at 10:10
  • I guess I'm just confused on why accessing a variable works for single agents but it isn't possible between two population of agents. I was able to replicate my code for two singular agents, but for some reason the same exact code provides the error of (Variable cannot be resolved or is not a field). Perhaps that is fundamental aspect of agent based modeling that I misunderstand/am unclear of. – Logicky May 26 '22 at 23:21
  • No, you need to understand populations vs single agents. Single agent: `myAgent.myVariable`. Population: `myAgentPop.get(i).myVariable`. You need to specify which specifc agent to access, when you have several – Benjamin May 27 '22 at 07:48