y_petri 2.0.15 → 2.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/y_petri/{manipulator → agent}/hash_key_pointer.rb +2 -2
- data/lib/y_petri/agent/petri_net_related.rb +115 -0
- data/lib/y_petri/{manipulator → agent}/selection.rb +2 -1
- data/lib/y_petri/{manipulator/simulation_related_methods.rb → agent/simulation_related.rb} +93 -110
- data/lib/y_petri/agent.rb +22 -0
- data/lib/y_petri/core/timed/euler.rb +20 -0
- data/lib/y_petri/core/timed/pseudo_euler.rb +31 -0
- data/lib/y_petri/core/timed/quasi_euler.rb +23 -0
- data/lib/y_petri/core/timed.rb +70 -0
- data/lib/y_petri/core/timeless/pseudo_euler.rb +20 -0
- data/lib/y_petri/core/timeless.rb +12 -0
- data/lib/y_petri/core.rb +100 -0
- data/lib/y_petri/dsl.rb +66 -0
- data/lib/y_petri/fixed_assets.rb +7 -0
- data/lib/y_petri/net/element_access.rb +239 -0
- data/lib/y_petri/net/state/feature/delta.rb +88 -0
- data/lib/y_petri/net/state/feature/firing.rb +57 -0
- data/lib/y_petri/net/state/feature/flux.rb +58 -0
- data/lib/y_petri/net/state/feature/gradient.rb +75 -0
- data/lib/y_petri/net/state/feature/marking.rb +62 -0
- data/lib/y_petri/net/state/feature.rb +79 -0
- data/lib/y_petri/net/state/features/dataset.rb +135 -0
- data/lib/y_petri/net/state/features/record.rb +50 -0
- data/lib/y_petri/net/state/features.rb +126 -0
- data/lib/y_petri/net/state.rb +121 -0
- data/lib/y_petri/net/timed.rb +8 -0
- data/lib/y_petri/net/visualization.rb +3 -3
- data/lib/y_petri/net.rb +73 -77
- data/lib/y_petri/place.rb +8 -3
- data/lib/y_petri/simulation/dependency.rb +107 -0
- data/lib/y_petri/simulation/element_representation.rb +20 -0
- data/lib/y_petri/simulation/elements/access.rb +57 -0
- data/lib/y_petri/simulation/elements.rb +45 -0
- data/lib/y_petri/simulation/feature_set.rb +21 -0
- data/lib/y_petri/simulation/initial_marking/access.rb +55 -0
- data/lib/y_petri/simulation/initial_marking.rb +15 -0
- data/lib/y_petri/simulation/marking_clamps/access.rb +34 -0
- data/lib/y_petri/simulation/marking_clamps.rb +18 -0
- data/lib/y_petri/simulation/marking_vector/access.rb +106 -0
- data/lib/y_petri/simulation/marking_vector.rb +156 -0
- data/lib/y_petri/simulation/matrix.rb +64 -0
- data/lib/y_petri/simulation/place_mapping.rb +62 -0
- data/lib/y_petri/simulation/place_representation.rb +74 -0
- data/lib/y_petri/simulation/places/access.rb +121 -0
- data/lib/y_petri/simulation/places/clamped.rb +8 -0
- data/lib/y_petri/simulation/places/free.rb +8 -0
- data/lib/y_petri/simulation/places/types.rb +25 -0
- data/lib/y_petri/simulation/places.rb +41 -0
- data/lib/y_petri/simulation/recorder.rb +54 -0
- data/lib/y_petri/simulation/timed/recorder.rb +53 -0
- data/lib/y_petri/simulation/timed.rb +161 -261
- data/lib/y_petri/simulation/timeless/recorder.rb +25 -0
- data/lib/y_petri/simulation/timeless.rb +35 -0
- data/lib/y_petri/simulation/transition_representation/A.rb +58 -0
- data/lib/y_petri/simulation/transition_representation/S.rb +45 -0
- data/lib/y_petri/simulation/transition_representation/T.rb +80 -0
- data/lib/y_petri/simulation/transition_representation/TS.rb +46 -0
- data/lib/y_petri/simulation/transition_representation/Ts.rb +32 -0
- data/lib/y_petri/simulation/transition_representation/a.rb +30 -0
- data/lib/y_petri/simulation/transition_representation/s.rb +29 -0
- data/lib/y_petri/simulation/transition_representation/t.rb +37 -0
- data/lib/y_petri/simulation/transition_representation/tS.rb +38 -0
- data/lib/y_petri/simulation/transition_representation/ts.rb +32 -0
- data/lib/y_petri/simulation/transition_representation/types.rb +62 -0
- data/lib/y_petri/simulation/transition_representation.rb +79 -0
- data/lib/y_petri/simulation/transitions/A.rb +40 -0
- data/lib/y_petri/simulation/transitions/S.rb +24 -0
- data/lib/y_petri/simulation/transitions/T.rb +34 -0
- data/lib/y_petri/simulation/transitions/TS.rb +57 -0
- data/lib/y_petri/simulation/transitions/Ts.rb +60 -0
- data/lib/y_petri/simulation/transitions/a.rb +8 -0
- data/lib/y_petri/simulation/transitions/access.rb +186 -0
- data/lib/y_petri/simulation/transitions/s.rb +9 -0
- data/lib/y_petri/simulation/transitions/t.rb +22 -0
- data/lib/y_petri/simulation/transitions/tS.rb +55 -0
- data/lib/y_petri/simulation/transitions/ts.rb +58 -0
- data/lib/y_petri/simulation/transitions/types.rb +98 -0
- data/lib/y_petri/simulation/transitions.rb +21 -0
- data/lib/y_petri/simulation.rb +176 -781
- data/lib/y_petri/transition/assignment.rb +7 -5
- data/lib/y_petri/transition/construction.rb +119 -187
- data/lib/y_petri/transition/init.rb +311 -0
- data/lib/y_petri/transition/ordinary_timeless.rb +8 -6
- data/lib/y_petri/transition/timed.rb +11 -18
- data/lib/y_petri/transition.rb +104 -132
- data/lib/y_petri/version.rb +1 -1
- data/lib/y_petri/world/dependency.rb +40 -0
- data/lib/y_petri/world/petri_net_related.rb +61 -0
- data/lib/y_petri/{workspace/simulation_related_methods.rb → world/simulation_related.rb} +42 -49
- data/lib/y_petri/world.rb +27 -0
- data/lib/y_petri.rb +47 -99
- data/test/{manipulator_test.rb → agent_test.rb} +19 -17
- data/{lib/y_petri → test/examples}/demonstrator.rb +0 -0
- data/{lib/y_petri → test/examples}/demonstrator_2.rb +1 -0
- data/{lib/y_petri → test/examples}/demonstrator_3.rb +0 -0
- data/{lib/y_petri → test/examples}/demonstrator_4.rb +0 -0
- data/test/examples/example_2.rb +16 -0
- data/test/{manual_examples.rb → examples/manual_examples.rb} +0 -0
- data/test/net_test.rb +126 -121
- data/test/place_test.rb +1 -1
- data/test/sim_test +565 -0
- data/test/simulation_test.rb +338 -264
- data/test/transition_test.rb +77 -174
- data/test/world_mock.rb +12 -0
- data/test/{workspace_test.rb → world_test.rb} +19 -20
- data/test/y_petri_test.rb +4 -5
- metadata +101 -26
- data/lib/y_petri/dependency_injection.rb +0 -45
- data/lib/y_petri/manipulator/petri_net_related_methods.rb +0 -74
- data/lib/y_petri/manipulator.rb +0 -20
- data/lib/y_petri/net/selections.rb +0 -209
- data/lib/y_petri/simulation/collections.rb +0 -460
- data/lib/y_petri/workspace/parametrized_subclassing.rb +0 -22
- data/lib/y_petri/workspace/petri_net_related_methods.rb +0 -88
- data/lib/y_petri/workspace.rb +0 -16
- data/test/timed_simulation_test.rb +0 -153
@@ -0,0 +1,60 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
# A mixin for collections of Ts transitions.
|
4
|
+
#
|
5
|
+
class YPetri::Simulation::Transitions
|
6
|
+
module Type_Ts
|
7
|
+
include Type_T
|
8
|
+
include Type_s
|
9
|
+
|
10
|
+
# gradient closure accessor.
|
11
|
+
#
|
12
|
+
def gradient_closure
|
13
|
+
@gradient_closure ||= to_gradient_closure
|
14
|
+
end
|
15
|
+
|
16
|
+
# Member gradient closures.
|
17
|
+
#
|
18
|
+
def gradient_closures
|
19
|
+
map &:gradient_closure
|
20
|
+
end
|
21
|
+
|
22
|
+
# Gradient contribution for free places.
|
23
|
+
#
|
24
|
+
def gradient
|
25
|
+
gradient_closure.call
|
26
|
+
end
|
27
|
+
|
28
|
+
# Gradient contribution to all places.
|
29
|
+
#
|
30
|
+
def ∇
|
31
|
+
f2a * gradient
|
32
|
+
end
|
33
|
+
alias gradient_all ∇
|
34
|
+
|
35
|
+
# Constructs a gradient closure that outputs a gradient vector corresponding
|
36
|
+
# to free places. The vector is the gradient contribution of the transitions
|
37
|
+
# in this collection.
|
38
|
+
#
|
39
|
+
def to_gradient_closure
|
40
|
+
fp = free_places
|
41
|
+
closures = gradient_closures
|
42
|
+
sMV = simulation.MarkingVector
|
43
|
+
stu = simulation.time_unit
|
44
|
+
|
45
|
+
code_sections = map.with_index do |t, i|
|
46
|
+
"a = closures[ #{i} ].call\n" +
|
47
|
+
t.increment_by_codomain_code( vector: "g", source: "a" )
|
48
|
+
end
|
49
|
+
body = code_sections.join( "\n" )
|
50
|
+
λ = <<-LAMBDA
|
51
|
+
-> do
|
52
|
+
g = sMV.zero( fp ) / stu
|
53
|
+
#{body}
|
54
|
+
return g
|
55
|
+
end
|
56
|
+
LAMBDA
|
57
|
+
eval λ
|
58
|
+
end
|
59
|
+
end # module Type_Ts
|
60
|
+
end # class YPetri::Simulation::Transitions
|
@@ -0,0 +1,186 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
# Simulation mixin providing access to transitions.
|
4
|
+
#
|
5
|
+
class YPetri::Simulation::Transitions
|
6
|
+
module Access
|
7
|
+
# Does a transition belong to the simulation?
|
8
|
+
#
|
9
|
+
def includes_transition?( id )
|
10
|
+
true.tap { begin; transition( id )
|
11
|
+
rescue NameError, TypeError
|
12
|
+
return false
|
13
|
+
end }
|
14
|
+
end
|
15
|
+
alias include_transition? includes_transition?
|
16
|
+
|
17
|
+
# Transition of the simulation (belonging to the net).
|
18
|
+
#
|
19
|
+
def t( id )
|
20
|
+
transitions( id ).source
|
21
|
+
end
|
22
|
+
|
23
|
+
# Transitions of the simulation (belonging to the net).
|
24
|
+
#
|
25
|
+
def tt( ids=nil )
|
26
|
+
transitions( ids ).sources
|
27
|
+
end
|
28
|
+
|
29
|
+
# Free places of the simulation (belonging to the net).
|
30
|
+
#
|
31
|
+
def ts_tt( ids=nil )
|
32
|
+
ts_transitions( ids ).sources
|
33
|
+
end
|
34
|
+
|
35
|
+
# Free places of the simulation (belonging to the net).
|
36
|
+
#
|
37
|
+
def tS_tt( ids=nil )
|
38
|
+
tS_transitions( ids ).sources
|
39
|
+
end
|
40
|
+
|
41
|
+
# Free places of the simulation (belonging to the net).
|
42
|
+
#
|
43
|
+
def Ts_tt( ids=nil )
|
44
|
+
Ts_transitions( ids ).sources
|
45
|
+
end
|
46
|
+
|
47
|
+
# Free places of the simulation (belonging to the net).
|
48
|
+
#
|
49
|
+
def TS_tt( ids=nil )
|
50
|
+
TS_transitions( ids ).sources
|
51
|
+
end
|
52
|
+
|
53
|
+
# Transitions' names. Arguments, if any, are treated as in +#tranistions+ method.
|
54
|
+
#
|
55
|
+
def tn ids=nil
|
56
|
+
transitions( ids ).names
|
57
|
+
end
|
58
|
+
|
59
|
+
# Names of *ts* transitions. Arguments are handled as with +#ts_transitions+.
|
60
|
+
#
|
61
|
+
def nts ids=nil
|
62
|
+
ts_transitions( ids ).names( true )
|
63
|
+
end
|
64
|
+
|
65
|
+
# Names of *tS* transitions. Arguments are handled as with +#tS_transitions+.
|
66
|
+
#
|
67
|
+
def ntS ids=nil
|
68
|
+
tS_transitions( ids ).names( true )
|
69
|
+
end
|
70
|
+
|
71
|
+
# Names of *Ts* transitions. Arguments are handled as with +#tS_transitions+.
|
72
|
+
#
|
73
|
+
def nTs ids=nil
|
74
|
+
Ts_transitions( ids ).names( true )
|
75
|
+
end
|
76
|
+
|
77
|
+
# Names of *TS* transitions. Arguments are handled as with +#TS_transitions+.
|
78
|
+
#
|
79
|
+
def nTS ids=nil
|
80
|
+
TS_transitions( ids ).names( true )
|
81
|
+
end
|
82
|
+
|
83
|
+
# Names of *A* transitions. Arguments are handled as with +#A_transitions+.
|
84
|
+
#
|
85
|
+
def nA ids=nil
|
86
|
+
A_transitions( ids ).names( true )
|
87
|
+
end
|
88
|
+
|
89
|
+
# Names of *S* transitions. Arguments are handled as with +#S_transitions+.
|
90
|
+
#
|
91
|
+
def nS ids=nil
|
92
|
+
S_transitions( ids ).names( true )
|
93
|
+
end
|
94
|
+
|
95
|
+
# Names of *s* transitions. Arguments are handled as with +#s_transitions+.
|
96
|
+
#
|
97
|
+
def ns ids=nil
|
98
|
+
s_transitions( ids ).names( true )
|
99
|
+
end
|
100
|
+
|
101
|
+
protected
|
102
|
+
|
103
|
+
# Transition instance identification.
|
104
|
+
#
|
105
|
+
def transition( id )
|
106
|
+
begin
|
107
|
+
Transition().instance( id )
|
108
|
+
rescue NameError, TypeError
|
109
|
+
begin
|
110
|
+
tr = net.transition( id )
|
111
|
+
Transition().instances.find { |t_rep| t_rep.source == tr } ||
|
112
|
+
Transition().instance( tr.name )
|
113
|
+
rescue NameError, TypeError => msg
|
114
|
+
raise TypeError, "The argument #{id} does not identify a " +
|
115
|
+
"transition instance! (#{msg})"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# Without arguments, returns all the transitions. If arguments are given,
|
121
|
+
# they are converted to transitions before being returned.
|
122
|
+
#
|
123
|
+
def transitions ids=nil
|
124
|
+
return @transitions if ids.nil?
|
125
|
+
Transitions().load( ids.map { |id| transition id } )
|
126
|
+
end
|
127
|
+
|
128
|
+
# Simulation's *ts* transtitions. If arguments are given, they must identify
|
129
|
+
# *ts* transitions, and are treated as in +#transitions+ method. Note that *A*
|
130
|
+
# transitions are not considered eligible *ts* tranisitions for the purposes
|
131
|
+
# of this method.
|
132
|
+
#
|
133
|
+
def ts_transitions ids=nil
|
134
|
+
return transitions.ts if ids.nil?
|
135
|
+
transitions.ts.subset( ids )
|
136
|
+
end
|
137
|
+
|
138
|
+
# Simulation's *tS* transitions. If arguments are given, they must identify
|
139
|
+
# *tS* transitions, and are treated as in +#transitions+ method.
|
140
|
+
#
|
141
|
+
def tS_transitions ids=nil
|
142
|
+
return transitions.tS if ids.nil?
|
143
|
+
transitions.tS.subset( ids )
|
144
|
+
end
|
145
|
+
|
146
|
+
# Simulation's *Ts* transitions. If arguments are given, they must identify
|
147
|
+
# *Ts* transitions, and are treated as in +#transitions+ method.
|
148
|
+
#
|
149
|
+
def Ts_transitions ids=nil
|
150
|
+
return transitions.Ts if ids.nil?
|
151
|
+
transitions.Ts.subset( ids )
|
152
|
+
end
|
153
|
+
|
154
|
+
# Simulation's *TS* transitions. If arguments are given, they must identify
|
155
|
+
# *TS* transitions, and are treated as in +#transitions+ method.
|
156
|
+
#
|
157
|
+
def TS_transitions ids=nil
|
158
|
+
return transitions.TS if ids.nil?
|
159
|
+
transitions.TS.subset( ids )
|
160
|
+
end
|
161
|
+
|
162
|
+
# Simulation's *A* transitions. If arguments are given, they must identify
|
163
|
+
# *A* transitions, and are treated as in +#transitions+ method.
|
164
|
+
#
|
165
|
+
def A_transitions ids=nil
|
166
|
+
return transitions.A if ids.nil?
|
167
|
+
transitions.A.subset( ids )
|
168
|
+
end
|
169
|
+
|
170
|
+
# Simulation's *S* transitions. If arguments are given, they must identify
|
171
|
+
# *S* transitions, and are treated as in +#transitions+ method.
|
172
|
+
#
|
173
|
+
def S_transitions ids=nil
|
174
|
+
return transitions.S if ids.nil?
|
175
|
+
transitions.S.subset( ids )
|
176
|
+
end
|
177
|
+
|
178
|
+
# Simulation's *s* transitions. If arguments are given, they must identify
|
179
|
+
# *s* transitions, and are treated as in +#transitions+ method.
|
180
|
+
#
|
181
|
+
def s_transitions ids=nil
|
182
|
+
return transitions.s if ids.nil?
|
183
|
+
transitions.s.subset( ids )
|
184
|
+
end
|
185
|
+
end # Access
|
186
|
+
end # class YPetri::Simulation::Transitions
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
# A mixin for collections of t transitions.
|
4
|
+
#
|
5
|
+
class YPetri::Simulation::Transitions
|
6
|
+
module Type_t
|
7
|
+
include Type_a
|
8
|
+
|
9
|
+
# State change if the timeless transitions fire once.
|
10
|
+
#
|
11
|
+
def delta
|
12
|
+
ts.delta + tS.delta
|
13
|
+
end
|
14
|
+
|
15
|
+
# State change if the timeless transitions fire once.
|
16
|
+
#
|
17
|
+
def Δ
|
18
|
+
tS.Δ + ts.Δ
|
19
|
+
end
|
20
|
+
alias delta_all delta
|
21
|
+
end # module Type_T
|
22
|
+
end # class YPetri::Simulation::Transitions
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
# A mixin for collections of tS transitions.
|
4
|
+
#
|
5
|
+
class YPetri::Simulation::Transitions
|
6
|
+
module Type_tS
|
7
|
+
include Type_t
|
8
|
+
include Type_S
|
9
|
+
|
10
|
+
# firing closure accessor.
|
11
|
+
#
|
12
|
+
def firing_closure
|
13
|
+
@firing_closure ||= to_firing_closure
|
14
|
+
end
|
15
|
+
|
16
|
+
# tS transitions have firing closures.
|
17
|
+
#
|
18
|
+
def firing_closures
|
19
|
+
map &:firing_closure
|
20
|
+
end
|
21
|
+
|
22
|
+
# Firing vector (to be multiplied by the stoichiometry to get deltas)
|
23
|
+
#
|
24
|
+
def firing_vector
|
25
|
+
firing_closure.call
|
26
|
+
end
|
27
|
+
|
28
|
+
# Firing vector for these tS transitions, returned as array.
|
29
|
+
#
|
30
|
+
def firing
|
31
|
+
firing_closures.map &:call
|
32
|
+
end
|
33
|
+
|
34
|
+
# Delta contribution to free places.
|
35
|
+
#
|
36
|
+
def delta
|
37
|
+
stoichiometry_matrix * firing_vector
|
38
|
+
end
|
39
|
+
|
40
|
+
# Delta contribution to all places
|
41
|
+
#
|
42
|
+
def Δ
|
43
|
+
SM() * firing_vector
|
44
|
+
end
|
45
|
+
alias delta_all Δ
|
46
|
+
|
47
|
+
# Builds the firing vector closure, that outputs the firing vector based on
|
48
|
+
# the system state when called.
|
49
|
+
#
|
50
|
+
def to_firing_closure
|
51
|
+
closures = firing_closures
|
52
|
+
-> { closures.map( &:call ).to_column_vector }
|
53
|
+
end
|
54
|
+
end # module Type_tS
|
55
|
+
end # class YPetri::Simulation::Transitions
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
# A mixin for collections of ts transitions.
|
4
|
+
#
|
5
|
+
class YPetri::Simulation::Transitions
|
6
|
+
module Type_ts
|
7
|
+
include Type_t
|
8
|
+
include Type_s
|
9
|
+
|
10
|
+
# Delta closure accessor.
|
11
|
+
#
|
12
|
+
def delta_closure
|
13
|
+
@delta_closure ||= to_delta_closure
|
14
|
+
end
|
15
|
+
|
16
|
+
# ts transitions have action closures.
|
17
|
+
#
|
18
|
+
def delta_closures
|
19
|
+
map &:delta_closure
|
20
|
+
end
|
21
|
+
|
22
|
+
# Delta contribution to free places.
|
23
|
+
#
|
24
|
+
def delta
|
25
|
+
delta_closure.call
|
26
|
+
end
|
27
|
+
|
28
|
+
# Delta contribution to all places
|
29
|
+
#
|
30
|
+
def Δ
|
31
|
+
f2a * delta
|
32
|
+
end
|
33
|
+
alias delta_all Δ
|
34
|
+
|
35
|
+
# Constructs a delta closure that outputs a delta vector corresponding to
|
36
|
+
# free places. The vector is the delta contribution of the transitions in
|
37
|
+
# this collection.
|
38
|
+
#
|
39
|
+
def to_delta_closure
|
40
|
+
fp = free_places
|
41
|
+
closures = delta_closures
|
42
|
+
sMV = simulation.MarkingVector
|
43
|
+
code_sections = map.with_index do |t, i|
|
44
|
+
"a = closures[#{i}].call\n" +
|
45
|
+
t.increment_by_codomain_code( vector: "delta", source: "a" )
|
46
|
+
end
|
47
|
+
body = code_sections.join( "\n" )
|
48
|
+
λ = <<-LAMBDA
|
49
|
+
-> do
|
50
|
+
delta = sMV.zero( fp )
|
51
|
+
#{body}
|
52
|
+
return delta
|
53
|
+
end
|
54
|
+
LAMBDA
|
55
|
+
eval λ
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end # class YPetri::Simulation::Transitions
|
@@ -0,0 +1,98 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
require_relative 'a'
|
4
|
+
require_relative 'A'
|
5
|
+
require_relative 't'
|
6
|
+
require_relative 'T'
|
7
|
+
require_relative 's'
|
8
|
+
require_relative 'S'
|
9
|
+
require_relative 'ts'
|
10
|
+
require_relative 'Ts'
|
11
|
+
require_relative 'tS'
|
12
|
+
require_relative 'TS'
|
13
|
+
|
14
|
+
# A mixin with transition type selectors.
|
15
|
+
#
|
16
|
+
class YPetri::Simulation::Transitions
|
17
|
+
module Types
|
18
|
+
# Subset of s type transitions, if any.
|
19
|
+
#
|
20
|
+
def s
|
21
|
+
( @Type_s ||= Class.new( self.class ).tap do |klass|
|
22
|
+
klass.class_exec { include Type_s }
|
23
|
+
end ).load subset( &:s? )
|
24
|
+
end
|
25
|
+
|
26
|
+
# Subset of S type transitions, if any.
|
27
|
+
#
|
28
|
+
def S
|
29
|
+
( @Type_S ||= Class.new( self.class ).tap do |klass|
|
30
|
+
klass.class_exec { include Type_S }
|
31
|
+
end ).load subset( &:S? )
|
32
|
+
end
|
33
|
+
|
34
|
+
# Subset of t type transitions, if any.
|
35
|
+
#
|
36
|
+
def t
|
37
|
+
( @Type_t ||= Class.new( self.class ).tap do |klass|
|
38
|
+
klass.class_exec { include Type_t }
|
39
|
+
end ).load subset( &:t? )
|
40
|
+
end
|
41
|
+
|
42
|
+
# Subset of T type transitions, if any.
|
43
|
+
#
|
44
|
+
def T
|
45
|
+
( @Type_T ||= Class.new( self.class ).tap do |klass|
|
46
|
+
klass.class_exec { include Type_T }
|
47
|
+
end ).load subset( &:T? )
|
48
|
+
end
|
49
|
+
|
50
|
+
# Subset of ts type transitions, if any.
|
51
|
+
#
|
52
|
+
def ts
|
53
|
+
( @Type_ts ||= Class.new( self.class ).tap do |klass|
|
54
|
+
klass.class_exec { include Type_ts }
|
55
|
+
end ).load subset( &:ts? )
|
56
|
+
end
|
57
|
+
|
58
|
+
# Subset of tS type transitions, if any.
|
59
|
+
#
|
60
|
+
def tS
|
61
|
+
( @Type_tS ||= Class.new( self.class ).tap do |klass|
|
62
|
+
klass.class_exec { include Type_tS }
|
63
|
+
end ).load subset( &:tS? )
|
64
|
+
end
|
65
|
+
|
66
|
+
# Subset of Ts type transitions, if any.
|
67
|
+
#
|
68
|
+
def Ts
|
69
|
+
( @Type_Ts ||= Class.new( self.class ).tap do |klass|
|
70
|
+
klass.class_exec { include Type_Ts }
|
71
|
+
end ).load subset( &:Ts? )
|
72
|
+
end
|
73
|
+
|
74
|
+
# Subset of TS type transitions, if any.
|
75
|
+
#
|
76
|
+
def TS
|
77
|
+
( @Type_TS ||= Class.new( self.class ).tap do |klass|
|
78
|
+
klass.class_exec { include Type_TS }
|
79
|
+
end ).load subset( &:TS? )
|
80
|
+
end
|
81
|
+
|
82
|
+
# Subset of A type transitions, if any.
|
83
|
+
#
|
84
|
+
def A
|
85
|
+
( @Type_A ||= Class.new( self.class ).tap do |klass|
|
86
|
+
klass.class_exec { include Type_A }
|
87
|
+
end ).load subset( &:A? )
|
88
|
+
end
|
89
|
+
|
90
|
+
# Subset of a type transitions, if any.
|
91
|
+
#
|
92
|
+
def a
|
93
|
+
( @Type_a ||= Class.new( self.class ).tap do |klass|
|
94
|
+
klass.class_exec { include Type_a }
|
95
|
+
end ).load subset( &:a? )
|
96
|
+
end
|
97
|
+
end # Types
|
98
|
+
end # class YPetri::Simulation::Transitions
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
# Transition collection for YPetri::Simulation.
|
4
|
+
#
|
5
|
+
class YPetri::Simulation
|
6
|
+
class Transitions < Elements
|
7
|
+
require_relative 'transitions/types'
|
8
|
+
include Types
|
9
|
+
|
10
|
+
# Pushes a transition to the collection.
|
11
|
+
#
|
12
|
+
def push transition
|
13
|
+
t = begin
|
14
|
+
net.transition( transition )
|
15
|
+
rescue NameError, TypeError
|
16
|
+
return super transition( transition )
|
17
|
+
end
|
18
|
+
super t.name ? Transition().new( t, name: t.name ) : Transition().new( t )
|
19
|
+
end
|
20
|
+
end # class Transitions
|
21
|
+
end # class YPetri::Simulation::Transitions
|