The live website can be accessed here: https://solipsia.github.io/RunEveryStreet/
This is an attempt at solving the Chinese Postman Problem by calculating the shortest route that covers all possible roads at least once within a selected town. This is a common problem faced by rubbish collectors cleaning every street while using the least amount of fuel, or a postman delivering letters to every house on foot. In my case, I wanted to run down every street in my town in the laziest manner possible.
The tool pulls map data from OpenStreetMap, converts it into a mathematical model (a Graph Database) consisting of nodes and edges, then applies an algorithm that produces a route. The algorithm calculates a large number of routes stochastically and selects the best one. The final route can be downloaded as a GPX file to a Garmin or other GPS.
- When the website is loaded, it pulls the background map tileset from OpenStreetMap via the OpenLayers API
- The user zooms and pans to select the area to analyse
- The map data is then downloaded in XML via the OpenStreetMap Overpass API
- Road segments, junctions and intersections are loaded into a data constellation of nodes (intersections) connected by edges (roads).
- This is then drawn on the screen using the p5.js framework.
- The user clicks on a node to select the starting point and clicks on roads to remove them from the graph in order to trim the coverage area.
- Any orphaned nodes or islands that cannot be reached from the starting point are then removed using a Flood Fill algorithm.
- The route-finding algorithm then calculates a large number of possible routes from the starting node:
- Create a list of all connected edges (roads) emanating from the current node
- Sort these by the number of times each edge has been traveled and pick the one with least travels
- If there is a tie with multiple edges with the same lowest number of travels, pick one randomly.
- Travel down the selected edge
- Repeat until all edges have been traveled at least once.
- At this point the route is complete and is drawn on the map, coloured from red at the start to green at the finish.
- Keep repeating above to create a large set of possible solutions until the user stops the process.
- Pick the shortest route of all those created and export it to GPX file for download