简体   繁体   中英

Find nearest Neighbour out of N points for M points

I am currently trying to assign regions to customers by optimizing driving distance. So far I have generated a from/to/driving time table and for every point withing the problem I am aware in what position they reside.

Thus I have a list a containing customer locations and a list b containing service locations. List be should be assigned to list a. For me it seems like every point in b should be evaluated on distance to a point in a and then assigned to the closest point.

My question...would there be a way to solve this problem using regular msSQL?

Use Kd tree for O(logN) to find the nearest neighbour of any given point . Here if the points are defined as co-ordinates then you can use 2-d tree . Make 2-d tree of the service locations and make query for NN on given customer locations. Note that kd tree can be used to get nearest neighbor when the distance are euclidean distances but cannot be used for any other random distances.

Kd trees

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM