module YPetri::Simulation::TransitionRepresentation::Type_A
A mixin for A transition representations.
Attributes
Public Instance Methods
Assignment action – true for A transitions.
# File lib/y_petri/simulation/transition_representation/A.rb, line 10 def A? true end
Nil for assignment transitions. Though technically timeless, assignment transitions are considered outside the s/S types.
# File lib/y_petri/simulation/transition_representation/A.rb, line 41 def S? nil end
Nil for assignment transitions. Though technically timeless, assignment transitions are considered outside the t/T types.
# File lib/y_petri/simulation/transition_representation/A.rb, line 25 def T? nil end
Normal (non-assignment) action – false for A transitions
# File lib/y_petri/simulation/transition_representation/A.rb, line 18 def a? false end
Returns the assignments to all places, as they would happen if A transition could change their values.
# File lib/y_petri/simulation/transition_representation/A.rb, line 72 def act codomain >> Array( function.( *domain.marking ) ) end
Returns the assignments, as they would happen if this A transition fired, as hash places >> action.
# File lib/y_petri/simulation/transition_representation/A.rb, line 65 def action act.select { |pl, v| pl.free? } end
Builds the A transition's function (asssignment action closure) into a closure already bound to the domain. Functions for A transitions have return value arity equal to the codomain size. The returned closure here ensures that the return value is always of Array type.
# File lib/y_petri/simulation/transition_representation/A.rb, line 105 def build_closure mv, f = simulation.m_vector, function λ = "-> { Array f.( %s ) }" % domain_access_code( vector: :mv ) eval λ end
Builds an assignment closure, which, when called, directly affects the simulation's marking vector (free places only).
# File lib/y_petri/simulation/transition_representation/A.rb, line 79 def construct_direct_assignment_closure mv, ac = simulation.m_vector, source.action_closure λ = if codomain.size == 1 then target = codomain.first return proc {} if target.clamped? i = target.m_vector_index "-> do mv.send :[]=, #{i}, 0, *ac.( %s ) end" else assignment_code = codomain_assignment_code vector: :mv, source: :act "-> do act = ac.( %s )\n#{assignment_code} end" end eval λ % domain_access_code( vector: :mv ) end
Initialization subroutine.
# File lib/y_petri/simulation/transition_representation/A.rb, line 56 def init @function = source.action_closure @direct_assignment_closure = construct_direct_assignment_closure @assignment_closure = to_assignment_closure end
Nil for assignment transitions. Though technically timeless, assignment transitions are considered outside the s/S types.
# File lib/y_petri/simulation/transition_representation/A.rb, line 49 def s? nil end
Nil for assignment transitions. Though technically timeless, assignment transitions are considered outside the t/T types.
# File lib/y_petri/simulation/transition_representation/A.rb, line 33 def t? nil end
Builds an assignment closure, which is bound to the domain and upon calling, returns the assignment action given the current domain marking.
# File lib/y_petri/simulation/transition_representation/A.rb, line 96 def to_assignment_closure build_closure end