Sha256: 1c9ae1b106575c7cf5bbdf9a178c845b556aae425bb164b039fdb9d34a227e31

Contents?: true

Size: 1.52 KB

Versions: 38

Compression:

Stored size: 1.52 KB

Contents

# -*- coding: utf-8 -*-

# Mixin for timed Petri net transitions.
# 
module YPetri::Transition::Type_T
  # Transition's action (before validation). Requires Δt as an argument.
  # 
  def action Δt
    if stoichiometric? then
      rate = rate_closure.( *domain_marking )
      stoichiometry.map { |coeff| rate * coeff * Δt }
    else
      Array( rate_closure.( *domain_marking ) ).map { |e| e * Δt }
    end
  end

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

  # Fires the transition regardless of cocking. For timed transitions, takes
  # Δt as an argument.
  # 
  def fire! Δt
    consciously "call #fire method" do
      act = note "action", is: Array( action Δt )
      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

  # YPetri transitions are _enabled_ if and only if the intended action would
  # lead to a legal codomain marking. For timed transitions, +#enabled?+ method
  # takes Δt as an argument.
  # 
  def enabled? Δt
    codomain.zip( action Δt ).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.1.33 lib/y_petri/transition/T.rb
y_petri-2.1.31 lib/y_petri/transition/T.rb
y_petri-2.1.30 lib/y_petri/transition/T.rb
y_petri-2.1.26 lib/y_petri/transition/T.rb
y_petri-2.1.25 lib/y_petri/transition/T.rb
y_petri-2.1.24 lib/y_petri/transition/T.rb
y_petri-2.1.22 lib/y_petri/transition/T.rb
y_petri-2.1.21 lib/y_petri/transition/T.rb
y_petri-2.1.20 lib/y_petri/transition/T.rb
y_petri-2.1.18 lib/y_petri/transition/T.rb
y_petri-2.1.17 lib/y_petri/transition/T.rb
y_petri-2.1.16 lib/y_petri/transition/T.rb
y_petri-2.1.12 lib/y_petri/transition/T.rb
y_petri-2.1.11 lib/y_petri/transition/T.rb
y_petri-2.1.10 lib/y_petri/transition/T.rb
y_petri-2.1.9 lib/y_petri/transition/T.rb
y_petri-2.1.7 lib/y_petri/transition/T.rb
y_petri-2.1.6 lib/y_petri/transition/T.rb