y_nelson 2.0.6 → 2.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +675 -22
- data/README.md +3 -3
- data/Ruby_for_YNelson_Users_in_20_minutes.lyx +2254 -0
- data/Ruby_for_YNelson_Users_in_20_minutes.pdf +0 -0
- data/YNelson_FPN_&_ZZ_domain_model_hands_on_in_color.pdf +0 -0
- data/YPetri_FPN_domain_model_hands_on_in_color.lyx +2766 -0
- data/lib/y_nelson/dsl.rb +1 -1
- data/lib/y_nelson/version.rb +1 -1
- data/lib/y_nelson.rb +2 -0
- data/test/y_nelson_test.rb +1 -3
- data/y_nelson.gemspec +1 -1
- metadata +7 -4
- data/zz.png +0 -0
@@ -0,0 +1,2766 @@
|
|
1
|
+
#LyX 2.0 created this file. For more info see http://www.lyx.org/
|
2
|
+
\lyxformat 413
|
3
|
+
\begin_document
|
4
|
+
\begin_header
|
5
|
+
\textclass article
|
6
|
+
\use_default_options false
|
7
|
+
\maintain_unincluded_children false
|
8
|
+
\language english
|
9
|
+
\language_package default
|
10
|
+
\inputencoding auto
|
11
|
+
\fontencoding global
|
12
|
+
\font_roman default
|
13
|
+
\font_sans default
|
14
|
+
\font_typewriter default
|
15
|
+
\font_default_family default
|
16
|
+
\use_non_tex_fonts false
|
17
|
+
\font_sc false
|
18
|
+
\font_osf false
|
19
|
+
\font_sf_scale 100
|
20
|
+
\font_tt_scale 100
|
21
|
+
|
22
|
+
\graphics default
|
23
|
+
\default_output_format default
|
24
|
+
\output_sync 0
|
25
|
+
\bibtex_command default
|
26
|
+
\index_command default
|
27
|
+
\paperfontsize default
|
28
|
+
\spacing single
|
29
|
+
\use_hyperref false
|
30
|
+
\papersize default
|
31
|
+
\use_geometry true
|
32
|
+
\use_amsmath 1
|
33
|
+
\use_esint 1
|
34
|
+
\use_mhchem 1
|
35
|
+
\use_mathdots 1
|
36
|
+
\cite_engine natbib_authoryear
|
37
|
+
\use_bibtopic false
|
38
|
+
\use_indices false
|
39
|
+
\paperorientation portrait
|
40
|
+
\suppress_date false
|
41
|
+
\use_refstyle 0
|
42
|
+
\index Index
|
43
|
+
\shortcut idx
|
44
|
+
\color #008000
|
45
|
+
\end_index
|
46
|
+
\leftmargin 2.2cm
|
47
|
+
\topmargin 3cm
|
48
|
+
\rightmargin 2.2cm
|
49
|
+
\bottommargin 3cm
|
50
|
+
\secnumdepth 3
|
51
|
+
\tocdepth 3
|
52
|
+
\paragraph_separation indent
|
53
|
+
\paragraph_indentation default
|
54
|
+
\quotes_language english
|
55
|
+
\papercolumns 1
|
56
|
+
\papersides 1
|
57
|
+
\paperpagestyle default
|
58
|
+
\tracking_changes false
|
59
|
+
\output_changes false
|
60
|
+
\html_math_output 0
|
61
|
+
\html_css_as_file 0
|
62
|
+
\html_be_strict false
|
63
|
+
\end_header
|
64
|
+
|
65
|
+
\begin_body
|
66
|
+
|
67
|
+
\begin_layout Title
|
68
|
+
Hands-on Guide to YPetri
|
69
|
+
\end_layout
|
70
|
+
|
71
|
+
\begin_layout Part*
|
72
|
+
Introduction
|
73
|
+
\end_layout
|
74
|
+
|
75
|
+
\begin_layout Standard
|
76
|
+
This document is a hands-on guide to
|
77
|
+
\family typewriter
|
78
|
+
\color blue
|
79
|
+
YPetri
|
80
|
+
\family default
|
81
|
+
\color inherit
|
82
|
+
,
|
83
|
+
\emph on
|
84
|
+
\color green
|
85
|
+
Petri nets
|
86
|
+
\emph default
|
87
|
+
\color inherit
|
88
|
+
and
|
89
|
+
\color red
|
90
|
+
Ruby
|
91
|
+
\color inherit
|
92
|
+
.
|
93
|
+
It is not assumed that the reader is familiar with any of these, though
|
94
|
+
such familiarity would be an advantage.
|
95
|
+
If you follow this guide closely, you will receive a concise and efficient
|
96
|
+
introduction to each of these three.
|
97
|
+
Newly introduced
|
98
|
+
\color red
|
99
|
+
Ruby keywords and terms
|
100
|
+
\color inherit
|
101
|
+
are highlighted in red,
|
102
|
+
\color green
|
103
|
+
Petri net terms
|
104
|
+
\color inherit
|
105
|
+
in green, and
|
106
|
+
\color blue
|
107
|
+
YPetri keywords and terms
|
108
|
+
\color inherit
|
109
|
+
in blue throughout this document.
|
110
|
+
\end_layout
|
111
|
+
|
112
|
+
\begin_layout Standard
|
113
|
+
|
114
|
+
\family typewriter
|
115
|
+
\color blue
|
116
|
+
YPetri
|
117
|
+
\family default
|
118
|
+
\color inherit
|
119
|
+
is a domain model and a simulator of
|
120
|
+
\emph on
|
121
|
+
\color green
|
122
|
+
functional
|
123
|
+
\emph default
|
124
|
+
|
125
|
+
\emph on
|
126
|
+
Petri nets
|
127
|
+
\emph default
|
128
|
+
\color inherit
|
129
|
+
similar, but not identical with
|
130
|
+
\emph on
|
131
|
+
\color green
|
132
|
+
hybrid functional Petri nets
|
133
|
+
\emph default
|
134
|
+
(HFPNs)
|
135
|
+
\color inherit
|
136
|
+
introduced by
|
137
|
+
\begin_inset CommandInset citation
|
138
|
+
LatexCommand citet
|
139
|
+
key "Matsuno2011brs"
|
140
|
+
|
141
|
+
\end_inset
|
142
|
+
|
143
|
+
.
|
144
|
+
For a recent review of the various flavors of Petri nets, see eg.
|
145
|
+
|
146
|
+
\begin_inset CommandInset citation
|
147
|
+
LatexCommand citet
|
148
|
+
key "Bos2008mbs"
|
149
|
+
|
150
|
+
\end_inset
|
151
|
+
|
152
|
+
.
|
153
|
+
|
154
|
+
\family typewriter
|
155
|
+
YPetri
|
156
|
+
\family default
|
157
|
+
is implemented in
|
158
|
+
\emph on
|
159
|
+
\color red
|
160
|
+
Ruby programming language
|
161
|
+
\emph default
|
162
|
+
\color inherit
|
163
|
+
.
|
164
|
+
It will be publicly available as
|
165
|
+
\emph on
|
166
|
+
\color blue
|
167
|
+
y_petri
|
168
|
+
\emph default
|
169
|
+
\color inherit
|
170
|
+
gem.
|
171
|
+
|
172
|
+
\family typewriter
|
173
|
+
YPetri
|
174
|
+
\family default
|
175
|
+
is the first in the series of Ruby gems (
|
176
|
+
\family typewriter
|
177
|
+
YPetri
|
178
|
+
\family default
|
179
|
+
,
|
180
|
+
\family typewriter
|
181
|
+
\color blue
|
182
|
+
YCell
|
183
|
+
\family default
|
184
|
+
\color inherit
|
185
|
+
,
|
186
|
+
\family typewriter
|
187
|
+
\color blue
|
188
|
+
YChem
|
189
|
+
\family default
|
190
|
+
\color inherit
|
191
|
+
, metrology library
|
192
|
+
\family typewriter
|
193
|
+
\color blue
|
194
|
+
SY
|
195
|
+
\family default
|
196
|
+
\color inherit
|
197
|
+
) intended to bring ergonomy to biochemical modeling.
|
198
|
+
Note that
|
199
|
+
\family typewriter
|
200
|
+
YPetri
|
201
|
+
\family default
|
202
|
+
does not depend on these, though it can be used together with
|
203
|
+
\family typewriter
|
204
|
+
SY
|
205
|
+
\family default
|
206
|
+
if desired.
|
207
|
+
Also,
|
208
|
+
\family typewriter
|
209
|
+
YPetri
|
210
|
+
\family default
|
211
|
+
is a general purpose simulator not limited to biochemistry.
|
212
|
+
\end_layout
|
213
|
+
|
214
|
+
\begin_layout Standard
|
215
|
+
|
216
|
+
\family typewriter
|
217
|
+
YPetri
|
218
|
+
\family default
|
219
|
+
provides a
|
220
|
+
\emph on
|
221
|
+
\color red
|
222
|
+
domain-specific language
|
223
|
+
\emph default
|
224
|
+
(DSL)
|
225
|
+
\color inherit
|
226
|
+
, which you can access eg.
|
227
|
+
from
|
228
|
+
\color red
|
229
|
+
inferior Ruby interpreter (
|
230
|
+
\emph on
|
231
|
+
irb
|
232
|
+
\emph default
|
233
|
+
)
|
234
|
+
\color inherit
|
235
|
+
.
|
236
|
+
DSLs can be thought of as APIs with user-friendly syntax.
|
237
|
+
As a believer in robot equality, I dislike the distinction between API
|
238
|
+
and UI (user interface), and prefer common textual command interface (CI)
|
239
|
+
for humanoid as well as cybernetic users.
|
240
|
+
\end_layout
|
241
|
+
|
242
|
+
\begin_layout Standard
|
243
|
+
And why bother learning Ruby syntax and
|
244
|
+
\family typewriter
|
245
|
+
YPetri
|
246
|
+
\family default
|
247
|
+
? Half-jokingly,
|
248
|
+
\family typewriter
|
249
|
+
YPetri
|
250
|
+
\family default
|
251
|
+
is
|
252
|
+
\emph on
|
253
|
+
The Simplest Way To Work With Complicated Petri Nets
|
254
|
+
\emph default
|
255
|
+
™.
|
256
|
+
Petri net software at higher development stage, or written for a different
|
257
|
+
purpose than
|
258
|
+
\family typewriter
|
259
|
+
YPetri
|
260
|
+
\family default
|
261
|
+
, does exist.
|
262
|
+
But none of the programs written for the same purpose as
|
263
|
+
\family typewriter
|
264
|
+
YPetri
|
265
|
+
\family default
|
266
|
+
can avoid taking the user through the same learning process as
|
267
|
+
\family typewriter
|
268
|
+
YPetri
|
269
|
+
\family default
|
270
|
+
does.
|
271
|
+
There are programs, that make handling of very simple Petri nets seem easier
|
272
|
+
than learning
|
273
|
+
\family typewriter
|
274
|
+
YPetri
|
275
|
+
\family default
|
276
|
+
, but this ease is skin-deep, and you will realize it once your models get
|
277
|
+
less simple.
|
278
|
+
And if you are serious about modelling, you can bet they will.
|
279
|
+
\end_layout
|
280
|
+
|
281
|
+
\begin_layout Part*
|
282
|
+
Using This Guide, or
|
283
|
+
\begin_inset Quotes eld
|
284
|
+
\end_inset
|
285
|
+
|
286
|
+
The Hard Way Is Easier
|
287
|
+
\begin_inset Quotes erd
|
288
|
+
\end_inset
|
289
|
+
|
290
|
+
|
291
|
+
\end_layout
|
292
|
+
|
293
|
+
\begin_layout Standard
|
294
|
+
The phrase above is borrowed from the textbook by Zed Shaw named
|
295
|
+
\begin_inset Quotes erd
|
296
|
+
\end_inset
|
297
|
+
|
298
|
+
|
299
|
+
\emph on
|
300
|
+
Learn Ruby the Hard Way
|
301
|
+
\emph default
|
302
|
+
|
303
|
+
\begin_inset Quotes eld
|
304
|
+
\end_inset
|
305
|
+
|
306
|
+
.
|
307
|
+
Apart from being a great shark-jumper, Zed is a great teacher familiar
|
308
|
+
with many programming languages, and I will borrow his teaching method
|
309
|
+
here.
|
310
|
+
Citing Zed,
|
311
|
+
\begin_inset Quotes eld
|
312
|
+
\end_inset
|
313
|
+
|
314
|
+
The title says it's the hard way...
|
315
|
+
but actually it's not.
|
316
|
+
\begin_inset Quotes erd
|
317
|
+
\end_inset
|
318
|
+
|
319
|
+
It's only
|
320
|
+
\begin_inset Quotes eld
|
321
|
+
\end_inset
|
322
|
+
|
323
|
+
hard
|
324
|
+
\begin_inset Quotes erd
|
325
|
+
\end_inset
|
326
|
+
|
327
|
+
because of the way people
|
328
|
+
\emph on
|
329
|
+
used
|
330
|
+
\emph default
|
331
|
+
to teach things.
|
332
|
+
|
333
|
+
\family typewriter
|
334
|
+
YPetri
|
335
|
+
\family default
|
336
|
+
is a language.
|
337
|
+
To learn it and see its usefulness, you will still need to do the incredibly
|
338
|
+
simple things that all language learners do:
|
339
|
+
\end_layout
|
340
|
+
|
341
|
+
\begin_layout Enumerate
|
342
|
+
Go through each example.
|
343
|
+
\end_layout
|
344
|
+
|
345
|
+
\begin_layout Enumerate
|
346
|
+
Type each sample code exactly.
|
347
|
+
\end_layout
|
348
|
+
|
349
|
+
\begin_layout Enumerate
|
350
|
+
Make it run.
|
351
|
+
\end_layout
|
352
|
+
|
353
|
+
\begin_layout Standard
|
354
|
+
\noindent
|
355
|
+
That's it.
|
356
|
+
This might feel
|
357
|
+
\emph on
|
358
|
+
very
|
359
|
+
\emph default
|
360
|
+
difficult at first, but stick with it.
|
361
|
+
It seems stupidly obvious, but, if you have a problem installing
|
362
|
+
\family typewriter
|
363
|
+
YPetri
|
364
|
+
\family default
|
365
|
+
, running
|
366
|
+
\emph on
|
367
|
+
irb
|
368
|
+
\emph default
|
369
|
+
and typing, you will have a problem learning.
|
370
|
+
If you go through this document without actually doing the exercises, you
|
371
|
+
might as well just not even read it.
|
372
|
+
Do not skip and do not skim.
|
373
|
+
By typing each example
|
374
|
+
\emph on
|
375
|
+
exactly
|
376
|
+
\emph default
|
377
|
+
, you will be training your brain to focus on the details of what you are
|
378
|
+
doing, as you are doing it.
|
379
|
+
While you do these examples, typing each one in, you will be making mistakes.
|
380
|
+
It's inevitable; humans do make mistakes.
|
381
|
+
By doing so, you will train yourself to notice mistakes and other problems.
|
382
|
+
Do not copy-paste.
|
383
|
+
Type each code sample in, manually.
|
384
|
+
The point is to train your hands, your brain, and your mind in how to read,
|
385
|
+
write and see Ruby and
|
386
|
+
\family typewriter
|
387
|
+
YPetri
|
388
|
+
\family default
|
389
|
+
code.
|
390
|
+
If you skip, skim and copy-paste, you are cheating yourself out of the
|
391
|
+
effectiveness of this guide.
|
392
|
+
\end_layout
|
393
|
+
|
394
|
+
\begin_layout Part*
|
395
|
+
Prerequisites
|
396
|
+
\end_layout
|
397
|
+
|
398
|
+
\begin_layout Standard
|
399
|
+
|
400
|
+
\family typewriter
|
401
|
+
YPetri
|
402
|
+
\family default
|
403
|
+
is currently in alpha stage and its installation is not covered in this
|
404
|
+
document.
|
405
|
+
As a prerequisite, you will need a working installation of Ruby 1.9 on your
|
406
|
+
computer.
|
407
|
+
If you have installed
|
408
|
+
\family typewriter
|
409
|
+
YPetri
|
410
|
+
\family default
|
411
|
+
as
|
412
|
+
\emph on
|
413
|
+
y_petri
|
414
|
+
\emph default
|
415
|
+
gem, then simply run
|
416
|
+
\emph on
|
417
|
+
irb
|
418
|
+
\emph default
|
419
|
+
and once inside, type:
|
420
|
+
\end_layout
|
421
|
+
|
422
|
+
\begin_layout LyX-Code
|
423
|
+
|
424
|
+
\color red
|
425
|
+
require
|
426
|
+
\color inherit
|
427
|
+
'y_petri'
|
428
|
+
\end_layout
|
429
|
+
|
430
|
+
\begin_layout Standard
|
431
|
+
After succesful
|
432
|
+
\family typewriter
|
433
|
+
require
|
434
|
+
\family default
|
435
|
+
, type:
|
436
|
+
\end_layout
|
437
|
+
|
438
|
+
\begin_layout LyX-Code
|
439
|
+
|
440
|
+
\color red
|
441
|
+
include
|
442
|
+
\color inherit
|
443
|
+
YPetri
|
444
|
+
\end_layout
|
445
|
+
|
446
|
+
\begin_layout Standard
|
447
|
+
This will augment your irb command session with interactive
|
448
|
+
\family typewriter
|
449
|
+
YPetri
|
450
|
+
\family default
|
451
|
+
command interface (
|
452
|
+
\family typewriter
|
453
|
+
YPetri
|
454
|
+
\family default
|
455
|
+
DSL CI).
|
456
|
+
You have to re-run
|
457
|
+
\emph on
|
458
|
+
irb
|
459
|
+
\emph default
|
460
|
+
from the scratch, and re-type '
|
461
|
+
\family typewriter
|
462
|
+
require
|
463
|
+
\family default
|
464
|
+
' and '
|
465
|
+
\family typewriter
|
466
|
+
include
|
467
|
+
\family default
|
468
|
+
' statements before each of the usage examples written below.
|
469
|
+
Please, also notice that this guide itself is alpha stage, so the actual
|
470
|
+
|
471
|
+
\family typewriter
|
472
|
+
YPetri
|
473
|
+
\family default
|
474
|
+
version you will be using may somewhat differ from this guide.
|
475
|
+
Also, the nucleotide metabolism model in Example 3 is yet to be tuned to
|
476
|
+
be realistic.
|
477
|
+
If something in this guide does not work, please do not hesitate to notify
|
478
|
+
us, we will appreciate your feedback.
|
479
|
+
\end_layout
|
480
|
+
|
481
|
+
\begin_layout Part*
|
482
|
+
Example I
|
483
|
+
\end_layout
|
484
|
+
|
485
|
+
\begin_layout Standard
|
486
|
+
This example is a gentle introduction to Petri net terminology,
|
487
|
+
\family typewriter
|
488
|
+
YPetri
|
489
|
+
\family default
|
490
|
+
DSL terminology, and Ruby syntax.
|
491
|
+
The most basic capability that
|
492
|
+
\family typewriter
|
493
|
+
YPetri
|
494
|
+
\family default
|
495
|
+
offers is that of user-driven
|
496
|
+
\emph on
|
497
|
+
\color green
|
498
|
+
token game
|
499
|
+
\emph default
|
500
|
+
\color inherit
|
501
|
+
.
|
502
|
+
We will thus create a small Petri net containing 2
|
503
|
+
\emph on
|
504
|
+
\color green
|
505
|
+
places
|
506
|
+
\emph default
|
507
|
+
\color inherit
|
508
|
+
and play token game with it.
|
509
|
+
\end_layout
|
510
|
+
|
511
|
+
\begin_layout Subsection*
|
512
|
+
Places
|
513
|
+
\end_layout
|
514
|
+
|
515
|
+
\begin_layout Standard
|
516
|
+
Type:
|
517
|
+
\end_layout
|
518
|
+
|
519
|
+
\begin_layout LyX-Code
|
520
|
+
A =
|
521
|
+
\color blue
|
522
|
+
Place
|
523
|
+
\color inherit
|
524
|
+
()
|
525
|
+
\end_layout
|
526
|
+
|
527
|
+
\begin_layout Standard
|
528
|
+
Syntactically, this will call
|
529
|
+
\emph on
|
530
|
+
\color red
|
531
|
+
method
|
532
|
+
\emph default
|
533
|
+
\color inherit
|
534
|
+
'
|
535
|
+
\family typewriter
|
536
|
+
Place
|
537
|
+
\family default
|
538
|
+
' of
|
539
|
+
\family typewriter
|
540
|
+
YPetri
|
541
|
+
\family default
|
542
|
+
DSL and assign its
|
543
|
+
\emph on
|
544
|
+
\color red
|
545
|
+
return value
|
546
|
+
\emph default
|
547
|
+
\color inherit
|
548
|
+
to the
|
549
|
+
\emph on
|
550
|
+
\color red
|
551
|
+
constant
|
552
|
+
\emph default
|
553
|
+
\color inherit
|
554
|
+
|
555
|
+
\family typewriter
|
556
|
+
A
|
557
|
+
\family default
|
558
|
+
.
|
559
|
+
In this case, the return value is an
|
560
|
+
\emph on
|
561
|
+
\color red
|
562
|
+
object
|
563
|
+
\emph default
|
564
|
+
\color inherit
|
565
|
+
, which is an
|
566
|
+
\emph on
|
567
|
+
\color red
|
568
|
+
instance
|
569
|
+
\emph default
|
570
|
+
\color inherit
|
571
|
+
of
|
572
|
+
\family typewriter
|
573
|
+
\color blue
|
574
|
+
YPetri::Place
|
575
|
+
\family default
|
576
|
+
\color inherit
|
577
|
+
|
578
|
+
\emph on
|
579
|
+
\color red
|
580
|
+
class
|
581
|
+
\emph default
|
582
|
+
\color inherit
|
583
|
+
.
|
584
|
+
We say that
|
585
|
+
\family typewriter
|
586
|
+
YPetri::Place
|
587
|
+
\family default
|
588
|
+
class
|
589
|
+
\emph on
|
590
|
+
\color red
|
591
|
+
represents
|
592
|
+
\emph default
|
593
|
+
\color inherit
|
594
|
+
the concept of Petri net places in
|
595
|
+
\family typewriter
|
596
|
+
YPetri
|
597
|
+
\family default
|
598
|
+
|
599
|
+
\emph on
|
600
|
+
domain model
|
601
|
+
\emph default
|
602
|
+
(and '
|
603
|
+
\family typewriter
|
604
|
+
Place
|
605
|
+
\family default
|
606
|
+
' method is called a
|
607
|
+
\emph on
|
608
|
+
\color red
|
609
|
+
constructor
|
610
|
+
\emph default
|
611
|
+
\color inherit
|
612
|
+
of
|
613
|
+
\family typewriter
|
614
|
+
YPetri::Place
|
615
|
+
\family default
|
616
|
+
, which is not important.).
|
617
|
+
Whole this object has now been assigned to
|
618
|
+
\family typewriter
|
619
|
+
A
|
620
|
+
\family default
|
621
|
+
.
|
622
|
+
On the screen, you will see the output:
|
623
|
+
\family typewriter
|
624
|
+
#<Place: name: A, marking: nil, default_marking: ø>
|
625
|
+
\family default
|
626
|
+
.
|
627
|
+
(This is the
|
628
|
+
\emph on
|
629
|
+
\color red
|
630
|
+
inspect string
|
631
|
+
\emph default
|
632
|
+
\color inherit
|
633
|
+
of the object, created by
|
634
|
+
\family typewriter
|
635
|
+
YPetri::Place#
|
636
|
+
\color red
|
637
|
+
inspect
|
638
|
+
\family default
|
639
|
+
\color inherit
|
640
|
+
method, which is not important.) In the following, screen output will always
|
641
|
+
be written immediately under the code sample, preceded by sherocket (
|
642
|
+
\family typewriter
|
643
|
+
#=>):
|
644
|
+
\end_layout
|
645
|
+
|
646
|
+
\begin_layout LyX-Code
|
647
|
+
B = Place()
|
648
|
+
\end_layout
|
649
|
+
|
650
|
+
\begin_layout LyX-Code
|
651
|
+
|
652
|
+
\family typewriter
|
653
|
+
#=> #<Place: name: B, marking: nil, default_marking: ø>
|
654
|
+
\end_layout
|
655
|
+
|
656
|
+
\begin_layout Standard
|
657
|
+
We have so far defined 2 Petri net places named
|
658
|
+
\family typewriter
|
659
|
+
A
|
660
|
+
\family default
|
661
|
+
,
|
662
|
+
\family typewriter
|
663
|
+
B
|
664
|
+
\family default
|
665
|
+
.
|
666
|
+
You can check it by typing:
|
667
|
+
\end_layout
|
668
|
+
|
669
|
+
\begin_layout LyX-Code
|
670
|
+
|
671
|
+
\color blue
|
672
|
+
places
|
673
|
+
\color inherit
|
674
|
+
()
|
675
|
+
\end_layout
|
676
|
+
|
677
|
+
\begin_layout LyX-Code
|
678
|
+
#=> [#<Place: name: A, marking: nil, default_marking: ø>,
|
679
|
+
\end_layout
|
680
|
+
|
681
|
+
\begin_layout LyX-Code
|
682
|
+
#<Place: name: B, marking: nil, default_marking: ø>]
|
683
|
+
\end_layout
|
684
|
+
|
685
|
+
\begin_layout LyX-Code
|
686
|
+
A.
|
687
|
+
\color blue
|
688
|
+
name
|
689
|
+
\color inherit
|
690
|
+
()
|
691
|
+
\end_layout
|
692
|
+
|
693
|
+
\begin_layout LyX-Code
|
694
|
+
#=> :A
|
695
|
+
\end_layout
|
696
|
+
|
697
|
+
\begin_layout Standard
|
698
|
+
These have automatically become part of a default Petri net instance (of
|
699
|
+
|
700
|
+
\family typewriter
|
701
|
+
YPetri::Net
|
702
|
+
\family default
|
703
|
+
class; object id may vary):
|
704
|
+
\end_layout
|
705
|
+
|
706
|
+
\begin_layout LyX-Code
|
707
|
+
|
708
|
+
\color blue
|
709
|
+
net
|
710
|
+
\color inherit
|
711
|
+
()
|
712
|
+
\end_layout
|
713
|
+
|
714
|
+
\begin_layout LyX-Code
|
715
|
+
#=> #<Net: name: Top, 2 pp, 0 tt >
|
716
|
+
\end_layout
|
717
|
+
|
718
|
+
\begin_layout Standard
|
719
|
+
Of course, you have full power of Ruby at your disposal.
|
720
|
+
To eg.
|
721
|
+
list only place names as strings, you can use standard Ruby methods:
|
722
|
+
\end_layout
|
723
|
+
|
724
|
+
\begin_layout LyX-Code
|
725
|
+
places.
|
726
|
+
\color red
|
727
|
+
map
|
728
|
+
\color inherit
|
729
|
+
( &:name )
|
730
|
+
\end_layout
|
731
|
+
|
732
|
+
\begin_layout LyX-Code
|
733
|
+
#=> [:A, :B]
|
734
|
+
\end_layout
|
735
|
+
|
736
|
+
\begin_layout Standard
|
737
|
+
Here, Ruby
|
738
|
+
\family typewriter
|
739
|
+
map
|
740
|
+
\family default
|
741
|
+
method transforms the
|
742
|
+
\emph on
|
743
|
+
\color red
|
744
|
+
array
|
745
|
+
\emph default
|
746
|
+
\color inherit
|
747
|
+
of places to the array of their names.
|
748
|
+
The advantage of internal DSLs is, that one retains full power of the language,
|
749
|
+
augmented with human-friendly, domain-specific CI.
|
750
|
+
GUI systems generally sandbox the user inside their interface, with no
|
751
|
+
way to overcome its limitations.
|
752
|
+
But let us go on.
|
753
|
+
Way above, you might have noticed '
|
754
|
+
\family typewriter
|
755
|
+
\color red
|
756
|
+
nil
|
757
|
+
\family default
|
758
|
+
\color inherit
|
759
|
+
' in the places' inspect strings.
|
760
|
+
This is because we have specified no
|
761
|
+
\emph on
|
762
|
+
\color green
|
763
|
+
marking
|
764
|
+
\emph default
|
765
|
+
\color inherit
|
766
|
+
for
|
767
|
+
\family typewriter
|
768
|
+
A
|
769
|
+
\family default
|
770
|
+
,
|
771
|
+
\family typewriter
|
772
|
+
B
|
773
|
+
\family default
|
774
|
+
:
|
775
|
+
\end_layout
|
776
|
+
|
777
|
+
\begin_layout LyX-Code
|
778
|
+
A.
|
779
|
+
\color blue
|
780
|
+
marking
|
781
|
+
\color inherit
|
782
|
+
()
|
783
|
+
\end_layout
|
784
|
+
|
785
|
+
\begin_layout LyX-Code
|
786
|
+
#=> nil
|
787
|
+
\end_layout
|
788
|
+
|
789
|
+
\begin_layout LyX-Code
|
790
|
+
places.map( &:marking )
|
791
|
+
\end_layout
|
792
|
+
|
793
|
+
\begin_layout LyX-Code
|
794
|
+
#=> [nil, nil]
|
795
|
+
\end_layout
|
796
|
+
|
797
|
+
\begin_layout Standard
|
798
|
+
Let us give these two places some marking:
|
799
|
+
\end_layout
|
800
|
+
|
801
|
+
\begin_layout LyX-Code
|
802
|
+
A.
|
803
|
+
\color blue
|
804
|
+
marking =
|
805
|
+
\color inherit
|
806
|
+
2
|
807
|
+
\end_layout
|
808
|
+
|
809
|
+
\begin_layout LyX-Code
|
810
|
+
#=> 2
|
811
|
+
\end_layout
|
812
|
+
|
813
|
+
\begin_layout LyX-Code
|
814
|
+
B.marking = 5
|
815
|
+
\end_layout
|
816
|
+
|
817
|
+
\begin_layout LyX-Code
|
818
|
+
#=> 5
|
819
|
+
\end_layout
|
820
|
+
|
821
|
+
\begin_layout Standard
|
822
|
+
The marking has indeed changed:
|
823
|
+
\end_layout
|
824
|
+
|
825
|
+
\begin_layout LyX-Code
|
826
|
+
places.map( &:marking )
|
827
|
+
\end_layout
|
828
|
+
|
829
|
+
\begin_layout LyX-Code
|
830
|
+
#=> [2, 5]
|
831
|
+
\end_layout
|
832
|
+
|
833
|
+
\begin_layout Standard
|
834
|
+
In classical Petri nets, this marking is understood as the number of
|
835
|
+
\emph on
|
836
|
+
\color green
|
837
|
+
tokens
|
838
|
+
\emph default
|
839
|
+
\color inherit
|
840
|
+
in each place, and is always an integer.
|
841
|
+
In this case,
|
842
|
+
\family typewriter
|
843
|
+
A
|
844
|
+
\family default
|
845
|
+
contains 2 tokens, while
|
846
|
+
\family typewriter
|
847
|
+
B
|
848
|
+
\family default
|
849
|
+
contains 5 tokens.
|
850
|
+
Tokens can represent anything: molecules, parts in the production line,
|
851
|
+
trains in the railway network...
|
852
|
+
\end_layout
|
853
|
+
|
854
|
+
\begin_layout Subsection*
|
855
|
+
Transitions
|
856
|
+
\end_layout
|
857
|
+
|
858
|
+
\begin_layout Standard
|
859
|
+
The behavior of a Petri net is defined by
|
860
|
+
\emph on
|
861
|
+
\color green
|
862
|
+
transitions
|
863
|
+
\emph default
|
864
|
+
\color inherit
|
865
|
+
.
|
866
|
+
Each transition defines a single operation: Adding / subtracting some amount
|
867
|
+
of tokens to / from some places.
|
868
|
+
Transition operation can often be expressed by the transition's
|
869
|
+
\emph on
|
870
|
+
stoichiometry
|
871
|
+
\emph default
|
872
|
+
– a list of places together with the number of tokens added / subtracted
|
873
|
+
when the transition
|
874
|
+
\emph on
|
875
|
+
\color green
|
876
|
+
fires
|
877
|
+
\emph default
|
878
|
+
\color inherit
|
879
|
+
.
|
880
|
+
For example, let us define:
|
881
|
+
\end_layout
|
882
|
+
|
883
|
+
\begin_layout LyX-Code
|
884
|
+
A2B =
|
885
|
+
\color blue
|
886
|
+
Transition
|
887
|
+
\color inherit
|
888
|
+
( stoichiometry: { A: -1, B: 1 } )
|
889
|
+
\end_layout
|
890
|
+
|
891
|
+
\begin_layout LyX-Code
|
892
|
+
#=> #<Transition: A2B (tS) >
|
893
|
+
\end_layout
|
894
|
+
|
895
|
+
\begin_layout Standard
|
896
|
+
Stoichiometry of this transition is given by
|
897
|
+
\emph on
|
898
|
+
\color red
|
899
|
+
hash
|
900
|
+
\emph default
|
901
|
+
\color inherit
|
902
|
+
|
903
|
+
\family typewriter
|
904
|
+
{ A: -1, B: 1 }
|
905
|
+
\family default
|
906
|
+
.
|
907
|
+
This hash is available from
|
908
|
+
\family typewriter
|
909
|
+
A2B
|
910
|
+
\family default
|
911
|
+
via '
|
912
|
+
\family typewriter
|
913
|
+
\color blue
|
914
|
+
s
|
915
|
+
\family default
|
916
|
+
\color inherit
|
917
|
+
' method:
|
918
|
+
\end_layout
|
919
|
+
|
920
|
+
\begin_layout LyX-Code
|
921
|
+
A2B.
|
922
|
+
\color blue
|
923
|
+
s
|
924
|
+
\color inherit
|
925
|
+
()
|
926
|
+
\end_layout
|
927
|
+
|
928
|
+
\begin_layout LyX-Code
|
929
|
+
#=> {:A=>-1, :B=>1}
|
930
|
+
\end_layout
|
931
|
+
|
932
|
+
\begin_layout Standard
|
933
|
+
|
934
|
+
\emph on
|
935
|
+
\color red
|
936
|
+
Keys
|
937
|
+
\emph default
|
938
|
+
\color inherit
|
939
|
+
of this hash are place names,
|
940
|
+
\emph on
|
941
|
+
\color red
|
942
|
+
values
|
943
|
+
\emph default
|
944
|
+
\color inherit
|
945
|
+
are
|
946
|
+
\emph on
|
947
|
+
\color green
|
948
|
+
stoichiometry coefficients
|
949
|
+
\emph default
|
950
|
+
\color inherit
|
951
|
+
.
|
952
|
+
('Stoichiometry' is a word known from the domain of chemistry, but '
|
953
|
+
\emph on
|
954
|
+
stoicheion
|
955
|
+
\emph default
|
956
|
+
' means simply 'element' in Greek, so there is no problem with using it
|
957
|
+
in the domain of general Petri nets.) To see the stoichiometry coefficients
|
958
|
+
of
|
959
|
+
\family typewriter
|
960
|
+
A2B
|
961
|
+
\family default
|
962
|
+
as an array, type:
|
963
|
+
\end_layout
|
964
|
+
|
965
|
+
\begin_layout LyX-Code
|
966
|
+
A2B.
|
967
|
+
\color blue
|
968
|
+
stoichiometry
|
969
|
+
\color inherit
|
970
|
+
()
|
971
|
+
\end_layout
|
972
|
+
|
973
|
+
\begin_layout LyX-Code
|
974
|
+
#=> [-1, 1]
|
975
|
+
\end_layout
|
976
|
+
|
977
|
+
\begin_layout Standard
|
978
|
+
Simply,
|
979
|
+
\family typewriter
|
980
|
+
A2B
|
981
|
+
\family default
|
982
|
+
subtracts 1 token from
|
983
|
+
\family typewriter
|
984
|
+
A
|
985
|
+
\family default
|
986
|
+
, and adds 1 token to
|
987
|
+
\family typewriter
|
988
|
+
B
|
989
|
+
\family default
|
990
|
+
.
|
991
|
+
This can represent conversion of
|
992
|
+
\family typewriter
|
993
|
+
A
|
994
|
+
\family default
|
995
|
+
to
|
996
|
+
\family typewriter
|
997
|
+
B
|
998
|
+
\family default
|
999
|
+
.
|
1000
|
+
In classical Petri nets, the arrows connecting places and transitions are
|
1001
|
+
called
|
1002
|
+
\emph on
|
1003
|
+
\color green
|
1004
|
+
arcs
|
1005
|
+
\emph default
|
1006
|
+
\color inherit
|
1007
|
+
.
|
1008
|
+
(The term was borrowed from graph theory.) For example, at this moment,
|
1009
|
+
our Petri net would contain one arc going from
|
1010
|
+
\family typewriter
|
1011
|
+
A
|
1012
|
+
\family default
|
1013
|
+
to
|
1014
|
+
\family typewriter
|
1015
|
+
A2B
|
1016
|
+
\family default
|
1017
|
+
, and one arc going from
|
1018
|
+
\family typewriter
|
1019
|
+
A2B
|
1020
|
+
\family default
|
1021
|
+
to
|
1022
|
+
\family typewriter
|
1023
|
+
B
|
1024
|
+
\family default
|
1025
|
+
.
|
1026
|
+
In
|
1027
|
+
\family typewriter
|
1028
|
+
YPetri
|
1029
|
+
\family default
|
1030
|
+
domain model, 'arcs' are not first-class citizens.
|
1031
|
+
The word is understood simply as a synonym for transitions' connectivity
|
1032
|
+
– the list of places connected to each transition:
|
1033
|
+
\end_layout
|
1034
|
+
|
1035
|
+
\begin_layout LyX-Code
|
1036
|
+
A2B.
|
1037
|
+
\color blue
|
1038
|
+
arcs
|
1039
|
+
\color inherit
|
1040
|
+
()
|
1041
|
+
\end_layout
|
1042
|
+
|
1043
|
+
\begin_layout LyX-Code
|
1044
|
+
#=> [#<Place: name: A, marking: 2, default_marking: ø >,
|
1045
|
+
\end_layout
|
1046
|
+
|
1047
|
+
\begin_layout LyX-Code
|
1048
|
+
#<Place: name: B, marking: 5, default_marking: ø >]
|
1049
|
+
\end_layout
|
1050
|
+
|
1051
|
+
\begin_layout Standard
|
1052
|
+
The transition
|
1053
|
+
\family typewriter
|
1054
|
+
A2B
|
1055
|
+
\family default
|
1056
|
+
is
|
1057
|
+
\emph on
|
1058
|
+
\color blue
|
1059
|
+
timeless
|
1060
|
+
\emph default
|
1061
|
+
\color inherit
|
1062
|
+
:
|
1063
|
+
\end_layout
|
1064
|
+
|
1065
|
+
\begin_layout LyX-Code
|
1066
|
+
A2B.
|
1067
|
+
\color blue
|
1068
|
+
timeless?
|
1069
|
+
\color inherit
|
1070
|
+
()
|
1071
|
+
\end_layout
|
1072
|
+
|
1073
|
+
\begin_layout LyX-Code
|
1074
|
+
#=> true
|
1075
|
+
\end_layout
|
1076
|
+
|
1077
|
+
\begin_layout Standard
|
1078
|
+
'Timeless' means that the transition's firing is not defined in time – it
|
1079
|
+
can fire anytime, as long as it is
|
1080
|
+
\emph on
|
1081
|
+
\color green
|
1082
|
+
enabled
|
1083
|
+
\emph default
|
1084
|
+
\color inherit
|
1085
|
+
.
|
1086
|
+
Classical Petri nets are timeless.
|
1087
|
+
In classical Petri nets, a transition is enabled whenever its
|
1088
|
+
\emph on
|
1089
|
+
\color blue
|
1090
|
+
downstream arcs
|
1091
|
+
\emph default
|
1092
|
+
\color inherit
|
1093
|
+
allow it to happen.
|
1094
|
+
Downstream arcs, or
|
1095
|
+
\emph on
|
1096
|
+
\color blue
|
1097
|
+
codomain
|
1098
|
+
\emph default
|
1099
|
+
\color inherit
|
1100
|
+
of a transition (these two are synonyms) are those places, whose marking
|
1101
|
+
can be directly affected by the transition's firing.
|
1102
|
+
In this case, both
|
1103
|
+
\family typewriter
|
1104
|
+
A
|
1105
|
+
\family default
|
1106
|
+
and
|
1107
|
+
\family typewriter
|
1108
|
+
B
|
1109
|
+
\family default
|
1110
|
+
is affected:
|
1111
|
+
\end_layout
|
1112
|
+
|
1113
|
+
\begin_layout LyX-Code
|
1114
|
+
A2B.
|
1115
|
+
\color blue
|
1116
|
+
downstream_arcs
|
1117
|
+
\color inherit
|
1118
|
+
()
|
1119
|
+
\end_layout
|
1120
|
+
|
1121
|
+
\begin_layout LyX-Code
|
1122
|
+
[#<Place: name: A, marking: 2, default_marking: ø>,
|
1123
|
+
\end_layout
|
1124
|
+
|
1125
|
+
\begin_layout LyX-Code
|
1126
|
+
#<Place: name: B, marking: 5, default_marking: ø>]
|
1127
|
+
\end_layout
|
1128
|
+
|
1129
|
+
\begin_layout LyX-Code
|
1130
|
+
A2B.
|
1131
|
+
\color blue
|
1132
|
+
codomain
|
1133
|
+
\color inherit
|
1134
|
+
()
|
1135
|
+
\end_layout
|
1136
|
+
|
1137
|
+
\begin_layout LyX-Code
|
1138
|
+
[#<Place: name: A, marking: 2, default_marking: ø>,
|
1139
|
+
\end_layout
|
1140
|
+
|
1141
|
+
\begin_layout LyX-Code
|
1142
|
+
#<Place: name: B, marking: 5, default_marking: ø>]
|
1143
|
+
\end_layout
|
1144
|
+
|
1145
|
+
\begin_layout Standard
|
1146
|
+
Since
|
1147
|
+
\family typewriter
|
1148
|
+
A2B
|
1149
|
+
\family default
|
1150
|
+
subtracts tokens from
|
1151
|
+
\family typewriter
|
1152
|
+
A
|
1153
|
+
\family default
|
1154
|
+
, it will be enabled so long, as there are any tokens left in
|
1155
|
+
\family typewriter
|
1156
|
+
A
|
1157
|
+
\family default
|
1158
|
+
.
|
1159
|
+
\end_layout
|
1160
|
+
|
1161
|
+
\begin_layout LyX-Code
|
1162
|
+
A2B.
|
1163
|
+
\color blue
|
1164
|
+
enabled?
|
1165
|
+
\color inherit
|
1166
|
+
()
|
1167
|
+
\end_layout
|
1168
|
+
|
1169
|
+
\begin_layout LyX-Code
|
1170
|
+
#=> true
|
1171
|
+
\end_layout
|
1172
|
+
|
1173
|
+
\begin_layout Subsection*
|
1174
|
+
Token game
|
1175
|
+
\end_layout
|
1176
|
+
|
1177
|
+
\begin_layout Standard
|
1178
|
+
After
|
1179
|
+
\family typewriter
|
1180
|
+
A2B
|
1181
|
+
\family default
|
1182
|
+
fires, the marking will change:
|
1183
|
+
\end_layout
|
1184
|
+
|
1185
|
+
\begin_layout LyX-Code
|
1186
|
+
A2B.
|
1187
|
+
\color blue
|
1188
|
+
fire!
|
1189
|
+
\color inherit
|
1190
|
+
()
|
1191
|
+
\end_layout
|
1192
|
+
|
1193
|
+
\begin_layout LyX-Code
|
1194
|
+
#=> nil
|
1195
|
+
\end_layout
|
1196
|
+
|
1197
|
+
\begin_layout LyX-Code
|
1198
|
+
places.map( &:marking )
|
1199
|
+
\end_layout
|
1200
|
+
|
1201
|
+
\begin_layout LyX-Code
|
1202
|
+
#=> [1, 6]
|
1203
|
+
\end_layout
|
1204
|
+
|
1205
|
+
\begin_layout LyX-Code
|
1206
|
+
A2B.fire!()
|
1207
|
+
\end_layout
|
1208
|
+
|
1209
|
+
\begin_layout LyX-Code
|
1210
|
+
#=> nil
|
1211
|
+
\end_layout
|
1212
|
+
|
1213
|
+
\begin_layout LyX-Code
|
1214
|
+
places.map( &:marking )
|
1215
|
+
\end_layout
|
1216
|
+
|
1217
|
+
\begin_layout LyX-Code
|
1218
|
+
#=> [0, 7]
|
1219
|
+
\end_layout
|
1220
|
+
|
1221
|
+
\begin_layout Standard
|
1222
|
+
At this point, there are no tokens left in
|
1223
|
+
\family typewriter
|
1224
|
+
A
|
1225
|
+
\family default
|
1226
|
+
and
|
1227
|
+
\family typewriter
|
1228
|
+
A2B
|
1229
|
+
\family default
|
1230
|
+
becomes
|
1231
|
+
\emph on
|
1232
|
+
\color green
|
1233
|
+
disabled
|
1234
|
+
\emph default
|
1235
|
+
\color inherit
|
1236
|
+
:
|
1237
|
+
\end_layout
|
1238
|
+
|
1239
|
+
\begin_layout LyX-Code
|
1240
|
+
A2B.enabled?
|
1241
|
+
\end_layout
|
1242
|
+
|
1243
|
+
\begin_layout LyX-Code
|
1244
|
+
#=> false
|
1245
|
+
\end_layout
|
1246
|
+
|
1247
|
+
\begin_layout Standard
|
1248
|
+
Attempt to fire a disabled transition
|
1249
|
+
\emph on
|
1250
|
+
\color red
|
1251
|
+
raises
|
1252
|
+
\emph default
|
1253
|
+
\color inherit
|
1254
|
+
an
|
1255
|
+
\emph on
|
1256
|
+
\color red
|
1257
|
+
error
|
1258
|
+
\emph default
|
1259
|
+
\color inherit
|
1260
|
+
(in Ruby, errors are friendly objects, who, like damsels in distress, are
|
1261
|
+
meant to be rescued with a bonus outcome):
|
1262
|
+
\end_layout
|
1263
|
+
|
1264
|
+
\begin_layout LyX-Code
|
1265
|
+
A2B.fire!
|
1266
|
+
\end_layout
|
1267
|
+
|
1268
|
+
\begin_layout LyX-Code
|
1269
|
+
#=> RuntimeError: Firing of #<Transition: A2B (tS)> would result in negative
|
1270
|
+
marking!
|
1271
|
+
\end_layout
|
1272
|
+
|
1273
|
+
\begin_layout Subsection*
|
1274
|
+
Functional transitions and non-integer marking
|
1275
|
+
\end_layout
|
1276
|
+
|
1277
|
+
\begin_layout Standard
|
1278
|
+
So far, all the examples were compatible with classical Petri nets.
|
1279
|
+
But
|
1280
|
+
\family typewriter
|
1281
|
+
YPetri
|
1282
|
+
\family default
|
1283
|
+
goes beyond – it represents
|
1284
|
+
\emph on
|
1285
|
+
functional Petri nets
|
1286
|
+
\emph default
|
1287
|
+
, similar to HFPNs proposed by
|
1288
|
+
\begin_inset CommandInset citation
|
1289
|
+
LatexCommand citet
|
1290
|
+
key "Matsuno2011brs"
|
1291
|
+
|
1292
|
+
\end_inset
|
1293
|
+
|
1294
|
+
, which was already mentioned in the introduction.
|
1295
|
+
|
1296
|
+
\family typewriter
|
1297
|
+
YPetri
|
1298
|
+
\family default
|
1299
|
+
domain model is similar, but not identical.
|
1300
|
+
On the side of similarities, YPetri allows non-integer marking of places:
|
1301
|
+
\end_layout
|
1302
|
+
|
1303
|
+
\begin_layout LyX-Code
|
1304
|
+
C = Place(
|
1305
|
+
\color blue
|
1306
|
+
marking
|
1307
|
+
\color inherit
|
1308
|
+
: 7.77 )
|
1309
|
+
\end_layout
|
1310
|
+
|
1311
|
+
\begin_layout LyX-Code
|
1312
|
+
#=> #<Place: name: C, marking: 7.77, default_marking: ø>
|
1313
|
+
\end_layout
|
1314
|
+
|
1315
|
+
\begin_layout Standard
|
1316
|
+
Here, you can notice that marking of places can be specified already upon
|
1317
|
+
initialization using '
|
1318
|
+
\family typewriter
|
1319
|
+
:marking
|
1320
|
+
\family default
|
1321
|
+
'
|
1322
|
+
\emph on
|
1323
|
+
\color red
|
1324
|
+
named argument
|
1325
|
+
\emph default
|
1326
|
+
\color inherit
|
1327
|
+
.
|
1328
|
+
Let us now define a
|
1329
|
+
\emph on
|
1330
|
+
\color blue
|
1331
|
+
timed
|
1332
|
+
\emph default
|
1333
|
+
\color inherit
|
1334
|
+
transition, representing logarithmic decay of
|
1335
|
+
\family typewriter
|
1336
|
+
C
|
1337
|
+
\family default
|
1338
|
+
with a rate constant of 0.05:
|
1339
|
+
\end_layout
|
1340
|
+
|
1341
|
+
\begin_layout LyX-Code
|
1342
|
+
C_decay = Transition( stoichiometry: { C: -1 },
|
1343
|
+
\color blue
|
1344
|
+
rate
|
1345
|
+
\color inherit
|
1346
|
+
: 0.05 )
|
1347
|
+
\end_layout
|
1348
|
+
|
1349
|
+
\begin_layout LyX-Code
|
1350
|
+
#=> #<Transition: C_decay (TS)>
|
1351
|
+
\end_layout
|
1352
|
+
|
1353
|
+
\begin_layout LyX-Code
|
1354
|
+
C_decay.
|
1355
|
+
\color blue
|
1356
|
+
timed?
|
1357
|
+
\end_layout
|
1358
|
+
|
1359
|
+
\begin_layout LyX-Code
|
1360
|
+
#=> true
|
1361
|
+
\end_layout
|
1362
|
+
|
1363
|
+
\begin_layout Standard
|
1364
|
+
Here, in the
|
1365
|
+
\family typewriter
|
1366
|
+
transition
|
1367
|
+
\family default
|
1368
|
+
constructor method, apart from '
|
1369
|
+
\family typewriter
|
1370
|
+
stoichiometry:
|
1371
|
+
\family default
|
1372
|
+
' named argument, another named argument, '
|
1373
|
+
\family typewriter
|
1374
|
+
rate:
|
1375
|
+
\family default
|
1376
|
+
', is introduced.
|
1377
|
+
Under '
|
1378
|
+
\family typewriter
|
1379
|
+
rate:
|
1380
|
+
\family default
|
1381
|
+
', it is possible to specify the transition's
|
1382
|
+
\emph on
|
1383
|
+
\color green
|
1384
|
+
function
|
1385
|
+
\emph default
|
1386
|
+
\color inherit
|
1387
|
+
, which governs its rate.
|
1388
|
+
Specifying a function in Ruby requires special syntax (called Ruby
|
1389
|
+
\emph on
|
1390
|
+
\color red
|
1391
|
+
closures
|
1392
|
+
\emph default
|
1393
|
+
\color inherit
|
1394
|
+
), based on lambda calculus.
|
1395
|
+
Ruby closures are easy to learn.
|
1396
|
+
But for the moment, in
|
1397
|
+
\family typewriter
|
1398
|
+
C_decay
|
1399
|
+
\family default
|
1400
|
+
transition, we are taking use of the convenience, that allows us to pass
|
1401
|
+
a numeric value under '
|
1402
|
+
\family typewriter
|
1403
|
+
rate:
|
1404
|
+
\family default
|
1405
|
+
' named argument, and have
|
1406
|
+
\family typewriter
|
1407
|
+
YPetri
|
1408
|
+
\family default
|
1409
|
+
create default mass action equation, using the supplied number as its rate
|
1410
|
+
constant.
|
1411
|
+
For
|
1412
|
+
\family typewriter
|
1413
|
+
C_decay
|
1414
|
+
\family default
|
1415
|
+
stoichiometry,
|
1416
|
+
\family typewriter
|
1417
|
+
{ C: -1 }
|
1418
|
+
\family default
|
1419
|
+
, default mass action will be logarithmic decay with rate constant 0.05.
|
1420
|
+
Naturally, when firing timed transitions, the time interval (
|
1421
|
+
\begin_inset Formula $\Delta$
|
1422
|
+
\end_inset
|
1423
|
+
|
1424
|
+
time) must be specified, for which the transition should be active:
|
1425
|
+
\end_layout
|
1426
|
+
|
1427
|
+
\begin_layout LyX-Code
|
1428
|
+
C_decay.fire!( 1 )
|
1429
|
+
\end_layout
|
1430
|
+
|
1431
|
+
\begin_layout LyX-Code
|
1432
|
+
#=> nil
|
1433
|
+
\end_layout
|
1434
|
+
|
1435
|
+
\begin_layout LyX-Code
|
1436
|
+
C.marking
|
1437
|
+
\end_layout
|
1438
|
+
|
1439
|
+
\begin_layout LyX-Code
|
1440
|
+
#=> 7.3815
|
1441
|
+
\end_layout
|
1442
|
+
|
1443
|
+
\begin_layout LyX-Code
|
1444
|
+
C_decay.fire! 1
|
1445
|
+
\end_layout
|
1446
|
+
|
1447
|
+
\begin_layout LyX-Code
|
1448
|
+
#=> nil
|
1449
|
+
\end_layout
|
1450
|
+
|
1451
|
+
\begin_layout LyX-Code
|
1452
|
+
C.marking
|
1453
|
+
\end_layout
|
1454
|
+
|
1455
|
+
\begin_layout LyX-Code
|
1456
|
+
#=> 7.012425
|
1457
|
+
\end_layout
|
1458
|
+
|
1459
|
+
\begin_layout LyX-Code
|
1460
|
+
C_decay.fire!( 0.1 )
|
1461
|
+
\end_layout
|
1462
|
+
|
1463
|
+
\begin_layout LyX-Code
|
1464
|
+
#=> nil
|
1465
|
+
\end_layout
|
1466
|
+
|
1467
|
+
\begin_layout LyX-Code
|
1468
|
+
C.marking
|
1469
|
+
\end_layout
|
1470
|
+
|
1471
|
+
\begin_layout LyX-Code
|
1472
|
+
#=> 6.977362875000001
|
1473
|
+
\end_layout
|
1474
|
+
|
1475
|
+
\begin_layout LyX-Code
|
1476
|
+
100.
|
1477
|
+
\color red
|
1478
|
+
times
|
1479
|
+
\color inherit
|
1480
|
+
do C_decay.fire! 1 end
|
1481
|
+
\end_layout
|
1482
|
+
|
1483
|
+
\begin_layout LyX-Code
|
1484
|
+
#=> 100
|
1485
|
+
\end_layout
|
1486
|
+
|
1487
|
+
\begin_layout LyX-Code
|
1488
|
+
C.marking
|
1489
|
+
\end_layout
|
1490
|
+
|
1491
|
+
\begin_layout LyX-Code
|
1492
|
+
#=> 0.04130968078231133
|
1493
|
+
\end_layout
|
1494
|
+
|
1495
|
+
\begin_layout Standard
|
1496
|
+
The penultimate statement was a call of Ruby '
|
1497
|
+
\family typewriter
|
1498
|
+
times
|
1499
|
+
\family default
|
1500
|
+
' method with the integer
|
1501
|
+
\family typewriter
|
1502
|
+
100
|
1503
|
+
\family default
|
1504
|
+
as the receiver, which results in 100 time repetition of the statement
|
1505
|
+
inside
|
1506
|
+
\family typewriter
|
1507
|
+
\color red
|
1508
|
+
do ...
|
1509
|
+
end
|
1510
|
+
\family default
|
1511
|
+
\emph on
|
1512
|
+
block
|
1513
|
+
\emph default
|
1514
|
+
\color inherit
|
1515
|
+
.
|
1516
|
+
Instead of
|
1517
|
+
\family typewriter
|
1518
|
+
do ...
|
1519
|
+
end
|
1520
|
+
\family default
|
1521
|
+
, it is possible to write a block using curly braces
|
1522
|
+
\family typewriter
|
1523
|
+
\color red
|
1524
|
+
{ ...
|
1525
|
+
}
|
1526
|
+
\family default
|
1527
|
+
\color inherit
|
1528
|
+
:
|
1529
|
+
\end_layout
|
1530
|
+
|
1531
|
+
\begin_layout LyX-Code
|
1532
|
+
100.times { C_decay.fire! 1 }
|
1533
|
+
\end_layout
|
1534
|
+
|
1535
|
+
\begin_layout LyX-Code
|
1536
|
+
#=> 100
|
1537
|
+
\end_layout
|
1538
|
+
|
1539
|
+
\begin_layout Standard
|
1540
|
+
This will cause another 100 time units of
|
1541
|
+
\family typewriter
|
1542
|
+
C_decay
|
1543
|
+
\family default
|
1544
|
+
firing.
|
1545
|
+
This brings
|
1546
|
+
\family typewriter
|
1547
|
+
C
|
1548
|
+
\family default
|
1549
|
+
marking down to almost zero:
|
1550
|
+
\end_layout
|
1551
|
+
|
1552
|
+
\begin_layout LyX-Code
|
1553
|
+
C.marking
|
1554
|
+
\end_layout
|
1555
|
+
|
1556
|
+
\begin_layout LyX-Code
|
1557
|
+
#=> 0.00024457517215434527
|
1558
|
+
\end_layout
|
1559
|
+
|
1560
|
+
\begin_layout Part*
|
1561
|
+
Example II
|
1562
|
+
\end_layout
|
1563
|
+
|
1564
|
+
\begin_layout Standard
|
1565
|
+
Instead of manually playing the token game using
|
1566
|
+
\family typewriter
|
1567
|
+
#fire!
|
1568
|
+
\family default
|
1569
|
+
method, let us now simulate a Petri net inside
|
1570
|
+
\family typewriter
|
1571
|
+
\color blue
|
1572
|
+
YPetri::TimedSimulation
|
1573
|
+
\family default
|
1574
|
+
\color inherit
|
1575
|
+
.
|
1576
|
+
Restart your irb session as described in the
|
1577
|
+
\series bold
|
1578
|
+
Prerequisites
|
1579
|
+
\series default
|
1580
|
+
chapter.
|
1581
|
+
We will now define 2 places.
|
1582
|
+
Since we are going to use
|
1583
|
+
\family typewriter
|
1584
|
+
TimedSimulation
|
1585
|
+
\family default
|
1586
|
+
, the marking owned by
|
1587
|
+
\family typewriter
|
1588
|
+
YPetri::Place
|
1589
|
+
\family default
|
1590
|
+
instances is irrelevant.
|
1591
|
+
We just need to specify the initial state.
|
1592
|
+
One way to do this is by specifying
|
1593
|
+
\family typewriter
|
1594
|
+
\color blue
|
1595
|
+
:default_marking
|
1596
|
+
\family default
|
1597
|
+
\color inherit
|
1598
|
+
named argument:
|
1599
|
+
\end_layout
|
1600
|
+
|
1601
|
+
\begin_layout LyX-Code
|
1602
|
+
A = Place(
|
1603
|
+
\color blue
|
1604
|
+
default_marking:
|
1605
|
+
\color inherit
|
1606
|
+
0.5 )
|
1607
|
+
\end_layout
|
1608
|
+
|
1609
|
+
\begin_layout LyX-Code
|
1610
|
+
#=> #<Place: name: A, marking: 0.5, default_marking: 0.5>
|
1611
|
+
\end_layout
|
1612
|
+
|
1613
|
+
\begin_layout LyX-Code
|
1614
|
+
B = Place( default_marking: 0.5 )
|
1615
|
+
\end_layout
|
1616
|
+
|
1617
|
+
\begin_layout LyX-Code
|
1618
|
+
#=> #<Place: name: B, marking: 0.5, default_marking: 0.5>
|
1619
|
+
\end_layout
|
1620
|
+
|
1621
|
+
\begin_layout Standard
|
1622
|
+
Now let us define a transition corresponding to pumping
|
1623
|
+
\family typewriter
|
1624
|
+
A
|
1625
|
+
\family default
|
1626
|
+
out of the system at a constant rate 0.005 per time unit.
|
1627
|
+
\end_layout
|
1628
|
+
|
1629
|
+
\begin_layout LyX-Code
|
1630
|
+
A_pump = Transition( stoichiometry: { A: -1 }, rate: proc { 0.005 } )
|
1631
|
+
\end_layout
|
1632
|
+
|
1633
|
+
\begin_layout LyX-Code
|
1634
|
+
#=> #<Transition: A_pump (SR)>
|
1635
|
+
\end_layout
|
1636
|
+
|
1637
|
+
\begin_layout Standard
|
1638
|
+
Here,
|
1639
|
+
\family typewriter
|
1640
|
+
proc { 0.005 }
|
1641
|
+
\family default
|
1642
|
+
is a closure, that defines the rate function.
|
1643
|
+
Closure
|
1644
|
+
\family typewriter
|
1645
|
+
proc { 0.005 }
|
1646
|
+
\family default
|
1647
|
+
ensures fixed rate 0.005 per time unit regardless of the marking of
|
1648
|
+
\family typewriter
|
1649
|
+
A
|
1650
|
+
\family default
|
1651
|
+
.
|
1652
|
+
You can notice, that this closure expects no arguments and always outputs
|
1653
|
+
0.005 as its return value.
|
1654
|
+
It is the simplest possible way to write a constant function.
|
1655
|
+
For comparison,
|
1656
|
+
\end_layout
|
1657
|
+
|
1658
|
+
\begin_layout LyX-Code
|
1659
|
+
B_decay = Transition( stoichiometry: { B: -1 }, rate: 0.05 )
|
1660
|
+
\end_layout
|
1661
|
+
|
1662
|
+
\begin_layout LyX-Code
|
1663
|
+
#=> #<Transition: B_decay (SR)>
|
1664
|
+
\end_layout
|
1665
|
+
|
1666
|
+
\begin_layout Standard
|
1667
|
+
will behind the scenes automatically create a slightly more complicated
|
1668
|
+
mass action closure, which is logarithmic decay of
|
1669
|
+
\family typewriter
|
1670
|
+
B
|
1671
|
+
\family default
|
1672
|
+
in this case.
|
1673
|
+
(You should remember this from
|
1674
|
+
\series bold
|
1675
|
+
Example I
|
1676
|
+
\series default
|
1677
|
+
.) Now we have created a net of 2 places and 2 transitions:
|
1678
|
+
\end_layout
|
1679
|
+
|
1680
|
+
\begin_layout LyX-Code
|
1681
|
+
net
|
1682
|
+
\end_layout
|
1683
|
+
|
1684
|
+
\begin_layout LyX-Code
|
1685
|
+
#=> #<Net: name: Top, 2 pp, 2 tt>
|
1686
|
+
\end_layout
|
1687
|
+
|
1688
|
+
\begin_layout Standard
|
1689
|
+
We can execute this Petri net as
|
1690
|
+
\family typewriter
|
1691
|
+
TimedSimulation
|
1692
|
+
\family default
|
1693
|
+
simply by typing:
|
1694
|
+
\end_layout
|
1695
|
+
|
1696
|
+
\begin_layout LyX-Code
|
1697
|
+
|
1698
|
+
\color blue
|
1699
|
+
run!
|
1700
|
+
\end_layout
|
1701
|
+
|
1702
|
+
\begin_layout LyX-Code
|
1703
|
+
#=> #<YPetri::TimedSimulation: 2 places, 2 transitions, time: 60, object
|
1704
|
+
id: 75530290>
|
1705
|
+
\end_layout
|
1706
|
+
|
1707
|
+
\begin_layout Standard
|
1708
|
+
At this point,
|
1709
|
+
\family typewriter
|
1710
|
+
run!
|
1711
|
+
\family default
|
1712
|
+
creates and executes a
|
1713
|
+
\family typewriter
|
1714
|
+
TimedSimulation
|
1715
|
+
\family default
|
1716
|
+
instance.
|
1717
|
+
The return value is the simulation instance itself (see the inspect string
|
1718
|
+
above), which by now has already finished execution and holds the simulation
|
1719
|
+
results.
|
1720
|
+
This simulation instance is accessible via
|
1721
|
+
\family typewriter
|
1722
|
+
simulation
|
1723
|
+
\family default
|
1724
|
+
method.
|
1725
|
+
\end_layout
|
1726
|
+
|
1727
|
+
\begin_layout LyX-Code
|
1728
|
+
|
1729
|
+
\color blue
|
1730
|
+
simulation
|
1731
|
+
\end_layout
|
1732
|
+
|
1733
|
+
\begin_layout LyX-Code
|
1734
|
+
#=> #<Simulation: Time: 60, 2 places, 2 transitions, object id: 75530290>
|
1735
|
+
\end_layout
|
1736
|
+
|
1737
|
+
\begin_layout Standard
|
1738
|
+
The simulation does not affect the net.
|
1739
|
+
The simulation instance works with its own
|
1740
|
+
\begin_inset Quotes eld
|
1741
|
+
\end_inset
|
1742
|
+
|
1743
|
+
mental image
|
1744
|
+
\begin_inset Quotes erd
|
1745
|
+
\end_inset
|
1746
|
+
|
1747
|
+
of the net, therefore the marking owned by
|
1748
|
+
\family typewriter
|
1749
|
+
YPetri::Place
|
1750
|
+
\family default
|
1751
|
+
instances does not change:
|
1752
|
+
\end_layout
|
1753
|
+
|
1754
|
+
\begin_layout LyX-Code
|
1755
|
+
places.map &:marking
|
1756
|
+
\end_layout
|
1757
|
+
|
1758
|
+
\begin_layout LyX-Code
|
1759
|
+
#=> [0.5, 0.5]
|
1760
|
+
\end_layout
|
1761
|
+
|
1762
|
+
\begin_layout Standard
|
1763
|
+
In a general case, it would be necessary to specify the simulation settings
|
1764
|
+
(step size, sampling rate, simulation time etc.) before running the simulation.
|
1765
|
+
Since we have not specified any, default settings were used:
|
1766
|
+
\end_layout
|
1767
|
+
|
1768
|
+
\begin_layout LyX-Code
|
1769
|
+
simulation.
|
1770
|
+
\color blue
|
1771
|
+
settings
|
1772
|
+
\end_layout
|
1773
|
+
|
1774
|
+
\begin_layout LyX-Code
|
1775
|
+
#=> {:step=>0.1, :sampling=>5, :time=>0..60}
|
1776
|
+
\end_layout
|
1777
|
+
|
1778
|
+
\begin_layout Standard
|
1779
|
+
We can see sampling done by the simulation by typing:
|
1780
|
+
\end_layout
|
1781
|
+
|
1782
|
+
\begin_layout LyX-Code
|
1783
|
+
|
1784
|
+
\color blue
|
1785
|
+
print_recording
|
1786
|
+
\end_layout
|
1787
|
+
|
1788
|
+
\begin_layout LyX-Code
|
1789
|
+
#=> 0.0,0.5,0.5
|
1790
|
+
\end_layout
|
1791
|
+
|
1792
|
+
\begin_layout LyX-Code
|
1793
|
+
5.0,0.475,0.38916
|
1794
|
+
\end_layout
|
1795
|
+
|
1796
|
+
\begin_layout LyX-Code
|
1797
|
+
10.0,0.45,0.30289
|
1798
|
+
\end_layout
|
1799
|
+
|
1800
|
+
\begin_layout LyX-Code
|
1801
|
+
15.0,0.425,0.23574
|
1802
|
+
\end_layout
|
1803
|
+
|
1804
|
+
\begin_layout LyX-Code
|
1805
|
+
20.0,0.4,0.18348
|
1806
|
+
\end_layout
|
1807
|
+
|
1808
|
+
\begin_layout LyX-Code
|
1809
|
+
25.0,0.375,0.1428
|
1810
|
+
\end_layout
|
1811
|
+
|
1812
|
+
\begin_layout LyX-Code
|
1813
|
+
30.0,0.35,0.11115
|
1814
|
+
\end_layout
|
1815
|
+
|
1816
|
+
\begin_layout LyX-Code
|
1817
|
+
35.0,0.325,0.08651
|
1818
|
+
\end_layout
|
1819
|
+
|
1820
|
+
\begin_layout LyX-Code
|
1821
|
+
40.0,0.3,0.06733
|
1822
|
+
\end_layout
|
1823
|
+
|
1824
|
+
\begin_layout LyX-Code
|
1825
|
+
45.0,0.275,0.0524
|
1826
|
+
\end_layout
|
1827
|
+
|
1828
|
+
\begin_layout LyX-Code
|
1829
|
+
50.0,0.25,0.04079
|
1830
|
+
\end_layout
|
1831
|
+
|
1832
|
+
\begin_layout LyX-Code
|
1833
|
+
55.0,0.225,0.03174
|
1834
|
+
\end_layout
|
1835
|
+
|
1836
|
+
\begin_layout LyX-Code
|
1837
|
+
60.0,0.2,0.02471
|
1838
|
+
\end_layout
|
1839
|
+
|
1840
|
+
\begin_layout LyX-Code
|
1841
|
+
nil
|
1842
|
+
\end_layout
|
1843
|
+
|
1844
|
+
\begin_layout Standard
|
1845
|
+
Indeed,
|
1846
|
+
\family typewriter
|
1847
|
+
A
|
1848
|
+
\family default
|
1849
|
+
is decreasing at a constant rate, while
|
1850
|
+
\family typewriter
|
1851
|
+
B
|
1852
|
+
\family default
|
1853
|
+
undergoes logarithmic decay.
|
1854
|
+
In a graphical desktop, we can plot a graph (requires
|
1855
|
+
\emph on
|
1856
|
+
gnuplot
|
1857
|
+
\emph default
|
1858
|
+
gem):
|
1859
|
+
\end_layout
|
1860
|
+
|
1861
|
+
\begin_layout LyX-Code
|
1862
|
+
|
1863
|
+
\color blue
|
1864
|
+
plot_recording
|
1865
|
+
\color inherit
|
1866
|
+
; nil
|
1867
|
+
\end_layout
|
1868
|
+
|
1869
|
+
\begin_layout LyX-Code
|
1870
|
+
#=> ""
|
1871
|
+
\end_layout
|
1872
|
+
|
1873
|
+
\begin_layout Standard
|
1874
|
+
We can investigate features of the recording (marking, gradient, firing,
|
1875
|
+
flux, delta):
|
1876
|
+
\end_layout
|
1877
|
+
|
1878
|
+
\begin_layout LyX-Code
|
1879
|
+
simulation.recording.marking.plot
|
1880
|
+
\end_layout
|
1881
|
+
|
1882
|
+
\begin_layout LyX-Code
|
1883
|
+
simulation.recording.gradient.plot
|
1884
|
+
\end_layout
|
1885
|
+
|
1886
|
+
\begin_layout LyX-Code
|
1887
|
+
simulation.recording.flux.plot
|
1888
|
+
\end_layout
|
1889
|
+
|
1890
|
+
\begin_layout LyX-Code
|
1891
|
+
simulation.recording.delta.plot
|
1892
|
+
\end_layout
|
1893
|
+
|
1894
|
+
\begin_layout Standard
|
1895
|
+
(As for firing, which is a feature of tS transitions, the plot would show
|
1896
|
+
nothing here, as all the transitions are timed in this case.)
|
1897
|
+
\end_layout
|
1898
|
+
|
1899
|
+
\begin_layout Part*
|
1900
|
+
Example III
|
1901
|
+
\end_layout
|
1902
|
+
|
1903
|
+
\begin_layout Standard
|
1904
|
+
A highly simplified cell-biological pathway simulated with
|
1905
|
+
\family typewriter
|
1906
|
+
YPetri::TimedSimulation
|
1907
|
+
\family default
|
1908
|
+
.
|
1909
|
+
Let's first define some assumptions.
|
1910
|
+
Type in the following commands (output not shown):
|
1911
|
+
\end_layout
|
1912
|
+
|
1913
|
+
\begin_layout LyX-Code
|
1914
|
+
Cytoplasm_volume_in_litres = 5.0e-11
|
1915
|
+
\end_layout
|
1916
|
+
|
1917
|
+
\begin_layout LyX-Code
|
1918
|
+
NA = 6.022e23
|
1919
|
+
\end_layout
|
1920
|
+
|
1921
|
+
\begin_layout LyX-Code
|
1922
|
+
Pieces_per_micromolar = NA / 1_000_000 * Cytoplasm_volume_in_litres
|
1923
|
+
\end_layout
|
1924
|
+
|
1925
|
+
\begin_layout LyX-Code
|
1926
|
+
|
1927
|
+
\color blue
|
1928
|
+
set_step
|
1929
|
+
\color inherit
|
1930
|
+
60
|
1931
|
+
\end_layout
|
1932
|
+
|
1933
|
+
\begin_layout LyX-Code
|
1934
|
+
|
1935
|
+
\color blue
|
1936
|
+
set_target_time
|
1937
|
+
\color inherit
|
1938
|
+
60 * 60 * 24
|
1939
|
+
\end_layout
|
1940
|
+
|
1941
|
+
\begin_layout Standard
|
1942
|
+
Let's define places corresponding to chemical species first (note that
|
1943
|
+
\family typewriter
|
1944
|
+
:
|
1945
|
+
\color blue
|
1946
|
+
m!
|
1947
|
+
\family default
|
1948
|
+
\color inherit
|
1949
|
+
is a synonym for
|
1950
|
+
\family typewriter
|
1951
|
+
:default_marking)
|
1952
|
+
\end_layout
|
1953
|
+
|
1954
|
+
\begin_layout LyX-Code
|
1955
|
+
AMP = Place
|
1956
|
+
\color blue
|
1957
|
+
m!
|
1958
|
+
\color inherit
|
1959
|
+
: 8695.0
|
1960
|
+
\end_layout
|
1961
|
+
|
1962
|
+
\begin_layout LyX-Code
|
1963
|
+
ADP = Place m!: 6521.0
|
1964
|
+
\end_layout
|
1965
|
+
|
1966
|
+
\begin_layout LyX-Code
|
1967
|
+
ATP = Place m!: 3152.0
|
1968
|
+
\end_layout
|
1969
|
+
|
1970
|
+
\begin_layout LyX-Code
|
1971
|
+
Deoxycytidine = Place m!: 0.5
|
1972
|
+
\end_layout
|
1973
|
+
|
1974
|
+
\begin_layout LyX-Code
|
1975
|
+
DeoxyCTP = Place m!: 1.0
|
1976
|
+
\end_layout
|
1977
|
+
|
1978
|
+
\begin_layout LyX-Code
|
1979
|
+
DeoxyGMP = Place m!: 1.0
|
1980
|
+
\end_layout
|
1981
|
+
|
1982
|
+
\begin_layout LyX-Code
|
1983
|
+
UMP_UDP_pool = Place m!: 2737.0
|
1984
|
+
\end_layout
|
1985
|
+
|
1986
|
+
\begin_layout LyX-Code
|
1987
|
+
DeoxyUMP_DeoxyUDP_pool = Place m!: 0.0
|
1988
|
+
\end_layout
|
1989
|
+
|
1990
|
+
\begin_layout LyX-Code
|
1991
|
+
DeoxyTMP = Place m!: 3.3
|
1992
|
+
\end_layout
|
1993
|
+
|
1994
|
+
\begin_layout LyX-Code
|
1995
|
+
DeoxyTDP_DeoxyTTP_pool = Place m!: 5.0
|
1996
|
+
\end_layout
|
1997
|
+
|
1998
|
+
\begin_layout LyX-Code
|
1999
|
+
Thymidine = Place m!: 0.5
|
2000
|
+
\end_layout
|
2001
|
+
|
2002
|
+
\begin_layout Standard
|
2003
|
+
All the places above have their marking in micromolars.
|
2004
|
+
The enzyme places below will have their marking in molecules per cell:
|
2005
|
+
\end_layout
|
2006
|
+
|
2007
|
+
\begin_layout LyX-Code
|
2008
|
+
TK1 = Place m!: 100_000
|
2009
|
+
\end_layout
|
2010
|
+
|
2011
|
+
\begin_layout LyX-Code
|
2012
|
+
TYMS = Place m!: 100_000
|
2013
|
+
\end_layout
|
2014
|
+
|
2015
|
+
\begin_layout LyX-Code
|
2016
|
+
RNR = Place m!: 100_000
|
2017
|
+
\end_layout
|
2018
|
+
|
2019
|
+
\begin_layout LyX-Code
|
2020
|
+
TMPK = Place m!: 100_000
|
2021
|
+
\end_layout
|
2022
|
+
|
2023
|
+
\begin_layout Standard
|
2024
|
+
Enzyme molecular weights:
|
2025
|
+
\end_layout
|
2026
|
+
|
2027
|
+
\begin_layout LyX-Code
|
2028
|
+
TK1_kDa = 24.8
|
2029
|
+
\end_layout
|
2030
|
+
|
2031
|
+
\begin_layout LyX-Code
|
2032
|
+
TYMS_kDa = 66.0
|
2033
|
+
\end_layout
|
2034
|
+
|
2035
|
+
\begin_layout LyX-Code
|
2036
|
+
RNR_kDa = 140.0
|
2037
|
+
\end_layout
|
2038
|
+
|
2039
|
+
\begin_layout LyX-Code
|
2040
|
+
TMPK_kDa = 50.0
|
2041
|
+
\end_layout
|
2042
|
+
|
2043
|
+
\begin_layout Standard
|
2044
|
+
Enzyme specfic activities (micromolar / minute / mg ):
|
2045
|
+
\end_layout
|
2046
|
+
|
2047
|
+
\begin_layout LyX-Code
|
2048
|
+
TK1_a = 5.40
|
2049
|
+
\end_layout
|
2050
|
+
|
2051
|
+
\begin_layout LyX-Code
|
2052
|
+
TYMS_a = 3.80
|
2053
|
+
\end_layout
|
2054
|
+
|
2055
|
+
\begin_layout LyX-Code
|
2056
|
+
RNR_a = 1.00
|
2057
|
+
\end_layout
|
2058
|
+
|
2059
|
+
\begin_layout LyX-Code
|
2060
|
+
TMPK_a = 0.83
|
2061
|
+
\end_layout
|
2062
|
+
|
2063
|
+
\begin_layout Standard
|
2064
|
+
Some species are kept fixed (as simulation-level clamps):
|
2065
|
+
\end_layout
|
2066
|
+
|
2067
|
+
\begin_layout LyX-Code
|
2068
|
+
|
2069
|
+
\color blue
|
2070
|
+
clamp
|
2071
|
+
\color inherit
|
2072
|
+
AMP: 8695.0, ADP: 6521.0, ATP: 3152.0
|
2073
|
+
\end_layout
|
2074
|
+
|
2075
|
+
\begin_layout LyX-Code
|
2076
|
+
clamp Deoxycytidine: 0.5, DeoxyCTP: 1.0, DeoxyGMP: 1.0
|
2077
|
+
\end_layout
|
2078
|
+
|
2079
|
+
\begin_layout LyX-Code
|
2080
|
+
clamp Thymidine: 0.5
|
2081
|
+
\end_layout
|
2082
|
+
|
2083
|
+
\begin_layout LyX-Code
|
2084
|
+
clamp UMP_UDP_pool: 2737.0
|
2085
|
+
\end_layout
|
2086
|
+
|
2087
|
+
\begin_layout Standard
|
2088
|
+
Before defining transitions, let's define some functions first:
|
2089
|
+
\end_layout
|
2090
|
+
|
2091
|
+
\begin_layout LyX-Code
|
2092
|
+
Vmax_per_minute_per_enzyme_molecule =
|
2093
|
+
\end_layout
|
2094
|
+
|
2095
|
+
\begin_layout LyX-Code
|
2096
|
+
lambda { |enzyme_specific_activity_in_micromol_per_minute_per_mg,
|
2097
|
+
\end_layout
|
2098
|
+
|
2099
|
+
\begin_layout LyX-Code
|
2100
|
+
enzyme_molecular_mass_in_kDa|
|
2101
|
+
\end_layout
|
2102
|
+
|
2103
|
+
\begin_layout LyX-Code
|
2104
|
+
enzyme_specific_activity_in_micromol_per_minute_per_mg *
|
2105
|
+
\end_layout
|
2106
|
+
|
2107
|
+
\begin_layout LyX-Code
|
2108
|
+
enzyme_molecular_mass_in_kDa }
|
2109
|
+
\end_layout
|
2110
|
+
|
2111
|
+
\begin_layout LyX-Code
|
2112
|
+
Vmax_per_minute =
|
2113
|
+
\end_layout
|
2114
|
+
|
2115
|
+
\begin_layout LyX-Code
|
2116
|
+
lambda { |specific_activity, kDa, enzyme_molecules_per_cell|
|
2117
|
+
\end_layout
|
2118
|
+
|
2119
|
+
\begin_layout LyX-Code
|
2120
|
+
Vmax_per_minute_per_enzyme_molecule.( specific_activity, kDa )
|
2121
|
+
*
|
2122
|
+
\end_layout
|
2123
|
+
|
2124
|
+
\begin_layout LyX-Code
|
2125
|
+
enzyme_molecules_per_cell }
|
2126
|
+
\end_layout
|
2127
|
+
|
2128
|
+
\begin_layout LyX-Code
|
2129
|
+
Vmax_per_second =
|
2130
|
+
\end_layout
|
2131
|
+
|
2132
|
+
\begin_layout LyX-Code
|
2133
|
+
lambda { |specific_activity, kDa, enzyme_molecules_per_cell|
|
2134
|
+
\end_layout
|
2135
|
+
|
2136
|
+
\begin_layout LyX-Code
|
2137
|
+
Vmax_per_minute.( specific_activity, kDa,
|
2138
|
+
\end_layout
|
2139
|
+
|
2140
|
+
\begin_layout LyX-Code
|
2141
|
+
enzyme_molecules_per_cell ) / 60 }
|
2142
|
+
\end_layout
|
2143
|
+
|
2144
|
+
\begin_layout LyX-Code
|
2145
|
+
Km_reduced =
|
2146
|
+
\end_layout
|
2147
|
+
|
2148
|
+
\begin_layout LyX-Code
|
2149
|
+
lambda { |km, ki_hash={}|
|
2150
|
+
\end_layout
|
2151
|
+
|
2152
|
+
\begin_layout LyX-Code
|
2153
|
+
ki_hash.map { |concentration, ci_Ki|
|
2154
|
+
\end_layout
|
2155
|
+
|
2156
|
+
\begin_layout LyX-Code
|
2157
|
+
concentration / ci_Ki }.reduce( 1, :+ ) * km }
|
2158
|
+
\end_layout
|
2159
|
+
|
2160
|
+
\begin_layout LyX-Code
|
2161
|
+
Occupancy =
|
2162
|
+
\end_layout
|
2163
|
+
|
2164
|
+
\begin_layout LyX-Code
|
2165
|
+
lambda { |concentration, reactant_Km, compet_inh_w_Ki_hash={}|
|
2166
|
+
\end_layout
|
2167
|
+
|
2168
|
+
\begin_layout LyX-Code
|
2169
|
+
concentration / ( concentration +
|
2170
|
+
\end_layout
|
2171
|
+
|
2172
|
+
\begin_layout LyX-Code
|
2173
|
+
Km_reduced.( reactant_Km,
|
2174
|
+
\end_layout
|
2175
|
+
|
2176
|
+
\begin_layout LyX-Code
|
2177
|
+
compet_inh_w_Ki_hash ) ) }
|
2178
|
+
\end_layout
|
2179
|
+
|
2180
|
+
\begin_layout LyX-Code
|
2181
|
+
MM_with_inh_micromolars_per_second =
|
2182
|
+
\end_layout
|
2183
|
+
|
2184
|
+
\begin_layout LyX-Code
|
2185
|
+
lambda { |reactant_concentration,
|
2186
|
+
\end_layout
|
2187
|
+
|
2188
|
+
\begin_layout LyX-Code
|
2189
|
+
enzyme_specific_activity,
|
2190
|
+
\end_layout
|
2191
|
+
|
2192
|
+
\begin_layout LyX-Code
|
2193
|
+
enzyme_mass_kDa,
|
2194
|
+
\end_layout
|
2195
|
+
|
2196
|
+
\begin_layout LyX-Code
|
2197
|
+
enzyme_molecules_per_cell,
|
2198
|
+
\end_layout
|
2199
|
+
|
2200
|
+
\begin_layout LyX-Code
|
2201
|
+
reactant_Km,
|
2202
|
+
\end_layout
|
2203
|
+
|
2204
|
+
\begin_layout LyX-Code
|
2205
|
+
competitive_inh_w_Ki_hash={}|
|
2206
|
+
\end_layout
|
2207
|
+
|
2208
|
+
\begin_layout LyX-Code
|
2209
|
+
Vmax_per_second.( enzyme_specific_activity,
|
2210
|
+
\end_layout
|
2211
|
+
|
2212
|
+
\begin_layout LyX-Code
|
2213
|
+
enzyme_mass_kDa,
|
2214
|
+
\end_layout
|
2215
|
+
|
2216
|
+
\begin_layout LyX-Code
|
2217
|
+
enzyme_molecules_per_cell ) *
|
2218
|
+
\end_layout
|
2219
|
+
|
2220
|
+
\begin_layout LyX-Code
|
2221
|
+
Occupancy.( reactant_concentration,
|
2222
|
+
\end_layout
|
2223
|
+
|
2224
|
+
\begin_layout LyX-Code
|
2225
|
+
reactant_Km,
|
2226
|
+
\end_layout
|
2227
|
+
|
2228
|
+
\begin_layout LyX-Code
|
2229
|
+
competitive_inh_w_Ki_hash ) }
|
2230
|
+
\end_layout
|
2231
|
+
|
2232
|
+
\begin_layout LyX-Code
|
2233
|
+
MMi = MM_with_inh_micromolars_per_second
|
2234
|
+
\end_layout
|
2235
|
+
|
2236
|
+
\begin_layout Standard
|
2237
|
+
Michaelis constants:
|
2238
|
+
\end_layout
|
2239
|
+
|
2240
|
+
\begin_layout LyX-Code
|
2241
|
+
TK1_Thymidine_Km = 5.0
|
2242
|
+
\end_layout
|
2243
|
+
|
2244
|
+
\begin_layout LyX-Code
|
2245
|
+
TYMS_DeoxyUMP_Km = 2.0
|
2246
|
+
\end_layout
|
2247
|
+
|
2248
|
+
\begin_layout LyX-Code
|
2249
|
+
RNR_UDP_Km = 1.0
|
2250
|
+
\end_layout
|
2251
|
+
|
2252
|
+
\begin_layout LyX-Code
|
2253
|
+
DNA_creation_speed = 3_000_000_000 / ( 12 * 3600 )
|
2254
|
+
\end_layout
|
2255
|
+
|
2256
|
+
\begin_layout LyX-Code
|
2257
|
+
TMPK_DeoxyTMP_Km = 12.0
|
2258
|
+
\end_layout
|
2259
|
+
|
2260
|
+
\begin_layout Standard
|
2261
|
+
And finally, let us define the transitions:
|
2262
|
+
\end_layout
|
2263
|
+
|
2264
|
+
\begin_layout LyX-Code
|
2265
|
+
TK1_Thymidine_DeoxyTMP =
|
2266
|
+
\end_layout
|
2267
|
+
|
2268
|
+
\begin_layout LyX-Code
|
2269
|
+
Transition
|
2270
|
+
\color blue
|
2271
|
+
domain:
|
2272
|
+
\color inherit
|
2273
|
+
[ Thymidine, TK1, DeoxyTDP_DeoxyTTP_pool,
|
2274
|
+
\end_layout
|
2275
|
+
|
2276
|
+
\begin_layout LyX-Code
|
2277
|
+
DeoxyCTP, Deoxycytidine, AMP, ADP, ATP ],
|
2278
|
+
\end_layout
|
2279
|
+
|
2280
|
+
\begin_layout LyX-Code
|
2281
|
+
stoichiometry: { Thymidine: -1, DeoxyTMP: 1 },
|
2282
|
+
\end_layout
|
2283
|
+
|
2284
|
+
\begin_layout LyX-Code
|
2285
|
+
rate: proc { |rc, e, pool1, ci2, ci3, master1, master2, master3|
|
2286
|
+
\end_layout
|
2287
|
+
|
2288
|
+
\begin_layout LyX-Code
|
2289
|
+
ci1 = pool1 * master3 / ( master2 + master3 )
|
2290
|
+
\end_layout
|
2291
|
+
|
2292
|
+
\begin_layout LyX-Code
|
2293
|
+
MMi.( rc, TK1_a, TK1_kDa, e, TK1_Thymidine_Km,
|
2294
|
+
\end_layout
|
2295
|
+
|
2296
|
+
\begin_layout LyX-Code
|
2297
|
+
ci1 => 13.5, ci2 => 0.8, ci3 => 40.0 ) }
|
2298
|
+
\end_layout
|
2299
|
+
|
2300
|
+
\begin_layout LyX-Code
|
2301
|
+
TYMS_DeoxyUMP_DeoxyTMP =
|
2302
|
+
\end_layout
|
2303
|
+
|
2304
|
+
\begin_layout LyX-Code
|
2305
|
+
Transition domain: [ DeoxyUMP_DeoxyUDP_pool, TYMS, AMP, ADP, ATP ],
|
2306
|
+
\end_layout
|
2307
|
+
|
2308
|
+
\begin_layout LyX-Code
|
2309
|
+
stoichiometry: { DeoxyUMP_DeoxyUDP_pool: -1, DeoxyTMP: 1 },
|
2310
|
+
\end_layout
|
2311
|
+
|
2312
|
+
\begin_layout LyX-Code
|
2313
|
+
rate: proc { |pool, e, master1, master2, master3|
|
2314
|
+
\end_layout
|
2315
|
+
|
2316
|
+
\begin_layout LyX-Code
|
2317
|
+
rc = pool * master2 / ( master1 + master2 )
|
2318
|
+
\end_layout
|
2319
|
+
|
2320
|
+
\begin_layout LyX-Code
|
2321
|
+
MMi.( rc, TYMS_a, TYMS_kDa, e, TYMS_DeoxyUMP_Km
|
2322
|
+
) }
|
2323
|
+
\end_layout
|
2324
|
+
|
2325
|
+
\begin_layout LyX-Code
|
2326
|
+
RNR_UDP_DeoxyUDP =
|
2327
|
+
\end_layout
|
2328
|
+
|
2329
|
+
\begin_layout LyX-Code
|
2330
|
+
Transition domain: [ UMP_UDP_pool, RNR, DeoxyUMP_DeoxyUDP_pool, AMP, ADP,
|
2331
|
+
ATP ],
|
2332
|
+
\end_layout
|
2333
|
+
|
2334
|
+
\begin_layout LyX-Code
|
2335
|
+
stoichiometry: { UMP_UDP_pool: -1, DeoxyUMP_DeoxyUDP_pool:
|
2336
|
+
1 },
|
2337
|
+
\end_layout
|
2338
|
+
|
2339
|
+
\begin_layout LyX-Code
|
2340
|
+
rate: proc { |pool, e, master1, master2, master3|
|
2341
|
+
\end_layout
|
2342
|
+
|
2343
|
+
\begin_layout LyX-Code
|
2344
|
+
rc = pool * master2 / ( master1 + master2 )
|
2345
|
+
\end_layout
|
2346
|
+
|
2347
|
+
\begin_layout LyX-Code
|
2348
|
+
MMi.( rc, RNR_a, RNR_kDa, e, RNR_UDP_Km ) }
|
2349
|
+
\end_layout
|
2350
|
+
|
2351
|
+
\begin_layout LyX-Code
|
2352
|
+
DNA_polymerase_consumption_of_DeoxyTTP =
|
2353
|
+
\end_layout
|
2354
|
+
|
2355
|
+
\begin_layout LyX-Code
|
2356
|
+
Transition stoichiometry: { DeoxyTDP_DeoxyTTP_pool: -1 },
|
2357
|
+
\end_layout
|
2358
|
+
|
2359
|
+
\begin_layout LyX-Code
|
2360
|
+
rate: proc { DNA_creation_speed / 4 }
|
2361
|
+
\end_layout
|
2362
|
+
|
2363
|
+
\begin_layout LyX-Code
|
2364
|
+
TMPK_DeoxyTMP_DeoxyTDP =
|
2365
|
+
\end_layout
|
2366
|
+
|
2367
|
+
\begin_layout LyX-Code
|
2368
|
+
Transition domain: [ DeoxyTMP, TMPK, ADP, DeoxyTDP_DeoxyTTP_pool, DeoxyGMP,
|
2369
|
+
AMP, ATP ],
|
2370
|
+
\end_layout
|
2371
|
+
|
2372
|
+
\begin_layout LyX-Code
|
2373
|
+
stoichiometry: { DeoxyTMP: -1, TMPK: 0, DeoxyTDP_DeoxyTTP_pool:
|
2374
|
+
1 },
|
2375
|
+
\end_layout
|
2376
|
+
|
2377
|
+
\begin_layout LyX-Code
|
2378
|
+
rate: proc { |rc, e, ci1, pool, ci4, master1, master3|
|
2379
|
+
\end_layout
|
2380
|
+
|
2381
|
+
\begin_layout LyX-Code
|
2382
|
+
master2 = ci1
|
2383
|
+
\end_layout
|
2384
|
+
|
2385
|
+
\begin_layout LyX-Code
|
2386
|
+
ci2 = pool * master2 / ( master2 + master3 )
|
2387
|
+
\end_layout
|
2388
|
+
|
2389
|
+
\begin_layout LyX-Code
|
2390
|
+
ci3 = pool * master3 / ( master2 + master3 )
|
2391
|
+
\end_layout
|
2392
|
+
|
2393
|
+
\begin_layout LyX-Code
|
2394
|
+
MMi.( rc, TMPK_a, TMPK_kDa, e, TMPK_DeoxyTMP_Km,
|
2395
|
+
\end_layout
|
2396
|
+
|
2397
|
+
\begin_layout LyX-Code
|
2398
|
+
ci1 => 250.0, ci2 => 30.0, ci3 => 750, ci4
|
2399
|
+
=> 117 ) }
|
2400
|
+
\end_layout
|
2401
|
+
|
2402
|
+
\begin_layout Standard
|
2403
|
+
The simulation should work.
|
2404
|
+
\end_layout
|
2405
|
+
|
2406
|
+
\begin_layout LyX-Code
|
2407
|
+
run!
|
2408
|
+
\end_layout
|
2409
|
+
|
2410
|
+
\begin_layout LyX-Code
|
2411
|
+
plot_recording
|
2412
|
+
\end_layout
|
2413
|
+
|
2414
|
+
\begin_layout Part*
|
2415
|
+
Example IV
|
2416
|
+
\end_layout
|
2417
|
+
|
2418
|
+
\begin_layout Standard
|
2419
|
+
Here, I will demonstrate the idea of using
|
2420
|
+
\family typewriter
|
2421
|
+
YPetri
|
2422
|
+
\family default
|
2423
|
+
together with
|
2424
|
+
\family typewriter
|
2425
|
+
\color blue
|
2426
|
+
SY
|
2427
|
+
\family default
|
2428
|
+
metrology library
|
2429
|
+
\color inherit
|
2430
|
+
.
|
2431
|
+
If you are experienced with biochemical modeling, then you surely know
|
2432
|
+
how big pain in the heel physical units are.
|
2433
|
+
Also, in
|
2434
|
+
\series bold
|
2435
|
+
Example III
|
2436
|
+
\series default
|
2437
|
+
, you might have noticed how much attention has been spent on units (in
|
2438
|
+
the assumptions, variable names, constant names...) You could have noticed
|
2439
|
+
messy unit conversion formulas.
|
2440
|
+
The aim of
|
2441
|
+
\family typewriter
|
2442
|
+
SY
|
2443
|
+
\family default
|
2444
|
+
is to take care of all this, to relieve the modeler from this task, to
|
2445
|
+
clean up the model code, and let the modeler concentrate on the real issue.
|
2446
|
+
That's a great dream, which, in biochemical modeling, has not been realized
|
2447
|
+
so far.
|
2448
|
+
\end_layout
|
2449
|
+
|
2450
|
+
\begin_layout Subsection*
|
2451
|
+
|
2452
|
+
\family typewriter
|
2453
|
+
SY
|
2454
|
+
\family default
|
2455
|
+
metrology library
|
2456
|
+
\end_layout
|
2457
|
+
|
2458
|
+
\begin_layout Standard
|
2459
|
+
|
2460
|
+
\family typewriter
|
2461
|
+
SY
|
2462
|
+
\family default
|
2463
|
+
is publicly available as a Ruby gem '
|
2464
|
+
\family typewriter
|
2465
|
+
sy
|
2466
|
+
\family default
|
2467
|
+
'.
|
2468
|
+
After installing it (
|
2469
|
+
\family typewriter
|
2470
|
+
gem install sy
|
2471
|
+
\family default
|
2472
|
+
), type:
|
2473
|
+
\end_layout
|
2474
|
+
|
2475
|
+
\begin_layout LyX-Code
|
2476
|
+
require 'sy'
|
2477
|
+
\end_layout
|
2478
|
+
|
2479
|
+
\begin_layout Standard
|
2480
|
+
Afterwards, your
|
2481
|
+
\family typewriter
|
2482
|
+
\color red
|
2483
|
+
Numeric
|
2484
|
+
\family default
|
2485
|
+
\color inherit
|
2486
|
+
objects (that is, numbers) should respond to methods representing physical
|
2487
|
+
units:
|
2488
|
+
\end_layout
|
2489
|
+
|
2490
|
+
\begin_layout LyX-Code
|
2491
|
+
1.m
|
2492
|
+
\end_layout
|
2493
|
+
|
2494
|
+
\begin_layout LyX-Code
|
2495
|
+
#=> #<±Magnitude: 1.m>
|
2496
|
+
\end_layout
|
2497
|
+
|
2498
|
+
\begin_layout LyX-Code
|
2499
|
+
1.s
|
2500
|
+
\end_layout
|
2501
|
+
|
2502
|
+
\begin_layout LyX-Code
|
2503
|
+
#=> #<±Magnitude: 1.s>
|
2504
|
+
\end_layout
|
2505
|
+
|
2506
|
+
\begin_layout LyX-Code
|
2507
|
+
1.kg.m.s(-2)
|
2508
|
+
\end_layout
|
2509
|
+
|
2510
|
+
\begin_layout LyX-Code
|
2511
|
+
#=> #<±Magnitude: 1.N>
|
2512
|
+
\end_layout
|
2513
|
+
|
2514
|
+
\begin_layout LyX-Code
|
2515
|
+
1.cm + 1.mm
|
2516
|
+
\end_layout
|
2517
|
+
|
2518
|
+
\begin_layout LyX-Code
|
2519
|
+
#=> #<±Magnitude: 0.011.m>
|
2520
|
+
\end_layout
|
2521
|
+
|
2522
|
+
\begin_layout Standard
|
2523
|
+
The core of the trick is that instead of naked numbers, numbers become magnitude
|
2524
|
+
s (
|
2525
|
+
\family typewriter
|
2526
|
+
SY::Magnitude
|
2527
|
+
\family default
|
2528
|
+
) of specified physical quantities:
|
2529
|
+
\end_layout
|
2530
|
+
|
2531
|
+
\begin_layout LyX-Code
|
2532
|
+
1.m.class
|
2533
|
+
\end_layout
|
2534
|
+
|
2535
|
+
\begin_layout LyX-Code
|
2536
|
+
#=> Length±@Magnitude
|
2537
|
+
\end_layout
|
2538
|
+
|
2539
|
+
\begin_layout LyX-Code
|
2540
|
+
1.cm.min⁻¹.class
|
2541
|
+
\end_layout
|
2542
|
+
|
2543
|
+
\begin_layout LyX-Code
|
2544
|
+
#=> Speed±@Magnitude
|
2545
|
+
\end_layout
|
2546
|
+
|
2547
|
+
\begin_layout Standard
|
2548
|
+
(You can type
|
2549
|
+
\family typewriter
|
2550
|
+
1.cm.min(-1)
|
2551
|
+
\family default
|
2552
|
+
if you find it difficult to type Unicode superscript characters "
|
2553
|
+
\family typewriter
|
2554
|
+
⁻¹
|
2555
|
+
\family default
|
2556
|
+
".) Magnitudes can be converted back to numbers with
|
2557
|
+
\family typewriter
|
2558
|
+
\color blue
|
2559
|
+
amount
|
2560
|
+
\family default
|
2561
|
+
\color inherit
|
2562
|
+
(alias
|
2563
|
+
\family typewriter
|
2564
|
+
\color blue
|
2565
|
+
to_f)
|
2566
|
+
\family default
|
2567
|
+
\color inherit
|
2568
|
+
method:
|
2569
|
+
\end_layout
|
2570
|
+
|
2571
|
+
\begin_layout LyX-Code
|
2572
|
+
1.km.amount
|
2573
|
+
\end_layout
|
2574
|
+
|
2575
|
+
\begin_layout LyX-Code
|
2576
|
+
#=> 1000.0
|
2577
|
+
\end_layout
|
2578
|
+
|
2579
|
+
\begin_layout LyX-Code
|
2580
|
+
1.cm.to_f
|
2581
|
+
\end_layout
|
2582
|
+
|
2583
|
+
\begin_layout LyX-Code
|
2584
|
+
#=> 0.01
|
2585
|
+
\end_layout
|
2586
|
+
|
2587
|
+
\begin_layout Subsection*
|
2588
|
+
Collaboration between
|
2589
|
+
\family typewriter
|
2590
|
+
SY
|
2591
|
+
\family default
|
2592
|
+
and
|
2593
|
+
\family typewriter
|
2594
|
+
YPetri
|
2595
|
+
\end_layout
|
2596
|
+
|
2597
|
+
\begin_layout Standard
|
2598
|
+
Enter:
|
2599
|
+
\end_layout
|
2600
|
+
|
2601
|
+
\begin_layout LyX-Code
|
2602
|
+
A = Place m!: 3.mM
|
2603
|
+
\end_layout
|
2604
|
+
|
2605
|
+
\begin_layout LyX-Code
|
2606
|
+
#=> #<Place: name: A, marking: 0.003.M, default_marking: 0.003.M >
|
2607
|
+
\end_layout
|
2608
|
+
|
2609
|
+
\begin_layout LyX-Code
|
2610
|
+
B = Place m!: 4.mM
|
2611
|
+
\end_layout
|
2612
|
+
|
2613
|
+
\begin_layout LyX-Code
|
2614
|
+
#=> #<Place: name: B, marking: 0.004.M, default_marking: 0.004.M >
|
2615
|
+
\end_layout
|
2616
|
+
|
2617
|
+
\begin_layout LyX-Code
|
2618
|
+
A2B = Transition s: { A: -1, B: 1 }, rate: 0.05.s⁻¹
|
2619
|
+
\end_layout
|
2620
|
+
|
2621
|
+
\begin_layout LyX-Code
|
2622
|
+
#=> #<Transition: A2B (SR) >
|
2623
|
+
\end_layout
|
2624
|
+
|
2625
|
+
\begin_layout LyX-Code
|
2626
|
+
B_decay = Transition s: { B: -1 }, rate: 0.002.s⁻¹
|
2627
|
+
\end_layout
|
2628
|
+
|
2629
|
+
\begin_layout LyX-Code
|
2630
|
+
#=> YPetri::Transition[ B_decay: stoichiometric transition with rate ]
|
2631
|
+
\end_layout
|
2632
|
+
|
2633
|
+
\begin_layout Standard
|
2634
|
+
Now we have created places and transitions, whose marking and rate closures
|
2635
|
+
are defined in physical units.
|
2636
|
+
Presently,
|
2637
|
+
\family typewriter
|
2638
|
+
YPetri::TimedSimulation
|
2639
|
+
\family default
|
2640
|
+
will not accept such a Petri net, so the only thing we can do is play the
|
2641
|
+
token game ourselves:
|
2642
|
+
\end_layout
|
2643
|
+
|
2644
|
+
\begin_layout LyX-Code
|
2645
|
+
fire_both_transitions = proc { |delta_t|
|
2646
|
+
\end_layout
|
2647
|
+
|
2648
|
+
\begin_layout LyX-Code
|
2649
|
+
A2B.fire! delta_t
|
2650
|
+
\end_layout
|
2651
|
+
|
2652
|
+
\begin_layout LyX-Code
|
2653
|
+
B_decay.fire! delta_t
|
2654
|
+
\end_layout
|
2655
|
+
|
2656
|
+
\begin_layout LyX-Code
|
2657
|
+
}
|
2658
|
+
\end_layout
|
2659
|
+
|
2660
|
+
\begin_layout LyX-Code
|
2661
|
+
#=> #<Proc:0x9b48f1c@(irb):19>
|
2662
|
+
\end_layout
|
2663
|
+
|
2664
|
+
\begin_layout Standard
|
2665
|
+
Here, we have defined a closure accepting one argument
|
2666
|
+
\begin_inset Formula $\Delta$
|
2667
|
+
\end_inset
|
2668
|
+
|
2669
|
+
t, which it will use to
|
2670
|
+
\family typewriter
|
2671
|
+
fire!
|
2672
|
+
\family default
|
2673
|
+
both
|
2674
|
+
\family typewriter
|
2675
|
+
A2B
|
2676
|
+
\family default
|
2677
|
+
and
|
2678
|
+
\family typewriter
|
2679
|
+
B_decay
|
2680
|
+
\family default
|
2681
|
+
.
|
2682
|
+
By calling this closure repeatedly, we can simulate the network without
|
2683
|
+
use of
|
2684
|
+
\family typewriter
|
2685
|
+
TimedSimulation
|
2686
|
+
\family default
|
2687
|
+
:
|
2688
|
+
\end_layout
|
2689
|
+
|
2690
|
+
\begin_layout LyX-Code
|
2691
|
+
places.map &:marking
|
2692
|
+
\end_layout
|
2693
|
+
|
2694
|
+
\begin_layout LyX-Code
|
2695
|
+
#=> [#<±Magnitude: 0.003.M>, #<±Magnitude: 0.004.M>]
|
2696
|
+
\end_layout
|
2697
|
+
|
2698
|
+
\begin_layout LyX-Code
|
2699
|
+
fire_both_transitions.( 1.s )
|
2700
|
+
\end_layout
|
2701
|
+
|
2702
|
+
\begin_layout LyX-Code
|
2703
|
+
#=> nil
|
2704
|
+
\end_layout
|
2705
|
+
|
2706
|
+
\begin_layout LyX-Code
|
2707
|
+
places.map &:marking
|
2708
|
+
\end_layout
|
2709
|
+
|
2710
|
+
\begin_layout LyX-Code
|
2711
|
+
#=> [#<±Magnitude: 0.00285.M>, #<±Magnitude: 0.00414.M>]
|
2712
|
+
\end_layout
|
2713
|
+
|
2714
|
+
\begin_layout LyX-Code
|
2715
|
+
100.times do fire_both_transitions.( 1.s ) end
|
2716
|
+
\end_layout
|
2717
|
+
|
2718
|
+
\begin_layout LyX-Code
|
2719
|
+
#=> 100
|
2720
|
+
\end_layout
|
2721
|
+
|
2722
|
+
\begin_layout LyX-Code
|
2723
|
+
places.map &:marking
|
2724
|
+
\end_layout
|
2725
|
+
|
2726
|
+
\begin_layout LyX-Code
|
2727
|
+
#=> [#<±Magnitude: 1.69e-05.M>, #<±Magnitude: 0.0058.M>]
|
2728
|
+
\end_layout
|
2729
|
+
|
2730
|
+
\begin_layout LyX-Code
|
2731
|
+
A.marking.
|
2732
|
+
\color blue
|
2733
|
+
in
|
2734
|
+
\color inherit
|
2735
|
+
:µM
|
2736
|
+
\end_layout
|
2737
|
+
|
2738
|
+
\begin_layout LyX-Code
|
2739
|
+
#=> 16.873508277951963
|
2740
|
+
\end_layout
|
2741
|
+
|
2742
|
+
\begin_layout LyX-Code
|
2743
|
+
B.marking.in :µM
|
2744
|
+
\end_layout
|
2745
|
+
|
2746
|
+
\begin_layout LyX-Code
|
2747
|
+
#=> 5797.976678013365
|
2748
|
+
\end_layout
|
2749
|
+
|
2750
|
+
\begin_layout LyX-Code
|
2751
|
+
|
2752
|
+
\end_layout
|
2753
|
+
|
2754
|
+
\begin_layout LyX-Code
|
2755
|
+
\begin_inset CommandInset bibtex
|
2756
|
+
LatexCommand bibtex
|
2757
|
+
bibfiles "/home/boris/b/1num/num,/home/boris/b/2prp/prp"
|
2758
|
+
options "plainnat"
|
2759
|
+
|
2760
|
+
\end_inset
|
2761
|
+
|
2762
|
+
|
2763
|
+
\end_layout
|
2764
|
+
|
2765
|
+
\end_body
|
2766
|
+
\end_document
|