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
use std::collections::HashMap;
use rand_xorshift::XorShiftRng;
use abstutil::Timer;
use geom::Polygon;
use map_model::{BuildingID, BuildingType, Map};
use sim::{PersonSpec, TripMode};
#[derive(Debug)]
pub struct DesireLine {
pub home_zone: String,
pub work_zone: String,
pub mode: TripMode,
pub number_commuters: usize,
}
pub fn disaggregate(
map: &Map,
zones: &HashMap<String, Polygon>,
desire_lines: Vec<DesireLine>,
rng: &mut XorShiftRng,
timer: &mut Timer,
) -> Vec<PersonSpec> {
timer.start("match zones");
let zones = create_zones(map, zones);
timer.stop("match zones");
Vec::new()
}
struct Zone {
polygon: Polygon,
pct_overlap: f64,
homes: Vec<BuildingID>,
workplaces: Vec<BuildingID>,
}
fn create_zones(map: &Map, input: &HashMap<String, Polygon>) -> HashMap<String, Zone> {
let mut zones = HashMap::new();
for (name, polygon) in input {
let mut overlapping_area = 0.0;
for p in polygon.intersection(map.get_boundary_polygon()) {
overlapping_area += p.area();
}
let pct_overlap = overlapping_area / polygon.area();
if pct_overlap == 0.0 {
continue;
}
zones.insert(
name.clone(),
Zone {
polygon: polygon.clone(),
pct_overlap,
homes: Vec::new(),
workplaces: Vec::new(),
},
);
}
for b in map.all_buildings() {
let center = b.polygon.center();
if let Some((_, zone)) = zones
.iter_mut()
.find(|(_, z)| z.polygon.contains_pt(center))
{
match b.bldg_type {
BuildingType::Residential { .. } => {
zone.homes.push(b.id);
}
BuildingType::ResidentialCommercial(_, _) => {
zone.homes.push(b.id);
zone.workplaces.push(b.id);
}
BuildingType::Commercial(_) => {
zone.workplaces.push(b.id);
}
BuildingType::Empty => {}
}
}
}
zones
}