map_model/
lib.rs

1//! `map_model` describes the world where simulations occur. Importing a map from OSM partly happens
2//! in `convert_osm` and here.
3//!
4//! Helpful terminology:
5//! - ch = contraction hierarchy, for speeding up pathfinding
6//! - degenerate intersection = only has 2 roads connected, so why is it an intersection at all?
7//! - lc = lane-change (which is modelled very strangely: <https://a-b-street.github.io/docs/tech/trafficsim/discrete_event/index.html#lane-changing>)
8//! - ltr = left-to-right, the order of lanes for a road
9//! - osm = OpenStreetMap
10//!
11//! Map objects are usually abbreviated in method names:
12//! - a = area
13//! - b = building
14//! - tr = transit route
15//! - ts = transit stop
16//! - i = intersection
17//! - l = lane
18//! - pl = parking lot
19//! - r = road
20//! - ss = stop sign
21//! - t = turn
22//! - ts = traffic signal
23
24#![allow(clippy::new_without_default)]
25
26#[macro_use]
27extern crate anyhow;
28#[macro_use]
29extern crate log;
30
31use std::collections::BTreeMap;
32use std::sync::{Arc, RwLock};
33
34use popgetter::CensusZone;
35use serde::{Deserialize, Serialize};
36
37use abstio::MapName;
38use abstutil::{
39    deserialize_btreemap, deserialize_multimap, serialize_btreemap, serialize_multimap, MultiMap,
40};
41use geom::{Bounds, FindClosest, GPSBounds, Polygon};
42pub use osm2streets::{
43    osm, BufferType, Direction, DrivingSide, IntersectionControl, IntersectionKind, LaneSpec,
44    LaneType, MapConfig, NamePerLanguage, RestrictionType, NORMAL_LANE_THICKNESS,
45    SIDEWALK_THICKNESS,
46};
47pub use raw_map::{Amenity, AmenityType, AreaType, CrossingType, ExtraPOI, ExtraPOIType};
48
49pub use crate::city::City;
50pub use crate::edits::{
51    EditCmd, EditEffects, EditIntersection, EditIntersectionControl, EditRoad, MapEdits,
52    PermanentMapEdits,
53};
54
55pub use crate::make::RawToMapOptions;
56pub use crate::objects::area::{Area, AreaID};
57pub use crate::objects::building::{Building, BuildingID, BuildingType, OffstreetParking};
58pub use crate::objects::intersection::{Intersection, IntersectionID};
59pub use crate::objects::lane::{CommonEndpoint, Lane, LaneID, PARKING_LOT_SPOT_LENGTH};
60pub use crate::objects::modal_filter::{DiagonalFilter, FilterType, RoadFilter};
61pub use crate::objects::movement::{CompressedMovementID, Movement, MovementID};
62pub use crate::objects::parking_lot::{ParkingLot, ParkingLotID};
63pub use crate::objects::road::{
64    Crossing, DirectedRoadID, OriginalRoad, Road, RoadID, RoadSideID, SideOfRoad,
65};
66pub use crate::objects::stop_signs::{ControlStopSign, RoadWithStopSign};
67pub use crate::objects::traffic_signals::{ControlTrafficSignal, Stage, StageType};
68pub use crate::objects::transit::{TransitRoute, TransitRouteID, TransitStop, TransitStopID};
69pub use crate::objects::turn::{Turn, TurnID, TurnPriority, TurnType};
70pub use crate::objects::zone::{AccessRestrictions, Zone};
71pub use crate::pathfind::uber_turns::{IntersectionCluster, UberTurn};
72pub use crate::pathfind::{
73    Path, PathConstraints, PathRequest, PathStep, PathStepV2, PathV2, Pathfinder, PathfinderCache,
74    PathfinderCaching, RoutingParams,
75};
76pub use crate::traversable::{Position, Traversable, MAX_BIKE_SPEED, MAX_WALKING_SPEED};
77pub use map::turn_type_from_angles;
78
79mod city;
80pub mod connectivity;
81mod edits;
82mod make;
83mod map;
84mod objects;
85mod pathfind;
86mod traversable;
87
88// The map used by the simulation and UI. This struct is declared here so that the rest of the
89// crate can reach into private fields.
90#[derive(Clone, Serialize, Deserialize)]
91pub struct Map {
92    roads: Vec<Road>,
93    intersections: Vec<Intersection>,
94    #[serde(skip_serializing, skip_deserializing)]
95    intersection_quad_tree: Arc<RwLock<Option<FindClosest<IntersectionID>>>>,
96    buildings: Vec<Building>,
97    #[serde(
98        serialize_with = "serialize_btreemap",
99        deserialize_with = "deserialize_btreemap"
100    )]
101    transit_stops: BTreeMap<TransitStopID, TransitStop>,
102    transit_routes: Vec<TransitRoute>,
103    areas: Vec<Area>,
104    parking_lots: Vec<ParkingLot>,
105    boundary_polygon: Polygon,
106
107    // Note that border nodes belong in neither!
108    stop_signs: BTreeMap<IntersectionID, ControlStopSign>,
109    traffic_signals: BTreeMap<IntersectionID, ControlTrafficSignal>,
110
111    #[serde(
112        serialize_with = "serialize_multimap",
113        deserialize_with = "deserialize_multimap"
114    )]
115    bus_routes_on_roads: MultiMap<osm::WayID, String>,
116
117    gps_bounds: GPSBounds,
118    bounds: Bounds,
119    config: MapConfig,
120
121    pathfinder: Pathfinder,
122    pathfinder_dirty: bool,
123    routing_params: RoutingParams,
124    // Not the source of truth, just cached.
125    zones: Vec<Zone>,
126    census_zones: Vec<(Polygon, CensusZone)>,
127    extra_pois: Vec<ExtraPOI>,
128
129    name: MapName,
130
131    #[serde(skip_serializing, skip_deserializing)]
132    edits: MapEdits,
133    #[serde(skip_serializing, skip_deserializing)]
134    edits_generation: usize,
135    #[serde(skip_serializing, skip_deserializing)]
136    road_to_buildings: MultiMap<RoadID, BuildingID>,
137}