module YPetri::Simulation::TransitionRepresentation::Type_A

A mixin for A transition representations.

Attributes

assignment_closure[R]
direct_assignment_closure[R]

Public Instance Methods

A?() click to toggle source

Assignment action – true for A transitions.

# File lib/y_petri/simulation/transition_representation/A.rb, line 10
def A?
  true
end
Also aliased as: assignment_action?, assignment?
S?() click to toggle source

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
T?() click to toggle source

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
Also aliased as: timed?, timed?
a?() click to toggle source

Normal (non-assignment) action – false for A transitions

# File lib/y_petri/simulation/transition_representation/A.rb, line 18
def a?
  false
end
act() click to toggle source

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
action() click to toggle source

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
assignment?()
Alias for: A?
assignment_action?()
Alias for: A?
build_closure() click to toggle source

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
construct_direct_assignment_closure() click to toggle source

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
init() click to toggle source

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
s?() click to toggle source

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
t?() click to toggle source

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
Also aliased as: timeless?, timeless?
timed?()
Alias for: T?
timeless?()
Alias for: t?
to_assignment_closure() click to toggle source

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