Sha256: 974d50337d0a9c07cf3b48d4f89a44d77b08495372cccd438dd8e4a9e7d66db2

Contents?: true

Size: 1.16 KB

Versions: 12

Compression:

Stored size: 1.16 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!
    consciously "to #fire!" do
      act = note "action", is: Array( action )
      msg = "Wrong output arity of the action closure of #{self}"
      fail TypeError, msg if act.size != codomain.size
      codomain.each_with_index { |p, i|
        note "assigning action node no. #{i} to #{p}"
        p.marking = note "marking to assign", is: act.fetch( i )
      }
    end
    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

12 entries across 12 versions & 1 rubygems

Version Path
y_petri-2.4.2 lib/y_petri/transition/A.rb
y_petri-2.4.0 lib/y_petri/transition/A.rb
y_petri-2.3.12 lib/y_petri/transition/A.rb
y_petri-2.3.11 lib/y_petri/transition/A.rb
y_petri-2.3.10 lib/y_petri/transition/A.rb
y_petri-2.3.9 lib/y_petri/transition/A.rb
y_petri-2.3.8 lib/y_petri/transition/A.rb
y_petri-2.3.6 lib/y_petri/transition/A.rb
y_petri-2.3.5 lib/y_petri/transition/A.rb
y_petri-2.3.4 lib/y_petri/transition/A.rb
y_petri-2.3.3 lib/y_petri/transition/A.rb
y_petri-2.3.2 lib/y_petri/transition/A.rb