Module: YPetri::Transition::Type_t

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

Overview

Mixin for timeless non-assignment Petri net transitions.

Instance Method Summary collapse

Instance Method Details

#actionObject

Result of the transition’s “function”, regardless of the #enabled? status.



14
15
16
17
18
19
20
21
# File 'lib/y_petri/transition/t.rb', line 14

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.

Returns:

  • (Boolean)


46
47
48
49
50
51
# File 'lib/y_petri/transition/t.rb', line 46

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

#fir(simulation = world.simulation) ⇒ Object

Transition’s firing under current simulation.



55
56
57
# File 'lib/y_petri/transition/t.rb', line 55

def fir simulation=world.simulation
  simulation.net.State.Feature.Firing( self ) % simulation
end

#fireObject

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



26
27
28
# File 'lib/y_petri/transition/t.rb', line 26

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

#fire!Object

Fires the transition regardless of cocking.



32
33
34
35
36
37
38
39
40
41
# File 'lib/y_petri/transition/t.rb', line 32

def fire!
  act = Array( action )
  fail TypeError, "Wrong output arity of the action " +
    "closure of #{self}!" if act.size != codomain.size
  codomain.each_with_index do |place, index|
    # adding action node no. index to place
    place.add act.fetch( index )
  end
  return nil
end

#functionObject

For timeless transitions, “function” refers to their action closure.



8
9
10
# File 'lib/y_petri/transition/t.rb', line 8

def function
  action_closure
end

#pa(simulation = world.simulation, **nn) ⇒ Object

Prints the transition’s action under current simulation.



61
62
63
64
# File 'lib/y_petri/transition/t.rb', line 61

def pa simulation=world.simulation, **nn
  ff = simulation.net.State.Features.Delta( codomain, transitions: self )
  ( ff >> ff % simulation ).pretty_print_numeric_values **nn
end