mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 03:35:51 +03:00
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:
parent
cbf0763327
commit
92b1f92d54
@ -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 {
|
||||
|
@ -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)]
|
||||
|
Loading…
Reference in New Issue
Block a user