Class: YPetri::Simulation::Recorder
- Inherits:
-
Object
- Object
- YPetri::Simulation::Recorder
- Defined in:
- lib/y_petri/simulation/recorder.rb
Overview
A machine that receives alerts during simulation and records a recording according to its implementation. Alerts are received via #alert
method. The recording bein recorded is stored in @recording instance variable. This can be reset by #reset!
method, which also accepts arguments to change the recorder settings and/or insert another recording.
Direct Known Subclasses
Constant Summary collapse
- SAMPLING_DECIMAL_PLACES =
5
Instance Attribute Summary collapse
-
#features ⇒ Object
readonly
Returns the value of attribute features.
Instance Method Summary collapse
-
#alert ⇒ Object
Hook to be called by simulators whenever there is a state change.
-
#initialize(features: net.State.marking( free_pp ), recording: nil, **nn) ⇒ Recorder
constructor
Initializes the recorder.
-
#new_recording ⇒ Object
Construct a new recording based on the parametrized class Recording().
- #recording ⇒ Object
-
#reset!(**nn) ⇒ Object
Assigns to @recording a new Dataset instance.
Constructor Details
#initialize(features: net.State.marking( free_pp ), recording: nil, **nn) ⇒ Recorder
Initializes the recorder. Takes 2 arguments: :features
expecting the feature set to record during simulation, and :recording
, expecting the initial state of the recording.
29 30 31 32 33 34 |
# File 'lib/y_petri/simulation/recorder.rb', line 29 def initialize features: net.State.marking( free_pp ), recording: nil, **nn @features = net.State.features( features ) if recording then reset! recording: recording else reset! end end |
Instance Attribute Details
#features ⇒ Object (readonly)
Returns the value of attribute features.
14 15 16 |
# File 'lib/y_petri/simulation/recorder.rb', line 14 def features @features end |
Instance Method Details
#alert ⇒ Object
Hook to be called by simulators whenever there is a state change. The decision to sample is then the business of the recorder.
55 56 57 |
# File 'lib/y_petri/simulation/recorder.rb', line 55 def alert sample! # vanilla recorder samples at every occasion end |
#new_recording ⇒ Object
Construct a new recording based on the parametrized class Recording().
38 39 40 |
# File 'lib/y_petri/simulation/recorder.rb', line 38 def new_recording features.new_dataset end |
#recording ⇒ Object
16 17 18 19 20 |
# File 'lib/y_petri/simulation/recorder.rb', line 16 def recording @recording.tap { |ds| ds.instance_variable_set :@settings, simulation.settings( true ) } end |
#reset!(**nn) ⇒ Object
Assigns to @recording a new Dataset instance. Without arguments, the new recording is empty. With :recording
named argument supplied, the new recording is filled with the prescribed contents.
46 47 48 49 50 |
# File 'lib/y_petri/simulation/recorder.rb', line 46 def reset! **nn @features = net.State.features( nn[:features] || @features ) @recording = new_recording @recording.update Hash[ nn[:recording] ] if nn[:recording] end |