Define a second ranking for roads, beyond the 3 tiers. Just use for the NACTO max cycle length heuristic. #446

This commit is contained in:
Dustin Carlino 2021-01-26 14:39:17 -08:00
parent cbf0763327
commit 92b1f92d54
2 changed files with 38 additions and 3 deletions

View File

@ -233,11 +233,18 @@ impl ControlTrafficSignal {
}
// What's the rank of each road?
let mut rank_per_road: BTreeMap<RoadID, osm::RoadRank> = BTreeMap::new();
let mut rank_per_road: BTreeMap<RoadID, usize> = BTreeMap::new();
for r in &map.get_i(self.id).roads {
rank_per_road.insert(*r, map.get_r(*r).get_rank());
rank_per_road.insert(
*r,
map.get_r(*r)
.osm_tags
.get(osm::HIGHWAY)
.map(|hwy| osm::RoadRank::detailed_from_highway(hwy))
.unwrap_or(0),
);
}
let mut ranks: Vec<osm::RoadRank> = rank_per_road.values().cloned().collect();
let mut ranks: Vec<usize> = rank_per_road.values().cloned().collect();
ranks.sort();
ranks.dedup();
if ranks.len() == 1 {

View File

@ -49,6 +49,34 @@ impl RoadRank {
_ => RoadRank::Local,
}
}
/// Larger number means a bigger road, according to https://wiki.openstreetmap.org/wiki/Key:highway
pub fn detailed_from_highway(hwy: &str) -> usize {
for (idx, x) in vec![
"motorway",
"motorway_link",
"trunk",
"trunk_link",
"primary",
"primary_link",
"secondary",
"secondary_link",
"tertiary",
"tertiary_link",
"unclassified",
"residential",
"cycleway",
]
.into_iter()
.enumerate()
{
if hwy == x {
return 100 - idx;
}
}
// Everything else gets lowest priority
0
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]