Class: YPetri::Simulation::Timed::Recorder

Inherits:
Recorder
  • Object
show all
Defined in:
lib/y_petri/simulation/timed/recorder.rb

Overview

Timed aspect of the recorder.

Constant Summary collapse

TIME_DECIMAL_PLACES =
5

Constants inherited from Recorder

Recorder::SAMPLING_DECIMAL_PLACES

Instance Attribute Summary collapse

Attributes inherited from Recorder

#features

Instance Method Summary collapse

Methods inherited from Recorder

#recording

Constructor Details

#initialize(sampling: default_sampling, next_time: time, **named_args) ⇒ Recorder

Apart from the vanilla version arguments, timed recorder takes :sampling argument.



17
18
19
20
# 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

Instance Attribute Details

#next_timeObject (readonly)

Returns the value of attribute next_time.



7
8
9
# File 'lib/y_petri/simulation/timed/recorder.rb', line 7

def next_time
  @next_time
end

#samplingObject

Returns the value of attribute sampling.



8
9
10
# File 'lib/y_petri/simulation/timed/recorder.rb', line 8

def sampling
  @sampling
end

Instance Method Details

#alert!Object

To be called by simulators whenever the state changes (every time that simulation time is incremented).



39
40
41
42
43
44
45
46
# 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) ⇒ Object

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.



52
53
54
55
56
# 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_recordingObject

Construct a new recording based on features.



24
25
26
# 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) ⇒ Object

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.



32
33
34
# 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