y_petri 2.0.15 → 2.1.3
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,153 +0,0 @@
|
|
1
|
-
#! /usr/bin/ruby
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
|
4
|
-
require 'minitest/spec'
|
5
|
-
require 'minitest/autorun'
|
6
|
-
require_relative '../lib/y_petri' # tested component itself
|
7
|
-
# require 'y_petri'
|
8
|
-
# require 'sy'
|
9
|
-
|
10
|
-
include Pyper if require 'pyper'
|
11
|
-
|
12
|
-
# **************************************************************************
|
13
|
-
# Test of TimedSimulation class.
|
14
|
-
# **************************************************************************
|
15
|
-
#
|
16
|
-
describe YPetri::Simulation::Timed do
|
17
|
-
before do
|
18
|
-
# skip "to speed up testing"
|
19
|
-
@a = YPetri::Place.new default_marking: 1.0
|
20
|
-
@b = YPetri::Place.new default_marking: 2.0
|
21
|
-
@c = YPetri::Place.new default_marking: 3.0
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "timed assembly a + b >> c" do
|
25
|
-
before do
|
26
|
-
@t1 = YPetri::Transition.new s: { @a => -1, @b => -1, @c => 1 }, rate: 0.1
|
27
|
-
@net = YPetri::Net.new << @a << @b << @c << @t1
|
28
|
-
@im_collection = [@a, @b, @c].τBmχHτ &:default_marking
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "simulation with step size 1" do
|
32
|
-
before do
|
33
|
-
@sim = YPetri::Simulation.new net: @net,
|
34
|
-
initial_marking: @im_collection,
|
35
|
-
step: 1,
|
36
|
-
sampling: 10,
|
37
|
-
time: 0..100
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should #step! with expected results" do
|
41
|
-
m = @sim.step!.marking
|
42
|
-
assert_in_delta 0.8, m[0]
|
43
|
-
assert_in_delta 1.8, m[1]
|
44
|
-
assert_in_delta 3.2, m[2]
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should behave" do
|
48
|
-
expect = Matrix.column_vector [-0.02, -0.02, 0.02]
|
49
|
-
( expect - @sim.ΔE( 0.1 ) ).column( 0 ).norm.must_be_within_delta 0
|
50
|
-
@sim.Euler_step! 0.1
|
51
|
-
expect = Matrix.column_vector [0.98, 1.98, 3.02]
|
52
|
-
( expect - @sim.marking_vector ).column( 0 ).norm.must_be_within_delta 0
|
53
|
-
@sim.method.must_equal :pseudo_Euler
|
54
|
-
@sim.send :reset!
|
55
|
-
@sim.step! 0.1
|
56
|
-
expect = Matrix.column_vector [0.98, 1.98, 3.02]
|
57
|
-
( expect - @sim.marking_vector ).column( 0 ).norm.must_be_within_delta 0
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "simulation with step size 0.1" do
|
62
|
-
before do
|
63
|
-
@sim = YPetri::Simulation.new net: @net,
|
64
|
-
initial_marking: @im_collection,
|
65
|
-
step: 0.1,
|
66
|
-
sampling: 10,
|
67
|
-
time: 0..100
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should behave" do
|
71
|
-
m = @sim.step!.marking
|
72
|
-
assert_equal 10, @sim.sampling_period
|
73
|
-
assert_in_delta 0.98, m[ 0 ], 1e-9
|
74
|
-
assert_in_delta 1.98, m[ 1 ], 1e-9
|
75
|
-
assert_in_delta 3.02, m[ 2 ], 1e-9
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should behave" do
|
79
|
-
@sim.run_until 31
|
80
|
-
expected_recording = {
|
81
|
-
0 => [ 1, 2, 3 ],
|
82
|
-
10 => [ 0.22265, 1.22265, 3.77735 ],
|
83
|
-
20 => [ 0.07131, 1.07131, 3.92869 ],
|
84
|
-
30 => [ 0.02496, 1.02496, 3.97503 ]
|
85
|
-
}
|
86
|
-
assert_equal expected_recording.keys, @sim.recording.keys
|
87
|
-
assert_in_delta 0, expected_recording.values.zip( @sim.recording.values )
|
88
|
-
.map{ |expected, actual| ( Vector[ *expected ] -
|
89
|
-
Vector[ *actual ] ).norm }.reduce( :+ ), 1e-4
|
90
|
-
expected_recording_string =
|
91
|
-
"0.0,1.0,2.0,3.0\n" +
|
92
|
-
"10.0,0.22265,1.22265,3.77735\n" +
|
93
|
-
"20.0,0.07131,1.07131,3.92869\n" +
|
94
|
-
"30.0,0.02496,1.02496,3.97504\n"
|
95
|
-
assert_equal expected_recording_string, @sim.recording_csv_string
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
describe "timed 'isomerization' with given as λ" do
|
101
|
-
before do
|
102
|
-
@t2 = YPetri::Transition.new s: { @a => -1, @c => 1 },
|
103
|
-
rate_closure: -> a { a * 0.5 }
|
104
|
-
@net = YPetri::Net.new << @a << @b << @c << @t2
|
105
|
-
end
|
106
|
-
|
107
|
-
describe "behavior of #step" do
|
108
|
-
before do
|
109
|
-
@sim = YPetri::Simulation.new net: @net,
|
110
|
-
initial_marking: [ @a, @b, @c ].τBᴍHτ( &:default_marking ),
|
111
|
-
step: 1,
|
112
|
-
sampling: 10
|
113
|
-
end
|
114
|
-
|
115
|
-
it "should have expected stoichiometry matrix" do
|
116
|
-
@sim.S.must_equal Matrix[ [-1, 0, 1] ].t
|
117
|
-
m = @sim.step!.marking
|
118
|
-
m[ 0 ].must_be_within_epsilon( 0.5, 1e-6 )
|
119
|
-
m[ 1 ].must_equal 2
|
120
|
-
m[ 2 ].must_be_within_delta( 3.5, 1e-9 )
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe "timed controlled isomerization" do
|
126
|
-
before do
|
127
|
-
@t3 = YPetri::Transition.new s: { @a => -1, @c => 1 },
|
128
|
-
domain: @b,
|
129
|
-
rate: -> a { a * 0.5 }
|
130
|
-
@net = YPetri::Net.new << @a << @b << @c << @t3
|
131
|
-
@sim = YPetri::Simulation.new net: @net,
|
132
|
-
initial_marking: { @a => 1, @b => 0.6, @c => 3 },
|
133
|
-
step: 1,
|
134
|
-
sampling: 10,
|
135
|
-
time: 0..2
|
136
|
-
end
|
137
|
-
|
138
|
-
it "should exhibit correct behavior of #step" do
|
139
|
-
@sim.marking.must_equal [1.0, 0.6, 3.0]
|
140
|
-
@t3.stoichiometric?.must_equal true
|
141
|
-
@t3.timed?.must_equal true
|
142
|
-
@t3.has_rate?.must_equal true
|
143
|
-
@sim.gradient.must_equal Matrix.cv [-0.3, 0.0, 0.3]
|
144
|
-
@sim.Δ_Euler.must_equal Matrix.cv [-0.3, 0.0, 0.3]
|
145
|
-
@sim.step!
|
146
|
-
@sim.marking_vector.must_equal Matrix.cv [0.7, 0.6, 3.3]
|
147
|
-
@sim.euler_step!
|
148
|
-
@sim.run!
|
149
|
-
@sim.marking_vector.map( &[:round, 5] )
|
150
|
-
.must_equal Matrix.cv [0.4, 0.6, 3.6]
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|