y_nelson 2.3.7 → 2.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Introduction_to_Ruby_for_YPetri_and_YNelson_Users.pdf +0 -0
- data/Introduction_to_YPetri_and_YNelson.pdf +0 -0
- data/Object_model_of_YPetri_and_YNelson.pdf +0 -0
- data/lib/y_nelson.rb +0 -1
- data/lib/y_nelson/agent.rb +12 -1
- data/lib/y_nelson/version.rb +1 -1
- data/test/y_nelson_test.rb +1 -1
- metadata +2 -5
- data/Introduction_to_Ruby_for_YPetri_and_YNelson_Users.lyx +0 -3265
- data/Introduction_to_YPetri_and_YNelson.lyx +0 -3593
- data/Object_model_of_YPetri_and_YNelson.lyx +0 -3842
@@ -1,3593 +0,0 @@
|
|
1
|
-
#LyX 2.1 created this file. For more info see http://www.lyx.org/
|
2
|
-
\lyxformat 474
|
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_math auto
|
16
|
-
\font_default_family default
|
17
|
-
\use_non_tex_fonts false
|
18
|
-
\font_sc false
|
19
|
-
\font_osf false
|
20
|
-
\font_sf_scale 100
|
21
|
-
\font_tt_scale 100
|
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_package amsmath 1
|
33
|
-
\use_package amssymb 1
|
34
|
-
\use_package cancel 1
|
35
|
-
\use_package esint 1
|
36
|
-
\use_package mathdots 1
|
37
|
-
\use_package mathtools 1
|
38
|
-
\use_package mhchem 1
|
39
|
-
\use_package stackrel 1
|
40
|
-
\use_package stmaryrd 1
|
41
|
-
\use_package undertilde 1
|
42
|
-
\cite_engine natbib
|
43
|
-
\cite_engine_type authoryear
|
44
|
-
\biblio_style plainnat
|
45
|
-
\use_bibtopic false
|
46
|
-
\use_indices false
|
47
|
-
\paperorientation portrait
|
48
|
-
\suppress_date false
|
49
|
-
\justification true
|
50
|
-
\use_refstyle 0
|
51
|
-
\index Index
|
52
|
-
\shortcut idx
|
53
|
-
\color #008000
|
54
|
-
\end_index
|
55
|
-
\leftmargin 2.2cm
|
56
|
-
\topmargin 3cm
|
57
|
-
\rightmargin 2.2cm
|
58
|
-
\bottommargin 3cm
|
59
|
-
\secnumdepth 3
|
60
|
-
\tocdepth 3
|
61
|
-
\paragraph_separation indent
|
62
|
-
\paragraph_indentation default
|
63
|
-
\quotes_language english
|
64
|
-
\papercolumns 1
|
65
|
-
\papersides 1
|
66
|
-
\paperpagestyle default
|
67
|
-
\tracking_changes false
|
68
|
-
\output_changes false
|
69
|
-
\html_math_output 0
|
70
|
-
\html_css_as_file 0
|
71
|
-
\html_be_strict false
|
72
|
-
\end_header
|
73
|
-
|
74
|
-
\begin_body
|
75
|
-
|
76
|
-
\begin_layout Title
|
77
|
-
Introduction to YNelson and YPetri (hands-on tutorial)
|
78
|
-
\end_layout
|
79
|
-
|
80
|
-
\begin_layout Part*
|
81
|
-
Introduction
|
82
|
-
\end_layout
|
83
|
-
|
84
|
-
\begin_layout Standard
|
85
|
-
This document is a hands-on guide to
|
86
|
-
\family typewriter
|
87
|
-
\color blue
|
88
|
-
YPetri
|
89
|
-
\family default
|
90
|
-
\color inherit
|
91
|
-
,
|
92
|
-
\family typewriter
|
93
|
-
\color blue
|
94
|
-
YNelson
|
95
|
-
\family default
|
96
|
-
\color inherit
|
97
|
-
and
|
98
|
-
\emph on
|
99
|
-
\color green
|
100
|
-
Nelson nets
|
101
|
-
\emph default
|
102
|
-
\color inherit
|
103
|
-
, which in turn rely on
|
104
|
-
\color red
|
105
|
-
Ruby
|
106
|
-
\color inherit
|
107
|
-
language.
|
108
|
-
It is not assumed you are familiar with Ruby, you can follow this guide
|
109
|
-
even if you never heard about it (but you will have to install it).
|
110
|
-
You more than likely never heard about Nelson nets.
|
111
|
-
Nelson net is a novel concept of
|
112
|
-
\emph on
|
113
|
-
\color green
|
114
|
-
Petri nets
|
115
|
-
\emph default
|
116
|
-
\color inherit
|
117
|
-
crossed with Ted Nelson's
|
118
|
-
\emph on
|
119
|
-
\color green
|
120
|
-
ZZ structures
|
121
|
-
\emph default
|
122
|
-
\color inherit
|
123
|
-
.
|
124
|
-
Do not worry about them: just follow the guide and you will learn everything
|
125
|
-
in time.
|
126
|
-
The text of this guide lets you know when new keywords and are introduced.
|
127
|
-
When mentioned for the first time,
|
128
|
-
\color red
|
129
|
-
Ruby keywords and terms
|
130
|
-
\color inherit
|
131
|
-
are highlighted in red,
|
132
|
-
\color green
|
133
|
-
Petri net terms
|
134
|
-
\color inherit
|
135
|
-
in green, and
|
136
|
-
\family typewriter
|
137
|
-
\color blue
|
138
|
-
YPetri / YNelson
|
139
|
-
\family default
|
140
|
-
keywords and terms
|
141
|
-
\color inherit
|
142
|
-
in blue throughout this document.
|
143
|
-
\end_layout
|
144
|
-
|
145
|
-
\begin_layout Standard
|
146
|
-
|
147
|
-
\family typewriter
|
148
|
-
\color blue
|
149
|
-
YNelson
|
150
|
-
\family default
|
151
|
-
\color inherit
|
152
|
-
serves to specify and simulate Nelson nets, a derivative of
|
153
|
-
\emph on
|
154
|
-
\color green
|
155
|
-
functional
|
156
|
-
\emph default
|
157
|
-
|
158
|
-
\emph on
|
159
|
-
Petri nets
|
160
|
-
\emph default
|
161
|
-
\color inherit
|
162
|
-
that live in
|
163
|
-
\emph on
|
164
|
-
\color green
|
165
|
-
ZZ space
|
166
|
-
\emph default
|
167
|
-
\color inherit
|
168
|
-
.
|
169
|
-
(You don't need to worry about ZZ space yet.)
|
170
|
-
\family typewriter
|
171
|
-
\color blue
|
172
|
-
YPetri
|
173
|
-
\family default
|
174
|
-
\color inherit
|
175
|
-
serves to specify and simulate Petri nets.
|
176
|
-
Petri nets are one of the basic formalisms in systems simulation.
|
177
|
-
I designed
|
178
|
-
\family typewriter
|
179
|
-
YPetri
|
180
|
-
\family default
|
181
|
-
and
|
182
|
-
\family typewriter
|
183
|
-
YNelson
|
184
|
-
\family default
|
185
|
-
because I needed to specify biochemical systems and I believed a Ruby DSL
|
186
|
-
would be ideal for that task.
|
187
|
-
Use of Petri nets for specifying biochemical systems is reviewed eg.
|
188
|
-
in
|
189
|
-
\begin_inset CommandInset citation
|
190
|
-
LatexCommand citet
|
191
|
-
key "Bos2008mbs"
|
192
|
-
|
193
|
-
\end_inset
|
194
|
-
|
195
|
-
and
|
196
|
-
\begin_inset CommandInset citation
|
197
|
-
LatexCommand citet
|
198
|
-
key "Koch2015pns"
|
199
|
-
|
200
|
-
\end_inset
|
201
|
-
|
202
|
-
.
|
203
|
-
|
204
|
-
\family typewriter
|
205
|
-
YPetri
|
206
|
-
\family default
|
207
|
-
provides a universal Petri net abstraction similar, but not identical with
|
208
|
-
|
209
|
-
\emph on
|
210
|
-
\color green
|
211
|
-
hybrid functional Petri net (HFPN)
|
212
|
-
\emph default
|
213
|
-
\color inherit
|
214
|
-
introduced by
|
215
|
-
\begin_inset CommandInset citation
|
216
|
-
LatexCommand citet
|
217
|
-
key "Matsuno2011brs"
|
218
|
-
|
219
|
-
\end_inset
|
220
|
-
|
221
|
-
.
|
222
|
-
|
223
|
-
\family typewriter
|
224
|
-
YPetri
|
225
|
-
\family default
|
226
|
-
/
|
227
|
-
\family typewriter
|
228
|
-
YNelson
|
229
|
-
\family default
|
230
|
-
serve equally well not just for biochemical systems, but for arbitrary
|
231
|
-
dynamical systems.
|
232
|
-
\end_layout
|
233
|
-
|
234
|
-
\begin_layout Standard
|
235
|
-
Finally, please forgive me for taking your time with this guide.
|
236
|
-
If you want to seriously work with
|
237
|
-
\emph on
|
238
|
-
complicated
|
239
|
-
\emph default
|
240
|
-
Petri Nets, no tool can avoid taking you through the process of learning
|
241
|
-
the language and the tool's interface.
|
242
|
-
Visual Petri net modelling tools are nice for simple tasks, such as drawing
|
243
|
-
arcs between places and transitions, but you need text anyway to write
|
244
|
-
the mathematical functions that govern firing of transitions.
|
245
|
-
|
246
|
-
\family typewriter
|
247
|
-
YPetri
|
248
|
-
\family default
|
249
|
-
/
|
250
|
-
\family typewriter
|
251
|
-
YNelson
|
252
|
-
\family default
|
253
|
-
are all textual without commiting the sin of introducing a new programming
|
254
|
-
language.
|
255
|
-
They are implemented as
|
256
|
-
\emph on
|
257
|
-
\color red
|
258
|
-
internal domain-specific languages (DSL)
|
259
|
-
\emph default
|
260
|
-
\color inherit
|
261
|
-
using Ruby as a host language.
|
262
|
-
You can run them interactively from
|
263
|
-
\color red
|
264
|
-
Ruby interpreter (
|
265
|
-
\emph on
|
266
|
-
irb
|
267
|
-
\emph default
|
268
|
-
)
|
269
|
-
\color inherit
|
270
|
-
.
|
271
|
-
In this way, you can freely use the host language to automate your interaction
|
272
|
-
with Petri nets.
|
273
|
-
\end_layout
|
274
|
-
|
275
|
-
\begin_layout Standard
|
276
|
-
|
277
|
-
\family typewriter
|
278
|
-
YPetri
|
279
|
-
\family default
|
280
|
-
/
|
281
|
-
\family typewriter
|
282
|
-
YNelson
|
283
|
-
\family default
|
284
|
-
are publicly available as
|
285
|
-
\emph on
|
286
|
-
\color blue
|
287
|
-
|
288
|
-
\begin_inset CommandInset href
|
289
|
-
LatexCommand href
|
290
|
-
name "y_petri"
|
291
|
-
target "https://rubygems.org/gems/y_petri"
|
292
|
-
|
293
|
-
\end_inset
|
294
|
-
|
295
|
-
|
296
|
-
\emph default
|
297
|
-
\color inherit
|
298
|
-
and
|
299
|
-
\emph on
|
300
|
-
\color blue
|
301
|
-
|
302
|
-
\begin_inset CommandInset href
|
303
|
-
LatexCommand href
|
304
|
-
name "y_nelson gem"
|
305
|
-
target "https://rubygems.org/gems/y_nelson"
|
306
|
-
|
307
|
-
\end_inset
|
308
|
-
|
309
|
-
|
310
|
-
\emph default
|
311
|
-
\color inherit
|
312
|
-
gems (
|
313
|
-
\emph on
|
314
|
-
\color red
|
315
|
-
gem
|
316
|
-
\emph default
|
317
|
-
\color inherit
|
318
|
-
= Ruby library).
|
319
|
-
|
320
|
-
\family typewriter
|
321
|
-
YNelson
|
322
|
-
\family default
|
323
|
-
depends on
|
324
|
-
\family typewriter
|
325
|
-
YPetri
|
326
|
-
\family default
|
327
|
-
and
|
328
|
-
\family typewriter
|
329
|
-
Yzz
|
330
|
-
\family default
|
331
|
-
gems, which in turn depend on our
|
332
|
-
\family typewriter
|
333
|
-
YSupport
|
334
|
-
\family default
|
335
|
-
gem.
|
336
|
-
Splitting the more general concerns to multiple gem is a desirable feature
|
337
|
-
– separation of concerns is a maxim of good software engineering.
|
338
|
-
I also separated dealing with physical units in your models out into
|
339
|
-
\family typewriter
|
340
|
-
SY
|
341
|
-
\family default
|
342
|
-
gem (
|
343
|
-
\emph on
|
344
|
-
\color blue
|
345
|
-
|
346
|
-
\begin_inset CommandInset href
|
347
|
-
LatexCommand href
|
348
|
-
name "sy"
|
349
|
-
target "https://rubygems.org/gems/sy"
|
350
|
-
|
351
|
-
\end_inset
|
352
|
-
|
353
|
-
|
354
|
-
\emph default
|
355
|
-
\color inherit
|
356
|
-
).
|
357
|
-
\end_layout
|
358
|
-
|
359
|
-
\begin_layout Part*
|
360
|
-
Using This Guide, or
|
361
|
-
\begin_inset Quotes eld
|
362
|
-
\end_inset
|
363
|
-
|
364
|
-
The Hard Way Is Easier
|
365
|
-
\begin_inset Quotes erd
|
366
|
-
\end_inset
|
367
|
-
|
368
|
-
|
369
|
-
\end_layout
|
370
|
-
|
371
|
-
\begin_layout Standard
|
372
|
-
The phrase above is borrowed from the textbook by Zed Shaw named
|
373
|
-
\begin_inset Quotes eld
|
374
|
-
\end_inset
|
375
|
-
|
376
|
-
Learn Ruby the Hard Way
|
377
|
-
\begin_inset Quotes erd
|
378
|
-
\end_inset
|
379
|
-
|
380
|
-
(highly recommended,
|
381
|
-
\emph on
|
382
|
-
\color magenta
|
383
|
-
|
384
|
-
\begin_inset CommandInset href
|
385
|
-
LatexCommand href
|
386
|
-
name "hyperlink here"
|
387
|
-
target "http://ruby.learncodethehardway.org/"
|
388
|
-
|
389
|
-
\end_inset
|
390
|
-
|
391
|
-
|
392
|
-
\emph default
|
393
|
-
\color inherit
|
394
|
-
).
|
395
|
-
Apart from being a great shark-jumper, Zed is a great teacher familiar
|
396
|
-
with many programming languages, and I will borrow his teaching method
|
397
|
-
here.
|
398
|
-
Citing Zed,
|
399
|
-
\begin_inset Quotes eld
|
400
|
-
\end_inset
|
401
|
-
|
402
|
-
The title says it's the hard way...
|
403
|
-
but actually it's not.
|
404
|
-
\begin_inset Quotes erd
|
405
|
-
\end_inset
|
406
|
-
|
407
|
-
It's only
|
408
|
-
\begin_inset Quotes eld
|
409
|
-
\end_inset
|
410
|
-
|
411
|
-
hard
|
412
|
-
\begin_inset Quotes erd
|
413
|
-
\end_inset
|
414
|
-
|
415
|
-
because of the way people
|
416
|
-
\emph on
|
417
|
-
used
|
418
|
-
\emph default
|
419
|
-
to teach things.
|
420
|
-
|
421
|
-
\family typewriter
|
422
|
-
YNelson
|
423
|
-
\family default
|
424
|
-
is a language.
|
425
|
-
To learn it and see its usefulness, you will still need to do the incredibly
|
426
|
-
simple things that all language learners do:
|
427
|
-
\end_layout
|
428
|
-
|
429
|
-
\begin_layout Enumerate
|
430
|
-
Go through each example.
|
431
|
-
\end_layout
|
432
|
-
|
433
|
-
\begin_layout Enumerate
|
434
|
-
Type each sample code exactly.
|
435
|
-
\end_layout
|
436
|
-
|
437
|
-
\begin_layout Enumerate
|
438
|
-
Make it run.
|
439
|
-
\end_layout
|
440
|
-
|
441
|
-
\begin_layout Standard
|
442
|
-
\noindent
|
443
|
-
That's it.
|
444
|
-
This might feel
|
445
|
-
\emph on
|
446
|
-
very
|
447
|
-
\emph default
|
448
|
-
difficult at first, but stick with it.
|
449
|
-
It seems stupidly obvious, but if you have a problem installing
|
450
|
-
\family typewriter
|
451
|
-
YPetri
|
452
|
-
\family default
|
453
|
-
and
|
454
|
-
\family typewriter
|
455
|
-
YNelson
|
456
|
-
\family default
|
457
|
-
, running
|
458
|
-
\emph on
|
459
|
-
irb
|
460
|
-
\emph default
|
461
|
-
and typing, you will have a problem learning.
|
462
|
-
If you go through this document without actually doing the exercises, you
|
463
|
-
might as well just not even read it.
|
464
|
-
Do not skip and do not skim.
|
465
|
-
By typing each example
|
466
|
-
\emph on
|
467
|
-
exactly
|
468
|
-
\emph default
|
469
|
-
, you will be training your brain to focus on the details of what you are
|
470
|
-
doing, as you are doing it.
|
471
|
-
While you do these examples, typing each one in, you will be making mistakes.
|
472
|
-
It's inevitable; humans do make mistakes.
|
473
|
-
By doing so, you will train yourself to notice mistakes and other problems.
|
474
|
-
Do not copy-paste.
|
475
|
-
Type each code sample in, manually.
|
476
|
-
The point is to train your hands, your brain, and your mind in how to read,
|
477
|
-
write and see Ruby and
|
478
|
-
\family typewriter
|
479
|
-
YNelson
|
480
|
-
\family default
|
481
|
-
code.
|
482
|
-
If you skip, skim and copy-paste, you are cheating yourself out of the
|
483
|
-
effectiveness of this guide.
|
484
|
-
\end_layout
|
485
|
-
|
486
|
-
\begin_layout Part*
|
487
|
-
Prerequisites
|
488
|
-
\end_layout
|
489
|
-
|
490
|
-
\begin_layout Standard
|
491
|
-
Firstly, you will need a working installation of Ruby 2.3 or later on your
|
492
|
-
computer.
|
493
|
-
Once this condition is met, basic
|
494
|
-
\family typewriter
|
495
|
-
YNelson
|
496
|
-
\family default
|
497
|
-
installation is as simple as typing
|
498
|
-
\begin_inset Quotes eld
|
499
|
-
\end_inset
|
500
|
-
|
501
|
-
|
502
|
-
\family typewriter
|
503
|
-
gem install y_nelson
|
504
|
-
\family default
|
505
|
-
|
506
|
-
\begin_inset Quotes erd
|
507
|
-
\end_inset
|
508
|
-
|
509
|
-
in the command prompt.
|
510
|
-
This will install most other dependencies, such as
|
511
|
-
\family typewriter
|
512
|
-
YPetri
|
513
|
-
\family default
|
514
|
-
.
|
515
|
-
However,
|
516
|
-
\family typewriter
|
517
|
-
YNelson
|
518
|
-
\family default
|
519
|
-
currently uses dependencies (gnuplot gem, graphviz gem...), whose installation
|
520
|
-
may pose challenges.
|
521
|
-
Once
|
522
|
-
\family typewriter
|
523
|
-
YNelson
|
524
|
-
\family default
|
525
|
-
is installed, run
|
526
|
-
\emph on
|
527
|
-
irb
|
528
|
-
\emph default
|
529
|
-
command interpreter, and type:
|
530
|
-
\end_layout
|
531
|
-
|
532
|
-
\begin_layout LyX-Code
|
533
|
-
|
534
|
-
\color red
|
535
|
-
require
|
536
|
-
\color inherit
|
537
|
-
'y_nelson' and
|
538
|
-
\color red
|
539
|
-
include
|
540
|
-
\color inherit
|
541
|
-
YNelson
|
542
|
-
\end_layout
|
543
|
-
|
544
|
-
\begin_layout Standard
|
545
|
-
This will augment your irb command session with interactive
|
546
|
-
\family typewriter
|
547
|
-
YNelson
|
548
|
-
\family default
|
549
|
-
command interface (
|
550
|
-
\family typewriter
|
551
|
-
YNelson
|
552
|
-
\family default
|
553
|
-
DSL CI).
|
554
|
-
You may also choose to work only with
|
555
|
-
\family typewriter
|
556
|
-
YPetri
|
557
|
-
\family default
|
558
|
-
alone, in which case the require line is:
|
559
|
-
\end_layout
|
560
|
-
|
561
|
-
\begin_layout LyX-Code
|
562
|
-
|
563
|
-
\color red
|
564
|
-
require
|
565
|
-
\color inherit
|
566
|
-
'y_petri' and
|
567
|
-
\color red
|
568
|
-
include
|
569
|
-
\color inherit
|
570
|
-
YPetri
|
571
|
-
\end_layout
|
572
|
-
|
573
|
-
\begin_layout Standard
|
574
|
-
You have to re-run
|
575
|
-
\emph on
|
576
|
-
irb
|
577
|
-
\emph default
|
578
|
-
from the scratch, and re-type '
|
579
|
-
\family typewriter
|
580
|
-
require
|
581
|
-
\family default
|
582
|
-
' and '
|
583
|
-
\family typewriter
|
584
|
-
include
|
585
|
-
\family default
|
586
|
-
' statements before each of the usage examples written below.
|
587
|
-
The nucleotide metabolism model in Example 3 is not realiscit (its kinetics
|
588
|
-
is not precise).
|
589
|
-
If something in this guide does not work, please do not hesitate to notify
|
590
|
-
me, I will appreciate your feedback.
|
591
|
-
\end_layout
|
592
|
-
|
593
|
-
\begin_layout Part*
|
594
|
-
Example I: Basics
|
595
|
-
\end_layout
|
596
|
-
|
597
|
-
\begin_layout Standard
|
598
|
-
This example is a gentle introduction to Petri net terminology,
|
599
|
-
\family typewriter
|
600
|
-
YNelson
|
601
|
-
\family default
|
602
|
-
DSL terminology, and Ruby syntax.
|
603
|
-
The most basic capability that
|
604
|
-
\family typewriter
|
605
|
-
YNelson
|
606
|
-
\family default
|
607
|
-
offers, is that of user-driven
|
608
|
-
\emph on
|
609
|
-
\color green
|
610
|
-
token game
|
611
|
-
\emph default
|
612
|
-
\color inherit
|
613
|
-
.
|
614
|
-
We will thus create a small Petri net containing 2
|
615
|
-
\emph on
|
616
|
-
\color green
|
617
|
-
places
|
618
|
-
\emph default
|
619
|
-
\color inherit
|
620
|
-
and play token game with it.
|
621
|
-
\end_layout
|
622
|
-
|
623
|
-
\begin_layout Subsection*
|
624
|
-
Places
|
625
|
-
\end_layout
|
626
|
-
|
627
|
-
\begin_layout Standard
|
628
|
-
Type:
|
629
|
-
\end_layout
|
630
|
-
|
631
|
-
\begin_layout LyX-Code
|
632
|
-
A =
|
633
|
-
\color blue
|
634
|
-
Place
|
635
|
-
\color inherit
|
636
|
-
( marking: 2 )
|
637
|
-
\end_layout
|
638
|
-
|
639
|
-
\begin_layout Standard
|
640
|
-
Syntactically, this will call
|
641
|
-
\emph on
|
642
|
-
\color red
|
643
|
-
method
|
644
|
-
\emph default
|
645
|
-
\color inherit
|
646
|
-
'
|
647
|
-
\family typewriter
|
648
|
-
Place
|
649
|
-
\family default
|
650
|
-
' of
|
651
|
-
\family typewriter
|
652
|
-
YNelson
|
653
|
-
\family default
|
654
|
-
DSL and assign its
|
655
|
-
\emph on
|
656
|
-
\color red
|
657
|
-
return value
|
658
|
-
\emph default
|
659
|
-
\color inherit
|
660
|
-
to the
|
661
|
-
\emph on
|
662
|
-
\color red
|
663
|
-
constant
|
664
|
-
\emph default
|
665
|
-
\color inherit
|
666
|
-
|
667
|
-
\family typewriter
|
668
|
-
A
|
669
|
-
\family default
|
670
|
-
.
|
671
|
-
In this case, the method is called with a single
|
672
|
-
\emph on
|
673
|
-
\color red
|
674
|
-
argument
|
675
|
-
\emph default
|
676
|
-
\color inherit
|
677
|
-
,
|
678
|
-
\family typewriter
|
679
|
-
marking
|
680
|
-
\family default
|
681
|
-
.
|
682
|
-
The return value is an
|
683
|
-
\emph on
|
684
|
-
\color red
|
685
|
-
object
|
686
|
-
\emph default
|
687
|
-
\color inherit
|
688
|
-
, which is an
|
689
|
-
\emph on
|
690
|
-
\color red
|
691
|
-
instance
|
692
|
-
\emph default
|
693
|
-
\color inherit
|
694
|
-
of
|
695
|
-
\family typewriter
|
696
|
-
\color blue
|
697
|
-
YNelson::Place
|
698
|
-
\family default
|
699
|
-
\color inherit
|
700
|
-
|
701
|
-
\emph on
|
702
|
-
\color red
|
703
|
-
class
|
704
|
-
\emph default
|
705
|
-
\color inherit
|
706
|
-
.
|
707
|
-
We say that
|
708
|
-
\family typewriter
|
709
|
-
YNelson::Place
|
710
|
-
\family default
|
711
|
-
class
|
712
|
-
\emph on
|
713
|
-
\color red
|
714
|
-
represents
|
715
|
-
\emph default
|
716
|
-
\color inherit
|
717
|
-
the concept of Petri net places in
|
718
|
-
\family typewriter
|
719
|
-
YNelson
|
720
|
-
\family default
|
721
|
-
|
722
|
-
\emph on
|
723
|
-
domain model
|
724
|
-
\emph default
|
725
|
-
.
|
726
|
-
('
|
727
|
-
\family typewriter
|
728
|
-
Place
|
729
|
-
\family default
|
730
|
-
' method is called a
|
731
|
-
\emph on
|
732
|
-
\color red
|
733
|
-
constructor
|
734
|
-
\emph default
|
735
|
-
\color inherit
|
736
|
-
of
|
737
|
-
\family typewriter
|
738
|
-
YNelson::Place
|
739
|
-
\family default
|
740
|
-
, which is not important.) This newly created Petri net place has now been
|
741
|
-
assigned to
|
742
|
-
\family typewriter
|
743
|
-
A
|
744
|
-
\family default
|
745
|
-
.
|
746
|
-
On the screen, you will see the output, which is simply the name of the
|
747
|
-
place –
|
748
|
-
\family typewriter
|
749
|
-
A
|
750
|
-
\family default
|
751
|
-
.
|
752
|
-
In the following text, screen output will always be written immediately
|
753
|
-
under the code sample, preceded by sherocket (
|
754
|
-
\family typewriter
|
755
|
-
#=>)
|
756
|
-
\family default
|
757
|
-
:
|
758
|
-
\end_layout
|
759
|
-
|
760
|
-
\begin_layout LyX-Code
|
761
|
-
B = Place()
|
762
|
-
\end_layout
|
763
|
-
|
764
|
-
\begin_layout LyX-Code
|
765
|
-
#=> B
|
766
|
-
\end_layout
|
767
|
-
|
768
|
-
\begin_layout Standard
|
769
|
-
In the above, we have so far defined 2 Petri net places (named
|
770
|
-
\family typewriter
|
771
|
-
A
|
772
|
-
\family default
|
773
|
-
,
|
774
|
-
\family typewriter
|
775
|
-
B
|
776
|
-
\family default
|
777
|
-
).
|
778
|
-
You can check them by typing:
|
779
|
-
\end_layout
|
780
|
-
|
781
|
-
\begin_layout LyX-Code
|
782
|
-
|
783
|
-
\color blue
|
784
|
-
places
|
785
|
-
\color inherit
|
786
|
-
()
|
787
|
-
\end_layout
|
788
|
-
|
789
|
-
\begin_layout LyX-Code
|
790
|
-
#=> [A, B]
|
791
|
-
\end_layout
|
792
|
-
|
793
|
-
\begin_layout LyX-Code
|
794
|
-
A.
|
795
|
-
\color blue
|
796
|
-
name
|
797
|
-
\color inherit
|
798
|
-
()
|
799
|
-
\end_layout
|
800
|
-
|
801
|
-
\begin_layout LyX-Code
|
802
|
-
#=> :A
|
803
|
-
\end_layout
|
804
|
-
|
805
|
-
\begin_layout Standard
|
806
|
-
These have automatically become part of a default Petri net instance (of
|
807
|
-
|
808
|
-
\family typewriter
|
809
|
-
YNelson::Net
|
810
|
-
\family default
|
811
|
-
class; object id may vary):
|
812
|
-
\end_layout
|
813
|
-
|
814
|
-
\begin_layout LyX-Code
|
815
|
-
|
816
|
-
\color blue
|
817
|
-
net
|
818
|
-
\color inherit
|
819
|
-
()
|
820
|
-
\end_layout
|
821
|
-
|
822
|
-
\begin_layout LyX-Code
|
823
|
-
#=> #<Net: name: Top, 2 places, 0 transitions>
|
824
|
-
\end_layout
|
825
|
-
|
826
|
-
\begin_layout Standard
|
827
|
-
Of course, you have full power of Ruby at your disposal.
|
828
|
-
To eg.
|
829
|
-
list only place names as strings, you can use standard Ruby methods:
|
830
|
-
\end_layout
|
831
|
-
|
832
|
-
\begin_layout LyX-Code
|
833
|
-
places.
|
834
|
-
\color red
|
835
|
-
map
|
836
|
-
\color inherit
|
837
|
-
( &:name )
|
838
|
-
\end_layout
|
839
|
-
|
840
|
-
\begin_layout LyX-Code
|
841
|
-
#=> [:A, :B]
|
842
|
-
\end_layout
|
843
|
-
|
844
|
-
\begin_layout Standard
|
845
|
-
Here, Ruby
|
846
|
-
\family typewriter
|
847
|
-
map
|
848
|
-
\family default
|
849
|
-
method transforms the
|
850
|
-
\emph on
|
851
|
-
\color red
|
852
|
-
array
|
853
|
-
\emph default
|
854
|
-
\color inherit
|
855
|
-
of places to the array of their names.
|
856
|
-
The advantage of internal DSLs is, that one retains full power of the language,
|
857
|
-
augmented with human-friendly, domain-specific commands.
|
858
|
-
GUI systems generally sandbox the user inside their interface, with no
|
859
|
-
way to overcome its limitations.
|
860
|
-
But let us go on.
|
861
|
-
You can notice that the
|
862
|
-
\emph on
|
863
|
-
\color green
|
864
|
-
marking
|
865
|
-
\emph default
|
866
|
-
\color inherit
|
867
|
-
of
|
868
|
-
\family typewriter
|
869
|
-
A
|
870
|
-
\family default
|
871
|
-
,
|
872
|
-
\family typewriter
|
873
|
-
B
|
874
|
-
\family default
|
875
|
-
is one we gave them upon their creation:
|
876
|
-
\end_layout
|
877
|
-
|
878
|
-
\begin_layout LyX-Code
|
879
|
-
places.map( &:marking )
|
880
|
-
\end_layout
|
881
|
-
|
882
|
-
\begin_layout LyX-Code
|
883
|
-
#=> [2, 5]
|
884
|
-
\end_layout
|
885
|
-
|
886
|
-
\begin_layout Standard
|
887
|
-
In classical Petri nets, marking is understood as the number of
|
888
|
-
\emph on
|
889
|
-
\color green
|
890
|
-
tokens
|
891
|
-
\emph default
|
892
|
-
\color inherit
|
893
|
-
in each place, which is always integer.
|
894
|
-
In this case,
|
895
|
-
\family typewriter
|
896
|
-
A
|
897
|
-
\family default
|
898
|
-
contains 2 tokens, while
|
899
|
-
\family typewriter
|
900
|
-
B
|
901
|
-
\family default
|
902
|
-
contains 5 tokens.
|
903
|
-
Tokens can represent anything: molecules, parts in the production line,
|
904
|
-
trains in the railway network...
|
905
|
-
\end_layout
|
906
|
-
|
907
|
-
\begin_layout Subsection*
|
908
|
-
Transitions
|
909
|
-
\end_layout
|
910
|
-
|
911
|
-
\begin_layout Standard
|
912
|
-
The behavior of a Petri net is defined by
|
913
|
-
\emph on
|
914
|
-
\color green
|
915
|
-
transitions
|
916
|
-
\emph default
|
917
|
-
\color inherit
|
918
|
-
.
|
919
|
-
Each transition defines a single operation: Adding / subtracting some amount
|
920
|
-
of tokens to / from some places.
|
921
|
-
Transition operation can often be expressed by
|
922
|
-
\emph on
|
923
|
-
stoichiometry
|
924
|
-
\emph default
|
925
|
-
– pairs of places with a corresponding number of tokens to add / subtract
|
926
|
-
when the transition
|
927
|
-
\emph on
|
928
|
-
\color green
|
929
|
-
fires
|
930
|
-
\emph default
|
931
|
-
\color inherit
|
932
|
-
.
|
933
|
-
For example, let us define:
|
934
|
-
\end_layout
|
935
|
-
|
936
|
-
\begin_layout LyX-Code
|
937
|
-
A2B =
|
938
|
-
\color blue
|
939
|
-
Transition
|
940
|
-
\color inherit
|
941
|
-
( stoichiometry: { A: -1, B: 1 } )
|
942
|
-
\end_layout
|
943
|
-
|
944
|
-
\begin_layout LyX-Code
|
945
|
-
#=> A2B
|
946
|
-
\end_layout
|
947
|
-
|
948
|
-
\begin_layout Standard
|
949
|
-
Stoichiometry of this transition is given by the
|
950
|
-
\emph on
|
951
|
-
\color red
|
952
|
-
hash
|
953
|
-
\emph default
|
954
|
-
\color inherit
|
955
|
-
|
956
|
-
\family typewriter
|
957
|
-
{ A: -1, B: 1 }
|
958
|
-
\family default
|
959
|
-
.
|
960
|
-
This hash is available from
|
961
|
-
\family typewriter
|
962
|
-
A2B
|
963
|
-
\family default
|
964
|
-
via '
|
965
|
-
\family typewriter
|
966
|
-
\color blue
|
967
|
-
s
|
968
|
-
\family default
|
969
|
-
\color inherit
|
970
|
-
' method:
|
971
|
-
\end_layout
|
972
|
-
|
973
|
-
\begin_layout LyX-Code
|
974
|
-
A2B.
|
975
|
-
\color blue
|
976
|
-
s
|
977
|
-
\color inherit
|
978
|
-
()
|
979
|
-
\end_layout
|
980
|
-
|
981
|
-
\begin_layout LyX-Code
|
982
|
-
#=> {:A=>-1, :B=>1}
|
983
|
-
\end_layout
|
984
|
-
|
985
|
-
\begin_layout Standard
|
986
|
-
|
987
|
-
\emph on
|
988
|
-
\color red
|
989
|
-
Keys
|
990
|
-
\emph default
|
991
|
-
\color inherit
|
992
|
-
of this hash are place names,
|
993
|
-
\emph on
|
994
|
-
\color red
|
995
|
-
values
|
996
|
-
\emph default
|
997
|
-
\color inherit
|
998
|
-
are
|
999
|
-
\emph on
|
1000
|
-
\color green
|
1001
|
-
stoichiometry coefficients
|
1002
|
-
\emph default
|
1003
|
-
\color inherit
|
1004
|
-
.
|
1005
|
-
('Stoichiometry' is a word known from the domain of chemistry, but '
|
1006
|
-
\emph on
|
1007
|
-
stoicheion
|
1008
|
-
\emph default
|
1009
|
-
' means simply 'element' in Greek, so there is no problem with using it
|
1010
|
-
in the domain of general Petri nets.) To see the stoichiometry coefficients
|
1011
|
-
of
|
1012
|
-
\family typewriter
|
1013
|
-
A2B
|
1014
|
-
\family default
|
1015
|
-
as an array, type:
|
1016
|
-
\end_layout
|
1017
|
-
|
1018
|
-
\begin_layout LyX-Code
|
1019
|
-
A2B.
|
1020
|
-
\color blue
|
1021
|
-
stoichiometry
|
1022
|
-
\color inherit
|
1023
|
-
()
|
1024
|
-
\end_layout
|
1025
|
-
|
1026
|
-
\begin_layout LyX-Code
|
1027
|
-
#=> [-1, 1]
|
1028
|
-
\end_layout
|
1029
|
-
|
1030
|
-
\begin_layout Standard
|
1031
|
-
Simply,
|
1032
|
-
\family typewriter
|
1033
|
-
A2B
|
1034
|
-
\family default
|
1035
|
-
subtracts 1 token from
|
1036
|
-
\family typewriter
|
1037
|
-
A
|
1038
|
-
\family default
|
1039
|
-
, and adds 1 token to
|
1040
|
-
\family typewriter
|
1041
|
-
B
|
1042
|
-
\family default
|
1043
|
-
.
|
1044
|
-
This can represent conversion of
|
1045
|
-
\family typewriter
|
1046
|
-
A
|
1047
|
-
\family default
|
1048
|
-
to
|
1049
|
-
\family typewriter
|
1050
|
-
B
|
1051
|
-
\family default
|
1052
|
-
.
|
1053
|
-
In classical Petri nets, the arrows connecting places and transitions are
|
1054
|
-
called
|
1055
|
-
\emph on
|
1056
|
-
\color green
|
1057
|
-
arcs
|
1058
|
-
\emph default
|
1059
|
-
\color inherit
|
1060
|
-
.
|
1061
|
-
(The term was borrowed from graph theory.) For example, at this moment,
|
1062
|
-
our Petri net would contain one arc going from
|
1063
|
-
\family typewriter
|
1064
|
-
A
|
1065
|
-
\family default
|
1066
|
-
to
|
1067
|
-
\family typewriter
|
1068
|
-
A2B
|
1069
|
-
\family default
|
1070
|
-
, and one arc going from
|
1071
|
-
\family typewriter
|
1072
|
-
A2B
|
1073
|
-
\family default
|
1074
|
-
to
|
1075
|
-
\family typewriter
|
1076
|
-
B
|
1077
|
-
\family default
|
1078
|
-
.
|
1079
|
-
In
|
1080
|
-
\family typewriter
|
1081
|
-
YNelson
|
1082
|
-
\family default
|
1083
|
-
domain model, 'arcs' are not first-class citizens.
|
1084
|
-
The word is understood simply as a synonym for transitions' connectivity
|
1085
|
-
– the list of places connected to each transition:
|
1086
|
-
\end_layout
|
1087
|
-
|
1088
|
-
\begin_layout LyX-Code
|
1089
|
-
A2B.
|
1090
|
-
\color blue
|
1091
|
-
arcs
|
1092
|
-
\color inherit
|
1093
|
-
()
|
1094
|
-
\end_layout
|
1095
|
-
|
1096
|
-
\begin_layout LyX-Code
|
1097
|
-
#=> [A, B]
|
1098
|
-
\end_layout
|
1099
|
-
|
1100
|
-
\begin_layout Standard
|
1101
|
-
The transition
|
1102
|
-
\family typewriter
|
1103
|
-
A2B
|
1104
|
-
\family default
|
1105
|
-
is
|
1106
|
-
\emph on
|
1107
|
-
\color blue
|
1108
|
-
timeless
|
1109
|
-
\emph default
|
1110
|
-
\color inherit
|
1111
|
-
:
|
1112
|
-
\end_layout
|
1113
|
-
|
1114
|
-
\begin_layout LyX-Code
|
1115
|
-
A2B.
|
1116
|
-
\color blue
|
1117
|
-
timeless?
|
1118
|
-
\color inherit
|
1119
|
-
()
|
1120
|
-
\end_layout
|
1121
|
-
|
1122
|
-
\begin_layout LyX-Code
|
1123
|
-
#=> true
|
1124
|
-
\end_layout
|
1125
|
-
|
1126
|
-
\begin_layout Standard
|
1127
|
-
'Timeless' means that the transition's firing is not defined in time – it
|
1128
|
-
can fire anytime, as long as it is
|
1129
|
-
\emph on
|
1130
|
-
\color green
|
1131
|
-
enabled
|
1132
|
-
\emph default
|
1133
|
-
\color inherit
|
1134
|
-
.
|
1135
|
-
Classical Petri nets are timeless.
|
1136
|
-
In classical Petri nets, a transition is enabled whenever its
|
1137
|
-
\emph on
|
1138
|
-
\color blue
|
1139
|
-
downstream arcs
|
1140
|
-
\emph default
|
1141
|
-
\color inherit
|
1142
|
-
allow it to happen.
|
1143
|
-
Downstream arcs, or
|
1144
|
-
\emph on
|
1145
|
-
\color blue
|
1146
|
-
codomain
|
1147
|
-
\emph default
|
1148
|
-
\color inherit
|
1149
|
-
of a transition (these two are synonyms) are those places, whose marking
|
1150
|
-
can be directly affected by the transition's firing.
|
1151
|
-
In this case, both
|
1152
|
-
\family typewriter
|
1153
|
-
A
|
1154
|
-
\family default
|
1155
|
-
and
|
1156
|
-
\family typewriter
|
1157
|
-
B
|
1158
|
-
\family default
|
1159
|
-
is affected:
|
1160
|
-
\end_layout
|
1161
|
-
|
1162
|
-
\begin_layout LyX-Code
|
1163
|
-
A2B.
|
1164
|
-
\color blue
|
1165
|
-
downstream_arcs
|
1166
|
-
\color inherit
|
1167
|
-
()
|
1168
|
-
\end_layout
|
1169
|
-
|
1170
|
-
\begin_layout LyX-Code
|
1171
|
-
[A, B]
|
1172
|
-
\end_layout
|
1173
|
-
|
1174
|
-
\begin_layout LyX-Code
|
1175
|
-
A2B.
|
1176
|
-
\color blue
|
1177
|
-
codomain
|
1178
|
-
\color inherit
|
1179
|
-
()
|
1180
|
-
\end_layout
|
1181
|
-
|
1182
|
-
\begin_layout LyX-Code
|
1183
|
-
[A, B]
|
1184
|
-
\end_layout
|
1185
|
-
|
1186
|
-
\begin_layout Standard
|
1187
|
-
Since
|
1188
|
-
\family typewriter
|
1189
|
-
A2B
|
1190
|
-
\family default
|
1191
|
-
subtracts tokens from
|
1192
|
-
\family typewriter
|
1193
|
-
A
|
1194
|
-
\family default
|
1195
|
-
, it will be enabled so long, as there are any tokens left in
|
1196
|
-
\family typewriter
|
1197
|
-
A
|
1198
|
-
\family default
|
1199
|
-
.
|
1200
|
-
\end_layout
|
1201
|
-
|
1202
|
-
\begin_layout LyX-Code
|
1203
|
-
A2B.
|
1204
|
-
\color blue
|
1205
|
-
enabled?
|
1206
|
-
\color inherit
|
1207
|
-
()
|
1208
|
-
\end_layout
|
1209
|
-
|
1210
|
-
\begin_layout LyX-Code
|
1211
|
-
#=> true
|
1212
|
-
\end_layout
|
1213
|
-
|
1214
|
-
\begin_layout Subsection*
|
1215
|
-
Token game
|
1216
|
-
\end_layout
|
1217
|
-
|
1218
|
-
\begin_layout Standard
|
1219
|
-
After
|
1220
|
-
\family typewriter
|
1221
|
-
A2B
|
1222
|
-
\family default
|
1223
|
-
fires, the marking will change:
|
1224
|
-
\end_layout
|
1225
|
-
|
1226
|
-
\begin_layout LyX-Code
|
1227
|
-
A2B.
|
1228
|
-
\color blue
|
1229
|
-
fire!
|
1230
|
-
\color inherit
|
1231
|
-
()
|
1232
|
-
\end_layout
|
1233
|
-
|
1234
|
-
\begin_layout LyX-Code
|
1235
|
-
#=> nil
|
1236
|
-
\end_layout
|
1237
|
-
|
1238
|
-
\begin_layout LyX-Code
|
1239
|
-
places.map( &:marking )
|
1240
|
-
\end_layout
|
1241
|
-
|
1242
|
-
\begin_layout LyX-Code
|
1243
|
-
#=> [1, 6]
|
1244
|
-
\end_layout
|
1245
|
-
|
1246
|
-
\begin_layout LyX-Code
|
1247
|
-
A2B.fire!()
|
1248
|
-
\end_layout
|
1249
|
-
|
1250
|
-
\begin_layout LyX-Code
|
1251
|
-
#=> nil
|
1252
|
-
\end_layout
|
1253
|
-
|
1254
|
-
\begin_layout LyX-Code
|
1255
|
-
places.map( &:marking )
|
1256
|
-
\end_layout
|
1257
|
-
|
1258
|
-
\begin_layout LyX-Code
|
1259
|
-
#=> [0, 7]
|
1260
|
-
\end_layout
|
1261
|
-
|
1262
|
-
\begin_layout Standard
|
1263
|
-
At this point, there are no tokens left in
|
1264
|
-
\family typewriter
|
1265
|
-
A
|
1266
|
-
\family default
|
1267
|
-
and
|
1268
|
-
\family typewriter
|
1269
|
-
A2B
|
1270
|
-
\family default
|
1271
|
-
becomes
|
1272
|
-
\emph on
|
1273
|
-
\color green
|
1274
|
-
disabled
|
1275
|
-
\emph default
|
1276
|
-
\color inherit
|
1277
|
-
:
|
1278
|
-
\end_layout
|
1279
|
-
|
1280
|
-
\begin_layout LyX-Code
|
1281
|
-
A2B.enabled?
|
1282
|
-
\end_layout
|
1283
|
-
|
1284
|
-
\begin_layout LyX-Code
|
1285
|
-
#=> false
|
1286
|
-
\end_layout
|
1287
|
-
|
1288
|
-
\begin_layout Standard
|
1289
|
-
Attempt to fire a disabled transition
|
1290
|
-
\emph on
|
1291
|
-
\color red
|
1292
|
-
raises
|
1293
|
-
\emph default
|
1294
|
-
\color inherit
|
1295
|
-
an
|
1296
|
-
\emph on
|
1297
|
-
\color red
|
1298
|
-
error
|
1299
|
-
\emph default
|
1300
|
-
\color inherit
|
1301
|
-
(in Ruby, errors are friendly objects, who, like damsels in distress, are
|
1302
|
-
meant to be rescued with a bonus outcome):
|
1303
|
-
\end_layout
|
1304
|
-
|
1305
|
-
\begin_layout LyX-Code
|
1306
|
-
A2B.fire!
|
1307
|
-
\end_layout
|
1308
|
-
|
1309
|
-
\begin_layout LyX-Code
|
1310
|
-
#=> YPetri::GuardError: When trying call #fire method, adding action node
|
1311
|
-
no.
|
1312
|
-
0 to A, marking change being -1, YPetri::GuardError occurred: Marking -1:Fixnum
|
1313
|
-
of A should not be negative!
|
1314
|
-
\end_layout
|
1315
|
-
|
1316
|
-
\begin_layout Subsection*
|
1317
|
-
Functional transitions and non-integer marking
|
1318
|
-
\end_layout
|
1319
|
-
|
1320
|
-
\begin_layout Standard
|
1321
|
-
So far, all the examples were compatible with classical Petri nets.
|
1322
|
-
But
|
1323
|
-
\family typewriter
|
1324
|
-
YNelson
|
1325
|
-
\family default
|
1326
|
-
goes beyond – it represents
|
1327
|
-
\emph on
|
1328
|
-
functional Petri nets
|
1329
|
-
\emph default
|
1330
|
-
, similar to
|
1331
|
-
\emph on
|
1332
|
-
Hybrid Functional Petri Net (HFPN)
|
1333
|
-
\emph default
|
1334
|
-
proposed by
|
1335
|
-
\begin_inset CommandInset citation
|
1336
|
-
LatexCommand citet
|
1337
|
-
key "Matsuno2011brs"
|
1338
|
-
|
1339
|
-
\end_inset
|
1340
|
-
|
1341
|
-
, which I already mentioned in the introductory part of this document.
|
1342
|
-
|
1343
|
-
\family typewriter
|
1344
|
-
YNelson
|
1345
|
-
\family default
|
1346
|
-
domain model is similar, but not identical to HFPN.
|
1347
|
-
On the side of similarities,
|
1348
|
-
\family typewriter
|
1349
|
-
YNelson
|
1350
|
-
\family default
|
1351
|
-
allows non-integer marking of places:
|
1352
|
-
\end_layout
|
1353
|
-
|
1354
|
-
\begin_layout LyX-Code
|
1355
|
-
C = Place(
|
1356
|
-
\color blue
|
1357
|
-
marking
|
1358
|
-
\color inherit
|
1359
|
-
: 7.77 )
|
1360
|
-
\end_layout
|
1361
|
-
|
1362
|
-
\begin_layout LyX-Code
|
1363
|
-
#=> C
|
1364
|
-
\end_layout
|
1365
|
-
|
1366
|
-
\begin_layout Standard
|
1367
|
-
Here, you can notice that marking of places can be specified already upon
|
1368
|
-
initialization using '
|
1369
|
-
\family typewriter
|
1370
|
-
:marking
|
1371
|
-
\family default
|
1372
|
-
'
|
1373
|
-
\emph on
|
1374
|
-
\color red
|
1375
|
-
named argument
|
1376
|
-
\emph default
|
1377
|
-
\color inherit
|
1378
|
-
.
|
1379
|
-
Let us now define a
|
1380
|
-
\emph on
|
1381
|
-
\color blue
|
1382
|
-
timed
|
1383
|
-
\emph default
|
1384
|
-
\color inherit
|
1385
|
-
transition, representing logarithmic decay of
|
1386
|
-
\family typewriter
|
1387
|
-
C
|
1388
|
-
\family default
|
1389
|
-
with a rate constant of 0.05:
|
1390
|
-
\end_layout
|
1391
|
-
|
1392
|
-
\begin_layout LyX-Code
|
1393
|
-
C_decay = Transition( stoichiometry: { C: -1 },
|
1394
|
-
\color blue
|
1395
|
-
rate
|
1396
|
-
\color inherit
|
1397
|
-
: 0.05 )
|
1398
|
-
\end_layout
|
1399
|
-
|
1400
|
-
\begin_layout LyX-Code
|
1401
|
-
#=> C_decay
|
1402
|
-
\end_layout
|
1403
|
-
|
1404
|
-
\begin_layout LyX-Code
|
1405
|
-
C_decay.
|
1406
|
-
\color blue
|
1407
|
-
timed?
|
1408
|
-
\end_layout
|
1409
|
-
|
1410
|
-
\begin_layout LyX-Code
|
1411
|
-
#=> true
|
1412
|
-
\end_layout
|
1413
|
-
|
1414
|
-
\begin_layout Standard
|
1415
|
-
Here, in the
|
1416
|
-
\family typewriter
|
1417
|
-
transition
|
1418
|
-
\family default
|
1419
|
-
constructor method, apart from '
|
1420
|
-
\family typewriter
|
1421
|
-
stoichiometry:
|
1422
|
-
\family default
|
1423
|
-
' named argument, another named argument, '
|
1424
|
-
\family typewriter
|
1425
|
-
rate:
|
1426
|
-
\family default
|
1427
|
-
', is introduced.
|
1428
|
-
Under '
|
1429
|
-
\family typewriter
|
1430
|
-
rate:
|
1431
|
-
\family default
|
1432
|
-
', it is possible to specify the transition's
|
1433
|
-
\emph on
|
1434
|
-
\color green
|
1435
|
-
function
|
1436
|
-
\emph default
|
1437
|
-
\color inherit
|
1438
|
-
, which governs its rate.
|
1439
|
-
Specifying a function in Ruby requires special syntax (called Ruby
|
1440
|
-
\emph on
|
1441
|
-
\color red
|
1442
|
-
closures
|
1443
|
-
\emph default
|
1444
|
-
\color inherit
|
1445
|
-
), based on lambda calculus.
|
1446
|
-
Ruby closures are easy to learn.
|
1447
|
-
But for the moment, in
|
1448
|
-
\family typewriter
|
1449
|
-
C_decay
|
1450
|
-
\family default
|
1451
|
-
transition, we are taking use of the convenience, that allows us to pass
|
1452
|
-
a numeric value under '
|
1453
|
-
\family typewriter
|
1454
|
-
rate:
|
1455
|
-
\family default
|
1456
|
-
' named argument, and have
|
1457
|
-
\family typewriter
|
1458
|
-
YNelson
|
1459
|
-
\family default
|
1460
|
-
create default mass action equation, using the supplied number as its rate
|
1461
|
-
constant.
|
1462
|
-
For
|
1463
|
-
\family typewriter
|
1464
|
-
C_decay
|
1465
|
-
\family default
|
1466
|
-
stoichiometry,
|
1467
|
-
\family typewriter
|
1468
|
-
{ C: -1 }
|
1469
|
-
\family default
|
1470
|
-
, default mass action will be logarithmic decay with rate constant 0.05.
|
1471
|
-
Naturally, when firing timed transitions, the time interval (
|
1472
|
-
\begin_inset Formula $\Delta$
|
1473
|
-
\end_inset
|
1474
|
-
|
1475
|
-
time) must be specified, for which the transition should be active:
|
1476
|
-
\end_layout
|
1477
|
-
|
1478
|
-
\begin_layout LyX-Code
|
1479
|
-
C_decay.fire!( 1 )
|
1480
|
-
\end_layout
|
1481
|
-
|
1482
|
-
\begin_layout LyX-Code
|
1483
|
-
#=> nil
|
1484
|
-
\end_layout
|
1485
|
-
|
1486
|
-
\begin_layout LyX-Code
|
1487
|
-
C.marking
|
1488
|
-
\end_layout
|
1489
|
-
|
1490
|
-
\begin_layout LyX-Code
|
1491
|
-
#=> 7.3815
|
1492
|
-
\end_layout
|
1493
|
-
|
1494
|
-
\begin_layout LyX-Code
|
1495
|
-
C_decay.fire! 1
|
1496
|
-
\end_layout
|
1497
|
-
|
1498
|
-
\begin_layout LyX-Code
|
1499
|
-
#=> nil
|
1500
|
-
\end_layout
|
1501
|
-
|
1502
|
-
\begin_layout LyX-Code
|
1503
|
-
C.marking
|
1504
|
-
\end_layout
|
1505
|
-
|
1506
|
-
\begin_layout LyX-Code
|
1507
|
-
#=> 7.012425
|
1508
|
-
\end_layout
|
1509
|
-
|
1510
|
-
\begin_layout LyX-Code
|
1511
|
-
C_decay.fire!( 0.1 )
|
1512
|
-
\end_layout
|
1513
|
-
|
1514
|
-
\begin_layout LyX-Code
|
1515
|
-
#=> nil
|
1516
|
-
\end_layout
|
1517
|
-
|
1518
|
-
\begin_layout LyX-Code
|
1519
|
-
C.marking
|
1520
|
-
\end_layout
|
1521
|
-
|
1522
|
-
\begin_layout LyX-Code
|
1523
|
-
#=> 6.977362875000001
|
1524
|
-
\end_layout
|
1525
|
-
|
1526
|
-
\begin_layout LyX-Code
|
1527
|
-
100.
|
1528
|
-
\color red
|
1529
|
-
times
|
1530
|
-
\color inherit
|
1531
|
-
do C_decay.fire! 1 end
|
1532
|
-
\end_layout
|
1533
|
-
|
1534
|
-
\begin_layout LyX-Code
|
1535
|
-
#=> 100
|
1536
|
-
\end_layout
|
1537
|
-
|
1538
|
-
\begin_layout LyX-Code
|
1539
|
-
C.marking
|
1540
|
-
\end_layout
|
1541
|
-
|
1542
|
-
\begin_layout LyX-Code
|
1543
|
-
#=> 0.04130968078231133
|
1544
|
-
\end_layout
|
1545
|
-
|
1546
|
-
\begin_layout Standard
|
1547
|
-
The penultimate statement was a call of Ruby '
|
1548
|
-
\family typewriter
|
1549
|
-
times
|
1550
|
-
\family default
|
1551
|
-
' method with the integer
|
1552
|
-
\family typewriter
|
1553
|
-
100
|
1554
|
-
\family default
|
1555
|
-
as the receiver, which results in 100 time repetition of the statement
|
1556
|
-
inside
|
1557
|
-
\family typewriter
|
1558
|
-
\color red
|
1559
|
-
do ...
|
1560
|
-
end
|
1561
|
-
\family default
|
1562
|
-
\emph on
|
1563
|
-
block
|
1564
|
-
\emph default
|
1565
|
-
\color inherit
|
1566
|
-
.
|
1567
|
-
Instead of
|
1568
|
-
\family typewriter
|
1569
|
-
do ...
|
1570
|
-
end
|
1571
|
-
\family default
|
1572
|
-
, it is possible to write a block using curly braces
|
1573
|
-
\family typewriter
|
1574
|
-
\color red
|
1575
|
-
{ ...
|
1576
|
-
}
|
1577
|
-
\family default
|
1578
|
-
\color inherit
|
1579
|
-
:
|
1580
|
-
\end_layout
|
1581
|
-
|
1582
|
-
\begin_layout LyX-Code
|
1583
|
-
100.times { C_decay.fire! 1 }
|
1584
|
-
\end_layout
|
1585
|
-
|
1586
|
-
\begin_layout LyX-Code
|
1587
|
-
#=> 100
|
1588
|
-
\end_layout
|
1589
|
-
|
1590
|
-
\begin_layout Standard
|
1591
|
-
This will cause another 100 time units of
|
1592
|
-
\family typewriter
|
1593
|
-
C_decay
|
1594
|
-
\family default
|
1595
|
-
firing.
|
1596
|
-
This brings
|
1597
|
-
\family typewriter
|
1598
|
-
C
|
1599
|
-
\family default
|
1600
|
-
marking down to almost zero:
|
1601
|
-
\end_layout
|
1602
|
-
|
1603
|
-
\begin_layout LyX-Code
|
1604
|
-
C.marking
|
1605
|
-
\end_layout
|
1606
|
-
|
1607
|
-
\begin_layout LyX-Code
|
1608
|
-
#=> 0.00024457517215434527
|
1609
|
-
\end_layout
|
1610
|
-
|
1611
|
-
\begin_layout Subsection*
|
1612
|
-
Four transition types
|
1613
|
-
\end_layout
|
1614
|
-
|
1615
|
-
\begin_layout Standard
|
1616
|
-
Thus far, we have demonstrated transitions with stoichiometry, which were
|
1617
|
-
either
|
1618
|
-
\emph on
|
1619
|
-
timed
|
1620
|
-
\emph default
|
1621
|
-
or not timed (
|
1622
|
-
\emph on
|
1623
|
-
timeless
|
1624
|
-
\emph default
|
1625
|
-
).
|
1626
|
-
Timed transitions are denoted by capital
|
1627
|
-
\begin_inset Quotes eld
|
1628
|
-
\end_inset
|
1629
|
-
|
1630
|
-
|
1631
|
-
\family typewriter
|
1632
|
-
T
|
1633
|
-
\family default
|
1634
|
-
|
1635
|
-
\begin_inset Quotes erd
|
1636
|
-
\end_inset
|
1637
|
-
|
1638
|
-
, timeless transitions by small
|
1639
|
-
\begin_inset Quotes eld
|
1640
|
-
\end_inset
|
1641
|
-
|
1642
|
-
|
1643
|
-
\family typewriter
|
1644
|
-
t
|
1645
|
-
\family default
|
1646
|
-
|
1647
|
-
\begin_inset Quotes erd
|
1648
|
-
\end_inset
|
1649
|
-
|
1650
|
-
.
|
1651
|
-
Similarly, stoichiometric transitions are denoted by capital
|
1652
|
-
\begin_inset Quotes eld
|
1653
|
-
\end_inset
|
1654
|
-
|
1655
|
-
|
1656
|
-
\family typewriter
|
1657
|
-
S
|
1658
|
-
\family default
|
1659
|
-
|
1660
|
-
\begin_inset Quotes erd
|
1661
|
-
\end_inset
|
1662
|
-
|
1663
|
-
, while transitions without stoichiometry (
|
1664
|
-
\emph on
|
1665
|
-
non-stoichiometric
|
1666
|
-
\emph default
|
1667
|
-
transitions) by small
|
1668
|
-
\begin_inset Quotes eld
|
1669
|
-
\end_inset
|
1670
|
-
|
1671
|
-
|
1672
|
-
\family typewriter
|
1673
|
-
s
|
1674
|
-
\family default
|
1675
|
-
|
1676
|
-
\begin_inset Quotes erd
|
1677
|
-
\end_inset
|
1678
|
-
|
1679
|
-
.
|
1680
|
-
Together, this gives 4 basic types of transitions:
|
1681
|
-
\family typewriter
|
1682
|
-
TS
|
1683
|
-
\family default
|
1684
|
-
,
|
1685
|
-
\family typewriter
|
1686
|
-
tS
|
1687
|
-
\family default
|
1688
|
-
,
|
1689
|
-
\family typewriter
|
1690
|
-
Ts
|
1691
|
-
\family default
|
1692
|
-
, and
|
1693
|
-
\family typewriter
|
1694
|
-
ts
|
1695
|
-
\family default
|
1696
|
-
.
|
1697
|
-
\end_layout
|
1698
|
-
|
1699
|
-
\begin_layout Standard
|
1700
|
-
The user can ask the type of a transition by calling the
|
1701
|
-
\family typewriter
|
1702
|
-
\color blue
|
1703
|
-
type
|
1704
|
-
\family default
|
1705
|
-
\color inherit
|
1706
|
-
method:
|
1707
|
-
\end_layout
|
1708
|
-
|
1709
|
-
\begin_layout LyX-Code
|
1710
|
-
A2B.type
|
1711
|
-
\end_layout
|
1712
|
-
|
1713
|
-
\begin_layout LyX-Code
|
1714
|
-
#=> :tS
|
1715
|
-
\end_layout
|
1716
|
-
|
1717
|
-
\begin_layout Standard
|
1718
|
-
Or investigate the type with inquirer methods:
|
1719
|
-
\end_layout
|
1720
|
-
|
1721
|
-
\begin_layout LyX-Code
|
1722
|
-
A2B.
|
1723
|
-
\color blue
|
1724
|
-
t?
|
1725
|
-
\end_layout
|
1726
|
-
|
1727
|
-
\begin_layout LyX-Code
|
1728
|
-
#=> true
|
1729
|
-
\end_layout
|
1730
|
-
|
1731
|
-
\begin_layout LyX-Code
|
1732
|
-
A2B.
|
1733
|
-
\color blue
|
1734
|
-
T?
|
1735
|
-
\end_layout
|
1736
|
-
|
1737
|
-
\begin_layout LyX-Code
|
1738
|
-
#=> false
|
1739
|
-
\end_layout
|
1740
|
-
|
1741
|
-
\begin_layout LyX-Code
|
1742
|
-
A2B.
|
1743
|
-
\color blue
|
1744
|
-
s?
|
1745
|
-
\end_layout
|
1746
|
-
|
1747
|
-
\begin_layout LyX-Code
|
1748
|
-
#=> false
|
1749
|
-
\end_layout
|
1750
|
-
|
1751
|
-
\begin_layout LyX-Code
|
1752
|
-
A2B.
|
1753
|
-
\color blue
|
1754
|
-
S?
|
1755
|
-
\end_layout
|
1756
|
-
|
1757
|
-
\begin_layout LyX-Code
|
1758
|
-
#=> true
|
1759
|
-
\end_layout
|
1760
|
-
|
1761
|
-
\begin_layout LyX-Code
|
1762
|
-
A2B.
|
1763
|
-
\color blue
|
1764
|
-
TS?
|
1765
|
-
\end_layout
|
1766
|
-
|
1767
|
-
\begin_layout LyX-Code
|
1768
|
-
#=> false
|
1769
|
-
\end_layout
|
1770
|
-
|
1771
|
-
\begin_layout LyX-Code
|
1772
|
-
A2B.
|
1773
|
-
\color blue
|
1774
|
-
tS?
|
1775
|
-
\end_layout
|
1776
|
-
|
1777
|
-
\begin_layout LyX-Code
|
1778
|
-
#=> true
|
1779
|
-
\end_layout
|
1780
|
-
|
1781
|
-
\begin_layout LyX-Code
|
1782
|
-
A2B.
|
1783
|
-
\color blue
|
1784
|
-
Ts?
|
1785
|
-
\end_layout
|
1786
|
-
|
1787
|
-
\begin_layout LyX-Code
|
1788
|
-
#=> false
|
1789
|
-
\end_layout
|
1790
|
-
|
1791
|
-
\begin_layout LyX-Code
|
1792
|
-
A2B.
|
1793
|
-
\color blue
|
1794
|
-
ts?
|
1795
|
-
\end_layout
|
1796
|
-
|
1797
|
-
\begin_layout LyX-Code
|
1798
|
-
#=> false
|
1799
|
-
\end_layout
|
1800
|
-
|
1801
|
-
\begin_layout Subsection*
|
1802
|
-
Assignment transitions
|
1803
|
-
\end_layout
|
1804
|
-
|
1805
|
-
\begin_layout Standard
|
1806
|
-
In
|
1807
|
-
\family typewriter
|
1808
|
-
YNelson
|
1809
|
-
\family default
|
1810
|
-
, there is one more transition type: an assignment transition, denoted by
|
1811
|
-
|
1812
|
-
\begin_inset Quotes eld
|
1813
|
-
\end_inset
|
1814
|
-
|
1815
|
-
|
1816
|
-
\family typewriter
|
1817
|
-
A
|
1818
|
-
\family default
|
1819
|
-
|
1820
|
-
\begin_inset Quotes erd
|
1821
|
-
\end_inset
|
1822
|
-
|
1823
|
-
.
|
1824
|
-
Assignment transitions do not add or subtract tokens from their target,
|
1825
|
-
but completely replace the codomain marking with their output.
|
1826
|
-
(Again, in
|
1827
|
-
\family typewriter
|
1828
|
-
YNelson
|
1829
|
-
\family default
|
1830
|
-
transitions,
|
1831
|
-
\emph on
|
1832
|
-
domain
|
1833
|
-
\emph default
|
1834
|
-
and
|
1835
|
-
\emph on
|
1836
|
-
codomain
|
1837
|
-
\emph default
|
1838
|
-
mean respectively upstream and downstream places.) Transitions other than
|
1839
|
-
|
1840
|
-
\family typewriter
|
1841
|
-
A
|
1842
|
-
\family default
|
1843
|
-
transitions can be collectively called non-assignment transitions, denoted
|
1844
|
-
by small
|
1845
|
-
\begin_inset Quotes eld
|
1846
|
-
\end_inset
|
1847
|
-
|
1848
|
-
|
1849
|
-
\family typewriter
|
1850
|
-
a
|
1851
|
-
\family default
|
1852
|
-
|
1853
|
-
\begin_inset Quotes erd
|
1854
|
-
\end_inset
|
1855
|
-
|
1856
|
-
.
|
1857
|
-
Note that assignment action is already achievable with plain
|
1858
|
-
\family typewriter
|
1859
|
-
ts
|
1860
|
-
\family default
|
1861
|
-
transitions (by subtracting away the previous codomain marking), so
|
1862
|
-
\family typewriter
|
1863
|
-
A
|
1864
|
-
\family default
|
1865
|
-
transitions are not strictly needed – their separate existence is just
|
1866
|
-
a syntactic convenience.
|
1867
|
-
\end_layout
|
1868
|
-
|
1869
|
-
\begin_layout Standard
|
1870
|
-
One way to construct assignment transitions is by setting
|
1871
|
-
\family typewriter
|
1872
|
-
:assignment
|
1873
|
-
\family default
|
1874
|
-
named argument to
|
1875
|
-
\emph on
|
1876
|
-
true
|
1877
|
-
\emph default
|
1878
|
-
:
|
1879
|
-
\end_layout
|
1880
|
-
|
1881
|
-
\begin_layout LyX-Code
|
1882
|
-
A_to_42 = Transition codomain: A, assignment: lambda { 42 }
|
1883
|
-
\end_layout
|
1884
|
-
|
1885
|
-
\begin_layout LyX-Code
|
1886
|
-
#=> A_to_42
|
1887
|
-
\end_layout
|
1888
|
-
|
1889
|
-
\begin_layout Standard
|
1890
|
-
Firing this transition results in marking of
|
1891
|
-
\family typewriter
|
1892
|
-
A
|
1893
|
-
\family default
|
1894
|
-
being set to 42:
|
1895
|
-
\end_layout
|
1896
|
-
|
1897
|
-
\begin_layout LyX-Code
|
1898
|
-
A_to_42.fire!
|
1899
|
-
\end_layout
|
1900
|
-
|
1901
|
-
\begin_layout LyX-Code
|
1902
|
-
#=> nil
|
1903
|
-
\end_layout
|
1904
|
-
|
1905
|
-
\begin_layout LyX-Code
|
1906
|
-
A.marking
|
1907
|
-
\end_layout
|
1908
|
-
|
1909
|
-
\begin_layout LyX-Code
|
1910
|
-
#=> 42
|
1911
|
-
\end_layout
|
1912
|
-
|
1913
|
-
\begin_layout Standard
|
1914
|
-
Assignment transitions are of special type
|
1915
|
-
\family typewriter
|
1916
|
-
A
|
1917
|
-
\family default
|
1918
|
-
:
|
1919
|
-
\end_layout
|
1920
|
-
|
1921
|
-
\begin_layout LyX-Code
|
1922
|
-
A_to_42.type
|
1923
|
-
\end_layout
|
1924
|
-
|
1925
|
-
\begin_layout LyX-Code
|
1926
|
-
#=> :A
|
1927
|
-
\end_layout
|
1928
|
-
|
1929
|
-
\begin_layout LyX-Code
|
1930
|
-
A_to_42.A?
|
1931
|
-
\end_layout
|
1932
|
-
|
1933
|
-
\begin_layout LyX-Code
|
1934
|
-
#=> true
|
1935
|
-
\end_layout
|
1936
|
-
|
1937
|
-
\begin_layout LyX-Code
|
1938
|
-
A_to_42.a?
|
1939
|
-
\end_layout
|
1940
|
-
|
1941
|
-
\begin_layout LyX-Code
|
1942
|
-
#=> false
|
1943
|
-
\end_layout
|
1944
|
-
|
1945
|
-
\begin_layout Part*
|
1946
|
-
Example II: Convenience
|
1947
|
-
\end_layout
|
1948
|
-
|
1949
|
-
\begin_layout Standard
|
1950
|
-
So far, to avoid confusing you, I used fairly conservative syntax.
|
1951
|
-
|
1952
|
-
\family typewriter
|
1953
|
-
YNelson
|
1954
|
-
\family default
|
1955
|
-
can do better than that.
|
1956
|
-
For convenience, many long keywords have short aliases.
|
1957
|
-
Frequently used syntactic constructs usually have shorter way of expressing
|
1958
|
-
the same.
|
1959
|
-
\end_layout
|
1960
|
-
|
1961
|
-
\begin_layout Standard
|
1962
|
-
As you have seen, in
|
1963
|
-
\family typewriter
|
1964
|
-
YNelson
|
1965
|
-
\family default
|
1966
|
-
one often uses transition constructors.
|
1967
|
-
Thus far, we have seen only one
|
1968
|
-
\emph on
|
1969
|
-
constructor method
|
1970
|
-
\emph default
|
1971
|
-
for transitions:
|
1972
|
-
\family typewriter
|
1973
|
-
Transition()
|
1974
|
-
\family default
|
1975
|
-
.
|
1976
|
-
|
1977
|
-
\family typewriter
|
1978
|
-
Transition()
|
1979
|
-
\family default
|
1980
|
-
method accepts several different named arguments (
|
1981
|
-
\family typewriter
|
1982
|
-
:domain
|
1983
|
-
\family default
|
1984
|
-
,
|
1985
|
-
\family typewriter
|
1986
|
-
:codomain
|
1987
|
-
\family default
|
1988
|
-
,
|
1989
|
-
\family typewriter
|
1990
|
-
:stoichiometry
|
1991
|
-
\family default
|
1992
|
-
|
1993
|
-
\family typewriter
|
1994
|
-
:assignment
|
1995
|
-
\family default
|
1996
|
-
,
|
1997
|
-
\family typewriter
|
1998
|
-
:rate
|
1999
|
-
\family default
|
2000
|
-
,
|
2001
|
-
\family typewriter
|
2002
|
-
:action
|
2003
|
-
\family default
|
2004
|
-
,
|
2005
|
-
\family typewriter
|
2006
|
-
:name
|
2007
|
-
\family default
|
2008
|
-
...) and depending on their values, returns a
|
2009
|
-
\family typewriter
|
2010
|
-
YNelson::Transition
|
2011
|
-
\family default
|
2012
|
-
class object of required type and properties.
|
2013
|
-
\end_layout
|
2014
|
-
|
2015
|
-
\begin_layout Standard
|
2016
|
-
Using long keywords in the constructor method makes the
|
2017
|
-
\family typewriter
|
2018
|
-
YNelson
|
2019
|
-
\family default
|
2020
|
-
code easy to read.
|
2021
|
-
But for the cases where trading readability for brevity is desirable, such
|
2022
|
-
as when you are playing with YNelson inside
|
2023
|
-
\emph on
|
2024
|
-
irb
|
2025
|
-
\emph default
|
2026
|
-
session, you will appreciate convenience.
|
2027
|
-
Actually, we already used syntactic shorthands in the earlier examples.
|
2028
|
-
We didn't type :
|
2029
|
-
\end_layout
|
2030
|
-
|
2031
|
-
\begin_layout LyX-Code
|
2032
|
-
Transition( name:
|
2033
|
-
\begin_inset Quotes eld
|
2034
|
-
\end_inset
|
2035
|
-
|
2036
|
-
A2B
|
2037
|
-
\begin_inset Quotes erd
|
2038
|
-
\end_inset
|
2039
|
-
|
2040
|
-
,
|
2041
|
-
\end_layout
|
2042
|
-
|
2043
|
-
\begin_layout LyX-Code
|
2044
|
-
codomain: [A, B],
|
2045
|
-
\end_layout
|
2046
|
-
|
2047
|
-
\begin_layout LyX-Code
|
2048
|
-
stoichiometry: [-1, 1] )
|
2049
|
-
\end_layout
|
2050
|
-
|
2051
|
-
\begin_layout LyX-Code
|
2052
|
-
A2B = transition( :A2B )
|
2053
|
-
\end_layout
|
2054
|
-
|
2055
|
-
\begin_layout Standard
|
2056
|
-
Instead, we just typed
|
2057
|
-
\end_layout
|
2058
|
-
|
2059
|
-
\begin_layout LyX-Code
|
2060
|
-
A2B = Transition( stoichiometry: { A: -1, B: 1 } )
|
2061
|
-
\end_layout
|
2062
|
-
|
2063
|
-
\begin_layout Standard
|
2064
|
-
Just so you know, the above shorthand is not easy to program in Ruby.
|
2065
|
-
When designing
|
2066
|
-
\family typewriter
|
2067
|
-
YNelson
|
2068
|
-
\family default
|
2069
|
-
, I took a lot of pain for your convenience.
|
2070
|
-
Even shorter way to express the same would be:
|
2071
|
-
\end_layout
|
2072
|
-
|
2073
|
-
\begin_layout LyX-Code
|
2074
|
-
A2B = Transition
|
2075
|
-
\color blue
|
2076
|
-
s
|
2077
|
-
\color inherit
|
2078
|
-
: { A: -1, B: 1 }
|
2079
|
-
\end_layout
|
2080
|
-
|
2081
|
-
\begin_layout Standard
|
2082
|
-
The above is a very simple timeless transition that just takes one token
|
2083
|
-
from
|
2084
|
-
\family typewriter
|
2085
|
-
A
|
2086
|
-
\family default
|
2087
|
-
and puts it into
|
2088
|
-
\family typewriter
|
2089
|
-
B
|
2090
|
-
\family default
|
2091
|
-
.
|
2092
|
-
(Constructor convenience is even more powerful for complex transitions.)
|
2093
|
-
Start a new
|
2094
|
-
\family typewriter
|
2095
|
-
irb
|
2096
|
-
\family default
|
2097
|
-
session and type:
|
2098
|
-
\end_layout
|
2099
|
-
|
2100
|
-
\begin_layout LyX-Code
|
2101
|
-
require 'y_nelson'
|
2102
|
-
\end_layout
|
2103
|
-
|
2104
|
-
\begin_layout LyX-Code
|
2105
|
-
include YNelson
|
2106
|
-
\end_layout
|
2107
|
-
|
2108
|
-
\begin_layout LyX-Code
|
2109
|
-
A = Place
|
2110
|
-
\color blue
|
2111
|
-
default_marking
|
2112
|
-
\color inherit
|
2113
|
-
: 5
|
2114
|
-
\end_layout
|
2115
|
-
|
2116
|
-
\begin_layout Standard
|
2117
|
-
Constantly typing
|
2118
|
-
\family typewriter
|
2119
|
-
default_marking
|
2120
|
-
\family default
|
2121
|
-
is tiresome.
|
2122
|
-
Shorter way to say the same is by using the alias
|
2123
|
-
\family typewriter
|
2124
|
-
\color blue
|
2125
|
-
m!
|
2126
|
-
\family default
|
2127
|
-
\color inherit
|
2128
|
-
of the same:
|
2129
|
-
\end_layout
|
2130
|
-
|
2131
|
-
\begin_layout LyX-Code
|
2132
|
-
B = Place m!: 5
|
2133
|
-
\end_layout
|
2134
|
-
|
2135
|
-
\begin_layout LyX-Code
|
2136
|
-
C = Place m!: 1
|
2137
|
-
\end_layout
|
2138
|
-
|
2139
|
-
\begin_layout LyX-Code
|
2140
|
-
D = Place m!: 1
|
2141
|
-
\end_layout
|
2142
|
-
|
2143
|
-
\begin_layout Standard
|
2144
|
-
Let's check the net's marking vector now:
|
2145
|
-
\end_layout
|
2146
|
-
|
2147
|
-
\begin_layout LyX-Code
|
2148
|
-
places.map &:marking #=> [5, 5, 1, 1]
|
2149
|
-
\end_layout
|
2150
|
-
|
2151
|
-
\begin_layout Standard
|
2152
|
-
If you typed everything correctly, you should see the above result.
|
2153
|
-
Shorter way to ask for the same information is:
|
2154
|
-
\end_layout
|
2155
|
-
|
2156
|
-
\begin_layout LyX-Code
|
2157
|
-
net.marking #=> [5, 5, 1, 1]
|
2158
|
-
\end_layout
|
2159
|
-
|
2160
|
-
\begin_layout Standard
|
2161
|
-
Even shorter way to say the same is:
|
2162
|
-
\end_layout
|
2163
|
-
|
2164
|
-
\begin_layout LyX-Code
|
2165
|
-
net.
|
2166
|
-
\color blue
|
2167
|
-
m
|
2168
|
-
\color inherit
|
2169
|
-
#=> [5, 5, 1, 1]
|
2170
|
-
\end_layout
|
2171
|
-
|
2172
|
-
\begin_layout Standard
|
2173
|
-
Now let's define the transition we want:
|
2174
|
-
\end_layout
|
2175
|
-
|
2176
|
-
\begin_layout LyX-Code
|
2177
|
-
B2A = Transition( stoichiometry: { B: -1, A: 1 },
|
2178
|
-
\end_layout
|
2179
|
-
|
2180
|
-
\begin_layout LyX-Code
|
2181
|
-
domain: [C, D],
|
2182
|
-
\end_layout
|
2183
|
-
|
2184
|
-
\begin_layout LyX-Code
|
2185
|
-
rate: lambda { |x, y| ( x * y ) ** 0.5 } )
|
2186
|
-
\end_layout
|
2187
|
-
|
2188
|
-
\begin_layout Standard
|
2189
|
-
To prove that it works, let's fire it for 0.1 time units:
|
2190
|
-
\end_layout
|
2191
|
-
|
2192
|
-
\begin_layout LyX-Code
|
2193
|
-
B2A.fire! 0.1 #=> nil
|
2194
|
-
\end_layout
|
2195
|
-
|
2196
|
-
\begin_layout LyX-Code
|
2197
|
-
net.m #=> [5.1, 4.9, 1, 1]
|
2198
|
-
\end_layout
|
2199
|
-
|
2200
|
-
\begin_layout Standard
|
2201
|
-
Can we express its constructor more concisely? The answer is yes.
|
2202
|
-
|
2203
|
-
\family typewriter
|
2204
|
-
B2A
|
2205
|
-
\family default
|
2206
|
-
is a
|
2207
|
-
\family typewriter
|
2208
|
-
TS
|
2209
|
-
\family default
|
2210
|
-
transition (check
|
2211
|
-
\family typewriter
|
2212
|
-
B2A.type
|
2213
|
-
\family default
|
2214
|
-
to make sure it is true), and for
|
2215
|
-
\family typewriter
|
2216
|
-
TS
|
2217
|
-
\family default
|
2218
|
-
transitions,
|
2219
|
-
\family typewriter
|
2220
|
-
\color blue
|
2221
|
-
TS()
|
2222
|
-
\family default
|
2223
|
-
\color inherit
|
2224
|
-
convenience constructor is available.
|
2225
|
-
With
|
2226
|
-
\family typewriter
|
2227
|
-
TS()
|
2228
|
-
\family default
|
2229
|
-
constructor, the definition of B2A would be much shorter:
|
2230
|
-
\end_layout
|
2231
|
-
|
2232
|
-
\begin_layout LyX-Code
|
2233
|
-
B2A = TS domain: [C, D], A: 1, B: -1 do |x, y| ( x * y ) ** 0.5 end
|
2234
|
-
\end_layout
|
2235
|
-
|
2236
|
-
\begin_layout Standard
|
2237
|
-
Note the
|
2238
|
-
\family typewriter
|
2239
|
-
\color red
|
2240
|
-
do ...
|
2241
|
-
end
|
2242
|
-
\family default
|
2243
|
-
\color inherit
|
2244
|
-
part in the above line: Using lambda syntax, it defines the rate function
|
2245
|
-
of the transition.
|
2246
|
-
Another convenience constructor worth mentioning is
|
2247
|
-
\family typewriter
|
2248
|
-
\color blue
|
2249
|
-
AT()
|
2250
|
-
\family default
|
2251
|
-
\color inherit
|
2252
|
-
for assignment transition.
|
2253
|
-
Earlier, we defined:
|
2254
|
-
\end_layout
|
2255
|
-
|
2256
|
-
\begin_layout LyX-Code
|
2257
|
-
A_to_42 = Transition codomain: A, assignment: lambda { 42 }
|
2258
|
-
\end_layout
|
2259
|
-
|
2260
|
-
\begin_layout Standard
|
2261
|
-
Using
|
2262
|
-
\family typewriter
|
2263
|
-
AT()
|
2264
|
-
\family default
|
2265
|
-
constructor, we can shorten this to:
|
2266
|
-
\end_layout
|
2267
|
-
|
2268
|
-
\begin_layout LyX-Code
|
2269
|
-
A_to_42 = AT A do 42 end
|
2270
|
-
\end_layout
|
2271
|
-
|
2272
|
-
\begin_layout Standard
|
2273
|
-
In short, syntactic shorthands can save a lot of typing.
|
2274
|
-
If you still miss some syntactic shorthand, feel free to define it on your
|
2275
|
-
own.
|
2276
|
-
For example, let us define a custom method named
|
2277
|
-
\family typewriter
|
2278
|
-
Foo
|
2279
|
-
\family default
|
2280
|
-
that acts as a constructor of places with default marking.
|
2281
|
-
\end_layout
|
2282
|
-
|
2283
|
-
\begin_layout LyX-Code
|
2284
|
-
|
2285
|
-
\color red
|
2286
|
-
def
|
2287
|
-
\color inherit
|
2288
|
-
Foo( m )
|
2289
|
-
\end_layout
|
2290
|
-
|
2291
|
-
\begin_layout LyX-Code
|
2292
|
-
Place( default_marking: m )
|
2293
|
-
\end_layout
|
2294
|
-
|
2295
|
-
\begin_layout LyX-Code
|
2296
|
-
end
|
2297
|
-
\end_layout
|
2298
|
-
|
2299
|
-
\begin_layout Standard
|
2300
|
-
After this, you can define places with default marking with even less typing:
|
2301
|
-
\end_layout
|
2302
|
-
|
2303
|
-
\begin_layout LyX-Code
|
2304
|
-
X = Foo 42
|
2305
|
-
\end_layout
|
2306
|
-
|
2307
|
-
\begin_layout LyX-Code
|
2308
|
-
Y = Foo 43
|
2309
|
-
\end_layout
|
2310
|
-
|
2311
|
-
\begin_layout Part*
|
2312
|
-
Example III: YNelson::Simulation
|
2313
|
-
\end_layout
|
2314
|
-
|
2315
|
-
\begin_layout Standard
|
2316
|
-
So far, we have been defining Petri nets and playing the token game using
|
2317
|
-
|
2318
|
-
\family typewriter
|
2319
|
-
#fire!
|
2320
|
-
\family default
|
2321
|
-
method, let us now simulate a Petri net inside
|
2322
|
-
\family typewriter
|
2323
|
-
YNelson
|
2324
|
-
\color blue
|
2325
|
-
::Simulation
|
2326
|
-
\family default
|
2327
|
-
\color inherit
|
2328
|
-
.
|
2329
|
-
Restart your irb session as described in the
|
2330
|
-
\series bold
|
2331
|
-
Prerequisites
|
2332
|
-
\series default
|
2333
|
-
chapter.
|
2334
|
-
We will now define 2 places.
|
2335
|
-
Since we are going to use
|
2336
|
-
\family typewriter
|
2337
|
-
TimedSimulation
|
2338
|
-
\family default
|
2339
|
-
, the marking owned by
|
2340
|
-
\family typewriter
|
2341
|
-
YNelson::Place
|
2342
|
-
\family default
|
2343
|
-
instances is irrelevant.
|
2344
|
-
We just need to specify the initial state eg.
|
2345
|
-
by specifying the default marking of the places:
|
2346
|
-
\end_layout
|
2347
|
-
|
2348
|
-
\begin_layout LyX-Code
|
2349
|
-
require 'y_nelson'
|
2350
|
-
\end_layout
|
2351
|
-
|
2352
|
-
\begin_layout LyX-Code
|
2353
|
-
include YNelson
|
2354
|
-
\end_layout
|
2355
|
-
|
2356
|
-
\begin_layout LyX-Code
|
2357
|
-
A = Place
|
2358
|
-
\color blue
|
2359
|
-
m!:
|
2360
|
-
\color inherit
|
2361
|
-
0.5
|
2362
|
-
\end_layout
|
2363
|
-
|
2364
|
-
\begin_layout LyX-Code
|
2365
|
-
B = Place m!: 0.5
|
2366
|
-
\end_layout
|
2367
|
-
|
2368
|
-
\begin_layout Standard
|
2369
|
-
Now let us define a transition corresponding to pumping
|
2370
|
-
\family typewriter
|
2371
|
-
A
|
2372
|
-
\family default
|
2373
|
-
out of the system at a constant rate 0.005 per time unit.
|
2374
|
-
\end_layout
|
2375
|
-
|
2376
|
-
\begin_layout LyX-Code
|
2377
|
-
A_pump = Transition s: { A: -1 }, rate:
|
2378
|
-
\color red
|
2379
|
-
proc
|
2380
|
-
\color inherit
|
2381
|
-
{ 0.005 }
|
2382
|
-
\end_layout
|
2383
|
-
|
2384
|
-
\begin_layout Standard
|
2385
|
-
Here,
|
2386
|
-
\family typewriter
|
2387
|
-
proc { 0.005 }
|
2388
|
-
\family default
|
2389
|
-
is a closure, that defines the rate function.
|
2390
|
-
Closure
|
2391
|
-
\family typewriter
|
2392
|
-
proc { 0.005 }
|
2393
|
-
\family default
|
2394
|
-
ensures fixed rate 0.005 per time unit regardless of the marking of
|
2395
|
-
\family typewriter
|
2396
|
-
A
|
2397
|
-
\family default
|
2398
|
-
.
|
2399
|
-
You can notice that this closure expects no arguments and always outputs
|
2400
|
-
0.005 as its return value.
|
2401
|
-
It is the simplest possible way to write a constant function.
|
2402
|
-
For comparison,
|
2403
|
-
\end_layout
|
2404
|
-
|
2405
|
-
\begin_layout LyX-Code
|
2406
|
-
B_decay = Transition s: { B: -1 }, rate: 0.05
|
2407
|
-
\end_layout
|
2408
|
-
|
2409
|
-
\begin_layout Standard
|
2410
|
-
will behind the scenes automatically create a slightly more complicated
|
2411
|
-
mass action closure, which is logarithmic decay of
|
2412
|
-
\family typewriter
|
2413
|
-
B
|
2414
|
-
\family default
|
2415
|
-
in this case.
|
2416
|
-
(You should remember this from
|
2417
|
-
\series bold
|
2418
|
-
Example I
|
2419
|
-
\series default
|
2420
|
-
.) Now we have created a net of 2 places and 2 transitions:
|
2421
|
-
\end_layout
|
2422
|
-
|
2423
|
-
\begin_layout LyX-Code
|
2424
|
-
net
|
2425
|
-
\end_layout
|
2426
|
-
|
2427
|
-
\begin_layout LyX-Code
|
2428
|
-
#=> #<Net: name: Top, 2 places, 2 transitions>
|
2429
|
-
\end_layout
|
2430
|
-
|
2431
|
-
\begin_layout Standard
|
2432
|
-
We can execute this Petri net as a
|
2433
|
-
\family typewriter
|
2434
|
-
Simulation
|
2435
|
-
\family default
|
2436
|
-
object simply by typing:
|
2437
|
-
\end_layout
|
2438
|
-
|
2439
|
-
\begin_layout LyX-Code
|
2440
|
-
|
2441
|
-
\color blue
|
2442
|
-
run!
|
2443
|
-
\color inherit
|
2444
|
-
#=> 60
|
2445
|
-
\end_layout
|
2446
|
-
|
2447
|
-
\begin_layout Standard
|
2448
|
-
At this point,
|
2449
|
-
\family typewriter
|
2450
|
-
run!
|
2451
|
-
\family default
|
2452
|
-
creates and executes a
|
2453
|
-
\family typewriter
|
2454
|
-
Simulation
|
2455
|
-
\family default
|
2456
|
-
instance.
|
2457
|
-
The return value is the simulation instance itself (see the inspect string
|
2458
|
-
above), which by now has already finished execution and holds the simulation
|
2459
|
-
results.
|
2460
|
-
This simulation instance is accessible via
|
2461
|
-
\family typewriter
|
2462
|
-
simulation
|
2463
|
-
\family default
|
2464
|
-
method.
|
2465
|
-
\end_layout
|
2466
|
-
|
2467
|
-
\begin_layout LyX-Code
|
2468
|
-
|
2469
|
-
\color blue
|
2470
|
-
simulation
|
2471
|
-
\end_layout
|
2472
|
-
|
2473
|
-
\begin_layout LyX-Code
|
2474
|
-
#=> #<Simulation: time: 60, pp: 2, tt: 2, oid: 75530290>
|
2475
|
-
\end_layout
|
2476
|
-
|
2477
|
-
\begin_layout Standard
|
2478
|
-
The simulation does not affect the net.
|
2479
|
-
The simulation instance works with its own
|
2480
|
-
\begin_inset Quotes eld
|
2481
|
-
\end_inset
|
2482
|
-
|
2483
|
-
mental image
|
2484
|
-
\begin_inset Quotes erd
|
2485
|
-
\end_inset
|
2486
|
-
|
2487
|
-
of the net, therefore the marking owned by
|
2488
|
-
\family typewriter
|
2489
|
-
YNelson::Place
|
2490
|
-
\family default
|
2491
|
-
instances does not change:
|
2492
|
-
\end_layout
|
2493
|
-
|
2494
|
-
\begin_layout LyX-Code
|
2495
|
-
net.marking #=> [0.5, 0.5]
|
2496
|
-
\end_layout
|
2497
|
-
|
2498
|
-
\begin_layout Standard
|
2499
|
-
In a general case, it would be necessary to specify the simulation settings
|
2500
|
-
(step size, sampling rate, simulation time etc.) before running the simulation.
|
2501
|
-
Since we have not specified any, default settings were used:
|
2502
|
-
\end_layout
|
2503
|
-
|
2504
|
-
\begin_layout LyX-Code
|
2505
|
-
simulation.
|
2506
|
-
\color blue
|
2507
|
-
settings
|
2508
|
-
\end_layout
|
2509
|
-
|
2510
|
-
\begin_layout LyX-Code
|
2511
|
-
#=> {:method=>:basic, :guarded=>false, :step=>0.1, :sampling=>5, :time=>0..60}
|
2512
|
-
\end_layout
|
2513
|
-
|
2514
|
-
\begin_layout Standard
|
2515
|
-
We can see sampling done by the simulation by typing:
|
2516
|
-
\end_layout
|
2517
|
-
|
2518
|
-
\begin_layout LyX-Code
|
2519
|
-
|
2520
|
-
\color blue
|
2521
|
-
print_recording
|
2522
|
-
\end_layout
|
2523
|
-
|
2524
|
-
\begin_layout LyX-Code
|
2525
|
-
#=> :A :B
|
2526
|
-
\end_layout
|
2527
|
-
|
2528
|
-
\begin_layout LyX-Code
|
2529
|
-
----------------
|
2530
|
-
\end_layout
|
2531
|
-
|
2532
|
-
\begin_layout LyX-Code
|
2533
|
-
0.5000 0.5000
|
2534
|
-
\end_layout
|
2535
|
-
|
2536
|
-
\begin_layout LyX-Code
|
2537
|
-
0.4750 0.3892
|
2538
|
-
\end_layout
|
2539
|
-
|
2540
|
-
\begin_layout LyX-Code
|
2541
|
-
0.4500 0.3029
|
2542
|
-
\end_layout
|
2543
|
-
|
2544
|
-
\begin_layout LyX-Code
|
2545
|
-
0.4250 0.2357
|
2546
|
-
\end_layout
|
2547
|
-
|
2548
|
-
\begin_layout LyX-Code
|
2549
|
-
0.4000 0.1835
|
2550
|
-
\end_layout
|
2551
|
-
|
2552
|
-
\begin_layout LyX-Code
|
2553
|
-
0.3750 0.1428
|
2554
|
-
\end_layout
|
2555
|
-
|
2556
|
-
\begin_layout LyX-Code
|
2557
|
-
0.3500 0.1111
|
2558
|
-
\end_layout
|
2559
|
-
|
2560
|
-
\begin_layout LyX-Code
|
2561
|
-
0.3250 0.0865
|
2562
|
-
\end_layout
|
2563
|
-
|
2564
|
-
\begin_layout LyX-Code
|
2565
|
-
0.3000 0.0673
|
2566
|
-
\end_layout
|
2567
|
-
|
2568
|
-
\begin_layout LyX-Code
|
2569
|
-
0.2750 0.0524
|
2570
|
-
\end_layout
|
2571
|
-
|
2572
|
-
\begin_layout LyX-Code
|
2573
|
-
0.2500 0.0408
|
2574
|
-
\end_layout
|
2575
|
-
|
2576
|
-
\begin_layout LyX-Code
|
2577
|
-
0.2250 0.0317
|
2578
|
-
\end_layout
|
2579
|
-
|
2580
|
-
\begin_layout LyX-Code
|
2581
|
-
0.2000 0.0247
|
2582
|
-
\end_layout
|
2583
|
-
|
2584
|
-
\begin_layout LyX-Code
|
2585
|
-
nil
|
2586
|
-
\end_layout
|
2587
|
-
|
2588
|
-
\begin_layout Standard
|
2589
|
-
Indeed,
|
2590
|
-
\family typewriter
|
2591
|
-
A
|
2592
|
-
\family default
|
2593
|
-
is decreasing at a constant rate, while
|
2594
|
-
\family typewriter
|
2595
|
-
B
|
2596
|
-
\family default
|
2597
|
-
undergoes logarithmic decay.
|
2598
|
-
In a graphical desktop, we can plot a graph (requires
|
2599
|
-
\emph on
|
2600
|
-
gnuplot
|
2601
|
-
\emph default
|
2602
|
-
gem):
|
2603
|
-
\end_layout
|
2604
|
-
|
2605
|
-
\begin_layout LyX-Code
|
2606
|
-
|
2607
|
-
\color blue
|
2608
|
-
recording.plot
|
2609
|
-
\color inherit
|
2610
|
-
# plots a graph
|
2611
|
-
\end_layout
|
2612
|
-
|
2613
|
-
\begin_layout Standard
|
2614
|
-
Previous command plots the default feature set, which is marking of the
|
2615
|
-
places.
|
2616
|
-
We can investigate also features of the recording (gradient or delta of
|
2617
|
-
places, firing or flux of the transitions...):
|
2618
|
-
\end_layout
|
2619
|
-
|
2620
|
-
\begin_layout LyX-Code
|
2621
|
-
recording.
|
2622
|
-
\color blue
|
2623
|
-
gradient
|
2624
|
-
\color inherit
|
2625
|
-
.plot
|
2626
|
-
\end_layout
|
2627
|
-
|
2628
|
-
\begin_layout LyX-Code
|
2629
|
-
recording.
|
2630
|
-
\color blue
|
2631
|
-
flux
|
2632
|
-
\color inherit
|
2633
|
-
.plot
|
2634
|
-
\end_layout
|
2635
|
-
|
2636
|
-
\begin_layout LyX-Code
|
2637
|
-
recording.
|
2638
|
-
\color blue
|
2639
|
-
delta
|
2640
|
-
\color inherit
|
2641
|
-
(
|
2642
|
-
\color blue
|
2643
|
-
delta_time
|
2644
|
-
\color inherit
|
2645
|
-
: 0.1 ).plot
|
2646
|
-
\end_layout
|
2647
|
-
|
2648
|
-
\begin_layout Standard
|
2649
|
-
The last feature set – delta – requires
|
2650
|
-
\family typewriter
|
2651
|
-
delta_time
|
2652
|
-
\family default
|
2653
|
-
named argument to extrapolate the changes (deltas) of the places in the
|
2654
|
-
given delta time.
|
2655
|
-
As for
|
2656
|
-
\family typewriter
|
2657
|
-
\color blue
|
2658
|
-
firing
|
2659
|
-
\family default
|
2660
|
-
\color inherit
|
2661
|
-
, a feature of
|
2662
|
-
\family typewriter
|
2663
|
-
tS
|
2664
|
-
\family default
|
2665
|
-
transitions, the plot would show nothing here, as there ar no
|
2666
|
-
\family typewriter
|
2667
|
-
tS
|
2668
|
-
\family default
|
2669
|
-
transitions here.
|
2670
|
-
\end_layout
|
2671
|
-
|
2672
|
-
\begin_layout Part*
|
2673
|
-
Example IV: A real system.
|
2674
|
-
\end_layout
|
2675
|
-
|
2676
|
-
\begin_layout Standard
|
2677
|
-
A highly simplified cell-biological pathway.
|
2678
|
-
Let's first define some assumptions.
|
2679
|
-
Type in the following commands (output not shown):
|
2680
|
-
\end_layout
|
2681
|
-
|
2682
|
-
\begin_layout LyX-Code
|
2683
|
-
require 'y_nelson'
|
2684
|
-
\end_layout
|
2685
|
-
|
2686
|
-
\begin_layout LyX-Code
|
2687
|
-
include YNelson
|
2688
|
-
\end_layout
|
2689
|
-
|
2690
|
-
\begin_layout LyX-Code
|
2691
|
-
|
2692
|
-
\end_layout
|
2693
|
-
|
2694
|
-
\begin_layout LyX-Code
|
2695
|
-
Pieces_per_microM = 100_000
|
2696
|
-
\end_layout
|
2697
|
-
|
2698
|
-
\begin_layout LyX-Code
|
2699
|
-
|
2700
|
-
\color blue
|
2701
|
-
set_step
|
2702
|
-
\color inherit
|
2703
|
-
10
|
2704
|
-
\end_layout
|
2705
|
-
|
2706
|
-
\begin_layout LyX-Code
|
2707
|
-
|
2708
|
-
\color blue
|
2709
|
-
set_sampling
|
2710
|
-
\color inherit
|
2711
|
-
30
|
2712
|
-
\end_layout
|
2713
|
-
|
2714
|
-
\begin_layout LyX-Code
|
2715
|
-
|
2716
|
-
\color blue
|
2717
|
-
set_target_time
|
2718
|
-
\color inherit
|
2719
|
-
30 * 60
|
2720
|
-
\end_layout
|
2721
|
-
|
2722
|
-
\begin_layout Standard
|
2723
|
-
Let's define places corresponding to chemical species first (note that
|
2724
|
-
\family typewriter
|
2725
|
-
:
|
2726
|
-
\color blue
|
2727
|
-
m!
|
2728
|
-
\family default
|
2729
|
-
\color inherit
|
2730
|
-
is a synonym for
|
2731
|
-
\family typewriter
|
2732
|
-
:default_marking)
|
2733
|
-
\end_layout
|
2734
|
-
|
2735
|
-
\begin_layout LyX-Code
|
2736
|
-
AMP = Place
|
2737
|
-
\color blue
|
2738
|
-
m!
|
2739
|
-
\color inherit
|
2740
|
-
: 8695.0
|
2741
|
-
\end_layout
|
2742
|
-
|
2743
|
-
\begin_layout LyX-Code
|
2744
|
-
ADP = Place m!: 6521.0
|
2745
|
-
\end_layout
|
2746
|
-
|
2747
|
-
\begin_layout LyX-Code
|
2748
|
-
ATP = Place m!: 3152.0
|
2749
|
-
\end_layout
|
2750
|
-
|
2751
|
-
\begin_layout LyX-Code
|
2752
|
-
DeoxyCytidine = Place m!: 5.0
|
2753
|
-
\end_layout
|
2754
|
-
|
2755
|
-
\begin_layout LyX-Code
|
2756
|
-
DeoxyCTP = Place m!: 20.0
|
2757
|
-
\end_layout
|
2758
|
-
|
2759
|
-
\begin_layout LyX-Code
|
2760
|
-
DeoxyGMP = Place m!: 20.0
|
2761
|
-
\end_layout
|
2762
|
-
|
2763
|
-
\begin_layout LyX-Code
|
2764
|
-
UMP_UDP_pool = Place m!: 2737.0
|
2765
|
-
\end_layout
|
2766
|
-
|
2767
|
-
\begin_layout LyX-Code
|
2768
|
-
DeoxyUMP_DeoxyUDP_pool = Place m!: 10.0
|
2769
|
-
\end_layout
|
2770
|
-
|
2771
|
-
\begin_layout LyX-Code
|
2772
|
-
DeoxyTMP = Place m!: 50.0
|
2773
|
-
\end_layout
|
2774
|
-
|
2775
|
-
\begin_layout LyX-Code
|
2776
|
-
DeoxyTDP_DeoxyTTP_pool = Place m!: 100.0
|
2777
|
-
\end_layout
|
2778
|
-
|
2779
|
-
\begin_layout LyX-Code
|
2780
|
-
Thymidine = Place m!: 10.0
|
2781
|
-
\end_layout
|
2782
|
-
|
2783
|
-
\begin_layout Standard
|
2784
|
-
All the places above have their marking in micromolars.
|
2785
|
-
The enzyme places below will have their marking in molecules per cell:
|
2786
|
-
\end_layout
|
2787
|
-
|
2788
|
-
\begin_layout LyX-Code
|
2789
|
-
TK1 = Place m!: 100_000 / Pieces_per_microM
|
2790
|
-
\end_layout
|
2791
|
-
|
2792
|
-
\begin_layout LyX-Code
|
2793
|
-
TYMS = Place m!: 100_000 / Pieces_per_microM
|
2794
|
-
\end_layout
|
2795
|
-
|
2796
|
-
\begin_layout LyX-Code
|
2797
|
-
RNR = Place m!: 100_000 / Pieces_per_microM
|
2798
|
-
\end_layout
|
2799
|
-
|
2800
|
-
\begin_layout LyX-Code
|
2801
|
-
TMPK = Place m!: 100_000 / Pieces_per_microM
|
2802
|
-
\end_layout
|
2803
|
-
|
2804
|
-
\begin_layout Standard
|
2805
|
-
Enzyme molecular weights:
|
2806
|
-
\end_layout
|
2807
|
-
|
2808
|
-
\begin_layout LyX-Code
|
2809
|
-
TK1_kDa = 24.8
|
2810
|
-
\end_layout
|
2811
|
-
|
2812
|
-
\begin_layout LyX-Code
|
2813
|
-
TYMS_kDa = 66.0
|
2814
|
-
\end_layout
|
2815
|
-
|
2816
|
-
\begin_layout LyX-Code
|
2817
|
-
RNR_kDa = 140.0
|
2818
|
-
\end_layout
|
2819
|
-
|
2820
|
-
\begin_layout LyX-Code
|
2821
|
-
TMPK_kDa = 50.0
|
2822
|
-
\end_layout
|
2823
|
-
|
2824
|
-
\begin_layout Standard
|
2825
|
-
Enzyme specific activities (in
|
2826
|
-
\emph on
|
2827
|
-
micromolar
|
2828
|
-
\emph default
|
2829
|
-
/
|
2830
|
-
\emph on
|
2831
|
-
minute
|
2832
|
-
\emph default
|
2833
|
-
/
|
2834
|
-
\emph on
|
2835
|
-
mg
|
2836
|
-
\emph default
|
2837
|
-
):
|
2838
|
-
\end_layout
|
2839
|
-
|
2840
|
-
\begin_layout LyX-Code
|
2841
|
-
TK1_a = 5.40
|
2842
|
-
\end_layout
|
2843
|
-
|
2844
|
-
\begin_layout LyX-Code
|
2845
|
-
TYMS_a = 3.80
|
2846
|
-
\end_layout
|
2847
|
-
|
2848
|
-
\begin_layout LyX-Code
|
2849
|
-
RNR_a = 1.00
|
2850
|
-
\end_layout
|
2851
|
-
|
2852
|
-
\begin_layout LyX-Code
|
2853
|
-
TMPK_a = 0.83
|
2854
|
-
\end_layout
|
2855
|
-
|
2856
|
-
\begin_layout Standard
|
2857
|
-
Some species are kept fixed (as simulation-level clamps):
|
2858
|
-
\end_layout
|
2859
|
-
|
2860
|
-
\begin_layout LyX-Code
|
2861
|
-
|
2862
|
-
\color blue
|
2863
|
-
clamp
|
2864
|
-
\color inherit
|
2865
|
-
AMP: 8695.0, ADP: 6521.0, ATP: 3152.0
|
2866
|
-
\end_layout
|
2867
|
-
|
2868
|
-
\begin_layout LyX-Code
|
2869
|
-
clamp DeoxyCytidine: 0.5, DeoxyCTP: 1.0, DeoxyGMP: 1.0
|
2870
|
-
\end_layout
|
2871
|
-
|
2872
|
-
\begin_layout LyX-Code
|
2873
|
-
clamp Thymidine: 0.5
|
2874
|
-
\end_layout
|
2875
|
-
|
2876
|
-
\begin_layout LyX-Code
|
2877
|
-
clamp UMP_UDP_pool: 2737.0
|
2878
|
-
\end_layout
|
2879
|
-
|
2880
|
-
\begin_layout Standard
|
2881
|
-
Before defining transitions, let's define some functions first:
|
2882
|
-
\end_layout
|
2883
|
-
|
2884
|
-
\begin_layout LyX-Code
|
2885
|
-
Vmax_per_min_per_enz_molecule =
|
2886
|
-
\end_layout
|
2887
|
-
|
2888
|
-
\begin_layout LyX-Code
|
2889
|
-
lambda { |spec_act_microM_per_min_per_mg, kDa|
|
2890
|
-
\end_layout
|
2891
|
-
|
2892
|
-
\begin_layout LyX-Code
|
2893
|
-
spec_act_microM_per_min_per_mg * kDa }
|
2894
|
-
\end_layout
|
2895
|
-
|
2896
|
-
\begin_layout LyX-Code
|
2897
|
-
Vmax_per_min =
|
2898
|
-
\end_layout
|
2899
|
-
|
2900
|
-
\begin_layout LyX-Code
|
2901
|
-
lambda { |spec_act, kDa, enz_molecules_per_cell|
|
2902
|
-
\end_layout
|
2903
|
-
|
2904
|
-
\begin_layout LyX-Code
|
2905
|
-
Vmax_per_min_per_enz_molecule.( spec_act, kDa ) *
|
2906
|
-
\end_layout
|
2907
|
-
|
2908
|
-
\begin_layout LyX-Code
|
2909
|
-
enz_molecules_per_cell }
|
2910
|
-
\end_layout
|
2911
|
-
|
2912
|
-
\begin_layout LyX-Code
|
2913
|
-
Vmax_per_s =
|
2914
|
-
\end_layout
|
2915
|
-
|
2916
|
-
\begin_layout LyX-Code
|
2917
|
-
lambda { |spec_act, kDa, enz_mol_per_cell|
|
2918
|
-
\end_layout
|
2919
|
-
|
2920
|
-
\begin_layout LyX-Code
|
2921
|
-
Vmax_per_min.( spec_act, kDa, enz_mol_per_cell ) / 60 }
|
2922
|
-
\end_layout
|
2923
|
-
|
2924
|
-
\begin_layout LyX-Code
|
2925
|
-
Km_reduced =
|
2926
|
-
\end_layout
|
2927
|
-
|
2928
|
-
\begin_layout LyX-Code
|
2929
|
-
lambda { |km, ki_hash={}|
|
2930
|
-
\end_layout
|
2931
|
-
|
2932
|
-
\begin_layout LyX-Code
|
2933
|
-
ki_hash.map { |c, ki| c / ki }.reduce( 1, :+ ) * km }
|
2934
|
-
\end_layout
|
2935
|
-
|
2936
|
-
\begin_layout LyX-Code
|
2937
|
-
Occupancy =
|
2938
|
-
\end_layout
|
2939
|
-
|
2940
|
-
\begin_layout LyX-Code
|
2941
|
-
lambda { |c, km, compet_inh_w_Ki_hash={}|
|
2942
|
-
\end_layout
|
2943
|
-
|
2944
|
-
\begin_layout LyX-Code
|
2945
|
-
c / ( c + Km_reduced.( km, compet_inh_w_Ki_hash ) ) }
|
2946
|
-
\end_layout
|
2947
|
-
|
2948
|
-
\begin_layout LyX-Code
|
2949
|
-
MM_with_inh_microM_per_second =
|
2950
|
-
\end_layout
|
2951
|
-
|
2952
|
-
\begin_layout LyX-Code
|
2953
|
-
lambda { |c, spec_act, kDa, enz_mol_per_cell, km, ki_hash={}|
|
2954
|
-
\end_layout
|
2955
|
-
|
2956
|
-
\begin_layout LyX-Code
|
2957
|
-
Vmax_per_s.( spec_act, kDa, enz_mol_per_cell ) *
|
2958
|
-
\end_layout
|
2959
|
-
|
2960
|
-
\begin_layout LyX-Code
|
2961
|
-
Occupancy.( c, km, ki_hash ) }
|
2962
|
-
\end_layout
|
2963
|
-
|
2964
|
-
\begin_layout LyX-Code
|
2965
|
-
MMi = MM_with_inh_microM_per_second
|
2966
|
-
\end_layout
|
2967
|
-
|
2968
|
-
\begin_layout Standard
|
2969
|
-
Michaelis constants:
|
2970
|
-
\end_layout
|
2971
|
-
|
2972
|
-
\begin_layout LyX-Code
|
2973
|
-
TK1_Thymidine_Km = 5.0
|
2974
|
-
\end_layout
|
2975
|
-
|
2976
|
-
\begin_layout LyX-Code
|
2977
|
-
TYMS_DeoxyUMP_Km = 2.0
|
2978
|
-
\end_layout
|
2979
|
-
|
2980
|
-
\begin_layout LyX-Code
|
2981
|
-
RNR_UDP_Km = 1.0
|
2982
|
-
\end_layout
|
2983
|
-
|
2984
|
-
\begin_layout LyX-Code
|
2985
|
-
DNA_creation_speed = 3_000_000_000 / ( 12 * 3600 )
|
2986
|
-
\end_layout
|
2987
|
-
|
2988
|
-
\begin_layout LyX-Code
|
2989
|
-
TMPK_DeoxyTMP_Km = 12.0
|
2990
|
-
\end_layout
|
2991
|
-
|
2992
|
-
\begin_layout Standard
|
2993
|
-
And finally, let us define the transitions:
|
2994
|
-
\end_layout
|
2995
|
-
|
2996
|
-
\begin_layout LyX-Code
|
2997
|
-
Transition name: :TK1_Thymidine_DeoxyTMP,
|
2998
|
-
\end_layout
|
2999
|
-
|
3000
|
-
\begin_layout LyX-Code
|
3001
|
-
|
3002
|
-
\color blue
|
3003
|
-
domain:
|
3004
|
-
\color inherit
|
3005
|
-
[ Thymidine, TK1, DeoxyTDP_DeoxyTTP_pool, DeoxyCTP,
|
3006
|
-
\end_layout
|
3007
|
-
|
3008
|
-
\begin_layout LyX-Code
|
3009
|
-
DeoxyCytidine, AMP, ADP, ATP ],
|
3010
|
-
\end_layout
|
3011
|
-
|
3012
|
-
\begin_layout LyX-Code
|
3013
|
-
stoichiometry: { Thymidine: -1, DeoxyTMP: 1 },
|
3014
|
-
\end_layout
|
3015
|
-
|
3016
|
-
\begin_layout LyX-Code
|
3017
|
-
rate: proc { |c, e, pool1, ci2, ci3, master1, master2, master3|
|
3018
|
-
\end_layout
|
3019
|
-
|
3020
|
-
\begin_layout LyX-Code
|
3021
|
-
ci1 = pool1 * master3 / ( master2 + master3 )
|
3022
|
-
\end_layout
|
3023
|
-
|
3024
|
-
\begin_layout LyX-Code
|
3025
|
-
MMi.( c, TK1_a, TK1_kDa, e, TK1_Thymidine_Km,
|
3026
|
-
\end_layout
|
3027
|
-
|
3028
|
-
\begin_layout LyX-Code
|
3029
|
-
ci1 => 13.5, ci2 => 0.8, ci3 => 40.0 ) }
|
3030
|
-
\end_layout
|
3031
|
-
|
3032
|
-
\begin_layout LyX-Code
|
3033
|
-
|
3034
|
-
\end_layout
|
3035
|
-
|
3036
|
-
\begin_layout LyX-Code
|
3037
|
-
Transition name: :TYMS_DeoxyUMP_DeoxyTMP,
|
3038
|
-
\end_layout
|
3039
|
-
|
3040
|
-
\begin_layout LyX-Code
|
3041
|
-
domain: [ DeoxyUMP_DeoxyUDP_pool, TYMS, AMP, ADP, ATP ],
|
3042
|
-
\end_layout
|
3043
|
-
|
3044
|
-
\begin_layout LyX-Code
|
3045
|
-
stoichiometry: { DeoxyUMP_DeoxyUDP_pool: -1, DeoxyTMP: 1 },
|
3046
|
-
\end_layout
|
3047
|
-
|
3048
|
-
\begin_layout LyX-Code
|
3049
|
-
rate: proc { |pool, e, mono, di, tri|
|
3050
|
-
\end_layout
|
3051
|
-
|
3052
|
-
\begin_layout LyX-Code
|
3053
|
-
c = pool * di / ( mono + di )
|
3054
|
-
\end_layout
|
3055
|
-
|
3056
|
-
\begin_layout LyX-Code
|
3057
|
-
MMi.( c, TYMS_a, TYMS_kDa, e, TYMS_DeoxyUMP_Km
|
3058
|
-
) }
|
3059
|
-
\end_layout
|
3060
|
-
|
3061
|
-
\begin_layout LyX-Code
|
3062
|
-
|
3063
|
-
\end_layout
|
3064
|
-
|
3065
|
-
\begin_layout LyX-Code
|
3066
|
-
Transition name: :RNR_UDP_DeoxyUDP,
|
3067
|
-
\end_layout
|
3068
|
-
|
3069
|
-
\begin_layout LyX-Code
|
3070
|
-
domain: [ UMP_UDP_pool, RNR, DeoxyUMP_DeoxyUDP_pool, AMP, ADP,
|
3071
|
-
ATP ],
|
3072
|
-
\end_layout
|
3073
|
-
|
3074
|
-
\begin_layout LyX-Code
|
3075
|
-
stoichiometry: { UMP_UDP_pool: -1, DeoxyUMP_DeoxyUDP_pool: 1
|
3076
|
-
},
|
3077
|
-
\end_layout
|
3078
|
-
|
3079
|
-
\begin_layout LyX-Code
|
3080
|
-
rate: proc { |pool, e, mono, di, tri|
|
3081
|
-
\end_layout
|
3082
|
-
|
3083
|
-
\begin_layout LyX-Code
|
3084
|
-
c = pool * di / ( mono + di )
|
3085
|
-
\end_layout
|
3086
|
-
|
3087
|
-
\begin_layout LyX-Code
|
3088
|
-
MMi.( c, RNR_a, RNR_kDa, e, RNR_UDP_Km ) }
|
3089
|
-
\end_layout
|
3090
|
-
|
3091
|
-
\begin_layout LyX-Code
|
3092
|
-
|
3093
|
-
\end_layout
|
3094
|
-
|
3095
|
-
\begin_layout LyX-Code
|
3096
|
-
Transition name: :DNA_polymerase_consumption_of_DeoxyTTP,
|
3097
|
-
\end_layout
|
3098
|
-
|
3099
|
-
\begin_layout LyX-Code
|
3100
|
-
stoichiometry: { DeoxyTDP_DeoxyTTP_pool: -1 },
|
3101
|
-
\end_layout
|
3102
|
-
|
3103
|
-
\begin_layout LyX-Code
|
3104
|
-
rate: proc { DNA_creation_speed / 4 }
|
3105
|
-
\end_layout
|
3106
|
-
|
3107
|
-
\begin_layout LyX-Code
|
3108
|
-
|
3109
|
-
\end_layout
|
3110
|
-
|
3111
|
-
\begin_layout LyX-Code
|
3112
|
-
Transition name: :TMPK_DeoxyTMP_DeoxyTDP,
|
3113
|
-
\end_layout
|
3114
|
-
|
3115
|
-
\begin_layout LyX-Code
|
3116
|
-
domain: [ DeoxyTMP, TMPK, DeoxyTDP_DeoxyTTP_pool, DeoxyGMP, AMP,
|
3117
|
-
ADP, ATP ],
|
3118
|
-
\end_layout
|
3119
|
-
|
3120
|
-
\begin_layout LyX-Code
|
3121
|
-
stoichiometry: { DeoxyTMP: -1, TMPK: 0, DeoxyTDP_DeoxyTTP_pool:
|
3122
|
-
1 },
|
3123
|
-
\end_layout
|
3124
|
-
|
3125
|
-
\begin_layout LyX-Code
|
3126
|
-
rate: proc { |c, e, pool, ci4, mono, di, tri|
|
3127
|
-
\end_layout
|
3128
|
-
|
3129
|
-
\begin_layout LyX-Code
|
3130
|
-
ci1 = di
|
3131
|
-
\end_layout
|
3132
|
-
|
3133
|
-
\begin_layout LyX-Code
|
3134
|
-
ci2 = pool * di / ( di + tri )
|
3135
|
-
\end_layout
|
3136
|
-
|
3137
|
-
\begin_layout LyX-Code
|
3138
|
-
ci3 = pool * tri / ( di + tri )
|
3139
|
-
\end_layout
|
3140
|
-
|
3141
|
-
\begin_layout LyX-Code
|
3142
|
-
MMi.( c, TMPK_a, TMPK_kDa, e, TMPK_DeoxyTMP_Km,
|
3143
|
-
\end_layout
|
3144
|
-
|
3145
|
-
\begin_layout LyX-Code
|
3146
|
-
ci1 => 250.0, ci2 => 30.0, ci3 => 750, ci4 =>
|
3147
|
-
117 ) }
|
3148
|
-
\end_layout
|
3149
|
-
|
3150
|
-
\begin_layout LyX-Code
|
3151
|
-
|
3152
|
-
\end_layout
|
3153
|
-
|
3154
|
-
\begin_layout LyX-Code
|
3155
|
-
Transition name: :PhosphataseI,
|
3156
|
-
\end_layout
|
3157
|
-
|
3158
|
-
\begin_layout LyX-Code
|
3159
|
-
stoichiometry: { DeoxyTMP: -1, Thymidine: 1 },
|
3160
|
-
\end_layout
|
3161
|
-
|
3162
|
-
\begin_layout LyX-Code
|
3163
|
-
rate: 0.04
|
3164
|
-
\end_layout
|
3165
|
-
|
3166
|
-
\begin_layout LyX-Code
|
3167
|
-
|
3168
|
-
\end_layout
|
3169
|
-
|
3170
|
-
\begin_layout LyX-Code
|
3171
|
-
Transition name: :PhosphataseII,
|
3172
|
-
\end_layout
|
3173
|
-
|
3174
|
-
\begin_layout LyX-Code
|
3175
|
-
stoichiometry: { DeoxyTDP_DeoxyTTP_pool: -1, DeoxyTMP: 1 },
|
3176
|
-
\end_layout
|
3177
|
-
|
3178
|
-
\begin_layout LyX-Code
|
3179
|
-
rate: 0.01
|
3180
|
-
\end_layout
|
3181
|
-
|
3182
|
-
\begin_layout Standard
|
3183
|
-
The created net can be visualized by:
|
3184
|
-
\end_layout
|
3185
|
-
|
3186
|
-
\begin_layout LyX-Code
|
3187
|
-
net.visualize
|
3188
|
-
\end_layout
|
3189
|
-
|
3190
|
-
\begin_layout Standard
|
3191
|
-
The simulation should work.
|
3192
|
-
\end_layout
|
3193
|
-
|
3194
|
-
\begin_layout LyX-Code
|
3195
|
-
run!
|
3196
|
-
\end_layout
|
3197
|
-
|
3198
|
-
\begin_layout Standard
|
3199
|
-
State recording can be plotted by:
|
3200
|
-
\end_layout
|
3201
|
-
|
3202
|
-
\begin_layout LyX-Code
|
3203
|
-
recording.plot
|
3204
|
-
\end_layout
|
3205
|
-
|
3206
|
-
\begin_layout Standard
|
3207
|
-
Flux of the transitions can be plotted by:
|
3208
|
-
\end_layout
|
3209
|
-
|
3210
|
-
\begin_layout LyX-Code
|
3211
|
-
recording.flux.plot
|
3212
|
-
\end_layout
|
3213
|
-
|
3214
|
-
\begin_layout Standard
|
3215
|
-
Please note that although this system qualitatively represents part of the
|
3216
|
-
deoxynucleotide metabolism network, its behavior is not realistic, because
|
3217
|
-
the available kinetic constants are not precise.
|
3218
|
-
\end_layout
|
3219
|
-
|
3220
|
-
\begin_layout Part*
|
3221
|
-
Example V: Using SY.
|
3222
|
-
\end_layout
|
3223
|
-
|
3224
|
-
\begin_layout Standard
|
3225
|
-
Here, we'll take a look at using
|
3226
|
-
\family typewriter
|
3227
|
-
YNelson
|
3228
|
-
\family default
|
3229
|
-
with
|
3230
|
-
\family typewriter
|
3231
|
-
\color blue
|
3232
|
-
SY
|
3233
|
-
\family default
|
3234
|
-
metrology library
|
3235
|
-
\color inherit
|
3236
|
-
.
|
3237
|
-
If you are experienced with biochemical modeling, then you surely know
|
3238
|
-
how big pain the physical units are.
|
3239
|
-
Also, in
|
3240
|
-
\series bold
|
3241
|
-
Example III
|
3242
|
-
\series default
|
3243
|
-
, you might have noticed how much attention has been spent on units (in
|
3244
|
-
the assumptions, variable names, constant names...) You could have noticed
|
3245
|
-
messy unit conversion formulas.
|
3246
|
-
The aim of
|
3247
|
-
\family typewriter
|
3248
|
-
SY
|
3249
|
-
\family default
|
3250
|
-
is to take care of all this, to relieve the modeler from the task of unit
|
3251
|
-
conversion, to clean up the model code, and let the modeler concentrate
|
3252
|
-
on the real issue.
|
3253
|
-
\end_layout
|
3254
|
-
|
3255
|
-
\begin_layout Subsection*
|
3256
|
-
|
3257
|
-
\family typewriter
|
3258
|
-
SY
|
3259
|
-
\family default
|
3260
|
-
metrology library
|
3261
|
-
\end_layout
|
3262
|
-
|
3263
|
-
\begin_layout Standard
|
3264
|
-
|
3265
|
-
\family typewriter
|
3266
|
-
SY
|
3267
|
-
\family default
|
3268
|
-
is publicly available as a Ruby gem '
|
3269
|
-
\family typewriter
|
3270
|
-
sy
|
3271
|
-
\family default
|
3272
|
-
'.
|
3273
|
-
After installing it (
|
3274
|
-
\family typewriter
|
3275
|
-
gem install sy
|
3276
|
-
\family default
|
3277
|
-
), type:
|
3278
|
-
\end_layout
|
3279
|
-
|
3280
|
-
\begin_layout LyX-Code
|
3281
|
-
require 'sy'
|
3282
|
-
\end_layout
|
3283
|
-
|
3284
|
-
\begin_layout Standard
|
3285
|
-
Afterwards, your
|
3286
|
-
\family typewriter
|
3287
|
-
\color red
|
3288
|
-
Numeric
|
3289
|
-
\family default
|
3290
|
-
\color inherit
|
3291
|
-
objects (that is, numbers) should respond to methods representing physical
|
3292
|
-
units:
|
3293
|
-
\end_layout
|
3294
|
-
|
3295
|
-
\begin_layout LyX-Code
|
3296
|
-
1.m #=> #<±Magnitude: 1.m>
|
3297
|
-
\end_layout
|
3298
|
-
|
3299
|
-
\begin_layout LyX-Code
|
3300
|
-
1.s #=> #<±Magnitude: 1.s>
|
3301
|
-
\end_layout
|
3302
|
-
|
3303
|
-
\begin_layout LyX-Code
|
3304
|
-
1.kg.m.s(-2) #=> #<±Magnitude: 1.N>
|
3305
|
-
\end_layout
|
3306
|
-
|
3307
|
-
\begin_layout LyX-Code
|
3308
|
-
1.cm + 1.mm #=> #<±Magnitude: 0.011.m>
|
3309
|
-
\end_layout
|
3310
|
-
|
3311
|
-
\begin_layout Standard
|
3312
|
-
The core of the trick is that instead of naked numbers, numbers become magnitude
|
3313
|
-
s (
|
3314
|
-
\family typewriter
|
3315
|
-
SY::Magnitude
|
3316
|
-
\family default
|
3317
|
-
) of specified physical quantities:
|
3318
|
-
\end_layout
|
3319
|
-
|
3320
|
-
\begin_layout LyX-Code
|
3321
|
-
1.m.quantity #=> #<Quantity:Length>
|
3322
|
-
\end_layout
|
3323
|
-
|
3324
|
-
\begin_layout LyX-Code
|
3325
|
-
1.cm.min⁻¹.quantity #=> #<Quantity:Speed>
|
3326
|
-
\end_layout
|
3327
|
-
|
3328
|
-
\begin_layout Standard
|
3329
|
-
(You can type
|
3330
|
-
\family typewriter
|
3331
|
-
1.cm.min(-1)
|
3332
|
-
\family default
|
3333
|
-
if you find it difficult to type Unicode superscript characters "
|
3334
|
-
\family typewriter
|
3335
|
-
⁻¹
|
3336
|
-
\family default
|
3337
|
-
".) Magnitudes can be converted back to numbers with
|
3338
|
-
\family typewriter
|
3339
|
-
\color blue
|
3340
|
-
amount
|
3341
|
-
\family default
|
3342
|
-
\color inherit
|
3343
|
-
(alias
|
3344
|
-
\family typewriter
|
3345
|
-
\color blue
|
3346
|
-
to_f)
|
3347
|
-
\family default
|
3348
|
-
\color inherit
|
3349
|
-
method:
|
3350
|
-
\end_layout
|
3351
|
-
|
3352
|
-
\begin_layout LyX-Code
|
3353
|
-
1.km.amount #=> 1000.0
|
3354
|
-
\end_layout
|
3355
|
-
|
3356
|
-
\begin_layout LyX-Code
|
3357
|
-
1.cm.to_f #=> 0.01
|
3358
|
-
\end_layout
|
3359
|
-
|
3360
|
-
\begin_layout Subsection*
|
3361
|
-
Collaboration between
|
3362
|
-
\family typewriter
|
3363
|
-
SY
|
3364
|
-
\family default
|
3365
|
-
and
|
3366
|
-
\family typewriter
|
3367
|
-
YNelson
|
3368
|
-
\end_layout
|
3369
|
-
|
3370
|
-
\begin_layout Standard
|
3371
|
-
In a fresh
|
3372
|
-
\family typewriter
|
3373
|
-
irb
|
3374
|
-
\family default
|
3375
|
-
session, enter:
|
3376
|
-
\end_layout
|
3377
|
-
|
3378
|
-
\begin_layout LyX-Code
|
3379
|
-
require 'sy'
|
3380
|
-
\end_layout
|
3381
|
-
|
3382
|
-
\begin_layout LyX-Code
|
3383
|
-
require 'y_nelson'
|
3384
|
-
\end_layout
|
3385
|
-
|
3386
|
-
\begin_layout LyX-Code
|
3387
|
-
include YNelson
|
3388
|
-
\end_layout
|
3389
|
-
|
3390
|
-
\begin_layout LyX-Code
|
3391
|
-
A = Place m!: 3.mM
|
3392
|
-
\end_layout
|
3393
|
-
|
3394
|
-
\begin_layout LyX-Code
|
3395
|
-
B = Place m!: 4.mM
|
3396
|
-
\end_layout
|
3397
|
-
|
3398
|
-
\begin_layout LyX-Code
|
3399
|
-
A2B = Transition s: { A: -1, B: 1 }, rate: 0.05.s⁻¹
|
3400
|
-
\end_layout
|
3401
|
-
|
3402
|
-
\begin_layout LyX-Code
|
3403
|
-
B_decay = Transition s: { B: -1 }, rate: 0.002.s⁻¹
|
3404
|
-
\end_layout
|
3405
|
-
|
3406
|
-
\begin_layout Standard
|
3407
|
-
We hereby specified marking and rate in physical units.
|
3408
|
-
Presently,
|
3409
|
-
\family typewriter
|
3410
|
-
YNelson
|
3411
|
-
\family default
|
3412
|
-
is not able to simulate such nets, but we can play token game with it:
|
3413
|
-
\end_layout
|
3414
|
-
|
3415
|
-
\begin_layout LyX-Code
|
3416
|
-
net.m #=> [#<±Magnitude: 0.003.M>, #<±Magnitude: 0.004.M>]
|
3417
|
-
\end_layout
|
3418
|
-
|
3419
|
-
\begin_layout LyX-Code
|
3420
|
-
A2B.fire! 1.s
|
3421
|
-
\end_layout
|
3422
|
-
|
3423
|
-
\begin_layout LyX-Code
|
3424
|
-
B_decay.fire! 1.s
|
3425
|
-
\end_layout
|
3426
|
-
|
3427
|
-
\begin_layout LyX-Code
|
3428
|
-
net.m #=> [#<±Magnitude: 0.00285.M>, #<±Magnitude: 0.00414.M>]
|
3429
|
-
\end_layout
|
3430
|
-
|
3431
|
-
\begin_layout Standard
|
3432
|
-
Let us fire the 2 defined transitions for 100 seconds:
|
3433
|
-
\end_layout
|
3434
|
-
|
3435
|
-
\begin_layout LyX-Code
|
3436
|
-
100.times do
|
3437
|
-
\end_layout
|
3438
|
-
|
3439
|
-
\begin_layout LyX-Code
|
3440
|
-
A2B.fire! 1.s
|
3441
|
-
\end_layout
|
3442
|
-
|
3443
|
-
\begin_layout LyX-Code
|
3444
|
-
B_decay.fire! 1.s
|
3445
|
-
\end_layout
|
3446
|
-
|
3447
|
-
\begin_layout LyX-Code
|
3448
|
-
end
|
3449
|
-
\end_layout
|
3450
|
-
|
3451
|
-
\begin_layout LyX-Code
|
3452
|
-
net.m #=> [#<±Magnitude: 1.69e-05.M>, #<±Magnitude: 0.0058.M>]
|
3453
|
-
\end_layout
|
3454
|
-
|
3455
|
-
\begin_layout Standard
|
3456
|
-
Finally, let us inspect the resulting marking of
|
3457
|
-
\family typewriter
|
3458
|
-
A
|
3459
|
-
\family default
|
3460
|
-
and
|
3461
|
-
\family typewriter
|
3462
|
-
B
|
3463
|
-
\family default
|
3464
|
-
expressed in micromolars:
|
3465
|
-
\end_layout
|
3466
|
-
|
3467
|
-
\begin_layout LyX-Code
|
3468
|
-
A.marking.
|
3469
|
-
\color blue
|
3470
|
-
in
|
3471
|
-
\color inherit
|
3472
|
-
:µM #=> 16.873508277951963
|
3473
|
-
\end_layout
|
3474
|
-
|
3475
|
-
\begin_layout LyX-Code
|
3476
|
-
B.marking.in :µM #=> 5797.976678013365
|
3477
|
-
\end_layout
|
3478
|
-
|
3479
|
-
\begin_layout Part*
|
3480
|
-
Example VI: Other simulation methods
|
3481
|
-
\end_layout
|
3482
|
-
|
3483
|
-
\begin_layout Standard
|
3484
|
-
At this moment, the default simulation method
|
3485
|
-
\family typewriter
|
3486
|
-
basic
|
3487
|
-
\family default
|
3488
|
-
method.
|
3489
|
-
This method is also called is implicit Euler, because when simulating timed
|
3490
|
-
nets, it implies first-order Euler method.
|
3491
|
-
For timed nets, YNelson provides two other methods: Runge-Kutta 4th order
|
3492
|
-
method and Gillespie stochastic method.
|
3493
|
-
Demonstrating Gillespie method:
|
3494
|
-
\end_layout
|
3495
|
-
|
3496
|
-
\begin_layout LyX-Code
|
3497
|
-
require 'y_nelson'
|
3498
|
-
\end_layout
|
3499
|
-
|
3500
|
-
\begin_layout LyX-Code
|
3501
|
-
include YNelson
|
3502
|
-
\end_layout
|
3503
|
-
|
3504
|
-
\begin_layout LyX-Code
|
3505
|
-
|
3506
|
-
\end_layout
|
3507
|
-
|
3508
|
-
\begin_layout LyX-Code
|
3509
|
-
A = Place m!: 10
|
3510
|
-
\end_layout
|
3511
|
-
|
3512
|
-
\begin_layout LyX-Code
|
3513
|
-
B = Place m!: 10
|
3514
|
-
\end_layout
|
3515
|
-
|
3516
|
-
\begin_layout LyX-Code
|
3517
|
-
AB = Place m!: 0
|
3518
|
-
\end_layout
|
3519
|
-
|
3520
|
-
\begin_layout LyX-Code
|
3521
|
-
AB_association = TS A: -1, B: -1, AB: 1, rate: 0.1
|
3522
|
-
\end_layout
|
3523
|
-
|
3524
|
-
\begin_layout LyX-Code
|
3525
|
-
AB_dissociation = TS AB: -1, A: 1, B: 1, rate: 0.1
|
3526
|
-
\end_layout
|
3527
|
-
|
3528
|
-
\begin_layout LyX-Code
|
3529
|
-
A2B = TS A: -1, B: 1, rate: 0.05
|
3530
|
-
\end_layout
|
3531
|
-
|
3532
|
-
\begin_layout LyX-Code
|
3533
|
-
B2A = TS A: 1, B: -1, rate: 0.07
|
3534
|
-
\end_layout
|
3535
|
-
|
3536
|
-
\begin_layout LyX-Code
|
3537
|
-
|
3538
|
-
\end_layout
|
3539
|
-
|
3540
|
-
\begin_layout LyX-Code
|
3541
|
-
set_step 1
|
3542
|
-
\end_layout
|
3543
|
-
|
3544
|
-
\begin_layout LyX-Code
|
3545
|
-
set_target_time 50
|
3546
|
-
\end_layout
|
3547
|
-
|
3548
|
-
\begin_layout LyX-Code
|
3549
|
-
set_sampling 1
|
3550
|
-
\end_layout
|
3551
|
-
|
3552
|
-
\begin_layout LyX-Code
|
3553
|
-
set_simulation_method :gillespie
|
3554
|
-
\end_layout
|
3555
|
-
|
3556
|
-
\begin_layout LyX-Code
|
3557
|
-
|
3558
|
-
\end_layout
|
3559
|
-
|
3560
|
-
\begin_layout LyX-Code
|
3561
|
-
run!
|
3562
|
-
\end_layout
|
3563
|
-
|
3564
|
-
\begin_layout LyX-Code
|
3565
|
-
print_recording
|
3566
|
-
\end_layout
|
3567
|
-
|
3568
|
-
\begin_layout LyX-Code
|
3569
|
-
plot_state
|
3570
|
-
\end_layout
|
3571
|
-
|
3572
|
-
\begin_layout Standard
|
3573
|
-
The state recording should show a random walk of the system state over the
|
3574
|
-
period of 50 time units.
|
3575
|
-
\end_layout
|
3576
|
-
|
3577
|
-
\begin_layout LyX-Code
|
3578
|
-
|
3579
|
-
\end_layout
|
3580
|
-
|
3581
|
-
\begin_layout LyX-Code
|
3582
|
-
\begin_inset CommandInset bibtex
|
3583
|
-
LatexCommand bibtex
|
3584
|
-
bibfiles "/home/boris/b/8oav/ptn/ptn"
|
3585
|
-
options "plainnat"
|
3586
|
-
|
3587
|
-
\end_inset
|
3588
|
-
|
3589
|
-
|
3590
|
-
\end_layout
|
3591
|
-
|
3592
|
-
\end_body
|
3593
|
-
\end_document
|