Module: YPetri::Transition::Type_t
- Defined in:
- lib/y_petri/transition/t.rb
Overview
Mixin for timed non-assignment timeless Petri net transitions.
Instance Method Summary collapse
-
#action ⇒ Object
Result of the transition’s “function”, regardless of the #enabled? status.
-
#enabled? ⇒ Boolean
Timeless transition is enabled if its action would result in a legal codomain marking.
-
#fire ⇒ Object
Fires the transition, honoring cocking.
-
#fire! ⇒ Object
Fires the transition regardless of cocking.
Instance Method Details
#action ⇒ Object
Result of the transition’s “function”, regardless of the #enabled? status.
8 9 10 11 12 13 14 15 |
# File 'lib/y_petri/transition/t.rb', line 8 def action if stoichiometric? then rslt = action_closure.( *domain_marking ) stoichiometry.map { |coeff| rslt * coeff } else action_closure.( *domain_marking ) end end |
#enabled? ⇒ Boolean
Timeless transition is enabled if its action would result in a legal codomain marking.
42 43 44 45 46 47 |
# File 'lib/y_petri/transition/t.rb', line 42 def enabled? codomain.zip( action ).all? do |place, change| begin; place.guard.( place.marking + change ) rescue YPetri::GuardError; false end end end |
#fire ⇒ 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 cocked?.tap { |x| ( uncock; fire! ) if x } end |
#fire! ⇒ Object
Fires the transition regardless of cocking.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/y_petri/transition/t.rb', line 26 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 |