pub struct Simulation {
    pub environment: SimulationEnvironment,
    pub object_agents: HashMap<RailwayObjectId, Box<dyn DecisionAgent<A = RailMovableAction>>>,
    pub metrics_handlers: Vec<Box<dyn MetricsHandler>>,
    pub is_paused: bool,
    pub speedup_factor: f64,
    /* private fields */
}
Expand description

A Simulation struct holding a railway graph and a list of moveable railway objects.

Fields§

§environment: SimulationEnvironment

The simulation environment

§object_agents: HashMap<RailwayObjectId, Box<dyn DecisionAgent<A = RailMovableAction>>>

A list of agents

§metrics_handlers: Vec<Box<dyn MetricsHandler>>

A list of metrics handlers

§is_paused: bool

simulation pause state

§speedup_factor: f64

Speedup factor of the simulation

Implementations§

source§

impl Simulation

source

pub fn new(graph: RailwayGraph) -> Self

Creates a new simulation with the given railway graph.

Arguments
  • graph - The railway graph representing the railway infrastructure.
Returns

A new Simulation instance.

source

pub fn get_observable_environment( &self ) -> &(dyn ObservableEnvironment + 'static)

Returns a reference to the observable environment of the simulation.

The observable environment allows external components to access the state of the simulation without being able to modify it. This is useful for agents to observe the simulation state and make decisions based on it.

Returns

A reference to a trait object implementing the ObservableEnvironment trait, which provides read-only access to the simulation environment.

source

pub fn add_object( &mut self, object: Box<dyn SimulationObject>, agent: Option<Box<dyn DecisionAgent<A = RailMovableAction>>> ) -> bool

Adds a moveable railway object to the simulation.

Arguments
  • object - The moveable railway object to be added to the simulation.
Returns

A boolean indicating if the object was successfully added.

source

pub fn remove_object(&mut self, id: i64) -> bool

Removes a moveable railway object from the simulation.

Arguments
  • id - The unique identifier of the moveable railway object to be removed.
Returns

A boolean indicating if the object was successfully removed.

source

pub fn add_agent_for_object( &mut self, object_id: RailwayObjectId, agent: Box<dyn DecisionAgent<A = RailMovableAction>> ) -> bool

Adds a decision agent for an object in the simulation.

Arguments
  • object_id - The unique identifier of the object.
  • agent - The decision agent to be added.
Returns

A boolean indicating if the agent was successfully added.

source

pub fn register_metrics_handler(&mut self, handler: Box<dyn MetricsHandler>)

Registers a metrics handler for the simulation.

This function adds a new metrics handler to the simulation. The metrics handler will be used to process events and gather metrics during the simulation run.

Arguments
  • handler - A boxed metrics handler that implements the MetricsHandler trait.
source

pub fn update(&mut self, delta_time: Duration)

Updates the simulation state based on the given delta time and the speedup factor.

Arguments
  • delta_time - The elapsed time since the last update.

Trait Implementations§

source§

impl Debug for Simulation

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Send for Simulation

source§

impl Sync for Simulation

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T, U> AsBindGroupShaderType<U> for Twhere U: ShaderType, &'a T: for<'a> Into<U>,

§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U

Return the T [ShaderType] for self. When used in [AsBindGroup] derives, it is safe to assume that all images in self exist.
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for Twhere T: Any,

§

fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for Twhere T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send + 'static>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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.

§

impl<T> IntoPropValue<Option<T>> for T

§

fn into_prop_value(self) -> Option<T>

Convert self to a value of a Properties struct.
§

impl<T> IntoPropValue<T> for T

§

fn into_prop_value(self) -> T

Convert self to a value of a Properties struct.
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<G1, G2> Within<G2> for G1where G2: Contains<G1>,

§

fn is_within(&self, b: &G2) -> bool

§

impl<G1, G2> Within<G2> for G1where G2: Contains<G1>,

§

fn is_within(&self, b: &G2) -> bool

§

impl<T> HasAllProps<(), T> for T

§

impl<T> Ungil for Twhere T: Send,