Module: YPetri::Transition::Type_T

Defined in:
lib/y_petri/transition/T.rb

Overview

Mixin for timed Petri net transitions.

Instance Method Summary collapse

Instance Method Details

#action(Δt) ⇒ Object

Transition’s action (before validation). Requires Δt as an argument.



8
9
10
11
12
13
14
15
# File 'lib/y_petri/transition/T.rb', line 8

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

#enabled?(Δt) ⇒ Boolean

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.

Returns:

  • (Boolean)


44
45
46
47
48
49
# File 'lib/y_petri/transition/T.rb', line 44

def enabled? Δt
  codomain.zip( action Δt ).all? do |place, change|
    begin; place.guard.( place.marking + change )
    rescue YPetri::GuardError; false end
  end
end

#fire(Δt) ⇒ Object

Fires the transition, honoring cocking. Returns true if the transition fired, false if it wasn’t cocked.



20
21
22
# File 'lib/y_petri/transition/T.rb', line 20

def fire Δt
  cocked?.tap { |x| ( uncock; fire! Δt ) if x }
end

#fire!(Δt) ⇒ Object

Fires the transition regardless of cocking. For timed transitions, takes Δt as an argument.



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/y_petri/transition/T.rb', line 27

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