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
data/lib/y_petri.rb
CHANGED
@@ -1,116 +1,64 @@
|
|
1
|
-
|
2
|
-
require 'csv'
|
3
|
-
require 'graphviz'
|
4
|
-
|
5
|
-
require 'y_support/local_object'
|
6
|
-
require 'y_support/respond_to'
|
7
|
-
require 'y_support/name_magic'
|
8
|
-
require 'y_support/unicode'
|
9
|
-
require 'y_support/typing'
|
10
|
-
require 'y_support/try'
|
11
|
-
require 'y_support/core_ext/hash'
|
12
|
-
require 'y_support/core_ext/array'
|
13
|
-
require 'y_support/stdlib_ext/matrix'
|
14
|
-
require 'y_support/abstract_algebra'
|
15
|
-
require 'y_support/kde'
|
1
|
+
#encoding: utf-8
|
16
2
|
|
17
3
|
require 'active_support/core_ext/module/delegation'
|
18
4
|
require 'active_support/core_ext/array/extract_options'
|
5
|
+
require 'active_support/inflector'
|
6
|
+
|
7
|
+
# The following are the Ruby libraries used by YPetri:
|
8
|
+
require 'gnuplot' # used for graph visualization
|
9
|
+
require 'csv' # not used at the moment
|
10
|
+
require 'graphviz' # used for Petri net visualization
|
11
|
+
|
12
|
+
# The following are the YSupport components used by YPetri:
|
13
|
+
require 'y_support/local_object' # object aware of its creation scope
|
14
|
+
require 'y_support/respond_to' # Symbol#~@ + RespondTo#===
|
15
|
+
require 'y_support/name_magic' # naming by assignment & more
|
16
|
+
require 'y_support/unicode' # ç means self.class
|
17
|
+
require 'y_support/typing' # run-time assertions
|
18
|
+
require 'y_support/try' # increased awareness in danger
|
19
|
+
require 'y_support/core_ext' # core extensions
|
20
|
+
require 'y_support/stdlib_ext/matrix' # matrix extensions
|
21
|
+
require 'y_support/abstract_algebra' #
|
22
|
+
require 'y_support/kde' # popup file with kioclient
|
19
23
|
|
20
24
|
require_relative 'y_petri/version'
|
25
|
+
require_relative 'y_petri/fixed_assets'
|
26
|
+
require_relative 'y_petri/world'
|
21
27
|
require_relative 'y_petri/place'
|
22
28
|
require_relative 'y_petri/transition'
|
23
29
|
require_relative 'y_petri/net'
|
24
30
|
require_relative 'y_petri/simulation'
|
25
|
-
require_relative 'y_petri/
|
26
|
-
require_relative 'y_petri/
|
31
|
+
require_relative 'y_petri/core'
|
32
|
+
require_relative 'y_petri/agent'
|
33
|
+
require_relative 'y_petri/dsl'
|
27
34
|
|
28
|
-
# YPetri represents Petri net (PN)
|
35
|
+
# YPetri represents Petri net (PN) formalims.
|
29
36
|
#
|
30
|
-
# A PN consists of places and transitions. There are also arcs,
|
31
|
-
#
|
32
|
-
#
|
37
|
+
# A PN consists of places and transitions. There are also arcs, "arrows"
|
38
|
+
# connecting places and transitions, but these are not considered first class
|
39
|
+
# citizens in YPetri.
|
33
40
|
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
# their operation
|
41
|
+
# During PN execution (simulation), transitions act upon places and change their
|
42
|
+
# marking by adding / removing tokens as dictated by their function -- more
|
43
|
+
# precisely, their operation prescription. Borrowing more from the functional
|
44
|
+
# terminology, I define domain an codomain of a PN transition in a similar way
|
45
|
+
# to the functional domain and codomain.
|
37
46
|
#
|
38
|
-
# Hybrid Functional Petri Net formalism, motivated by
|
39
|
-
# processes
|
40
|
-
#
|
41
|
-
#
|
42
|
-
# fluid transition between Fixnum and Bignum,
|
43
|
-
# transition between
|
44
|
-
#
|
47
|
+
# Hybrid Functional Petri Net (HFPN) formalism, motivated by the needs of
|
48
|
+
# modeling of cellular processes, explicitly introduces the option of having
|
49
|
+
# discrete as well as continuous places and transitions (therefrom "hybrid").
|
50
|
+
# In YPetri, the emphasis is elsewhere. Just like in modern computer languages,
|
51
|
+
# there is a fluid transition between Fixnum and Bignum, YPetri attempts for
|
52
|
+
# similarly fluid transition between Integer (ie. discrete) and floating point
|
53
|
+
# (ie. continuous) representation of token amounts and reaction speeds. Whole
|
54
|
+
# discrete / continuous issue thus becomes the business of the simulator, not
|
55
|
+
# the model.
|
45
56
|
#
|
46
57
|
module YPetri
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
58
|
+
class << self
|
59
|
+
def included( receiver )
|
60
|
+
receiver.extend YPetri::DSL
|
61
|
+
receiver.delegate :y_petri_agent, to: "self.class"
|
62
|
+
end
|
51
63
|
end
|
52
|
-
|
53
|
-
GuardError = Class.new TypeError
|
54
|
-
|
55
|
-
def self.included( receiver )
|
56
|
-
# receiver.instance_variable_set :@YPetriManipulator, Manipulator.new
|
57
|
-
# puts "included in #{receiver}"
|
58
|
-
receiver.module_exec {
|
59
|
-
define_method :y_petri_manipulator do
|
60
|
-
singleton_class.instance_variable_get :@YPetriManipulator or
|
61
|
-
( puts "defining Manipulator for #{self} singleton class" if YPetri::DEBUG
|
62
|
-
singleton_class.instance_variable_set :@YPetriManipulator, Manipulator.new )
|
63
|
-
end
|
64
|
-
}
|
65
|
-
end
|
66
|
-
|
67
|
-
delegate( :workspace, to: :y_petri_manipulator )
|
68
|
-
|
69
|
-
# Petri net aspect.
|
70
|
-
delegate( :Place, :Transition, :Net,
|
71
|
-
:place, :transition, :pl, :tr,
|
72
|
-
:places, :transitions, :nets,
|
73
|
-
:pp, :tt, :nn,
|
74
|
-
:net_point,
|
75
|
-
:net_selection,
|
76
|
-
:net, :ne,
|
77
|
-
:net_point_reset,
|
78
|
-
:net_point_set,
|
79
|
-
to: :y_petri_manipulator )
|
80
|
-
|
81
|
-
# Simulation aspect.
|
82
|
-
delegate( :simulation_point, :ssc_point, :cc_point, :imc_point,
|
83
|
-
:simulation_selection, :ssc_selection,
|
84
|
-
:cc_selection, :imc_selection,
|
85
|
-
:simulations,
|
86
|
-
:clamp_collections,
|
87
|
-
:initial_marking_collections,
|
88
|
-
:simulation_settings_collections,
|
89
|
-
:clamp_collection_names, :cc_names,
|
90
|
-
:initial_marking_collection_names, :imc_names,
|
91
|
-
:simulation_settings_collection_names, :ssc_names,
|
92
|
-
:set_clamp_collection, :set_cc,
|
93
|
-
:set_initial_marking_collection, :set_imc,
|
94
|
-
:set_simulation_settings_collection, :set_ssc,
|
95
|
-
:new_timed_simulation,
|
96
|
-
:clamp_cc, :initial_marking_cc, :simulation_settings_cc,
|
97
|
-
:simulation_point_position,
|
98
|
-
:simulation,
|
99
|
-
:clamp_collection, :cc,
|
100
|
-
:initial_marking_collection, :imc,
|
101
|
-
:simulation_settings_collection, :ssc,
|
102
|
-
:clamp,
|
103
|
-
:initial_marking,
|
104
|
-
:set_step, :set_step_size,
|
105
|
-
:set_time, :set_target_time,
|
106
|
-
:set_sampling,
|
107
|
-
:set_simulation_method,
|
108
|
-
:new_timed_simulation,
|
109
|
-
:run!,
|
110
|
-
:print_recording,
|
111
|
-
:plot,
|
112
|
-
:plot_selected,
|
113
|
-
:plot_state,
|
114
|
-
:plot_flux,
|
115
|
-
to: :y_petri_manipulator )
|
116
64
|
end
|
@@ -7,16 +7,16 @@ require_relative '../lib/y_petri' # tested component itself
|
|
7
7
|
# require 'y_petri'
|
8
8
|
# require 'sy'
|
9
9
|
|
10
|
-
describe
|
10
|
+
describe YPetri::Agent do
|
11
11
|
before do
|
12
|
-
@m =
|
12
|
+
@m = YPetri::Agent.new
|
13
13
|
end
|
14
14
|
|
15
15
|
it "has net basic points" do
|
16
16
|
# --- net point related assets ---
|
17
17
|
@m.net_point_reset
|
18
|
-
@m.
|
19
|
-
@m.net.must_equal @m.
|
18
|
+
@m.net_point_reset @m.world.net( :Top )
|
19
|
+
@m.net.must_equal @m.world.Net::Top
|
20
20
|
# --- simulation point related assets ---
|
21
21
|
@m.simulation_point.reset
|
22
22
|
@m.simulation.must_equal nil
|
@@ -24,19 +24,19 @@ describe ::YPetri::Manipulator do
|
|
24
24
|
# --- cc point related assets ---
|
25
25
|
@m.cc_point.reset
|
26
26
|
@m.cc_point.set :Base
|
27
|
-
@m.cc.must_equal @m.
|
27
|
+
@m.cc.must_equal @m.world.clamp_collection
|
28
28
|
@m.cc.wont_equal :Base
|
29
29
|
@m.cc_point.key.must_equal :Base
|
30
30
|
# --- imc point related assets ---
|
31
31
|
@m.imc_point.reset
|
32
32
|
@m.imc_point.set :Base
|
33
|
-
@m.imc.must_equal @m.
|
33
|
+
@m.imc.must_equal @m.world.initial_marking_collection
|
34
34
|
@m.imc.wont_equal :Base
|
35
35
|
@m.imc_point.key.must_equal :Base
|
36
36
|
# --- ssc point related assets ---
|
37
37
|
@m.ssc_point.reset
|
38
38
|
@m.ssc_point.set :Base
|
39
|
-
@m.ssc.must_equal @m.
|
39
|
+
@m.ssc.must_equal @m.world.simulation_settings_collection
|
40
40
|
@m.ssc.wont_equal :Base
|
41
41
|
@m.ssc_point.key.must_equal :Base
|
42
42
|
end
|
@@ -64,8 +64,8 @@ describe ::YPetri::Manipulator do
|
|
64
64
|
@m.initial_marking_collections,
|
65
65
|
@m.simulation_settings_collections ]
|
66
66
|
.map( &:keys ).must_equal [[:Base]] * 3
|
67
|
-
@m.
|
68
|
-
@m.
|
67
|
+
@m.pn.must_equal []
|
68
|
+
@m.tn.must_equal []
|
69
69
|
@m.nn.must_equal [ :Top ] # ie. :Top net spanning whole workspace
|
70
70
|
end
|
71
71
|
|
@@ -84,15 +84,17 @@ describe ::YPetri::Manipulator do
|
|
84
84
|
|
85
85
|
it "works" do
|
86
86
|
@m.run!
|
87
|
-
@m.simulation.places.
|
88
|
-
|
89
|
-
@m.simulation.
|
90
|
-
|
87
|
+
@m.simulation.send( :places ).map( &:source )
|
88
|
+
.must_equal [ @p, @q ]
|
89
|
+
@m.simulation.send( :transitions ).map( &:source )
|
90
|
+
.must_equal [ @decay_t, @constant_flux_t ]
|
91
|
+
@m.simulation.nTS.must_equal [ :Tp, :Tq ]
|
92
|
+
@m.simulation.send( :transition, :Tp ).sparse_stoichiometry_vector
|
91
93
|
.must_equal Matrix.column_vector( [-1, 0] )
|
92
|
-
@m.simulation.
|
93
|
-
.must_equal 2
|
94
|
-
@m.simulation.
|
95
|
-
.must_equal 2
|
94
|
+
@m.simulation.send( :S_transitions )
|
95
|
+
.stoichiometry_matrix.column_size.must_equal 2
|
96
|
+
@m.simulation.send( :S_transitions )
|
97
|
+
.stoichiometry_matrix.row_size.must_equal 2
|
96
98
|
@m.simulation.flux_vector.row_size.must_equal 2
|
97
99
|
# @m.plot_recording
|
98
100
|
end
|
File without changes
|
@@ -31,6 +31,7 @@ DeoxyU12P = Place m!: 0.0.µM
|
|
31
31
|
DeoxyTMP = Place m!: 3.3.µM
|
32
32
|
DeoxyT23P = Place m!: 5.0.µM
|
33
33
|
Thymidine = Place m!: 0.5.µM
|
34
|
+
|
34
35
|
TK1 = Place m!: 100_000.unit.( SY::MoleAmount ) / Cytoplasm_volume
|
35
36
|
TYMS = Place m!: 100_000.unit.( SY::MoleAmount ) / Cytoplasm_volume
|
36
37
|
RNR = Place m!: 100_000.unit.( SY::MoleAmount ) / Cytoplasm_volume
|
File without changes
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
require 'y_petri'
|
4
|
+
include YPetri
|
5
|
+
|
6
|
+
A = Place( default_marking: 0.5 )
|
7
|
+
B = Place( default_marking: 0.5 )
|
8
|
+
A_pump = Transition( stoichiometry: { A: -1 }, rate: proc { 0.005 } )
|
9
|
+
B_decay = Transition( stoichiometry: { B: -1 }, rate: 0.05 )
|
10
|
+
net
|
11
|
+
run!
|
12
|
+
simulation
|
13
|
+
places.map &:marking
|
14
|
+
simulation.settings
|
15
|
+
print_recording
|
16
|
+
plot_state; nil
|
File without changes
|
data/test/net_test.rb
CHANGED
@@ -1,170 +1,175 @@
|
|
1
1
|
#! /usr/bin/ruby
|
2
|
-
#
|
2
|
+
# encoding: utf-8
|
3
3
|
|
4
4
|
require 'minitest/spec'
|
5
5
|
require 'minitest/autorun'
|
6
6
|
require_relative '../lib/y_petri' # tested component itself
|
7
7
|
# require 'y_petri'
|
8
8
|
# require 'sy'
|
9
|
+
require_relative 'world_mock'
|
9
10
|
|
10
11
|
describe YPetri::Net do
|
11
12
|
before do
|
12
|
-
@
|
13
|
-
@pç = pç = Class.new YPetri::Place
|
14
|
-
@nç = nç = Class.new YPetri::Net
|
15
|
-
[ tç, pç, nç ].each { |ç|
|
16
|
-
ç.namespace!
|
17
|
-
ç.class_exec {
|
18
|
-
define_method :Place do pç end
|
19
|
-
define_method :Transition do tç end
|
20
|
-
define_method :Net do nç end
|
21
|
-
private :Place, :Transition, :Net
|
22
|
-
}
|
23
|
-
}
|
24
|
-
@p1 = pç.new ɴ: "A", quantum: 0.1, marking: 1.1
|
25
|
-
@p2 = pç.new ɴ: "B", quantum: 0.1, marking: 2.2
|
26
|
-
@p3 = pç.new ɴ: "C", quantum: 0.1, marking: 3.3
|
27
|
-
@net = nç.new
|
28
|
-
[@p1, @p2, @p3].each { |p| @net.include_place! p }
|
29
|
-
@p_not_included = pç.new ɴ: "X", marking: 0
|
13
|
+
@w = YPetri::World.new
|
30
14
|
end
|
31
15
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
it "should expose its elements" do
|
40
|
-
assert_equal [@p1, @p2, @p3], @net.places
|
41
|
-
assert_equal [:A, :B, :C], @net.pp
|
42
|
-
assert_equal [], @net.transitions
|
43
|
-
end
|
16
|
+
it "should initialize" do
|
17
|
+
net = @w.Net.new
|
18
|
+
net.places.must_equal []
|
19
|
+
net.transitions.must_equal []
|
20
|
+
net.pp.must_equal []
|
21
|
+
net.tt.must_equal []
|
22
|
+
end
|
44
23
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
assert_equal [], @net.transitions_without_rate
|
49
|
-
assert_equal [], @net.stoichiometric_transitions
|
50
|
-
assert_equal [], @net.nonstoichiometric_transitions
|
24
|
+
describe "element access" do
|
25
|
+
before do
|
26
|
+
@net = @w.Net.new
|
51
27
|
end
|
52
28
|
|
53
|
-
it "should
|
54
|
-
|
55
|
-
|
56
|
-
|
29
|
+
it "should work" do
|
30
|
+
p = @w.Place.new name: "A", quantum: 0.1, marking: 1.1
|
31
|
+
@net.includes_place?( p ).must_equal false
|
32
|
+
@net.include_place p
|
33
|
+
@net.places.must_equal [ p ]
|
34
|
+
@net.place( :A ).must_equal p
|
35
|
+
@net.places( [] ).must_equal []
|
36
|
+
@net.places( [:A] ).must_equal [ p ]
|
57
37
|
end
|
38
|
+
end
|
58
39
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
@net.exclude_place! @p_not_included
|
66
|
-
@net.include_transition! YPetri::Transition.new( s: { @p_not_included => -1 } )
|
67
|
-
flunk "Attempt to include illegal transition fails to raise"
|
68
|
-
rescue; end
|
40
|
+
describe "world with 3 places" do
|
41
|
+
before do
|
42
|
+
@p1 = @w.Place.new name: "A", quantum: 0.1, marking: 1.1
|
43
|
+
@p2 = @w.Place.new name: "B", quantum: 0.1, marking: 2.2
|
44
|
+
@p3 = @w.Place.new name: "C", quantum: 0.1, marking: 3.3
|
45
|
+
@p4 = @w.Place.new name: "X", marking: 0
|
69
46
|
end
|
70
47
|
|
71
|
-
describe "
|
48
|
+
describe "net of 3 places and no transitions" do
|
72
49
|
before do
|
73
|
-
@
|
74
|
-
|
75
|
-
|
76
|
-
@net.
|
50
|
+
# @p1.m = 1.1
|
51
|
+
# @p2.m = 2.2
|
52
|
+
# @p3.m = 3.3
|
53
|
+
@net = @w.Net.of @p1, @p2, @p3
|
77
54
|
end
|
78
55
|
|
79
56
|
it "should expose its elements" do
|
80
|
-
assert_equal [@
|
81
|
-
assert_equal [:
|
57
|
+
assert_equal [@p1, @p2, @p3], @net.places
|
58
|
+
assert_equal [:A, :B, :C], @net.pn
|
59
|
+
assert_equal [], @net.transitions
|
82
60
|
end
|
83
61
|
|
84
62
|
it "should expose transition groups" do
|
85
|
-
assert_equal
|
86
|
-
assert_equal [
|
87
|
-
assert_equal [], @net.rateless_transitions
|
88
|
-
assert_equal [@t1], @net.stoichiometric_transitions
|
89
|
-
assert_equal [], @net.nonstoichiometric_transitions
|
63
|
+
assert_equal [], @net.S_transitions
|
64
|
+
assert_equal [], @net.s_transitions
|
90
65
|
end
|
91
66
|
|
92
67
|
it "should tell its qualities" do
|
93
68
|
assert_equal true, @net.functional?
|
94
|
-
assert_equal
|
95
|
-
assert @net.include?( @
|
96
|
-
end
|
97
|
-
|
98
|
-
it "should have #place & #transition for safe access to the said elements" do
|
99
|
-
@net.send( :place, @p1 ).must_equal @p1
|
100
|
-
@net.send( :transition, @t1 ).must_equal @t1
|
69
|
+
assert_equal false, @net.timed?
|
70
|
+
assert @net.include?( @p1 ) && !@net.include?( YPetri::Place.new )
|
101
71
|
end
|
102
72
|
|
103
|
-
it "
|
104
|
-
@net.
|
105
|
-
@net.
|
73
|
+
it "should have 'standard equipment' methods" do
|
74
|
+
assert @net == @net.dup
|
75
|
+
assert @net.inspect.start_with? "#<Net:"
|
76
|
+
assert @net.include?( @p1 )
|
77
|
+
assert ! @net.include?( @p_not_included )
|
78
|
+
begin
|
79
|
+
@net.exclude_place! @p_not_included
|
80
|
+
@net.include_transition! YPetri::Transition.new( s: { @p_not_included => -1 } )
|
81
|
+
flunk "Attempt to include illegal transition fails to raise"
|
82
|
+
rescue; end
|
106
83
|
end
|
107
84
|
|
108
|
-
|
109
|
-
assert_equal [1.1, 2.2, 3.3], [@p1, @p2, @p3].map( &:marking ).map{ |n| n.round 6 }
|
110
|
-
assert_equal 2.2 * 3.3 * 0.01, @t1.rate_closure.call( @p2.marking, @p3.marking )
|
111
|
-
assert_equal [ @p2, @p3 ], @t1.domain
|
112
|
-
@t1.fire! 1
|
113
|
-
assert_equal [1.1726, 2.1274, 3.2274], [@p1, @p2, @p3].map( &:marking ).map{ |n| n.round 6 }
|
114
|
-
end
|
115
|
-
|
116
|
-
describe "plus 1 more nameless timeless functionless transition" do
|
85
|
+
describe "plus 1 stoichio. transition with rate" do
|
117
86
|
before do
|
118
|
-
@
|
119
|
-
|
87
|
+
@t1 = @w.Transition.avid( ɴ: "T1",
|
88
|
+
s: { @p1 => 1, @p2 => -1, @p3 => -1 },
|
89
|
+
rate: 0.01 )
|
90
|
+
@net.include_transition @t1
|
120
91
|
end
|
121
92
|
|
122
93
|
it "should expose its elements" do
|
123
|
-
assert_equal [@t1
|
124
|
-
assert_equal [:T1
|
125
|
-
@net.
|
126
|
-
@net.
|
94
|
+
assert_equal [ @t1 ], @net.transitions
|
95
|
+
assert_equal [ :T1 ], @net.tn
|
96
|
+
@net.transition( :T1 ).must_equal @t1
|
97
|
+
@net.transitions( [] ).must_equal []
|
98
|
+
@net.transitions( [ :T1 ] ).must_equal [ @t1 ]
|
99
|
+
@net.element( :T1 ).must_equal @t1
|
100
|
+
@net.elements( [] ).must_equal []
|
101
|
+
@net.elements( [ :T1 ] ).must_equal [ @t1 ]
|
102
|
+
@net.elements( [ :A, :T1 ] ).must_equal [ @p1, @t1 ]
|
127
103
|
end
|
128
104
|
|
129
105
|
it "should expose transition groups" do
|
130
|
-
assert_equal [], @net.
|
131
|
-
assert_equal [], @net.
|
132
|
-
assert_equal [@t2], @net.timeless_stoichiometric_transitions
|
133
|
-
assert_equal [nil], @net.timeless_stoichiometric_tt
|
134
|
-
assert_equal [], @net.timed_nonstoichiometric_transitions_without_rate
|
135
|
-
assert_equal [], @net.timed_rateless_nonstoichiometric_transitions
|
136
|
-
assert_equal [], @net.timed_nonstoichiometric_tt_without_rate
|
137
|
-
assert_equal [], @net.timed_rateless_nonstoichiometric_tt
|
138
|
-
assert_equal [], @net.timed_nonstoichiometric_transitions_without_rate
|
139
|
-
assert_equal [], @net.timed_rateless_nonstoichiometric_transitions
|
140
|
-
assert_equal [], @net.timed_nonstoichiometric_tt_without_rate
|
141
|
-
assert_equal [], @net.timed_rateless_nonstoichiometric_tt
|
142
|
-
assert_equal [], @net.nonstoichiometric_transitions_with_rate
|
143
|
-
assert_equal [], @net.nonstoichiometric_tt_with_rate
|
144
|
-
assert_equal [@t1], @net.stoichiometric_transitions_with_rate
|
145
|
-
assert_equal [:T1], @net.stoichiometric_tt_with_rate
|
146
|
-
assert_equal [], @net.assignment_transitions
|
147
|
-
assert_equal [], @net.assignment_tt
|
148
|
-
assert_equal [@t1, @t2], @net.stoichiometric_transitions
|
149
|
-
assert_equal [:T1, nil], @net.stoichiometric_tt
|
150
|
-
assert_equal [], @net.nonstoichiometric_transitions
|
151
|
-
assert_equal [], @net.nonstoichiometric_tt
|
152
|
-
assert_equal [@t1], @net.timed_transitions
|
153
|
-
assert_equal [:T1], @net.timed_tt
|
154
|
-
assert_equal [@t2], @net.timeless_transitions
|
155
|
-
assert_equal [nil], @net.timeless_tt
|
156
|
-
assert_equal [@t1], @net.transitions_with_rate
|
157
|
-
assert_equal [:T1], @net.tt_with_rate
|
158
|
-
assert_equal [@t2], @net.rateless_transitions
|
159
|
-
assert_equal [nil], @net.rateless_tt
|
106
|
+
assert_equal [@t1], @net.S_transitions
|
107
|
+
assert_equal [], @net.s_transitions
|
160
108
|
end
|
161
109
|
|
162
110
|
it "should tell its qualities" do
|
163
|
-
assert_equal false, @net.functional?
|
164
|
-
assert_equal false, @net.timed?
|
165
|
-
@net.exclude_transition! @t2
|
166
111
|
assert_equal true, @net.functional?
|
167
112
|
assert_equal true, @net.timed?
|
113
|
+
assert @net.include?( @t1 )
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should have #place & #transition for safe access to them" do
|
117
|
+
@net.send( :place, @p1 ).must_equal @p1
|
118
|
+
@net.send( :transition, @t1 ).must_equal @t1
|
119
|
+
@net.send( :element, @p1 ).must_equal @p1
|
120
|
+
end
|
121
|
+
|
122
|
+
it "has #new_simulation & #new_timed_simulation constructors" do
|
123
|
+
@net.must_respond_to :simulation
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should have other methods" do
|
127
|
+
assert_equal [1.1, 2.2, 3.3], [@p1, @p2, @p3].map( &:marking ).map{ |n| n.round 6 }
|
128
|
+
assert_equal 2.2 * 3.3 * 0.01, @t1.rate_closure.call( @p2.marking, @p3.marking )
|
129
|
+
assert_equal [ @p2, @p3 ], @t1.domain
|
130
|
+
@t1.fire! 1
|
131
|
+
assert_equal [1.1726, 2.1274, 3.2274], [@p1, @p2, @p3].map( &:marking ).map{ |n| n.round 6 }
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "plus 1 more nameless timeless functionless transition" do
|
135
|
+
before do
|
136
|
+
@t2 = @w.Transition.new s: { @p2 => -1, @p3 => 1 }
|
137
|
+
@net.include_transition @t2
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should expose its elements" do
|
141
|
+
assert_equal [@t1, @t2], @net.transitions
|
142
|
+
assert_equal [:T1, nil], @net.tn
|
143
|
+
@net.tap{ |n| n.exclude_transition @t1 }.exclude_transition @t2
|
144
|
+
@net.tap{ |n| n.exclude_place @p3 }.pn.must_equal [:A, :B]
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should expose transition groups" do
|
148
|
+
assert_equal [], @net.ts_transitions
|
149
|
+
assert_equal [], @net.nts
|
150
|
+
assert_equal [@t2], @net.tS_transitions
|
151
|
+
assert_equal [nil], @net.ntS
|
152
|
+
assert_equal [@t1], @net.TS_transitions
|
153
|
+
assert_equal [:T1], @net.nTS
|
154
|
+
assert_equal [], @net.A_transitions
|
155
|
+
assert_equal [], @net.nA
|
156
|
+
assert_equal [@t1, @t2], @net.S_transitions
|
157
|
+
assert_equal [:T1, nil], @net.nS
|
158
|
+
assert_equal [], @net.s_transitions
|
159
|
+
assert_equal [], @net.ns
|
160
|
+
assert_equal [@t1], @net.T_transitions
|
161
|
+
assert_equal [:T1], @net.nT
|
162
|
+
assert_equal [@t2], @net.t_transitions
|
163
|
+
assert_equal [nil], @net.nt
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should tell its qualities" do
|
167
|
+
assert_equal false, @net.functional?
|
168
|
+
assert_equal true, @net.timed?
|
169
|
+
@net.exclude_transition @t2
|
170
|
+
assert_equal true, @net.functional?
|
171
|
+
assert_equal true, @net.timed?
|
172
|
+
end
|
168
173
|
end
|
169
174
|
end
|
170
175
|
end
|
data/test/place_test.rb
CHANGED
@@ -10,7 +10,7 @@ require_relative '../lib/y_petri' # tested component itself
|
|
10
10
|
describe YPetri::Place do
|
11
11
|
before do
|
12
12
|
@pç = pç = Class.new YPetri::Place
|
13
|
-
@p = pç.
|
13
|
+
@p = pç.avid default_marking: 3.2,
|
14
14
|
marking: 1.1,
|
15
15
|
quantum: 0.1,
|
16
16
|
name: "P1"
|