Distance Matrix Generation Algorithm: Efficiently Calculate Distances Between Areas
Algorithm 1: Distance matrix generation
-
Input:
- List of all areas
- All trips, grouped by trip start area
-
N = len(all areas)
-
Create a distance matrix Dis with dimensions [N][N]
-
For each pair of areas (ai, aj) in all areas, do the following:
- Get all trips from ai to aj from the dataset
- Calculate the average distance of those trips
- Set Dis[ai][aj] to the average distance
-
For each pair of areas (ai, aj) in all areas, do the following:
- If Dis[ai][aj] is NULL (i.e., no recorded trips), do the following:
- Find all candidate paths from ai to aj using bidirectional search
- Set Dis[ai][aj] to the minimum distance among all candidate paths
- If Dis[ai][aj] is NULL (i.e., no recorded trips), do the following:
-
Return the distance matrix Dis.
原文地址: https://www.cveoy.top/t/topic/m1iu 著作权归作者所有。请勿转载和采集!