pub struct Simulation { /* private fields */ }
Expand description
A traffic simulation.
Implementations§
Source§impl Simulation
impl Simulation
Sourcepub fn add_link(&mut self, attributes: &LinkAttributes<'_>) -> LinkId
pub fn add_link(&mut self, attributes: &LinkAttributes<'_>) -> LinkId
Adds a link to the network.
Sourcepub fn add_link_group(&mut self, link_ids: &[LinkId])
pub fn add_link_group(&mut self, link_ids: &[LinkId])
Specifies that these vehicles on these links may interact with vehicles on other links in the group.
Sourcepub fn add_lane_change(&mut self, from: LinkId, to: LinkId)
pub fn add_lane_change(&mut self, from: LinkId, to: LinkId)
Permits vehicles to lane change from the from
link to the to
link.
Both links must belong to the same LinkGroup.
Sourcepub fn add_link_convergance(&mut self, a: LinkId, b: LinkId)
pub fn add_link_convergance(&mut self, a: LinkId, b: LinkId)
Specifies that two links may converge or cross.
Sourcepub fn add_link_connection(&mut self, from: LinkId, to: LinkId)
pub fn add_link_connection(&mut self, from: LinkId, to: LinkId)
Specifies that the end of the from
link connects to the start of the to
link.
Sourcepub fn add_traffic_light(&mut self, light: TrafficLight) -> TrafficLightId
pub fn add_traffic_light(&mut self, light: TrafficLight) -> TrafficLightId
Adds a traffic light to the simulation.
Sourcepub fn add_vehicle(
&mut self,
attributes: &VehicleAttributes,
link: LinkId,
) -> VehicleId
pub fn add_vehicle( &mut self, attributes: &VehicleAttributes, link: LinkId, ) -> VehicleId
Adds a vehicle to the simulation.
Sourcepub fn set_vehicle_frozen(&mut self, vehicle_id: VehicleId, frozen: bool)
pub fn set_vehicle_frozen(&mut self, vehicle_id: VehicleId, frozen: bool)
Sets the frozen
attribute of a vehicle. When a vehicle is frozen,
it will maximally decelerate until its velocity is zero and remain stopped
until it is no longer frozen.
Sourcepub fn get_vehicle_frozen(&mut self, vehicle_id: VehicleId) -> bool
pub fn get_vehicle_frozen(&mut self, vehicle_id: VehicleId) -> bool
Gets the frozen
attribute of a vehicle. Read more.
Sourcepub fn step(&mut self, dt: f64)
pub fn step(&mut self, dt: f64)
Advances the simulation by dt
seconds.
For a realistic simulation, do not use a time step greater than around 0.2.
Sourcepub fn step_fast(&mut self, dt: f64)
pub fn step_fast(&mut self, dt: f64)
Advances the simulation by dt
seconds, but only integrates vehicles positions,
and doesn’t recalculate more expensive aspects of the simulation.
Use this to achieve better performance while retaining a smooth animation frame rate, though beware that simulating too many consecutive frames with this method will result in a noticeable degradation in simulation quality and realism.
Sourcepub fn iter_links(&self) -> impl Iterator<Item = &Link>
pub fn iter_links(&self) -> impl Iterator<Item = &Link>
Returns an iterator over all the links in the simulation.
Sourcepub fn iter_vehicles(&self) -> impl Iterator<Item = &Vehicle>
pub fn iter_vehicles(&self) -> impl Iterator<Item = &Vehicle>
Returns an iterator over all the vehicles in the simulation.
Sourcepub fn get_vehicle(&self, vehicle_id: VehicleId) -> &Vehicle
pub fn get_vehicle(&self, vehicle_id: VehicleId) -> &Vehicle
Gets a reference to the vehicle with the given ID.
Sourcepub fn get_link(&self, link_id: LinkId) -> &Link
pub fn get_link(&self, link_id: LinkId) -> &Link
Gets a reference to the link with the given ID.
Sourcepub fn set_link_control(&mut self, link_id: LinkId, control: TrafficControl)
pub fn set_link_control(&mut self, link_id: LinkId, control: TrafficControl)
Sets the TrafficControl at the start of the given link.
Sourcepub fn debug(&mut self) -> Value
pub fn debug(&mut self) -> Value
Gets the debugging information for the previously simulated frame as JSON array.
Sourcepub fn do_lane_change(
&mut self,
vehicle_id: VehicleId,
link_id: LinkId,
distance: f64,
)
pub fn do_lane_change( &mut self, vehicle_id: VehicleId, link_id: LinkId, distance: f64, )
Causes the given vehicle to change lanes from its current link to the specified link.
It will smoothly transition from one to the other over the given distance
specified in metres.
Sourcepub fn set_vehicle_route(&mut self, vehicle_id: VehicleId, route: &[LinkId])
pub fn set_vehicle_route(&mut self, vehicle_id: VehicleId, route: &[LinkId])
Sets the route for the given vehicle, which is the list of links it will traverse after it has exited its current link.
Trait Implementations§
Source§impl Clone for Simulation
impl Clone for Simulation
Source§fn clone(&self) -> Simulation
fn clone(&self) -> Simulation
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Default for Simulation
impl Default for Simulation
Source§fn default() -> Simulation
fn default() -> Simulation
Source§impl<'de> Deserialize<'de> for Simulation
impl<'de> Deserialize<'de> for Simulation
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Simulation
impl !RefUnwindSafe for Simulation
impl !Send for Simulation
impl !Sync for Simulation
impl Unpin for Simulation
impl UnwindSafe for Simulation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more