1
votes

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

1 Answers

0
votes

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