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