0

Without using the search option in the GIS map in anylogic, I want Anylogic to take a user input which is the name of a location and then place an agent in that location. Then, as the model runs I want it to search for schools near that agent/location found earlier. Then I want the schools found to be made into a collection. This is then important for me to compute some aspects further. How do I do this using functions/codes in Java.

I am able to achieve all this using individual search in the search window of GIS map in anylogic. But I want it to happen such that once a user types a location as a user input in the simulation window( using a parameter or so), automatically the map places the agent there and then searches schools and then places agents there and then these agents become a collection which will be used in another function for computing. I want to automate it using codes.Please help. Thanks in advance.

1 Answers1

1

You will need to set up a population of your agents and specify their initial location based on a parameter that you create inside your custom agent.

enter image description here

enter image description here

For this simple example, I created variable location of type String where a user can input the location where you want to search for a school.

Then inside the create Agents button I added this code

// Find the location we are searching for as a GPS point
GISPoint point = map.searchFirst(location);

// Set the visible map to this location
map.setCenterLatitude(point.getLatitude());
map.setCenterLongitude(point.getLongitude());
map.setMapScale(1/1000000.0);

//Set the search parameters to be within a range from the location we got
map.setSearchBounds(point.getLatitude()-5, point.getLongitude()-5, point.getLatitude()+5, point.getLongitude()+5);

// Search for points within the map serachable area and for each create a new agent.
List<GISPoint> schools = map.search("School");
for (GISPoint gisPoint:schools){
    add_myAgent(gisPoint);
}

It works when testing, however, the results for Schools in the searchable area around New York were very small. But this is the case even when doing it manually.

enter image description here

Jaco-Ben Vosloo
  • 3,770
  • 2
  • 16
  • 33
  • Thank you for the response. It helps me a lot. However, once the schools are found what about making them into a collection automatically (again programmatically). I do not want any of these operations to happen manually. – Ann Francis Aug 22 '21 at 09:24
  • Further when I do add_schools to add agent school to the GIS location- it is adding only to the first search result not to all the schools like we do when we do in a manual search and conversion. – Ann Francis Aug 23 '21 at 04:32
  • Yes, you will have to do a for loop for all the schools that you found and each one of them. Can you perhaps add more detail about how you do it manually. Don't you have all the school info in an external document? – Jaco-Ben Vosloo Aug 23 '21 at 05:24
  • No I do not have the info in an external document. By manually, I meant. In the GIS map when we type schools in the search box it shows the schools in that zoomed area. Then we can convert it into GIS points. However, for my problem I want all this search and conversion to GIS points and collection to happen via a code so that the user is not bothered about all this. – Ann Francis Aug 24 '21 at 04:28
  • I misunderstood the question somewhat, see my completely new answer, I think this answers your question. Let me know – Jaco-Ben Vosloo Aug 24 '21 at 09:21
  • Thank you so much @Jaco-Ben Vosloo for demonstrating so clearly. Yes it worked for me. I just now need to see if I need to make them a collection so that I give results to the user like nearest 2 schools are so and so etc. Your time in explaining this is highly appreciated. Thanks again – Ann Francis Aug 25 '21 at 11:05
  • Thank you @AnnFrancis, if you found my answer correctly addressed your question remember to accept it. You can ask a new question, but it will be relatively easy to do. I don't want to complicate this answer so will answer your next question. – Jaco-Ben Vosloo Aug 25 '21 at 11:30