0

I am new to anylogic and am trying to build an agent-based model which randomly directs agents (vehicles) from a starting point (a Home location point on GIS map) to a selection of locations. I have 6 different sets of collections which have varying respective locations stored within them (SchoolsCollection, SupermarketsCollection, ShoppingCentresCollection, HospitalsCollection, TourismCollection and WorkOfficeCollection).

Within my statechart for my vehicles, I instruct it to visit 4 locations. So far I have only been able to make the agent move to a random location within one of the collections in each transition using: moveTo(randomFrom(main.HospitalsCollection)) for example.

But as I want my agent to randomly pick a location from the six collections above and not revisit the same class of collection from its previous journey, I am unsure on how to:

  1. move my agent to randomly select a location from the collection of collections I have above

  2. when moving on to the next location via the transition in my statechart, to not revsit the previous type of location it was just at (ie not go from one school in one trip and the following trip go to another school). From my limited experience, I would imagine this make use an if loop?

If you could help me with the above two queries that would be much appreciated!

Thanks in advance.

Emile Zankoul
  • 2,161
  • 2
  • 6
  • 18
  • you can add another collection of collections and choose randomly from there, and then when you selected something, choose randomly from the chosen collection... then remove that from the collection of collections so you don't select it again – Felipe Feb 16 '22 at 17:29
  • Welcome to SOF, always try to ask separate questions in separate issues. Makes it much easier to reply, also see https://stackoverflow.com/help/how-to-ask – Benjamin Feb 16 '22 at 17:32
  • @Felipe I was thinking of implementing something along this approach, but I can't seem to figure out how to place the collections under one collection. When I create a new collection, under its properties, I see that I can add each individual element from which I have stored in the collections, but I don't think this is what I am after. What would I have to do to place these sub-collections into a main collection? – Abdullah Feb 16 '22 at 19:10

1 Answers1

0

Either do the approach by Felipe or you can also group your elements in 1 large LinkedHashMap collection where the keys are a String (or better an OptionList with the types "Hospital", "School"...) and the values are ArrayList<GISPoint> with all the actual points.

(LinkedHashMaps are a standard Java data type, check the web to learn about them).

Re avoiding revisiting: Best have a collection in each Vehicle placesVisted (type ArrayList<GISPoint> or similar) and store each place you already visited. Then before moving somewhere else, first check if you have been there previously

Benjamin
  • 10,603
  • 3
  • 16
  • 28