2

I have a goal to run every block of every street in my city. I've been keeping track of my progress on a custom google map that I draw. It's onerous to log and obnoxious to trial & error plot new routes

As I get more into Python, I realized this is a task ripe for automation.

Looking around though, I see a lot of options for route planning API (google and GraphHopper look compelling). But I'm not trying to just get from A->B and minimize distance.

I want to upweight certain blocks (ones I've yet to run) and downweight others (ones I've run hundreds of times). This is definitely a solved problem (eg "current traffic" is used to weight route optimizations), but I can't seem to find good examples.

Are there any existing python libraries that can weight maps and provide routing solutions?

Or alternatively, am I wrong to give up on some of these APIs so soon?

ScottieB
  • 3,958
  • 6
  • 42
  • 60

1 Answers1

2

I don't think those API can help, because you need a route calculated using a custom "cost function".

Simplifying, routing APIs like graphhopper/google maps, use a cost function like cost = distance / speed.

Instead, you need a cost function that gives lower values for "yet to run" streets.

You could do a local installation of graphhopper, and follow this example https://github.com/graphhopper/graphhopper/blob/0.8/docs/core/weighting.md

or you could use PostgreSQL + PostGIS + pgRouting and calculate a custom cost based on your history. You can find something similar to your needs here http://pgrouting.org/docs/howto/oneway.html

I'm sure you can connect to a postgresql database with python, but you need some additional work to install the necessary software and to import data.

Graphhopper has a built-in OSM importer and you can get a working instance easier (in my opinion).

fradal83
  • 2,002
  • 1
  • 10
  • 9