lib/y_petri/transition/timed.rb in y_petri-2.0.15 vs lib/y_petri/transition/timed.rb in y_petri-2.1.3
- old
+ new
@@ -4,24 +4,15 @@
#
module YPetri::Transition::Timed
# Transition's action (before validation). Requires Δt as an argument.
#
def action Δt
- if has_rate? then
- if stoichiometric? then
- rate = rate_closure.( *domain_marking )
- stoichiometry.map { |coeff| rate * coeff * Δt }
- else # assuming that rate closure return value has correct arity
- rate_closure.( *domain_marking ).map { |e| component * Δt }
- end
- else # timed rateless
- if stoichiometric? then
- rslt = action_closure.( Δt, *domain_marking )
- stoichiometry.map { |coeff| rslt * coeff }
- else
- action_closure.( Δt, *domain_marking ) # caveat result arity!
- end
+ 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.
@@ -32,14 +23,16 @@
# Fires the transition regardless of cocking. For timed transitions, takes
# Δt as an argument.
#
def fire! Δt
- try "to call #fire method" do
+ consciously "call #fire method" do
act = note "action", is: Array( action Δt )
- codomain.each_with_index do |codomain_place, i|
- note "adding action element no. #{i} to place #{codomain_place}"
- codomain_place.add( note "marking change", is: act.fetch( i ) )
+ 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