gather penalties based on sim state too. #217

This commit is contained in:
Dustin Carlino 2020-07-23 10:58:25 -07:00
parent 23a1b1a397
commit 9757750bfa
3 changed files with 44 additions and 6 deletions

View File

@ -299,9 +299,17 @@ impl TurnExplorer {
}
} else {
let (lt, lc) = turns[idx - 1].penalty(&app.primary.map);
let (vehicles, bike) = app
.primary
.sim
.target_lane_penalty(app.primary.map.get_l(turns[idx - 1].id.dst));
col.push(
format!("Penalties: {} for lane types, {} for lane changing", lt, lc)
.draw_text(ctx),
format!(
"Penalties: {} for lane types, {} for lane changing, {} for vehicles, {} for \
slow bikes",
lt, lc, vehicles, bike
)
.draw_text(ctx),
);
col.push(ColorLegend::row(ctx, CURRENT_TURN, "current turn"));
col.push(ColorLegend::row(ctx, CONFLICTING_TURN, "conflicting turn"));

View File

@ -3,12 +3,12 @@ use crate::mechanics::Queue;
use crate::{
ActionAtEnd, AgentID, AgentProperties, CarID, Command, CreateCar, DistanceInterval,
DrawCarInput, Event, IntersectionSimState, ParkedCar, ParkingSimState, ParkingSpot, PersonID,
Scheduler, TimeInterval, TransitSimState, TripManager, UnzoomedAgent, Vehicle, WalkingSimState,
FOLLOWING_DISTANCE,
Scheduler, TimeInterval, TransitSimState, TripManager, UnzoomedAgent, Vehicle, VehicleType,
WalkingSimState, FOLLOWING_DISTANCE,
};
use abstutil::{deserialize_btreemap, serialize_btreemap};
use geom::{Distance, Duration, PolyLine, Time};
use map_model::{LaneID, Map, Path, PathStep, Traversable};
use map_model::{Lane, LaneID, Map, Path, PathStep, Traversable};
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashSet, VecDeque};
@ -1051,4 +1051,25 @@ impl DrivingSimState {
pub fn collect_events(&mut self) -> Vec<Event> {
std::mem::replace(&mut self.events, Vec::new())
}
pub fn target_lane_penalty(&self, lane: &Lane) -> (usize, usize) {
let queue = &self.queues[&Traversable::Lane(lane.id)];
let mut num_vehicles = queue.cars.len();
if queue.laggy_head.is_some() {
num_vehicles += 1;
}
let bike_cost = if queue.cars.iter().any(|c| c.1 == VehicleType::Bike)
|| queue
.laggy_head
.map(|c| c.1 == VehicleType::Bike)
.unwrap_or(false)
{
1
} else {
0
};
(num_vehicles, bike_cost)
}
}

View File

@ -13,7 +13,7 @@ use derivative::Derivative;
use geom::{Distance, Duration, PolyLine, Pt2D, Speed, Time};
use instant::Instant;
use map_model::{
BuildingID, BusRoute, BusRouteID, IntersectionID, LaneID, Map, ParkingLotID, Path,
BuildingID, BusRoute, BusRouteID, IntersectionID, Lane, LaneID, Map, ParkingLotID, Path,
PathConstraints, PathRequest, Position, RoadID, Traversable,
};
use rand_xorshift::XorShiftRng;
@ -1168,6 +1168,15 @@ impl Sim {
pts_per_type.into_iter().collect()
}
// (number of vehicles in the lane, penalty if a bike or other slow vehicle is present)
pub fn target_lane_penalty(&self, lane: &Lane) -> (usize, usize) {
if lane.is_sidewalk() {
(0, 0)
} else {
self.driving.target_lane_penalty(lane)
}
}
}
// Invasive debugging