Module: YPetri::Transition::Type_T
- Defined in:
- lib/y_petri/transition/T.rb
Overview
Mixin for timed Petri net transitions.
Instance Method Summary collapse
-
#action(Δt) ⇒ Object
Transition’s action (before validation).
-
#enabled?(Δt) ⇒ Boolean
YPetri transitions are enabled if and only if the intended action would lead to a legal codomain marking.
-
#f(simulation = world.simulation) ⇒ Object
Transition’s flux under current simulation.
-
#fir(simulation = world.simulation, **nn) ⇒ Object
Transition’s firing under current simulation.
-
#fire(Δt) ⇒ Object
Fires the transition, honoring cocking.
-
#fire!(Δt) ⇒ Object
Fires the transition regardless of cocking.
-
#pa(simulation = world.simulation, **nn) ⇒ Object
Prints the transition’s action under current simulation.
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.
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 |
#f(simulation = world.simulation) ⇒ Object
Transition’s flux under current simulation.
61 62 63 |
# File 'lib/y_petri/transition/T.rb', line 61 def f simulation=world.simulation simulation.net.State.Feature.Flux( self ) % simulation end |
#fir(simulation = world.simulation, **nn) ⇒ Object
Transition’s firing under current simulation.
53 54 55 56 57 |
# File 'lib/y_petri/transition/T.rb', line 53 def fir simulation=world.simulation, **nn nn.must_have :delta_time, syn!: :Δt Δt = nn.delete( :delta_time ) || simulation.step simulation.net.State.Feature.Firing( self ) % [ simulation, Δt: Δt ] 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 node no. #{i} to #{p}" p.add note( "marking change", is: act.fetch( i ) ) end end return nil end |
#pa(simulation = world.simulation, **nn) ⇒ Object
Prints the transition’s action under current simulation.
67 68 69 70 71 72 |
# File 'lib/y_petri/transition/T.rb', line 67 def pa simulation=world.simulation, **nn nn.must_have :delta_time, syn!: :Δt Δt = nn.delete( :delta_time ) || simulation.step ff = simulation.net.State.Features.Delta( codomain, transitions: self ) ( ff >> ff % simulation ).pretty_print_numeric_values( **nn ) end |