Class: YPetri::Simulation::Recorder

Inherits:
Object
  • Object
show all
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

Timed::Recorder, Timeless::Recorder

Constant Summary collapse

SAMPLING_DECIMAL_PLACES =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#featuresObject (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

#alertObject

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_recordingObject

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

#recordingObject



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