y_petri 2.2.4 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +675 -0
  3. data/README.md +6 -3
  4. data/Rakefile +1 -1
  5. data/lib/y_petri/agent/{petri_net_related.rb → petri_net_aspect.rb} +34 -10
  6. data/lib/y_petri/agent/{simulation_related.rb → simulation_aspect.rb} +49 -34
  7. data/lib/y_petri/agent.rb +5 -5
  8. data/lib/y_petri/core/guarded.rb +24 -0
  9. data/lib/y_petri/core/timed/euler.rb +4 -8
  10. data/lib/y_petri/core/timed/gillespie.rb +11 -17
  11. data/lib/y_petri/core/timed/methods.rb +23 -0
  12. data/lib/y_petri/core/timed/pseudo_euler.rb +10 -13
  13. data/lib/y_petri/core/timed/quasi_euler.rb +9 -8
  14. data/lib/y_petri/core/timed/runge_kutta.rb +10 -18
  15. data/lib/y_petri/core/timed.rb +6 -14
  16. data/lib/y_petri/core/timeless/methods.rb +15 -0
  17. data/lib/y_petri/core/timeless/pseudo_euler.rb +4 -8
  18. data/lib/y_petri/core/timeless.rb +9 -4
  19. data/lib/y_petri/core.rb +44 -42
  20. data/lib/y_petri/net/data_set.rb +246 -142
  21. data/lib/y_petri/net/node_access.rb +282 -0
  22. data/lib/y_petri/net/own_state.rb +14 -4
  23. data/lib/y_petri/net/state/feature/assignment.rb +123 -0
  24. data/lib/y_petri/net/state/feature/delta.rb +55 -35
  25. data/lib/y_petri/net/state/feature/firing.rb +68 -25
  26. data/lib/y_petri/net/state/feature/flux.rb +9 -2
  27. data/lib/y_petri/net/state/feature/gradient.rb +36 -19
  28. data/lib/y_petri/net/state/feature/marking.rb +10 -5
  29. data/lib/y_petri/net/state/feature.rb +105 -11
  30. data/lib/y_petri/net/state/features/record.rb +144 -99
  31. data/lib/y_petri/net/state/features.rb +327 -200
  32. data/lib/y_petri/net/state.rb +48 -82
  33. data/lib/y_petri/net/visualization.rb +1 -1
  34. data/lib/y_petri/net.rb +62 -47
  35. data/lib/y_petri/place/arcs.rb +44 -0
  36. data/lib/y_petri/place/features.rb +115 -0
  37. data/lib/y_petri/place.rb +62 -29
  38. data/lib/y_petri/simulation/dependency.rb +31 -67
  39. data/lib/y_petri/simulation/feature_set.rb +1 -1
  40. data/lib/y_petri/simulation/initial_marking/access.rb +42 -26
  41. data/lib/y_petri/simulation/marking_clamps/access.rb +22 -17
  42. data/lib/y_petri/simulation/marking_clamps.rb +0 -2
  43. data/lib/y_petri/simulation/marking_vector/access.rb +102 -40
  44. data/lib/y_petri/simulation/marking_vector.rb +35 -37
  45. data/lib/y_petri/simulation/matrix.rb +1 -1
  46. data/lib/y_petri/simulation/node_representation.rb +25 -0
  47. data/lib/y_petri/simulation/nodes/access.rb +78 -0
  48. data/lib/y_petri/simulation/{elements.rb → nodes.rb} +14 -13
  49. data/lib/y_petri/simulation/place_mapping.rb +2 -2
  50. data/lib/y_petri/simulation/place_representation.rb +8 -7
  51. data/lib/y_petri/simulation/places/access.rb +89 -70
  52. data/lib/y_petri/simulation/places/free.rb +1 -1
  53. data/lib/y_petri/simulation/places/types.rb +20 -22
  54. data/lib/y_petri/simulation/places.rb +23 -18
  55. data/lib/y_petri/simulation/recorder.rb +23 -18
  56. data/lib/y_petri/simulation/timed/recorder.rb +19 -11
  57. data/lib/y_petri/simulation/timed.rb +93 -29
  58. data/lib/y_petri/simulation/timeless/recorder.rb +11 -6
  59. data/lib/y_petri/simulation/timeless.rb +13 -3
  60. data/lib/y_petri/simulation/transition_representation/A.rb +24 -4
  61. data/lib/y_petri/simulation/transition_representation/S.rb +11 -1
  62. data/lib/y_petri/simulation/transition_representation/T.rb +1 -1
  63. data/lib/y_petri/simulation/transition_representation/Ts.rb +1 -1
  64. data/lib/y_petri/simulation/transition_representation/a.rb +1 -1
  65. data/lib/y_petri/simulation/transition_representation/s.rb +12 -1
  66. data/lib/y_petri/simulation/transition_representation/t.rb +1 -1
  67. data/lib/y_petri/simulation/transition_representation/tS.rb +1 -1
  68. data/lib/y_petri/simulation/transition_representation/ts.rb +1 -1
  69. data/lib/y_petri/simulation/transition_representation/types.rb +1 -1
  70. data/lib/y_petri/simulation/transition_representation.rb +4 -11
  71. data/lib/y_petri/simulation/transitions/A.rb +17 -2
  72. data/lib/y_petri/simulation/transitions/S.rb +1 -1
  73. data/lib/y_petri/simulation/transitions/T.rb +1 -1
  74. data/lib/y_petri/simulation/transitions/Ts.rb +6 -5
  75. data/lib/y_petri/simulation/transitions/a.rb +1 -1
  76. data/lib/y_petri/simulation/transitions/access.rb +195 -168
  77. data/lib/y_petri/simulation/transitions/s.rb +1 -1
  78. data/lib/y_petri/simulation/transitions/t.rb +1 -1
  79. data/lib/y_petri/simulation/transitions/tS.rb +1 -1
  80. data/lib/y_petri/simulation/transitions/ts.rb +1 -1
  81. data/lib/y_petri/simulation/transitions/types.rb +1 -1
  82. data/lib/y_petri/simulation/transitions.rb +5 -7
  83. data/lib/y_petri/simulation.rb +84 -90
  84. data/lib/y_petri/transition/A.rb +8 -2
  85. data/lib/y_petri/transition/T.rb +25 -2
  86. data/lib/y_petri/transition/arcs.rb +19 -3
  87. data/lib/y_petri/transition/construction_convenience.rb +11 -10
  88. data/lib/y_petri/transition/t.rb +14 -1
  89. data/lib/y_petri/transition/types.rb +6 -1
  90. data/lib/y_petri/transition.rb +9 -12
  91. data/lib/y_petri/version.rb +1 -1
  92. data/lib/y_petri/world/dependency.rb +3 -3
  93. data/lib/y_petri/world/{petri_net_related.rb → petri_net_aspect.rb} +4 -4
  94. data/lib/y_petri/world/simulation_aspect.rb +352 -0
  95. data/lib/y_petri/world.rb +4 -4
  96. data/lib/y_petri.rb +1 -1
  97. data/test/agent_test.rb +2 -1
  98. data/test/examples/demonstrator.rb +4 -1
  99. data/test/examples/demonstrator_2.rb +5 -0
  100. data/test/examples/demonstrator_4.rb +6 -5
  101. data/test/examples/example_2.rb +2 -0
  102. data/test/examples/manual_examples.rb +4 -4
  103. data/test/net_test.rb +457 -54
  104. data/test/place_test.rb +11 -7
  105. data/test/simulation_test.rb +358 -331
  106. data/test/transition_test.rb +11 -10
  107. data/test/world_test.rb +2 -0
  108. data/test/y_petri_test.rb +2 -1
  109. data/y_petri.gemspec +24 -18
  110. metadata +71 -17
  111. data/LICENSE +0 -22
  112. data/lib/y_petri/net/element_access.rb +0 -239
  113. data/lib/y_petri/simulation/element_representation.rb +0 -20
  114. data/lib/y_petri/simulation/elements/access.rb +0 -57
  115. data/lib/y_petri/transition/type.rb +0 -103
  116. data/lib/y_petri/transition/type_information.rb +0 -103
  117. data/lib/y_petri/world/simulation_related.rb +0 -176
@@ -1,4 +1,4 @@
1
- #encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
3
  # A mixin for collections of A transitions.
4
4
  #
@@ -7,12 +7,18 @@ class YPetri::Simulation::Transitions
7
7
  def initialize
8
8
  end
9
9
 
10
- # Assignment closures that directly affect the marking when called.
10
+ # Assignment closures.
11
11
  #
12
12
  def assignment_closures
13
13
  map &:assignment_closure
14
14
  end
15
15
 
16
+ # Assignment closures that directly affect the marking when called.
17
+ #
18
+ def direct_assignment_closures
19
+ map &:direct_assignment_closure
20
+ end
21
+
16
22
  # Combined assignment action, as it would occur if these A transitions fired
17
23
  # in order, as hash place >> action.
18
24
  #
@@ -34,5 +40,14 @@ class YPetri::Simulation::Transitions
34
40
  -> { closures.each &:call }
35
41
  end
36
42
  alias assignment_closure to_assignment_closure
43
+
44
+ # Builds a joint direct assignment closure, directly bound to the marking
45
+ # vector and changing its values when called.
46
+ #
47
+ def to_direct_assignment_closure
48
+ closures = direct_assignment_closures
49
+ -> { closures.each &:call }
50
+ end
51
+ alias direct_assignment_closure to_direct_assignment_closure
37
52
  end # Type_A
38
53
  end # class YPetri::Simulation::Transitions
@@ -1,4 +1,4 @@
1
- #encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
3
  # A mixin for collections of S transitions.
4
4
  #
@@ -1,4 +1,4 @@
1
- #encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
3
  # A mixin for collections of T transitions.
4
4
  #
@@ -1,4 +1,4 @@
1
- #encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
3
  # A mixin for collections of Ts transitions.
4
4
  #
@@ -31,10 +31,11 @@ class YPetri::Simulation::Transitions
31
31
  # in this collection.
32
32
  #
33
33
  def to_gradient_closure
34
- fp = free_places
35
- closures = gradient_closures
34
+ fp = free_places #.tap { |fp| puts; print "fp: "; Kernel::p fp }
35
+ closures = gradient_closures #.tap { |cl| puts; print "closures: "; Kernel::p cl }
36
36
  sMV = simulation.MarkingVector
37
37
  stu = simulation.time_unit
38
+ zero = ( sMV.zero( fp ) / stu ) #.tap { |z| puts; print "zero mv: "; Kernel::p z }
38
39
 
39
40
  code_sections = map.with_index do |t, i|
40
41
  "a = closures[ #{i} ].call\n" +
@@ -43,12 +44,12 @@ class YPetri::Simulation::Transitions
43
44
  body = code_sections.join( "\n" )
44
45
  λ = <<-LAMBDA
45
46
  -> do
46
- g = sMV.zero( fp ) / stu
47
+ g = zero
47
48
  #{body}
48
49
  return g
49
50
  end
50
51
  LAMBDA
51
- eval λ
52
+ eval λ #.tap { |l| puts; puts "eval code: "; puts l }
52
53
  end
53
54
  alias gradient_closure to_gradient_closure
54
55
  end # module Type_Ts
@@ -1,4 +1,4 @@
1
- #encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
3
  # A mixin for collections of A transitions.
4
4
  #
@@ -1,4 +1,4 @@
1
- #encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
3
  # Simulation mixin providing access to transitions.
4
4
  #
@@ -6,9 +6,8 @@ class YPetri::Simulation::Transitions
6
6
  module Access
7
7
  # Does a transition belong to the simulation?
8
8
  #
9
- def includes_transition?( id )
10
- true.tap { begin; transition( id )
11
- rescue NameError, TypeError
9
+ def includes_transition?( transition )
10
+ true.tap { begin; transition( transition ); rescue NameError, TypeError
12
11
  return false
13
12
  end }
14
13
  end
@@ -16,239 +15,267 @@ class YPetri::Simulation::Transitions
16
15
 
17
16
  # Net's transition.
18
17
  #
19
- def t( id )
20
- transitions( id ).source
21
- end
22
-
23
- # Net's transitions.
24
- #
25
- def tt( ids=nil )
26
- transitions( ids ).sources
27
- end
28
-
29
- # Net's *ts* transitions.
30
- #
31
- def ts_tt( ids=nil )
32
- ts_transitions( ids ).sources
33
- end
34
-
35
- # Net's *tS* transitions.
36
- #
37
- def tS_tt( ids=nil )
38
- tS_transitions( ids ).sources
39
- end
40
-
18
+ def t( transition )
19
+ transition( transition ).source
20
+ end
21
+
22
+ # Makes it so that when "transitions" is abbreviated to "tt", transitions
23
+ # of the underlying net are returned rather than simulation's transition
24
+ # representations.
25
+ #
26
+ chain Tt: :Transitions,
27
+ tt: :transitions,
28
+ ts_Tt: :ts_Transitions,
29
+ ts_tt: :ts_transitions,
30
+ tS_Tt: :tS_Transitions,
31
+ tS_tt: :tS_transitions,
32
+ Ts_Tt: :Ts_Transitions,
33
+ Ts_tt: :Ts_transitions,
34
+ TS_Tt: :TS_Transitions,
35
+ TS_tt: :TS_transitions,
36
+ A_Tt: :A_Transitions,
37
+ A_tt: :A_transitions,
38
+ S_Tt: :S_Transitions,
39
+ S_tt: :S_transitions,
40
+ s_Tt: :S_Transitions,
41
+ s_tt: :S_transitions,
42
+ T_Tt: :T_Transitions,
43
+ T_tt: :T_transitions,
44
+ t_Tt: :t_Transitions,
45
+ t_tt: :t_transitions,
46
+ &:sources
47
+
48
+ # Makes it so that +Tn+/+tn+ means "names of transitions", and that when
49
+ # message "n" + transition_type is sent to the simulation, it returns names
50
+ # of the trasitions of the specified type.
51
+ #
52
+ chain Tn: :Tt,
53
+ tn: :tt,
54
+ nts: :ts_tt,
55
+ ntS: :tS_tt,
56
+ nTs: :Ts_tt,
57
+ nTS: :TS_tt,
58
+ nA: :A_tt,
59
+ nS: :S_tt,
60
+ ns: :s_tt,
61
+ nT: :T_tt,
62
+ nt: :t_tt do |r| r.names( true ) end
41
63
 
42
- # Net's *Ts* transitions.
43
- #
44
- def Ts_tt( ids=nil )
45
- Ts_transitions( ids ).sources
46
- end
47
-
48
- # Net's *TS* transitions.
49
- #
50
- def TS_tt( ids=nil )
51
- TS_transitions( ids ).sources
52
- end
53
-
54
- # Net's *A* transitions.
55
- #
56
- def A_tt( ids=nil )
57
- A_transitions( ids ).sources
58
- end
59
-
60
- # Net's *S* transitions.
61
- #
62
- def S_tt( ids=nil )
63
- S_transitions( ids ).sources
64
- end
65
-
66
- # Net's *s* (non-stoichiometric) transitions.
67
- #
68
- def s_tt( ids=nil )
69
- s_transitions( ids ).sources
70
- end
71
-
72
- # Net's *T* transitions.
73
- #
74
- def T_tt( ids=nil )
75
- T_transitions( ids ).sources
76
- end
64
+ protected
77
65
 
78
- # Net's *t* (timeless) transitions.
66
+ # Transition instance identification.
79
67
  #
80
- def t_tt ids=nil
81
- return transitions.t if ids.nil?
82
- transitions.t.subset( ids )
68
+ def transition( transition )
69
+ begin; Transition().instance( transition ); rescue NameError, TypeError
70
+ begin
71
+ transition = net.transition( transition )
72
+ Transition().instances.find { |t_rep| t_rep.source == transition } ||
73
+ Transition().instance( transition.name )
74
+ rescue NameError, TypeError => msg
75
+ fail TypeError, "Unknown transition instance: #{transition}! (#{msg})"
76
+ end
77
+ end
83
78
  end
84
79
 
85
- # Names of specified transitions.
80
+ # Constructs an instance of @Transitions parametrized subclass. Expects a
81
+ # single array of transitions or transition ids and returns an array of
82
+ # corresponding transition representations in the simulation. Note that the
83
+ # includer of the +Transitions::Access+ module normally overloads
84
+ # :Transitions message in such way, that even without an argument, it does
85
+ # not fil, but returns @Transitions parametrized subclass itself.
86
86
  #
87
- def tn ids=nil
88
- tt( ids ).names
87
+ def Transitions( array )
88
+ Transitions().load array.map &method( :transition )
89
89
  end
90
90
 
91
- # Names of specified *ts* transitions.
91
+ # Without arguments, returns all the transition representations in the
92
+ # simulation. Otherwise, it accepts an arbitrary number of nodes or node
93
+ # ids as arguments, and returns an array of the corresponding transition
94
+ # representations.
92
95
  #
93
- def nts ids=nil
94
- ts_tt( ids ).names( true )
96
+ def transitions( *transitions )
97
+ return @transitions if transitions.empty?
98
+ Transitions( transitions )
95
99
  end
96
100
 
97
- # Names of specified *tS* transitions.
101
+ # Simulation's *ts* transitions. Expects a single array of +ts+ transitions
102
+ # or their ids and returns an array of the corresponding ts transition
103
+ # representations.
98
104
  #
99
- def ntS ids=nil
100
- tS_tt( ids ).names( true )
105
+ def ts_Transitions( array )
106
+ transitions.ts.subset( array )
101
107
  end
102
108
 
103
- # Names of specified *Ts* transitions.
109
+ # Simulation's *ts* transitions. Without arguments, returns all the ts
110
+ # transitions of the simulation. Otherwise, it accepts an arbitrary number
111
+ # of ts transitions or transition ids as arguments, and returns an array of
112
+ # the corresponding ts transitions of the simulation.
104
113
  #
105
- def nTs ids=nil
106
- Ts_tt( ids ).names( true )
114
+ def ts_transitions( *transitions )
115
+ return transitions().ts if transitions.empty?
116
+ ts_Transitions( transitions )
107
117
  end
108
118
 
109
- # Names of specified *TS* transitions.
119
+ # Simulation's *tS* transitions. Expects a single array of +tS+ transitions
120
+ # or their ids and returns an array of the corresponding tS transition
121
+ # representations.
110
122
  #
111
- def nTS ids=nil
112
- TS_tt( ids ).names( true )
123
+ def tS_Transitions( array )
124
+ transitions.tS.subset( array )
113
125
  end
114
126
 
115
- # Names of specified *A* transitions.
127
+ # Simulation's *tS* transitions. Without arguments, returns all the tS
128
+ # transitions of the simulation. Otherwise, it accepts an arbitrary number
129
+ # of tS transitions or transition ids as arguments, and returns an array of
130
+ # the corresponding tS transitions of the simulation.
116
131
  #
117
- def nA ids=nil
118
- A_tt( ids ).names( true )
132
+ def tS_transitions( *transitions )
133
+ return transitions().tS if transitions.empty?
134
+ tS_Transitions( transitions )
119
135
  end
120
136
 
121
- # Names of specified *S* transitions.
137
+ # Simulation's *Ts* transitions. Expects a single array of +Ts+ transitions
138
+ # or their ids and returns an array of the corresponding Ts transition
139
+ # representations.
122
140
  #
123
- def nS ids=nil
124
- S_tt( ids ).names( true )
141
+ def Ts_Transitions( array )
142
+ transitions.Ts.subset( array )
125
143
  end
126
144
 
127
- # Names of specified *s* transitions.
145
+ # Simulation's *Ts* transitions. Without arguments, returns all the Ts
146
+ # transitions of the simulation. Otherwise, it accepts an arbitrary number
147
+ # of Ts transitions or transition ids as arguments, and returns an array of
148
+ # the corresponding Ts transitions of the simulation.
128
149
  #
129
- def ns ids=nil
130
- s_tt( ids ).names( true )
150
+ def Ts_transitions( *transitions )
151
+ return transitions().Ts if transitions.empty?
152
+ Ts_Transitions( transitions )
131
153
  end
132
154
 
133
- # Names of specified *T* transitions.
155
+ # Simulation's *TS* transitions. Expects a single array of +TS+ transitions
156
+ # or their ids and returns an array of the corresponding TS transition
157
+ # representations.
134
158
  #
135
- def nT ids=nil
136
- T_tt( ids ).names( true )
159
+ def TS_Transitions( array )
160
+ transitions.TS.subset( array )
137
161
  end
138
162
 
139
- # Names of specified *t* transitions.
163
+ # Simulation's *TS* transitions. Without arguments, returns all the TS
164
+ # transitions of the simulation. Otherwise, it accepts an arbitrary number
165
+ # of TS transitions or transition ids as arguments, and returns an array of
166
+ # the corresponding TS transitions of the simulation.
140
167
  #
141
- def nt ids=nil
142
- t_tt( ids ).names( true )
168
+ def TS_transitions( *transitions )
169
+ return transitions().TS if transitions.empty?
170
+ TS_Transitions( transitions )
143
171
  end
144
172
 
145
- protected
146
-
147
- # Transition instance identification.
173
+ # Simulation's *A* transitions. Expects a single array of +A+ transitions
174
+ # or their ids and returns an array of the corresponding A transition
175
+ # representations.
148
176
  #
149
- def transition( id )
150
- begin
151
- Transition().instance( id )
152
- rescue NameError, TypeError
153
- begin
154
- tr = net.transition( id )
155
- Transition().instances.find { |t_rep| t_rep.source == tr } ||
156
- Transition().instance( tr.name )
157
- rescue NameError, TypeError => msg
158
- raise TypeError, "The argument #{id} does not identify a " +
159
- "transition instance! (#{msg})"
160
- end
161
- end
177
+ def A_Transitions( array )
178
+ transitions.A.subset( array )
162
179
  end
163
180
 
164
- # Without arguments, returns all the transitions. If arguments are given,
165
- # they are converted to transitions before being returned.
181
+ # Simulation's *A* transitions. Without arguments, returns all the A
182
+ # transitions of the simulation. Otherwise, it accepts an arbitrary number
183
+ # of A transitions or transition ids as arguments, and returns an array of
184
+ # the corresponding A transitions of the simulation.
166
185
  #
167
- def transitions ids=nil
168
- return @transitions if ids.nil?
169
- Transitions().load( ids.map { |id| transition id } )
186
+ def A_transitions( *transitions )
187
+ return transitions().A if transitions.empty?
188
+ A_Transitions( transitions )
170
189
  end
171
190
 
172
- # Simulation's *ts* transtitions. If arguments are given, they must identify
173
- # *ts* transitions, and are treated as in +#transitions+ method. Note that *A*
174
- # transitions are not considered eligible *ts* tranisitions for the purposes
175
- # of this method.
191
+ # Simulation's *a* transitions. Expects a single array of +a+ transitions
192
+ # or their ids and returns an array of the corresponding a transition
193
+ # representations.
176
194
  #
177
- def ts_transitions ids=nil
178
- return transitions.ts if ids.nil?
179
- transitions.ts.subset( transitions ids )
195
+ def a_Transitions( array )
196
+ transitions.a.subset( array )
180
197
  end
181
198
 
182
- # Simulation's *tS* transitions. If arguments are given, they must identify
183
- # *tS* transitions, and are treated as in +#transitions+ method.
199
+ # Simulation's *a* transitions. Without arguments, returns all the a
200
+ # transitions of the simulation. Otherwise, it accepts an arbitrary number
201
+ # of a transitions or transition ids as arguments, and returns an array of
202
+ # the corresponding a transitions of the simulation.
184
203
  #
185
- def tS_transitions ids=nil
186
- return transitions.tS if ids.nil?
187
- transitions.tS.subset( transitions ids )
204
+ def a_transitions( *transitions )
205
+ return transitions().a if transitions.empty?
206
+ a_Transitions( transitions )
188
207
  end
189
208
 
190
- # Simulation's *Ts* transitions. If arguments are given, they must identify
191
- # *Ts* transitions, and are treated as in +#transitions+ method.
209
+ # Simulation's *S* transitions. Expects a single array of +S+ transitions
210
+ # or their ids and returns an array of the corresponding S transition
211
+ # representations.
192
212
  #
193
- def Ts_transitions ids=nil
194
- return transitions.Ts if ids.nil?
195
- transitions.Ts.subset( transitions ids )
213
+ def S_Transitions( array )
214
+ transitions.S.subset( array )
196
215
  end
197
216
 
198
- # Simulation's *TS* transitions. If arguments are given, they must identify
199
- # *TS* transitions, and are treated as in +#transitions+ method.
217
+ # Simulation's *S* transitions. Without arguments, returns all the S
218
+ # transitions of the simulation. Otherwise, it accepts an arbitrary number
219
+ # of S transitions or transition ids as arguments, and returns an array of
220
+ # the corresponding S transitions of the simulation.
200
221
  #
201
- def TS_transitions ids=nil
202
- return transitions.TS if ids.nil?
203
- transitions.TS.subset( transitions ids )
222
+ def S_transitions( *transitions )
223
+ return transitions().S if transitions.empty?
224
+ S_Transitions( transitions )
204
225
  end
205
226
 
206
- # Simulation's *A* transitions. If arguments are given, they must identify
207
- # *A* transitions, and are treated as in +#transitions+ method.
227
+ # Simulation's *s* transitions. Expects a single array of +s+ transitions
228
+ # or their ids and returns an array of the corresponding s transition
229
+ # representations.
208
230
  #
209
- def A_transitions ids=nil
210
- return transitions.A if ids.nil?
211
- transitions.A.subset( transitions ids )
231
+ def s_Transitions( array )
232
+ transitions.s.subset( array )
212
233
  end
213
234
 
214
- # Simulation's *a* transitions. If argument are given, they must identify
215
- # *a* transitions, and are treated as in +#transitions+ method.
235
+ # Simulation's *s* transitions. Without arguments, returns all the s
236
+ # transitions of the simulation. Otherwise, it accepts an arbitrary number
237
+ # of s transitions or transition ids as arguments, and returns an array of
238
+ # the corresponding s transitions of the simulation.
216
239
  #
217
- def a_transitions ids=nil
218
- return transitions.a if ids.nil?
219
- transitions.a.subset( transitions ids )
240
+ def s_transitions( *transitions )
241
+ return transitions().s if transitions.empty?
242
+ s_Transitions( transitions )
220
243
  end
221
244
 
222
- # Simulation's *S* transitions. If arguments are given, they must identify
223
- # *S* transitions, and are treated as in +#transitions+ method.
245
+ # Simulation's *T* transitions. Expects a single array of +T+ transitions
246
+ # or their ids and returns an array of the corresponding T transition
247
+ # representations.
224
248
  #
225
- def S_transitions ids=nil
226
- return transitions.S if ids.nil?
227
- transitions.S.subset( transitions ids )
249
+ def T_Transitions( array )
250
+ transitions.T.subset( array )
228
251
  end
229
252
 
230
- # Simulation's *s* transitions. If arguments are given, they must identify
231
- # *s* transitions, and are treated as in +#transitions+ method.
253
+ # Simulation's *T* transitions. Without arguments, returns all the T
254
+ # transitions of the simulation. Otherwise, it accepts an arbitrary number
255
+ # of T transitions or transition ids as arguments, and returns an array of
256
+ # the corresponding T transitions of the simulation.
232
257
  #
233
- def s_transitions ids=nil
234
- return transitions.s if ids.nil?
235
- transitions.s.subset( transitions ids )
258
+ def T_transitions( *transitions )
259
+ return transitions().T if transitions.empty?
260
+ T_Transitions( transitions )
236
261
  end
237
262
 
238
- # Simulation's *T* transitions. If arguments are given, they must identify
239
- # *T* transitions, and are treated as in +#transitions+ method.
263
+ # Simulation's *t* transitions. Expects a single array of +t+ transitions
264
+ # or their ids and returns an array of the corresponding t transition
265
+ # representations.
240
266
  #
241
- def T_transitions ids=nil
242
- return transitions.T if ids.nil?
243
- transitions.T.subset( transitions ids )
267
+ def t_Transitions( array )
268
+ transitions.t.subset( array )
244
269
  end
245
270
 
246
- # Simulation's *t* transitions. If arguments are given, they must identify
247
- # *t* transitions, and are treated as in +#transitions+ method.
271
+ # Simulation's *t* transitions. Without arguments, returns all the t
272
+ # transitions of the simulation. Otherwise, it accepts an arbitrary number
273
+ # of t transitions or transition ids as arguments, and returns an array of
274
+ # the corresponding t transitions of the simulation.
248
275
  #
249
- def t_transitions ids=nil
250
- return transitions.t if ids.nil?
251
- transitions.t.subset( transitions ids )
276
+ def t_transitions( *transitions )
277
+ return transitions().t if transitions.empty?
278
+ t_Transitions( transitions )
252
279
  end
253
280
  end # Access
254
281
  end # class YPetri::Simulation::Transitions
@@ -1,4 +1,4 @@
1
- #encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
3
  # A mixin for collections of s transitions.
4
4
  #
@@ -1,4 +1,4 @@
1
- #encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
3
  # A mixin for collections of t transitions.
4
4
  #
@@ -1,4 +1,4 @@
1
- #encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
3
  # A mixin for collections of tS transitions.
4
4
  #
@@ -1,4 +1,4 @@
1
- #encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
3
  # A mixin for collections of ts transitions.
4
4
  #
@@ -1,4 +1,4 @@
1
- #encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
3
  require_relative 'a'
4
4
  require_relative 'A'
@@ -1,18 +1,16 @@
1
1
  # encoding: utf-8
2
2
 
3
- # Transition collection for YPetri::Simulation.
4
- #
5
3
  class YPetri::Simulation
6
- class Transitions < Elements
4
+ # Transition collection for YPetri::Simulation.
5
+ #
6
+ class Transitions < Nodes
7
7
  require_relative 'transitions/types'
8
- include Types
8
+ Types # ★ means include
9
9
 
10
10
  # Pushes a transition to the collection.
11
11
  #
12
12
  def push transition
13
- t = begin
14
- net.transition( transition )
15
- rescue NameError, TypeError
13
+ t = begin; net.transition( transition ); rescue NameError, TypeError
16
14
  return super transition( transition )
17
15
  end
18
16
  super t.name ? Transition().new( t, name: t.name ) : Transition().new( t )