y_petri 2.0.15 → 2.1.3
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/{manipulator → agent}/hash_key_pointer.rb +2 -2
- data/lib/y_petri/agent/petri_net_related.rb +115 -0
- data/lib/y_petri/{manipulator → agent}/selection.rb +2 -1
- data/lib/y_petri/{manipulator/simulation_related_methods.rb → agent/simulation_related.rb} +93 -110
- data/lib/y_petri/agent.rb +22 -0
- data/lib/y_petri/core/timed/euler.rb +20 -0
- data/lib/y_petri/core/timed/pseudo_euler.rb +31 -0
- data/lib/y_petri/core/timed/quasi_euler.rb +23 -0
- data/lib/y_petri/core/timed.rb +70 -0
- data/lib/y_petri/core/timeless/pseudo_euler.rb +20 -0
- data/lib/y_petri/core/timeless.rb +12 -0
- data/lib/y_petri/core.rb +100 -0
- data/lib/y_petri/dsl.rb +66 -0
- data/lib/y_petri/fixed_assets.rb +7 -0
- data/lib/y_petri/net/element_access.rb +239 -0
- data/lib/y_petri/net/state/feature/delta.rb +88 -0
- data/lib/y_petri/net/state/feature/firing.rb +57 -0
- data/lib/y_petri/net/state/feature/flux.rb +58 -0
- data/lib/y_petri/net/state/feature/gradient.rb +75 -0
- data/lib/y_petri/net/state/feature/marking.rb +62 -0
- data/lib/y_petri/net/state/feature.rb +79 -0
- data/lib/y_petri/net/state/features/dataset.rb +135 -0
- data/lib/y_petri/net/state/features/record.rb +50 -0
- data/lib/y_petri/net/state/features.rb +126 -0
- data/lib/y_petri/net/state.rb +121 -0
- data/lib/y_petri/net/timed.rb +8 -0
- data/lib/y_petri/net/visualization.rb +3 -3
- data/lib/y_petri/net.rb +73 -77
- data/lib/y_petri/place.rb +8 -3
- data/lib/y_petri/simulation/dependency.rb +107 -0
- data/lib/y_petri/simulation/element_representation.rb +20 -0
- data/lib/y_petri/simulation/elements/access.rb +57 -0
- data/lib/y_petri/simulation/elements.rb +45 -0
- data/lib/y_petri/simulation/feature_set.rb +21 -0
- data/lib/y_petri/simulation/initial_marking/access.rb +55 -0
- data/lib/y_petri/simulation/initial_marking.rb +15 -0
- data/lib/y_petri/simulation/marking_clamps/access.rb +34 -0
- data/lib/y_petri/simulation/marking_clamps.rb +18 -0
- data/lib/y_petri/simulation/marking_vector/access.rb +106 -0
- data/lib/y_petri/simulation/marking_vector.rb +156 -0
- data/lib/y_petri/simulation/matrix.rb +64 -0
- data/lib/y_petri/simulation/place_mapping.rb +62 -0
- data/lib/y_petri/simulation/place_representation.rb +74 -0
- data/lib/y_petri/simulation/places/access.rb +121 -0
- data/lib/y_petri/simulation/places/clamped.rb +8 -0
- data/lib/y_petri/simulation/places/free.rb +8 -0
- data/lib/y_petri/simulation/places/types.rb +25 -0
- data/lib/y_petri/simulation/places.rb +41 -0
- data/lib/y_petri/simulation/recorder.rb +54 -0
- data/lib/y_petri/simulation/timed/recorder.rb +53 -0
- data/lib/y_petri/simulation/timed.rb +161 -261
- data/lib/y_petri/simulation/timeless/recorder.rb +25 -0
- data/lib/y_petri/simulation/timeless.rb +35 -0
- data/lib/y_petri/simulation/transition_representation/A.rb +58 -0
- data/lib/y_petri/simulation/transition_representation/S.rb +45 -0
- data/lib/y_petri/simulation/transition_representation/T.rb +80 -0
- data/lib/y_petri/simulation/transition_representation/TS.rb +46 -0
- data/lib/y_petri/simulation/transition_representation/Ts.rb +32 -0
- data/lib/y_petri/simulation/transition_representation/a.rb +30 -0
- data/lib/y_petri/simulation/transition_representation/s.rb +29 -0
- data/lib/y_petri/simulation/transition_representation/t.rb +37 -0
- data/lib/y_petri/simulation/transition_representation/tS.rb +38 -0
- data/lib/y_petri/simulation/transition_representation/ts.rb +32 -0
- data/lib/y_petri/simulation/transition_representation/types.rb +62 -0
- data/lib/y_petri/simulation/transition_representation.rb +79 -0
- data/lib/y_petri/simulation/transitions/A.rb +40 -0
- data/lib/y_petri/simulation/transitions/S.rb +24 -0
- data/lib/y_petri/simulation/transitions/T.rb +34 -0
- data/lib/y_petri/simulation/transitions/TS.rb +57 -0
- data/lib/y_petri/simulation/transitions/Ts.rb +60 -0
- data/lib/y_petri/simulation/transitions/a.rb +8 -0
- data/lib/y_petri/simulation/transitions/access.rb +186 -0
- data/lib/y_petri/simulation/transitions/s.rb +9 -0
- data/lib/y_petri/simulation/transitions/t.rb +22 -0
- data/lib/y_petri/simulation/transitions/tS.rb +55 -0
- data/lib/y_petri/simulation/transitions/ts.rb +58 -0
- data/lib/y_petri/simulation/transitions/types.rb +98 -0
- data/lib/y_petri/simulation/transitions.rb +21 -0
- data/lib/y_petri/simulation.rb +176 -781
- data/lib/y_petri/transition/assignment.rb +7 -5
- data/lib/y_petri/transition/construction.rb +119 -187
- data/lib/y_petri/transition/init.rb +311 -0
- data/lib/y_petri/transition/ordinary_timeless.rb +8 -6
- data/lib/y_petri/transition/timed.rb +11 -18
- data/lib/y_petri/transition.rb +104 -132
- data/lib/y_petri/version.rb +1 -1
- data/lib/y_petri/world/dependency.rb +40 -0
- data/lib/y_petri/world/petri_net_related.rb +61 -0
- data/lib/y_petri/{workspace/simulation_related_methods.rb → world/simulation_related.rb} +42 -49
- data/lib/y_petri/world.rb +27 -0
- data/lib/y_petri.rb +47 -99
- data/test/{manipulator_test.rb → agent_test.rb} +19 -17
- data/{lib/y_petri → test/examples}/demonstrator.rb +0 -0
- data/{lib/y_petri → test/examples}/demonstrator_2.rb +1 -0
- data/{lib/y_petri → test/examples}/demonstrator_3.rb +0 -0
- data/{lib/y_petri → test/examples}/demonstrator_4.rb +0 -0
- data/test/examples/example_2.rb +16 -0
- data/test/{manual_examples.rb → examples/manual_examples.rb} +0 -0
- data/test/net_test.rb +126 -121
- data/test/place_test.rb +1 -1
- data/test/sim_test +565 -0
- data/test/simulation_test.rb +338 -264
- data/test/transition_test.rb +77 -174
- data/test/world_mock.rb +12 -0
- data/test/{workspace_test.rb → world_test.rb} +19 -20
- data/test/y_petri_test.rb +4 -5
- metadata +101 -26
- data/lib/y_petri/dependency_injection.rb +0 -45
- data/lib/y_petri/manipulator/petri_net_related_methods.rb +0 -74
- data/lib/y_petri/manipulator.rb +0 -20
- data/lib/y_petri/net/selections.rb +0 -209
- data/lib/y_petri/simulation/collections.rb +0 -460
- data/lib/y_petri/workspace/parametrized_subclassing.rb +0 -22
- data/lib/y_petri/workspace/petri_net_related_methods.rb +0 -88
- data/lib/y_petri/workspace.rb +0 -16
- data/test/timed_simulation_test.rb +0 -153
data/test/transition_test.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#! /usr/bin/ruby
|
2
|
-
#
|
2
|
+
# encoding: utf-8
|
3
3
|
|
4
4
|
require 'minitest/spec'
|
5
5
|
require 'minitest/autorun'
|
@@ -36,220 +36,124 @@ describe ::YPetri::Transition do
|
|
36
36
|
# Note: ts transitions require a function, and thus are always functional
|
37
37
|
before do
|
38
38
|
@t1 = @ç.new codomain: [ @p1, @p3 ], domain: @p2, action: -> a { [ a, a ] }
|
39
|
-
|
40
|
-
@
|
41
|
-
# Only when the domain is unary, is the closure allowed to be timeless:
|
42
|
-
@t3 = @ç.new codomain: [ @p1, @p3 ], action: -> t { [ t, t ] }, timed: false, domain: [ @p2 ]
|
43
|
-
# With nullary action closure, timeless is implied, so this is allowed
|
44
|
-
@t4 = @ç.new action: -> { [ 0.5, 0.5 ] }, codomain: [ @p1, @p3 ]
|
45
|
-
# ... also for stoichiometric variety
|
46
|
-
@t5 = @ç.new action: -> { 0.5 }, codomain: [ @p1, @p3 ], s: [ 1, 1 ]
|
39
|
+
@t2 = @ç.new codomain: [ @p1, @p3 ] do |t| [ t, t ] end
|
40
|
+
@t3 = @ç.new action: -> { [ 0.5, 0.5 ] }, codomain: [ @p1, @p3 ]
|
47
41
|
end
|
48
42
|
|
49
43
|
it "should raise errors for bad parameters" do
|
50
|
-
#
|
51
|
-
-> { @ç.new
|
52
|
-
.must_raise ArgumentError
|
53
|
-
# saying that the transition is timeless points to a conflict:
|
54
|
-
-> { @ç.new codomain: [ @p1, @p3 ], action: -> t { [ t, t ] }, timeless: true }
|
44
|
+
# codomain omitted
|
45
|
+
-> { @ç.new domain: @p2, action: -> t { [ t, t ] } }
|
55
46
|
.must_raise ArgumentError
|
47
|
+
# mangled codomain
|
48
|
+
-> { @ç.new codomain: [ @p1, :a ], action: -> t { [ t, t ] } }
|
49
|
+
.must_raise TypeError
|
50
|
+
# domain omitted
|
51
|
+
-> { @ç.new codomain: [ @p1, :a ], action: -> t { [ t, t ] } }
|
52
|
+
.must_raise TypeError
|
53
|
+
# action closure arity greater than the domain
|
54
|
+
-> { @ç.new codomain: [ @p1, @p3 ], action: -> t { [ t, t ] }, domain: [] }
|
55
|
+
.must_raise TypeError
|
56
56
|
end
|
57
57
|
|
58
|
-
it "should
|
58
|
+
it "should work" do
|
59
|
+
@t1.type.must_equal :ts
|
59
60
|
@t1.domain.must_equal [@p2]
|
60
61
|
@t1.action_arcs.must_equal [@p1, @p3]
|
61
62
|
assert @t1.functional?
|
62
|
-
assert @t1.timeless?
|
63
|
-
assert @t2.
|
64
|
-
assert [@t3, @t4, @t5].all? { |t| t.timeless? }
|
65
|
-
assert @t2.rateless?
|
63
|
+
assert [@t1, @t2, @t3].all? { |t| t.timeless? }
|
64
|
+
assert [@t1, @t2, @t3].all? { |t| t.s? }
|
66
65
|
# Now let's flex them:
|
67
66
|
@t1.fire!
|
68
67
|
[@p1.m, @p3.m].must_equal [3, 5]
|
69
68
|
@t3.fire!
|
70
|
-
[@p1.m, @p3.m].must_equal [5,
|
71
|
-
@
|
72
|
-
[@p1.m, @p3.m].must_equal [
|
73
|
-
@t5.fire!
|
74
|
-
[@p1.m, @p3.m].must_equal [6, 8]
|
75
|
-
# now t2 for firing requires delta time
|
76
|
-
@t2.fire! 1
|
77
|
-
[@p1.m, @p3.m].must_equal [7, 9]
|
78
|
-
@t2.fire! 0.1
|
79
|
-
[@p1.m, @p3.m ].must_equal [7.1, 9.1]
|
80
|
-
# let's change @p2 marking
|
81
|
-
@p2.m = 0.1
|
82
|
-
@t1.fire!
|
83
|
-
assert_in_epsilon 7.2, @p1.marking, 1e-9
|
84
|
-
assert_in_epsilon 9.2, @p3.marking, 1e-9
|
85
|
-
# let's test #domain_marking, #codomain_marking, #zero_action
|
69
|
+
[@p1.m, @p3.m].must_equal [3.5, 5.5]
|
70
|
+
@t2.fire!
|
71
|
+
[@p1.m, @p3.m].must_equal [7.0, 9.0]
|
86
72
|
@t1.codomain_marking.must_equal [@p1.m, @p3.m]
|
87
73
|
@t1.domain_marking.must_equal [@p2.m]
|
88
74
|
@t1.zero_action.must_equal [0, 0]
|
89
75
|
end
|
90
76
|
end
|
91
77
|
|
92
|
-
describe "
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
describe "tS transitions (timeless stoichiometric)" do
|
97
|
-
describe "functionless tS transitions" do
|
98
|
-
# For functionless tS transitions, stoichiometric vector must be given,
|
99
|
-
# from which the action closure is then generated.
|
100
|
-
|
101
|
-
before do
|
102
|
-
# tS transition with only stoichiometric vector, as hash
|
103
|
-
@ftS1 = @ç.new stoichiometry: { @p1 => 1 }
|
104
|
-
# tS transition with only stoichiometric vector, as array + codomain
|
105
|
-
@ftS2 = @ç.new stoichiometry: 1, codomain: @p1
|
106
|
-
# :stoichiometry keyword is aliased as :s
|
107
|
-
@ftS3 = @ç.new s: 1, codomain: @p1
|
108
|
-
# :codomain is aliased as :action_arcs
|
109
|
-
@ftS4 = @ç.new s: 1, action_arcs: @p1
|
110
|
-
# square brackets (optional for size 1 vectors)
|
111
|
-
@ftS5 = @ç.new s: [ 1 ], downstream: [ @p1 ]
|
112
|
-
# another alias of :codomain is :downstream_places
|
113
|
-
@ftS6 = @ç.new s: [ 1 ], downstream_places: [ @p1 ]
|
114
|
-
# And now, collect all of the above:
|
115
|
-
@tt = @ftS1, @ftS2, @ftS3, @ftS4, @ftS5, @ftS6
|
116
|
-
end
|
117
|
-
|
118
|
-
it "should work" do
|
119
|
-
# ...should be the same, having a single action arc:
|
120
|
-
assert @tt.all? { |t| t.action_arcs == [@p1] }
|
121
|
-
# timeless:
|
122
|
-
assert @tt.all? { |t| t.timeless? }
|
123
|
-
# rateless:
|
124
|
-
assert @tt.all? { |t| t.rateless? }
|
125
|
-
assert @tt.all? { |t| not t.has_rate? }
|
126
|
-
# no assignment action
|
127
|
-
assert @tt.all? { |t| not t.assignment_action? }
|
128
|
-
# not considered functional
|
129
|
-
assert @tt.all? { |t| t.functionless? }
|
130
|
-
assert @tt.all? { |t| not t.functional? }
|
131
|
-
# and having nullary action closure
|
132
|
-
assert @tt.all? { |t| t.action_closure.arity == 0 }
|
133
|
-
# the transitions should be able to #fire!
|
134
|
-
@ftS1.fire!
|
135
|
-
# the difference is apparent: marking of place @p1 jumped to 2:
|
136
|
-
@p1.marking.must_equal 2
|
137
|
-
# but should not #fire (no exclamation mark) unless cocked
|
138
|
-
assert !@ftS1.cocked?
|
139
|
-
@ftS1.fire
|
140
|
-
@p1.marking.must_equal 2
|
141
|
-
# cock it
|
142
|
-
@ftS1.cock
|
143
|
-
assert @ftS1.cocked?
|
144
|
-
# uncock again, just to test cocking
|
145
|
-
@ftS1.uncock
|
146
|
-
assert @ftS1.uncocked?
|
147
|
-
@ftS1.cock
|
148
|
-
assert !@ftS1.uncocked?
|
149
|
-
@ftS1.fire
|
150
|
-
@p1.marking.must_equal 3
|
151
|
-
# enough playing, we'll reset @p1 marking
|
152
|
-
@p1.reset_marking
|
153
|
-
@p1.marking.must_equal 1
|
154
|
-
# #action
|
155
|
-
assert @tt.all? { |t| t.action == [1] }
|
156
|
-
# #zero_action
|
157
|
-
assert @tt.all? { |t| t.zero_action }
|
158
|
-
# #domain_marking
|
159
|
-
assert @tt.all? { |t| t.domain_marking == [] }
|
160
|
-
# #codomain_marking
|
161
|
-
assert @tt.all? { |t| t.codomain_marking == [@p1.m] }
|
162
|
-
# #enabled?
|
163
|
-
@p1.m.must_equal 1
|
164
|
-
@p1.guard.( 1 ).must_equal 1
|
165
|
-
@tt.each { |t| t.enabled?.must_equal true }
|
166
|
-
end
|
78
|
+
describe "tS transitions" do
|
79
|
+
before do
|
80
|
+
@t1 = @ç.new s: { @p5 => -1, @p1 => 1 }, action: proc { 1 }
|
81
|
+
@t2 = @ç.new s: { @p5 => -1, @p1 => 1 } # should be "functionless"
|
167
82
|
end
|
168
83
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
end
|
192
|
-
|
193
|
-
it "should init and perform" do
|
194
|
-
assert @tt.all? { |t| t.action_arcs == [ @p1 ] }
|
195
|
-
assert @tt.all? { |t| t.timeless? }
|
196
|
-
assert @tt.all? { |t| not t.has_rate? }
|
197
|
-
assert @tt.all? { |t| t.rateless? }
|
198
|
-
assert @tt.all? { |t| not t.assignment_action? }
|
199
|
-
assert @tt.all? { |t| not t.functionless? }
|
200
|
-
assert @tt.all? { |t| t.functional? }
|
201
|
-
# and having nullary action closure
|
202
|
-
assert @tt.all? { |t| t.action_closure.arity == 0 }
|
203
|
-
# the transitions should be able to #fire!
|
204
|
-
@FtS1.fire!
|
205
|
-
# no need for more testing here
|
206
|
-
end
|
84
|
+
it "should work" do
|
85
|
+
@t1.type.must_equal :tS
|
86
|
+
@t2.type.must_equal :tS
|
87
|
+
@t1.codomain.must_equal [@p5, @p1]
|
88
|
+
@t2.codomain.must_equal [@p5, @p1]
|
89
|
+
assert @t1.functional?
|
90
|
+
assert ! @t2.functional? # "functionless"
|
91
|
+
assert ! @t1.timed?
|
92
|
+
assert ! @t2.timed?
|
93
|
+
@t1.stoichiometry.must_equal [-1, 1]
|
94
|
+
@t2.stoichiometry.must_equal [-1, 1]
|
95
|
+
@t1.stoichio.must_equal( { @p5 => -1, @p1 => 1 } )
|
96
|
+
@t2.stoichio.must_equal( { @p5 => -1, @p1 => 1 } )
|
97
|
+
@t1.s.must_equal( { @p5.object_id => -1, @p1.object_id => 1 } )
|
98
|
+
@t2.s.must_equal( { @p5.object_id => -1, @p1.object_id => 1 } )
|
99
|
+
@t1.domain.must_equal [@p5] # inferred domain
|
100
|
+
@t2.domain.must_equal [] # domain is empty in functionless transitions!
|
101
|
+
[@p1.m, @p5.m].must_equal [1, 5]
|
102
|
+
@t1.fire!
|
103
|
+
[@p1.m, @p5.m].must_equal [2, 4]
|
104
|
+
@t2.fire!
|
105
|
+
[@p1.m, @p5.m].must_equal [3, 3]
|
207
106
|
end
|
208
107
|
end
|
209
108
|
|
210
|
-
describe "TSr transitions (timed rateless stoichiometric)" do
|
211
|
-
# Sr transitions have an action closure, require a function block, and thus
|
212
|
-
# are always functional. Their closure must take Δt as its first argument.
|
213
|
-
|
214
|
-
#LATER: To save time, I omit the tests of TSr transitions for now.
|
215
|
-
end
|
216
109
|
|
217
|
-
describe "
|
218
|
-
|
219
|
-
|
110
|
+
describe "Ts transitions" do
|
111
|
+
before do
|
112
|
+
@t1 = @ç.new domain: @p5, codomain: [@p5, @p1], rate: proc { [-1, 1] }
|
113
|
+
end
|
220
114
|
|
221
|
-
|
115
|
+
it "should work" do
|
116
|
+
@t1.type.must_equal :Ts
|
117
|
+
@t1.codomain.must_equal [@p5, @p1]
|
118
|
+
assert @t1.functional?
|
119
|
+
assert @t1.timed?
|
120
|
+
@t1.domain.must_equal [@p5]
|
121
|
+
[@p1.m, @p5.m].must_equal [1, 5]
|
122
|
+
@t1.rate_closure.arity.must_equal 0
|
123
|
+
@t1.fire! 0.5
|
124
|
+
[@p1.m, @p5.m].must_equal [1.5, 4.5]
|
125
|
+
end
|
222
126
|
end
|
223
127
|
|
224
|
-
describe "
|
128
|
+
describe "TS transitions (timed stoichiometric)" do
|
225
129
|
before do
|
226
130
|
# This should give standard mass action by magic:
|
227
|
-
@
|
131
|
+
@TS1 = @ç.new s: { @p1 => -1, @p2 => -1, @p4 => 1 }, rate: 0.1
|
228
132
|
# While this has custom closure:
|
229
|
-
@
|
133
|
+
@TS2 = @ç.new s: { @p1 => -1, @p3 => 1 }, rate: -> a { a * 0.5 }
|
230
134
|
# While this one even has domain explicitly specified:
|
231
|
-
@
|
135
|
+
@TS3 = @ç.new s: { @p1 => -1, @p2 => -1, @p4 => 1 },
|
232
136
|
upstream_arcs: @p3, rate: -> a { a * 0.5 }
|
233
137
|
end
|
234
138
|
|
235
139
|
it "should init and work" do
|
236
|
-
@
|
237
|
-
@
|
238
|
-
@
|
239
|
-
@
|
240
|
-
@
|
241
|
-
@
|
242
|
-
@
|
140
|
+
@TS1.timed?.must_equal true
|
141
|
+
@TS1.upstream_arcs.must_equal [@p1, @p2]
|
142
|
+
@TS1.action_arcs.must_equal [@p1, @p2, @p4]
|
143
|
+
@TS2.domain.must_equal [@p1]
|
144
|
+
@TS2.action_arcs.must_equal [@p1, @p3]
|
145
|
+
@TS3.domain.must_equal [@p3]
|
146
|
+
@TS3.action_arcs.must_equal [@p1, @p2, @p4]
|
243
147
|
# and flex them
|
244
|
-
@
|
148
|
+
@TS1.fire! 1.0
|
245
149
|
[@p1, @p2, @p4].map( &:marking ).must_equal [0.8, 1.8, 4.2]
|
246
|
-
@
|
150
|
+
@TS2.fire! 1.0
|
247
151
|
[@p1, @p3].map( &:marking ).must_equal [0.4, 3.4]
|
248
152
|
# the action t3 cannot fire with delta time 1.0
|
249
|
-
-> { @
|
153
|
+
-> { @TS3.fire! 1.0 }.must_raise YPetri::GuardError
|
250
154
|
[@p1, @p2, @p3, @p4].map( &:marking ).must_equal [0.4, 1.8, 3.4, 4.2]
|
251
155
|
# but it can fire with eg. delta time 0.1
|
252
|
-
@
|
156
|
+
@TS3.fire! 0.1
|
253
157
|
assert_in_epsilon 0.23, @p1.marking, 1e-15
|
254
158
|
assert_in_epsilon 1.63, @p2.marking, 1e-15
|
255
159
|
assert_in_epsilon 3.4, @p3.marking, 1e-15
|
@@ -265,7 +169,6 @@ end
|
|
265
169
|
#
|
266
170
|
describe "upstream and downstream reference mτs of places and transitions" do
|
267
171
|
before do
|
268
|
-
# skip "to speed up testing"
|
269
172
|
@tç = tç = Class.new YPetri::Transition
|
270
173
|
@pç = pç = Class.new YPetri::Place
|
271
174
|
[ tç, pç ].each { |ç|
|
data/test/world_mock.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
WORLD_MOCK = -> do
|
2
|
+
w = YPetri::World.new
|
3
|
+
[ w.Place, w.Transition, w.Net ].tap do |p, t, _|
|
4
|
+
def p.nw( n, *args, &block )
|
5
|
+
new( *args ).tap { |i| i.name = n }
|
6
|
+
end
|
7
|
+
|
8
|
+
def t.nw( n, *args, &block )
|
9
|
+
new( *args ).tap { |i| i.name = n }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#! /usr/bin/ruby
|
2
|
-
#
|
2
|
+
# encoding: utf-8
|
3
3
|
|
4
4
|
require 'minitest/spec'
|
5
5
|
require 'minitest/autorun'
|
@@ -9,34 +9,32 @@ require_relative '../lib/y_petri' # tested component itself
|
|
9
9
|
|
10
10
|
include Pyper if require 'pyper'
|
11
11
|
|
12
|
-
describe YPetri::
|
12
|
+
describe YPetri::World do
|
13
13
|
before do
|
14
|
-
@w = YPetri::
|
15
|
-
a = @w.Place.
|
16
|
-
b = @w.Place.
|
17
|
-
c = @w.Place.
|
18
|
-
t1 = @w.Transition.
|
14
|
+
@w = YPetri::World.new
|
15
|
+
a = @w.Place.avid( default_marking: 1.0, name: "AA" )
|
16
|
+
b = @w.Place.avid( default_marking: 2.0, name: "BB" )
|
17
|
+
c = @w.Place.avid( ɴ: "CC", default_marking: 3.0 )
|
18
|
+
t1 = @w.Transition.avid s: { a => -1, b => -1, c => 1 },
|
19
19
|
rate: 0.1,
|
20
20
|
ɴ: "AA_BB_assembly"
|
21
|
-
t2 = @w.Transition.
|
21
|
+
t2 = @w.Transition.avid ɴ: "AA_appearing",
|
22
22
|
codomain: a,
|
23
23
|
rate: -> { 0.1 },
|
24
24
|
stoichiometry: 1
|
25
25
|
@pp, @tt = [a, b, c], [t1, t2]
|
26
26
|
@f_name = "test_output.csv"
|
27
|
-
@w.set_imc @pp
|
27
|
+
@w.set_imc @pp >> @pp.map( &:default_marking )
|
28
28
|
@w.set_ssc step: 0.1, sampling: 10, time: 0..50
|
29
29
|
@w.set_cc( {} )
|
30
|
-
@sim = @w.
|
30
|
+
@sim = @w.new_simulation
|
31
31
|
File.delete @f_name rescue nil
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should present places, transitions, nets, simulations" do
|
35
35
|
assert_kind_of YPetri::Net, @w.Net::Top
|
36
36
|
assert_equal @pp[0], @w.place( "AA" )
|
37
|
-
assert_equal :AA, @w.pl( @pp[0] )
|
38
37
|
assert_equal @tt[0], @w.transition( "AA_BB_assembly" )
|
39
|
-
assert_equal :AA_appearing, @w.tr( @tt[1] )
|
40
38
|
assert_equal @pp, @w.places
|
41
39
|
assert_equal @tt, @w.transitions
|
42
40
|
assert_equal 1, @w.nets.size
|
@@ -48,25 +46,26 @@ describe YPetri::Workspace do
|
|
48
46
|
assert_equal [:Base], @w.clamp_collections.keys
|
49
47
|
assert_equal [:Base], @w.initial_marking_collections.keys
|
50
48
|
assert_equal [:Base], @w.simulation_settings_collections.keys
|
51
|
-
assert_equal [:AA, :BB, :CC], @w.
|
52
|
-
assert_equal [:AA_BB_assembly, :AA_appearing], @w.
|
53
|
-
assert_equal [:Top], @w.
|
49
|
+
assert_equal [:AA, :BB, :CC], @w.places.names
|
50
|
+
assert_equal [:AA_BB_assembly, :AA_appearing], @w.transitions.names
|
51
|
+
assert_equal [:Top], @w.nets.names
|
54
52
|
end
|
55
53
|
|
56
54
|
it "should simulate" do
|
57
55
|
assert_equal 1, @w.simulations.size
|
58
56
|
assert_kind_of( YPetri::Simulation, @w.simulation )
|
59
|
-
assert_equal 2, @w.simulation.
|
57
|
+
assert_equal 2, @w.simulation.TS_tt.size
|
60
58
|
@tt[0].domain.must_equal [ @pp[0], @pp[1] ]
|
61
59
|
@tt[1].domain.must_equal []
|
62
|
-
|
60
|
+
assert @w.simulation.timed?
|
61
|
+
assert_equal [0.2, 0.1], @w.simulation.flux_vector.column_to_a
|
63
62
|
@w.simulation.step!
|
64
63
|
@w.simulation.run!
|
65
|
-
|
66
|
-
|
64
|
+
rec_csv = @w.simulation.recording.to_csv
|
65
|
+
expected_rec_csv =
|
67
66
|
"0.0,1.0,2.0,3.0\n" +
|
68
67
|
"10.0,0.86102,0.86102,4.13898\n" +
|
69
68
|
"20.0,1.29984,0.29984,4.70016\n"
|
70
|
-
|
69
|
+
rec_csv.to_s[0, expected_rec_csv.size].must_equal expected_rec_csv
|
71
70
|
end
|
72
71
|
end
|
data/test/y_petri_test.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#! /usr/bin/ruby
|
2
|
-
#
|
2
|
+
# encoding: utf-8
|
3
3
|
|
4
4
|
require 'minitest/spec'
|
5
5
|
require 'minitest/autorun'
|
@@ -11,7 +11,7 @@ require_relative '../lib/y_petri' # tested component itself
|
|
11
11
|
#
|
12
12
|
describe YPetri do
|
13
13
|
it "should have basic classes" do
|
14
|
-
[ :Place, :Transition, :Net, :Simulation, :
|
14
|
+
[ :Place, :Transition, :Net, :Simulation, :World, :Agent ]
|
15
15
|
.each { |ß| YPetri.const_get( ß ).must_be_kind_of Module }
|
16
16
|
end
|
17
17
|
end
|
@@ -22,6 +22,5 @@ require_relative 'place_test'
|
|
22
22
|
require_relative 'transition_test'
|
23
23
|
require_relative 'net_test'
|
24
24
|
require_relative 'simulation_test'
|
25
|
-
require_relative '
|
26
|
-
require_relative '
|
27
|
-
require_relative 'manipulator_test'
|
25
|
+
require_relative 'world_test'
|
26
|
+
require_relative 'agent_test'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: y_petri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- boris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: y_support
|
@@ -65,51 +65,120 @@ files:
|
|
65
65
|
- README.md
|
66
66
|
- Rakefile
|
67
67
|
- lib/y_petri.rb
|
68
|
-
- lib/y_petri/
|
69
|
-
- lib/y_petri/
|
70
|
-
- lib/y_petri/
|
71
|
-
- lib/y_petri/
|
72
|
-
- lib/y_petri/
|
73
|
-
- lib/y_petri/
|
74
|
-
- lib/y_petri/
|
75
|
-
- lib/y_petri/
|
76
|
-
- lib/y_petri/
|
77
|
-
- lib/y_petri/
|
68
|
+
- lib/y_petri/agent.rb
|
69
|
+
- lib/y_petri/agent/hash_key_pointer.rb
|
70
|
+
- lib/y_petri/agent/petri_net_related.rb
|
71
|
+
- lib/y_petri/agent/selection.rb
|
72
|
+
- lib/y_petri/agent/simulation_related.rb
|
73
|
+
- lib/y_petri/core.rb
|
74
|
+
- lib/y_petri/core/timed.rb
|
75
|
+
- lib/y_petri/core/timed/euler.rb
|
76
|
+
- lib/y_petri/core/timed/pseudo_euler.rb
|
77
|
+
- lib/y_petri/core/timed/quasi_euler.rb
|
78
|
+
- lib/y_petri/core/timeless.rb
|
79
|
+
- lib/y_petri/core/timeless/pseudo_euler.rb
|
80
|
+
- lib/y_petri/dsl.rb
|
81
|
+
- lib/y_petri/fixed_assets.rb
|
78
82
|
- lib/y_petri/net.rb
|
79
|
-
- lib/y_petri/net/
|
83
|
+
- lib/y_petri/net/element_access.rb
|
84
|
+
- lib/y_petri/net/state.rb
|
85
|
+
- lib/y_petri/net/state/feature.rb
|
86
|
+
- lib/y_petri/net/state/feature/delta.rb
|
87
|
+
- lib/y_petri/net/state/feature/firing.rb
|
88
|
+
- lib/y_petri/net/state/feature/flux.rb
|
89
|
+
- lib/y_petri/net/state/feature/gradient.rb
|
90
|
+
- lib/y_petri/net/state/feature/marking.rb
|
91
|
+
- lib/y_petri/net/state/features.rb
|
92
|
+
- lib/y_petri/net/state/features/dataset.rb
|
93
|
+
- lib/y_petri/net/state/features/record.rb
|
94
|
+
- lib/y_petri/net/timed.rb
|
80
95
|
- lib/y_petri/net/visualization.rb
|
81
96
|
- lib/y_petri/place.rb
|
82
97
|
- lib/y_petri/place/arcs.rb
|
83
98
|
- lib/y_petri/place/guard.rb
|
84
99
|
- lib/y_petri/simulation.rb
|
85
|
-
- lib/y_petri/simulation/
|
100
|
+
- lib/y_petri/simulation/dependency.rb
|
101
|
+
- lib/y_petri/simulation/element_representation.rb
|
102
|
+
- lib/y_petri/simulation/elements.rb
|
103
|
+
- lib/y_petri/simulation/elements/access.rb
|
104
|
+
- lib/y_petri/simulation/feature_set.rb
|
105
|
+
- lib/y_petri/simulation/initial_marking.rb
|
106
|
+
- lib/y_petri/simulation/initial_marking/access.rb
|
107
|
+
- lib/y_petri/simulation/marking_clamps.rb
|
108
|
+
- lib/y_petri/simulation/marking_clamps/access.rb
|
109
|
+
- lib/y_petri/simulation/marking_vector.rb
|
110
|
+
- lib/y_petri/simulation/marking_vector/access.rb
|
111
|
+
- lib/y_petri/simulation/matrix.rb
|
112
|
+
- lib/y_petri/simulation/place_mapping.rb
|
113
|
+
- lib/y_petri/simulation/place_representation.rb
|
114
|
+
- lib/y_petri/simulation/places.rb
|
115
|
+
- lib/y_petri/simulation/places/access.rb
|
116
|
+
- lib/y_petri/simulation/places/clamped.rb
|
117
|
+
- lib/y_petri/simulation/places/free.rb
|
118
|
+
- lib/y_petri/simulation/places/types.rb
|
119
|
+
- lib/y_petri/simulation/recorder.rb
|
86
120
|
- lib/y_petri/simulation/timed.rb
|
121
|
+
- lib/y_petri/simulation/timed/recorder.rb
|
122
|
+
- lib/y_petri/simulation/timeless.rb
|
123
|
+
- lib/y_petri/simulation/timeless/recorder.rb
|
124
|
+
- lib/y_petri/simulation/transition_representation.rb
|
125
|
+
- lib/y_petri/simulation/transition_representation/A.rb
|
126
|
+
- lib/y_petri/simulation/transition_representation/S.rb
|
127
|
+
- lib/y_petri/simulation/transition_representation/T.rb
|
128
|
+
- lib/y_petri/simulation/transition_representation/TS.rb
|
129
|
+
- lib/y_petri/simulation/transition_representation/Ts.rb
|
130
|
+
- lib/y_petri/simulation/transition_representation/a.rb
|
131
|
+
- lib/y_petri/simulation/transition_representation/s.rb
|
132
|
+
- lib/y_petri/simulation/transition_representation/t.rb
|
133
|
+
- lib/y_petri/simulation/transition_representation/tS.rb
|
134
|
+
- lib/y_petri/simulation/transition_representation/ts.rb
|
135
|
+
- lib/y_petri/simulation/transition_representation/types.rb
|
136
|
+
- lib/y_petri/simulation/transitions.rb
|
137
|
+
- lib/y_petri/simulation/transitions/A.rb
|
138
|
+
- lib/y_petri/simulation/transitions/S.rb
|
139
|
+
- lib/y_petri/simulation/transitions/T.rb
|
140
|
+
- lib/y_petri/simulation/transitions/TS.rb
|
141
|
+
- lib/y_petri/simulation/transitions/Ts.rb
|
142
|
+
- lib/y_petri/simulation/transitions/a.rb
|
143
|
+
- lib/y_petri/simulation/transitions/access.rb
|
144
|
+
- lib/y_petri/simulation/transitions/s.rb
|
145
|
+
- lib/y_petri/simulation/transitions/t.rb
|
146
|
+
- lib/y_petri/simulation/transitions/tS.rb
|
147
|
+
- lib/y_petri/simulation/transitions/ts.rb
|
148
|
+
- lib/y_petri/simulation/transitions/types.rb
|
87
149
|
- lib/y_petri/transition.rb
|
88
150
|
- lib/y_petri/transition/arcs.rb
|
89
151
|
- lib/y_petri/transition/assignment.rb
|
90
152
|
- lib/y_petri/transition/cocking.rb
|
91
153
|
- lib/y_petri/transition/construction.rb
|
154
|
+
- lib/y_petri/transition/init.rb
|
92
155
|
- lib/y_petri/transition/ordinary_timeless.rb
|
93
156
|
- lib/y_petri/transition/timed.rb
|
94
157
|
- lib/y_petri/version.rb
|
95
|
-
- lib/y_petri/
|
96
|
-
- lib/y_petri/
|
97
|
-
- lib/y_petri/
|
98
|
-
- lib/y_petri/
|
158
|
+
- lib/y_petri/world.rb
|
159
|
+
- lib/y_petri/world/dependency.rb
|
160
|
+
- lib/y_petri/world/petri_net_related.rb
|
161
|
+
- lib/y_petri/world/simulation_related.rb
|
99
162
|
- test/acceptance/basic_usage_test.rb
|
100
163
|
- test/acceptance/simulation_test.rb
|
101
164
|
- test/acceptance/simulation_with_physical_units_test.rb
|
102
165
|
- test/acceptance/token_game_test.rb
|
103
166
|
- test/acceptance/visualization_test.rb
|
104
167
|
- test/acceptance_tests.rb
|
105
|
-
- test/
|
106
|
-
- test/
|
168
|
+
- test/agent_test.rb
|
169
|
+
- test/examples/demonstrator.rb
|
170
|
+
- test/examples/demonstrator_2.rb
|
171
|
+
- test/examples/demonstrator_3.rb
|
172
|
+
- test/examples/demonstrator_4.rb
|
173
|
+
- test/examples/example_2.rb
|
174
|
+
- test/examples/manual_examples.rb
|
107
175
|
- test/net_test.rb
|
108
176
|
- test/place_test.rb
|
177
|
+
- test/sim_test
|
109
178
|
- test/simulation_test.rb
|
110
|
-
- test/timed_simulation_test.rb
|
111
179
|
- test/transition_test.rb
|
112
|
-
- test/
|
180
|
+
- test/world_mock.rb
|
181
|
+
- test/world_test.rb
|
113
182
|
- test/y_petri_test.rb
|
114
183
|
- y_petri.gemspec
|
115
184
|
homepage: ''
|
@@ -142,12 +211,18 @@ test_files:
|
|
142
211
|
- test/acceptance/token_game_test.rb
|
143
212
|
- test/acceptance/visualization_test.rb
|
144
213
|
- test/acceptance_tests.rb
|
145
|
-
- test/
|
146
|
-
- test/
|
214
|
+
- test/agent_test.rb
|
215
|
+
- test/examples/demonstrator.rb
|
216
|
+
- test/examples/demonstrator_2.rb
|
217
|
+
- test/examples/demonstrator_3.rb
|
218
|
+
- test/examples/demonstrator_4.rb
|
219
|
+
- test/examples/example_2.rb
|
220
|
+
- test/examples/manual_examples.rb
|
147
221
|
- test/net_test.rb
|
148
222
|
- test/place_test.rb
|
223
|
+
- test/sim_test
|
149
224
|
- test/simulation_test.rb
|
150
|
-
- test/timed_simulation_test.rb
|
151
225
|
- test/transition_test.rb
|
152
|
-
- test/
|
226
|
+
- test/world_mock.rb
|
227
|
+
- test/world_test.rb
|
153
228
|
- test/y_petri_test.rb
|
@@ -1,45 +0,0 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
|
3
|
-
# Provides basic skeleton for dependency injection for the triples of the
|
4
|
-
# parametrized subclasses of Place, Transition and Net in different workspaces.
|
5
|
-
#
|
6
|
-
module YPetri::DependencyInjection
|
7
|
-
|
8
|
-
private
|
9
|
-
|
10
|
-
# Place class -- to be overriden in subclasses for dependency injection.
|
11
|
-
#
|
12
|
-
def Place
|
13
|
-
YPetri::Place
|
14
|
-
end
|
15
|
-
|
16
|
-
# Transition class -- to be overriden in subclasses for dependency injection.
|
17
|
-
#
|
18
|
-
def Transition
|
19
|
-
YPetri::Transition
|
20
|
-
end
|
21
|
-
|
22
|
-
# Net class -- to be overriden in subclasses for dependency injection
|
23
|
-
#
|
24
|
-
def Net
|
25
|
-
YPetri::Net
|
26
|
-
end
|
27
|
-
|
28
|
-
# Place instance identification.
|
29
|
-
#
|
30
|
-
def place id
|
31
|
-
Place().instance( id )
|
32
|
-
end
|
33
|
-
|
34
|
-
# Transition instance identification.
|
35
|
-
#
|
36
|
-
def transition id
|
37
|
-
Transition().instance( id )
|
38
|
-
end
|
39
|
-
|
40
|
-
# Net instance identification.
|
41
|
-
#
|
42
|
-
def net id
|
43
|
-
Net().instance( id )
|
44
|
-
end
|
45
|
-
end # module YPetri::DependencyInjection
|