def _initDistanceMatrix(self, roads, locations, metric): junctionIds = list(set(locations)) self._junctionToMatIdx = {j: i for i, j in enumerate(junctionIds)} pointsMat = np.zeros((2, len(junctionIds))) pointsMat[0, :] = [roads[p].lat for p in junctionIds] pointsMat[1, :] = [roads[p].lon for p in junctionIds] print("MST heuristic is computing required metadata...") self._distMat = np.zeros((len(junctionIds), len(junctionIds))) from states import MapState for i in range(len(junctionIds)): for j in range(len(junctionIds)): if i == j: continue self._distMat[i,j] = \ metric.compute(MapState(junctionIds[i], roads[junctionIds[i]].coordinates), MapState(junctionIds[j], roads[junctionIds[j]].coordinates))
def expand(self, state): for l in self._roads[state.junctionIdx].links: yield MapState(l.target, self._roads[l.target].coordinates)
def __init__(self, roads, source, target): self._roads = roads I = MapState(source, roads[source].coordinates) super().__init__(I) self.target = MapState(target, roads[target].coordinates)