y_petri 2.4.8 → 2.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3429 @@
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, including
511
+ \family typewriter
512
+ YPetri
513
+ \family default
514
+ .
515
+ However,
516
+ \family typewriter
517
+ YPetri
518
+ \family default
519
+ has other 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';
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';
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( marking: 5 ) #=> B
762
+ \end_layout
763
+
764
+ \begin_layout Standard
765
+ In the above, we have so far defined 2 Petri net places (named
766
+ \family typewriter
767
+ A
768
+ \family default
769
+ ,
770
+ \family typewriter
771
+ B
772
+ \family default
773
+ ).
774
+ You can check them by typing:
775
+ \end_layout
776
+
777
+ \begin_layout LyX-Code
778
+
779
+ \color blue
780
+ places
781
+ \color inherit
782
+ () #=> [A, B]
783
+ \end_layout
784
+
785
+ \begin_layout LyX-Code
786
+ A.
787
+ \color blue
788
+ name
789
+ \color inherit
790
+ () #=> :A
791
+ \end_layout
792
+
793
+ \begin_layout Standard
794
+ These have automatically become part of a default Petri net instance (of
795
+
796
+ \family typewriter
797
+ YNelson::Net
798
+ \family default
799
+ class; object id may vary):
800
+ \end_layout
801
+
802
+ \begin_layout LyX-Code
803
+
804
+ \color blue
805
+ net
806
+ \color inherit
807
+ () #=> #<Net: name: Top, 2 places, 0 transitions>
808
+ \end_layout
809
+
810
+ \begin_layout Standard
811
+ Of course, you have full power of Ruby at your disposal.
812
+ To eg.
813
+ list only place names as strings, you can use standard Ruby methods:
814
+ \end_layout
815
+
816
+ \begin_layout LyX-Code
817
+ places.
818
+ \color red
819
+ map
820
+ \color inherit
821
+ ( &:name ) #=> [:A, :B]
822
+ \end_layout
823
+
824
+ \begin_layout Standard
825
+ Here, Ruby
826
+ \family typewriter
827
+ map
828
+ \family default
829
+ method transforms the
830
+ \emph on
831
+ \color red
832
+ array
833
+ \emph default
834
+ \color inherit
835
+ of places to the array of their names.
836
+ The advantage of internal DSLs is, that one retains full power of the language,
837
+ augmented with human-friendly, domain-specific commands.
838
+ GUI systems generally sandbox the user inside their interface, with no
839
+ way to overcome its limitations.
840
+ But let us go on.
841
+ You can notice that the
842
+ \emph on
843
+ \color green
844
+ marking
845
+ \emph default
846
+ \color inherit
847
+ of
848
+ \family typewriter
849
+ A
850
+ \family default
851
+ ,
852
+ \family typewriter
853
+ B
854
+ \family default
855
+ is one we gave them upon their creation:
856
+ \end_layout
857
+
858
+ \begin_layout LyX-Code
859
+ places.map( &:marking ) #=> [2, 5]
860
+ \end_layout
861
+
862
+ \begin_layout Standard
863
+ In classical Petri nets, marking is understood as the number of
864
+ \emph on
865
+ \color green
866
+ tokens
867
+ \emph default
868
+ \color inherit
869
+ in each place, which is always integer.
870
+ In this case,
871
+ \family typewriter
872
+ A
873
+ \family default
874
+ contains 2 tokens, while
875
+ \family typewriter
876
+ B
877
+ \family default
878
+ contains 5 tokens.
879
+ Tokens can represent anything: molecules, parts in the production line,
880
+ trains in the railway network...
881
+ \end_layout
882
+
883
+ \begin_layout Subsection*
884
+ Transitions
885
+ \end_layout
886
+
887
+ \begin_layout Standard
888
+ The behavior of a Petri net is defined by
889
+ \emph on
890
+ \color green
891
+ transitions
892
+ \emph default
893
+ \color inherit
894
+ .
895
+ Each transition defines a single operation: Adding / subtracting some amount
896
+ of tokens to / from some places.
897
+ Transition operation can often be expressed by
898
+ \emph on
899
+ stoichiometry
900
+ \emph default
901
+ – pairs of places with a corresponding number of tokens to add / subtract
902
+ when the transition
903
+ \emph on
904
+ \color green
905
+ fires
906
+ \emph default
907
+ \color inherit
908
+ .
909
+ For example, let us define:
910
+ \end_layout
911
+
912
+ \begin_layout LyX-Code
913
+ A2B =
914
+ \color blue
915
+ Transition
916
+ \color inherit
917
+ ( stoichiometry: { A: -1, B: 1 } )
918
+ \end_layout
919
+
920
+ \begin_layout LyX-Code
921
+ #=> A2B
922
+ \end_layout
923
+
924
+ \begin_layout Standard
925
+ Stoichiometry of this transition is given by the
926
+ \emph on
927
+ \color red
928
+ hash
929
+ \emph default
930
+ \color inherit
931
+
932
+ \family typewriter
933
+ { A: -1, B: 1 }
934
+ \family default
935
+ .
936
+ This hash is available from
937
+ \family typewriter
938
+ A2B
939
+ \family default
940
+ via '
941
+ \family typewriter
942
+ \color blue
943
+ s
944
+ \family default
945
+ \color inherit
946
+ ' method:
947
+ \end_layout
948
+
949
+ \begin_layout LyX-Code
950
+ A2B.
951
+ \color blue
952
+ s
953
+ \color inherit
954
+ () #=> {:A=>-1, :B=>1}
955
+ \end_layout
956
+
957
+ \begin_layout Standard
958
+
959
+ \emph on
960
+ \color red
961
+ Keys
962
+ \emph default
963
+ \color inherit
964
+ of this hash are place names,
965
+ \emph on
966
+ \color red
967
+ values
968
+ \emph default
969
+ \color inherit
970
+ are
971
+ \emph on
972
+ \color green
973
+ stoichiometry coefficients
974
+ \emph default
975
+ \color inherit
976
+ .
977
+ ('Stoichiometry' is a word known from the domain of chemistry, but '
978
+ \emph on
979
+ stoicheion
980
+ \emph default
981
+ ' means simply 'element' in Greek, so there is no problem with using it
982
+ in the domain of general Petri nets.) To see the stoichiometry coefficients
983
+ of
984
+ \family typewriter
985
+ A2B
986
+ \family default
987
+ as an array, type:
988
+ \end_layout
989
+
990
+ \begin_layout LyX-Code
991
+ A2B.
992
+ \color blue
993
+ stoichiometry
994
+ \color inherit
995
+ () #=> [-1, 1]
996
+ \end_layout
997
+
998
+ \begin_layout Standard
999
+ Simply,
1000
+ \family typewriter
1001
+ A2B
1002
+ \family default
1003
+ subtracts 1 token from
1004
+ \family typewriter
1005
+ A
1006
+ \family default
1007
+ , and adds 1 token to
1008
+ \family typewriter
1009
+ B
1010
+ \family default
1011
+ .
1012
+ This can represent conversion of
1013
+ \family typewriter
1014
+ A
1015
+ \family default
1016
+ to
1017
+ \family typewriter
1018
+ B
1019
+ \family default
1020
+ .
1021
+ In classical Petri nets, the arrows connecting places and transitions are
1022
+ called
1023
+ \emph on
1024
+ \color green
1025
+ arcs
1026
+ \emph default
1027
+ \color inherit
1028
+ .
1029
+ (The term was borrowed from graph theory.) For example, at this moment,
1030
+ our Petri net would contain one arc going from
1031
+ \family typewriter
1032
+ A
1033
+ \family default
1034
+ to
1035
+ \family typewriter
1036
+ A2B
1037
+ \family default
1038
+ , and one arc going from
1039
+ \family typewriter
1040
+ A2B
1041
+ \family default
1042
+ to
1043
+ \family typewriter
1044
+ B
1045
+ \family default
1046
+ .
1047
+ In
1048
+ \family typewriter
1049
+ YNelson
1050
+ \family default
1051
+ domain model, 'arcs' are not first-class citizens.
1052
+ The word is understood simply as a synonym for transitions' connectivity
1053
+ – the list of places connected to each transition:
1054
+ \end_layout
1055
+
1056
+ \begin_layout LyX-Code
1057
+ A2B.
1058
+ \color blue
1059
+ arcs
1060
+ \color inherit
1061
+ () #=> [A, B]
1062
+ \end_layout
1063
+
1064
+ \begin_layout Standard
1065
+ The transition
1066
+ \family typewriter
1067
+ A2B
1068
+ \family default
1069
+ is
1070
+ \emph on
1071
+ \color blue
1072
+ timeless
1073
+ \emph default
1074
+ \color inherit
1075
+ :
1076
+ \end_layout
1077
+
1078
+ \begin_layout LyX-Code
1079
+ A2B.
1080
+ \color blue
1081
+ timeless?
1082
+ \color inherit
1083
+ () #=> true
1084
+ \end_layout
1085
+
1086
+ \begin_layout Standard
1087
+ 'Timeless' means that the transition's firing is not defined in time – it
1088
+ can fire anytime, as long as it is
1089
+ \emph on
1090
+ \color green
1091
+ enabled
1092
+ \emph default
1093
+ \color inherit
1094
+ .
1095
+ Classical Petri nets are timeless.
1096
+ In classical Petri nets, a transition is enabled whenever its
1097
+ \emph on
1098
+ \color blue
1099
+ downstream arcs
1100
+ \emph default
1101
+ \color inherit
1102
+ allow it to happen.
1103
+ Downstream arcs, or
1104
+ \emph on
1105
+ \color blue
1106
+ codomain
1107
+ \emph default
1108
+ \color inherit
1109
+ of a transition (these two are synonyms) are those places, whose marking
1110
+ can be directly affected by the transition's firing.
1111
+ In this case, both
1112
+ \family typewriter
1113
+ A
1114
+ \family default
1115
+ and
1116
+ \family typewriter
1117
+ B
1118
+ \family default
1119
+ is affected:
1120
+ \end_layout
1121
+
1122
+ \begin_layout LyX-Code
1123
+ A2B.
1124
+ \color blue
1125
+ downstream_arcs
1126
+ \color inherit
1127
+ () #=> [A, B]
1128
+ \end_layout
1129
+
1130
+ \begin_layout LyX-Code
1131
+ A2B.
1132
+ \color blue
1133
+ codomain
1134
+ \color inherit
1135
+ () #=> [A, B]
1136
+ \end_layout
1137
+
1138
+ \begin_layout Standard
1139
+ Since
1140
+ \family typewriter
1141
+ A2B
1142
+ \family default
1143
+ subtracts tokens from
1144
+ \family typewriter
1145
+ A
1146
+ \family default
1147
+ , it will be enabled so long, as there are any tokens left in
1148
+ \family typewriter
1149
+ A
1150
+ \family default
1151
+ .
1152
+ \end_layout
1153
+
1154
+ \begin_layout LyX-Code
1155
+ A2B.
1156
+ \color blue
1157
+ enabled?
1158
+ \color inherit
1159
+ () #=> true
1160
+ \end_layout
1161
+
1162
+ \begin_layout Subsection*
1163
+ Token game
1164
+ \end_layout
1165
+
1166
+ \begin_layout Standard
1167
+ After
1168
+ \family typewriter
1169
+ A2B
1170
+ \family default
1171
+ fires, the marking will change:
1172
+ \end_layout
1173
+
1174
+ \begin_layout LyX-Code
1175
+ A2B.
1176
+ \color blue
1177
+ fire!
1178
+ \color inherit
1179
+ () #=> nil
1180
+ \end_layout
1181
+
1182
+ \begin_layout LyX-Code
1183
+ places.map( &:marking ) #=> [1, 6]
1184
+ \end_layout
1185
+
1186
+ \begin_layout LyX-Code
1187
+ A2B.fire!() #=> nil
1188
+ \end_layout
1189
+
1190
+ \begin_layout LyX-Code
1191
+ places.map( &:marking ) #=> [0, 7]
1192
+ \end_layout
1193
+
1194
+ \begin_layout Standard
1195
+ At this point, there are no tokens left in
1196
+ \family typewriter
1197
+ A
1198
+ \family default
1199
+ and
1200
+ \family typewriter
1201
+ A2B
1202
+ \family default
1203
+ becomes
1204
+ \emph on
1205
+ \color green
1206
+ disabled
1207
+ \emph default
1208
+ \color inherit
1209
+ :
1210
+ \end_layout
1211
+
1212
+ \begin_layout LyX-Code
1213
+ A2B.enabled? #=> false
1214
+ \end_layout
1215
+
1216
+ \begin_layout Standard
1217
+ Attempt to fire a disabled transition
1218
+ \emph on
1219
+ \color red
1220
+ raises
1221
+ \emph default
1222
+ \color inherit
1223
+ an
1224
+ \emph on
1225
+ \color red
1226
+ error
1227
+ \emph default
1228
+ \color inherit
1229
+ (in Ruby, errors are friendly objects, who, like damsels in distress, are
1230
+ meant to be rescued with a bonus outcome):
1231
+ \end_layout
1232
+
1233
+ \begin_layout LyX-Code
1234
+ A2B.fire!
1235
+ \end_layout
1236
+
1237
+ \begin_layout LyX-Code
1238
+ #=> YPetri::GuardError: Marking -1:Fixnum of A should not be negative!
1239
+ \end_layout
1240
+
1241
+ \begin_layout Subsection*
1242
+ Functional transitions and non-integer marking
1243
+ \end_layout
1244
+
1245
+ \begin_layout Standard
1246
+ So far, all the examples were compatible with classical Petri nets.
1247
+ But
1248
+ \family typewriter
1249
+ YNelson
1250
+ \family default
1251
+ goes beyond – it represents
1252
+ \emph on
1253
+ functional Petri nets
1254
+ \emph default
1255
+ , similar to
1256
+ \emph on
1257
+ Hybrid Functional Petri Net (HFPN)
1258
+ \emph default
1259
+ proposed by
1260
+ \begin_inset CommandInset citation
1261
+ LatexCommand citet
1262
+ key "Matsuno2011brs"
1263
+
1264
+ \end_inset
1265
+
1266
+ , which I already mentioned in the introductory part of this document.
1267
+
1268
+ \family typewriter
1269
+ YNelson
1270
+ \family default
1271
+ domain model is similar, but not identical to HFPN.
1272
+ On the side of similarities,
1273
+ \family typewriter
1274
+ YNelson
1275
+ \family default
1276
+ allows non-integer marking of places:
1277
+ \end_layout
1278
+
1279
+ \begin_layout LyX-Code
1280
+ C = Place(
1281
+ \color blue
1282
+ marking
1283
+ \color inherit
1284
+ : 7.77 ) #=> C
1285
+ \end_layout
1286
+
1287
+ \begin_layout Standard
1288
+ Here, you can notice that marking of places can be specified already upon
1289
+ initialization using '
1290
+ \family typewriter
1291
+ :marking
1292
+ \family default
1293
+ '
1294
+ \emph on
1295
+ \color red
1296
+ named argument
1297
+ \emph default
1298
+ \color inherit
1299
+ .
1300
+ Let us now define a
1301
+ \emph on
1302
+ \color blue
1303
+ timed
1304
+ \emph default
1305
+ \color inherit
1306
+ transition, representing logarithmic decay of
1307
+ \family typewriter
1308
+ C
1309
+ \family default
1310
+ with a rate constant of 0.05:
1311
+ \end_layout
1312
+
1313
+ \begin_layout LyX-Code
1314
+ C_decay = Transition( stoichiometry: { C: -1 },
1315
+ \color blue
1316
+ rate
1317
+ \color inherit
1318
+ : 0.05 )
1319
+ \end_layout
1320
+
1321
+ \begin_layout LyX-Code
1322
+ #=> C_decay
1323
+ \end_layout
1324
+
1325
+ \begin_layout LyX-Code
1326
+ C_decay.
1327
+ \color blue
1328
+ timed?
1329
+ \color inherit
1330
+ #=> true
1331
+ \end_layout
1332
+
1333
+ \begin_layout Standard
1334
+ Here, in the
1335
+ \family typewriter
1336
+ transition
1337
+ \family default
1338
+ constructor method, apart from '
1339
+ \family typewriter
1340
+ stoichiometry:
1341
+ \family default
1342
+ ' named argument, another named argument, '
1343
+ \family typewriter
1344
+ rate:
1345
+ \family default
1346
+ ', is introduced.
1347
+ Under '
1348
+ \family typewriter
1349
+ rate:
1350
+ \family default
1351
+ ', it is possible to specify the transition's
1352
+ \emph on
1353
+ \color green
1354
+ function
1355
+ \emph default
1356
+ \color inherit
1357
+ , which governs its rate.
1358
+ Specifying a function in Ruby requires special syntax (called Ruby
1359
+ \emph on
1360
+ \color red
1361
+ closures
1362
+ \emph default
1363
+ \color inherit
1364
+ ), based on lambda calculus.
1365
+ Ruby closures are easy to learn.
1366
+ But for the moment, in
1367
+ \family typewriter
1368
+ C_decay
1369
+ \family default
1370
+ transition, we are taking use of the convenience, that allows us to pass
1371
+ a numeric value under '
1372
+ \family typewriter
1373
+ rate:
1374
+ \family default
1375
+ ' named argument, and have
1376
+ \family typewriter
1377
+ YNelson
1378
+ \family default
1379
+ create default mass action equation, using the supplied number as its rate
1380
+ constant.
1381
+ For
1382
+ \family typewriter
1383
+ C_decay
1384
+ \family default
1385
+ stoichiometry,
1386
+ \family typewriter
1387
+ { C: -1 }
1388
+ \family default
1389
+ , default mass action will be logarithmic decay with rate constant 0.05.
1390
+ Naturally, when firing timed transitions, the time interval (
1391
+ \begin_inset Formula $\Delta$
1392
+ \end_inset
1393
+
1394
+ time) must be specified, for which the transition should be active:
1395
+ \end_layout
1396
+
1397
+ \begin_layout LyX-Code
1398
+ C_decay.fire!( 1 ) #=> nil
1399
+ \end_layout
1400
+
1401
+ \begin_layout LyX-Code
1402
+ C.marking #=> 7.3815
1403
+ \end_layout
1404
+
1405
+ \begin_layout LyX-Code
1406
+ C_decay.fire! 1 #=> nil
1407
+ \end_layout
1408
+
1409
+ \begin_layout LyX-Code
1410
+ C.marking #=> 7.012425
1411
+ \end_layout
1412
+
1413
+ \begin_layout LyX-Code
1414
+ C_decay.fire!( 0.1 ) #=> nil
1415
+ \end_layout
1416
+
1417
+ \begin_layout LyX-Code
1418
+ C.marking #=> 6.977362875000001
1419
+ \end_layout
1420
+
1421
+ \begin_layout LyX-Code
1422
+ 100.
1423
+ \color red
1424
+ times
1425
+ \color inherit
1426
+ do C_decay.fire! 1 end #=> 100
1427
+ \end_layout
1428
+
1429
+ \begin_layout LyX-Code
1430
+ C.marking #=> 0.04130968078231133
1431
+ \end_layout
1432
+
1433
+ \begin_layout Standard
1434
+ The penultimate statement was a call of Ruby '
1435
+ \family typewriter
1436
+ times
1437
+ \family default
1438
+ ' method with the integer
1439
+ \family typewriter
1440
+ 100
1441
+ \family default
1442
+ as the receiver, which results in 100 time repetition of the statement
1443
+ inside
1444
+ \family typewriter
1445
+ \color red
1446
+ do ...
1447
+ end
1448
+ \family default
1449
+ \emph on
1450
+ block
1451
+ \emph default
1452
+ \color inherit
1453
+ .
1454
+ Instead of
1455
+ \family typewriter
1456
+ do ...
1457
+ end
1458
+ \family default
1459
+ , it is possible to write a block using curly braces
1460
+ \family typewriter
1461
+ \color red
1462
+ { ...
1463
+ }
1464
+ \family default
1465
+ \color inherit
1466
+ :
1467
+ \end_layout
1468
+
1469
+ \begin_layout LyX-Code
1470
+ 100.times { C_decay.fire! 1 } #=> 100
1471
+ \end_layout
1472
+
1473
+ \begin_layout Standard
1474
+ This will cause another 100 time units of
1475
+ \family typewriter
1476
+ C_decay
1477
+ \family default
1478
+ firing.
1479
+ This brings
1480
+ \family typewriter
1481
+ C
1482
+ \family default
1483
+ marking down to almost zero:
1484
+ \end_layout
1485
+
1486
+ \begin_layout LyX-Code
1487
+ C.marking #=> 0.00024457517215434527
1488
+ \end_layout
1489
+
1490
+ \begin_layout Subsection*
1491
+ Four transition types
1492
+ \end_layout
1493
+
1494
+ \begin_layout Standard
1495
+ Thus far, we have demonstrated transitions with stoichiometry, which were
1496
+ either
1497
+ \emph on
1498
+ timed
1499
+ \emph default
1500
+ or not timed (
1501
+ \emph on
1502
+ timeless
1503
+ \emph default
1504
+ ).
1505
+ Timed transitions are denoted by capital
1506
+ \begin_inset Quotes eld
1507
+ \end_inset
1508
+
1509
+
1510
+ \family typewriter
1511
+ T
1512
+ \family default
1513
+
1514
+ \begin_inset Quotes erd
1515
+ \end_inset
1516
+
1517
+ , timeless transitions by small
1518
+ \begin_inset Quotes eld
1519
+ \end_inset
1520
+
1521
+
1522
+ \family typewriter
1523
+ t
1524
+ \family default
1525
+
1526
+ \begin_inset Quotes erd
1527
+ \end_inset
1528
+
1529
+ .
1530
+ Similarly, stoichiometric transitions are denoted by capital
1531
+ \begin_inset Quotes eld
1532
+ \end_inset
1533
+
1534
+
1535
+ \family typewriter
1536
+ S
1537
+ \family default
1538
+
1539
+ \begin_inset Quotes erd
1540
+ \end_inset
1541
+
1542
+ , while transitions without stoichiometry (
1543
+ \emph on
1544
+ non-stoichiometric
1545
+ \emph default
1546
+ transitions) by small
1547
+ \begin_inset Quotes eld
1548
+ \end_inset
1549
+
1550
+
1551
+ \family typewriter
1552
+ s
1553
+ \family default
1554
+
1555
+ \begin_inset Quotes erd
1556
+ \end_inset
1557
+
1558
+ .
1559
+ Together, this gives 4 basic types of transitions:
1560
+ \family typewriter
1561
+ TS
1562
+ \family default
1563
+ ,
1564
+ \family typewriter
1565
+ tS
1566
+ \family default
1567
+ ,
1568
+ \family typewriter
1569
+ Ts
1570
+ \family default
1571
+ , and
1572
+ \family typewriter
1573
+ ts
1574
+ \family default
1575
+ .
1576
+ \end_layout
1577
+
1578
+ \begin_layout Standard
1579
+ The user can ask the type of a transition by calling the
1580
+ \family typewriter
1581
+ \color blue
1582
+ type
1583
+ \family default
1584
+ \color inherit
1585
+ method:
1586
+ \end_layout
1587
+
1588
+ \begin_layout LyX-Code
1589
+ A2B.type #=> :tS
1590
+ \end_layout
1591
+
1592
+ \begin_layout Standard
1593
+ Or investigate the type with inquirer methods:
1594
+ \end_layout
1595
+
1596
+ \begin_layout LyX-Code
1597
+ A2B.
1598
+ \color blue
1599
+ t?
1600
+ \color inherit
1601
+ #=> true
1602
+ \end_layout
1603
+
1604
+ \begin_layout LyX-Code
1605
+ A2B.
1606
+ \color blue
1607
+ T?
1608
+ \color inherit
1609
+ #=> false
1610
+ \end_layout
1611
+
1612
+ \begin_layout LyX-Code
1613
+ A2B.
1614
+ \color blue
1615
+ s?
1616
+ \color inherit
1617
+ #=> false
1618
+ \end_layout
1619
+
1620
+ \begin_layout LyX-Code
1621
+ A2B.
1622
+ \color blue
1623
+ S?
1624
+ \color inherit
1625
+ #=> true
1626
+ \end_layout
1627
+
1628
+ \begin_layout LyX-Code
1629
+ A2B.
1630
+ \color blue
1631
+ TS?
1632
+ \color inherit
1633
+ #=> false
1634
+ \end_layout
1635
+
1636
+ \begin_layout LyX-Code
1637
+ A2B.
1638
+ \color blue
1639
+ tS?
1640
+ \color inherit
1641
+ #=> true
1642
+ \end_layout
1643
+
1644
+ \begin_layout LyX-Code
1645
+ A2B.
1646
+ \color blue
1647
+ Ts?
1648
+ \color inherit
1649
+ #=> false
1650
+ \end_layout
1651
+
1652
+ \begin_layout LyX-Code
1653
+ A2B.
1654
+ \color blue
1655
+ ts?
1656
+ \color inherit
1657
+ #=> false
1658
+ \end_layout
1659
+
1660
+ \begin_layout Subsection*
1661
+ Assignment transitions
1662
+ \end_layout
1663
+
1664
+ \begin_layout Standard
1665
+ In
1666
+ \family typewriter
1667
+ YNelson
1668
+ \family default
1669
+ , there is one more transition type: an assignment transition, denoted by
1670
+
1671
+ \begin_inset Quotes eld
1672
+ \end_inset
1673
+
1674
+
1675
+ \family typewriter
1676
+ A
1677
+ \family default
1678
+
1679
+ \begin_inset Quotes erd
1680
+ \end_inset
1681
+
1682
+ .
1683
+ Assignment transitions do not add or subtract tokens from their target,
1684
+ but completely replace the codomain marking with their output.
1685
+ (Again, in
1686
+ \family typewriter
1687
+ YNelson
1688
+ \family default
1689
+ transitions,
1690
+ \emph on
1691
+ domain
1692
+ \emph default
1693
+ and
1694
+ \emph on
1695
+ codomain
1696
+ \emph default
1697
+ mean respectively upstream and downstream places.) Transitions other than
1698
+
1699
+ \family typewriter
1700
+ A
1701
+ \family default
1702
+ transitions can be collectively called non-assignment transitions, denoted
1703
+ by small
1704
+ \begin_inset Quotes eld
1705
+ \end_inset
1706
+
1707
+
1708
+ \family typewriter
1709
+ a
1710
+ \family default
1711
+
1712
+ \begin_inset Quotes erd
1713
+ \end_inset
1714
+
1715
+ .
1716
+ Note that assignment action is already achievable with plain
1717
+ \family typewriter
1718
+ ts
1719
+ \family default
1720
+ transitions (by subtracting away the previous codomain marking), so
1721
+ \family typewriter
1722
+ A
1723
+ \family default
1724
+ transitions are not strictly needed – their separate existence is just
1725
+ a syntactic convenience.
1726
+ \end_layout
1727
+
1728
+ \begin_layout Standard
1729
+ One way to construct assignment transitions is by setting
1730
+ \family typewriter
1731
+ :assignment
1732
+ \family default
1733
+ named argument to
1734
+ \emph on
1735
+ true
1736
+ \emph default
1737
+ :
1738
+ \end_layout
1739
+
1740
+ \begin_layout LyX-Code
1741
+ A_to_42 = Transition codomain: A, assignment: lambda { 42 }
1742
+ \end_layout
1743
+
1744
+ \begin_layout LyX-Code
1745
+ #=> A_to_42
1746
+ \end_layout
1747
+
1748
+ \begin_layout Standard
1749
+ Firing this transition results in marking of
1750
+ \family typewriter
1751
+ A
1752
+ \family default
1753
+ being set to 42:
1754
+ \end_layout
1755
+
1756
+ \begin_layout LyX-Code
1757
+ A_to_42.fire! #=> nil
1758
+ \end_layout
1759
+
1760
+ \begin_layout LyX-Code
1761
+ A.marking #=> 42
1762
+ \end_layout
1763
+
1764
+ \begin_layout Standard
1765
+ Assignment transitions are of special type
1766
+ \family typewriter
1767
+ A
1768
+ \family default
1769
+ :
1770
+ \end_layout
1771
+
1772
+ \begin_layout LyX-Code
1773
+ A_to_42.type #=> :A
1774
+ \end_layout
1775
+
1776
+ \begin_layout LyX-Code
1777
+ A_to_42.A? #=> true
1778
+ \end_layout
1779
+
1780
+ \begin_layout LyX-Code
1781
+ A_to_42.a? #=> false
1782
+ \end_layout
1783
+
1784
+ \begin_layout Part*
1785
+ Example II: Convenience
1786
+ \end_layout
1787
+
1788
+ \begin_layout Standard
1789
+ So far, to avoid confusing you, I used fairly conservative syntax.
1790
+
1791
+ \family typewriter
1792
+ YNelson
1793
+ \family default
1794
+ can do better than that.
1795
+ For convenience, many long keywords have short aliases.
1796
+ Frequently used syntactic constructs usually have shorter way of expressing
1797
+ the same.
1798
+ \end_layout
1799
+
1800
+ \begin_layout Standard
1801
+ As you have seen, in
1802
+ \family typewriter
1803
+ YNelson
1804
+ \family default
1805
+ one often uses transition constructors.
1806
+ Thus far, we have seen only one
1807
+ \emph on
1808
+ constructor method
1809
+ \emph default
1810
+ for transitions:
1811
+ \family typewriter
1812
+ Transition()
1813
+ \family default
1814
+ .
1815
+
1816
+ \family typewriter
1817
+ Transition()
1818
+ \family default
1819
+ method accepts several different named arguments (
1820
+ \family typewriter
1821
+ :domain
1822
+ \family default
1823
+ ,
1824
+ \family typewriter
1825
+ :codomain
1826
+ \family default
1827
+ ,
1828
+ \family typewriter
1829
+ :stoichiometry
1830
+ \family default
1831
+
1832
+ \family typewriter
1833
+ :assignment
1834
+ \family default
1835
+ ,
1836
+ \family typewriter
1837
+ :rate
1838
+ \family default
1839
+ ,
1840
+ \family typewriter
1841
+ :action
1842
+ \family default
1843
+ ,
1844
+ \family typewriter
1845
+ :name
1846
+ \family default
1847
+ ...) and depending on their values, returns a
1848
+ \family typewriter
1849
+ YNelson::Transition
1850
+ \family default
1851
+ class object of required type and properties.
1852
+ \end_layout
1853
+
1854
+ \begin_layout Standard
1855
+ Using long keywords in the constructor method makes the
1856
+ \family typewriter
1857
+ YNelson
1858
+ \family default
1859
+ code easy to read.
1860
+ But for the cases where trading readability for brevity is desirable, such
1861
+ as when you are playing with YNelson inside
1862
+ \emph on
1863
+ irb
1864
+ \emph default
1865
+ session, you will appreciate convenience.
1866
+ Actually, we already used syntactic shorthands in the earlier examples.
1867
+ We didn't type :
1868
+ \end_layout
1869
+
1870
+ \begin_layout LyX-Code
1871
+ Transition( name: "A2B",
1872
+ \end_layout
1873
+
1874
+ \begin_layout LyX-Code
1875
+ codomain: [A, B],
1876
+ \end_layout
1877
+
1878
+ \begin_layout LyX-Code
1879
+ stoichiometry: [-1, 1] )
1880
+ \end_layout
1881
+
1882
+ \begin_layout LyX-Code
1883
+ A2B = transition( :A2B )
1884
+ \end_layout
1885
+
1886
+ \begin_layout Standard
1887
+ Instead, we just typed
1888
+ \end_layout
1889
+
1890
+ \begin_layout LyX-Code
1891
+ A2B = Transition( stoichiometry: { A: -1, B: 1 } )
1892
+ \end_layout
1893
+
1894
+ \begin_layout Standard
1895
+ Just so you know, the above shorthand is not easy to program in Ruby.
1896
+ When designing
1897
+ \family typewriter
1898
+ YNelson
1899
+ \family default
1900
+ , I took a lot of pain for your convenience.
1901
+ Even shorter way to express the same would be:
1902
+ \end_layout
1903
+
1904
+ \begin_layout LyX-Code
1905
+ A2B = Transition
1906
+ \color blue
1907
+ s
1908
+ \color inherit
1909
+ : { A: -1, B: 1 }
1910
+ \end_layout
1911
+
1912
+ \begin_layout Standard
1913
+ The above is a very simple timeless transition that just takes one token
1914
+ from
1915
+ \family typewriter
1916
+ A
1917
+ \family default
1918
+ and puts it into
1919
+ \family typewriter
1920
+ B
1921
+ \family default
1922
+ .
1923
+ (Constructor convenience is even more powerful for complex transitions.)
1924
+ Start a new
1925
+ \family typewriter
1926
+ irb
1927
+ \family default
1928
+ session and type:
1929
+ \end_layout
1930
+
1931
+ \begin_layout LyX-Code
1932
+ require 'y_nelson'
1933
+ \end_layout
1934
+
1935
+ \begin_layout LyX-Code
1936
+ include YNelson
1937
+ \end_layout
1938
+
1939
+ \begin_layout LyX-Code
1940
+ A = Place
1941
+ \color blue
1942
+ default_marking
1943
+ \color inherit
1944
+ : 5
1945
+ \end_layout
1946
+
1947
+ \begin_layout Standard
1948
+ Constantly typing
1949
+ \family typewriter
1950
+ default_marking
1951
+ \family default
1952
+ is tiresome.
1953
+ Shorter way to say the same is by using the alias
1954
+ \family typewriter
1955
+ \color blue
1956
+ m!
1957
+ \family default
1958
+ \color inherit
1959
+ of the same:
1960
+ \end_layout
1961
+
1962
+ \begin_layout LyX-Code
1963
+ B = Place m!: 5
1964
+ \end_layout
1965
+
1966
+ \begin_layout LyX-Code
1967
+ C = Place m!: 1
1968
+ \end_layout
1969
+
1970
+ \begin_layout LyX-Code
1971
+ D = Place m!: 1
1972
+ \end_layout
1973
+
1974
+ \begin_layout Standard
1975
+ Let's check the net's marking vector now:
1976
+ \end_layout
1977
+
1978
+ \begin_layout LyX-Code
1979
+ places.map &:marking #=> [5, 5, 1, 1]
1980
+ \end_layout
1981
+
1982
+ \begin_layout Standard
1983
+ If you typed everything correctly, you should see the above result.
1984
+ Shorter way to ask for the same information is:
1985
+ \end_layout
1986
+
1987
+ \begin_layout LyX-Code
1988
+ net.marking #=> "A: 5, B: 5, C: 1, D: 1"
1989
+ \end_layout
1990
+
1991
+ \begin_layout Standard
1992
+ Even shorter way to ask is:
1993
+ \end_layout
1994
+
1995
+ \begin_layout LyX-Code
1996
+ net.
1997
+ \color blue
1998
+ m
1999
+ \color inherit
2000
+ #=> [5, 5, 1, 1]
2001
+ \end_layout
2002
+
2003
+ \begin_layout Standard
2004
+ Now let's define the transition we want:
2005
+ \end_layout
2006
+
2007
+ \begin_layout LyX-Code
2008
+ B2A = Transition( stoichiometry: { B: -1, A: 1 },
2009
+ \end_layout
2010
+
2011
+ \begin_layout LyX-Code
2012
+ domain: [C, D],
2013
+ \end_layout
2014
+
2015
+ \begin_layout LyX-Code
2016
+ rate: lambda { |x, y| ( x * y ) ** 0.5 } )
2017
+ \end_layout
2018
+
2019
+ \begin_layout Standard
2020
+ To prove that it works, let's fire it for 0.1 time units:
2021
+ \end_layout
2022
+
2023
+ \begin_layout LyX-Code
2024
+ B2A.fire! 0.1 #=> nil
2025
+ \end_layout
2026
+
2027
+ \begin_layout LyX-Code
2028
+ net.m #=> [5.1, 4.9, 1, 1]
2029
+ \end_layout
2030
+
2031
+ \begin_layout Standard
2032
+ Can we express its constructor more concisely? The answer is yes.
2033
+
2034
+ \family typewriter
2035
+ B2A
2036
+ \family default
2037
+ is a
2038
+ \family typewriter
2039
+ TS
2040
+ \family default
2041
+ transition (check
2042
+ \family typewriter
2043
+ B2A.type
2044
+ \family default
2045
+ to make sure it is true), and for
2046
+ \family typewriter
2047
+ TS
2048
+ \family default
2049
+ transitions,
2050
+ \family typewriter
2051
+ \color blue
2052
+ TS()
2053
+ \family default
2054
+ \color inherit
2055
+ convenience constructor is available.
2056
+ With
2057
+ \family typewriter
2058
+ TS()
2059
+ \family default
2060
+ constructor, the definition of B2A would be much shorter:
2061
+ \end_layout
2062
+
2063
+ \begin_layout LyX-Code
2064
+ B2A = TS domain: [C, D], A: 1, B: -1 do |x, y| ( x * y ) ** 0.5 end
2065
+ \end_layout
2066
+
2067
+ \begin_layout Standard
2068
+ Note the
2069
+ \family typewriter
2070
+ \color red
2071
+ do ...
2072
+ end
2073
+ \family default
2074
+ \color inherit
2075
+ part in the above line: Using lambda syntax, it defines the rate function
2076
+ of the transition.
2077
+ Another convenience constructor worth mentioning is
2078
+ \family typewriter
2079
+ \color blue
2080
+ AT()
2081
+ \family default
2082
+ \color inherit
2083
+ for assignment transition.
2084
+ Earlier, we defined:
2085
+ \end_layout
2086
+
2087
+ \begin_layout LyX-Code
2088
+ A_to_42 = Transition codomain: A, assignment: lambda { 42 }
2089
+ \end_layout
2090
+
2091
+ \begin_layout Standard
2092
+ Using
2093
+ \family typewriter
2094
+ AT()
2095
+ \family default
2096
+ constructor, we can shorten this to:
2097
+ \end_layout
2098
+
2099
+ \begin_layout LyX-Code
2100
+ A_to_42 = AT A do 42 end
2101
+ \end_layout
2102
+
2103
+ \begin_layout Standard
2104
+ In short, syntactic shorthands can save a lot of typing.
2105
+ If you still miss some syntactic shorthand, feel free to define it on your
2106
+ own.
2107
+ For example, let us define a custom method named
2108
+ \family typewriter
2109
+ Foo
2110
+ \family default
2111
+ that acts as a constructor of places with default marking.
2112
+ \end_layout
2113
+
2114
+ \begin_layout LyX-Code
2115
+
2116
+ \color red
2117
+ def
2118
+ \color inherit
2119
+ Foo( m )
2120
+ \end_layout
2121
+
2122
+ \begin_layout LyX-Code
2123
+ Place( default_marking: m )
2124
+ \end_layout
2125
+
2126
+ \begin_layout LyX-Code
2127
+ end
2128
+ \end_layout
2129
+
2130
+ \begin_layout Standard
2131
+ After this, you can define places with default marking with even less typing:
2132
+ \end_layout
2133
+
2134
+ \begin_layout LyX-Code
2135
+ X = Foo 42
2136
+ \end_layout
2137
+
2138
+ \begin_layout LyX-Code
2139
+ Y = Foo 43
2140
+ \end_layout
2141
+
2142
+ \begin_layout Part*
2143
+ Example III: YNelson::Simulation
2144
+ \end_layout
2145
+
2146
+ \begin_layout Standard
2147
+ So far, we have been defining Petri nets and playing the token game using
2148
+
2149
+ \family typewriter
2150
+ #fire!
2151
+ \family default
2152
+ method, let us now simulate a Petri net inside
2153
+ \family typewriter
2154
+ YNelson
2155
+ \color blue
2156
+ ::Simulation
2157
+ \family default
2158
+ \color inherit
2159
+ .
2160
+ Restart your irb session as described in the
2161
+ \series bold
2162
+ Prerequisites
2163
+ \series default
2164
+ chapter.
2165
+ We will now define 2 places.
2166
+ Since we are going to use
2167
+ \family typewriter
2168
+ TimedSimulation
2169
+ \family default
2170
+ , the marking owned by
2171
+ \family typewriter
2172
+ YNelson::Place
2173
+ \family default
2174
+ instances is irrelevant.
2175
+ We just need to specify the initial state eg.
2176
+ by specifying the default marking of the places:
2177
+ \end_layout
2178
+
2179
+ \begin_layout LyX-Code
2180
+ require 'y_nelson'
2181
+ \end_layout
2182
+
2183
+ \begin_layout LyX-Code
2184
+ include YNelson
2185
+ \end_layout
2186
+
2187
+ \begin_layout LyX-Code
2188
+ A = Place
2189
+ \color blue
2190
+ m!:
2191
+ \color inherit
2192
+ 0.5
2193
+ \end_layout
2194
+
2195
+ \begin_layout LyX-Code
2196
+ B = Place m!: 0.5
2197
+ \end_layout
2198
+
2199
+ \begin_layout Standard
2200
+ Now let us define a transition corresponding to pumping
2201
+ \family typewriter
2202
+ A
2203
+ \family default
2204
+ out of the system at a constant rate 0.005 per time unit.
2205
+ \end_layout
2206
+
2207
+ \begin_layout LyX-Code
2208
+ A_pump = Transition s: { A: -1 }, rate:
2209
+ \color red
2210
+ proc
2211
+ \color inherit
2212
+ { 0.005 }
2213
+ \end_layout
2214
+
2215
+ \begin_layout Standard
2216
+ Here,
2217
+ \family typewriter
2218
+ proc { 0.005 }
2219
+ \family default
2220
+ is a closure, that defines the rate function.
2221
+ Closure
2222
+ \family typewriter
2223
+ proc { 0.005 }
2224
+ \family default
2225
+ ensures fixed rate 0.005 per time unit regardless of the marking of
2226
+ \family typewriter
2227
+ A
2228
+ \family default
2229
+ .
2230
+ You can notice that this closure expects no arguments and always outputs
2231
+ 0.005 as its return value.
2232
+ It is the simplest possible way to write a constant function.
2233
+ For comparison,
2234
+ \end_layout
2235
+
2236
+ \begin_layout LyX-Code
2237
+ B_decay = Transition s: { B: -1 }, rate: 0.05
2238
+ \end_layout
2239
+
2240
+ \begin_layout Standard
2241
+ will behind the scenes automatically create a slightly more complicated
2242
+ mass action closure, which is logarithmic decay of
2243
+ \family typewriter
2244
+ B
2245
+ \family default
2246
+ in this case.
2247
+ (You should remember this from
2248
+ \series bold
2249
+ Example I
2250
+ \series default
2251
+ .) Now we have created a net of 2 places and 2 transitions:
2252
+ \end_layout
2253
+
2254
+ \begin_layout LyX-Code
2255
+ net
2256
+ \end_layout
2257
+
2258
+ \begin_layout LyX-Code
2259
+ #=> #<Net: name: Top, 2 places, 2 transitions>
2260
+ \end_layout
2261
+
2262
+ \begin_layout Standard
2263
+ We can execute this Petri net as a
2264
+ \family typewriter
2265
+ Simulation
2266
+ \family default
2267
+ object simply by typing:
2268
+ \end_layout
2269
+
2270
+ \begin_layout LyX-Code
2271
+
2272
+ \color blue
2273
+ run!
2274
+ \color inherit
2275
+ #=> 60
2276
+ \end_layout
2277
+
2278
+ \begin_layout Standard
2279
+ At this point,
2280
+ \family typewriter
2281
+ run!
2282
+ \family default
2283
+ creates and executes a
2284
+ \family typewriter
2285
+ Simulation
2286
+ \family default
2287
+ instance.
2288
+ The return value is the simulation instance itself (see the inspect string
2289
+ above), which by now has already finished execution and holds the simulation
2290
+ results.
2291
+ This simulation instance is accessible via
2292
+ \family typewriter
2293
+ simulation
2294
+ \family default
2295
+ method.
2296
+ \end_layout
2297
+
2298
+ \begin_layout LyX-Code
2299
+
2300
+ \color blue
2301
+ simulation
2302
+ \end_layout
2303
+
2304
+ \begin_layout LyX-Code
2305
+ #=> #<Simulation: time: 60, pp: 2, tt: 2, oid: 75530290>
2306
+ \end_layout
2307
+
2308
+ \begin_layout Standard
2309
+ The simulation does not affect the net.
2310
+ The simulation instance works with its own
2311
+ \begin_inset Quotes eld
2312
+ \end_inset
2313
+
2314
+ mental image
2315
+ \begin_inset Quotes erd
2316
+ \end_inset
2317
+
2318
+ of the net, therefore the marking owned by
2319
+ \family typewriter
2320
+ YNelson::Place
2321
+ \family default
2322
+ instances does not change:
2323
+ \end_layout
2324
+
2325
+ \begin_layout LyX-Code
2326
+ net.marking #=> "A: 0.5, B: 0.5"
2327
+ \end_layout
2328
+
2329
+ \begin_layout Standard
2330
+ In a general case, it would be necessary to specify the simulation settings
2331
+ (step size, sampling rate, simulation time etc.) before running the simulation.
2332
+ Since we have not specified any, default settings were used:
2333
+ \end_layout
2334
+
2335
+ \begin_layout LyX-Code
2336
+ simulation.
2337
+ \color blue
2338
+ settings
2339
+ \end_layout
2340
+
2341
+ \begin_layout LyX-Code
2342
+ #=> {:method=>:basic, :guarded=>false, :step=>0.1, :sampling=>5, :time=>0..60}
2343
+ \end_layout
2344
+
2345
+ \begin_layout Standard
2346
+ We can see sampling done by the simulation by typing:
2347
+ \end_layout
2348
+
2349
+ \begin_layout LyX-Code
2350
+
2351
+ \color blue
2352
+ print_recording
2353
+ \end_layout
2354
+
2355
+ \begin_layout LyX-Code
2356
+ #=> :A :B
2357
+ \end_layout
2358
+
2359
+ \begin_layout LyX-Code
2360
+ ----------------
2361
+ \end_layout
2362
+
2363
+ \begin_layout LyX-Code
2364
+ 0.5000 0.5000
2365
+ \end_layout
2366
+
2367
+ \begin_layout LyX-Code
2368
+ 0.4750 0.3892
2369
+ \end_layout
2370
+
2371
+ \begin_layout LyX-Code
2372
+ 0.4500 0.3029
2373
+ \end_layout
2374
+
2375
+ \begin_layout LyX-Code
2376
+ 0.4250 0.2357
2377
+ \end_layout
2378
+
2379
+ \begin_layout LyX-Code
2380
+ 0.4000 0.1835
2381
+ \end_layout
2382
+
2383
+ \begin_layout LyX-Code
2384
+ 0.3750 0.1428
2385
+ \end_layout
2386
+
2387
+ \begin_layout LyX-Code
2388
+ 0.3500 0.1111
2389
+ \end_layout
2390
+
2391
+ \begin_layout LyX-Code
2392
+ 0.3250 0.0865
2393
+ \end_layout
2394
+
2395
+ \begin_layout LyX-Code
2396
+ 0.3000 0.0673
2397
+ \end_layout
2398
+
2399
+ \begin_layout LyX-Code
2400
+ 0.2750 0.0524
2401
+ \end_layout
2402
+
2403
+ \begin_layout LyX-Code
2404
+ 0.2500 0.0408
2405
+ \end_layout
2406
+
2407
+ \begin_layout LyX-Code
2408
+ 0.2250 0.0317
2409
+ \end_layout
2410
+
2411
+ \begin_layout LyX-Code
2412
+ 0.2000 0.0247
2413
+ \end_layout
2414
+
2415
+ \begin_layout LyX-Code
2416
+ nil
2417
+ \end_layout
2418
+
2419
+ \begin_layout Standard
2420
+ Indeed,
2421
+ \family typewriter
2422
+ A
2423
+ \family default
2424
+ is decreasing at a constant rate, while
2425
+ \family typewriter
2426
+ B
2427
+ \family default
2428
+ undergoes logarithmic decay.
2429
+ In a graphical desktop, we can plot a graph (requires
2430
+ \emph on
2431
+ gnuplot
2432
+ \emph default
2433
+ gem):
2434
+ \end_layout
2435
+
2436
+ \begin_layout LyX-Code
2437
+
2438
+ \color blue
2439
+ recording.plot
2440
+ \color inherit
2441
+ # plots a graph
2442
+ \end_layout
2443
+
2444
+ \begin_layout Standard
2445
+ Previous command plots the default feature set, which is marking of the
2446
+ places.
2447
+ We can investigate also features of the recording (gradient or delta of
2448
+ places, firing or flux of the transitions...):
2449
+ \end_layout
2450
+
2451
+ \begin_layout LyX-Code
2452
+ recording.
2453
+ \color blue
2454
+ gradient
2455
+ \color inherit
2456
+ .plot
2457
+ \end_layout
2458
+
2459
+ \begin_layout LyX-Code
2460
+ recording.
2461
+ \color blue
2462
+ flux
2463
+ \color inherit
2464
+ .plot
2465
+ \end_layout
2466
+
2467
+ \begin_layout LyX-Code
2468
+ recording.
2469
+ \color blue
2470
+ delta
2471
+ \color inherit
2472
+ (
2473
+ \color blue
2474
+ delta_time
2475
+ \color inherit
2476
+ : 0.1 ).plot
2477
+ \end_layout
2478
+
2479
+ \begin_layout Standard
2480
+ The last feature set – delta – requires
2481
+ \family typewriter
2482
+ delta_time
2483
+ \family default
2484
+ named argument to extrapolate the changes (deltas) of the places in the
2485
+ given delta time.
2486
+ As for
2487
+ \family typewriter
2488
+ \color blue
2489
+ firing
2490
+ \family default
2491
+ \color inherit
2492
+ , a feature of
2493
+ \family typewriter
2494
+ tS
2495
+ \family default
2496
+ transitions, the plot would show nothing here, as there ar no
2497
+ \family typewriter
2498
+ tS
2499
+ \family default
2500
+ transitions here.
2501
+ \end_layout
2502
+
2503
+ \begin_layout Part*
2504
+ Example IV: A real system.
2505
+ \end_layout
2506
+
2507
+ \begin_layout Standard
2508
+ A highly simplified cell-biological pathway.
2509
+ Let's first define some assumptions.
2510
+ Type in the following commands (output not shown):
2511
+ \end_layout
2512
+
2513
+ \begin_layout LyX-Code
2514
+ require 'y_nelson'
2515
+ \end_layout
2516
+
2517
+ \begin_layout LyX-Code
2518
+ include YNelson
2519
+ \end_layout
2520
+
2521
+ \begin_layout LyX-Code
2522
+
2523
+ \end_layout
2524
+
2525
+ \begin_layout LyX-Code
2526
+ Pieces_per_microM = 100_000
2527
+ \end_layout
2528
+
2529
+ \begin_layout LyX-Code
2530
+
2531
+ \color blue
2532
+ set_step
2533
+ \color inherit
2534
+ 10
2535
+ \end_layout
2536
+
2537
+ \begin_layout LyX-Code
2538
+
2539
+ \color blue
2540
+ set_sampling
2541
+ \color inherit
2542
+ 30
2543
+ \end_layout
2544
+
2545
+ \begin_layout LyX-Code
2546
+
2547
+ \color blue
2548
+ set_target_time
2549
+ \color inherit
2550
+ 30 * 60
2551
+ \end_layout
2552
+
2553
+ \begin_layout Standard
2554
+ Let's define places corresponding to chemical species first (note that
2555
+ \family typewriter
2556
+ :
2557
+ \color blue
2558
+ m!
2559
+ \family default
2560
+ \color inherit
2561
+ is a synonym for
2562
+ \family typewriter
2563
+ :default_marking)
2564
+ \end_layout
2565
+
2566
+ \begin_layout LyX-Code
2567
+ AMP = Place
2568
+ \color blue
2569
+ m!
2570
+ \color inherit
2571
+ : 8695.0
2572
+ \end_layout
2573
+
2574
+ \begin_layout LyX-Code
2575
+ ADP = Place m!: 6521.0
2576
+ \end_layout
2577
+
2578
+ \begin_layout LyX-Code
2579
+ ATP = Place m!: 3152.0
2580
+ \end_layout
2581
+
2582
+ \begin_layout LyX-Code
2583
+ DeoxyCytidine = Place m!: 5.0
2584
+ \end_layout
2585
+
2586
+ \begin_layout LyX-Code
2587
+ DeoxyCTP = Place m!: 20.0
2588
+ \end_layout
2589
+
2590
+ \begin_layout LyX-Code
2591
+ DeoxyGMP = Place m!: 20.0
2592
+ \end_layout
2593
+
2594
+ \begin_layout LyX-Code
2595
+ UMP_UDP_pool = Place m!: 2737.0
2596
+ \end_layout
2597
+
2598
+ \begin_layout LyX-Code
2599
+ DeoxyUMP_DeoxyUDP_pool = Place m!: 10.0
2600
+ \end_layout
2601
+
2602
+ \begin_layout LyX-Code
2603
+ DeoxyTMP = Place m!: 50.0
2604
+ \end_layout
2605
+
2606
+ \begin_layout LyX-Code
2607
+ DeoxyTDP_DeoxyTTP_pool = Place m!: 100.0
2608
+ \end_layout
2609
+
2610
+ \begin_layout LyX-Code
2611
+ Thymidine = Place m!: 10.0
2612
+ \end_layout
2613
+
2614
+ \begin_layout Standard
2615
+ All the places above have their marking in micromolars.
2616
+ The enzyme places below will have their marking in molecules per cell:
2617
+ \end_layout
2618
+
2619
+ \begin_layout LyX-Code
2620
+ TK1 = Place m!: 100_000 / Pieces_per_microM
2621
+ \end_layout
2622
+
2623
+ \begin_layout LyX-Code
2624
+ TYMS = Place m!: 100_000 / Pieces_per_microM
2625
+ \end_layout
2626
+
2627
+ \begin_layout LyX-Code
2628
+ RNR = Place m!: 100_000 / Pieces_per_microM
2629
+ \end_layout
2630
+
2631
+ \begin_layout LyX-Code
2632
+ TMPK = Place m!: 100_000 / Pieces_per_microM
2633
+ \end_layout
2634
+
2635
+ \begin_layout Standard
2636
+ Enzyme molecular weights:
2637
+ \end_layout
2638
+
2639
+ \begin_layout LyX-Code
2640
+ TK1_kDa = 24.8
2641
+ \end_layout
2642
+
2643
+ \begin_layout LyX-Code
2644
+ TYMS_kDa = 66.0
2645
+ \end_layout
2646
+
2647
+ \begin_layout LyX-Code
2648
+ RNR_kDa = 140.0
2649
+ \end_layout
2650
+
2651
+ \begin_layout LyX-Code
2652
+ TMPK_kDa = 50.0
2653
+ \end_layout
2654
+
2655
+ \begin_layout Standard
2656
+ Enzyme specific activities (in
2657
+ \emph on
2658
+ micromolar
2659
+ \emph default
2660
+ /
2661
+ \emph on
2662
+ minute
2663
+ \emph default
2664
+ /
2665
+ \emph on
2666
+ mg
2667
+ \emph default
2668
+ ):
2669
+ \end_layout
2670
+
2671
+ \begin_layout LyX-Code
2672
+ TK1_a = 5.40
2673
+ \end_layout
2674
+
2675
+ \begin_layout LyX-Code
2676
+ TYMS_a = 3.80
2677
+ \end_layout
2678
+
2679
+ \begin_layout LyX-Code
2680
+ RNR_a = 1.00
2681
+ \end_layout
2682
+
2683
+ \begin_layout LyX-Code
2684
+ TMPK_a = 0.83
2685
+ \end_layout
2686
+
2687
+ \begin_layout Standard
2688
+ Some species are kept fixed (as simulation-level clamps):
2689
+ \end_layout
2690
+
2691
+ \begin_layout LyX-Code
2692
+
2693
+ \color blue
2694
+ clamp
2695
+ \color inherit
2696
+ AMP: 8695.0, ADP: 6521.0, ATP: 3152.0
2697
+ \end_layout
2698
+
2699
+ \begin_layout LyX-Code
2700
+ clamp DeoxyCytidine: 0.5, DeoxyCTP: 1.0, DeoxyGMP: 1.0
2701
+ \end_layout
2702
+
2703
+ \begin_layout LyX-Code
2704
+ clamp Thymidine: 0.5
2705
+ \end_layout
2706
+
2707
+ \begin_layout LyX-Code
2708
+ clamp UMP_UDP_pool: 2737.0
2709
+ \end_layout
2710
+
2711
+ \begin_layout Standard
2712
+ Before defining transitions, let's define some functions first:
2713
+ \end_layout
2714
+
2715
+ \begin_layout LyX-Code
2716
+ Vmax_per_min_per_enz_molecule =
2717
+ \end_layout
2718
+
2719
+ \begin_layout LyX-Code
2720
+ lambda { |spec_act_microM_per_min_per_mg, kDa|
2721
+ \end_layout
2722
+
2723
+ \begin_layout LyX-Code
2724
+ spec_act_microM_per_min_per_mg * kDa }
2725
+ \end_layout
2726
+
2727
+ \begin_layout LyX-Code
2728
+ Vmax_per_min =
2729
+ \end_layout
2730
+
2731
+ \begin_layout LyX-Code
2732
+ lambda { |spec_act, kDa, enz_molecules_per_cell|
2733
+ \end_layout
2734
+
2735
+ \begin_layout LyX-Code
2736
+ Vmax_per_min_per_enz_molecule.( spec_act, kDa ) *
2737
+ \end_layout
2738
+
2739
+ \begin_layout LyX-Code
2740
+ enz_molecules_per_cell }
2741
+ \end_layout
2742
+
2743
+ \begin_layout LyX-Code
2744
+ Vmax_per_s =
2745
+ \end_layout
2746
+
2747
+ \begin_layout LyX-Code
2748
+ lambda { |spec_act, kDa, enz_mol_per_cell|
2749
+ \end_layout
2750
+
2751
+ \begin_layout LyX-Code
2752
+ Vmax_per_min.( spec_act, kDa, enz_mol_per_cell ) / 60 }
2753
+ \end_layout
2754
+
2755
+ \begin_layout LyX-Code
2756
+ Km_reduced =
2757
+ \end_layout
2758
+
2759
+ \begin_layout LyX-Code
2760
+ lambda { |km, ki_hash={}|
2761
+ \end_layout
2762
+
2763
+ \begin_layout LyX-Code
2764
+ ki_hash.map { |c, ki| c / ki }.reduce( 1, :+ ) * km }
2765
+ \end_layout
2766
+
2767
+ \begin_layout LyX-Code
2768
+ Occupancy =
2769
+ \end_layout
2770
+
2771
+ \begin_layout LyX-Code
2772
+ lambda { |c, km, compet_inh_w_Ki_hash={}|
2773
+ \end_layout
2774
+
2775
+ \begin_layout LyX-Code
2776
+ c / ( c + Km_reduced.( km, compet_inh_w_Ki_hash ) ) }
2777
+ \end_layout
2778
+
2779
+ \begin_layout LyX-Code
2780
+ MM_with_inh_microM_per_second =
2781
+ \end_layout
2782
+
2783
+ \begin_layout LyX-Code
2784
+ lambda { |c, spec_act, kDa, enz_mol_per_cell, km, ki_hash={}|
2785
+ \end_layout
2786
+
2787
+ \begin_layout LyX-Code
2788
+ Vmax_per_s.( spec_act, kDa, enz_mol_per_cell ) *
2789
+ \end_layout
2790
+
2791
+ \begin_layout LyX-Code
2792
+ Occupancy.( c, km, ki_hash ) }
2793
+ \end_layout
2794
+
2795
+ \begin_layout LyX-Code
2796
+ MMi = MM_with_inh_microM_per_second
2797
+ \end_layout
2798
+
2799
+ \begin_layout Standard
2800
+ Michaelis constants:
2801
+ \end_layout
2802
+
2803
+ \begin_layout LyX-Code
2804
+ TK1_Thymidine_Km = 5.0
2805
+ \end_layout
2806
+
2807
+ \begin_layout LyX-Code
2808
+ TYMS_DeoxyUMP_Km = 2.0
2809
+ \end_layout
2810
+
2811
+ \begin_layout LyX-Code
2812
+ RNR_UDP_Km = 1.0
2813
+ \end_layout
2814
+
2815
+ \begin_layout LyX-Code
2816
+ DNA_creation_speed = 3_000_000_000 / ( 12 * 3600 )
2817
+ \end_layout
2818
+
2819
+ \begin_layout LyX-Code
2820
+ TMPK_DeoxyTMP_Km = 12.0
2821
+ \end_layout
2822
+
2823
+ \begin_layout Standard
2824
+ And finally, let us define the transitions:
2825
+ \end_layout
2826
+
2827
+ \begin_layout LyX-Code
2828
+ Transition name: :TK1_Thymidine_DeoxyTMP,
2829
+ \end_layout
2830
+
2831
+ \begin_layout LyX-Code
2832
+
2833
+ \color blue
2834
+ domain:
2835
+ \color inherit
2836
+ [ Thymidine, TK1, DeoxyTDP_DeoxyTTP_pool, DeoxyCTP,
2837
+ \end_layout
2838
+
2839
+ \begin_layout LyX-Code
2840
+ DeoxyCytidine, AMP, ADP, ATP ],
2841
+ \end_layout
2842
+
2843
+ \begin_layout LyX-Code
2844
+ stoichiometry: { Thymidine: -1, DeoxyTMP: 1 },
2845
+ \end_layout
2846
+
2847
+ \begin_layout LyX-Code
2848
+ rate: proc { |c, e, pool1, ci2, ci3, master1, master2, master3|
2849
+ \end_layout
2850
+
2851
+ \begin_layout LyX-Code
2852
+ ci1 = pool1 * master3 / ( master2 + master3 )
2853
+ \end_layout
2854
+
2855
+ \begin_layout LyX-Code
2856
+ MMi.( c, TK1_a, TK1_kDa, e, TK1_Thymidine_Km,
2857
+ \end_layout
2858
+
2859
+ \begin_layout LyX-Code
2860
+ ci1 => 13.5, ci2 => 0.8, ci3 => 40.0 ) }
2861
+ \end_layout
2862
+
2863
+ \begin_layout LyX-Code
2864
+
2865
+ \end_layout
2866
+
2867
+ \begin_layout LyX-Code
2868
+ Transition name: :TYMS_DeoxyUMP_DeoxyTMP,
2869
+ \end_layout
2870
+
2871
+ \begin_layout LyX-Code
2872
+ domain: [ DeoxyUMP_DeoxyUDP_pool, TYMS, AMP, ADP, ATP ],
2873
+ \end_layout
2874
+
2875
+ \begin_layout LyX-Code
2876
+ stoichiometry: { DeoxyUMP_DeoxyUDP_pool: -1, DeoxyTMP: 1 },
2877
+ \end_layout
2878
+
2879
+ \begin_layout LyX-Code
2880
+ rate: proc { |pool, e, mono, di, tri|
2881
+ \end_layout
2882
+
2883
+ \begin_layout LyX-Code
2884
+ c = pool * di / ( mono + di )
2885
+ \end_layout
2886
+
2887
+ \begin_layout LyX-Code
2888
+ MMi.( c, TYMS_a, TYMS_kDa, e, TYMS_DeoxyUMP_Km
2889
+ ) }
2890
+ \end_layout
2891
+
2892
+ \begin_layout LyX-Code
2893
+
2894
+ \end_layout
2895
+
2896
+ \begin_layout LyX-Code
2897
+ Transition name: :RNR_UDP_DeoxyUDP,
2898
+ \end_layout
2899
+
2900
+ \begin_layout LyX-Code
2901
+ domain: [ UMP_UDP_pool, RNR, DeoxyUMP_DeoxyUDP_pool, AMP, ADP,
2902
+ ATP ],
2903
+ \end_layout
2904
+
2905
+ \begin_layout LyX-Code
2906
+ stoichiometry: { UMP_UDP_pool: -1, DeoxyUMP_DeoxyUDP_pool: 1
2907
+ },
2908
+ \end_layout
2909
+
2910
+ \begin_layout LyX-Code
2911
+ rate: proc { |pool, e, mono, di, tri|
2912
+ \end_layout
2913
+
2914
+ \begin_layout LyX-Code
2915
+ c = pool * di / ( mono + di )
2916
+ \end_layout
2917
+
2918
+ \begin_layout LyX-Code
2919
+ MMi.( c, RNR_a, RNR_kDa, e, RNR_UDP_Km ) }
2920
+ \end_layout
2921
+
2922
+ \begin_layout LyX-Code
2923
+
2924
+ \end_layout
2925
+
2926
+ \begin_layout LyX-Code
2927
+ Transition name: :DNA_polymerase_consumption_of_DeoxyTTP,
2928
+ \end_layout
2929
+
2930
+ \begin_layout LyX-Code
2931
+ stoichiometry: { DeoxyTDP_DeoxyTTP_pool: -1 },
2932
+ \end_layout
2933
+
2934
+ \begin_layout LyX-Code
2935
+ rate: proc { DNA_creation_speed / 4 }
2936
+ \end_layout
2937
+
2938
+ \begin_layout LyX-Code
2939
+
2940
+ \end_layout
2941
+
2942
+ \begin_layout LyX-Code
2943
+ Transition name: :TMPK_DeoxyTMP_DeoxyTDP,
2944
+ \end_layout
2945
+
2946
+ \begin_layout LyX-Code
2947
+ domain: [ DeoxyTMP, TMPK, DeoxyTDP_DeoxyTTP_pool, DeoxyGMP, AMP,
2948
+ ADP, ATP ],
2949
+ \end_layout
2950
+
2951
+ \begin_layout LyX-Code
2952
+ stoichiometry: { DeoxyTMP: -1, TMPK: 0, DeoxyTDP_DeoxyTTP_pool:
2953
+ 1 },
2954
+ \end_layout
2955
+
2956
+ \begin_layout LyX-Code
2957
+ rate: proc { |c, e, pool, ci4, mono, di, tri|
2958
+ \end_layout
2959
+
2960
+ \begin_layout LyX-Code
2961
+ ci1 = di
2962
+ \end_layout
2963
+
2964
+ \begin_layout LyX-Code
2965
+ ci2 = pool * di / ( di + tri )
2966
+ \end_layout
2967
+
2968
+ \begin_layout LyX-Code
2969
+ ci3 = pool * tri / ( di + tri )
2970
+ \end_layout
2971
+
2972
+ \begin_layout LyX-Code
2973
+ MMi.( c, TMPK_a, TMPK_kDa, e, TMPK_DeoxyTMP_Km,
2974
+ \end_layout
2975
+
2976
+ \begin_layout LyX-Code
2977
+ ci1 => 250.0, ci2 => 30.0, ci3 => 750, ci4 =>
2978
+ 117 ) }
2979
+ \end_layout
2980
+
2981
+ \begin_layout LyX-Code
2982
+
2983
+ \end_layout
2984
+
2985
+ \begin_layout LyX-Code
2986
+ Transition name: :PhosphataseI,
2987
+ \end_layout
2988
+
2989
+ \begin_layout LyX-Code
2990
+ stoichiometry: { DeoxyTMP: -1, Thymidine: 1 },
2991
+ \end_layout
2992
+
2993
+ \begin_layout LyX-Code
2994
+ rate: 0.04
2995
+ \end_layout
2996
+
2997
+ \begin_layout LyX-Code
2998
+
2999
+ \end_layout
3000
+
3001
+ \begin_layout LyX-Code
3002
+ Transition name: :PhosphataseII,
3003
+ \end_layout
3004
+
3005
+ \begin_layout LyX-Code
3006
+ stoichiometry: { DeoxyTDP_DeoxyTTP_pool: -1, DeoxyTMP: 1 },
3007
+ \end_layout
3008
+
3009
+ \begin_layout LyX-Code
3010
+ rate: 0.01
3011
+ \end_layout
3012
+
3013
+ \begin_layout Standard
3014
+ The created net can be visualized by:
3015
+ \end_layout
3016
+
3017
+ \begin_layout LyX-Code
3018
+ net.visualize
3019
+ \end_layout
3020
+
3021
+ \begin_layout Standard
3022
+ After executing the above command, you should see a file named
3023
+ \family typewriter
3024
+ y_petri_graph.png
3025
+ \family default
3026
+ in your working directory.
3027
+ The simulation should work.
3028
+ \end_layout
3029
+
3030
+ \begin_layout LyX-Code
3031
+ run!
3032
+ \end_layout
3033
+
3034
+ \begin_layout Standard
3035
+ State recording can be plotted by:
3036
+ \end_layout
3037
+
3038
+ \begin_layout LyX-Code
3039
+ recording.plot
3040
+ \end_layout
3041
+
3042
+ \begin_layout Standard
3043
+ Flux of the transitions can be plotted by:
3044
+ \end_layout
3045
+
3046
+ \begin_layout LyX-Code
3047
+ recording.flux.plot
3048
+ \end_layout
3049
+
3050
+ \begin_layout Standard
3051
+ Please note that although this system qualitatively represents part of the
3052
+ deoxynucleotide metabolism network, its behavior is not realistic, because
3053
+ the available kinetic constants are not precise.
3054
+ \end_layout
3055
+
3056
+ \begin_layout Part*
3057
+ Example V: Using SY.
3058
+ \end_layout
3059
+
3060
+ \begin_layout Standard
3061
+ Here, we'll take a look at using
3062
+ \family typewriter
3063
+ YNelson
3064
+ \family default
3065
+ with
3066
+ \family typewriter
3067
+ \color blue
3068
+ SY
3069
+ \family default
3070
+ metrology library
3071
+ \color inherit
3072
+ .
3073
+ If you are experienced with biochemical modeling, then you surely know
3074
+ how big pain the physical units are.
3075
+ Also, in
3076
+ \series bold
3077
+ Example III
3078
+ \series default
3079
+ , you might have noticed how much attention has been spent on units (in
3080
+ the assumptions, variable names, constant names...) You could have noticed
3081
+ messy unit conversion formulas.
3082
+ The aim of
3083
+ \family typewriter
3084
+ SY
3085
+ \family default
3086
+ is to take care of all this, to relieve the modeler from the task of unit
3087
+ conversion, to clean up the model code, and let the modeler concentrate
3088
+ on the real issue.
3089
+ \end_layout
3090
+
3091
+ \begin_layout Subsection*
3092
+
3093
+ \family typewriter
3094
+ SY
3095
+ \family default
3096
+ metrology library
3097
+ \end_layout
3098
+
3099
+ \begin_layout Standard
3100
+
3101
+ \family typewriter
3102
+ SY
3103
+ \family default
3104
+ is publicly available as a Ruby gem '
3105
+ \family typewriter
3106
+ sy
3107
+ \family default
3108
+ '.
3109
+ After installing it (
3110
+ \family typewriter
3111
+ gem install sy
3112
+ \family default
3113
+ ), type:
3114
+ \end_layout
3115
+
3116
+ \begin_layout LyX-Code
3117
+ require 'sy'
3118
+ \end_layout
3119
+
3120
+ \begin_layout Standard
3121
+ Afterwards, your
3122
+ \family typewriter
3123
+ \color red
3124
+ Numeric
3125
+ \family default
3126
+ \color inherit
3127
+ objects (that is, numbers) should respond to methods representing physical
3128
+ units:
3129
+ \end_layout
3130
+
3131
+ \begin_layout LyX-Code
3132
+ 1.m #=> #<±Magnitude: 1.m>
3133
+ \end_layout
3134
+
3135
+ \begin_layout LyX-Code
3136
+ 1.s #=> #<±Magnitude: 1.s>
3137
+ \end_layout
3138
+
3139
+ \begin_layout LyX-Code
3140
+ 1.kg.m.s(-2) #=> #<±Magnitude: 1.N>
3141
+ \end_layout
3142
+
3143
+ \begin_layout LyX-Code
3144
+ 1.cm + 1.mm #=> #<±Magnitude: 0.011.m>
3145
+ \end_layout
3146
+
3147
+ \begin_layout Standard
3148
+ The core of the trick is that instead of naked numbers, numbers become magnitude
3149
+ s (
3150
+ \family typewriter
3151
+ SY::Magnitude
3152
+ \family default
3153
+ ) of specified physical quantities:
3154
+ \end_layout
3155
+
3156
+ \begin_layout LyX-Code
3157
+ 1.m.quantity #=> #<Quantity:Length>
3158
+ \end_layout
3159
+
3160
+ \begin_layout LyX-Code
3161
+ 1.cm.min⁻¹.quantity #=> #<Quantity:Speed>
3162
+ \end_layout
3163
+
3164
+ \begin_layout Standard
3165
+ (You can type
3166
+ \family typewriter
3167
+ 1.cm.min(-1)
3168
+ \family default
3169
+ if you find it difficult to type Unicode superscript characters "
3170
+ \family typewriter
3171
+ ⁻¹
3172
+ \family default
3173
+ ".) Magnitudes can be converted back to numbers with
3174
+ \family typewriter
3175
+ \color blue
3176
+ amount
3177
+ \family default
3178
+ \color inherit
3179
+ (alias
3180
+ \family typewriter
3181
+ \color blue
3182
+ to_f)
3183
+ \family default
3184
+ \color inherit
3185
+ method:
3186
+ \end_layout
3187
+
3188
+ \begin_layout LyX-Code
3189
+ 1.km.amount #=> 1000.0
3190
+ \end_layout
3191
+
3192
+ \begin_layout LyX-Code
3193
+ 1.cm.to_f #=> 0.01
3194
+ \end_layout
3195
+
3196
+ \begin_layout Subsection*
3197
+ Collaboration between
3198
+ \family typewriter
3199
+ SY
3200
+ \family default
3201
+ and
3202
+ \family typewriter
3203
+ YNelson
3204
+ \end_layout
3205
+
3206
+ \begin_layout Standard
3207
+ In a fresh
3208
+ \family typewriter
3209
+ irb
3210
+ \family default
3211
+ session, enter:
3212
+ \end_layout
3213
+
3214
+ \begin_layout LyX-Code
3215
+ require 'sy'
3216
+ \end_layout
3217
+
3218
+ \begin_layout LyX-Code
3219
+ require 'y_nelson'
3220
+ \end_layout
3221
+
3222
+ \begin_layout LyX-Code
3223
+ include YNelson
3224
+ \end_layout
3225
+
3226
+ \begin_layout LyX-Code
3227
+ A = Place m!: 3.mM
3228
+ \end_layout
3229
+
3230
+ \begin_layout LyX-Code
3231
+ B = Place m!: 4.mM
3232
+ \end_layout
3233
+
3234
+ \begin_layout LyX-Code
3235
+ A2B = Transition s: { A: -1, B: 1 }, rate: 0.05.s⁻¹
3236
+ \end_layout
3237
+
3238
+ \begin_layout LyX-Code
3239
+ B_decay = Transition s: { B: -1 }, rate: 0.002.s⁻¹
3240
+ \end_layout
3241
+
3242
+ \begin_layout Standard
3243
+ We hereby specified marking and rate in physical units.
3244
+ Presently,
3245
+ \family typewriter
3246
+ YNelson
3247
+ \family default
3248
+ is not able to simulate such nets, but we can play token game with it:
3249
+ \end_layout
3250
+
3251
+ \begin_layout LyX-Code
3252
+ net.m #=> [#<±Magnitude: 0.003.M>, #<±Magnitude: 0.004.M>]
3253
+ \end_layout
3254
+
3255
+ \begin_layout LyX-Code
3256
+ A2B.fire! 1.s
3257
+ \end_layout
3258
+
3259
+ \begin_layout LyX-Code
3260
+ B_decay.fire! 1.s
3261
+ \end_layout
3262
+
3263
+ \begin_layout LyX-Code
3264
+ net.m #=> [#<±Magnitude: 0.00285.M>, #<±Magnitude: 0.00414.M>]
3265
+ \end_layout
3266
+
3267
+ \begin_layout Standard
3268
+ Let us fire the 2 defined transitions for 100 seconds:
3269
+ \end_layout
3270
+
3271
+ \begin_layout LyX-Code
3272
+ 100.times do
3273
+ \end_layout
3274
+
3275
+ \begin_layout LyX-Code
3276
+ A2B.fire! 1.s
3277
+ \end_layout
3278
+
3279
+ \begin_layout LyX-Code
3280
+ B_decay.fire! 1.s
3281
+ \end_layout
3282
+
3283
+ \begin_layout LyX-Code
3284
+ end
3285
+ \end_layout
3286
+
3287
+ \begin_layout LyX-Code
3288
+ net.m #=> [#<±Magnitude: 1.69e-05.M>, #<±Magnitude: 0.0058.M>]
3289
+ \end_layout
3290
+
3291
+ \begin_layout Standard
3292
+ Finally, let us inspect the resulting marking of
3293
+ \family typewriter
3294
+ A
3295
+ \family default
3296
+ and
3297
+ \family typewriter
3298
+ B
3299
+ \family default
3300
+ expressed in micromolars:
3301
+ \end_layout
3302
+
3303
+ \begin_layout LyX-Code
3304
+ A.marking.
3305
+ \color blue
3306
+ in
3307
+ \color inherit
3308
+ :µM #=> 16.873508277951963
3309
+ \end_layout
3310
+
3311
+ \begin_layout LyX-Code
3312
+ B.marking.in :µM #=> 5797.976678013365
3313
+ \end_layout
3314
+
3315
+ \begin_layout Part*
3316
+ Example VI: Other simulation methods
3317
+ \end_layout
3318
+
3319
+ \begin_layout Standard
3320
+ At this moment, the default simulation method
3321
+ \family typewriter
3322
+ basic
3323
+ \family default
3324
+ method.
3325
+ This method is also called is implicit Euler, because when simulating timed
3326
+ nets, it implies first-order Euler method.
3327
+ For timed nets, YNelson provides two other methods: Runge-Kutta 4th order
3328
+ method and Gillespie stochastic method.
3329
+ Demonstrating Gillespie method:
3330
+ \end_layout
3331
+
3332
+ \begin_layout LyX-Code
3333
+ require 'y_nelson'
3334
+ \end_layout
3335
+
3336
+ \begin_layout LyX-Code
3337
+ include YNelson
3338
+ \end_layout
3339
+
3340
+ \begin_layout LyX-Code
3341
+
3342
+ \end_layout
3343
+
3344
+ \begin_layout LyX-Code
3345
+ A = Place m!: 10
3346
+ \end_layout
3347
+
3348
+ \begin_layout LyX-Code
3349
+ B = Place m!: 10
3350
+ \end_layout
3351
+
3352
+ \begin_layout LyX-Code
3353
+ AB = Place m!: 0
3354
+ \end_layout
3355
+
3356
+ \begin_layout LyX-Code
3357
+ AB_association = TS A: -1, B: -1, AB: 1, rate: 0.1
3358
+ \end_layout
3359
+
3360
+ \begin_layout LyX-Code
3361
+ AB_dissociation = TS AB: -1, A: 1, B: 1, rate: 0.1
3362
+ \end_layout
3363
+
3364
+ \begin_layout LyX-Code
3365
+ A2B = TS A: -1, B: 1, rate: 0.05
3366
+ \end_layout
3367
+
3368
+ \begin_layout LyX-Code
3369
+ B2A = TS A: 1, B: -1, rate: 0.07
3370
+ \end_layout
3371
+
3372
+ \begin_layout LyX-Code
3373
+
3374
+ \end_layout
3375
+
3376
+ \begin_layout LyX-Code
3377
+ set_step 1
3378
+ \end_layout
3379
+
3380
+ \begin_layout LyX-Code
3381
+ set_target_time 50
3382
+ \end_layout
3383
+
3384
+ \begin_layout LyX-Code
3385
+ set_sampling 1
3386
+ \end_layout
3387
+
3388
+ \begin_layout LyX-Code
3389
+ set_simulation_method :gillespie
3390
+ \end_layout
3391
+
3392
+ \begin_layout LyX-Code
3393
+
3394
+ \end_layout
3395
+
3396
+ \begin_layout LyX-Code
3397
+ run!
3398
+ \end_layout
3399
+
3400
+ \begin_layout LyX-Code
3401
+ print_recording
3402
+ \end_layout
3403
+
3404
+ \begin_layout LyX-Code
3405
+ plot_state
3406
+ \end_layout
3407
+
3408
+ \begin_layout Standard
3409
+ The state recording should show a random walk of the system state over the
3410
+ period of 50 time units.
3411
+ \end_layout
3412
+
3413
+ \begin_layout LyX-Code
3414
+
3415
+ \end_layout
3416
+
3417
+ \begin_layout LyX-Code
3418
+ \begin_inset CommandInset bibtex
3419
+ LatexCommand bibtex
3420
+ bibfiles "/home/boris/b/8oav/ptn/ptn"
3421
+ options "plainnat"
3422
+
3423
+ \end_inset
3424
+
3425
+
3426
+ \end_layout
3427
+
3428
+ \end_body
3429
+ \end_document