averbraeck / medlabs

Agent-Based Simulation for Disease Spread in Cities and Regions
BSD 3-Clause "New" or "Revised" License
3 stars 2 forks source link

Improve grid-based locations #9

Closed averbraeck closed 4 months ago

averbraeck commented 4 months ago

In the current medlabs base library, the nearest cache and grid are optimized for Beijing's latitude, and static. One of the things to quickly improve is to make them parameterizable and self-adapting for the latitude and longitude of the location of the model. This is also necessary for issue #8, to find locations at larger distances.

averbraeck commented 4 months ago

The idea is to merge the grid and the cache, and to allocate every location to a (smaller) grid cell. This way, distances can be quickly assessed without making a calculation. Distances can be:

averbraeck commented 4 months ago

When the grid cells are 100x100 m, the walking time to the neighbor cell with 5 km/h is on average 72 seconds, i.e. a bit more than one minute. That seems to be a sufficient resolution for most models. For Haaglanden, this would mean 150x200 cells = 30,000 cells. Each location belongs to one cell. The cell coordinate for the location can be stored as two (16 bits) shorts, allowing for a 3200x3200 km grid (or 6500x6500 km when also using the negative values), The cells can be stored as an integer (32 bits) index by using (lonGridIndex<<16 + latGridIndex). The indexes can be used for a Map<Integer, TIntList> (map from grid cell index to a list of location ids) to compactly store the locations per grid cell.

averbraeck commented 4 months ago

The grid has been implemented and tested. It works much better than the previous implementation.