Sha256: 82d8a30e935b4a61916c8ff2e0b6c71b511883b02b95a5443c9be0e61146ab42

Contents?: true

Size: 1.35 KB

Versions: 38

Compression:

Stored size: 1.35 KB

Contents

#encoding: utf-8

require_relative 'places/types'
require_relative 'places/free'
require_relative 'places/clamped'

# Place collection for YPetri::Simulation.
#
class YPetri::Simulation::Places
  ★ Types

  # Pushes a place to the collection.
  # 
  def push place
    p = begin
          net.place( place )
        rescue NameError, TypeError
          return super place( place )
        end
    super p.name ? Place().new( p, name: p.name ) : Place().new( p )
  end

  # Ensures that all the places that are not clamped have their initial marking
  # set. Optional argument :use_default_marking is set to _true_ by default, in
  # which case own default marking of the source places is used if it was not
  # specified when constructing the simulation. If set to _false_, then presence
  # of places with missing initial marking simply raises errors.
  # 
  def complete_initial_marking( use_default_marking: true )
    missing = reject { |pl| ( free + clamped ).include? pl }
    unless use_default_marking
      fail TypeError, "All places must have default marking or clamp!" unless
        missing.empty?
    end
    missing.each { |pl|
      dflt = pl.source.default_marking
      fail TypeError, "Source's default marking is missing (nil)!" if dflt.nil?
      simulation.send :set_initial_marking, { of: pl, to: dflt }
    }
  end
end # class YPetri::Simulation::Places

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
y_petri-2.2.4 lib/y_petri/simulation/places.rb
y_petri-2.2.3 lib/y_petri/simulation/places.rb
y_petri-2.2.2 lib/y_petri/simulation/places.rb
y_petri-2.2.1 lib/y_petri/simulation/places.rb
y_petri-2.2.0 lib/y_petri/simulation/places.rb
y_petri-2.1.51 lib/y_petri/simulation/places.rb
y_petri-2.1.50 lib/y_petri/simulation/places.rb
y_petri-2.1.49 lib/y_petri/simulation/places.rb
y_petri-2.1.48 lib/y_petri/simulation/places.rb
y_petri-2.1.47 lib/y_petri/simulation/places.rb
y_petri-2.1.46 lib/y_petri/simulation/places.rb
y_petri-2.1.45 lib/y_petri/simulation/places.rb
y_petri-2.1.44 lib/y_petri/simulation/places.rb
y_petri-2.1.42 lib/y_petri/simulation/places.rb
y_petri-2.1.40 lib/y_petri/simulation/places.rb
y_petri-2.1.39 lib/y_petri/simulation/places.rb
y_petri-2.1.37 lib/y_petri/simulation/places.rb
y_petri-2.1.36 lib/y_petri/simulation/places.rb
y_petri-2.1.35 lib/y_petri/simulation/places.rb
y_petri-2.1.34 lib/y_petri/simulation/places.rb