0

So I have a set of points in a city (say houses or residences) and I want to find the shortest distance between these points and a set of candidate points for a store. I am looking for the best store locations that will minimize the distance to all of the houses in the set. So I will iteratively move the candidate store points and then recompute the distances between each store and house (again using Djikstra's algorithm). Because of the sheer volume of calculations, I cannot keep hitting the database for each iteration of the optimization algorithm.

I have used pgrouting many times and this would work, however it would be too slow because of the large number of points and the fact that it has to search the disk each time.

Is there a tool where I an load some small Open Street Maps city map in memory and then calculate the shortest routes in memory? I would need something fast, so preferably in C or python? But any language is okay as long as it works.

krishnab
  • 9,270
  • 12
  • 66
  • 123
  • The normal way of calculating these 'reach' problems is to start a one-to-many calculation from the potential store locations. Do this e.g. with a simple Dijkstra and using fast preprocessed graph can give you responses for every store in milliseconds. E.g. have a look at the OSM routers http://wiki.openstreetmap.org/wiki/Routing – Karussell Nov 28 '15 at 14:12

2 Answers2

1

In python you can use networkx for graph work. It has breadth-first search functions.

https://networkx.github.io/

Michael Neylon
  • 584
  • 4
  • 14
  • Interesting idea here. So I would take the open street map segments and define and edgelist. But the question is can networkx handle the GIS information as well. So I will have to give it Lat,Long coordinates for the road segments and also for the houses and stuff. Would it be able to calculate distances to a location that was on the network, or even geographically slightly off the network. – krishnab Jul 28 '15 at 19:53
  • @krishnab I don't know if it can take into account road map information itself. It could handle a list of nodes with coordinates and then you can build an edge list based off of that, but it would be shortest path / straight lines. I imagine to incorporate distance taken over a road you would have to find the edge length between every node using a map route first. – Michael Neylon Jul 28 '15 at 20:10
1

Heres and idea. Get the latlongs of the house and all the stores. Calculate the geohash of all points(house and stores) with maximum precision (12) and check if geohash of any stores matches that of the house. If it doesnt, calculate the geohash with lower precision (11) and then rinse and repeat till you get a store(May be multiple Ill get into that later) that matches the geohash of the house.

This is a fuzzy-distance calculation. This will work great and with minimal processing time. But this will fail if you get two or more stores with the same geohash with some precision. So this is what I recommend you do

  1. The geohash loop with decreasing precision. Break when geohash of store(s) match the gohash of the house
  2. IF (more than one sores match) Go for plain distance calculation and find the closest store and return it
  3. ELSE return the one store that the matches the geohash

Advantage of this method : Changes your strict requirements to a fuzzy probability problem. If you get a single sore, great. If you dont at least you reduce the number of candidates for distance calculation

Disadvantage of this method: What if all stores land in the same geohash ? We introduce the same complexity here.

Youll be banking on the chances that not all(or most) stores come under the same geohash. Realistically speaking, the disadvantage is only a disadvantage in corner cases. So overall you should soo performance improvement

Shreyas Chavan
  • 1,079
  • 1
  • 7
  • 17