y_petri 2.1.3 → 2.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/lib/y_petri/agent/petri_net_related.rb +25 -5
  3. data/lib/y_petri/agent/selection.rb +12 -10
  4. data/lib/y_petri/agent/simulation_related.rb +14 -58
  5. data/lib/y_petri/agent.rb +15 -17
  6. data/lib/y_petri/core/timed/euler.rb +13 -15
  7. data/lib/y_petri/core/timed/pseudo_euler.rb +22 -24
  8. data/lib/y_petri/core/timed/quasi_euler.rb +15 -17
  9. data/lib/y_petri/core/timed.rb +42 -44
  10. data/lib/y_petri/core/timeless/pseudo_euler.rb +12 -14
  11. data/lib/y_petri/core/timeless.rb +10 -7
  12. data/lib/y_petri/core.rb +3 -3
  13. data/lib/y_petri/dsl.rb +46 -46
  14. data/lib/y_petri/fixed_assets.rb +8 -0
  15. data/lib/y_petri/net/data_set.rb +238 -0
  16. data/lib/y_petri/net/own_state.rb +63 -0
  17. data/lib/y_petri/net/state/feature/delta.rb +98 -71
  18. data/lib/y_petri/net/state/feature/firing.rb +51 -54
  19. data/lib/y_petri/net/state/feature/flux.rb +51 -55
  20. data/lib/y_petri/net/state/feature/gradient.rb +55 -59
  21. data/lib/y_petri/net/state/feature/marking.rb +55 -59
  22. data/lib/y_petri/net/state/feature.rb +65 -67
  23. data/lib/y_petri/net/state/features/record.rb +150 -43
  24. data/lib/y_petri/net/state/features.rb +252 -96
  25. data/lib/y_petri/net/state.rb +114 -106
  26. data/lib/y_petri/net/visualization.rb +3 -2
  27. data/lib/y_petri/net.rb +29 -24
  28. data/lib/y_petri/place/arcs.rb +3 -3
  29. data/lib/y_petri/place/guard.rb +35 -117
  30. data/lib/y_petri/place/guarded.rb +86 -0
  31. data/lib/y_petri/place.rb +6 -3
  32. data/lib/y_petri/simulation/element_representation.rb +2 -2
  33. data/lib/y_petri/simulation/elements.rb +3 -1
  34. data/lib/y_petri/simulation/feature_set.rb +3 -1
  35. data/lib/y_petri/simulation/marking_vector.rb +3 -1
  36. data/lib/y_petri/simulation/place_mapping.rb +3 -1
  37. data/lib/y_petri/simulation/places.rb +1 -1
  38. data/lib/y_petri/simulation/recorder.rb +60 -54
  39. data/lib/y_petri/simulation/timed/recorder.rb +12 -1
  40. data/lib/y_petri/simulation/timed.rb +173 -172
  41. data/lib/y_petri/simulation/transitions/access.rb +97 -29
  42. data/lib/y_petri/simulation.rb +11 -9
  43. data/lib/y_petri/transition/{assignment.rb → A.rb} +2 -2
  44. data/lib/y_petri/transition/{timed.rb → T.rb} +2 -2
  45. data/lib/y_petri/transition/arcs.rb +3 -3
  46. data/lib/y_petri/transition/cocking.rb +3 -3
  47. data/lib/y_petri/transition/{init.rb → construction_convenience.rb} +6 -53
  48. data/lib/y_petri/transition/{ordinary_timeless.rb → t.rb} +2 -2
  49. data/lib/y_petri/transition/type.rb +103 -0
  50. data/lib/y_petri/transition/type_information.rb +103 -0
  51. data/lib/y_petri/transition/types.rb +107 -0
  52. data/lib/y_petri/transition/usable_without_world.rb +14 -0
  53. data/lib/y_petri/transition.rb +87 -101
  54. data/lib/y_petri/version.rb +1 -1
  55. data/lib/y_petri/world/dependency.rb +30 -28
  56. data/lib/y_petri/world.rb +10 -8
  57. data/test/acceptance/basic_usage_test.rb +3 -3
  58. data/test/acceptance/simulation_test.rb +3 -3
  59. data/test/acceptance/simulation_with_physical_units_test.rb +2 -2
  60. data/test/acceptance/token_game_test.rb +2 -2
  61. data/test/acceptance/visualization_test.rb +3 -3
  62. data/test/acceptance_tests.rb +2 -2
  63. data/test/agent_test.rb +1 -1
  64. data/test/net_test.rb +41 -17
  65. data/test/place_test.rb +1 -1
  66. data/test/simulation_test.rb +39 -39
  67. data/test/transition_test.rb +1 -1
  68. data/test/world_test.rb +1 -1
  69. data/test/y_petri_test.rb +1 -1
  70. metadata +13 -8
  71. data/lib/y_petri/net/state/features/dataset.rb +0 -135
  72. data/lib/y_petri/transition/construction.rb +0 -311
@@ -14,88 +14,132 @@ class YPetri::Simulation::Transitions
14
14
  end
15
15
  alias include_transition? includes_transition?
16
16
 
17
- # Transition of the simulation (belonging to the net).
17
+ # Net's transition.
18
18
  #
19
19
  def t( id )
20
20
  transitions( id ).source
21
21
  end
22
22
 
23
- # Transitions of the simulation (belonging to the net).
23
+ # Net's transitions.
24
24
  #
25
25
  def tt( ids=nil )
26
26
  transitions( ids ).sources
27
27
  end
28
28
 
29
- # Free places of the simulation (belonging to the net).
29
+ # Net's *ts* transitions.
30
30
  #
31
31
  def ts_tt( ids=nil )
32
32
  ts_transitions( ids ).sources
33
33
  end
34
34
 
35
- # Free places of the simulation (belonging to the net).
35
+ # Net's *tS* transitions.
36
36
  #
37
37
  def tS_tt( ids=nil )
38
38
  tS_transitions( ids ).sources
39
39
  end
40
40
 
41
- # Free places of the simulation (belonging to the net).
41
+
42
+ # Net's *Ts* transitions.
42
43
  #
43
44
  def Ts_tt( ids=nil )
44
45
  Ts_transitions( ids ).sources
45
46
  end
46
47
 
47
- # Free places of the simulation (belonging to the net).
48
+ # Net's *TS* transitions.
48
49
  #
49
50
  def TS_tt( ids=nil )
50
51
  TS_transitions( ids ).sources
51
52
  end
52
53
 
53
- # Transitions' names. Arguments, if any, are treated as in +#tranistions+ method.
54
+ # Net's *A* transitions.
55
+ #
56
+ def A_tt( ids=nil )
57
+ A_transitions( ids ).sources
58
+ end
59
+
60
+ # Net's *S* transitions.
61
+ #
62
+ def S_tt( ids=nil )
63
+ S_transitions( ids ).sources
64
+ end
65
+
66
+ # Net's *s* (non-stoichiometric) transitions.
67
+ #
68
+ def s_tt( ids=nil )
69
+ s_transitions( ids ).sources
70
+ end
71
+
72
+ # Net's *T* transitions.
73
+ #
74
+ def T_tt( ids=nil )
75
+ T_transitions( ids ).sources
76
+ end
77
+
78
+ # Net's *t* (timeless) transitions.
79
+ #
80
+ def t_tt ids=nil
81
+ return transitions.t if ids.nil?
82
+ transitions.t.subset( ids )
83
+ end
84
+
85
+ # Names of specified transitions.
54
86
  #
55
87
  def tn ids=nil
56
- transitions( ids ).names
88
+ tt( ids ).names
57
89
  end
58
90
 
59
- # Names of *ts* transitions. Arguments are handled as with +#ts_transitions+.
91
+ # Names of specified *ts* transitions.
60
92
  #
61
93
  def nts ids=nil
62
- ts_transitions( ids ).names( true )
94
+ ts_tt( ids ).names( true )
63
95
  end
64
96
 
65
- # Names of *tS* transitions. Arguments are handled as with +#tS_transitions+.
97
+ # Names of specified *tS* transitions.
66
98
  #
67
99
  def ntS ids=nil
68
- tS_transitions( ids ).names( true )
100
+ tS_tt( ids ).names( true )
69
101
  end
70
102
 
71
- # Names of *Ts* transitions. Arguments are handled as with +#tS_transitions+.
103
+ # Names of specified *Ts* transitions.
72
104
  #
73
105
  def nTs ids=nil
74
- Ts_transitions( ids ).names( true )
106
+ Ts_tt( ids ).names( true )
75
107
  end
76
108
 
77
- # Names of *TS* transitions. Arguments are handled as with +#TS_transitions+.
109
+ # Names of specified *TS* transitions.
78
110
  #
79
111
  def nTS ids=nil
80
- TS_transitions( ids ).names( true )
112
+ TS_tt( ids ).names( true )
81
113
  end
82
114
 
83
- # Names of *A* transitions. Arguments are handled as with +#A_transitions+.
115
+ # Names of specified *A* transitions.
84
116
  #
85
117
  def nA ids=nil
86
- A_transitions( ids ).names( true )
118
+ A_tt( ids ).names( true )
87
119
  end
88
120
 
89
- # Names of *S* transitions. Arguments are handled as with +#S_transitions+.
121
+ # Names of specified *S* transitions.
90
122
  #
91
123
  def nS ids=nil
92
- S_transitions( ids ).names( true )
124
+ S_tt( ids ).names( true )
93
125
  end
94
126
 
95
- # Names of *s* transitions. Arguments are handled as with +#s_transitions+.
127
+ # Names of specified *s* transitions.
96
128
  #
97
129
  def ns ids=nil
98
- s_transitions( ids ).names( true )
130
+ s_tt( ids ).names( true )
131
+ end
132
+
133
+ # Names of specified *T* transitions.
134
+ #
135
+ def nT ids=nil
136
+ T_tt( ids ).names( true )
137
+ end
138
+
139
+ # Names of specified *t* transitions.
140
+ #
141
+ def nt ids=nil
142
+ t_tt( ids ).names( true )
99
143
  end
100
144
 
101
145
  protected
@@ -132,7 +176,7 @@ class YPetri::Simulation::Transitions
132
176
  #
133
177
  def ts_transitions ids=nil
134
178
  return transitions.ts if ids.nil?
135
- transitions.ts.subset( ids )
179
+ transitions.ts.subset( transitions ids )
136
180
  end
137
181
 
138
182
  # Simulation's *tS* transitions. If arguments are given, they must identify
@@ -140,7 +184,7 @@ class YPetri::Simulation::Transitions
140
184
  #
141
185
  def tS_transitions ids=nil
142
186
  return transitions.tS if ids.nil?
143
- transitions.tS.subset( ids )
187
+ transitions.tS.subset( transitions ids )
144
188
  end
145
189
 
146
190
  # Simulation's *Ts* transitions. If arguments are given, they must identify
@@ -148,7 +192,7 @@ class YPetri::Simulation::Transitions
148
192
  #
149
193
  def Ts_transitions ids=nil
150
194
  return transitions.Ts if ids.nil?
151
- transitions.Ts.subset( ids )
195
+ transitions.Ts.subset( transitions ids )
152
196
  end
153
197
 
154
198
  # Simulation's *TS* transitions. If arguments are given, they must identify
@@ -156,7 +200,7 @@ class YPetri::Simulation::Transitions
156
200
  #
157
201
  def TS_transitions ids=nil
158
202
  return transitions.TS if ids.nil?
159
- transitions.TS.subset( ids )
203
+ transitions.TS.subset( transitions ids )
160
204
  end
161
205
 
162
206
  # Simulation's *A* transitions. If arguments are given, they must identify
@@ -164,7 +208,15 @@ class YPetri::Simulation::Transitions
164
208
  #
165
209
  def A_transitions ids=nil
166
210
  return transitions.A if ids.nil?
167
- transitions.A.subset( ids )
211
+ transitions.A.subset( transitions ids )
212
+ end
213
+
214
+ # Simulation's *a* transitions. If argument are given, they must identify
215
+ # *a* transitions, and are treated as in +#transitions+ method.
216
+ #
217
+ def a_transitions ids=nil
218
+ return transitions.a if ids.nil?
219
+ transitions.a.subset( transitions ids )
168
220
  end
169
221
 
170
222
  # Simulation's *S* transitions. If arguments are given, they must identify
@@ -172,7 +224,7 @@ class YPetri::Simulation::Transitions
172
224
  #
173
225
  def S_transitions ids=nil
174
226
  return transitions.S if ids.nil?
175
- transitions.S.subset( ids )
227
+ transitions.S.subset( transitions ids )
176
228
  end
177
229
 
178
230
  # Simulation's *s* transitions. If arguments are given, they must identify
@@ -180,7 +232,23 @@ class YPetri::Simulation::Transitions
180
232
  #
181
233
  def s_transitions ids=nil
182
234
  return transitions.s if ids.nil?
183
- transitions.s.subset( ids )
235
+ transitions.s.subset( transitions ids )
236
+ end
237
+
238
+ # Simulation's *T* transitions. If arguments are given, they must identify
239
+ # *T* transitions, and are treated as in +#transitions+ method.
240
+ #
241
+ def T_transitions ids=nil
242
+ return transitions.T if ids.nil?
243
+ transitions.T.subset( transitions ids )
244
+ end
245
+
246
+ # Simulation's *t* transitions. If arguments are given, they must identify
247
+ # *t* transitions, and are treated as in +#transitions+ method.
248
+ #
249
+ def t_transitions ids=nil
250
+ return transitions.t if ids.nil?
251
+ transitions.t.subset( transitions ids )
184
252
  end
185
253
  end # Access
186
254
  end # class YPetri::Simulation::Transitions
@@ -35,12 +35,12 @@ require_relative 'simulation/timed'
35
35
  # to be specified. Both come as hashes:
36
36
  #
37
37
  class YPetri::Simulation
38
- include Places::Access
39
- include Transitions::Access
40
- include Elements::Access
41
- include InitialMarking::Access
42
- include MarkingClamps::Access
43
- include MarkingVector::Access
38
+ Places::Access # ★ means include
39
+ Transitions::Access
40
+ Elements::Access
41
+ InitialMarking::Access
42
+ MarkingClamps::Access
43
+ MarkingVector::Access
44
44
 
45
45
  DEFAULT_SETTINGS = -> do { method: :pseudo_euler, guarded: false } end
46
46
 
@@ -94,6 +94,7 @@ class YPetri::Simulation
94
94
  method = settings[:method] # the simulation method
95
95
  @guarded = settings[:guarded] # guarding on / off
96
96
  m_clamps = settings[:marking_clamps] || {}
97
+ m = settings[:marking]
97
98
  init_m = settings[:initial_marking] || {}
98
99
  use_default_marking = if settings.has? :use_default_marking then
99
100
  settings[:use_default_marking]
@@ -150,7 +151,7 @@ class YPetri::Simulation
150
151
  # Init the core.
151
152
  @core = Core().new( method: method, guarded: guarded )
152
153
  # Reset.
153
- reset!
154
+ if m then reset! marking: m else reset! end
154
155
  end
155
156
 
156
157
  # Simulation settings.
@@ -194,9 +195,10 @@ class YPetri::Simulation
194
195
 
195
196
  # Resets the simulation
196
197
  #
197
- def reset! **settings
198
+ def reset! **nn
199
+ m = nn[:marking]
198
200
  tap do
199
- m_vector.reset!
201
+ if m then m_vector.reset! m else m_vector.reset! end
200
202
  recorder.reset!
201
203
  recorder.alert
202
204
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Mixin for the transitions with assignment action.
4
4
  #
5
- module YPetri::Transition::Assignment
5
+ module YPetri::Transition::Type_A
6
6
  # Transition's action (before validation).
7
7
  #
8
8
  def action
@@ -36,4 +36,4 @@ module YPetri::Transition::Assignment
36
36
  def enabled?
37
37
  true
38
38
  end
39
- end # class YPetri::Transition::Assignment
39
+ end # class YPetri::Transition::Type_A
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Mixin for timed Petri net transitions.
4
4
  #
5
- module YPetri::Transition::Timed
5
+ module YPetri::Transition::Type_T
6
6
  # Transition's action (before validation). Requires Δt as an argument.
7
7
  #
8
8
  def action Δt
@@ -47,4 +47,4 @@ module YPetri::Transition::Timed
47
47
  rescue YPetri::GuardError; false end
48
48
  end
49
49
  end
50
- end # class YPetri::Transition::Timed
50
+ end # class YPetri::Transition::Type_T
@@ -1,8 +1,8 @@
1
- # -*- coding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  # Connectivity aspect of a transition.
4
4
  #
5
- class YPetri::Transition
5
+ module YPetri::Transition::Arcs
6
6
  # Names of upstream places.
7
7
  #
8
8
  def domain_pp; domain.map { |p| p.name || p.object_id } end
@@ -48,4 +48,4 @@ class YPetri::Transition
48
48
  downstream_places.each &:fire_downstream_recursively
49
49
  return true
50
50
  end
51
- end # class YPetri::Transition
51
+ end # module YPetri::Transition::Arcs
@@ -1,9 +1,9 @@
1
- # -*- coding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  # Cocking mechanics of a transition. A transition has to be cocked, before
4
4
  # it can succesfuly +#fire+. (+#fire!+ method disregards cocking.)
5
5
  #
6
- class YPetri::Transition
6
+ module YPetri::Transition::Cocking
7
7
  # Is the transition cocked?
8
8
  #
9
9
  def cocked?
@@ -29,4 +29,4 @@ class YPetri::Transition
29
29
  @cocked = false
30
30
  end
31
31
  alias :uncock! :uncock
32
- end # class YPetri::Transition
32
+ end # class YPetri::Transition::Cocking
@@ -1,58 +1,11 @@
1
1
  # encoding: utf-8
2
2
 
3
- # Constructor syntax aspect of a transition. Large part of the functionality
4
- # of the Transition class is the convenient constructor syntax.
3
+ # Given the four transition types (TS, Ts, tS, ts), transition construction
4
+ # is not an easy task. Actually, having convenient constructor syntax is an
5
+ # important part of the functionality of the Transition class. Construction
6
+ # related functionality is thus gathered together in this mixin.
5
7
  #
6
- class YPetri::Transition
7
- # Transition class represents many different kinds of Petri net transitions.
8
- # It makes the constructor syntax a bit more polymorphic. The type of the
9
- # transition to construct is mostly inferred from the constructor arguments.
10
- #
11
- # Mandatorily, the constructor will always need a way to determine the domain
12
- # (upstream arcs) and codomain (downstream arcs) of the transition. Also, the
13
- # constructor must have a way to determine the transition's action. This is
14
- # best explained by examples -- let us have 3 places A, B, C, for whe we will
15
- # create different kinds of transitions:
16
- #
17
- #
18
- # ==== TS (timed stoichiometric)
19
- #
20
- # Rate closure and stoichiometry has to be supplied. Rate closure arity should
21
- # correspond to the domain size. Return arity should be 1 (to be multiplied by
22
- # the stoichiometry vector, as in all other stoichiometric transitions).
23
- #
24
- # Transition.new stoichiometry: { A: -1, B: 1 },
25
- # rate: -> a { a * 0.5 }
26
- #
27
- #
28
- # ==== Ts (timed nonstoichiometric)
29
- #
30
- # Rate closure has to be supplied, whose arity should match the domain, and
31
- # output arity codomain.
32
- #
33
- # ==== tS (timeless stoichiometric)
34
- #
35
- # Stoichiometry has to be supplied, action closure is optional. If supplied,
36
- # its return arity should be 1 (to be multiplied by the stoichiometry vector).
37
- #
38
- # ==== ts transitions (timeless nonstoichiometric)
39
- #
40
- # Action closure is expected with return arity equal to the codomain size:
41
- #
42
- # Transition.new upstream_arcs: [A, C], downstream_arcs: [A, B],
43
- # action_closure: proc { |m, x|
44
- # if x > 0 then [-(m / 2), (m / 2)]
45
- # else [1, 0] end
46
- # }
47
- #
48
- def initialize *args, &block
49
- check_in_arguments *args, &block # the big job
50
- extend timed? ? Timed : ( assignment? ? Assignment : OrdinaryTimeless )
51
- inform_upstream_places # that they have been connected
52
- inform_downstream_places # that they have been connected
53
- uncock # transitions initialize uncocked
54
- end
55
-
8
+ module YPetri::Transition::ConstructionConvenience
56
9
  private
57
10
 
58
11
  # Checking in the arguments supplied to #initialize looks like a big job.
@@ -308,4 +261,4 @@ class YPetri::Transition
308
261
  def inform_downstream_places
309
262
  downstream_places.each { |p| p.send :register_upstream_transition, self }
310
263
  end
311
- end # class YPetri::Transition
264
+ end # class YPetri::Transition::ConstructionConvenience
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Mixin for timed non-assignment timeless Petri net transitions.
4
4
  #
5
- module YPetri::Transition::OrdinaryTimeless
5
+ module YPetri::Transition::Type_t
6
6
  # Result of the transition's "function", regardless of the #enabled? status.
7
7
  #
8
8
  def action
@@ -45,4 +45,4 @@ module YPetri::Transition::OrdinaryTimeless
45
45
  rescue YPetri::GuardError; false end
46
46
  end
47
47
  end
48
- end # class YPetri::Transition::OrdinaryTimeless
48
+ end # class YPetri::Transition::Type_t
@@ -0,0 +1,103 @@
1
+ # encoding: utf-8
2
+
3
+ module YPetri::Transition::TypeInformation
4
+ # Is this a timed stoichiometric transition?
5
+ #
6
+ def TS?
7
+ type == :TS
8
+ end
9
+
10
+ # Is this a timed non-stoichiometric transition?
11
+ #
12
+ def Ts?
13
+ type == :Ts
14
+ end
15
+
16
+ # Is this a timeless stoichiometric transition?
17
+ #
18
+ def tS?
19
+ type == :tS
20
+ end
21
+
22
+ # Is this a timeless non-stoichiometric transition?
23
+ #
24
+ def ts?
25
+ type == :ts
26
+ end
27
+
28
+ # Is this a stoichiometric transition?
29
+ #
30
+ def stoichiometric?; @stoichiometric end
31
+ alias S? stoichiometric?
32
+
33
+ # Is this a non-stoichiometric transition?
34
+ #
35
+ def nonstoichiometric?
36
+ ! stoichiometric?
37
+ end
38
+ alias s? nonstoichiometric?
39
+
40
+ # Does the transition's action depend on delta time?
41
+ #
42
+ def timed?
43
+ @timed
44
+ end
45
+ alias T? timed?
46
+
47
+ # Is the transition timeless? (Opposite of #timed?)
48
+ #
49
+ def timeless?
50
+ not timed?
51
+ end
52
+ alias t? timeless?
53
+
54
+ # Is the transition functional?
55
+ #
56
+ # Explanation: If rate or action closure is supplied, a transition is always
57
+ # considered 'functional'. Otherwise, it is considered not 'functional'.
58
+ # Note that even transitions that are not functional still have standard
59
+ # action acc. to Petri's definition. Also note that a timed transition is
60
+ # necessarily functional.
61
+ #
62
+ def functional?
63
+ @functional
64
+ end
65
+
66
+ # Opposite of #functional?
67
+ #
68
+ def functionless?
69
+ not functional?
70
+ end
71
+
72
+ # Reports the transition's membership in one of the 4 basic types:
73
+ #
74
+ # 1. TS .... timed stoichiometric
75
+ # 2. tS .... timeless stoichiometric
76
+ # 3. Ts .... timed nonstoichiometric
77
+ # 4. ts .... timeless nonstoichiometric
78
+ #
79
+ # plus the fifth type
80
+ #
81
+ # 5. A .... assignment transitions
82
+ #
83
+ def type
84
+ return :A if assignment_action?
85
+ timed? ? ( stoichiometric? ? :TS : :Ts ) : ( stoichiometric? ? :tS : :ts )
86
+ end
87
+
88
+ # Is this a transition with assignment action? (Transitions with assignment
89
+ # action, or "assignment transitions", completely replace the marking of their
90
+ # codomain with their action closure result, like in spreadsheets.)
91
+ #
92
+ def assignment_action?
93
+ @assignment_action
94
+ end
95
+ alias assignment? assignment_action?
96
+ alias A? assignment_action?
97
+
98
+ # Is this a non-assignment transition? (Opposite of +#A?+)
99
+ #
100
+ def a?
101
+ ! assignment_action?
102
+ end
103
+ end # class YPetri::Transition::Type
@@ -0,0 +1,103 @@
1
+ # encoding: utf-8
2
+
3
+ module YPetri::Transition::Types
4
+ # Is this a timed stoichiometric transition?
5
+ #
6
+ def TS?
7
+ type == :TS
8
+ end
9
+
10
+ # Is this a timed non-stoichiometric transition?
11
+ #
12
+ def Ts?
13
+ type == :Ts
14
+ end
15
+
16
+ # Is this a timeless stoichiometric transition?
17
+ #
18
+ def tS?
19
+ type == :tS
20
+ end
21
+
22
+ # Is this a timeless non-stoichiometric transition?
23
+ #
24
+ def ts?
25
+ type == :ts
26
+ end
27
+
28
+ # Is this a stoichiometric transition?
29
+ #
30
+ def stoichiometric?; @stoichiometric end
31
+ alias S? stoichiometric?
32
+
33
+ # Is this a non-stoichiometric transition?
34
+ #
35
+ def nonstoichiometric?
36
+ ! stoichiometric?
37
+ end
38
+ alias s? nonstoichiometric?
39
+
40
+ # Does the transition's action depend on delta time?
41
+ #
42
+ def timed?
43
+ @timed
44
+ end
45
+ alias T? timed?
46
+
47
+ # Is the transition timeless? (Opposite of #timed?)
48
+ #
49
+ def timeless?
50
+ not timed?
51
+ end
52
+ alias t? timeless?
53
+
54
+ # Is the transition functional?
55
+ #
56
+ # Explanation: If rate or action closure is supplied, a transition is always
57
+ # considered 'functional'. Otherwise, it is considered not 'functional'.
58
+ # Note that even transitions that are not functional still have standard
59
+ # action acc. to Petri's definition. Also note that a timed transition is
60
+ # necessarily functional.
61
+ #
62
+ def functional?
63
+ @functional
64
+ end
65
+
66
+ # Opposite of #functional?
67
+ #
68
+ def functionless?
69
+ not functional?
70
+ end
71
+
72
+ # Reports the transition's membership in one of the 4 basic types:
73
+ #
74
+ # 1. TS .... timed stoichiometric
75
+ # 2. tS .... timeless stoichiometric
76
+ # 3. Ts .... timed nonstoichiometric
77
+ # 4. ts .... timeless nonstoichiometric
78
+ #
79
+ # plus the fifth type
80
+ #
81
+ # 5. A .... assignment transitions
82
+ #
83
+ def type
84
+ return :A if assignment_action?
85
+ timed? ? ( stoichiometric? ? :TS : :Ts ) : ( stoichiometric? ? :tS : :ts )
86
+ end
87
+
88
+ # Is this a transition with assignment action? (Transitions with assignment
89
+ # action, or "assignment transitions", completely replace the marking of their
90
+ # codomain with their action closure result, like in spreadsheets.)
91
+ #
92
+ def assignment_action?
93
+ @assignment_action
94
+ end
95
+ alias assignment? assignment_action?
96
+ alias A? assignment_action?
97
+
98
+ # Is this a non-assignment transition? (Opposite of +#A?+)
99
+ #
100
+ def a?
101
+ ! assignment_action?
102
+ end
103
+ end # class YPetri::Transition::Type