arup-group / genet

Manipulate MATSim networks via a Python API.
MIT License
45 stars 9 forks source link

Split (active) modal subgraphs #153

Closed KasiaKoz closed 2 years ago

KasiaKoz commented 2 years ago

Adds a script to split given modes from the links on the network graph from under the 'modes' attribute. You end up with a graph with many more links, the links with mentioned modes exists only with that mode, all other attributes are copied across (for the time being anyway, we might have to set/scale capacity/speed eventually).

Context: We use Hermes in MATSim, which results in slower vehicles, like bikes, blocking cars on links. Creating separate links for that mode is an initial solution to that problem.

Bonus: Noticed a lag with method that adds links. Because with this script we're adding links with the same from and to nodes, we need to generate a multi-index (links are stores in the graph in this format: (from_node, to_node, multiindex)). One line, which gives a closer initial guess for the multi-index speeds things up for larger graphs:

Screenshot 2022-10-24 at 10 34 20 (time in seconds)

KasiaKoz commented 2 years ago

Improved script description