Sha256: 8ac85e71978805ea255d60b3a6c2466089a996a7d9966e27b1f7c309f624f765

Contents?: true

Size: 1.41 KB

Versions: 7

Compression:

Stored size: 1.41 KB

Contents

# encoding: utf-8

# Place collection for YPetri::Simulation.
#
class YPetri::Simulation::Places < YPetri::Simulation::Nodes
  require_relative 'places/types'

  ★ 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 ? PlacePS().new( p, name: p.name ) : PlacePS().new( p )
  end

  # Marking of the place collection in the current simulation.
  # 
  def marking
    simulation.M self
  end

  private

  # 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 )
    offenders = reject { |place| ( free + clamped ).include? place }
    fail TypeError, "All places must have default marking or clamp!" unless
      use_default_marking unless offenders.empty?
    offenders.each { |place|
      dm = place.source.default_marking
      fail TypeError, "#{place.source} has no default marking!" if dm.nil?
      simulation.send( :set_initial_marking, place, to: dm )
    }
  end
end # class YPetri::Simulation::Places

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
y_petri-2.4.9 lib/y_petri/simulation/places.rb
y_petri-2.4.8 lib/y_petri/simulation/places.rb
y_petri-2.4.6 lib/y_petri/simulation/places.rb
y_petri-2.4.4 lib/y_petri/simulation/places.rb
y_petri-2.4.3 lib/y_petri/simulation/places.rb
y_petri-2.4.2 lib/y_petri/simulation/places.rb
y_petri-2.4.0 lib/y_petri/simulation/places.rb