-
Notifications
You must be signed in to change notification settings - Fork 19
Description
Is your feature request related to a problem? Please describe.
in osm and routing networks it is common to have turn restrictions. these change the possible shortest paths of a given mode.
due to the fact that no open or clear algorithm exist for that matter, I either use valhalla when using osm (it takes turn restrictions into account) or proprietary software. I havent found routing engines in the R ecosystem that do that.
Describe the solution you'd like
there is one way I know to handle this problem that is implemented in MATSim that basically changes the structure of the net, and breaks a node that has a restriction to a system of many nodes.
due to the fact that this solution might cause spatial distortions a mess up graph indexing, I thought of a different
way to tackle the problem - switching nodes and edges using to_linegraph, and then removing those "edge-to-edge" (which resemble a part of a node) edges, thus implementing turn restrictions.
(my post-doc instructor once told me there are 3 ways to deal with turn restrictions, but never told me which ones; here are 2. there are probably more and they might be more readible/efficient. )
Describe alternatives you've considered
this mainly gpt-generated script is a start, I don't know how to move weights from the edges to the nodes so st_network_cost will take them into account, or how to use the temp network to start and end in a specific node and not in an edge.
library(sfnetworks)
library(tidygraph)
#> Warning: package 'tidygraph' was built under R version 4.3.3
#>
#> Attaching package: 'tidygraph'
#> The following object is masked from 'package:stats':
#>
#> filter
# Original sfnetwork 'g' with spatial edges
lg <- convert(as_sfnetwork(roxel), to_linegraph)
# Suppose you have a data frame 'turns' listing prohibited transitions:
# from_edge_id | to_edge_id
from_edge_id = 423
to_edge_id = 1
lg2 <- lg %>%
activate("edges") %>%
filter(!(from %in% from_edge_id & to %in% to_edge_id))
# Now 'lg2' is a line graph without the restricted turns.
Created on 2025-06-10 with [reprex v2.1.1](https://reprex.tidyverse.org/)