class YPetri::Simulation::Timed::Recorder
Timed
aspect of the recorder.
Constants
- TIME_DECIMAL_PLACES
Attributes
next_time[R]
sampling[RW]
Public Class Methods
new( sampling: default_sampling, next_time: time, **named_args )
click to toggle source
Apart from the vanilla version arguments, timed recorder takes :sampling
argument.
Calls superclass method
YPetri::Simulation::Recorder::new
# File lib/y_petri/simulation/timed/recorder.rb, line 17 def initialize( sampling: default_sampling, next_time: time, **named_args ) super @sampling, @next_time = sampling, next_time end
Public Instance Methods
alert!()
click to toggle source
To be called by simulators whenever the state changes (every time that simulation time
is incremented).
# File lib/y_petri/simulation/timed/recorder.rb, line 39 def alert! t = time.round( 9 ) t2 = next_time.round( 9 ) if t >= t2 then # it's time to sample sample! @next_time += sampling end end
back!(by=simulation.step)
click to toggle source
Steps the simulation back. This prototype version of the method simply reconstructs a new simulation at a given time (1 simulation step by default) before the current time.
# File lib/y_petri/simulation/timed/recorder.rb, line 52 def back! by=simulation.step time = simulation.time - by simulation.recording.reconstruct( at: simulation.recording.floor( time ) ) .tap { |sim| sim.run! upto: time } end
new_recording()
click to toggle source
Construct a new recording based on features
.
# File lib/y_petri/simulation/timed/recorder.rb, line 24 def new_recording features.DataSet.new type: :timed end
reset!(sampling: default_sampling, next_time: time, **named_args)
click to toggle source
Like +YPetri::Simulation::Recorder#reset+, but allowing for an additional named argument :next_time
that sets the next sampling time, and +:sampling:, resetting the sampling period.
Calls superclass method
YPetri::Simulation::Recorder#reset!
# File lib/y_petri/simulation/timed/recorder.rb, line 32 def reset! sampling: default_sampling, next_time: time, **named_args super.tap{ @sampling, @next_time = sampling, next_time } end
Private Instance Methods
sample!()
click to toggle source
Records the current state as a pair { sampling_time => system_state }.
Calls superclass method
YPetri::Simulation::Recorder#sample!
# File lib/y_petri/simulation/timed/recorder.rb, line 62 def sample! sampling_time = time.round( TIME_DECIMAL_PLACES ) super sampling_time end