Reputation: 1
I'm trying to implement a model in which vehicles move from a City agent Cidade
to a Port agent Porto
.
The parameters are loaded from a database - Ports: latitude
and longitude
; City: cidades
. There is a City
agent type embedded in Main called cidades
and there is a population of Port agents in Main called portoes
.
Those parameters are used to define the position of the City
and Ports
agents in a gis map
so that it is possible to map the distances between them
I'm using the getNearestAgent
function to get the nearest agent from the collection. The body of the function is defined as return getNearestAgent(main.portoes);
.
The function is returning the value of the nearest Port
in relation to the first element of the City
agent. What I'm trying to do in sequence is calculate the nearest Port
to every City
element, but I'm not sure how.
Upvotes: 0
Views: 66
Reputation: 9421
Like this
LinkedHashMap<City,Port> nearestPortsFromCity=new LinkedHashMap<City,Port>();
for(City city : cities){
nearestPortsFromCity.put(city,getNearestAgent(findAll(main.ports,p->p.city.equals(city)));
}
With that done, now you can access the nearest port from a city by doing
Port nearest=nearestPortsFromCity.get(theCity);
Upvotes: 1