y_petri 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/y_petri/manipulator/hash_key_pointer.rb +38 -0
- data/lib/y_petri/manipulator/petri_net_related_methods.rb +55 -0
- data/lib/y_petri/manipulator/selection.rb +11 -0
- data/lib/y_petri/manipulator/simulation_related_methods.rb +361 -0
- data/lib/y_petri/manipulator.rb +9 -587
- data/lib/y_petri/net.rb +65 -106
- data/lib/y_petri/simulation.rb +28 -9
- data/lib/y_petri/timed_simulation.rb +10 -3
- data/lib/y_petri/transition.rb +13 -28
- data/lib/y_petri/version.rb +2 -1
- data/lib/y_petri/workspace/petri_net_related_methods.rb +88 -0
- data/lib/y_petri/workspace/{instance_methods.rb → simulation_related_methods.rb} +7 -80
- data/lib/y_petri/workspace.rb +8 -8
- data/lib/y_petri.rb +29 -58
- data/test/y_petri_test.rb +38 -43
- metadata +9 -6
- data/test/y_petri_graph.png +0 -0
data/lib/y_petri.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
|
3
1
|
require 'gnuplot'
|
4
2
|
require 'csv'
|
5
3
|
require 'graphviz'
|
@@ -12,8 +10,8 @@ require 'y_support/typing'
|
|
12
10
|
require 'y_support/core_ext/hash'
|
13
11
|
require 'y_support/core_ext/array'
|
14
12
|
require 'y_support/stdlib_ext/matrix'
|
15
|
-
|
16
13
|
require 'y_support/abstract_algebra'
|
14
|
+
require 'y_support/kde'
|
17
15
|
|
18
16
|
require 'active_support/core_ext/module/delegation'
|
19
17
|
require 'active_support/core_ext/array/extract_options'
|
@@ -46,8 +44,6 @@ require_relative 'y_petri/manipulator'
|
|
46
44
|
# Float (continuous) - the decision should be on the simulator.
|
47
45
|
#
|
48
46
|
module YPetri
|
49
|
-
DEBUG = false
|
50
|
-
|
51
47
|
DEFAULT_SIMULATION_SETTINGS = lambda do
|
52
48
|
{ step_size: 0.02,
|
53
49
|
sampling_period: 2,
|
@@ -66,68 +62,44 @@ module YPetri
|
|
66
62
|
}
|
67
63
|
end
|
68
64
|
|
69
|
-
delegate( :workspace,
|
70
|
-
|
71
|
-
|
65
|
+
delegate( :workspace, to: :y_petri_manipulator )
|
66
|
+
|
67
|
+
# Petri net-related methods.
|
68
|
+
delegate( :Place, :Transition, :Net,
|
69
|
+
:place, :transition, :pl, :tr,
|
72
70
|
:places, :transitions, :nets,
|
73
|
-
:simulations,
|
74
71
|
:pp, :tt, :nn,
|
72
|
+
:net_point,
|
73
|
+
:net_selection,
|
74
|
+
:net, :ne,
|
75
|
+
:net_point_reset,
|
76
|
+
:net_point_set,
|
77
|
+
to: :y_petri_manipulator )
|
78
|
+
|
79
|
+
# Simulation-related methods.
|
80
|
+
delegate( :simulation_point, :ssc_point, :cc_point, :imc_point,
|
81
|
+
:simulation_selection, :ssc_selection,
|
82
|
+
:cc_selection, :imc_selection,
|
83
|
+
:simulations,
|
75
84
|
:clamp_collections,
|
76
|
-
:
|
85
|
+
:initial_marking_collections,
|
77
86
|
:simulation_settings_collections,
|
87
|
+
:clamp_collection_names, :cc_names,
|
88
|
+
:initial_marking_collection_names, :imc_names,
|
89
|
+
:simulation_settings_collection_names, :ssc_names,
|
90
|
+
:set_clamp_collection, :set_cc,
|
91
|
+
:set_initial_marking_collection, :set_imc,
|
92
|
+
:set_simulation_settings_collection, :set_ssc,
|
93
|
+
:new_timed_simulation,
|
78
94
|
:clamp_cc, :initial_marking_cc, :simulation_settings_cc,
|
79
|
-
:Place,
|
80
|
-
:Transition,
|
81
|
-
:Net,
|
82
|
-
:net_point_reset,
|
83
|
-
:net_point_to, :net→,
|
84
|
-
:net,
|
85
|
-
:simulation_point_reset,
|
86
|
-
:simulation_point_to,
|
87
|
-
:simulation,
|
88
95
|
:simulation_point_position,
|
89
|
-
:
|
90
|
-
:cc_point_to, :cc→,
|
96
|
+
:simulation,
|
91
97
|
:clamp_collection, :cc,
|
92
|
-
:cc_point_position,
|
93
|
-
:imc_point_reset,
|
94
|
-
:imc_point_to, :imc→,
|
95
98
|
:initial_marking_collection, :imc,
|
96
|
-
:imc_point_position,
|
97
|
-
:ssc_point_reset,
|
98
|
-
:ssc_point_to, :ssc→,
|
99
99
|
:simulation_settings_collection, :ssc,
|
100
|
-
:ssc_point_position,
|
101
|
-
:net_selection,
|
102
|
-
:simulation_selection,
|
103
|
-
:ssc_selection,
|
104
|
-
:cc_selection,
|
105
|
-
:imc_selection,
|
106
|
-
:net_selection_clear,
|
107
|
-
:net_select!,
|
108
|
-
:net_select,
|
109
|
-
:net_unselect,
|
110
|
-
:simulation_selection_clear,
|
111
|
-
:simulation_select!,
|
112
|
-
:simulation_select,
|
113
|
-
:simulation_unselect,
|
114
|
-
:cc_selection_clear,
|
115
|
-
:cc_select!,
|
116
|
-
:cc_select,
|
117
|
-
:cc_unselect,
|
118
|
-
:imc_selection_clear,
|
119
|
-
:imc_select!,
|
120
|
-
:imc_select,
|
121
|
-
:imc_unselect,
|
122
|
-
:ssc_selection_clear,
|
123
|
-
:ssc_select!,
|
124
|
-
:ssc_select,
|
125
|
-
:ssc_unselect,
|
126
100
|
:clamp,
|
127
|
-
:initial_marking,
|
128
|
-
:set_step, :
|
129
|
-
:set_time, :set_target_time,
|
130
|
-
:set_sampling,
|
101
|
+
:initial_marking,
|
102
|
+
:set_step, :set_time, :set_sampling,
|
131
103
|
:set_simulation_method,
|
132
104
|
:new_timed_simulation,
|
133
105
|
:run!,
|
@@ -136,6 +108,5 @@ module YPetri
|
|
136
108
|
:plot_selected,
|
137
109
|
:plot_state,
|
138
110
|
:plot_flux,
|
139
|
-
:plot_all,
|
140
111
|
to: :y_petri_manipulator )
|
141
112
|
end
|
data/test/y_petri_test.rb
CHANGED
@@ -302,11 +302,11 @@ describe ::YPetri::Transition do
|
|
302
302
|
describe "6. stoichiometric transitions with rate (SR transitions)" do
|
303
303
|
before do
|
304
304
|
# now this should give standard mass action by magic:
|
305
|
-
@SR1 = @ç.new s: { @p1 => -1, @p2 => -1, @p4 => 1 },
|
306
|
-
# while this has custom
|
307
|
-
@SR2 = @ç.new s: { @p1 => -1, @p3 => 1 },
|
305
|
+
@SR1 = @ç.new s: { @p1 => -1, @p2 => -1, @p4 => 1 }, rate: 0.1
|
306
|
+
# while this has custom closure
|
307
|
+
@SR2 = @ç.new s: { @p1 => -1, @p3 => 1 }, rate: λ { |a| a * 0.5 }
|
308
308
|
# while this one even has domain specified:
|
309
|
-
@SR3 = @ç.new s: { @p1 => -1, @p2 => -1, @p4 => 1 }, upstream_arcs: @p3,
|
309
|
+
@SR3 = @ç.new s: { @p1 => -1, @p2 => -1, @p4 => 1 }, upstream_arcs: @p3, rate: λ { |a| a * 0.5 }
|
310
310
|
end
|
311
311
|
|
312
312
|
it "should init and work" do
|
@@ -598,13 +598,14 @@ describe ::YPetri::Simulation do
|
|
598
598
|
@p5 = @pç.new name: "P5", default_marking: 5
|
599
599
|
@t1 = @tç.new name: "T1",
|
600
600
|
s: { @p1 => -1, @p2 => -1, @p4 => 1 },
|
601
|
-
|
601
|
+
rate: 0.1
|
602
602
|
@t2 = @tç.new name: "T2",
|
603
603
|
s: { @p1 => -1, @p3 => 1 },
|
604
|
-
|
604
|
+
rate: λ { |a| a * 0.5 }
|
605
605
|
@t3 = @tç.new name: "T3",
|
606
606
|
s: { @p1 => -1, @p2 => -1, @p4 => 1 },
|
607
|
-
domain: @p3,
|
607
|
+
domain: @p3,
|
608
|
+
rate: λ { |a| a * 0.5 }
|
608
609
|
@net = @nç.new << @p1 << @p2 << @p3 << @p4 << @p5
|
609
610
|
@net.include_transition! @t1
|
610
611
|
@net.include_transition! @t2
|
@@ -818,7 +819,7 @@ describe ::YPetri::Simulation do
|
|
818
819
|
it "5. handles sR transitions" do
|
819
820
|
assert_equal [], @s.rate_closures_for_sR
|
820
821
|
assert_equal [], @s.rate_closures_for_s
|
821
|
-
@s.gradient_for_sR.must_equal Matrix.zero( @s.free_pp.size, 1 )
|
822
|
+
# @s.gradient_for_sR.must_equal Matrix.zero( @s.free_pp.size, 1 )
|
822
823
|
@s.Δ_Euler_for_sR( 1.0 ).must_equal Matrix.zero( @s.free_pp.size, 1 )
|
823
824
|
end
|
824
825
|
|
@@ -934,7 +935,7 @@ describe ::YPetri::TimedSimulation do
|
|
934
935
|
end
|
935
936
|
end
|
936
937
|
|
937
|
-
describe "timed 'isomerization' with
|
938
|
+
describe "timed 'isomerization' with given as λ" do
|
938
939
|
before do
|
939
940
|
@t2 = ::YPetri::Transition.new s: { @a => -1, @c => 1 },
|
940
941
|
rate_closure: λ { |a| a * 0.5 }
|
@@ -1020,9 +1021,9 @@ describe ::YPetri::Workspace do
|
|
1020
1021
|
it "should present places, transitions, nets, simulations" do
|
1021
1022
|
assert_kind_of ::YPetri::Net, @w.Net::Top
|
1022
1023
|
assert_equal @pp[0], @w.place( "AA" )
|
1023
|
-
assert_equal :AA, @w.
|
1024
|
+
assert_equal :AA, @w.pl( @pp[0] )
|
1024
1025
|
assert_equal @tt[0], @w.transition( "AA_BB_assembly" )
|
1025
|
-
assert_equal :AA_appearing, @w.
|
1026
|
+
assert_equal :AA_appearing, @w.tr( @tt[1] )
|
1026
1027
|
assert_equal @pp, @w.places
|
1027
1028
|
assert_equal @tt, @w.transitions
|
1028
1029
|
assert_equal 1, @w.nets.size
|
@@ -1070,49 +1071,43 @@ describe ::YPetri::Manipulator do
|
|
1070
1071
|
it "has net basic points" do
|
1071
1072
|
# --- net point related assets ---
|
1072
1073
|
@m.net_point_reset
|
1073
|
-
@m.
|
1074
|
+
@m.net_point_set @m.workspace.net( :Top )
|
1074
1075
|
@m.net.must_equal @m.workspace.Net::Top
|
1075
1076
|
# --- simulation point related assets ---
|
1076
|
-
@m.
|
1077
|
-
@m.simulation_point_to nil
|
1077
|
+
@m.simulation_point.reset
|
1078
1078
|
@m.simulation.must_equal nil
|
1079
|
-
@m.
|
1079
|
+
@m.simulation_point.key.must_equal nil
|
1080
1080
|
# --- cc point related assets ---
|
1081
|
-
@m.
|
1082
|
-
@m.
|
1081
|
+
@m.cc_point.reset
|
1082
|
+
@m.cc_point.set :Base
|
1083
1083
|
@m.cc.must_equal @m.workspace.clamp_collection
|
1084
1084
|
@m.cc.wont_equal :Base
|
1085
|
-
@m.
|
1085
|
+
@m.cc_point.key.must_equal :Base
|
1086
1086
|
# --- imc point related assets ---
|
1087
|
-
@m.
|
1088
|
-
@m.
|
1087
|
+
@m.imc_point.reset
|
1088
|
+
@m.imc_point.set :Base
|
1089
1089
|
@m.imc.must_equal @m.workspace.initial_marking_collection
|
1090
1090
|
@m.imc.wont_equal :Base
|
1091
|
-
@m.
|
1091
|
+
@m.imc_point.key.must_equal :Base
|
1092
1092
|
# --- ssc point related assets ---
|
1093
|
-
@m.
|
1094
|
-
@m.
|
1093
|
+
@m.ssc_point.reset
|
1094
|
+
@m.ssc_point.set :Base
|
1095
1095
|
@m.ssc.must_equal @m.workspace.simulation_settings_collection
|
1096
1096
|
@m.ssc.wont_equal :Base
|
1097
|
-
@m.
|
1097
|
+
@m.ssc_point.key.must_equal :Base
|
1098
1098
|
end
|
1099
1099
|
|
1100
1100
|
it "has basic selections" do
|
1101
|
-
@m.
|
1102
|
-
@m.
|
1103
|
-
@m.
|
1104
|
-
@m.
|
1105
|
-
@m.
|
1106
|
-
@m.net_selection.must_equal []
|
1107
|
-
@m.simulation_selection.must_equal []
|
1108
|
-
@m.ssc_selection.must_equal []
|
1109
|
-
@m.cc_selection.must_equal []
|
1110
|
-
@m.imc_selection.must_equal []
|
1111
|
-
[ :net, :simulation, :cc, :imc, :ssc ].each { |sym1|
|
1112
|
-
[ :select!, :select, :unselect ].each { |sym2|
|
1113
|
-
@m.must_respond_to "#{sym1}_#{sym2}"
|
1114
|
-
}
|
1115
|
-
}
|
1101
|
+
@m.net_selection.clear
|
1102
|
+
@m.simulation_selection.clear
|
1103
|
+
@m.cc_selection.clear
|
1104
|
+
@m.imc_selection.clear
|
1105
|
+
@m.ssc_selection.clear
|
1106
|
+
@m.net_selection.get.must_equal []
|
1107
|
+
@m.simulation_selection.get.must_equal []
|
1108
|
+
@m.ssc_selection.get.must_equal []
|
1109
|
+
@m.cc_selection.get.must_equal []
|
1110
|
+
@m.imc_selection.get.must_equal []
|
1116
1111
|
end
|
1117
1112
|
|
1118
1113
|
it "presents some methods from workspace" do
|
@@ -1198,7 +1193,7 @@ end
|
|
1198
1193
|
# @m.place( :B ).marking = 5
|
1199
1194
|
# @m.places.map( &:name ).must_equal [:A, :B, :C]
|
1200
1195
|
# @m.places.map( &:marking ).must_equal [2, 5, 7.77]
|
1201
|
-
# @m.transition( :A2B ).
|
1196
|
+
# @m.transition( :A2B ).arcs.must_equal [ @m.place( :A ), @m.place( :B ) ]
|
1202
1197
|
# @m.transition( :A2B ).fire!
|
1203
1198
|
# @m.places.map( &:marking ).must_equal [1, 6, 7.77]
|
1204
1199
|
# @m.transition( :A2B ).fire!
|
@@ -1228,7 +1223,7 @@ end
|
|
1228
1223
|
# @m.net.must_be_kind_of ::YPetri::Net
|
1229
1224
|
# @m.run!
|
1230
1225
|
# @m.simulation.must_be_kind_of ::YPetri::TimedSimulation
|
1231
|
-
# @m.
|
1226
|
+
# @m.plot_state
|
1232
1227
|
# sleep 3
|
1233
1228
|
# end
|
1234
1229
|
# end
|
@@ -1369,7 +1364,7 @@ end
|
|
1369
1364
|
|
1370
1365
|
# it "should work" do
|
1371
1366
|
# @m.run!
|
1372
|
-
# @m.
|
1367
|
+
# @m.plot_state
|
1373
1368
|
# sleep 3
|
1374
1369
|
# end
|
1375
1370
|
# end
|
@@ -1514,7 +1509,7 @@ end
|
|
1514
1509
|
# # === Simulation execution
|
1515
1510
|
# @m.run!
|
1516
1511
|
# # === Plotting of the results
|
1517
|
-
# @m.
|
1512
|
+
# @m.plot_state
|
1518
1513
|
# sleep 20
|
1519
1514
|
# end
|
1520
1515
|
# end
|
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.0.
|
4
|
+
version: 2.0.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-05-
|
11
|
+
date: 2013-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: y_support
|
@@ -70,6 +70,10 @@ files:
|
|
70
70
|
- lib/y_petri/demonstrator_3.rb
|
71
71
|
- lib/y_petri/demonstrator_4.rb
|
72
72
|
- lib/y_petri/manipulator.rb
|
73
|
+
- lib/y_petri/manipulator/hash_key_pointer.rb
|
74
|
+
- lib/y_petri/manipulator/petri_net_related_methods.rb
|
75
|
+
- lib/y_petri/manipulator/selection.rb
|
76
|
+
- lib/y_petri/manipulator/simulation_related_methods.rb
|
73
77
|
- lib/y_petri/net.rb
|
74
78
|
- lib/y_petri/place.rb
|
75
79
|
- lib/y_petri/simulation.rb
|
@@ -77,10 +81,10 @@ files:
|
|
77
81
|
- lib/y_petri/transition.rb
|
78
82
|
- lib/y_petri/version.rb
|
79
83
|
- lib/y_petri/workspace.rb
|
80
|
-
- lib/y_petri/workspace/instance_methods.rb
|
81
84
|
- lib/y_petri/workspace/parametrized_subclassing.rb
|
85
|
+
- lib/y_petri/workspace/petri_net_related_methods.rb
|
86
|
+
- lib/y_petri/workspace/simulation_related_methods.rb
|
82
87
|
- test/simple_manual_examples.rb
|
83
|
-
- test/y_petri_graph.png
|
84
88
|
- test/y_petri_test.rb
|
85
89
|
- y_petri.gemspec
|
86
90
|
homepage: ''
|
@@ -102,11 +106,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
106
|
version: '0'
|
103
107
|
requirements: []
|
104
108
|
rubyforge_project:
|
105
|
-
rubygems_version: 2.0.
|
109
|
+
rubygems_version: 2.0.3
|
106
110
|
signing_key:
|
107
111
|
specification_version: 4
|
108
112
|
summary: a Petri net domain model and simulator
|
109
113
|
test_files:
|
110
114
|
- test/simple_manual_examples.rb
|
111
|
-
- test/y_petri_graph.png
|
112
115
|
- test/y_petri_test.rb
|
data/test/y_petri_graph.png
DELETED
Binary file
|