Sha256: 0e16220245c8ce60cbb1496af8b324fb50be3827cc7ace4636287d58c695affd

Contents?: true

Size: 1.6 KB

Versions: 13

Compression:

Stored size: 1.6 KB

Contents

# encoding: utf-8

# A mixin for timeless simulations.
# 
class YPetri::Simulation
  module Timeless
    require_relative 'timeless/recorder'

    # False for timeless simulations.
    # 
    def timed?
      false
    end

    private

    # Initialization subroutine for timeless simulations. Sets up the
    # parametrized subclasses +@Core+ (the simulator) and +@Recorder+,
    # and initializes the +@recorder+ attribute.
    # 
    def init **settings
      method = settings[:method] # the simulation method
      features_to_record = settings[:record]
      init_core_and_recorder_subclasses
      @core = Core().new( method: method, guarded: guarded )
      @recorder = if features_to_record then 
                    # we'll have to figure out features
                    ff = case features_to_record
                         when Array then
                           net.State.Features
                             .infer_from_elements( features_to_record )
                         when Hash then
                           net.State.features( features_to_record )
                         end
                    Recorder().new( features: ff )
                  else
                    Recorder().new # init the recorder
                  end
    end

    # Sets up subclasses of +Core+ (the simulator) and +Recorder+ (the sampler)
    # for timeless simulations.
    # 
    def init_core_and_recorder_subclasses
      param_class( { Core: YPetri::Core::Timeless,
                     Recorder: Recorder },
                   with: { simulation: self } )
    end
  end # module Timeless
end # module YPetri::Simulation

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
y_petri-2.2.4 lib/y_petri/simulation/timeless.rb
y_petri-2.2.3 lib/y_petri/simulation/timeless.rb
y_petri-2.2.2 lib/y_petri/simulation/timeless.rb
y_petri-2.2.1 lib/y_petri/simulation/timeless.rb
y_petri-2.2.0 lib/y_petri/simulation/timeless.rb
y_petri-2.1.51 lib/y_petri/simulation/timeless.rb
y_petri-2.1.50 lib/y_petri/simulation/timeless.rb
y_petri-2.1.49 lib/y_petri/simulation/timeless.rb
y_petri-2.1.48 lib/y_petri/simulation/timeless.rb
y_petri-2.1.47 lib/y_petri/simulation/timeless.rb
y_petri-2.1.46 lib/y_petri/simulation/timeless.rb
y_petri-2.1.45 lib/y_petri/simulation/timeless.rb
y_petri-2.1.44 lib/y_petri/simulation/timeless.rb