y_petri 2.0.7 → 2.0.14.p1
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.
- checksums.yaml +4 -4
- data/lib/y_petri/net/selections.rb +209 -0
- data/lib/y_petri/net/visualization.rb +67 -0
- data/lib/y_petri/net.rb +33 -311
- data/lib/y_petri/place/guard.rb +20 -13
- data/lib/y_petri/place.rb +12 -7
- data/lib/y_petri/simulation.rb +8 -9
- data/lib/y_petri/transition/assignment.rb +37 -0
- data/lib/y_petri/transition/{constructor_syntax.rb → construction.rb} +1 -0
- data/lib/y_petri/transition/ordinary_timeless.rb +46 -0
- data/lib/y_petri/transition/timed.rb +57 -0
- data/lib/y_petri/transition.rb +103 -220
- data/lib/y_petri/version.rb +1 -1
- data/lib/y_petri.rb +1 -1
- data/test/acceptance/basic_usage_test.rb +30 -0
- data/test/acceptance/simulation_test.rb +132 -0
- data/test/acceptance/simulation_with_physical_units_test.rb +153 -0
- data/test/acceptance/token_game_test.rb +36 -0
- data/test/acceptance/visualization_test.rb +25 -0
- data/test/acceptance_tests.rb +14 -0
- data/test/manipulator_test.rb +100 -0
- data/test/{simple_manual_examples.rb → manual_examples.rb} +0 -0
- data/test/net_test.rb +171 -0
- data/test/place_test.rb +7 -6
- data/test/simulation_test.rb +280 -0
- data/test/timed_simulation_test.rb +149 -0
- data/test/transition_test.rb +2 -4
- data/test/workspace_test.rb +72 -0
- data/test/y_petri_test.rb +16 -1107
- metadata +34 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c46f784c2f2df0ff3008daa1c29aaeb03dbafcc
|
4
|
+
data.tar.gz: cd6bb027a5079b5b02241f2bf08edcf3b6aeeb47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de99715667452ffbfe93f2984b193f9af2601a0ec52de5a8551b2be331574adf4a8e56f4f27f8e7a6f664a961597d708d16a8365303ab65bcbbdf44fae125fc5
|
7
|
+
data.tar.gz: ed7637fc1976b90b3336237a98c2ef0e7255dac36e6c8b720c6c1b3bfc0f9726e3e42f233d29624827b862e5ea75bea87ed19a4442ed5c5e01f0aaab9379b812
|
@@ -0,0 +1,209 @@
|
|
1
|
+
# Selections of various kinds of places / transitions (place names / transition
|
2
|
+
# names) in a Petri net.
|
3
|
+
#
|
4
|
+
class YPetri::Net
|
5
|
+
# Names of places in the net.
|
6
|
+
#
|
7
|
+
def pp
|
8
|
+
places.map &:name
|
9
|
+
end
|
10
|
+
|
11
|
+
# Names of transitions in the net.
|
12
|
+
#
|
13
|
+
def tt
|
14
|
+
transitions.map &:name
|
15
|
+
end
|
16
|
+
|
17
|
+
# Array of _ts_ transitions in the net.
|
18
|
+
#
|
19
|
+
def timeless_nonstoichiometric_transitions
|
20
|
+
transitions.select { |t| t.timeless? && t.nonstoichiometric? }
|
21
|
+
end
|
22
|
+
alias ts_transitions timeless_nonstoichiometric_transitions
|
23
|
+
|
24
|
+
# Names of _ts_ transitions in the net.
|
25
|
+
#
|
26
|
+
def timeless_nonstoichiometric_tt
|
27
|
+
timeless_nonstoichiometric_transitions.map &:name
|
28
|
+
end
|
29
|
+
alias ts_tt timeless_nonstoichiometric_tt
|
30
|
+
|
31
|
+
# Array of _tsa_ transitions in the net.
|
32
|
+
#
|
33
|
+
def timeless_nonstoichiometric_nonassignment_transitions
|
34
|
+
transitions.select { |t|
|
35
|
+
t.timeless? && t.nonstoichiometric? && ! t.assignment_action?
|
36
|
+
}
|
37
|
+
end
|
38
|
+
alias tsa_transitions timeless_nonstoichiometric_nonassignment_transitions
|
39
|
+
|
40
|
+
# Names of _tsa_ transitions in the net.
|
41
|
+
#
|
42
|
+
def timeless_nonstoichiometric_nonassignment_tt
|
43
|
+
timeless_nonstoichiometric_nonassignment_transitions.map &:name
|
44
|
+
end
|
45
|
+
alias tsa_tt timeless_nonstoichiometric_nonassignment_tt
|
46
|
+
|
47
|
+
# Array of _tS_ transitions in the net.
|
48
|
+
#
|
49
|
+
def timeless_stoichiometric_transitions
|
50
|
+
transitions.select { |t| t.timeless? && t.stoichiometric? }
|
51
|
+
end
|
52
|
+
alias tS_transitions timeless_stoichiometric_transitions
|
53
|
+
|
54
|
+
# Names of _tS_ transitions in the net.
|
55
|
+
#
|
56
|
+
def timeless_stoichiometric_tt
|
57
|
+
timeless_stoichiometric_transitions.map &:name
|
58
|
+
end
|
59
|
+
alias tS_tt timeless_stoichiometric_tt
|
60
|
+
|
61
|
+
# Array of _Tsr_ transitions in the net.
|
62
|
+
#
|
63
|
+
def timed_nonstoichiometric_transitions_without_rate
|
64
|
+
transitions.select { |t| t.timed? && t.nonstoichiometric? && t.rateless? }
|
65
|
+
end
|
66
|
+
alias timed_rateless_nonstoichiometric_transitions \
|
67
|
+
timed_nonstoichiometric_transitions_without_rate
|
68
|
+
alias Tsr_transitions timed_nonstoichiometric_transitions_without_rate
|
69
|
+
|
70
|
+
# Names of _Tsr_ transitions in the net.
|
71
|
+
#
|
72
|
+
def timed_nonstoichiometric_tt_without_rate
|
73
|
+
timed_nonstoichiometric_transitions_without_rate.map &:name
|
74
|
+
end
|
75
|
+
alias timed_rateless_nonstoichiometric_tt \
|
76
|
+
timed_nonstoichiometric_tt_without_rate
|
77
|
+
alias Tsr_tt timed_nonstoichiometric_tt_without_rate
|
78
|
+
|
79
|
+
# Array of _TSr_ transitions in the net.
|
80
|
+
#
|
81
|
+
def timed_stoichiometric_transitions_without_rate
|
82
|
+
transitions.select { |t| t.timed? && t.stoichiometric? && t.rateless? }
|
83
|
+
end
|
84
|
+
alias timed_rateless_stoichiometric_transitions \
|
85
|
+
timed_stoichiometric_transitions_without_rate
|
86
|
+
alias TSr_transitions timed_stoichiometric_transitions_without_rate
|
87
|
+
|
88
|
+
# Names of _TSr_ transitions in the net.
|
89
|
+
#
|
90
|
+
def timed_stoichiometric_tt_without_rate
|
91
|
+
timed_stoichiometric_transitions_without_rate.map &:name
|
92
|
+
end
|
93
|
+
alias timed_rateless_stoichiometric_tt timed_stoichiometric_tt_without_rate
|
94
|
+
alias Tsr_tt timed_stoichiometric_tt_without_rate
|
95
|
+
|
96
|
+
# Array of _sR_ transitions in the net.
|
97
|
+
#
|
98
|
+
def nonstoichiometric_transitions_with_rate
|
99
|
+
transitions.select { |t| t.has_rate? && t.nonstoichiometric? }
|
100
|
+
end
|
101
|
+
alias sR_transitions nonstoichiometric_transitions_with_rate
|
102
|
+
|
103
|
+
# Names of _sR_ transitions in the net.
|
104
|
+
#
|
105
|
+
def nonstoichiometric_tt_with_rate
|
106
|
+
nonstoichiometric_transitions_with_rate.map &:name
|
107
|
+
end
|
108
|
+
alias sR_tt nonstoichiometric_tt_with_rate
|
109
|
+
|
110
|
+
# Array of _SR_ transitions in the net.
|
111
|
+
#
|
112
|
+
def stoichiometric_transitions_with_rate
|
113
|
+
transitions.select { |t| t.has_rate? and t.stoichiometric? }
|
114
|
+
end
|
115
|
+
alias SR_transitions stoichiometric_transitions_with_rate
|
116
|
+
|
117
|
+
# Names of _SR_ transitions in the net.
|
118
|
+
#
|
119
|
+
def stoichiometric_tt_with_rate
|
120
|
+
stoichiometric_transitions_with_rate.map &:name
|
121
|
+
end
|
122
|
+
alias SR_tt stoichiometric_tt_with_rate
|
123
|
+
|
124
|
+
# Array of transitions with _explicit assignment action_ (_A transitions_)
|
125
|
+
# in the net.
|
126
|
+
#
|
127
|
+
def assignment_transitions
|
128
|
+
transitions.select { |t| t.assignment_action? }
|
129
|
+
end
|
130
|
+
alias A_transitions assignment_transitions
|
131
|
+
|
132
|
+
# Names of transitions with _explicit assignment action_ (_A transitions_)
|
133
|
+
# in the net.
|
134
|
+
#
|
135
|
+
def assignment_tt
|
136
|
+
assignment_transitions.map &:name
|
137
|
+
end
|
138
|
+
alias A_tt assignment_tt
|
139
|
+
|
140
|
+
# Array of _stoichiometric_ transitions in the net.
|
141
|
+
#
|
142
|
+
def stoichiometric_transitions
|
143
|
+
transitions.select &:stoichiometric?
|
144
|
+
end
|
145
|
+
alias S_transitions stoichiometric_transitions
|
146
|
+
|
147
|
+
# Names of _stoichiometric_ transitions in the net.
|
148
|
+
#
|
149
|
+
def stoichiometric_tt
|
150
|
+
stoichiometric_transitions.map &:name
|
151
|
+
end
|
152
|
+
alias S_tt stoichiometric_tt
|
153
|
+
|
154
|
+
# Array of _nonstoichiometric_ transitions in the net.
|
155
|
+
#
|
156
|
+
def nonstoichiometric_transitions
|
157
|
+
transitions.select &:nonstoichiometric?
|
158
|
+
end
|
159
|
+
alias s_transitions nonstoichiometric_transitions
|
160
|
+
|
161
|
+
# Names of _nonstoichimetric_ transitions in the net.
|
162
|
+
#
|
163
|
+
def nonstoichiometric_tt
|
164
|
+
nonstoichiometric_transitions.map &:name
|
165
|
+
end
|
166
|
+
alias s_tt nonstoichiometric_tt
|
167
|
+
|
168
|
+
# Array of _timed_ transitions in the net.
|
169
|
+
#
|
170
|
+
def timed_transitions; transitions.select &:timed? end
|
171
|
+
alias T_transitions timed_transitions
|
172
|
+
|
173
|
+
# Names of _timed_ transitions in the net.
|
174
|
+
#
|
175
|
+
def timed_tt; timed_transitions.map &:name end
|
176
|
+
alias T_tt timed_tt
|
177
|
+
|
178
|
+
# Array of _timeless_ transitions in the net.
|
179
|
+
#
|
180
|
+
def timeless_transitions; transitions.select &:timeless? end
|
181
|
+
alias t_transitions timeless_transitions
|
182
|
+
|
183
|
+
# Names of _timeless_ transitions in the net.
|
184
|
+
#
|
185
|
+
def timeless_tt; timeless_transitions.map &:name end
|
186
|
+
alias t_tt timeless_tt
|
187
|
+
|
188
|
+
# Array of _transitions with rate_ in the net.
|
189
|
+
#
|
190
|
+
def transitions_with_rate; transitions.select &:has_rate? end
|
191
|
+
alias R_transitions transitions_with_rate
|
192
|
+
|
193
|
+
# Names of _transitions with rate_ in the net.
|
194
|
+
#
|
195
|
+
def tt_with_rate; transitions_with_rate.map &:name end
|
196
|
+
alias R_tt tt_with_rate
|
197
|
+
|
198
|
+
# Array of _rateless_ transitions in the net.
|
199
|
+
#
|
200
|
+
def rateless_transitions; transitions.select &:rateless? end
|
201
|
+
alias transitions_without_rate rateless_transitions
|
202
|
+
alias r_transitions rateless_transitions
|
203
|
+
|
204
|
+
# Names of _rateless_ transitions in the net.
|
205
|
+
#
|
206
|
+
def rateless_tt; rateless_transitions.map &:name end
|
207
|
+
alias tt_without_rate rateless_tt
|
208
|
+
alias r_tt rateless_tt
|
209
|
+
end # class YPetri::Net
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
# Own visualization capabilities of a Petri net.
|
4
|
+
#
|
5
|
+
class YPetri::Net
|
6
|
+
# Visualizes the net with Graphviz.
|
7
|
+
#
|
8
|
+
def visualize
|
9
|
+
require 'graphviz'
|
10
|
+
γ = GraphViz.new :G
|
11
|
+
# Add places and transitions.
|
12
|
+
place_nodes = places.map.with_object Hash.new do |pl, ꜧ|
|
13
|
+
ꜧ[pl] = γ.add_nodes pl.name.to_s,
|
14
|
+
fillcolor: 'lightgrey',
|
15
|
+
color: 'grey',
|
16
|
+
style: 'filled'
|
17
|
+
end
|
18
|
+
transition_nodes = transitions.map.with_object Hash.new do |tr, ꜧ|
|
19
|
+
ꜧ[tr] = γ.add_nodes tr.name.to_s,
|
20
|
+
shape: 'box',
|
21
|
+
fillcolor: if tr.assignment? then 'yellow'
|
22
|
+
elsif tr.basic_type == :SR then 'lightcyan'
|
23
|
+
else 'ghostwhite' end,
|
24
|
+
color: if tr.assignment? then 'goldenrod'
|
25
|
+
elsif tr.basic_type == :SR then 'cyan'
|
26
|
+
else 'grey' end,
|
27
|
+
style: 'filled'
|
28
|
+
end
|
29
|
+
# Add Petri net arcs.
|
30
|
+
transition_nodes.each { |tr, tr_node|
|
31
|
+
if tr.assignment? then
|
32
|
+
tr.codomain.each { |pl|
|
33
|
+
γ.add_edges tr_node, place_nodes[pl], color: 'goldenrod'
|
34
|
+
}
|
35
|
+
( tr.domain - tr.codomain ).each { |pl|
|
36
|
+
γ.add_edges tr_node, place_nodes[pl], color: 'grey', arrowhead: 'none'
|
37
|
+
}
|
38
|
+
elsif tr.basic_type == :SR then
|
39
|
+
tr.codomain.each { |pl|
|
40
|
+
if tr.stoichio[pl] > 0 then # producing arc
|
41
|
+
γ.add_edges tr_node, place_nodes[pl], color: 'cyan'
|
42
|
+
elsif tr.stoichio[pl] < 0 then # consuming arc
|
43
|
+
γ.add_edges place_nodes[pl], tr_node, color: 'cyan'
|
44
|
+
else
|
45
|
+
γ.add_edges place_nodes[pl], tr_node, color: 'grey', arrowhead: 'none'
|
46
|
+
end
|
47
|
+
}
|
48
|
+
( tr.domain - tr.codomain ).each { |pl|
|
49
|
+
γ.add_edges tr_node, place_nodes[pl], color: 'grey', arrowhead: 'none'
|
50
|
+
}
|
51
|
+
end
|
52
|
+
}
|
53
|
+
# Generate output image.
|
54
|
+
γ.output png: File.expand_path( "~/y_petri_graph.png" )
|
55
|
+
# require 'y_support/kde'
|
56
|
+
YSupport::KDE.show_file_with_kioclient File.expand_path( "~/y_petri_graph.png" )
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
# Display a file with kioclient (KDE).
|
62
|
+
#
|
63
|
+
def show_file_with_kioclient( file_name )
|
64
|
+
system "sleep 0.2; kioclient exec 'file:%s'" %
|
65
|
+
File.expand_path( '.', file_name )
|
66
|
+
end
|
67
|
+
end # class YPetri::Net
|