y_petri 2.1.3 → 2.1.6
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 +25 -5
- data/lib/y_petri/agent/selection.rb +12 -10
- data/lib/y_petri/agent/simulation_related.rb +14 -58
- data/lib/y_petri/agent.rb +15 -17
- data/lib/y_petri/core/timed/euler.rb +13 -15
- data/lib/y_petri/core/timed/pseudo_euler.rb +22 -24
- data/lib/y_petri/core/timed/quasi_euler.rb +15 -17
- data/lib/y_petri/core/timed.rb +42 -44
- data/lib/y_petri/core/timeless/pseudo_euler.rb +12 -14
- data/lib/y_petri/core/timeless.rb +10 -7
- data/lib/y_petri/core.rb +3 -3
- data/lib/y_petri/dsl.rb +46 -46
- data/lib/y_petri/fixed_assets.rb +8 -0
- data/lib/y_petri/net/data_set.rb +238 -0
- data/lib/y_petri/net/own_state.rb +63 -0
- data/lib/y_petri/net/state/feature/delta.rb +98 -71
- data/lib/y_petri/net/state/feature/firing.rb +51 -54
- data/lib/y_petri/net/state/feature/flux.rb +51 -55
- data/lib/y_petri/net/state/feature/gradient.rb +55 -59
- data/lib/y_petri/net/state/feature/marking.rb +55 -59
- data/lib/y_petri/net/state/feature.rb +65 -67
- data/lib/y_petri/net/state/features/record.rb +150 -43
- data/lib/y_petri/net/state/features.rb +252 -96
- data/lib/y_petri/net/state.rb +114 -106
- data/lib/y_petri/net/visualization.rb +3 -2
- data/lib/y_petri/net.rb +29 -24
- data/lib/y_petri/place/arcs.rb +3 -3
- data/lib/y_petri/place/guard.rb +35 -117
- data/lib/y_petri/place/guarded.rb +86 -0
- data/lib/y_petri/place.rb +6 -3
- data/lib/y_petri/simulation/element_representation.rb +2 -2
- data/lib/y_petri/simulation/elements.rb +3 -1
- data/lib/y_petri/simulation/feature_set.rb +3 -1
- data/lib/y_petri/simulation/marking_vector.rb +3 -1
- data/lib/y_petri/simulation/place_mapping.rb +3 -1
- data/lib/y_petri/simulation/places.rb +1 -1
- data/lib/y_petri/simulation/recorder.rb +60 -54
- data/lib/y_petri/simulation/timed/recorder.rb +12 -1
- data/lib/y_petri/simulation/timed.rb +173 -172
- data/lib/y_petri/simulation/transitions/access.rb +97 -29
- data/lib/y_petri/simulation.rb +11 -9
- data/lib/y_petri/transition/{assignment.rb → A.rb} +2 -2
- data/lib/y_petri/transition/{timed.rb → T.rb} +2 -2
- data/lib/y_petri/transition/arcs.rb +3 -3
- data/lib/y_petri/transition/cocking.rb +3 -3
- data/lib/y_petri/transition/{init.rb → construction_convenience.rb} +6 -53
- data/lib/y_petri/transition/{ordinary_timeless.rb → t.rb} +2 -2
- data/lib/y_petri/transition/type.rb +103 -0
- data/lib/y_petri/transition/type_information.rb +103 -0
- data/lib/y_petri/transition/types.rb +107 -0
- data/lib/y_petri/transition/usable_without_world.rb +14 -0
- data/lib/y_petri/transition.rb +87 -101
- data/lib/y_petri/version.rb +1 -1
- data/lib/y_petri/world/dependency.rb +30 -28
- data/lib/y_petri/world.rb +10 -8
- data/test/acceptance/basic_usage_test.rb +3 -3
- data/test/acceptance/simulation_test.rb +3 -3
- data/test/acceptance/simulation_with_physical_units_test.rb +2 -2
- data/test/acceptance/token_game_test.rb +2 -2
- data/test/acceptance/visualization_test.rb +3 -3
- data/test/acceptance_tests.rb +2 -2
- data/test/agent_test.rb +1 -1
- data/test/net_test.rb +41 -17
- data/test/place_test.rb +1 -1
- data/test/simulation_test.rb +39 -39
- data/test/transition_test.rb +1 -1
- data/test/world_test.rb +1 -1
- data/test/y_petri_test.rb +1 -1
- metadata +13 -8
- data/lib/y_petri/net/state/features/dataset.rb +0 -135
- data/lib/y_petri/transition/construction.rb +0 -311
@@ -1,58 +1,54 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
end )
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
attr_reader :instances
|
28
|
-
|
29
|
-
alias __new__ new
|
30
|
-
|
31
|
-
def new id
|
32
|
-
instances[ id ]
|
33
|
-
end
|
34
|
-
|
35
|
-
def of transition_id
|
36
|
-
new transition_id
|
37
|
-
end
|
3
|
+
# Flux of a Petri net TS transition.
|
4
|
+
#
|
5
|
+
class YPetri::Net::State::Feature::Flux < YPetri::Net::State::Feature
|
6
|
+
attr_reader :transitionn
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def parametrize *args
|
10
|
+
Class.instance_method( :parametrize ).bind( self ).( *args ).tap do |ç|
|
11
|
+
ç.instance_variable_set( :@instances,
|
12
|
+
Hash.new do |hsh, id|
|
13
|
+
case id
|
14
|
+
when self then
|
15
|
+
hsh[ id.transition ]
|
16
|
+
when ç.net.Transition then
|
17
|
+
hsh[ id ] = ç.__new__( id )
|
18
|
+
else
|
19
|
+
hsh[ ç.net.transition( id ) ]
|
20
|
+
end
|
21
|
+
end )
|
38
22
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :instances
|
26
|
+
|
27
|
+
alias __new__ new
|
28
|
+
|
29
|
+
def new id
|
30
|
+
instances[ id ]
|
31
|
+
end
|
32
|
+
|
33
|
+
def of transition_id
|
34
|
+
new transition_id
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def initialize id
|
39
|
+
@transition = net.transition( id.is_a?( Flux ) ? id.transition : id )
|
40
|
+
end
|
41
|
+
|
42
|
+
def extract_from arg, **nn
|
43
|
+
case arg
|
44
|
+
when YPetri::Simulation then
|
45
|
+
arg.send( :TS_transitions, [ transition ] ).flux.first
|
46
|
+
else
|
47
|
+
fail TypeError, "Argument type not supported!"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def label
|
52
|
+
"Φ:#{transition.name}"
|
53
|
+
end
|
54
|
+
end # class YPetri::Net::State::Feature::Flux
|
@@ -1,75 +1,71 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
class Gradient < Feature
|
8
|
-
attr_reader :place, :transitions
|
3
|
+
# Gradient of a Petri net place caused by a certain set of T transitions.
|
4
|
+
#
|
5
|
+
class YPetri::Net::State::Feature::Gradient < YPetri::Net::State::Feature
|
6
|
+
attr_reader :place, :transitions
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
8
|
+
class << self
|
9
|
+
def parametrize *args
|
10
|
+
Class.instance_method( :parametrize ).bind( self ).( *args ).tap do |ç|
|
11
|
+
# First, prepare the hash of instances.
|
12
|
+
hsh = Hash.new do |ꜧ, id|
|
13
|
+
if id.is_a? self then
|
14
|
+
ꜧ[ [ id.place, transitions: id.transitions.sort( &:object_id ) ] ]
|
15
|
+
else
|
16
|
+
p = id.fetch( 0 )
|
17
|
+
tt = id
|
18
|
+
.fetch( 1 )
|
19
|
+
.fetch( :transitions )
|
20
|
+
if p.is_a? ç.net.Place and tt.all? { |t| t.is_a? ç.net.Transition }
|
21
|
+
if tt == tt.sort then
|
22
|
+
ꜧ[ id ] = ç.__new__( *id )
|
17
23
|
else
|
18
|
-
p
|
19
|
-
tt = id
|
20
|
-
.fetch( 1 )
|
21
|
-
.fetch( :transitions )
|
22
|
-
if p.is_a? ç.net.Place and tt.all? { |t| t.is_a? ç.net.Transition }
|
23
|
-
if tt == tt.sort then
|
24
|
-
ꜧ[ id ] = ç.__new__( *id )
|
25
|
-
else
|
26
|
-
ꜧ[ [ p, transitions: tt.sort ] ]
|
27
|
-
end
|
28
|
-
else
|
29
|
-
ꜧ[ [ ç.net.place( p ), transitions: ç.net.transitions( tt ) ] ]
|
30
|
-
end
|
24
|
+
ꜧ[ [ p, transitions: tt.sort ] ]
|
31
25
|
end
|
26
|
+
else
|
27
|
+
ꜧ[ [ ç.net.place( p ), transitions: ç.net.transitions( tt ) ] ]
|
32
28
|
end
|
33
|
-
# And then, assign it to the :@instances variable.
|
34
|
-
ç.instance_variable_set :@instances, hsh
|
35
29
|
end
|
36
30
|
end
|
31
|
+
# And then, assign it to the :@instances variable.
|
32
|
+
ç.instance_variable_set :@instances, hsh
|
33
|
+
end
|
34
|
+
end
|
37
35
|
|
38
|
-
|
36
|
+
attr_reader :instances
|
39
37
|
|
40
|
-
|
38
|
+
alias __new__ new
|
41
39
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
def new *args
|
41
|
+
return instances[ *args ] if args.size == 1
|
42
|
+
instances[ args ]
|
43
|
+
end
|
46
44
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
def of *args
|
46
|
+
new *args
|
47
|
+
end
|
48
|
+
end
|
51
49
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
50
|
+
def initialize *id
|
51
|
+
@place = net.place id.fetch( 0 )
|
52
|
+
@transitions = net.transitions id.fetch( 1 ).fetch( :transitions )
|
53
|
+
end
|
56
54
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
55
|
+
def extract_from arg, **nn
|
56
|
+
case arg
|
57
|
+
when YPetri::Simulation then
|
58
|
+
arg.send( :T_transitions, transitions ).gradient.fetch( place )
|
59
|
+
else
|
60
|
+
fail TypeError, "Argument type not supported!"
|
61
|
+
end
|
62
|
+
end
|
65
63
|
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
def to_s
|
65
|
+
place.name
|
66
|
+
end
|
69
67
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end # class Feature
|
75
|
-
end # YPetri::Net::State
|
68
|
+
def label
|
69
|
+
"∂:#{place.name}:#{transitions.size}tt"
|
70
|
+
end
|
71
|
+
end # class YPetri::Net::State::Feature::Gradient
|
@@ -1,62 +1,58 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
end )
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
attr_reader :instances
|
28
|
-
|
29
|
-
alias __new__ new
|
30
|
-
|
31
|
-
def new id
|
32
|
-
instances[ id ]
|
33
|
-
end
|
34
|
-
|
35
|
-
def of id
|
36
|
-
new id
|
37
|
-
end
|
3
|
+
# Marking of a Petri net place.
|
4
|
+
#
|
5
|
+
class YPetri::Net::State::Feature::Marking < YPetri::Net::State::Feature
|
6
|
+
attr_reader :place
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def parametrize *args
|
10
|
+
Class.instance_method( :parametrize ).bind( self ).( *args ).tap do |ç|
|
11
|
+
ç.instance_variable_set( :@instances,
|
12
|
+
Hash.new do |hsh, id|
|
13
|
+
case id
|
14
|
+
when self then
|
15
|
+
hsh[ id.place ]
|
16
|
+
when ç.net.Place then
|
17
|
+
hsh[ id ] = ç.__new__( id )
|
18
|
+
else
|
19
|
+
hsh[ ç.net.place( id ) ]
|
20
|
+
end
|
21
|
+
end )
|
38
22
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :instances
|
26
|
+
|
27
|
+
alias __new__ new
|
28
|
+
|
29
|
+
def new id
|
30
|
+
instances[ id ]
|
31
|
+
end
|
32
|
+
|
33
|
+
def of id
|
34
|
+
new id
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def initialize place
|
39
|
+
@place = net.place( place )
|
40
|
+
end
|
41
|
+
|
42
|
+
def extract_from arg, **nn
|
43
|
+
case arg
|
44
|
+
when YPetri::Simulation then
|
45
|
+
arg.m( [ place ] ).first
|
46
|
+
else
|
47
|
+
fail TypeError, "Argument type not supported!"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_s
|
52
|
+
place.name
|
53
|
+
end
|
54
|
+
|
55
|
+
def label
|
56
|
+
":#{place.name}"
|
57
|
+
end
|
58
|
+
end # YPetri::Net::State::Feature::Marking
|
@@ -1,79 +1,77 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
require_relative 'feature/delta'
|
3
|
+
# A feature of a Petri net.
|
4
|
+
#
|
5
|
+
class YPetri::Net::State::Feature
|
6
|
+
require_relative 'feature/marking'
|
7
|
+
require_relative 'feature/firing'
|
8
|
+
require_relative 'feature/gradient'
|
9
|
+
require_relative 'feature/flux'
|
10
|
+
require_relative 'feature/delta'
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
}
|
19
|
-
sç = ç.State
|
20
|
-
ç.instance_variable_set :@Marking, Marking.parametrize( State: sç )
|
21
|
-
ç.instance_variable_set :@Firing, Firing.parametrize( State: sç )
|
22
|
-
ç.instance_variable_set :@Gradient, Gradient.parametrize( State: sç )
|
23
|
-
ç.instance_variable_set :@Flux, Flux.parametrize( State: sç )
|
24
|
-
ç.instance_variable_set :@Delta, Delta.parametrize( State: sç )
|
12
|
+
class << self
|
13
|
+
def parametrize parameters
|
14
|
+
Class.new( self ).tap do |ç|
|
15
|
+
parameters.each_pair do |ß, val|
|
16
|
+
ç.define_singleton_method ß do val end
|
25
17
|
end
|
18
|
+
sç = ç.State
|
19
|
+
ç.instance_variable_set :@Marking, Marking.parametrize( State: sç )
|
20
|
+
ç.instance_variable_set :@Firing, Firing.parametrize( State: sç )
|
21
|
+
ç.instance_variable_set :@Gradient, Gradient.parametrize( State: sç )
|
22
|
+
ç.instance_variable_set :@Flux, Flux.parametrize( State: sç )
|
23
|
+
ç.instance_variable_set :@Delta, Delta.parametrize( State: sç )
|
26
24
|
end
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
27
|
+
delegate :net,
|
28
|
+
to: "State()"
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
def Marking id=L!
|
31
|
+
return @Marking if id.local_object?
|
32
|
+
case id
|
33
|
+
when Marking() then id
|
34
|
+
when Marking then Marking().of( id.place )
|
35
|
+
else Marking().of( id ) end # assume it's a place
|
36
|
+
end
|
38
37
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
38
|
+
def Firing id=L!
|
39
|
+
return @Firing if id.local_object?
|
40
|
+
case id
|
41
|
+
when Firing() then id
|
42
|
+
when Firing then Firing().of( id.transition )
|
43
|
+
else Firing().of( id ) end # assume it's a place
|
44
|
+
end
|
46
45
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
46
|
+
def Gradient id=L!, transitions: net.T_tt
|
47
|
+
return @Gradient if id.local_object?
|
48
|
+
case id
|
49
|
+
when Gradient() then id
|
50
|
+
when Gradient then
|
51
|
+
Gradient().of( id.place, transitions: id.transitions )
|
52
|
+
else Gradient().of( id, transitions: transitions ) end # assume it's a place
|
53
|
+
end
|
55
54
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
55
|
+
def Flux id=L!
|
56
|
+
return @Flux if id.local_object?
|
57
|
+
case id
|
58
|
+
when Flux() then id
|
59
|
+
when Flux then Flux().of( id.transition )
|
60
|
+
else Flux().of( id ) end # assume it's a place
|
61
|
+
end
|
63
62
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
63
|
+
def Delta id=L!, transitions: net.tt
|
64
|
+
return @Delta if id.local_object?
|
65
|
+
case id
|
66
|
+
when Delta() then id
|
67
|
+
when Delta then
|
68
|
+
Delta().of( id.place, transitions: id.transitions )
|
69
|
+
else Delta().of( id, transitions: transitions ) end # assume it's a place
|
70
|
+
end
|
71
|
+
end # class << self
|
73
72
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
end # YPetri::Net::State
|
73
|
+
delegate :net,
|
74
|
+
:State,
|
75
|
+
:Marking, :Firing, :Gradient, :Flux, :Delta,
|
76
|
+
to: "self.class"
|
77
|
+
end # class YPetri::Net::State::Feature
|