--- title: Route Em emoji: πŸ—ΊοΈ colorFrom: blue colorTo: indigo sdk: docker app_port: 7860 pinned: false license: mit --- # Route Em Finds the **shortest closed route that covers every road, both sides** β€” the route you'd drive or walk to put a paper on every doorstep. ## How to use it 1. **Drop your map screenshot** in the left panel. It stays in your browser β€” it's never uploaded. It's a visual reference for matching the map. 2. **Type a ZIP code or address** and hit Find. The map jumps there. 3. **Click "Draw box"** and drag a rectangle around the neighborhood. 4. *Optional:* shift-click to set where you start and end. 5. **Solve route.** You get the route drawn in travel order (blue β†’ yellow), deadhead segments dashed red, plus total distance, deadhead miles, efficiency, and turn-by-turn directions. ## Why it's optimal, not a guess This is the **Directed Chinese Postman Problem**: - Two-way street β†’ **two required passes** (one per curb). - One-way street β†’ **one required pass**. - Find the shortest closed walk covering every required pass. Solved exactly: 1. Compute each intersection's imbalance (`out_degree βˆ’ in_degree`). 2. **Min-cost flow** from deficit nodes to surplus nodes, cost = shortest-path distance. This yields the cheapest set of passes to *repeat* ("deadhead"). 3. Add those repeats β€” the graph is now Eulerian β€” and extract the Eulerian circuit. That circuit is provably the shortest possible. The solver asserts full coverage before returning anything. ## Notes - Roads come from **OpenStreetMap** via Overpass. Coverage is only as good as OSM's data for your area β€” check for missing new streets. - Areas are capped at **25 sq mi / 6,000 passes**. A real paper route is well under 1 sq mi. - Deadhead mileage is *unavoidable*, not a flaw β€” cul-de-sacs and dead ends force backtracking by definition. - Time estimates use crude constants (12 mph driving, 2.5 mph walking, stops included). - This Space calls the public Overpass and Nominatim APIs. On a shared IP they occasionally rate-limit; if a solve fails, wait a moment and retry. ## Deploy your own ```bash git clone https://huggingface.co/spaces//route-em cd route-em # copy app.py, Dockerfile, README.md in (deps are inlined in the Dockerfile) git add . && git commit -m "Route Em" && git push ``` The Space builds itself from the Dockerfile. First build takes a few minutes (geopandas).