mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 20:29:04 +03:00
be able to launch DES model on any lane
This commit is contained in:
parent
f7d3db302d
commit
9d450363ea
@ -43,9 +43,9 @@
|
||||
|
||||
## Discrete-event model
|
||||
|
||||
- Make cars cover an entire lane, even when it's short
|
||||
- try real distance over time ;) but does it make intersection calculation extremely hard?
|
||||
- avoid impossible accel/deaccel
|
||||
- Make cars cover an entire lane, even when it's short
|
||||
- Handle lead car being faster
|
||||
- The speed stated in the middle of intervals is clearly wrong for the follower car
|
||||
|
||||
|
@ -7,13 +7,14 @@ use sim::{CarID, CarState, DrawCarInput, VehicleType};
|
||||
const FOLLOWING_DISTANCE: Distance = Distance::const_meters(1.0);
|
||||
|
||||
pub struct World {
|
||||
lane: LaneID,
|
||||
leader: Car,
|
||||
follower: Car,
|
||||
}
|
||||
|
||||
impl World {
|
||||
pub fn new(map: &Map) -> World {
|
||||
let lane = map.get_l(LaneID(1250));
|
||||
pub fn new(l: LaneID, map: &Map) -> World {
|
||||
let lane = map.get_l(l);
|
||||
let speed_limit = map.get_parent(lane.id).get_speed_limit();
|
||||
|
||||
let mut leader = Car {
|
||||
@ -74,21 +75,25 @@ impl World {
|
||||
|
||||
leader.validate();
|
||||
follower.validate();
|
||||
World { leader, follower }
|
||||
World {
|
||||
leader,
|
||||
follower,
|
||||
lane: l,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_draw_cars(&self, time: Duration, map: &Map) -> Vec<DrawCarInput> {
|
||||
let mut draw = Vec::new();
|
||||
for car in vec![&self.leader, &self.follower] {
|
||||
if let Some((d, _)) = car.dist_at(time) {
|
||||
draw.push(draw_car(car, d, map));
|
||||
draw.push(car.get_draw_car(d, map.get_l(self.lane)));
|
||||
}
|
||||
}
|
||||
draw
|
||||
}
|
||||
|
||||
pub fn draw_tooltips(&self, g: &mut GfxCtx, ctx: &DrawCtx, time: Duration) {
|
||||
let lane = ctx.map.get_l(LaneID(1250));
|
||||
let lane = ctx.map.get_l(self.lane);
|
||||
|
||||
for car in vec![&self.leader, &self.follower] {
|
||||
if let Some((d, idx)) = car.dist_at(time) {
|
||||
@ -106,24 +111,6 @@ impl World {
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_car(car: &Car, front: Distance, map: &Map) -> DrawCarInput {
|
||||
let lane = map.get_l(LaneID(1250));
|
||||
|
||||
DrawCarInput {
|
||||
id: car.id,
|
||||
waiting_for_turn: None,
|
||||
stopping_trace: None,
|
||||
state: car.state,
|
||||
vehicle_type: VehicleType::Car,
|
||||
on: Traversable::Lane(lane.id),
|
||||
body: lane
|
||||
.lane_center_pts
|
||||
.slice(front - car.car_length, front)
|
||||
.unwrap()
|
||||
.0,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Interval {
|
||||
start_dist: Distance,
|
||||
@ -474,6 +461,22 @@ impl Car {
|
||||
assert_eq!(speed, Speed::ZERO);
|
||||
self.next_state(Distance::ZERO, Speed::ZERO, time);
|
||||
}
|
||||
|
||||
fn get_draw_car(&self, front: Distance, lane: &Lane) -> DrawCarInput {
|
||||
DrawCarInput {
|
||||
id: self.id,
|
||||
waiting_for_turn: None,
|
||||
stopping_trace: None,
|
||||
state: self.state,
|
||||
vehicle_type: VehicleType::Car,
|
||||
on: Traversable::Lane(lane.id),
|
||||
body: lane
|
||||
.lane_center_pts
|
||||
.slice(front - self.car_length, front)
|
||||
.unwrap()
|
||||
.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn overlap<A: PartialOrd>((a_start, a_end): (A, A), (b_start, b_end): (A, A)) -> bool {
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::objects::DrawCtx;
|
||||
use crate::objects::{DrawCtx, ID};
|
||||
use crate::plugins::sim::des_model;
|
||||
use crate::plugins::{BlockingPlugin, PluginCtx};
|
||||
use ezgui::{EventLoopMode, GfxCtx};
|
||||
use ezgui::{EventLoopMode, GfxCtx, Key};
|
||||
use map_model::{Map, Traversable};
|
||||
use sim::{CarID, DrawCarInput, DrawPedestrianInput, GetDrawAgents, PedestrianID, Tick};
|
||||
|
||||
@ -20,13 +20,17 @@ pub struct SimpleModelController {
|
||||
|
||||
impl SimpleModelController {
|
||||
pub fn new(ctx: &mut PluginCtx) -> Option<SimpleModelController> {
|
||||
if ctx.input.action_chosen("start simple model") {
|
||||
return Some(SimpleModelController {
|
||||
current_tick: Tick::zero(),
|
||||
world: des_model::World::new(&ctx.primary.map),
|
||||
mode: AutoMode::Off,
|
||||
show_tooltips: false,
|
||||
});
|
||||
if let Some(ID::Lane(id)) = ctx.primary.current_selection {
|
||||
if ctx.primary.map.get_l(id).is_driving()
|
||||
&& ctx.input.contextual_action(Key::C, "start simple model")
|
||||
{
|
||||
return Some(SimpleModelController {
|
||||
current_tick: Tick::zero(),
|
||||
world: des_model::World::new(id, &ctx.primary.map),
|
||||
mode: AutoMode::Off,
|
||||
show_tooltips: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
@ -75,7 +75,6 @@ impl<S: UIState> GUI<RenderingHints> for UI<S> {
|
||||
(Some(Key::D), "diff all A/B trips"),
|
||||
(Some(Key::S), "seed the sim with agents"),
|
||||
(Some(Key::LeftAlt), "swap the primary/secondary sim"),
|
||||
(Some(Key::C), "start simple model"),
|
||||
],
|
||||
),
|
||||
Folder::new(
|
||||
|
Loading…
Reference in New Issue
Block a user