1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//! `map_model` describes the world where simulations occur. Importing a map from OSM partly happens
//! in `convert_osm` and here.
//!
//! Helpful terminology:
//! - ch = contraction hierarchy, for speeding up pathfinding
//! - degenerate intersection = only has 2 roads connected, so why is it an intersection at all?
//! - lc = lane-change (which is modelled very strangely: <https://a-b-street.github.io/docs/tech/trafficsim/discrete_event.html#lane-changing>)
//! - ltr = left-to-right, the order of lanes for a road
//! - osm = OpenStreetMap
//!
//! Map objects are usually abbreviated in method names:
//! - a = area
//! - b = building
//! - tr = transit route
//! - ts = transit stop
//! - i = intersection
//! - l = lane
//! - pl = parking lot
//! - r = road
//! - ss = stop sign
//! - t = turn
//! - ts = traffic signal

#![allow(clippy::new_without_default)]

#[macro_use]
extern crate anyhow;
#[macro_use]
extern crate log;

use std::collections::BTreeMap;

use serde::{Deserialize, Serialize};

use abstio::MapName;
use abstutil::{
    deserialize_btreemap, deserialize_multimap, serialize_btreemap, serialize_multimap, MultiMap,
};
use geom::{Bounds, GPSBounds, Polygon};
// Re-export a bunch of things for convenience
pub use raw_map::{Amenity, AmenityType, AreaType};
pub use street_network::ControlType as IntersectionType;
pub use street_network::{
    osm, BufferType, Direction, DrivingSide, LaneSpec, LaneType, MapConfig, NamePerLanguage,
    OriginalRoad, RestrictionType, NORMAL_LANE_THICKNESS, SIDEWALK_THICKNESS,
};

pub use crate::city::City;
pub use crate::edits::{
    EditCmd, EditEffects, EditIntersection, EditRoad, MapEdits, PermanentMapEdits,
};
pub use crate::make::RawToMapOptions;
pub use crate::objects::area::{Area, AreaID};
pub use crate::objects::block::{Block, Perimeter};
pub use crate::objects::building::{Building, BuildingID, BuildingType, OffstreetParking};
pub use crate::objects::intersection::{Intersection, IntersectionID};
pub use crate::objects::lane::{CommonEndpoint, Lane, LaneID, PARKING_LOT_SPOT_LENGTH};
pub use crate::objects::movement::{CompressedMovementID, Movement, MovementID};
pub use crate::objects::parking_lot::{ParkingLot, ParkingLotID};
pub use crate::objects::road::{DirectedRoadID, Road, RoadID, RoadSideID, SideOfRoad};
pub use crate::objects::stop_signs::{ControlStopSign, RoadWithStopSign};
pub use crate::objects::traffic_signals::{ControlTrafficSignal, Stage, StageType};
pub use crate::objects::transit::{TransitRoute, TransitRouteID, TransitStop, TransitStopID};
pub use crate::objects::turn::{Turn, TurnID, TurnPriority, TurnType};
pub use crate::objects::zone::{AccessRestrictions, Zone};
pub use crate::pathfind::uber_turns::{IntersectionCluster, UberTurn};
pub use crate::pathfind::{
    Path, PathConstraints, PathRequest, PathStep, PathStepV2, PathV2, Pathfinder, PathfinderCache,
    PathfinderCaching, RoutingParams,
};
pub use crate::traversable::{Position, Traversable, MAX_BIKE_SPEED, MAX_WALKING_SPEED};

mod city;
pub mod connectivity;
mod edits;
mod make;
mod map;
mod objects;
mod pathfind;
mod traversable;

// The map used by the simulation and UI. This struct is declared here so that the rest of the
// crate can reach into private fields.
#[derive(Clone, Serialize, Deserialize)]
pub struct Map {
    roads: Vec<Road>,
    intersections: Vec<Intersection>,
    buildings: Vec<Building>,
    #[serde(
        serialize_with = "serialize_btreemap",
        deserialize_with = "deserialize_btreemap"
    )]
    transit_stops: BTreeMap<TransitStopID, TransitStop>,
    transit_routes: Vec<TransitRoute>,
    areas: Vec<Area>,
    parking_lots: Vec<ParkingLot>,
    boundary_polygon: Polygon,

    // Note that border nodes belong in neither!
    stop_signs: BTreeMap<IntersectionID, ControlStopSign>,
    traffic_signals: BTreeMap<IntersectionID, ControlTrafficSignal>,

    #[serde(
        serialize_with = "serialize_multimap",
        deserialize_with = "deserialize_multimap"
    )]
    bus_routes_on_roads: MultiMap<osm::WayID, String>,

    gps_bounds: GPSBounds,
    bounds: Bounds,
    config: MapConfig,

    pathfinder: Pathfinder,
    pathfinder_dirty: bool,
    routing_params: RoutingParams,
    // Not the source of truth, just cached.
    zones: Vec<Zone>,

    name: MapName,

    #[serde(skip_serializing, skip_deserializing)]
    edits: MapEdits,
    #[serde(skip_serializing, skip_deserializing)]
    edits_generation: usize,
    #[serde(skip_serializing, skip_deserializing)]
    road_to_buildings: MultiMap<RoadID, BuildingID>,
}