use scenario for the big run

This commit is contained in:
Dustin Carlino 2019-02-25 19:55:04 -08:00
parent f1ad9f8b0c
commit 4bf7a6f4ea
4 changed files with 67 additions and 26 deletions

View File

@ -2,6 +2,7 @@ use crate::objects::{DrawCtx, ID};
use crate::plugins::sim::new_des_model;
use crate::plugins::{BlockingPlugin, PluginCtx};
use crate::render::MIN_ZOOM_FOR_DETAIL;
use abstutil::Timer;
use ezgui::{EventLoopMode, GfxCtx, Key};
use geom::{Distance, Duration, Speed};
use map_model::{BuildingID, LaneID, Map, Position, Traversable};
@ -119,6 +120,7 @@ impl GetDrawAgents for EvenSimplerModelController {
}
fn populate_sim(start: LaneID, map: &Map) -> new_des_model::Sim {
let mut timer = Timer::new("populate_sim");
let mut sim = new_des_model::Sim::new(map);
let mut sources = vec![start];
@ -153,27 +155,17 @@ fn populate_sim(start: LaneID, map: &Map) -> new_des_model::Sim {
random_ped_near(source, &mut sim, map, &mut rng);
}
sim.spawn_all_trips(map);
sim.spawn_all_trips(map, &mut timer);
timer.done();
sim
}
fn densely_populate_sim(map: &Map) -> new_des_model::Sim {
let mut timer = Timer::new("densely_populate_sim");
let mut sim = new_des_model::Sim::new(map);
let mut rng = XorShiftRng::from_seed([42; 16]);
for l in map.all_lanes() {
let len = l.length();
if l.is_driving() && len >= new_des_model::MAX_CAR_LENGTH {
for _ in 0..rng.gen_range(0, 5) {
spawn_car(&mut sim, &mut rng, map, l.id);
}
seed_parked_cars_near(l.id, &mut rng, &mut sim, map);
random_ped_near(l.id, &mut sim, map, &mut rng);
}
}
sim.spawn_all_trips(map);
new_des_model::Scenario::small_run(map).instantiate(&mut sim, map, &mut rng, &mut timer);
timer.done();
sim
}

View File

@ -10,6 +10,7 @@ pub use self::mechanics::{
DrivingSimState, IntersectionSimState, ParkingSimState, WalkingSimState,
};
pub use self::router::{ActionAtEnd, Router};
pub use self::scenario::Scenario;
pub use self::scheduler::{Command, Scheduler};
pub use self::sim::Sim;
pub use self::spawn::{TripSpawner, TripSpec};

View File

@ -61,12 +61,12 @@ pub struct SeedParkedCars {
}
impl Scenario {
pub fn describe(&self) -> Vec<String> {
/*pub fn describe(&self) -> Vec<String> {
abstutil::to_json(self)
.split('\n')
.map(|s| s.to_string())
.collect()
}
}*/
// TODO may need to fork the RNG a bit more
pub fn instantiate(&self, sim: &mut Sim, map: &Map, rng: &mut XorShiftRng, timer: &mut Timer) {
@ -234,13 +234,13 @@ impl Scenario {
if let Some(goal) =
s.goal.pick_driving_goal(map, &neighborhoods, rng, timer)
{
// TODO Do the distance correction here
let vehicle = rand_car(rng);
sim.schedule_trip(
spawn_time,
TripSpec::CarAppearing(
// TODO could pretty easily pick any lane here
Position::new(starting_driving_lanes[0], Distance::ZERO),
rand_car(rng),
Position::new(starting_driving_lanes[0], vehicle.length),
vehicle,
goal,
),
map,
@ -287,12 +287,62 @@ impl Scenario {
}
}
sim.spawn_all_trips(map);
sim.spawn_all_trips(map, timer);
timer.stop(&format!("Instantiating {}", self.scenario_name));
}
pub fn save(&self) {
/*pub fn save(&self) {
abstutil::save_object("scenarios", &self.map_name, &self.scenario_name, self);
}*/
pub fn small_run(map: &Map) -> Scenario {
let mut s = Scenario {
scenario_name: "small_spawn".to_string(),
map_name: map.get_name().to_string(),
seed_parked_cars: vec![SeedParkedCars {
neighborhood: "_everywhere_".to_string(),
cars_per_building: WeightedUsizeChoice {
weights: vec![5, 5],
},
}],
spawn_over_time: vec![SpawnOverTime {
num_agents: 100,
start_time: Duration::ZERO,
stop_time: Duration::seconds(5.0),
start_from_neighborhood: "_everywhere_".to_string(),
goal: OriginDestination::Neighborhood("_everywhere_".to_string()),
percent_biking: 0.5,
percent_use_transit: 0.5,
}],
// If there are no sidewalks/driving lanes at a border, scenario instantiation will
// just warn and skip them.
border_spawn_over_time: map
.all_incoming_borders()
.into_iter()
.map(|i| BorderSpawnOverTime {
num_peds: 10,
num_cars: 10,
num_bikes: 10,
start_time: Duration::ZERO,
stop_time: Duration::seconds(5.0),
start_from_border: i.id,
goal: OriginDestination::Neighborhood("_everywhere_".to_string()),
percent_use_transit: 0.5,
})
.collect(),
};
for i in map.all_outgoing_borders() {
s.spawn_over_time.push(SpawnOverTime {
num_agents: 10,
start_time: Duration::ZERO,
stop_time: Duration::seconds(5.0),
start_from_neighborhood: "_everywhere_".to_string(),
goal: OriginDestination::Border(i.id),
percent_biking: 0.5,
percent_use_transit: 0.5,
});
}
s
}
}

View File

@ -36,16 +36,14 @@ impl Sim {
.schedule_trip(start_time, spec, map, &self.parking);
}
pub fn spawn_all_trips(&mut self, map: &Map) {
let mut timer = Timer::new("spawn all trips");
pub fn spawn_all_trips(&mut self, map: &Map, timer: &mut Timer) {
self.spawner.spawn_all(
map,
&self.parking,
&mut self.trips,
&mut self.scheduler,
&mut timer,
timer,
);
timer.done();
}
pub fn get_free_spots(&self, l: LaneID) -> Vec<ParkingSpot> {