All Projects → mehrdadn → Sota Py

mehrdadn / Sota Py

Licence: other
A discrete-time Python-based solver for the Stochastic On-Time Arrival routing problem

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Sota Py

Stplanr
Sustainable transport planning with R
Stars: ✭ 352 (-7.61%)
Mutual labels:  transportation, routing
spopt
Spatial Optimization
Stars: ✭ 186 (-51.18%)
Mutual labels:  transportation, routing
Shufflenet
ShuffleNet in PyTorch. Based on https://arxiv.org/abs/1707.01083
Stars: ✭ 262 (-31.23%)
Mutual labels:  convolution
iOS-Routing-Example
A Clean, Simple and Composable Routing System for iOS apps in Swift
Stars: ✭ 29 (-92.39%)
Mutual labels:  routing
Fluro
Fluro is a Flutter routing library that adds flexible routing options like wildcards, named parameters and clear route definitions.
Stars: ✭ 3,372 (+785.04%)
Mutual labels:  routing
Docker Tuntap Osx
A tuntap shim installer for "Docker for Mac"
Stars: ✭ 264 (-30.71%)
Mutual labels:  routing
Freerouting
Advanced PCB autorouter (finally, no Java installation required)
Stars: ✭ 307 (-19.42%)
Mutual labels:  routing
Cortex
Routing system for WordPress
Stars: ✭ 300 (-21.26%)
Mutual labels:  routing
Massiv
Efficient Haskell Arrays featuring Parallel computation
Stars: ✭ 328 (-13.91%)
Mutual labels:  convolution
Jaguar
Jaguar, a server framework built for speed, simplicity and extensible. ORM, Session, Authentication & Authorization, OAuth
Stars: ✭ 286 (-24.93%)
Mutual labels:  routing
Abstract State Router
Like ui-router, but without all the Angular. The best way to structure a single-page webapp.
Stars: ✭ 288 (-24.41%)
Mutual labels:  routing
Django Multiurl
Have you ever wanted multiple views to match to the same URL? Now you can.
Stars: ✭ 268 (-29.66%)
Mutual labels:  routing
V2ray Rules Dat
🦄 🎃 👻 V2Ray 路由规则文件加强版,可代替 V2Ray 官方 geoip.dat 和 geosite.dat,兼容 Shadowsocks-windows、Xray-core、Trojan-Go 和 leaf。Enhanced edition of V2Ray rules dat files, compatible with Xray-core, Shadowsocks-windows, Trojan-Go and leaf.
Stars: ✭ 6,550 (+1619.16%)
Mutual labels:  routing
Ffrouter
Powerful and easy-to-use URL routing library in iOS that supports URL Rewrite(强大、易用、支持 URL Rewrite的 iOS 路由库)
Stars: ✭ 263 (-30.97%)
Mutual labels:  routing
Imaging
Imaging is a simple image processing package for Go
Stars: ✭ 4,023 (+955.91%)
Mutual labels:  convolution
Navigation
Routing for SPAs, the Elm way
Stars: ✭ 255 (-33.07%)
Mutual labels:  routing
Simple Php Router
Simple, fast and yet powerful PHP router that is easy to get integrated and in any project. Heavily inspired by the way Laravel handles routing, with both simplicity and expand-ability in mind.
Stars: ✭ 279 (-26.77%)
Mutual labels:  routing
Libretaxi
Open source Uber #deleteuber
Stars: ✭ 3,687 (+867.72%)
Mutual labels:  transportation
Maro
Multi-Agent Resource Optimization (MARO) platform is an instance of Reinforcement Learning as a Service (RaaS) for real-world resource optimization problems.
Stars: ✭ 378 (-0.79%)
Mutual labels:  transportation
Nested Navigation Demo Flutter
Nested navigation with BottomNavigationBar
Stars: ✭ 367 (-3.67%)
Mutual labels:  routing

What is SOTA-Py?

SOTA-Py is a Python-based solver for the policy- and path-based "SOTA" problems, using the algorithm(s) described in Tractable Pathfinding for the Stochastic On-Time Arrival Problem (also in the corresponding arXiv preprint) and previous works referenced therein.

What is the SOTA problem? Read on...

Theory (in plain English)

What is the Stochastic On-Time Arrival problem (SOTA)?

It's the reliable routing problem:

How do you travel from point A to point B in T time under traffic?

For example, you might have a meeting in San Jose at 3pm, and one to reach in San Francisco at 4pm.
Or you might need to get from your house to the airport in less than 1 hour.

Doesn't Google Maps already solve this?

No. It doesn't let you specify a time budget. It only lets you specify a departure or arrival time, but not both.

What it (probably) gives you is the path with the least expected (average) time to your destination.

But so what? 30 minutes or 60 minutes—isn't there a single best path?

No. That would only be the case if traffic was perfectly predictable.

If you don't have a lot of time, you might need to take a riskier path (e.g. a highway), otherwise you might have no chance of reaching your destination on time. But if you have a lot of time, you might take a safer path (like side roads) that no one uses, to avoid suddenly getting stuck in the middle of, say, a highway, due to traffic.

That means your time budget can affect your route.

Policy- vs. Path-based Routing

What is the policy-based SOTA problem?

It is the case of the SOTA problem where you decide which road to take based on how much time you have left. You'd probably need a navigation device for this, since there are too many possibilities in the "policy" to print on paper.

This is what you'd prefer to do, because it can potentially give better results depending on whether you get lucky/unlucky with traffic.

This is a dynamic-programming problem, because the probability of reaching your destination on time is just the maximum probability of reaching it from each road at the next intersection.

What is the path-based SOTA problem?

It is the SOTA problem in the case where you statically decide on the entire path before you depart.
You can just print out a map for this on paper, the old-fashioned way.

This is—counterintuitively!—a much tougher problem than finding the policy. Even though the solution looks simpler (it's just a path rather than a policy), it's much harder to compute. Why? Intuitively, it's because after you travel a bit, you won't necessarily be on the most optimal path anymore, so you can't make that assumption to simplify the problem initially.
By contrast, in the policy-based scenario, you always assume that your future actions are optimal, so you have an optimal subproblem structure to exploit.

The Algorithm

The (unhelpful) ultra-short version is that Dijkstra's algorithm is used for policy-based SOTA and A* is used for path-based SOTA.

The (more helpful) short version is:

  • For the policy computation, a re-visiting variant of Dijkstra's algorithm is used to obtain an optimal ordering for computing the reliabilty of each node, and a technique known as zero-delay convolution is used to perform cross-dependent convolutions incrementally to keep the time complexity quasilinear in the time budget. (A naive FFT would not do this.)
  • For the path computation, the computed policy is used as an (admissible) heuristic in A*. Note that this choice of a heuristic is critical. A poor heuristic can easily result in exponential running time.

For the long version, please see the paper linked above, and others referenced inside. The paper should (hopefully) be quite easy to follow and understand, especially as far as research papers go.

Note that the pre-processing algorithms from the paper (such as arc-potentials) are not implemented, but they should be far easier to implement than the pathfinding algorithms themselves.

The Traffic Model

This code models the travel time across every road as a mixture of Gaussian distributions (GMM) ("censored" to strictly positive travel times). It discretizes the distributions and solves the discrete problem in discrete-time.

Obviously, realistic travel times are not normally distributed. But that's the model of the data I had. Getting good traffic data is hard, and encoding data efficiently is also hard. If you don't like the current model, you'd have to change the code to accommodate other models.

The Code

Inputs

Dependencies

  • NumPy is the only hard external dependency.
  • Numba, if available, is used for compiling Python to native code (≈ 3× speedup).
  • PyGLET, if available, is used for rendering the results on the screen via OpenGL.
  • SciPy, if available, is used for slightly faster FFTs.

Map File Format

The road network and traffic data is assumed to be a concatentation of JSON objects, each as follows:

{
	"id": [10000, 1],
	"startNodeId": [1000, 0],
	"endNodeId": [1001, 0],
	"geom": { "points": [
		{"lat": 37.7, "lon": -122.4},
		{"lat": 37.8, "lon": -122.5}
	]},
	"length": 12,
	"speedLimit": 11.2,
	"lanes": 1,
	"hmm": [
		{"mode": "go", "mean": 1.2, "cov": 1.5, "prob": 0.85},
		{"mode": "stop", "mean": 7, "cov": 0.1, "prob": 1.5E-1}
	]
}

Note the following:

  • The HMM directly represents travel times for various "modes" of travel (stop, go, etc.) for the Gaussian mixture model.
  • The HMM is "optional". If missing, pseudo-random data is generated.
  • The length and speed limit are divided to obtain the minimum travel time across each edge (we assume an ideal world where everyone abides by the speed limit). Therefore, their individual values are not relevant; only their ratio is relevant.
  • The number of lanes is only for rendering purposes.
  • Every ID is assumed to be of the form [primary, secondary], where the secondary number is small.
    The secondary component is intended to distinguish different segments of the same road for each edge.
  • A minimum covariance is enforced in the code. (If your variance is too low, you may need to change this.)
  • No comma or brackets should delimit these objects, so the full file isn't strictly JSON.
  • For hand-checking simple cases, I recommend you set the length to be a multiple of the speed limit in order to avoid floating-point round-off error.

Maintenance (or: why is the code ugly?)

This code isn't intended to finish any job for you. It's certainly not production-quality. It's just meant to help any researchers working on this topic get started and/or cross-check their algorithm correctness.

Given that it's not meant to be used in any production, I don't plan on actively maintaining it unless I encounter bugs (or if I see enough interest from others).

Example

There's no short "getting started" code example, sorry. The main startup file is basically a (very) long example.

Usage

It's pretty self-explanatory:

python Main.py --source=65280072.0 --dest=65345534.0 --budget=1800 --network="data/sf.osm.json"

The time discretization interval is automatically chosen to be the globally minimum travel time across any edge in the network, since it should be as large as possible (for speed) and smaller than the travel time of every edge. You would need to change this in the code for greater accuracy.

Note that a time budget that is too high can cause the pathfinding algorithm to thrash exponentially, because the reliability of every path reaches 100% as your time budget increases, and the algorithm ends up trying all of them.
However, realistically, you would not need to run this algorithm for very high time budgets. A classical path would already be reliable enough.

Demo

Note that you (obviously) need both a map and traffic data to run this code. Unfortunately I can't release the dataset I used in the paper, but I have a sample map from OpenStreetMap, and the code attempts to naively fill in missing traffic data, so that should be good enough to get started.

Here's an example of what one can get in 15 seconds on my machine. The code runs in two phases:

  • As time increases, the optimal policy is computed for reachable roads farther and farther from the destination (highlighted), until the source is reached.
    Roads that can never be used to reach the destination on time are not examined.
  • Once the policy is determined, the optimal path for each time budget up to the one requested is determined, in order from high to low time budget.
    This is to demonstrate the fact that the optimal path can change depending on the time budget.

Animation

Contact

Licensing

Please refer to the license file.

For attribution, a reference to the aforementioned article (which this code is based on) would be kindly appreciated.

Questions/Comments

If you find a bug, have questions, would like to contribute, or the like, feel free to open a GitHub issue/pull request/etc.

For private inquiries (e.g. commercial licensing requests), you can find my contact information if you search around (e.g. see the paper linked above).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].