pub struct Simulator<M: AbstractSimulator> { /* private fields */ }
Expand description
A DEVS simulator that uses a virtual clock (i.e., no real time is used).
Implementations§
Source§impl<M: AbstractSimulator> Simulator<M>
impl<M: AbstractSimulator> Simulator<M>
Sourcepub const fn new(model: M) -> Self
pub const fn new(model: M) -> Self
Examples found in repository?
examples/gpt.rs (line 244)
232fn main() {
233 let period = 1.;
234 let proc_time = 1.1;
235 let obs_time = 10.;
236
237 let generator = generator::Generator::new(generator::GeneratorState::new(period));
238 let processor = processor::Processor::new(processor::ProcessorState::new(proc_time));
239 let transducer = transducer::Transducer::new(transducer::TransducerState::new(obs_time));
240
241 let ef = EF::new(generator, transducer);
242 let efp = EFP::new(ef, processor);
243
244 let mut simulator = xdevs::simulator::Simulator::new(efp);
245 simulator.simulate_rt(
246 0.0,
247 14.0,
248 xdevs::simulator::std::sleep(0.0, 1.0, None),
249 |_| {},
250 );
251}
Sourcepub fn simulate_rt(
&mut self,
t_start: f64,
t_stop: f64,
wait_until: impl FnMut(f64, &mut M::Input) -> f64,
propagate_output: impl FnMut(&M::Output),
)
pub fn simulate_rt( &mut self, t_start: f64, t_stop: f64, wait_until: impl FnMut(f64, &mut M::Input) -> f64, propagate_output: impl FnMut(&M::Output), )
It executes the simulation of the inner DEVS model from t_start
to t_stop
.
It provides support for real time execution via the following arguments:
wait_until
: a closure that is called between state transitions. It receives the time of the next state transition and a mutable reference to the input ports. It returns the actual time “waited”. If the returned time is equal to the input time, an internal/confluent state transition is performed. Otherwise, it assumes that an external event happened and executes the external transition function.propagate_output
: a closure that is called after output functions. It receives a mutable reference to the output ports so the closure can access to output events. Feel free to ignore this argument if you do not need to propagate output messages.
Examples found in repository?
examples/gpt.rs (lines 245-250)
232fn main() {
233 let period = 1.;
234 let proc_time = 1.1;
235 let obs_time = 10.;
236
237 let generator = generator::Generator::new(generator::GeneratorState::new(period));
238 let processor = processor::Processor::new(processor::ProcessorState::new(proc_time));
239 let transducer = transducer::Transducer::new(transducer::TransducerState::new(obs_time));
240
241 let ef = EF::new(generator, transducer);
242 let efp = EFP::new(ef, processor);
243
244 let mut simulator = xdevs::simulator::Simulator::new(efp);
245 simulator.simulate_rt(
246 0.0,
247 14.0,
248 xdevs::simulator::std::sleep(0.0, 1.0, None),
249 |_| {},
250 );
251}
Sourcepub fn simulate_vt(&mut self, t_start: f64, t_stop: f64)
pub fn simulate_vt(&mut self, t_start: f64, t_stop: f64)
It executes the simulation of the inner DEVS model from t_start
to t_stop
.
It uses a virtual clock (i.e., no real time is used).
Auto Trait Implementations§
impl<M> Freeze for Simulator<M>where
M: Freeze,
impl<M> RefUnwindSafe for Simulator<M>where
M: RefUnwindSafe,
impl<M> Send for Simulator<M>where
M: Send,
impl<M> Sync for Simulator<M>where
M: Sync,
impl<M> Unpin for Simulator<M>where
M: Unpin,
impl<M> UnwindSafe for Simulator<M>where
M: UnwindSafe,
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
Mutably borrows from an owned value. Read more