Class: YPetri::Simulation::TransitionRepresentation
- Inherits:
-
ElementRepresentation
- Object
- ElementRepresentation
- YPetri::Simulation::TransitionRepresentation
- Includes:
- Types
- Defined in:
- lib/y_petri/simulation/transition_representation/S.rb,
lib/y_petri/simulation/transition_representation.rb,
lib/y_petri/simulation/transition_representation/T.rb,
lib/y_petri/simulation/transition_representation/s.rb,
lib/y_petri/simulation/transition_representation/t.rb,
lib/y_petri/simulation/transition_representation/TS.rb,
lib/y_petri/simulation/transition_representation/Ts.rb,
lib/y_petri/simulation/transition_representation/tS.rb,
lib/y_petri/simulation/transition_representation/ts.rb,
lib/y_petri/simulation/transition_representation/types.rb
Overview
A mixin with transition types.
Defined Under Namespace
Modules: Type_A, Type_S, Type_T, Type_TS, Type_Ts, Type_a, Type_s, Type_t, Type_tS, Type_ts, Types
Instance Attribute Summary collapse
-
#codomain ⇒ Object
readonly
Returns the value of attribute codomain.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#function ⇒ Object
readonly
source transition function.
Attributes included from Types
Attributes inherited from ElementRepresentation
Instance Method Summary collapse
-
#build_closure ⇒ Object
Builds the transition’s function into a closure.
-
#codomain_assignment_code(vector: (fail ArgumentError, "No vector!"), source: (fail ArgumentError, "No source array!")) ⇒ Object
Builds a code string that assigns to the free places of the codomain.
-
#codomain_indices ⇒ Object
Returns the indices of this transition’s codomain in the marking vector.
-
#domain_access_code(vector: :m_vector) ⇒ Object
Builds a code string for accessing the domain directly from a marking vector, given as argument.
-
#domain_indices ⇒ Object
Returns the indices of this transition’s domain in the marking vector.
-
#free_codomain_indices ⇒ Object
Returns the indices of this transition’s codomain among the free places.
-
#free_domain_indices ⇒ Object
Returns the indices of this transition’s domain among the free places.
-
#increment_by_codomain_code(vector: (fail ArgumentError, "No vector!"), source: (fail ArgumentError, "No source array!")) ⇒ Object
Builds a closure that increments a vector with this transition’s codomain.
-
#initialize(net_transition) ⇒ TransitionRepresentation
constructor
Expect a single YPetri place as an argument.
Methods included from Types
#TS?, #Ts?, #tS?, #ts?, #type_init
Constructor Details
#initialize(net_transition) ⇒ TransitionRepresentation
Expect a single YPetri place as an argument.
15 16 17 18 19 |
# File 'lib/y_petri/simulation/transition_representation.rb', line 15 def initialize net_transition super @domain, @codomain = places( source.domain ), places( source.codomain ) type_init end |
Instance Attribute Details
#codomain ⇒ Object (readonly)
Returns the value of attribute codomain.
10 11 12 |
# File 'lib/y_petri/simulation/transition_representation.rb', line 10 def codomain @codomain end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
10 11 12 |
# File 'lib/y_petri/simulation/transition_representation.rb', line 10 def domain @domain end |
#function ⇒ Object (readonly)
source transition function
11 12 13 |
# File 'lib/y_petri/simulation/transition_representation.rb', line 11 def function @function end |
Instance Method Details
#build_closure ⇒ Object
Builds the transition’s function into a closure.
47 48 49 50 51 |
# File 'lib/y_petri/simulation/transition_representation.rb', line 47 def build_closure mv, f = simulation.m_vector, function λ = "-> { f.( %s ) }" % domain_access_code( vector: :mv ) eval λ end |
#codomain_assignment_code(vector: (fail ArgumentError, "No vector!"), source: (fail ArgumentError, "No source array!")) ⇒ Object
Builds a code string that assigns to the free places of the codomain.
63 64 65 66 67 68 |
# File 'lib/y_petri/simulation/transition_representation.rb', line 63 def codomain_assignment_code vector: (fail ArgumentError, "No vector!"), source: (fail ArgumentError, "No source array!") Matrix.column_vector_assignment_code( vector: vector, indices: free_codomain_indices, source: source ) end |
#codomain_indices ⇒ Object
Returns the indices of this transition’s codomain in the marking vector.
29 30 31 |
# File 'lib/y_petri/simulation/transition_representation.rb', line 29 def codomain_indices codomain.map { |p| places.index p } end |
#domain_access_code(vector: :m_vector) ⇒ Object
Builds a code string for accessing the domain directly from a marking vector, given as argument.
56 57 58 59 |
# File 'lib/y_petri/simulation/transition_representation.rb', line 56 def domain_access_code( vector: :m_vector ) Matrix.column_vector_access_code( vector: vector, indices: domain_indices ) end |
#domain_indices ⇒ Object
Returns the indices of this transition’s domain in the marking vector.
23 24 25 |
# File 'lib/y_petri/simulation/transition_representation.rb', line 23 def domain_indices domain.map { |p| places.index p } end |
#free_codomain_indices ⇒ Object
Returns the indices of this transition’s codomain among the free places.
41 42 43 |
# File 'lib/y_petri/simulation/transition_representation.rb', line 41 def free_codomain_indices codomain.map { |p| free_places.index p } end |
#free_domain_indices ⇒ Object
Returns the indices of this transition’s domain among the free places.
35 36 37 |
# File 'lib/y_petri/simulation/transition_representation.rb', line 35 def free_domain_indices domain.map { |p| free_places.index p } end |
#increment_by_codomain_code(vector: (fail ArgumentError, "No vector!"), source: (fail ArgumentError, "No source array!")) ⇒ Object
Builds a closure that increments a vector with this transition’s codomain.
72 73 74 75 76 77 |
# File 'lib/y_petri/simulation/transition_representation.rb', line 72 def increment_by_codomain_code vector: (fail ArgumentError, "No vector!"), source: (fail ArgumentError, "No source array!") Matrix.column_vector_increment_by_array_code vector: vector, indices: free_codomain_indices, source: source end |