Module: YPetri::Simulation::TransitionRepresentation::Type_A

Defined in:
lib/y_petri/simulation/transition_representation/A.rb

Overview

A mixin for A transition representations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#assignment_closureObject (readonly)

Returns the value of attribute assignment_closure.



6
7
8
# File 'lib/y_petri/simulation/transition_representation/A.rb', line 6

def assignment_closure
  @assignment_closure
end

#direct_assignment_closureObject (readonly)

Returns the value of attribute direct_assignment_closure.



6
7
8
# File 'lib/y_petri/simulation/transition_representation/A.rb', line 6

def direct_assignment_closure
  @direct_assignment_closure
end

Instance Method Details

#A?Boolean Also known as: assignment_action?, assignment?

Assignment action – true for A transitions.

Returns:

  • (Boolean)


10
11
12
# File 'lib/y_petri/simulation/transition_representation/A.rb', line 10

def A?
  true
end

#a?Boolean

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

Returns:

  • (Boolean)


18
19
20
# File 'lib/y_petri/simulation/transition_representation/A.rb', line 18

def a?
  false
end

#actObject

Returns the assignments to all places, as they would happen if A transition could change their values.



72
73
74
# File 'lib/y_petri/simulation/transition_representation/A.rb', line 72

def act
  codomain >> Array( function.( *domain.marking ) )
end

#actionObject

Returns the assignments, as they would happen if this A transition fired, as hash places >> action.



65
66
67
# File 'lib/y_petri/simulation/transition_representation/A.rb', line 65

def action
  act.select { |pl, v| pl.free? }
end

#build_closureObject

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.



105
106
107
108
109
# 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_closureObject

Builds an assignment closure, which, when called, directly affects the simulation’s marking vector (free places only).



79
80
81
82
83
84
85
86
87
88
89
90
91
# 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

#initObject

Initialization subroutine.



56
57
58
59
60
# 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?Boolean

Nil for assignment transitions. Though technically timeless, assignment transitions are considered outside the s/S types.

Returns:

  • (Boolean)


49
50
51
# File 'lib/y_petri/simulation/transition_representation/A.rb', line 49

def s?
  nil
end

#S?Boolean

Nil for assignment transitions. Though technically timeless, assignment transitions are considered outside the s/S types.

Returns:

  • (Boolean)


41
42
43
# File 'lib/y_petri/simulation/transition_representation/A.rb', line 41

def S?
  nil
end

#t?Boolean Also known as: timeless?

Nil for assignment transitions. Though technically timeless, assignment transitions are considered outside the t/T types.

Returns:

  • (Boolean)


33
34
35
# File 'lib/y_petri/simulation/transition_representation/A.rb', line 33

def t?
  nil
end

#T?Boolean Also known as: timed?

Nil for assignment transitions. Though technically timeless, assignment transitions are considered outside the t/T types.

Returns:

  • (Boolean)


25
26
27
# File 'lib/y_petri/simulation/transition_representation/A.rb', line 25

def T?
  nil
end

#to_assignment_closureObject

Builds an assignment closure, which is bound to the domain and upon calling, returns the assignment action given the current domain marking.



96
97
98
# File 'lib/y_petri/simulation/transition_representation/A.rb', line 96

def to_assignment_closure
  build_closure
end