mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 07:25:47 +03:00
cargo +nightly fmt
This commit is contained in:
parent
c811c7e044
commit
aa765f70ed
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -2386,6 +2386,14 @@ dependencies = [
|
||||
"getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_distr"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.1.0"
|
||||
@ -2791,6 +2799,7 @@ dependencies = [
|
||||
"libm 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"map_model 0.1.0",
|
||||
"rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_distr 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_xorshift 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -4034,6 +4043,7 @@ dependencies = [
|
||||
"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
|
||||
"checksum rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
|
||||
"checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
|
||||
"checksum rand_distr 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "96977acbdd3a6576fb1d27391900035bf3863d4a16422973a409b488cf29ffb2"
|
||||
"checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4"
|
||||
"checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
|
||||
"checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08"
|
||||
|
@ -11,8 +11,8 @@ geom = { path = "../geom" }
|
||||
instant = "0.1.2"
|
||||
map_model = { path = "../map_model" }
|
||||
rand = "0.7.0"
|
||||
rand_xorshift = "0.2.0"
|
||||
rand_distr = "0.2.2"
|
||||
rand_xorshift = "0.2.0"
|
||||
serde = "1.0.98"
|
||||
serde_derive = "1.0.98"
|
||||
libm = "0.2.1"
|
||||
|
@ -68,8 +68,6 @@ impl From<f64> for AnyTime {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum StateEvent {
|
||||
Exposition,
|
||||
@ -90,44 +88,59 @@ pub struct Event {
|
||||
impl Event {
|
||||
fn next(&self, now: AnyTime, rng: &mut XorShiftRng) -> State {
|
||||
match self.s {
|
||||
StateEvent::Exposition => State::Exposed((Event {
|
||||
s: StateEvent::Incubation,
|
||||
p_hosp: self.p_hosp,
|
||||
p_death: self.p_death,
|
||||
t: now + State::get_time_normal(State::T_INC, State::T_INC / 2.0, rng),
|
||||
}, now.into()) ),
|
||||
StateEvent::Exposition => State::Exposed((
|
||||
Event {
|
||||
s: StateEvent::Incubation,
|
||||
p_hosp: self.p_hosp,
|
||||
p_death: self.p_death,
|
||||
t: now + State::get_time_normal(State::T_INC, State::T_INC / 2.0, rng),
|
||||
},
|
||||
now.into(),
|
||||
)),
|
||||
StateEvent::Incubation => {
|
||||
if rng.gen_bool(self.p_death) {
|
||||
State::Infectious((Event {
|
||||
s: StateEvent::Recovery,
|
||||
p_hosp: self.p_hosp,
|
||||
p_death: self.p_death,
|
||||
t: now + State::get_time_normal(State::T_INF, State::T_INF / 2.0, rng),
|
||||
}, now.into()))
|
||||
State::Infectious((
|
||||
Event {
|
||||
s: StateEvent::Recovery,
|
||||
p_hosp: self.p_hosp,
|
||||
p_death: self.p_death,
|
||||
t: now + State::get_time_normal(State::T_INF, State::T_INF / 2.0, rng),
|
||||
},
|
||||
now.into(),
|
||||
))
|
||||
} else {
|
||||
State::Infectious((Event {
|
||||
s: StateEvent::Hospitalization,
|
||||
p_hosp: self.p_hosp,
|
||||
p_death: self.p_death,
|
||||
t: now + State::get_time_normal(State::T_INF, State::T_INF / 2.0, rng),
|
||||
}, now.into()))
|
||||
State::Infectious((
|
||||
Event {
|
||||
s: StateEvent::Hospitalization,
|
||||
p_hosp: self.p_hosp,
|
||||
p_death: self.p_death,
|
||||
t: now + State::get_time_normal(State::T_INF, State::T_INF / 2.0, rng),
|
||||
},
|
||||
now.into(),
|
||||
))
|
||||
}
|
||||
}
|
||||
StateEvent::Hospitalization => {
|
||||
if rng.gen_bool(self.p_hosp) {
|
||||
State::Hospitalized((Event {
|
||||
s: StateEvent::Recovery,
|
||||
p_hosp: self.p_hosp,
|
||||
p_death: self.p_death,
|
||||
t: now + State::get_time_normal(State::T_INF, State::T_INF / 2.0, rng),
|
||||
}, now.into()))
|
||||
State::Hospitalized((
|
||||
Event {
|
||||
s: StateEvent::Recovery,
|
||||
p_hosp: self.p_hosp,
|
||||
p_death: self.p_death,
|
||||
t: now + State::get_time_normal(State::T_INF, State::T_INF / 2.0, rng),
|
||||
},
|
||||
now.into(),
|
||||
))
|
||||
} else {
|
||||
State::Hospitalized((Event {
|
||||
s: StateEvent::Death,
|
||||
p_hosp: self.p_hosp,
|
||||
p_death: self.p_death,
|
||||
t: now + State::get_time_normal(State::T_INF, State::T_INF / 2.0, rng),
|
||||
}, now.into()))
|
||||
State::Hospitalized((
|
||||
Event {
|
||||
s: StateEvent::Death,
|
||||
p_hosp: self.p_hosp,
|
||||
p_death: self.p_death,
|
||||
t: now + State::get_time_normal(State::T_INF, State::T_INF / 2.0, rng),
|
||||
},
|
||||
now.into(),
|
||||
))
|
||||
}
|
||||
}
|
||||
StateEvent::Death => State::Dead(now.into()),
|
||||
@ -164,12 +177,13 @@ impl State {
|
||||
}
|
||||
|
||||
fn new(p_hosp: f64, p_death: f64) -> Self {
|
||||
Self::Sane((Event {
|
||||
s: StateEvent::Exposition,
|
||||
p_hosp,
|
||||
p_death,
|
||||
t: AnyTime::from(std::f64::INFINITY),
|
||||
},
|
||||
Self::Sane((
|
||||
Event {
|
||||
s: StateEvent::Exposition,
|
||||
p_hosp,
|
||||
p_death,
|
||||
t: AnyTime::from(std::f64::INFINITY),
|
||||
},
|
||||
Time::START_OF_DAY,
|
||||
))
|
||||
}
|
||||
@ -186,7 +200,7 @@ impl State {
|
||||
|
||||
fn is_sane(&self) -> bool {
|
||||
match self {
|
||||
State::Sane((ev,_)) => !ev.t.is_finite(),
|
||||
State::Sane((ev, _)) => !ev.t.is_finite(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@ -222,17 +236,20 @@ impl State {
|
||||
pub fn get_time(&self) -> Option<Time> {
|
||||
match self {
|
||||
Self::Sane(_) => None,
|
||||
Self::Recovered(t) | Self::Dead(t) | Self::Exposed((_, t)) | Self::Infectious((_, t)) | Self::Hospitalized((_, t)) => {
|
||||
Some(*t)
|
||||
}
|
||||
Self::Recovered(t)
|
||||
| Self::Dead(t)
|
||||
| Self::Exposed((_, t))
|
||||
| Self::Infectious((_, t))
|
||||
| Self::Hospitalized((_, t)) => Some(*t),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_event_time(&self) -> Option<AnyTime> {
|
||||
match self {
|
||||
Self::Sane((ev, _)) | Self::Exposed((ev, _)) | Self::Infectious((ev, _)) | Self::Hospitalized((ev, _)) => {
|
||||
Some(ev.t)
|
||||
}
|
||||
Self::Sane((ev, _))
|
||||
| Self::Exposed((ev, _))
|
||||
| Self::Infectious((ev, _))
|
||||
| Self::Hospitalized((ev, _)) => Some(ev.t),
|
||||
Self::Recovered(_) | Self::Dead(_) => None,
|
||||
}
|
||||
}
|
||||
@ -301,7 +318,12 @@ impl State {
|
||||
}
|
||||
|
||||
// TODO: not sure if we want an option here... I guess here we want because we could have
|
||||
pub fn start(self, now: AnyTime, overlap: Duration, rng: &mut XorShiftRng) -> Result<Self, String> {
|
||||
pub fn start(
|
||||
self,
|
||||
now: AnyTime,
|
||||
overlap: Duration,
|
||||
rng: &mut XorShiftRng,
|
||||
) -> Result<Self, String> {
|
||||
// rewrite this part with it
|
||||
match self {
|
||||
Self::Sane((ev, t)) => {
|
||||
@ -311,8 +333,9 @@ impl State {
|
||||
Ok(Self::Sane((ev, t)))
|
||||
}
|
||||
}
|
||||
_ => Err(String::from("Error: impossible to start from a non-sane situation."))
|
||||
_ => Err(String::from(
|
||||
"Error: impossible to start from a non-sane situation.",
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::pandemic::{AnyTime, State};
|
||||
use crate::{CarID, Command, Event, Person, PersonID, Scheduler, TripPhaseType};
|
||||
use crate::{CarID, Event, Person, PersonID, Scheduler, TripPhaseType};
|
||||
use geom::{Duration, Time};
|
||||
use map_model::{BuildingID, BusStopID};
|
||||
use rand::Rng;
|
||||
@ -67,7 +67,13 @@ impl PandemicModel {
|
||||
for p in population {
|
||||
let state = State::new(0.5, 0.5);
|
||||
let state = if self.rng.gen_bool(State::ini_exposed_ratio()) {
|
||||
let next_state = state.start(AnyTime::from(Time::START_OF_DAY), Duration::seconds(std::f64::MAX), &mut self.rng).unwrap();
|
||||
let next_state = state
|
||||
.start(
|
||||
AnyTime::from(Time::START_OF_DAY),
|
||||
Duration::seconds(std::f64::MAX),
|
||||
&mut self.rng,
|
||||
)
|
||||
.unwrap();
|
||||
let next_state = if self.rng.gen_bool(State::ini_infectious_ratio()) {
|
||||
next_state
|
||||
.next_default(AnyTime::from(Time::START_OF_DAY), &mut self.rng)
|
||||
@ -84,47 +90,66 @@ impl PandemicModel {
|
||||
}
|
||||
|
||||
pub fn count_sane(&self) -> usize {
|
||||
self.pop.iter().filter(|(_, state)| match state {
|
||||
State::Sane(_) => true,
|
||||
_ => false,
|
||||
}).count()
|
||||
self.pop
|
||||
.iter()
|
||||
.filter(|(_, state)| match state {
|
||||
State::Sane(_) => true,
|
||||
_ => false,
|
||||
})
|
||||
.count()
|
||||
// self.sane.len()
|
||||
}
|
||||
|
||||
pub fn count_exposed(&self) -> usize {
|
||||
self.pop.iter().filter(|(_, state)| match state {
|
||||
State::Exposed(_) => true,
|
||||
_ => false,
|
||||
}).count()
|
||||
self.pop
|
||||
.iter()
|
||||
.filter(|(_, state)| match state {
|
||||
State::Exposed(_) => true,
|
||||
_ => false,
|
||||
})
|
||||
.count()
|
||||
// self.exposed.len()
|
||||
}
|
||||
|
||||
pub fn count_infected(&self) -> usize {
|
||||
// self.infected.len()
|
||||
self.pop.iter().filter(|(_, state)| match state {
|
||||
State::Infectious(_) | State::Hospitalized(_) => true,
|
||||
_ => false,
|
||||
}).count()
|
||||
self.pop
|
||||
.iter()
|
||||
.filter(|(_, state)| match state {
|
||||
State::Infectious(_) | State::Hospitalized(_) => true,
|
||||
_ => false,
|
||||
})
|
||||
.count()
|
||||
}
|
||||
|
||||
pub fn count_recovered(&self) -> usize {
|
||||
self.pop.iter().filter(|(_, state)| match state {
|
||||
State::Recovered(_) => true,
|
||||
_ => false,
|
||||
}).count()
|
||||
self.pop
|
||||
.iter()
|
||||
.filter(|(_, state)| match state {
|
||||
State::Recovered(_) => true,
|
||||
_ => false,
|
||||
})
|
||||
.count()
|
||||
// self.recovered.len()
|
||||
}
|
||||
|
||||
pub fn count_dead(&self) -> usize {
|
||||
self.pop.iter().filter(|(_, state)| match state {
|
||||
State::Dead(_) => true,
|
||||
_ => false,
|
||||
}).count()
|
||||
self.pop
|
||||
.iter()
|
||||
.filter(|(_, state)| match state {
|
||||
State::Dead(_) => true,
|
||||
_ => false,
|
||||
})
|
||||
.count()
|
||||
// self.recovered.len()
|
||||
}
|
||||
|
||||
pub fn count_total(&self) -> usize {
|
||||
self.count_sane() + self.count_exposed() + self.count_infected() + self.count_recovered() + self.count_dead()
|
||||
self.count_sane()
|
||||
+ self.count_exposed()
|
||||
+ self.count_infected()
|
||||
+ self.count_recovered()
|
||||
+ self.count_dead()
|
||||
}
|
||||
|
||||
pub fn handle_event(&mut self, now: Time, ev: &Event, scheduler: &mut Scheduler) {
|
||||
@ -263,7 +288,6 @@ impl PandemicModel {
|
||||
|
||||
// transition from a state to another without interaction with others
|
||||
fn transition(&mut self, now: Time, person: PersonID, _scheduler: &mut Scheduler) {
|
||||
|
||||
let state = self.pop.remove(&person).unwrap();
|
||||
let state = state.next(AnyTime::from(now), &mut self.rng).unwrap();
|
||||
self.pop.insert(person, state);
|
||||
@ -276,11 +300,22 @@ impl PandemicModel {
|
||||
// }
|
||||
}
|
||||
|
||||
fn become_exposed(&mut self, now: Time, overlap: Duration, person: PersonID, _scheduler: &mut Scheduler) {
|
||||
fn become_exposed(
|
||||
&mut self,
|
||||
now: Time,
|
||||
overlap: Duration,
|
||||
person: PersonID,
|
||||
_scheduler: &mut Scheduler,
|
||||
) {
|
||||
// When poeple become expose
|
||||
let state = self.pop.remove(&person).unwrap();
|
||||
assert_eq!(state.get_event_time().unwrap().inner_seconds(), std::f64::INFINITY);
|
||||
let state = state.start(AnyTime::from(now), overlap, &mut self.rng).unwrap();
|
||||
assert_eq!(
|
||||
state.get_event_time().unwrap().inner_seconds(),
|
||||
std::f64::INFINITY
|
||||
);
|
||||
let state = state
|
||||
.start(AnyTime::from(now), overlap, &mut self.rng)
|
||||
.unwrap();
|
||||
self.pop.insert(person, state);
|
||||
|
||||
// if self.rng.gen_bool(0.1) {
|
||||
|
Loading…
Reference in New Issue
Block a user