y_petri 2.2.4 → 2.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +675 -0
- data/README.md +6 -3
- data/Rakefile +1 -1
- data/lib/y_petri/agent/{petri_net_related.rb → petri_net_aspect.rb} +34 -10
- data/lib/y_petri/agent/{simulation_related.rb → simulation_aspect.rb} +49 -34
- data/lib/y_petri/agent.rb +5 -5
- data/lib/y_petri/core/guarded.rb +24 -0
- data/lib/y_petri/core/timed/euler.rb +4 -8
- data/lib/y_petri/core/timed/gillespie.rb +11 -17
- data/lib/y_petri/core/timed/methods.rb +23 -0
- data/lib/y_petri/core/timed/pseudo_euler.rb +10 -13
- data/lib/y_petri/core/timed/quasi_euler.rb +9 -8
- data/lib/y_petri/core/timed/runge_kutta.rb +10 -18
- data/lib/y_petri/core/timed.rb +6 -14
- data/lib/y_petri/core/timeless/methods.rb +15 -0
- data/lib/y_petri/core/timeless/pseudo_euler.rb +4 -8
- data/lib/y_petri/core/timeless.rb +9 -4
- data/lib/y_petri/core.rb +44 -42
- data/lib/y_petri/net/data_set.rb +246 -142
- data/lib/y_petri/net/node_access.rb +282 -0
- data/lib/y_petri/net/own_state.rb +14 -4
- data/lib/y_petri/net/state/feature/assignment.rb +123 -0
- data/lib/y_petri/net/state/feature/delta.rb +55 -35
- data/lib/y_petri/net/state/feature/firing.rb +68 -25
- data/lib/y_petri/net/state/feature/flux.rb +9 -2
- data/lib/y_petri/net/state/feature/gradient.rb +36 -19
- data/lib/y_petri/net/state/feature/marking.rb +10 -5
- data/lib/y_petri/net/state/feature.rb +105 -11
- data/lib/y_petri/net/state/features/record.rb +144 -99
- data/lib/y_petri/net/state/features.rb +327 -200
- data/lib/y_petri/net/state.rb +48 -82
- data/lib/y_petri/net/visualization.rb +1 -1
- data/lib/y_petri/net.rb +62 -47
- data/lib/y_petri/place/arcs.rb +44 -0
- data/lib/y_petri/place/features.rb +115 -0
- data/lib/y_petri/place.rb +62 -29
- data/lib/y_petri/simulation/dependency.rb +31 -67
- data/lib/y_petri/simulation/feature_set.rb +1 -1
- data/lib/y_petri/simulation/initial_marking/access.rb +42 -26
- data/lib/y_petri/simulation/marking_clamps/access.rb +22 -17
- data/lib/y_petri/simulation/marking_clamps.rb +0 -2
- data/lib/y_petri/simulation/marking_vector/access.rb +102 -40
- data/lib/y_petri/simulation/marking_vector.rb +35 -37
- data/lib/y_petri/simulation/matrix.rb +1 -1
- data/lib/y_petri/simulation/node_representation.rb +25 -0
- data/lib/y_petri/simulation/nodes/access.rb +78 -0
- data/lib/y_petri/simulation/{elements.rb → nodes.rb} +14 -13
- data/lib/y_petri/simulation/place_mapping.rb +2 -2
- data/lib/y_petri/simulation/place_representation.rb +8 -7
- data/lib/y_petri/simulation/places/access.rb +89 -70
- data/lib/y_petri/simulation/places/free.rb +1 -1
- data/lib/y_petri/simulation/places/types.rb +20 -22
- data/lib/y_petri/simulation/places.rb +23 -18
- data/lib/y_petri/simulation/recorder.rb +23 -18
- data/lib/y_petri/simulation/timed/recorder.rb +19 -11
- data/lib/y_petri/simulation/timed.rb +93 -29
- data/lib/y_petri/simulation/timeless/recorder.rb +11 -6
- data/lib/y_petri/simulation/timeless.rb +13 -3
- data/lib/y_petri/simulation/transition_representation/A.rb +24 -4
- data/lib/y_petri/simulation/transition_representation/S.rb +11 -1
- data/lib/y_petri/simulation/transition_representation/T.rb +1 -1
- data/lib/y_petri/simulation/transition_representation/Ts.rb +1 -1
- data/lib/y_petri/simulation/transition_representation/a.rb +1 -1
- data/lib/y_petri/simulation/transition_representation/s.rb +12 -1
- data/lib/y_petri/simulation/transition_representation/t.rb +1 -1
- data/lib/y_petri/simulation/transition_representation/tS.rb +1 -1
- data/lib/y_petri/simulation/transition_representation/ts.rb +1 -1
- data/lib/y_petri/simulation/transition_representation/types.rb +1 -1
- data/lib/y_petri/simulation/transition_representation.rb +4 -11
- data/lib/y_petri/simulation/transitions/A.rb +17 -2
- data/lib/y_petri/simulation/transitions/S.rb +1 -1
- data/lib/y_petri/simulation/transitions/T.rb +1 -1
- data/lib/y_petri/simulation/transitions/Ts.rb +6 -5
- data/lib/y_petri/simulation/transitions/a.rb +1 -1
- data/lib/y_petri/simulation/transitions/access.rb +195 -168
- data/lib/y_petri/simulation/transitions/s.rb +1 -1
- data/lib/y_petri/simulation/transitions/t.rb +1 -1
- data/lib/y_petri/simulation/transitions/tS.rb +1 -1
- data/lib/y_petri/simulation/transitions/ts.rb +1 -1
- data/lib/y_petri/simulation/transitions/types.rb +1 -1
- data/lib/y_petri/simulation/transitions.rb +5 -7
- data/lib/y_petri/simulation.rb +84 -90
- data/lib/y_petri/transition/A.rb +8 -2
- data/lib/y_petri/transition/T.rb +25 -2
- data/lib/y_petri/transition/arcs.rb +19 -3
- data/lib/y_petri/transition/construction_convenience.rb +11 -10
- data/lib/y_petri/transition/t.rb +14 -1
- data/lib/y_petri/transition/types.rb +6 -1
- data/lib/y_petri/transition.rb +9 -12
- data/lib/y_petri/version.rb +1 -1
- data/lib/y_petri/world/dependency.rb +3 -3
- data/lib/y_petri/world/{petri_net_related.rb → petri_net_aspect.rb} +4 -4
- data/lib/y_petri/world/simulation_aspect.rb +352 -0
- data/lib/y_petri/world.rb +4 -4
- data/lib/y_petri.rb +1 -1
- data/test/agent_test.rb +2 -1
- data/test/examples/demonstrator.rb +4 -1
- data/test/examples/demonstrator_2.rb +5 -0
- data/test/examples/demonstrator_4.rb +6 -5
- data/test/examples/example_2.rb +2 -0
- data/test/examples/manual_examples.rb +4 -4
- data/test/net_test.rb +457 -54
- data/test/place_test.rb +11 -7
- data/test/simulation_test.rb +358 -331
- data/test/transition_test.rb +11 -10
- data/test/world_test.rb +2 -0
- data/test/y_petri_test.rb +2 -1
- data/y_petri.gemspec +24 -18
- metadata +71 -17
- data/LICENSE +0 -22
- data/lib/y_petri/net/element_access.rb +0 -239
- data/lib/y_petri/simulation/element_representation.rb +0 -20
- data/lib/y_petri/simulation/elements/access.rb +0 -57
- data/lib/y_petri/transition/type.rb +0 -103
- data/lib/y_petri/transition/type_information.rb +0 -103
- 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
|
-
★
|
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
|
-
|
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
|
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
|
58
|
-
|
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
|
-
#
|
157
|
+
# Convenience visualizer of the upstream net.
|
133
158
|
#
|
134
|
-
def
|
135
|
-
|
136
|
-
"#<Place: #{ ( [n, m, d, q].compact ).join ', ' }>"
|
159
|
+
def uv
|
160
|
+
upstream_net.visualize
|
137
161
|
end
|
138
162
|
|
139
|
-
#
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
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,
|
150
|
-
nς = "name: #{n.nil? ? '∅' : n}"
|
182
|
+
m, n, q = marking, name, quantum
|
151
183
|
mς = "marking: #{m.nil? ? 'nil' : m}"
|
152
|
-
|
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
|
5
|
-
#
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
100
|
-
|
101
|
-
|
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
|
-
|
104
|
-
|
105
|
-
|
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,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
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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(
|
51
|
-
initial_marking.set(
|
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
|
-
#
|
8
|
-
#
|
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
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
#
|
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(
|
24
|
-
marking_clamps
|
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(
|
30
|
-
marking_clamps.set(
|
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
|
-
|
@@ -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
|
7
|
+
# Marking of the selected places as a column vector. Expects a single array
|
8
|
+
# argument.
|
8
9
|
#
|
9
|
-
def
|
10
|
-
|
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
|
-
#
|
15
|
+
# Acts as a getter of the simulation's state vector, instance variable
|
16
|
+
# +@m_vector+.
|
18
17
|
#
|
19
|
-
def
|
20
|
-
m_vector
|
18
|
+
def state
|
19
|
+
@m_vector or fail TypeError, "State not constructed yet!"
|
21
20
|
end
|
22
21
|
|
23
|
-
#
|
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
|
26
|
-
|
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
|
-
#
|
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
|
-
|
32
|
-
|
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
|
37
|
-
#
|
38
|
-
#
|
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
|
42
|
-
|
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
|
66
|
-
|
114
|
+
def Marking_vector array
|
115
|
+
M_vector Free_places( array )
|
67
116
|
end
|
68
117
|
|
69
|
-
# Marking of free places
|
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
|
72
|
-
|
121
|
+
def marking_vector *places
|
122
|
+
m_vector *free_places( *places )
|
73
123
|
end
|
74
124
|
|
75
|
-
#
|
125
|
+
# Array-returning versions of +#Marking_vector+ and +#marking_vector+.
|
76
126
|
#
|
77
|
-
|
78
|
-
|
79
|
-
|
127
|
+
chain Marking: :Marking_vector,
|
128
|
+
marking: :marking_vector,
|
129
|
+
&:to_a
|
80
130
|
|
81
|
-
#
|
131
|
+
# Versions of +#Marking_vector+ and +#marking_vector+ that return hash of
|
132
|
+
# { place => marking } pairs.
|
82
133
|
#
|
83
|
-
|
84
|
-
|
85
|
-
|
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(
|
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
|