Struct Simulation

Source
pub struct Simulation { /* private fields */ }
Expand description

A traffic simulation.

Implementations§

Source§

impl Simulation

Source

pub fn new() -> Self

Creates a new simulation.

Adds a link to the network.

Specifies that these vehicles on these links may interact with vehicles on other links in the group.

Source

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.

Specifies that two links may converge or cross.

Specifies that the end of the from link connects to the start of the to link.

Source

pub fn add_traffic_light(&mut self, light: TrafficLight) -> TrafficLightId

Adds a traffic light to the simulation.

Source

pub fn add_vehicle( &mut self, attributes: &VehicleAttributes, link: LinkId, ) -> VehicleId

Adds a vehicle to the simulation.

Source

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.

Source

pub fn get_vehicle_frozen(&mut self, vehicle_id: VehicleId) -> bool

Gets the frozen attribute of a vehicle. Read more.

Source

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.

Source

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.

Source

pub fn frame(&self) -> usize

Gets the current simulation frame index.

Returns an iterator over all the links in the simulation.

Source

pub fn iter_vehicles(&self) -> impl Iterator<Item = &Vehicle>

Returns an iterator over all the vehicles in the simulation.

Source

pub fn get_vehicle(&self, vehicle_id: VehicleId) -> &Vehicle

Gets a reference to the vehicle with the given ID.

Gets a reference to the link with the given ID.

Sets the TrafficControl at the start of the given link.

Source

pub fn debug(&mut self) -> Value

Gets the debugging information for the previously simulated frame as JSON array.

Source

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.

Source

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

Source§

fn clone(&self) -> Simulation

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Simulation

Source§

fn default() -> Simulation

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Simulation

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Simulation

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,