y_petri 2.0.15 → 2.1.3

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/lib/y_petri/{manipulator → agent}/hash_key_pointer.rb +2 -2
  3. data/lib/y_petri/agent/petri_net_related.rb +115 -0
  4. data/lib/y_petri/{manipulator → agent}/selection.rb +2 -1
  5. data/lib/y_petri/{manipulator/simulation_related_methods.rb → agent/simulation_related.rb} +93 -110
  6. data/lib/y_petri/agent.rb +22 -0
  7. data/lib/y_petri/core/timed/euler.rb +20 -0
  8. data/lib/y_petri/core/timed/pseudo_euler.rb +31 -0
  9. data/lib/y_petri/core/timed/quasi_euler.rb +23 -0
  10. data/lib/y_petri/core/timed.rb +70 -0
  11. data/lib/y_petri/core/timeless/pseudo_euler.rb +20 -0
  12. data/lib/y_petri/core/timeless.rb +12 -0
  13. data/lib/y_petri/core.rb +100 -0
  14. data/lib/y_petri/dsl.rb +66 -0
  15. data/lib/y_petri/fixed_assets.rb +7 -0
  16. data/lib/y_petri/net/element_access.rb +239 -0
  17. data/lib/y_petri/net/state/feature/delta.rb +88 -0
  18. data/lib/y_petri/net/state/feature/firing.rb +57 -0
  19. data/lib/y_petri/net/state/feature/flux.rb +58 -0
  20. data/lib/y_petri/net/state/feature/gradient.rb +75 -0
  21. data/lib/y_petri/net/state/feature/marking.rb +62 -0
  22. data/lib/y_petri/net/state/feature.rb +79 -0
  23. data/lib/y_petri/net/state/features/dataset.rb +135 -0
  24. data/lib/y_petri/net/state/features/record.rb +50 -0
  25. data/lib/y_petri/net/state/features.rb +126 -0
  26. data/lib/y_petri/net/state.rb +121 -0
  27. data/lib/y_petri/net/timed.rb +8 -0
  28. data/lib/y_petri/net/visualization.rb +3 -3
  29. data/lib/y_petri/net.rb +73 -77
  30. data/lib/y_petri/place.rb +8 -3
  31. data/lib/y_petri/simulation/dependency.rb +107 -0
  32. data/lib/y_petri/simulation/element_representation.rb +20 -0
  33. data/lib/y_petri/simulation/elements/access.rb +57 -0
  34. data/lib/y_petri/simulation/elements.rb +45 -0
  35. data/lib/y_petri/simulation/feature_set.rb +21 -0
  36. data/lib/y_petri/simulation/initial_marking/access.rb +55 -0
  37. data/lib/y_petri/simulation/initial_marking.rb +15 -0
  38. data/lib/y_petri/simulation/marking_clamps/access.rb +34 -0
  39. data/lib/y_petri/simulation/marking_clamps.rb +18 -0
  40. data/lib/y_petri/simulation/marking_vector/access.rb +106 -0
  41. data/lib/y_petri/simulation/marking_vector.rb +156 -0
  42. data/lib/y_petri/simulation/matrix.rb +64 -0
  43. data/lib/y_petri/simulation/place_mapping.rb +62 -0
  44. data/lib/y_petri/simulation/place_representation.rb +74 -0
  45. data/lib/y_petri/simulation/places/access.rb +121 -0
  46. data/lib/y_petri/simulation/places/clamped.rb +8 -0
  47. data/lib/y_petri/simulation/places/free.rb +8 -0
  48. data/lib/y_petri/simulation/places/types.rb +25 -0
  49. data/lib/y_petri/simulation/places.rb +41 -0
  50. data/lib/y_petri/simulation/recorder.rb +54 -0
  51. data/lib/y_petri/simulation/timed/recorder.rb +53 -0
  52. data/lib/y_petri/simulation/timed.rb +161 -261
  53. data/lib/y_petri/simulation/timeless/recorder.rb +25 -0
  54. data/lib/y_petri/simulation/timeless.rb +35 -0
  55. data/lib/y_petri/simulation/transition_representation/A.rb +58 -0
  56. data/lib/y_petri/simulation/transition_representation/S.rb +45 -0
  57. data/lib/y_petri/simulation/transition_representation/T.rb +80 -0
  58. data/lib/y_petri/simulation/transition_representation/TS.rb +46 -0
  59. data/lib/y_petri/simulation/transition_representation/Ts.rb +32 -0
  60. data/lib/y_petri/simulation/transition_representation/a.rb +30 -0
  61. data/lib/y_petri/simulation/transition_representation/s.rb +29 -0
  62. data/lib/y_petri/simulation/transition_representation/t.rb +37 -0
  63. data/lib/y_petri/simulation/transition_representation/tS.rb +38 -0
  64. data/lib/y_petri/simulation/transition_representation/ts.rb +32 -0
  65. data/lib/y_petri/simulation/transition_representation/types.rb +62 -0
  66. data/lib/y_petri/simulation/transition_representation.rb +79 -0
  67. data/lib/y_petri/simulation/transitions/A.rb +40 -0
  68. data/lib/y_petri/simulation/transitions/S.rb +24 -0
  69. data/lib/y_petri/simulation/transitions/T.rb +34 -0
  70. data/lib/y_petri/simulation/transitions/TS.rb +57 -0
  71. data/lib/y_petri/simulation/transitions/Ts.rb +60 -0
  72. data/lib/y_petri/simulation/transitions/a.rb +8 -0
  73. data/lib/y_petri/simulation/transitions/access.rb +186 -0
  74. data/lib/y_petri/simulation/transitions/s.rb +9 -0
  75. data/lib/y_petri/simulation/transitions/t.rb +22 -0
  76. data/lib/y_petri/simulation/transitions/tS.rb +55 -0
  77. data/lib/y_petri/simulation/transitions/ts.rb +58 -0
  78. data/lib/y_petri/simulation/transitions/types.rb +98 -0
  79. data/lib/y_petri/simulation/transitions.rb +21 -0
  80. data/lib/y_petri/simulation.rb +176 -781
  81. data/lib/y_petri/transition/assignment.rb +7 -5
  82. data/lib/y_petri/transition/construction.rb +119 -187
  83. data/lib/y_petri/transition/init.rb +311 -0
  84. data/lib/y_petri/transition/ordinary_timeless.rb +8 -6
  85. data/lib/y_petri/transition/timed.rb +11 -18
  86. data/lib/y_petri/transition.rb +104 -132
  87. data/lib/y_petri/version.rb +1 -1
  88. data/lib/y_petri/world/dependency.rb +40 -0
  89. data/lib/y_petri/world/petri_net_related.rb +61 -0
  90. data/lib/y_petri/{workspace/simulation_related_methods.rb → world/simulation_related.rb} +42 -49
  91. data/lib/y_petri/world.rb +27 -0
  92. data/lib/y_petri.rb +47 -99
  93. data/test/{manipulator_test.rb → agent_test.rb} +19 -17
  94. data/{lib/y_petri → test/examples}/demonstrator.rb +0 -0
  95. data/{lib/y_petri → test/examples}/demonstrator_2.rb +1 -0
  96. data/{lib/y_petri → test/examples}/demonstrator_3.rb +0 -0
  97. data/{lib/y_petri → test/examples}/demonstrator_4.rb +0 -0
  98. data/test/examples/example_2.rb +16 -0
  99. data/test/{manual_examples.rb → examples/manual_examples.rb} +0 -0
  100. data/test/net_test.rb +126 -121
  101. data/test/place_test.rb +1 -1
  102. data/test/sim_test +565 -0
  103. data/test/simulation_test.rb +338 -264
  104. data/test/transition_test.rb +77 -174
  105. data/test/world_mock.rb +12 -0
  106. data/test/{workspace_test.rb → world_test.rb} +19 -20
  107. data/test/y_petri_test.rb +4 -5
  108. metadata +101 -26
  109. data/lib/y_petri/dependency_injection.rb +0 -45
  110. data/lib/y_petri/manipulator/petri_net_related_methods.rb +0 -74
  111. data/lib/y_petri/manipulator.rb +0 -20
  112. data/lib/y_petri/net/selections.rb +0 -209
  113. data/lib/y_petri/simulation/collections.rb +0 -460
  114. data/lib/y_petri/workspace/parametrized_subclassing.rb +0 -22
  115. data/lib/y_petri/workspace/petri_net_related_methods.rb +0 -88
  116. data/lib/y_petri/workspace.rb +0 -16
  117. data/test/timed_simulation_test.rb +0 -153
@@ -1,460 +0,0 @@
1
- #encoding: utf-8
2
-
3
- # Mixin that provides methods exposing place and transition collections to
4
- # YPetri::Simulation.
5
- #
6
- class YPetri::Simulation
7
- module Collections
8
- # Returns the simulation's places. Optional arguments / block make it return
9
- # a hash <tt>places => values</tt>, such as:
10
- #
11
- # places :marking
12
- # #=> { <Place:Foo> => 42, <Place:Bar> => 43, ... }
13
- #
14
- def places *aa, &b
15
- return @places.dup if aa.empty? && b.nil?
16
- zip_to_hash places, *aa, &b
17
- end
18
-
19
- # Returns the simulation's transitions. Optional arguments / block make it
20
- # return a hash <tt>places => values</tt>, such as:
21
- #
22
- # transitions :flux
23
- # #=> { <Transition:Baz> => 42, <Transition:Quux => 43, ... }
24
- #
25
- def transitions *aa, &b
26
- return @transitions.dup if aa.empty? && b.nil?
27
- zip_to_hash transitions, *aa, &b
28
- end
29
-
30
- # Like #places method, except that in the output, names are used instead of
31
- # place instances when possible.
32
- #
33
- def pp *aa, &b
34
- return places.map &:name if aa.empty? && b.nil?
35
- zip_to_hash( places.map { |p| p.name || p }, *aa, &b )
36
- end
37
-
38
- # Like #transitions method, except that in the output, names are used
39
- # instead of transition instances when possible.
40
- #
41
- def tt *aa, &b
42
- return transitions.map &:name if aa.empty? && b.nil?
43
- zip_to_hash( transitions.map { |t| t.name || t }, *aa, &b )
44
- end
45
-
46
- # Returns the simulation's free places, with same syntax options as #places
47
- # method.
48
- #
49
- def free_places *aa, &b
50
- return zip_to_hash free_places, *aa, &b unless aa.empty? && b.nil?
51
- kk = @initial_marking.keys
52
- places.select { |p| kk.include? p }
53
- end
54
-
55
- # Like #free_places, except that in the output, names are used instead of
56
- # place instances when possible.
57
- #
58
- def free_pp *aa, &b
59
- return free_places.map { |p| p.name || p } if aa.empty? && b.nil?
60
- zip_to_hash free_pp, *aa, &b
61
- end
62
-
63
- # Initial marking definitions for free places (as array).
64
- #
65
- def im
66
- free_places.map { |p| @initial_marking[p] }
67
- end
68
-
69
- # Marking array of all places as it appears at the beginning of a simulation.
70
- #
71
- def initial_marking
72
- raise # FIXME: "Initial marking" for all places (ie. incl. clamped ones).
73
- end
74
-
75
- # Initial marking of free places (as column vector).
76
- #
77
- def im_vector
78
- Matrix.column_vector im
79
- end
80
- alias iᴍ im_vector
81
-
82
- # Marking of all places at the beginning of a simulation (as column vector).
83
- #
84
- def initial_marking_vector
85
- Matrix.column_vector initial_marking
86
- end
87
-
88
- # Returns the simulation's clamped places, with same syntax options as #places
89
- # method.
90
- #
91
- def clamped_places *aa, &b
92
- return zip_to_hash clamped_places, *aa, &b unless aa.empty? && b.nil?
93
- kk = @marking_clamps.keys
94
- places.select { |p| kk.include? p }
95
- end
96
-
97
- # Like #clamped_places, except that in the output, names are used instead of
98
- # place instances whenever possible.
99
- #
100
- def clamped_pp *aa, &b
101
- return clamped_places.map { |p| p.name || p } if aa.empty? && b.nil?
102
- zip_to_hash clamped_pp, *aa, &b
103
- end
104
-
105
- # Place clamp definitions for clamped places (as array)
106
- #
107
- def marking_clamps
108
- clamped_places.map { |p| @marking_clamps[p] }
109
- end
110
- alias place_clamps marking_clamps
111
-
112
- # Marking of free places (as array).
113
- #
114
- def m
115
- m_vector.column_to_a
116
- end
117
-
118
- # Marking of free places (as hash of pairs <tt>{ name: marking }</tt>).
119
- #
120
- def pm
121
- free_pp :m
122
- end
123
- alias p_m pm
124
-
125
- # Marking of free places (as hash of pairs <tt>{ place: marking }</tt>.
126
- #
127
- def place_m
128
- free_places :m
129
- end
130
-
131
- # Marking of all places (as array).
132
- #
133
- def marking
134
- marking_vector ? marking_vector.column_to_a : nil
135
- end
136
-
137
- # Marking of all places (as hash of pairs <tt>{ name: marking }</tt>).
138
- #
139
- def p_marking
140
- pp :marking
141
- end
142
- alias pmarking p_marking
143
-
144
- # Marking of all places (as hash of pairs <tt>{ place: marking }</tt>.
145
- #
146
- def place_marking
147
- places :marking
148
- end
149
-
150
- # Marking of a specified place or a collection of places.
151
- #
152
- def marking_of places
153
- m = place_marking
154
- return places.map { |pl| m[ place( pl ) ] } if places.respond_to? :each
155
- m[ place( place_or_places ) ]
156
- end
157
- alias m_of marking_of
158
-
159
- # Marking of free places ( as column vector).
160
- #
161
- def m_vector
162
- F2A().t * @marking_vector
163
- end
164
- alias ᴍ m_vector
165
-
166
- # Marking of clamped places (as column vector).
167
- #
168
- def marking_vector_of_clamped_places
169
- C2A().t * @marking_vector
170
- end
171
- alias ᴍ_clamped marking_vector_of_clamped_places
172
-
173
- # Marking of clamped places (as array).
174
- #
175
- def marking_of_clamped_places
176
- marking_vector_of_clamped_places.column( 0 ).to_a
177
- end
178
- alias m_clamped marking_of_clamped_places
179
-
180
- # Returns a stoichiometry matrix for an arbitrary array of stoichiometric
181
- # transitions. The returned stoichiometry matrix has the number of columns
182
- # equal to the number of supplied stoichimetric transitions, and the number
183
- # of rows equal to the number of free places. When multiplied by a vector
184
- # corresponding to the transitions (such as flux vector), the resulting
185
- # column vector corresponds to the free places.
186
- #
187
- def S_for( stoichiometric_transitions )
188
- stoichiometric_transitions.map { |t| sparse_σ t }
189
- .reduce( Matrix.empty( free_places.size, 0 ), :join_right )
190
- end
191
-
192
- # Returns a stoichiometry matrix for an arbitrary array of stoichiometric
193
- # transitions. Behaves like +#S_for+ method, with the difference that the
194
- # rows correspond to _all_ places, not just free places.
195
- #
196
- def stoichiometry_matrix_for( stoichiometric_transitions )
197
- stoichiometric_transitions.map { |t| sparse_stoichiometry_vector t }
198
- .reduce( Matrix.empty( places.size, 0 ), :join_right )
199
- end
200
-
201
- # Stoichiometry matrix of this simulation. By calling this method, the
202
- # caller asserts, that all transitions in this simulation are SR transitions
203
- # (or error).
204
- #
205
- def S
206
- return S_SR() if s_transitions.empty? && r_transitions.empty?
207
- raise "The simulation contains also non-stoichiometric transitions! " +
208
- "Consider using #S_for_SR."
209
- end
210
-
211
- # ==== ts transitions
212
-
213
- # Returns the simulation's *ts* transitions, with syntax options like
214
- # #transitions method.
215
- #
216
- def ts_transitions *aa, &b
217
- return zip_to_hash ts_transitions, *aa, &b unless aa.empty? && b.nil?
218
- sift_from_net :ts_transitions
219
- end
220
-
221
- # Like #ts_transitions, except that in the output, names are used instead
222
- # of instances when possible.
223
- #
224
- def ts_tt *aa, &b
225
- return zip_to_hash ts_tt, *aa, &b unless aa.empty? && b.nil?
226
- ts_transitions.map { |t| t.name || t }
227
- end
228
-
229
- # Returns the simulation's *non-assignment* *ts* transtitions, with syntax
230
- # options like #transitions method. While *A* transitions can be regarded
231
- # as a special kind of *ts* transitions, it may often be useful to separate
232
- # them out from the collection of "ordinary" *ts* transtitions (*tsa*
233
- # transitions).
234
- #
235
- def tsa_transitions *aa, &b
236
- return zip_to_hash tsa_transitions, *aa, &b unless aa.empty? && b.nil?
237
- sift_from_net :tsa_transitions
238
- end
239
-
240
- # Like #tsa_transitions, except that in the output, names are used instead
241
- # of instances when possible.
242
- #
243
- def tsa_tt *aa, &b
244
- return zip_to_hash tsa_tt, *aa, &b unless aa.empty? && b.nil?
245
- tsa_transitions.map { |t| t.name || t }
246
- end
247
-
248
- # ==== tS transitions
249
-
250
- # Returns the simulation's *tS* transitions, with syntax options like
251
- # #transitions method.
252
- #
253
- def tS_transitions *aa, &b
254
- return zip_to_hash tS_transitions, *aa, &b unless aa.empty? && b.nil?
255
- sift_from_net :tS_transitions
256
- end
257
-
258
- # Like #tS_transitions, except that in the output, names are used instead
259
- # of instances when possible.
260
- #
261
- def tS_tt *aa, &b
262
- return zip_to_hash tS_tt, *aa, &b unless aa.empty? && b.nil?
263
- tS_transitions.map { |t| t.name || t }
264
- end
265
-
266
- # ==== Tsr transitions
267
-
268
- # Returns the simulation's *Tsr* transitions, with syntax options like
269
- # #transitions method.
270
- #
271
- def Tsr_transitions *aa, &b
272
- return zip_to_hash Tsr_transitions(), *aa, &b unless aa.empty? && b.nil?
273
- sift_from_net :Tsr_transitions
274
- end
275
-
276
- # Like #Tsr_transitions, except that in the output, names are used instead
277
- # of instances when possible.
278
- #
279
- def Tsr_tt *aa, &b
280
- return zip_to_hash Tsr_tt(), *aa, &b unless aa.empty? && b.nil?
281
- Tsr_transitions().map { |t| t.name || t }
282
- end
283
-
284
- # ==== TSr transitions
285
-
286
- # Returns the simulation's *TSr* transitions, with syntax options like
287
- # #transitions method.
288
- #
289
- def TSr_transitions *aa, &b
290
- return zip_to_hash TSr_transitions(), *aa, &b unless aa.empty? && b.nil?
291
- sift_from_net :TSr_transitions
292
- end
293
-
294
- # Like #TSr_transitions, except that in the output, names are used instead
295
- # of instances when possible.
296
- #
297
- def TSr_tt *aa, &b
298
- return zip_to_hash TSr_tt(), *aa, &b unless aa.empty? && b.nil?
299
- TSr_transitions().map { |t| t.name || t }
300
- end
301
-
302
- # ==== sR transitions
303
-
304
- # Returns the simulation's *sR* transitions, with syntax options like
305
- # #transitions method.
306
- #
307
- def sR_transitions *aa, &b
308
- return zip_to_hash sR_transitions(), *aa, &b unless aa.empty? && b.nil?
309
- sift_from_net :sR_transitions
310
- end
311
-
312
- # Like #sR_transitions, except that in the output, names are used instead
313
- # of instances when possible.
314
- #
315
- def sR_tt *aa, &b
316
- return zip_to_hash sR_tt(), *aa, &b unless aa.empty? && b.nil?
317
- sR_transitions.map { |t| t.name || t }
318
- end
319
-
320
- # ==== SR transitions
321
-
322
- # Returns the simulation's *SR* transitions, with syntax options like
323
- # #transitions method.
324
- #
325
- def SR_transitions *aa, &b
326
- return zip_to_hash SR_transitions(), *aa, &b unless aa.empty? && b.nil?
327
- sift_from_net :SR_transitions
328
- end
329
-
330
- # Like #SR_transitions, except that in the output, names are used instead
331
- # of instances when possible.
332
- #
333
- def SR_tt *aa, &b
334
- return zip_to_hash SR_tt(), *aa, &b unless aa.empty? && b.nil?
335
- SR_transitions().map { |t| t.name || t }
336
- end
337
-
338
- # ==== Assignment (A) transitions
339
-
340
- # Returns the simulation's *A* transitions, with syntax options like
341
- # #transitions method.
342
- #
343
- def A_transitions *aa, &b
344
- return zip_to_hash A_transitions(), *aa, &b unless aa.empty? && b.nil?
345
- sift_from_net :A_transitions
346
- end
347
- alias assignment_transitions A_transitions
348
-
349
- # Like #A_transitions, except that in the output, names are used instead
350
- # of instances when possible.
351
- #
352
- def A_tt *aa, &b
353
- return zip_to_hash A_tt(), *aa, &b unless aa.empty? && b.nil?
354
- A_transitions().map { |t| t.name || t }
355
- end
356
- alias assignment_tt A_tt
357
-
358
- # ==== Stoichiometric transitions of arbitrary type (S transitions)
359
-
360
- # Returns the simulation's *S* transitions, with syntax options like
361
- # #transitions method.
362
- #
363
- def S_transitions *aa, &b
364
- return zip_to_hash S_transitions(), *aa, &b unless aa.empty? && b.nil?
365
- sift_from_net :S_transitions
366
- end
367
-
368
- # Like #S_transitions, except that in the output, names are used instead
369
- # of instances when possible.
370
- #
371
- def S_tt *aa, &b
372
- return zip_to_hash S_tt(), *aa, &b unless aa.empty? && b.nil?
373
- S_transitions().map { |t| t.name || t }
374
- end
375
-
376
- # ==== Nonstoichiometric transitions of arbitrary type (s transitions)
377
-
378
- # Returns the simulation's *s* transitions, with syntax options like
379
- # #transitions method.
380
- #
381
- def s_transitions *aa, &b
382
- return zip_to_hash s_transitions, *aa, &b unless aa.empty? && b.nil?
383
- sift_from_net :s_transitions
384
- end
385
-
386
- # Like #s_transitions, except that in the output, names are used instead
387
- # of instances when possible.
388
- #
389
- def s_tt *aa, &b
390
- return zip_to_hash s_tt, *aa, &b unless aa.empty? && b.nil?
391
- s_transitions.map { |t| t.name || t }
392
- end
393
-
394
- # ==== Transitions with rate of arbitrary type (R transitions)
395
-
396
- # Returns the simulation's *R* transitions, with syntax options like
397
- # #transitions method.
398
- #
399
- def R_transitions *aa, &b
400
- return zip_to_hash R_transitions(), *aa, &b unless aa.empty? && b.nil?
401
- sift_from_net :R_transitions
402
- end
403
-
404
- # Like #R_transitions, except that in the output, names are used instead
405
- # of instances when possible.
406
- #
407
- def R_tt *aa, &b
408
- return zip_to_hash R_tt(), *aa, &b unless aa.empty? && b.nil?
409
- R_transitions().map { |t| t.name || t }
410
- end
411
-
412
- # ==== Rateless transitions of arbitrary type (r transitions)
413
-
414
- # Returns the simulation's *r* transitions, with syntax options like
415
- # #transitions method.
416
- #
417
- def r_transitions *aa, &b
418
- return zip_to_hash r_transitions, *aa, &b unless aa.empty? && b.nil?
419
- sift_from_net :r_transitions
420
- end
421
-
422
- # Like #r_transitions, except that transition names are used instead of
423
- # instances, whenever possible.
424
- #
425
- def r_tt *aa, &b
426
- return zip_to_hash r_tt, *aa, &b unless aa.empty? && b.nil?
427
- r_transitions.map { |t| t.name || t }
428
- end
429
-
430
- private
431
-
432
- # This helper method takes a collection, a variable number of other arguments
433
- # and an optional block, and returns a hash whose keys are the collection
434
- # members, and whose values are given by the supplied othe arguments and/or
435
- # block in the following way: If there is no additional argument, but a block
436
- # is supplied, this is applied to the collection. If there is exactly one
437
- # other argument, and it is also a collection, it is used as values.
438
- # Otherwise, these other arguments are treated as a message to be sent to
439
- # self (via #send), expecting it to return a collection to be used as hash
440
- # values. Optional block (which is always assumed to be unary) can be used
441
- # to additionally modify the second collection.
442
- #
443
- def zip_to_hash collection, *args, &block
444
- sz = args.size
445
- values = if sz == 0 then collection
446
- elsif sz == 1 && args[0].respond_to?( :each ) then args[0]
447
- else send *args end
448
- Hash[ collection.zip( block ? values.map( &block ) : values ) ]
449
- end
450
-
451
- # Chicken approach towards ensuring that transitions in question come in
452
- # the same order as in @transitions local variable. Takes a symbol as the
453
- # argument (:SR, :TSr, :sr etc.)
454
- #
455
- def sift_from_net type_of_transitions
456
- from_net = net.send type_of_transitions
457
- @transitions.select { |t| from_net.include? t }
458
- end
459
- end # module Collections
460
- end # class YPetri::Simulation
@@ -1,22 +0,0 @@
1
-
2
- module YPetri::Workspace::ParametrizedSubclassing
3
- def initialize
4
- # Parametrized subclasses of Place, Transition and Net.
5
- @Place = place_subclass = Class.new( YPetri::Place )
6
- @Transition = transition_subclass = Class.new YPetri::Transition
7
- @Net = net_subclass = Class.new YPetri::Net
8
-
9
- # Make them namespaces and inject dependencies:
10
- [ @Place, @Transition, @Net ].each do |klass|
11
- klass.namespace!
12
- klass.class_exec do # make'em work together
13
- define_method :Place do place_subclass end
14
- define_method :Transition do transition_subclass end
15
- define_method :Net do net_subclass end
16
- private :Place, :Transition, :Net # Redeclare private after redef???
17
- end
18
- end
19
-
20
- super # param. subclassing achieved, proceed ahead normally
21
- end # def initialize
22
- end # module YPetri::Workspace::ParametrizedSubclassing
@@ -1,88 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- # Workspace instance methods related to Petri net itsef (places, transitions,
4
- # net instances).
5
- #
6
- module YPetri::Workspace::PetriNetRelatedMethods
7
- # Readers for @Place, @Transition, @Net instance variables, which should
8
- # contain said classes, or their instance-specific subclasses.
9
-
10
- # Parametrized Place class.
11
- #
12
- attr_reader :Place
13
-
14
- # Parametrized Transition class.
15
- #
16
- attr_reader :Transition
17
-
18
- # Parametrized Net class.
19
- #
20
- attr_reader :Net
21
-
22
- # Instance initialization.
23
- #
24
- def initialize
25
- set_up_Top_net # Sets up :Top net encompassing all places and transitions.
26
- super
27
- end
28
-
29
- # Returns a place instance identified by the argument.
30
- #
31
- def place which; Place().instance which end
32
-
33
- # Returns a transition instance identified by the argument.
34
- #
35
- def transition which; Transition().instance which end
36
-
37
- # Returns a net instance identified by the argument.
38
- #
39
- def net which; Net().instance which end
40
-
41
- # Returns the name of a place identified by the argument.
42
- #
43
- def pl which; place( which ).name end
44
-
45
- # Returns the name of a transition identified by the argument.
46
- #
47
- def tr which; transition( which ).name end
48
-
49
- # Returns the name of a net identified by the argument.
50
- #
51
- def ne which; net( which ).name end
52
-
53
- # Place instances.
54
- #
55
- def places; Place().instances end
56
-
57
- # Transition instances.
58
- #
59
- def transitions; Transition().instances end
60
-
61
- # Net instances.
62
- #
63
- def nets; Net().instances end
64
-
65
- # Place names.
66
- #
67
- def pp; places.map &:name end
68
-
69
- # Transition names.
70
- #
71
- def tt; transitions.map &:name end
72
-
73
- # Net names.
74
- #
75
- def nn; nets.map &:name end
76
-
77
- private
78
-
79
- # Creates all-encompassing Net instance named :Top.
80
- #
81
- def set_up_Top_net
82
- Net().new name: :Top # all-encompassing :Top net
83
- # Hook new places to add themselves magically to the :Top net.
84
- Place().new_instance_closure { |new_inst| net( :Top ) << new_inst }
85
- # Hook new transitions to add themselves magically to the :Top net.
86
- Transition().new_instance_closure { |new_inst| net( :Top ) << new_inst }
87
- end
88
- end # module YPetri::Workspace::PetriNetRelatedMethods
@@ -1,16 +0,0 @@
1
- # Workspace holds places, transitions, nets and other assets needed to set up
2
- # and simulate Petri nets (settings, clamps, initial markings etc.). Workspace
3
- # provides basic, decent, vanilla methods to just do what is necessary. It is
4
- # up to YPetri::Manipulator to provide ergonomical DSL to the user.
5
- #
6
- class YPetri::Workspace
7
- include NameMagic
8
-
9
- require_relative 'workspace/petri_net_related_methods'
10
- require_relative 'workspace/parametrized_subclassing'
11
- require_relative 'workspace/simulation_related_methods'
12
-
13
- include self::PetriNetRelatedMethods
14
- prepend self::ParametrizedSubclassing
15
- include self::SimulationRelatedMethods
16
- end