y_petri 2.1.7 → 2.1.9
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/agent/petri_net_related.rb +9 -8
- data/lib/y_petri/agent/simulation_related.rb +2 -2
- data/lib/y_petri/dsl.rb +1 -1
- data/lib/y_petri/net/state/feature/flux.rb +1 -1
- data/lib/y_petri/net.rb +2 -0
- data/lib/y_petri/place.rb +2 -0
- data/lib/y_petri/simulation/timed.rb +3 -3
- data/lib/y_petri/transition.rb +2 -0
- data/lib/y_petri/version.rb +1 -1
- data/lib/y_petri/world/dependency.rb +2 -2
- data/lib/y_petri/world/petri_net_related.rb +5 -5
- data/lib/y_petri/world.rb +2 -3
- data/test/net_test.rb +11 -11
- data/test/place_test.rb +1 -1
- data/test/simulation_test.rb +7 -7
- data/test/transition_test.rb +26 -26
- data/test/y_petri_test.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70791aeefd6b43e56ccdbf4fb980d51768e4ecec
|
4
|
+
data.tar.gz: d3b852100353e1df976a7c8f3ffd84e0cd2c6dce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a03c5f1c57429be512c5e023e99a92a9973c7ad94df76f75d04cdca96e02fa530d91383ea360c06a4e354d3a8824b8b6885d3ff76bb4d3a553e395813aa321ba
|
7
|
+
data.tar.gz: 844311666d998f34bec07216f7ea0cd37233b0f4309ed88860dcda7f4dfc44e61931c08e246f024f4fee33741dbbe32ac443cca0829e7bdb9893e66fbfa127a4
|
@@ -65,13 +65,13 @@ module YPetri::Agent::PetriNetRelated
|
|
65
65
|
named_args.update( guard: block ) if block # use block as a guard
|
66
66
|
named_args.may_have :default_marking, syn!: :m!
|
67
67
|
named_args.may_have :marking, syn!: :m
|
68
|
-
world.Place.new *ordered_args, **named_args
|
68
|
+
world.Place.send( :new, *ordered_args, **named_args, &block )
|
69
69
|
end
|
70
70
|
|
71
71
|
# Transition constructor: Creates a new transition in the current world.
|
72
72
|
#
|
73
73
|
def Transition( *ordered, **named, &block )
|
74
|
-
world.Transition.new *ordered, **named, &block
|
74
|
+
world.Transition.send( :new, *ordered, **named, &block )
|
75
75
|
end
|
76
76
|
|
77
77
|
# Timed transition constructor: Creates a new timed transition in the current
|
@@ -80,7 +80,7 @@ module YPetri::Agent::PetriNetRelated
|
|
80
80
|
def T( *ordered, **named, &block )
|
81
81
|
fail ArgumentError, "Timed transition constructor requires a block " +
|
82
82
|
"defining the rate function!" unless block
|
83
|
-
world.Transition.new *ordered, **named.update( rate: block )
|
83
|
+
world.Transition.send( :new, *ordered, **named.update( rate: block ) )
|
84
84
|
end
|
85
85
|
|
86
86
|
# Timed stoichiometric transition constructor, that expects stoichiometry
|
@@ -103,16 +103,17 @@ module YPetri::Agent::PetriNetRelated
|
|
103
103
|
def A( *codomain, **nn, &block )
|
104
104
|
fail ArgumentError, "Assignment transition constructor requires a block " +
|
105
105
|
"defining the assignment function!" unless block
|
106
|
-
world.Transition.
|
107
|
-
|
108
|
-
|
109
|
-
|
106
|
+
world.Transition.send( :new,
|
107
|
+
codomain: codomain,
|
108
|
+
assignment: true,
|
109
|
+
action: block,
|
110
|
+
**nn )
|
110
111
|
end
|
111
112
|
|
112
113
|
# Net constructor: Creates a new Net instance in the current world.
|
113
114
|
#
|
114
115
|
def Net *ordered, **named, &block
|
115
|
-
world.Net.new *ordered, **named, &block
|
116
|
+
world.Net.send( :new, *ordered, **named, &block )
|
116
117
|
end
|
117
118
|
|
118
119
|
# Returns the net identified, or the net at point (if no argument given).
|
data/lib/y_petri/dsl.rb
CHANGED
data/lib/y_petri/net.rb
CHANGED
data/lib/y_petri/place.rb
CHANGED
@@ -38,7 +38,7 @@ module YPetri::Simulation::Timed
|
|
38
38
|
initial_time..target_time
|
39
39
|
end
|
40
40
|
|
41
|
-
#
|
41
|
+
# Returns the settings pertaining to the Timed aspect of the simulation,
|
42
42
|
# that is, +:step+, +:sampling+ and +:time+.
|
43
43
|
#
|
44
44
|
def settings all=false
|
@@ -48,7 +48,7 @@ module YPetri::Simulation::Timed
|
|
48
48
|
end
|
49
49
|
|
50
50
|
# Same as +#run!+, but guards against run upto infinity.
|
51
|
-
#
|
51
|
+
#
|
52
52
|
def run( upto: target_time, final_step: :exact )
|
53
53
|
fail "Upto time equals infinity!" if upto == Float::INFINITY
|
54
54
|
run!( upto: upto, final_step: final_step )
|
@@ -57,7 +57,7 @@ module YPetri::Simulation::Timed
|
|
57
57
|
# Near alias for +#run_upto+. Accepts +:upto+ named argument, using
|
58
58
|
# @target_time attribute as a default. The second optional argument,
|
59
59
|
# +:final_step+, has the same options as in +#run_upto+ method.
|
60
|
-
#
|
60
|
+
#
|
61
61
|
def run!( upto: target_time, final_step: :exact )
|
62
62
|
run_upto( upto, final_step: final_step )
|
63
63
|
end
|
data/lib/y_petri/transition.rb
CHANGED
data/lib/y_petri/version.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#encoding: utf-8
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
# Provides basic skeleton for dependency injection for the triples of the
|
4
4
|
# parametrized subclasses of Place, Transition and Net in different workspaces.
|
5
|
-
#
|
5
|
+
#
|
6
6
|
class YPetri::World
|
7
7
|
module Dependency
|
8
8
|
delegate :Place, :Transition, :Net, to: :world
|
@@ -13,19 +13,19 @@ module YPetri::World::PetriNetRelated
|
|
13
13
|
|
14
14
|
# Returns a place instance identified by the argument.
|
15
15
|
#
|
16
|
-
def place id
|
16
|
+
def place( id )
|
17
17
|
Place().instance( id )
|
18
18
|
end
|
19
19
|
|
20
20
|
# Returns a transition instance identified by the argument.
|
21
21
|
#
|
22
|
-
def transition id
|
22
|
+
def transition( id )
|
23
23
|
Transition().instance( id )
|
24
24
|
end
|
25
25
|
|
26
26
|
# Returns a net instance identified by the argument.
|
27
27
|
#
|
28
|
-
def net id
|
28
|
+
def net( id )
|
29
29
|
Net().instance( id )
|
30
30
|
end
|
31
31
|
|
@@ -52,10 +52,10 @@ module YPetri::World::PetriNetRelated
|
|
52
52
|
# Creates all-encompassing Net instance named :Top.
|
53
53
|
#
|
54
54
|
def set_up_Top_net
|
55
|
-
Net().new name: :Top # all-encompassing :Top net
|
55
|
+
Net().send :new, name: :Top # all-encompassing :Top net
|
56
56
|
# Hook new places to add themselves magically to the :Top net.
|
57
57
|
Place().new_instance_closure { |new_inst| net( :Top ) << new_inst }
|
58
58
|
# Hook new transitions to add themselves magically to the :Top net.
|
59
|
-
Transition().new_instance_closure { |new_inst| net( :Top ) << new_inst }
|
59
|
+
Transition().new_instance_closure { |new_inst| net( :Top ) << new_inst }
|
60
60
|
end
|
61
61
|
end # module YPetri::World::PetriNetRelated
|
data/lib/y_petri/world.rb
CHANGED
@@ -4,11 +4,10 @@ require_relative 'world/dependency'
|
|
4
4
|
require_relative 'world/petri_net_related'
|
5
5
|
require_relative 'world/simulation_related'
|
6
6
|
|
7
|
-
|
8
7
|
# As the name suggests, represents the world. Holds places, transitions, nets
|
9
8
|
# and other assets needed to set up and simulate Petri nets (settings, clamps,
|
10
|
-
# initial markings etc.). Provides basic methods to do what is necessary.
|
11
|
-
#
|
9
|
+
# initial markings etc.). Provides basic methods to do what is necessary. More
|
10
|
+
# ergonomic and DSL-like methods are up to the YPetri::Agent.
|
12
11
|
#
|
13
12
|
class YPetri::World
|
14
13
|
★ NameMagic # ★ means include
|
data/test/net_test.rb
CHANGED
@@ -14,7 +14,7 @@ describe YPetri::Net do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should initialize" do
|
17
|
-
net = @w.Net.new
|
17
|
+
net = @w.Net.send :new
|
18
18
|
net.places.must_equal []
|
19
19
|
net.transitions.must_equal []
|
20
20
|
net.pp.must_equal []
|
@@ -23,11 +23,11 @@ describe YPetri::Net do
|
|
23
23
|
|
24
24
|
describe "element access" do
|
25
25
|
before do
|
26
|
-
@net = @w.Net.new
|
26
|
+
@net = @w.Net.send :new
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should be able to include places" do
|
30
|
-
p = @w.Place.new name: "A", quantum: 0.1, marking: 1.1
|
30
|
+
p = @w.Place.send :new, name: "A", quantum: 0.1, marking: 1.1
|
31
31
|
@net.includes_place?( p ).must_equal false
|
32
32
|
@net.include_place p
|
33
33
|
@net.places.must_equal [ p ]
|
@@ -39,10 +39,10 @@ describe YPetri::Net do
|
|
39
39
|
|
40
40
|
describe "world with 3 places" do
|
41
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
|
42
|
+
@p1 = @w.Place.send :new, name: "A", quantum: 0.1, marking: 1.1
|
43
|
+
@p2 = @w.Place.send :new, name: "B", quantum: 0.1, marking: 2.2
|
44
|
+
@p3 = @w.Place.send :new, name: "C", quantum: 0.1, marking: 3.3
|
45
|
+
@p4 = @w.Place.send :new, name: "X", marking: 0
|
46
46
|
end
|
47
47
|
|
48
48
|
describe "net of 3 places and no transitions" do
|
@@ -59,7 +59,7 @@ describe YPetri::Net do
|
|
59
59
|
it "should allow only right transitions to be included in it" do
|
60
60
|
assert @net.include?( @p1 )
|
61
61
|
assert ! @net.include?( @p4 )
|
62
|
-
t = @w.Transition.new s: { @p4 => -1 }
|
62
|
+
t = @w.Transition.send :new, s: { @p4 => -1 }
|
63
63
|
-> { @net.include_transition t }.must_raise RuntimeError
|
64
64
|
end
|
65
65
|
|
@@ -71,7 +71,7 @@ describe YPetri::Net do
|
|
71
71
|
it "should be able to tell its qualities" do
|
72
72
|
assert_equal false, @net.functional?
|
73
73
|
assert_equal false, @net.timed?
|
74
|
-
assert @net.include?( @p1 ) && !@net.include?( YPetri::Place.new )
|
74
|
+
assert @net.include?( @p1 ) && !@net.include?( YPetri::Place.send :new )
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should know its state and marking features" do
|
@@ -142,7 +142,7 @@ describe YPetri::Net do
|
|
142
142
|
|
143
143
|
describe "plus 1 more nameless timeless functionless transition" do
|
144
144
|
before do
|
145
|
-
@t2 = @w.Transition.new s: { @p2 => -1, @p3 => 1 }
|
145
|
+
@t2 = @w.Transition.send :new, s: { @p2 => -1, @p3 => 1 }
|
146
146
|
@net.include_transition @t2
|
147
147
|
end
|
148
148
|
|
@@ -189,7 +189,7 @@ end
|
|
189
189
|
describe YPetri::Net::State do
|
190
190
|
before do
|
191
191
|
@w = YPetri::World.new
|
192
|
-
@net = @w.Net.new
|
192
|
+
@net = @w.Net.send :new
|
193
193
|
end
|
194
194
|
|
195
195
|
it "should be already parametrized on @w.Net" do
|
data/test/place_test.rb
CHANGED
data/test/simulation_test.rb
CHANGED
@@ -13,7 +13,7 @@ describe YPetri::Simulation do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should allow for creation of an empty simulation" do
|
16
|
-
net = @w.Net.new
|
16
|
+
net = @w.Net.send :new
|
17
17
|
sim = net.simulation
|
18
18
|
sim.pp.must_equal []
|
19
19
|
sim.pp( *[] ).must_equal []
|
@@ -23,8 +23,8 @@ describe YPetri::Simulation do
|
|
23
23
|
|
24
24
|
describe "simulation setup" do
|
25
25
|
before do
|
26
|
-
@p = @w.Place.new name: :A, default_marking: 1
|
27
|
-
@q = @w.Place.new name: :B, default_marking: 2
|
26
|
+
@p = @w.Place.send :new, name: :A, default_marking: 1
|
27
|
+
@q = @w.Place.send :new, name: :B, default_marking: 2
|
28
28
|
@net = @w.Net.of @p, @q
|
29
29
|
end
|
30
30
|
|
@@ -80,10 +80,10 @@ describe YPetri::Simulation do
|
|
80
80
|
|
81
81
|
describe "transition representation aspects" do
|
82
82
|
before do
|
83
|
-
@ts = @w.Transition.new name: "T_ts", codomain: :A, action: -> { 1 }
|
84
|
-
@tS = @w.Transition.new name: "T_tS", s: { B: -1, A: 1 }, action: proc { 1 }
|
85
|
-
@Ts = @w.Transition.new name: "T_Ts", codomain: :A, rate: -> { 1 }
|
86
|
-
@TS = @w.Transition.new name: "T_TS", s: { B: -1, A: 1 }, rate: proc { 1 }
|
83
|
+
@ts = @w.Transition.send :new, name: "T_ts", codomain: :A, action: -> { 1 }
|
84
|
+
@tS = @w.Transition.send :new, name: "T_tS", s: { B: -1, A: 1 }, action: proc { 1 }
|
85
|
+
@Ts = @w.Transition.send :new, name: "T_Ts", codomain: :A, rate: -> { 1 }
|
86
|
+
@TS = @w.Transition.send :new, name: "T_TS", s: { B: -1, A: 1 }, rate: proc { 1 }
|
87
87
|
end
|
88
88
|
|
89
89
|
it "should be what intended" do
|
data/test/transition_test.rb
CHANGED
@@ -25,33 +25,33 @@ describe ::YPetri::Transition do
|
|
25
25
|
private :Place, :Transition
|
26
26
|
}
|
27
27
|
end
|
28
|
-
@p1 = pç.new default_marking: 1.0
|
29
|
-
@p2 = pç.new default_marking: 2.0
|
30
|
-
@p3 = pç.new default_marking: 3.0
|
31
|
-
@p4 = pç.new default_marking: 4.0
|
32
|
-
@p5 = pç.new default_marking: 5.0
|
28
|
+
@p1 = pç.send :new, default_marking: 1.0
|
29
|
+
@p2 = pç.send :new, default_marking: 2.0
|
30
|
+
@p3 = pç.send :new, default_marking: 3.0
|
31
|
+
@p4 = pç.send :new, default_marking: 4.0
|
32
|
+
@p5 = pç.send :new, default_marking: 5.0
|
33
33
|
end
|
34
34
|
|
35
35
|
describe "ts transitions (timeless nonstoichiometric)" do
|
36
36
|
# Note: ts transitions require a function, and thus are always functional
|
37
37
|
before do
|
38
|
-
@t1 = @ç.new codomain: [ @p1, @p3 ], domain: @p2, action: -> a { [ a, a ] }
|
39
|
-
@t2 = @ç.new codomain: [ @p1, @p3 ] do |t| [ t, t ] end
|
40
|
-
@t3 = @ç.new action: -> { [ 0.5, 0.5 ] }, codomain: [ @p1, @p3 ]
|
38
|
+
@t1 = @ç.send :new, codomain: [ @p1, @p3 ], domain: @p2, action: -> a { [ a, a ] }
|
39
|
+
@t2 = @ç.send :new, codomain: [ @p1, @p3 ] do |t| [ t, t ] end
|
40
|
+
@t3 = @ç.send :new, action: -> { [ 0.5, 0.5 ] }, codomain: [ @p1, @p3 ]
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should raise errors for bad parameters" do
|
44
44
|
# codomain omitted
|
45
|
-
-> { @ç.new domain: @p2, action: -> t { [ t, t ] } }
|
45
|
+
-> { @ç.send :new, domain: @p2, action: -> t { [ t, t ] } }
|
46
46
|
.must_raise ArgumentError
|
47
47
|
# mangled codomain
|
48
|
-
-> { @ç.new codomain: [ @p1, :a ], action: -> t { [ t, t ] } }
|
48
|
+
-> { @ç.send :new, codomain: [ @p1, :a ], action: -> t { [ t, t ] } }
|
49
49
|
.must_raise TypeError
|
50
50
|
# domain omitted
|
51
|
-
-> { @ç.new codomain: [ @p1, :a ], action: -> t { [ t, t ] } }
|
51
|
+
-> { @ç.send :new, codomain: [ @p1, :a ], action: -> t { [ t, t ] } }
|
52
52
|
.must_raise TypeError
|
53
53
|
# action closure arity greater than the domain
|
54
|
-
-> { @ç.new codomain: [ @p1, @p3 ], action: -> t { [ t, t ] }, domain: [] }
|
54
|
+
-> { @ç.send :new, codomain: [ @p1, @p3 ], action: -> t { [ t, t ] }, domain: [] }
|
55
55
|
.must_raise TypeError
|
56
56
|
end
|
57
57
|
|
@@ -77,8 +77,8 @@ describe ::YPetri::Transition do
|
|
77
77
|
|
78
78
|
describe "tS transitions" do
|
79
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"
|
80
|
+
@t1 = @ç.send :new, s: { @p5 => -1, @p1 => 1 }, action: proc { 1 }
|
81
|
+
@t2 = @ç.send :new, s: { @p5 => -1, @p1 => 1 } # should be "functionless"
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should work" do
|
@@ -109,7 +109,7 @@ describe ::YPetri::Transition do
|
|
109
109
|
|
110
110
|
describe "Ts transitions" do
|
111
111
|
before do
|
112
|
-
@t1 = @ç.new domain: @p5, codomain: [@p5, @p1], rate: proc { [-1, 1] }
|
112
|
+
@t1 = @ç.send :new, domain: @p5, codomain: [@p5, @p1], rate: proc { [-1, 1] }
|
113
113
|
end
|
114
114
|
|
115
115
|
it "should work" do
|
@@ -128,12 +128,12 @@ describe ::YPetri::Transition do
|
|
128
128
|
describe "TS transitions (timed stoichiometric)" do
|
129
129
|
before do
|
130
130
|
# This should give standard mass action by magic:
|
131
|
-
@TS1 = @ç.new s: { @p1 => -1, @p2 => -1, @p4 => 1 }, rate: 0.1
|
131
|
+
@TS1 = @ç.send :new, s: { @p1 => -1, @p2 => -1, @p4 => 1 }, rate: 0.1
|
132
132
|
# While this has custom closure:
|
133
|
-
@TS2 = @ç.new s: { @p1 => -1, @p3 => 1 }, rate: -> a { a * 0.5 }
|
133
|
+
@TS2 = @ç.send :new, s: { @p1 => -1, @p3 => 1 }, rate: -> a { a * 0.5 }
|
134
134
|
# While this one even has domain explicitly specified:
|
135
|
-
@TS3 = @ç.new s: { @p1 => -1, @p2 => -1, @p4 => 1 },
|
136
|
-
|
135
|
+
@TS3 = @ç.send :new, s: { @p1 => -1, @p2 => -1, @p4 => 1 },
|
136
|
+
upstream_arcs: @p3, rate: -> a { a * 0.5 }
|
137
137
|
end
|
138
138
|
|
139
139
|
it "should init and work" do
|
@@ -178,14 +178,14 @@ describe "upstream and downstream reference mτs of places and transitions" do
|
|
178
178
|
private :Place, :Transition
|
179
179
|
}
|
180
180
|
}
|
181
|
-
@a = @pç.new
|
182
|
-
@b = @pç.new
|
183
|
-
@c = @pç.new
|
181
|
+
@a = @pç.send :new, default_marking: 1.0
|
182
|
+
@b = @pç.send :new, default_marking: 2.0
|
183
|
+
@c = @pç.send :new, default_marking: 3.0
|
184
184
|
end
|
185
185
|
|
186
186
|
describe "Place" do
|
187
187
|
it "should have #register_ustream/downstream_transition methods" do
|
188
|
-
@t1 = @tç.new s: {}
|
188
|
+
@t1 = @tç.send :new, s: {}
|
189
189
|
@a.instance_variable_get( :@upstream_arcs ).must_equal []
|
190
190
|
@a.instance_variable_get( :@downstream_arcs ).must_equal []
|
191
191
|
@a.send :register_upstream_transition, @t1
|
@@ -195,7 +195,7 @@ describe "upstream and downstream reference mτs of places and transitions" do
|
|
195
195
|
|
196
196
|
describe "upstream and downstream reference methods" do
|
197
197
|
before do
|
198
|
-
@t1 = @tç.new s: { @a => -1, @b => 1 }, rate: 1
|
198
|
+
@t1 = @tç.send :new, s: { @a => -1, @b => 1 }, rate: 1
|
199
199
|
end
|
200
200
|
|
201
201
|
it "should show on the referencers" do
|
@@ -209,8 +209,8 @@ describe "upstream and downstream reference mτs of places and transitions" do
|
|
209
209
|
|
210
210
|
describe "assignment action transitions" do
|
211
211
|
before do
|
212
|
-
@p = @pç.new default_marking: 1.0
|
213
|
-
@t = @tç.new codomain: @p, action: -> { 1 }, assignment_action: true
|
212
|
+
@p = @pç.send :new, default_marking: 1.0
|
213
|
+
@t = @tç.send :new, codomain: @p, action: -> { 1 }, assignment_action: true
|
214
214
|
end
|
215
215
|
|
216
216
|
it "should work" do
|
data/test/y_petri_test.rb
CHANGED
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.1.
|
4
|
+
version: 2.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- boris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: y_support
|