y_petri 2.2.4 → 2.3.2

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.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +675 -0
  3. data/README.md +6 -3
  4. data/Rakefile +1 -1
  5. data/lib/y_petri/agent/{petri_net_related.rb → petri_net_aspect.rb} +34 -10
  6. data/lib/y_petri/agent/{simulation_related.rb → simulation_aspect.rb} +49 -34
  7. data/lib/y_petri/agent.rb +5 -5
  8. data/lib/y_petri/core/guarded.rb +24 -0
  9. data/lib/y_petri/core/timed/euler.rb +4 -8
  10. data/lib/y_petri/core/timed/gillespie.rb +11 -17
  11. data/lib/y_petri/core/timed/methods.rb +23 -0
  12. data/lib/y_petri/core/timed/pseudo_euler.rb +10 -13
  13. data/lib/y_petri/core/timed/quasi_euler.rb +9 -8
  14. data/lib/y_petri/core/timed/runge_kutta.rb +10 -18
  15. data/lib/y_petri/core/timed.rb +6 -14
  16. data/lib/y_petri/core/timeless/methods.rb +15 -0
  17. data/lib/y_petri/core/timeless/pseudo_euler.rb +4 -8
  18. data/lib/y_petri/core/timeless.rb +9 -4
  19. data/lib/y_petri/core.rb +44 -42
  20. data/lib/y_petri/net/data_set.rb +246 -142
  21. data/lib/y_petri/net/node_access.rb +282 -0
  22. data/lib/y_petri/net/own_state.rb +14 -4
  23. data/lib/y_petri/net/state/feature/assignment.rb +123 -0
  24. data/lib/y_petri/net/state/feature/delta.rb +55 -35
  25. data/lib/y_petri/net/state/feature/firing.rb +68 -25
  26. data/lib/y_petri/net/state/feature/flux.rb +9 -2
  27. data/lib/y_petri/net/state/feature/gradient.rb +36 -19
  28. data/lib/y_petri/net/state/feature/marking.rb +10 -5
  29. data/lib/y_petri/net/state/feature.rb +105 -11
  30. data/lib/y_petri/net/state/features/record.rb +144 -99
  31. data/lib/y_petri/net/state/features.rb +327 -200
  32. data/lib/y_petri/net/state.rb +48 -82
  33. data/lib/y_petri/net/visualization.rb +1 -1
  34. data/lib/y_petri/net.rb +62 -47
  35. data/lib/y_petri/place/arcs.rb +44 -0
  36. data/lib/y_petri/place/features.rb +115 -0
  37. data/lib/y_petri/place.rb +62 -29
  38. data/lib/y_petri/simulation/dependency.rb +31 -67
  39. data/lib/y_petri/simulation/feature_set.rb +1 -1
  40. data/lib/y_petri/simulation/initial_marking/access.rb +42 -26
  41. data/lib/y_petri/simulation/marking_clamps/access.rb +22 -17
  42. data/lib/y_petri/simulation/marking_clamps.rb +0 -2
  43. data/lib/y_petri/simulation/marking_vector/access.rb +102 -40
  44. data/lib/y_petri/simulation/marking_vector.rb +35 -37
  45. data/lib/y_petri/simulation/matrix.rb +1 -1
  46. data/lib/y_petri/simulation/node_representation.rb +25 -0
  47. data/lib/y_petri/simulation/nodes/access.rb +78 -0
  48. data/lib/y_petri/simulation/{elements.rb → nodes.rb} +14 -13
  49. data/lib/y_petri/simulation/place_mapping.rb +2 -2
  50. data/lib/y_petri/simulation/place_representation.rb +8 -7
  51. data/lib/y_petri/simulation/places/access.rb +89 -70
  52. data/lib/y_petri/simulation/places/free.rb +1 -1
  53. data/lib/y_petri/simulation/places/types.rb +20 -22
  54. data/lib/y_petri/simulation/places.rb +23 -18
  55. data/lib/y_petri/simulation/recorder.rb +23 -18
  56. data/lib/y_petri/simulation/timed/recorder.rb +19 -11
  57. data/lib/y_petri/simulation/timed.rb +93 -29
  58. data/lib/y_petri/simulation/timeless/recorder.rb +11 -6
  59. data/lib/y_petri/simulation/timeless.rb +13 -3
  60. data/lib/y_petri/simulation/transition_representation/A.rb +24 -4
  61. data/lib/y_petri/simulation/transition_representation/S.rb +11 -1
  62. data/lib/y_petri/simulation/transition_representation/T.rb +1 -1
  63. data/lib/y_petri/simulation/transition_representation/Ts.rb +1 -1
  64. data/lib/y_petri/simulation/transition_representation/a.rb +1 -1
  65. data/lib/y_petri/simulation/transition_representation/s.rb +12 -1
  66. data/lib/y_petri/simulation/transition_representation/t.rb +1 -1
  67. data/lib/y_petri/simulation/transition_representation/tS.rb +1 -1
  68. data/lib/y_petri/simulation/transition_representation/ts.rb +1 -1
  69. data/lib/y_petri/simulation/transition_representation/types.rb +1 -1
  70. data/lib/y_petri/simulation/transition_representation.rb +4 -11
  71. data/lib/y_petri/simulation/transitions/A.rb +17 -2
  72. data/lib/y_petri/simulation/transitions/S.rb +1 -1
  73. data/lib/y_petri/simulation/transitions/T.rb +1 -1
  74. data/lib/y_petri/simulation/transitions/Ts.rb +6 -5
  75. data/lib/y_petri/simulation/transitions/a.rb +1 -1
  76. data/lib/y_petri/simulation/transitions/access.rb +195 -168
  77. data/lib/y_petri/simulation/transitions/s.rb +1 -1
  78. data/lib/y_petri/simulation/transitions/t.rb +1 -1
  79. data/lib/y_petri/simulation/transitions/tS.rb +1 -1
  80. data/lib/y_petri/simulation/transitions/ts.rb +1 -1
  81. data/lib/y_petri/simulation/transitions/types.rb +1 -1
  82. data/lib/y_petri/simulation/transitions.rb +5 -7
  83. data/lib/y_petri/simulation.rb +84 -90
  84. data/lib/y_petri/transition/A.rb +8 -2
  85. data/lib/y_petri/transition/T.rb +25 -2
  86. data/lib/y_petri/transition/arcs.rb +19 -3
  87. data/lib/y_petri/transition/construction_convenience.rb +11 -10
  88. data/lib/y_petri/transition/t.rb +14 -1
  89. data/lib/y_petri/transition/types.rb +6 -1
  90. data/lib/y_petri/transition.rb +9 -12
  91. data/lib/y_petri/version.rb +1 -1
  92. data/lib/y_petri/world/dependency.rb +3 -3
  93. data/lib/y_petri/world/{petri_net_related.rb → petri_net_aspect.rb} +4 -4
  94. data/lib/y_petri/world/simulation_aspect.rb +352 -0
  95. data/lib/y_petri/world.rb +4 -4
  96. data/lib/y_petri.rb +1 -1
  97. data/test/agent_test.rb +2 -1
  98. data/test/examples/demonstrator.rb +4 -1
  99. data/test/examples/demonstrator_2.rb +5 -0
  100. data/test/examples/demonstrator_4.rb +6 -5
  101. data/test/examples/example_2.rb +2 -0
  102. data/test/examples/manual_examples.rb +4 -4
  103. data/test/net_test.rb +457 -54
  104. data/test/place_test.rb +11 -7
  105. data/test/simulation_test.rb +358 -331
  106. data/test/transition_test.rb +11 -10
  107. data/test/world_test.rb +2 -0
  108. data/test/y_petri_test.rb +2 -1
  109. data/y_petri.gemspec +24 -18
  110. metadata +71 -17
  111. data/LICENSE +0 -22
  112. data/lib/y_petri/net/element_access.rb +0 -239
  113. data/lib/y_petri/simulation/element_representation.rb +0 -20
  114. data/lib/y_petri/simulation/elements/access.rb +0 -57
  115. data/lib/y_petri/transition/type.rb +0 -103
  116. data/lib/y_petri/transition/type_information.rb +0 -103
  117. data/lib/y_petri/world/simulation_related.rb +0 -176
data/lib/y_petri/place.rb CHANGED
@@ -3,14 +3,16 @@
3
3
  require_relative 'place/guard'
4
4
  require_relative 'place/guarded'
5
5
  require_relative 'place/arcs'
6
+ require_relative 'place/features'
6
7
 
7
8
  # Represents a Petri net place.
8
9
  #
9
10
  class YPetri::Place
10
11
  ★ NameMagic # ★ means include
12
+ ★ YPetri::World::Dependency
11
13
  ★ Arcs
12
14
  ★ Guarded
13
- YPetri::World::Dependency
15
+ Features
14
16
 
15
17
  class << self
16
18
  ★ YPetri::World::Dependency
@@ -21,7 +23,19 @@ class YPetri::Place
21
23
 
22
24
  attr_reader :quantum
23
25
  attr_reader :guards
24
- attr_accessor :default_marking
26
+ attr_reader :has_default_marking
27
+ alias has_default_marking? has_default_marking
28
+
29
+ def default_marking
30
+ fail TypeError, "No default marking was specified for #{self}!" unless
31
+ has_default_marking?
32
+ @default_marking
33
+ end
34
+
35
+ def default_marking= marking
36
+ @has_default_marking = true
37
+ @default_marking = marking
38
+ end
25
39
 
26
40
  # Arguments supplied upon place initialization may include:
27
41
  #
@@ -48,14 +62,19 @@ class YPetri::Place
48
62
  # that the place has no guards whatsoever, +:guard+ argumend should be set to
49
63
  # _false_.
50
64
  #
51
- def initialize quantum: 1,
52
- default_marking: nil,
53
- marking: nil,
54
- guard: L!,
55
- &block
65
+ def initialize guard: L!, **named_args, &block
56
66
  @upstream_arcs, @downstream_arcs, @guards = [], [], [] # init to empty
57
- @quantum, @default_marking = quantum, default_marking
58
- self.marking = marking || default_marking
67
+ @quantum = named_args.has?( :quantum ) ? named_args[:quantum] : 1
68
+ named_args.may_have :default_marking, syn!: :m!
69
+ if named_args.has? :default_marking then
70
+ @has_default_marking = true
71
+ @default_marking = named_args[:default_marking]
72
+ else
73
+ @has_default_marking = false
74
+ end
75
+ if named_args.has? :marking then @marking = named_args[:marking] else
76
+ @marking = default_marking if has_default_marking?
77
+ end
59
78
  # Check in :guard value and the corresponding &block.
60
79
  if guard.ℓ? then # guard NL assertion not given, use block or default guards
61
80
  block ? guard( &block ) : add_default_guards!( @marking )
@@ -67,13 +86,6 @@ class YPetri::Place
67
86
  end
68
87
  end
69
88
 
70
- # Getter of the place's +@marking+ attribute.
71
- #
72
- def m
73
- @marking
74
- end
75
- alias value m
76
-
77
89
  # Used without arguments, it is a getter of the place's +@marking+ attribute,
78
90
  # just like the +Place#m+ method. However, if a string and a block is supplied
79
91
  # to it, it acts as an alias of the +Place#guard+ method. This is because this:
@@ -92,6 +104,19 @@ class YPetri::Place
92
104
  guard args[0], &block
93
105
  end
94
106
 
107
+ # Near-alias for #marking.
108
+ #
109
+ def value
110
+ marking
111
+ end
112
+
113
+ # Getter of the place's marking attribute under a simulation (current
114
+ # simulation by default).
115
+ #
116
+ def m simulation=world.simulation
117
+ simulation.net.State.Feature.Marking( self ) % simulation
118
+ end
119
+
95
120
  # Marking setter.
96
121
  #
97
122
  def marking=( new_marking )
@@ -129,28 +154,36 @@ class YPetri::Place
129
154
  @marking = guard.( @default_marking )
130
155
  end
131
156
 
132
- # Builds an inspect string of the place.
157
+ # Convenience visualizer of the upstream net.
133
158
  #
134
- def inspect
135
- n, m, d, q = instance_description_strings
136
- "#<Place: #{ ( [n, m, d, q].compact ).join ', ' }>"
159
+ def uv
160
+ upstream_net.visualize
137
161
  end
138
162
 
139
- # Returns a string representing the place.
140
- #
141
- def to_s
142
- n, m = name, marking
143
- "#{n.nil? ? 'Place' : n}[#{m.nil? ? 'nil' : m}]"
144
- end
163
+ # Let's try leave these to NameMagic
164
+
165
+ # # Builds an inspect string of the place.
166
+ # #
167
+ # def inspect
168
+ # n, m, d, q = instance_description_strings
169
+ # "#<Place: #{ ( [n, m, d, q].compact ).join ', ' }>"
170
+ # end
171
+
172
+ # # Returns a string representing the place.
173
+ # #
174
+ # def to_s
175
+ # n, m = name, marking
176
+ # "#{n.nil? ? 'Place' : n}[#{m.nil? ? 'nil' : m}]"
177
+ # end
145
178
 
146
179
  private
147
180
 
148
181
  def instance_description_strings
149
- m, n, d, q = marking, name, default_marking, quantum
150
- nς = "name: #{n.nil? ? '∅' : n}"
182
+ m, n, q = marking, name, quantum
151
183
  mς = "marking: #{m.nil? ? 'nil' : m}"
152
- dς = "default_marking: #{d.nil? ? '∅' : d}"
184
+ nς = "name: #{n.nil? ? '∅' : n}"
153
185
  qς = q == 1 ? nil : "quantum: #{q.nil? ? '∅' : q}"
186
+ dς = "default_marking: #{has_default_marking ? default_marking : '∅'}"
154
187
  return nς, mς, dς, qς
155
188
  end
156
189
  end # class YPetri::Place
@@ -1,8 +1,8 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  # Place / transition collection mixin for parametrized classes of
4
- # YPetri::Simulation. Expects the module where it is included to define
5
- # +#simulation+ method returning the current simulation instance.
4
+ # YPetri::Simulation. Expects the includer to provide +#simulation+
5
+ # method returning current +Simulation+ instance.
6
6
  #
7
7
  class YPetri::Simulation
8
8
  module Dependency
@@ -36,72 +36,36 @@ class YPetri::Simulation
36
36
  end
37
37
  end
38
38
 
39
- def element *args, &block
40
- simulation.send :element, *args, &block
41
- end
42
-
43
- def place *args, &block
44
- simulation.send :place, *args, &block
45
- end
46
-
47
- def transition *args, &block
48
- simulation.send :transition, *args, &block
49
- end
50
-
51
- def elements *args, &block
52
- simulation.send :elements, *args, &block
53
- end
54
-
55
- def places *args, &block
56
- simulation.send :places, *args, &block
57
- end
58
-
59
- def transitions *args, &block
60
- simulation.send :transitions, *args, &block
61
- end
62
-
63
- def free_places *args, &block
64
- simulation.send :free_places, *args, &block
65
- end
66
-
67
- def clamped_places *args, &block
68
- simulation.send :clamped_places, *args, &block
69
- end
70
-
71
- def ts_transitions *args, &block
72
- simulation.send :ts_transitions, *args, &block
73
- end
74
-
75
- def tS_transitions *args, &block
76
- simulation.send :tS_transitions, *args, &block
77
- end
78
-
79
- def Ts_transitions *args, &block
80
- simulation.send :Ts_transitions, *args, &block
81
- end
82
-
83
- def TS_transitions *args, &block
84
- simulation.send :TS_transitions, *args, &block
85
- end
86
-
87
- def t_transitions *args, &block
88
- simulation.send :t_transitions, *args, &block
89
- end
90
-
91
- def T_transitions *args, &block
92
- simulation.send :T_transitions, *args, &block
93
- end
94
-
95
- def s_transitions *args, &block
96
- simulation.send :s_transitions, *args, &block
97
- end
39
+ # Necessary to overcoming the protected character of the listed methods.
40
+ #
41
+ [ :node,
42
+ :place,
43
+ :transition
44
+ ].each { |sym| define_method sym do |e| simulation.send sym, e end }
98
45
 
99
- def S_transitions *args, &block
100
- simulation.send :S_transitions, *args, &block
101
- end
46
+ # Necessary to overcoming the protected character of the listed methods.
47
+ #
48
+ [ :Nodes,
49
+ :Places,
50
+ :Transitions
51
+ ].each { |sym| define_method sym do |array| simulation.send sym, array end }
102
52
 
103
- def A_transitions *args, &block
104
- simulation.send :A_transitions, *args, &block
105
- end
53
+ # Necessary to overcoming the protected character of the listed methods.
54
+ #
55
+ [ :nodes,
56
+ :places,
57
+ :free_places,
58
+ :clamped_places,
59
+ :transitions,
60
+ :ts_transitions,
61
+ :tS_transitions,
62
+ :Ts_transitions,
63
+ :TS_transitions,
64
+ :t_transitions,
65
+ :T_transitions,
66
+ :s_transitions,
67
+ :S_transitions,
68
+ :A_transitions
69
+ ].each { |sym| define_method sym do |*e| simulation.send sym, *e end }
106
70
  end # class Dependency
107
71
  end # class YPetri::Simulation
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- # Basic elements of a simulation, a mixin intended for YPetri::Simulation.
3
+ # Basic nodes of a simulation, a mixin intended for YPetri::Simulation.
4
4
  #
5
5
  class YPetri::Simulation
6
6
  # Represents a set of features of a simulation state.
@@ -1,34 +1,51 @@
1
- #encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
3
  # Simulation mixin providing access to the initial marking.
4
4
  #
5
5
  class YPetri::Simulation::InitialMarking
6
6
  module Access
7
- # Without arguments, acts as a getter of @initial_marking. If arguments are
8
- # supplied, they must identify free places, and are mapped to their initial
9
- # marking.
10
- #
11
- def initial_marking ids=nil
12
- if ids.nil? then
13
- @initial_marking or
14
- fail TypeError, "InitialMarking object not instantiated yet!"
15
- else
16
- free_places( ids ).map { |pl| initial_marking[ place( pl ) ] }
17
- end
18
- end
19
-
20
- # Without arguments, returns the marking of all the simulation's places
21
- # (both free and clamped) as it appears after reset. If arguments are
22
- # supplied, they must identify places, and are converted to either their
23
- # initial marking (free places), or their clamp value (clamped places).
24
- #
25
- def im ids=nil
26
- return im( places ) if ids.nil?
27
- places( ids ).map { |pl|
28
- pl.free? ? initial_marking( of: pl ) : marking_clamp( of: pl )
7
+ # Expects a single array of free places or place ids, and returns an array
8
+ # of their initial markings.
9
+ #
10
+ def Initial_markings array
11
+ Free_places( array ).map { |place| initial_marking[ place place ] }
12
+ end
13
+ alias initial_Markings Initial_markings
14
+
15
+ # Expects an arbitrary number of arguments identifying free places, whose
16
+ # initial markings are then returned. If no arguments are given, acts as
17
+ # a getter of +@initial_marking+ instance variable.
18
+ #
19
+ def initial_markings *free_places
20
+ return initial_marking if free_places.empty?
21
+ Initial_markings( free_places )
22
+ end
23
+
24
+ # Expects a single free place and returns the value of its initial marking.
25
+ #
26
+ def initial_marking arg=L!
27
+ return initial_markings( arg ).first unless arg.local_object?
28
+ @initial_marking or fail TypeError, "+@initial_marking+ not present yet!"
29
+ end
30
+
31
+ # Expects a single array of places, and returns their marking as it would
32
+ # appear right after the simulation reset.
33
+ #
34
+ def Im array
35
+ places( array ).map { |place|
36
+ place.free? ? initial_marking( place ) : marking_clamp( place )
29
37
  }
30
38
  end
31
39
 
40
+ # Expects an arbitrary number of places or place identifiers, and returns
41
+ # their marking as it would appear right after the simulation reset. If no
42
+ # arguments are given, returns all of them.
43
+ #
44
+ def im *places
45
+ return Im places() if places.empty?
46
+ Im( places )
47
+ end
48
+
32
49
  # Returns initial marking vector for free places. Like +#initial_marking+,
33
50
  # but returns a column vector.
34
51
  #
@@ -47,9 +64,8 @@ class YPetri::Simulation::InitialMarking
47
64
 
48
65
  # Sets the initial marking of a place (frontend of +InitialMarking#set+).
49
66
  #
50
- def set_initial_marking( of: (fail ArgumentError), to: (fail ArgumentError) )
51
- initial_marking.set( of, to: to )
67
+ def set_initial_marking( place, to: (fail ArgumentError) )
68
+ initial_marking.set( place, to: to )
52
69
  end
53
70
  end # module Access
54
71
  end # class YPetri::Simulation::InitialMarking
55
-
@@ -1,34 +1,39 @@
1
- #encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
3
  # Simulation mixin providing access to the marking clamps.
4
4
  #
5
5
  class YPetri::Simulation::MarkingClamps
6
6
  module Access
7
- # Without arguments, acts as a getter of the @marking_clamp hash. If
8
- # arguments are supplied, they must identify clamped places, and are mapped
9
- # to their clamp values.
7
+ # Expects a single array of clamped places or place ids, and returns an array
8
+ # of their clamp values.
10
9
  #
11
- def marking_clamps ids=nil
12
- if ids.nil? then
13
- @marking_clamps or
14
- fail TypeError, "MarkingClamps object not instantiated yet!"
15
- else
16
- clamped_places( ids ).map { |p| marking_clamp of: p }
17
- end
10
+ def Marking_clamps array
11
+ Clamped_places( array ).map { |place| marking_clamps.fetch( place ) }
12
+ end
13
+ alias marking_Clamps Marking_clamps
14
+
15
+ # Expects an arbitrary number of arguments identifying clamped places, whose
16
+ # marking clamps are then returned. If no arguments are given, acts as a
17
+ # getter of +@marking_clamps+ instance variable.
18
+ #
19
+ def marking_clamps *clamped_places
20
+ return Marking_clamps( clamped_places ) unless clamped_places.empty?
21
+ @marking_clamps or
22
+ fail TypeError, "+@marking_clamps+ not instantiated yet!"
18
23
  end
19
24
  alias clamps marking_clamps
20
25
 
21
- # Marking clamp identification.
26
+ # Identification of a single marking clamp. Expects a single clamped place or
27
+ # place id and returns the value of its clamp.
22
28
  #
23
- def marking_clamp( of: (fail ArgumentError) )
24
- marking_clamps.clamp_of( of )
29
+ def marking_clamp( clamped_place )
30
+ marking_clamps( clamped_place ).first
25
31
  end
26
32
 
27
33
  # Sets the marking clamp of a place (frontend of +InitialMarking#set+).
28
34
  #
29
- def set_marking_clamp( of: (fail ArgumentError), to: (fail ArgumentError) )
30
- marking_clamps.set( of, to: to )
35
+ def set_marking_clamp( place, to: (fail ArgumentError) )
36
+ marking_clamps.set( place, to: to )
31
37
  end
32
38
  end # module Access
33
39
  end # class YPetri::Simulation::MarkingClamps
34
-
@@ -2,8 +2,6 @@
2
2
  #
3
3
  class YPetri::Simulation
4
4
  class MarkingClamps < PlaceMapping
5
- alias clamp_of of
6
-
7
5
  # Sets the clamp for a given place to a given value.
8
6
  #
9
7
  def set place_id, to: (fail ArgumentError, "No :to value!")
@@ -1,45 +1,91 @@
1
- #encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
- # A mixin.
3
+ # A mixin to +YPetri::Simulation+.
4
4
  #
5
5
  class YPetri::Simulation::MarkingVector
6
6
  module Access
7
- # Marking of all places (as a column vector).
7
+ # Marking of the selected places as a column vector. Expects a single array
8
+ # argument.
8
9
  #
9
- def m_vector ids=nil
10
- if ids.nil? then
11
- @m_vector or fail TypeError, "Marking vector not established yet!"
12
- else
13
- m_vector.select( ids )
14
- end
10
+ def M_vector array
11
+ m_vector.select( array )
15
12
  end
13
+ alias m_Vector M_vector
16
14
 
17
- # Marking of all places (as array).
15
+ # Acts as a getter of the simulation's state vector, instance variable
16
+ # +@m_vector+.
18
17
  #
19
- def m ids=nil
20
- m_vector( ids ).to_a
18
+ def state
19
+ @m_vector or fail TypeError, "State not constructed yet!"
21
20
  end
22
21
 
23
- # Marking of all places (as hash).
22
+ # Convenience method that accepts any number of places or place ids as
23
+ # arguments, and returns their marking as a column vector. If no arguments
24
+ # are supplied, the method returns the simulation's state vector.
24
25
  #
25
- def place_m ids=nil
26
- m_vector( ids ).to_hash
26
+ def m_vector *places
27
+ begin
28
+ return state if places.empty?
29
+ m_vector.select( places )
30
+ end
27
31
  end
28
-
29
- # Marking of the indicated places (as hash with place names as keys).
32
+
33
+ # Array-returning equivalents of +#M_vector+ and +m_vector+.
34
+ #
35
+ def M *args; M_vector( *args ).to_a end
36
+ def m *args; m_vector( *args ).to_a end
37
+
38
+
39
+ # map! M: :M_vector,
40
+ # m: :m_vector,
41
+ # &:column_to_a
42
+
43
+ # Hash-returning { place => marking } equivalents Marking of all places
44
+ # (as hash).
30
45
  #
31
- def p_m ids=nil
32
- places( ids ).names( true ) >> m( ids )
46
+ chain Place_m: :M_vector,
47
+ place_m: :m_vector,
48
+ &:to_hash
49
+ alias place_M Place_m
50
+
51
+ # Marking of the indicated places as a hash of { place name => marking }
52
+ # pairs. Expects a single array of places or place ids as an argument.
53
+ #
54
+ def P_m places
55
+ Places( places ).names( true ) >> M( places )
56
+ end
57
+ alias p_M P_m
58
+ alias Pn_m P_m
59
+
60
+ # Marking of the indicated places as a hash of { place name => marking }
61
+ # pairs. Expects and arbitrary number of places or place ids and arguments.
62
+ # If no arguments are given, marking of all the places is returned.
63
+ #
64
+ def p_m *places
65
+ places( *places ).names( true ) >> m( *places )
33
66
  end
34
67
  alias pn_m p_m
35
68
 
36
- # Pretty prints marking of the indicated places as hash with place names as
37
- # keys. Takes optional list of place ids (ordered argument no. 1), and
38
- # optional 2 named arguments (+:gap+ and +:precision+), as in
39
- # +#pretty_print_numeric_values+.
69
+ # Pretty prints marking of the indicated places. Expects an array of places
70
+ # or place ids as an argument. In addition, accepts 2 optional named
71
+ # arguments, +:gap+ and +:precision+ (alias +:p+), that control the layout
72
+ # of the printed table, like in +#pretty_print_numeric_values+ method.
73
+ #
74
+ def Pm places, **named_args
75
+ gap = named_args[:gap] || 0
76
+ named_args.may_have :precision, syn!: :pn
77
+ precision = named_args.delete( :precision ) || 3
78
+ P_m( places ).pretty_print_numeric_values gap: gap, precision: precision
79
+ end
80
+
81
+ # Pretty prints marking of the indicated places. Expects an arbitrary number
82
+ # of places or place ids, and 2 optional named arguments, +:gap+ and
83
+ # +:precision+ (alias +:p+), that control the layout of the printed table,
84
+ # like in +#pretty_print_numeric_values+ method.
40
85
  #
41
- def pm ids=nil, gap: 0, precision: 3
42
- p_m( ids ).pretty_print_numeric_values gap: gap, precision: precision
86
+ def pm *places, **named_args
87
+ return Pm places() if places.empty?
88
+ Pm( places, **named_args )
43
89
  end
44
90
 
45
91
  # Modifies the marking vector. Takes one argument. If the argument is a hash
@@ -58,31 +104,44 @@ class YPetri::Simulation::MarkingVector
58
104
  else # convert it with #each
59
105
  update_m( new_m.each.to_a )
60
106
  end
107
+ return nil
61
108
  end
109
+ alias set_m update_m
62
110
 
63
- # Marking vector of free places.
111
+ # Marking vector of free places. Expects an array of places or place ids, for
112
+ # which the marking vectro is returned.
64
113
  #
65
- def marking_vector ids=nil
66
- m_vector free_places( ids )
114
+ def Marking_vector array
115
+ M_vector Free_places( array )
67
116
  end
68
117
 
69
- # Marking of free places (as array).
118
+ # Marking vector of free places. Expects an arbitrary number of free places
119
+ # or place ids and returns the marking vector for them.
70
120
  #
71
- def marking ids=nil
72
- marking_vector( ids ).to_a
121
+ def marking_vector *places
122
+ m_vector *free_places( *places )
73
123
  end
74
124
 
75
- # Marking of free places (as hash).
125
+ # Array-returning versions of +#Marking_vector+ and +#marking_vector+.
76
126
  #
77
- def place_marking ids=nil
78
- marking_vector( ids ).to_hash
79
- end
127
+ chain Marking: :Marking_vector,
128
+ marking: :marking_vector,
129
+ &:to_a
80
130
 
81
- # Marking of free places (as hash with place names as keys).
131
+ # Versions of +#Marking_vector+ and +#marking_vector+ that return hash of
132
+ # { place => marking } pairs.
82
133
  #
83
- def p_marking ids=nil
84
- marking_vector( ids ).to_h
85
- end
134
+ chain Place_marking: :Marking_vector,
135
+ place_marking: :marking_vector,
136
+ &:to_hash
137
+
138
+ # Versions of +#Marking_vector+ and +#marking_vector+ that return hash of
139
+ # { place name => marking } pairs.
140
+ #
141
+ chain P_marking: :Marking_vector,
142
+ p_marking: :marking_vector,
143
+ &:to_h
144
+ alias Pn_marking P_marking
86
145
  alias pn_marking p_marking
87
146
 
88
147
  # Modifies the marking vector. Like +#update_m+, but the places must be
@@ -92,7 +151,7 @@ class YPetri::Simulation::MarkingVector
92
151
  def update_marking new_m
93
152
  case new_m
94
153
  when Hash then # assume { place => marking } hash
95
- ( free_places( *new_m.keys ) >> new_m.values )
154
+ ( free_places( new_m.keys ) >> new_m.values )
96
155
  .each_pair { |id, val| m_vector.set( id, val ) }
97
156
  when Array then
98
157
  msg = "T be a collection with size == number of net's free places!"
@@ -101,13 +160,16 @@ class YPetri::Simulation::MarkingVector
101
160
  else # convert it with #each
102
161
  update_marking( new_m.each.to_a )
103
162
  end
163
+ return nil
104
164
  end
165
+ alias set_marking update_marking
105
166
 
106
167
  # Expects a Δ marking vector for free places and performs the specified
107
168
  # change on the marking vector of the simulation.
108
169
  #
109
170
  def increment_marking Δ_free
110
171
  @m_vector += f2a * Δ_free
172
+ return nil
111
173
  end
112
174
  end # module Access
113
175
  end # class YPetri::Simulation::MarkingVector