Sha256: 9a2a215eab7b9f986ff195246018a8746aad20d90db1c3db855fa5667a28ff53

Contents?: true

Size: 1.33 KB

Versions: 38

Compression:

Stored size: 1.33 KB

Contents

# encoding: utf-8

# Mixin for timed non-assignment timeless Petri net transitions.
# 
module YPetri::Transition::Type_t
  # Result of the transition's "function", regardless of the #enabled? status.
  # 
  def action
    if stoichiometric? then
      rslt = action_closure.( *domain_marking )
      stoichiometry.map { |coeff| rslt * coeff }
    else
      action_closure.( *domain_marking )
    end
  end # action

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

  # Fires the transition regardless of cocking.
  # 
  def fire!
    consciously "call #fire method" do
      act = Array( action )
      msg = "Wrong output arity of the action closure of #{self}!"
      fail TypeError, msg if act.size != codomain.size
      codomain.each_with_index do |p, i|
        note "adding action element no. #{i} to #{p}"
        p.add note( "marking change", is: act.fetch( i ) )
      end
    end
    return nil
  end

  # Timeless transition is _enabled_ if its action would result in a legal
  # codomain marking.
  # 
  def enabled?
    codomain.zip( action ).all? do |place, change|
      begin; place.guard.( place.marking + change )
      rescue YPetri::GuardError; false end
    end
  end
end # class YPetri::Transition::Type_t

Version data entries

38 entries across 38 versions & 1 rubygems

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