y_petri 2.2.4 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,352 @@
1
+ # encoding: utf-8
2
+
3
+ # Workspace instance methods related to the Simulation aspect of YPetri
4
+ # (stored marking collections, clamp collections, inital marking collections,
5
+ # management of simulations...)
6
+ #
7
+ module YPetri::World::SimulationAspect
8
+ # Collections of clamps, initial marking vectors, and simulation settings.
9
+ #
10
+ attr_reader :clamp_collections,
11
+ :initial_marking_collections,
12
+ :simulation_settings_collections
13
+
14
+ # Instance initialization.
15
+ #
16
+ def initialize
17
+ @simulations = {} # { simulation => its settings }
18
+ @clamp_collections = { Base: {} } # { collection name => clamp hash }
19
+ @initial_marking_collections = { Base: {} } # { collection name => im hash }
20
+ @simulation_settings_collections = # { collection name => ss hash }
21
+ { Base: ( YPetri::Simulation::DEFAULT_SETTINGS.call
22
+ .update YPetri::Simulation::Timed::DEFAULT_SETTINGS.call ) }
23
+ super
24
+ end
25
+
26
+ # Hash of simulation instances and their settings.
27
+ #
28
+ def simulations
29
+ @simulations
30
+ end
31
+
32
+ # Clamp collection names.
33
+ #
34
+ def clamp_collection_names
35
+ @clamp_collections.keys
36
+ end
37
+ alias ncc clamp_collection_names
38
+
39
+ # Initial marking collection names.
40
+ #
41
+ def initial_marking_collection_names
42
+ @initial_marking_collections.keys
43
+ end
44
+ alias nimc initial_marking_collection_names
45
+
46
+ # Simulation settings collection names.
47
+ #
48
+ def simulation_settings_collection_names
49
+ @simulation_settings_collections.keys
50
+ end
51
+ alias nssc simulation_settings_collection_names
52
+
53
+ # Clamp collection identified by the argument.
54
+ #
55
+ def clamp_collection name=:Base
56
+ @clamp_collections[name]
57
+ end
58
+ alias cc clamp_collection
59
+
60
+ # Marking collection identified by the argument.
61
+ #
62
+ def initial_marking_collection name=:Base
63
+ @initial_marking_collections[name]
64
+ end
65
+ alias imc initial_marking_collection
66
+
67
+ # Simulation settings collection specified by the argument.
68
+ #
69
+ def simulation_settings_collection name=:Base
70
+ @simulation_settings_collections[name]
71
+ end
72
+ alias ssc simulation_settings_collection
73
+
74
+ # Creates a new clamp collection. If collection identifier is not given,
75
+ # resets :Base clamp collection to new values.
76
+ #
77
+ def set_clamp_collection( name=:Base, clamp_hash )
78
+ @clamp_collections[name] = clamp_hash
79
+ end
80
+ alias set_cc set_clamp_collection
81
+
82
+ # Creates a new initial marking collection. If collection identifier is not
83
+ # given, resets :Base initial marking collection to new values.
84
+ #
85
+ def set_initial_marking_collection( name=:Base, initial_marking_hash )
86
+ @initial_marking_collections[name] = initial_marking_hash
87
+ end
88
+ alias set_imc set_initial_marking_collection
89
+
90
+ # Creates a new simulation settings collection. If collection identifier is
91
+ # not given, resets :Base simulation settings collection to new values.
92
+ #
93
+ def set_simulation_settings_collection( name=:Base, sim_set_hash )
94
+ @simulation_settings_collections[name] = sim_set_hash
95
+ end
96
+ alias set_ssc set_simulation_settings_collection
97
+
98
+ # Presents a simulation specified by the argument, which must be a hash with
99
+ # four items: :net, :clamp_collection, :inital_marking_collection and
100
+ # :simulation_settings_collection.
101
+ #
102
+ def simulation settings={}
103
+ key = case settings
104
+ when ~:may_have then # it is a hash or equivalent
105
+ settings.may_have :net
106
+ settings.may_have :cc, syn!: :clamp_collection
107
+ settings.may_have :imc, syn!: :initial_marking_collection
108
+ settings.may_have :ssc, syn!: :simulation_settings_collection
109
+ { net: net( settings[:net] || self.Net::Top ), # the key
110
+ cc: settings[:cc] || :Base,
111
+ imc: settings[:imc] || :Base,
112
+ ssc: settings[:ssc] || :Base }
113
+ else # use the unprocessed argument itself as the key
114
+ settings
115
+ end
116
+ @simulations[ key ]
117
+ end
118
+
119
+ # Makes a new timed simulation. Named arguments for this method are the same
120
+ # as for TimedSimulation#new, but in addition, :name can be supplied.
121
+ #
122
+ # To create a simulation, simulation settings collection, initial marking
123
+ # collection, and clamp collection have to be specified. A <em>place clamp</em>,
124
+ # is a fixed value, at which the marking is held. Similarly, <em>initial
125
+ # marking</em> is the marking, which a free place receives at the beginning.
126
+ # Free places are those, that are not clamped. After initialization, marking
127
+ # of free places is allowed to change as the transition fire.
128
+ #
129
+ # For example, having places :P1..:P5, clamped :P1, :P2 can be written as eg.:
130
+ #
131
+ # * clamps = { P1: 4, P2: 5 }
132
+ #
133
+ # Places :P3, :P4, :P5 are <em>free</em>. Their initial marking has to be
134
+ # specified, which can be written as eg.:
135
+ #
136
+ # * initial_markings = { P3: 1, P4: 2, P5: 3 }
137
+ #
138
+ # As for simulation settings, their exact nature depends on the simulation
139
+ # method. For default Euler method, there are 3 important parameters:
140
+ # - <em>step_size</em>,
141
+ # - <em>sampling_period</em>,
142
+ # - <em>target_time</em>
143
+ #
144
+ # For example, default simulation settings are:
145
+ #
146
+ # * default_ss = { step_size: 0.1, sampling_period: 5, target_time: 60 }
147
+ #
148
+ def new_simulation( net: Net()::Top, **nn )
149
+ net_inst = net( net )
150
+ nn.may_have :cc, syn!: :clamp_collection
151
+ nn.may_have :imc, syn!: :initial_marking_collection
152
+ nn.may_have :ssc, syn!: :simulation_settings_collection
153
+ cc_id = nn.delete( :cc ) || :Base
154
+ imc_id = nn.delete( :imc ) || :Base
155
+ ssc_id = nn.delete( :ssc ) || :Base
156
+ # Construct the simulation key:
157
+ key = if nn.has? :name, syn!: :ɴ then # explicit key (name)
158
+ nn[:name]
159
+ else # constructed key
160
+ {}.merge( net: net_inst,
161
+ cc: cc_id,
162
+ imc: imc_id,
163
+ ssc: ssc_id )
164
+ .merge( nn )
165
+ end
166
+ # Let's clarify what we got so far.
167
+ sim_settings = ssc( ssc_id )
168
+ mc_hash = cc( cc_id )
169
+ im_hash = imc( imc_id )
170
+ # Create and return the simulation
171
+ sim = net_inst.simulation **sim_settings.merge( initial_marking: im_hash,
172
+ marking_clamps: mc_hash
173
+ ).merge( nn )
174
+ @simulations[ key ] = sim
175
+ end
176
+ end # module YPetri::World::SimulationAspect
177
+ # encoding: utf-8
178
+
179
+ # Workspace instance methods related to the Simulation aspect of YPetri
180
+ # (stored marking collections, clamp collections, inital marking collections,
181
+ # management of simulations...)
182
+ #
183
+ module YPetri::World::SimulationAspect
184
+ # Collections of clamps, initial marking vectors, and simulation settings.
185
+ #
186
+ attr_reader :clamp_collections,
187
+ :initial_marking_collections,
188
+ :simulation_settings_collections
189
+
190
+ # Instance initialization.
191
+ #
192
+ def initialize
193
+ @simulations = {} # { simulation => its settings }
194
+ @clamp_collections = { Base: {} } # { collection name => clamp hash }
195
+ @initial_marking_collections = { Base: {} } # { collection name => im hash }
196
+ @simulation_settings_collections = # { collection name => ss hash }
197
+ { Base: ( YPetri::Simulation::DEFAULT_SETTINGS.call
198
+ .update YPetri::Simulation::Timed::DEFAULT_SETTINGS.call ) }
199
+ super
200
+ end
201
+
202
+ # Hash of simulation instances and their settings.
203
+ #
204
+ def simulations
205
+ @simulations
206
+ end
207
+
208
+ # Clamp collection names.
209
+ #
210
+ def clamp_collection_names
211
+ @clamp_collections.keys
212
+ end
213
+ alias ncc clamp_collection_names
214
+
215
+ # Initial marking collection names.
216
+ #
217
+ def initial_marking_collection_names
218
+ @initial_marking_collections.keys
219
+ end
220
+ alias nimc initial_marking_collection_names
221
+
222
+ # Simulation settings collection names.
223
+ #
224
+ def simulation_settings_collection_names
225
+ @simulation_settings_collections.keys
226
+ end
227
+ alias nssc simulation_settings_collection_names
228
+
229
+ # Clamp collection identified by the argument.
230
+ #
231
+ def clamp_collection name=:Base
232
+ @clamp_collections[name]
233
+ end
234
+ alias cc clamp_collection
235
+
236
+ # Marking collection identified by the argument.
237
+ #
238
+ def initial_marking_collection name=:Base
239
+ @initial_marking_collections[name]
240
+ end
241
+ alias imc initial_marking_collection
242
+
243
+ # Simulation settings collection specified by the argument.
244
+ #
245
+ def simulation_settings_collection name=:Base
246
+ @simulation_settings_collections[name]
247
+ end
248
+ alias ssc simulation_settings_collection
249
+
250
+ # Creates a new clamp collection. If collection identifier is not given,
251
+ # resets :Base clamp collection to new values.
252
+ #
253
+ def set_clamp_collection( name=:Base, clamp_hash )
254
+ @clamp_collections[name] = clamp_hash
255
+ end
256
+ alias set_cc set_clamp_collection
257
+
258
+ # Creates a new initial marking collection. If collection identifier is not
259
+ # given, resets :Base initial marking collection to new values.
260
+ #
261
+ def set_initial_marking_collection( name=:Base, initial_marking_hash )
262
+ @initial_marking_collections[name] = initial_marking_hash
263
+ end
264
+ alias set_imc set_initial_marking_collection
265
+
266
+ # Creates a new simulation settings collection. If collection identifier is
267
+ # not given, resets :Base simulation settings collection to new values.
268
+ #
269
+ def set_simulation_settings_collection( name=:Base, sim_set_hash )
270
+ @simulation_settings_collections[name] = sim_set_hash
271
+ end
272
+ alias set_ssc set_simulation_settings_collection
273
+
274
+ # Presents a simulation specified by the argument, which must be a hash with
275
+ # four items: :net, :clamp_collection, :inital_marking_collection and
276
+ # :simulation_settings_collection.
277
+ #
278
+ def simulation settings={}
279
+ key = case settings
280
+ when ~:may_have then # it is a hash or equivalent
281
+ settings.may_have :net
282
+ settings.may_have :cc, syn!: :clamp_collection
283
+ settings.may_have :imc, syn!: :initial_marking_collection
284
+ settings.may_have :ssc, syn!: :simulation_settings_collection
285
+ { net: net( settings[:net] || self.Net::Top ), # the key
286
+ cc: settings[:cc] || :Base,
287
+ imc: settings[:imc] || :Base,
288
+ ssc: settings[:ssc] || :Base }
289
+ else # use the unprocessed argument itself as the key
290
+ settings
291
+ end
292
+ @simulations[ key ]
293
+ end
294
+
295
+ # Makes a new timed simulation. Named arguments for this method are the same
296
+ # as for TimedSimulation#new, but in addition, :name can be supplied.
297
+ #
298
+ # To create a simulation, simulation settings collection, initial marking
299
+ # collection, and clamp collection have to be specified. A <em>place clamp</em>,
300
+ # is a fixed value, at which the marking is held. Similarly, <em>initial
301
+ # marking</em> is the marking, which a free place receives at the beginning.
302
+ # Free places are those, that are not clamped. After initialization, marking
303
+ # of free places is allowed to change as the transition fire.
304
+ #
305
+ # For example, having places :P1..:P5, clamped :P1, :P2 can be written as eg.:
306
+ #
307
+ # * clamps = { P1: 4, P2: 5 }
308
+ #
309
+ # Places :P3, :P4, :P5 are <em>free</em>. Their initial marking has to be
310
+ # specified, which can be written as eg.:
311
+ #
312
+ # * initial_markings = { P3: 1, P4: 2, P5: 3 }
313
+ #
314
+ # As for simulation settings, their exact nature depends on the simulation
315
+ # method. For default Euler method, there are 3 important parameters:
316
+ # - <em>step_size</em>,
317
+ # - <em>sampling_period</em>,
318
+ # - <em>target_time</em>
319
+ #
320
+ # For example, default simulation settings are:
321
+ #
322
+ # * default_ss = { step_size: 0.1, sampling_period: 5, target_time: 60 }
323
+ #
324
+ def new_simulation( net: Net()::Top, **nn )
325
+ net_inst = net( net )
326
+ nn.may_have :cc, syn!: :clamp_collection
327
+ nn.may_have :imc, syn!: :initial_marking_collection
328
+ nn.may_have :ssc, syn!: :simulation_settings_collection
329
+ cc_id = nn.delete( :cc ) || :Base
330
+ imc_id = nn.delete( :imc ) || :Base
331
+ ssc_id = nn.delete( :ssc ) || :Base
332
+ # Construct the simulation key:
333
+ key = if nn.has? :name, syn!: :ɴ then # explicit key (name)
334
+ nn[:name]
335
+ else # constructed key
336
+ {}.merge( net: net_inst,
337
+ cc: cc_id,
338
+ imc: imc_id,
339
+ ssc: ssc_id )
340
+ .merge( nn )
341
+ end
342
+ # Let's clarify what we got so far.
343
+ sim_settings = ssc( ssc_id )
344
+ mc_hash = cc( cc_id )
345
+ im_hash = imc( imc_id )
346
+ # Create and return the simulation
347
+ sim = net_inst.simulation **sim_settings.merge( initial_marking: im_hash,
348
+ marking_clamps: mc_hash
349
+ ).merge( nn )
350
+ @simulations[ key ] = sim
351
+ end
352
+ end # module YPetri::World::SimulationAspect
data/lib/y_petri/world.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require_relative 'world/dependency'
4
- require_relative 'world/petri_net_related'
5
- require_relative 'world/simulation_related'
4
+ require_relative 'world/petri_net_aspect'
5
+ require_relative 'world/simulation_aspect'
6
6
 
7
7
  # As the name suggests, represents the world. Holds places, transitions, nets
8
8
  # and other assets needed to set up and simulate Petri nets (settings, clamps,
@@ -11,8 +11,8 @@ require_relative 'world/simulation_related'
11
11
  #
12
12
  class YPetri::World
13
13
  ★ NameMagic # ★ means include
14
- PetriNetRelated
15
- SimulationRelated
14
+ PetriNetAspect
15
+ SimulationAspect
16
16
 
17
17
  def initialize
18
18
  # Parametrize the Place / Transition / Net classes.
data/lib/y_petri.rb CHANGED
@@ -35,7 +35,7 @@ require_relative 'y_petri/core'
35
35
  require_relative 'y_petri/agent'
36
36
  require_relative 'y_petri/dsl'
37
37
 
38
- # YPetri represents Petri net (PN) formalims.
38
+ # YPetri represents Petri net (PN) formalisms.
39
39
  #
40
40
  # A PN consists of places and transitions. There are also arcs, "arrows"
41
41
  # connecting places and transitions, but these are not considered first class
data/test/agent_test.rb CHANGED
@@ -100,7 +100,8 @@ describe YPetri::Agent do
100
100
  rec.marking.plot
101
101
  rec.flux.plot
102
102
  rec.gradient.plot
103
- rec.delta( Δt: 1 ).plot
103
+ rec.delta_timed( Δt: 1 ).plot
104
+ rec.delta_timeless( Δt: 1 ).plot
104
105
  @m.plot_marking
105
106
  @m.plot_flux
106
107
  @m.plot_gradient
@@ -1,5 +1,8 @@
1
1
  #encoding: utf-8
2
2
 
3
+ # A working demonstration of the simulation functionality, but
4
+ # the resulting curve looks weird (too straight), look into it.
5
+
3
6
  require 'y_petri'
4
7
  include YPetri
5
8
 
@@ -161,4 +164,4 @@ Transition name: :TMPK_DeoxyTMP_DeoxyTDP,
161
164
 
162
165
  # execution
163
166
  run!
164
- plot_recording
167
+ recording.plot
@@ -1,5 +1,10 @@
1
1
  #encoding: utf-8
2
2
 
3
+ # This file demonstrates execution with values of SY::Magnitude type
4
+ # (ie. values with assigned physical units). It works, but the execution
5
+ # is slow and the recording is not fully adapted to the use of physical
6
+ # units yet.
7
+
3
8
  require 'y_petri'
4
9
  include YPetri
5
10
  require 'sy'
@@ -1,5 +1,7 @@
1
1
  #encoding: utf-8
2
2
 
3
+ # Unfinished demonstration of TTP pathway simulation, search for FIXME.
4
+
3
5
  require 'y_petri'
4
6
  include YPetri
5
7
  require 'sy'
@@ -46,10 +48,11 @@ DeoxyUMP = Place m!: 2.70 # Traut1994pcp
46
48
  DeoxyUDP = Place m!: 0.5 # Traut1994pcp
47
49
  DeoxyUTP = Place m!: 0.7 # Traut1994pcp
48
50
 
49
- DeoxyThymidine = Place m!: 0.5 # Traut1994pcp
51
+ Thymidine = Place m!: 0.5 # Traut1994pcp
50
52
  DeoxyTMP = Place m!: 0.0 # in situ
51
53
  DeoxyTDP = Place m!: 2.4 # Traut1994pcp
52
54
  DeoxyTTP = Place m!: 17.0 # Traut1994pcp
55
+ DeoxyT23P = Place m!: 2.4 + 17.0
53
56
 
54
57
  # === Empirical places (in arbitrary units)
55
58
 
@@ -75,19 +78,17 @@ TK1tetra = Place m!: 0 # TK1 in the tetramer form (phosphoryla
75
78
 
76
79
  # Assignment transition keeping TK1_di level based on total TK1 monomer
77
80
  Transition name: :TK1_di_ϝ,
78
- assignment: true,
79
81
  domain: TK1,
80
82
  codomain: TK1di,
81
- action: lambda { |monomer| # solution of a quadratic equation for dimer / tetramer balance
83
+ assignment: lambda { |monomer| # solution of a quadratic equation for dimer / tetramer balance
82
84
  TK1_4mer_Kd / 4 * ( ( 1 + 4 / TK1_4mer_Kd * monomer ) ** 0.5 - 1 )
83
85
  }
84
86
 
85
87
  # Assignment transition keeping TK1_tetra level based on total TK1 tetramer
86
88
  Transition name: :TK1_tetra_ϝ,
87
- assignment: true,
88
89
  domain: [ TK1, TK1di ],
89
90
  codomain: TK1tetra,
90
- action: lambda { |monomer, dimer| # based on equation monomer = dimer * 2 + tetramer * 4
91
+ assignment: lambda { |monomer, dimer| # based on equation monomer = dimer * 2 + tetramer * 4
91
92
  monomer / 4 - dimer / 2
92
93
  }
93
94
 
@@ -1,5 +1,7 @@
1
1
  #encoding: utf-8
2
2
 
3
+ # A minimalistic demonstration of the simulation capability.
4
+
3
5
  require 'y_petri'
4
6
  include YPetri
5
7
 
@@ -8,7 +8,8 @@ require 'mathn'
8
8
  set_step 10
9
9
  set_target_time 600
10
10
  set_sampling 10
11
- set_simulation_method :Euler_with_timeless_transitions_firing_after_each_step
11
+ # Euler with timeless transitions firing after each step:
12
+ set_simulation_method :PseudoEuler
12
13
 
13
14
  A = Place m!: 1
14
15
  B = Place m!: 10
@@ -16,13 +17,12 @@ C = Place m!: 0
16
17
 
17
18
  Transition name: :B_disappearing,
18
19
  s: { B: -1 },
19
- action: lambda { |m| m >= 1 ? 1 : 0 }
20
+ action: -> m { m >= 1 ? 1 : 0 }
20
21
 
21
22
  Transition name: :C_held_at_half_B,
22
- assignment: true,
23
23
  domain: :B,
24
24
  codomain: :C,
25
- action: lambda { |x| x / 2 }
25
+ assignment: -> x { x / 2 }
26
26
 
27
27
  run!
28
28
  plot_recording