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 being 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.Features.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.



33
34
35
36
37
38
# File 'lib/y_petri/simulation/recorder.rb', line 33

def initialize features: net.State.Features.Marking( free_pp ),
               recording: nil,
               **nn
  @features = net.State.Features( features )
  recording ? reset!( recording: recording ) : reset!
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

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



60
61
62
# File 'lib/y_petri/simulation/recorder.rb', line 60

def alert!
  sample! # vanilla recorder samples at every occasion
end

#new_recordingObject

Construct a new recording based on the Recording() class.



42
43
44
# File 'lib/y_petri/simulation/recorder.rb', line 42

def new_recording
  @features.DataSet.new
end

#recordingObject



16
17
18
19
20
# File 'lib/y_petri/simulation/recorder.rb', line 16

def recording
  @recording.tap { |dataset|
    dataset.instance_variable_set :@settings, simulation.settings( true )
  }
end

#reset!(features: nil, recording: nil, **named_args) ⇒ Object

Assigns to @recording a new DataSet instance. If no arguments are supplied to this method, the new recording will stay empty. A recording can be optionally supplied via :recording named argument.



50
51
52
53
54
55
# File 'lib/y_petri/simulation/recorder.rb', line 50

def reset! features: nil, recording: nil, **named_args
  @features = net.State.Features( features ) if features
  @recording = new_recording
  @recording.update Hash[ recording ] if recording
  return self
end