Sha256: 84c5529df74cdde282fb64b9145e26e673f329c5db7fe0ae56fae224e66063a9

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

# encoding: utf-8

# Mixin for the transitions with assignment action.
# 
module YPetri::Transition::Type_A
  # Transition's action (before validation).
  # 
  def action
    action_closure.( *domain_marking )
  end

  # Applies action to the codomain, honoring cocking. Returns true if the transition
  # fired, false if it wasn't cocked.
  # 
  def fire
    cocked?.tap { |x| ( uncock; fire! ) if x }
  end

  # Assigns the action closure result to the codomain, regardless of cocking.
  # 
  def fire!
    act = Array( action )
    fail TypeError, "Wrong output arity of the action " +
      "closure of #{self}" if act.size != codomain.size
    codomain.each_with_index { |place, index|
      # assigning action node no. index to place
      place.marking = act.fetch( index )
    }
    return nil
  end

  # A transitions are always _enabled_.
  # 
  def enabled?
    true
  end

  # Transition's assignment action under current simulation.
  # 
  def a simulation=world.simulation
    simulation.net.State.Feature.Assignment( self ) % simulation
  end
end # class YPetri::Transition::Type_A

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
y_petri-2.4.3 lib/y_petri/transition/A.rb