y_petri 2.1.16 → 2.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: faa600d44898af726d1c1fa7fe8e7e1304713539
4
- data.tar.gz: b9037c0ba92671423c1b7625b2d82a83a6411fb0
3
+ metadata.gz: 2328ba306b41ea9642ef62fca6a3636d4d095d41
4
+ data.tar.gz: 3c6681ef9997d219fa94451dcc5af1e67e3e643b
5
5
  SHA512:
6
- metadata.gz: 6b7be8d04a04a33505f903d2b173e715621d0be2b9a0c136b22d8fccc7a47174cf5dbb09dcb1fb66f540ec600cebd95aef06d23c28fc7a043f18ebb8bf9ac3cb
7
- data.tar.gz: e443882ed004b50a4b2e8727961a0ab0101ac9d21e29ec67a48bd8a009545f5ce08bf3878133a1c50ba04bace33fcb602ef59715847cf2610a5203cc53f6186c
6
+ metadata.gz: 229068a2726963c754dc2cb29c1a0403975dad8699469659ea94c1f13dce35e4ee52e3f6e7ffbbe3b88aae0f769e40767115c0d8b9c16f4628f7aad37584ced7
7
+ data.tar.gz: 165e17b35a5f4573a4eb6b36003d62d48223dd7ef75e262c03646fc3102d7ba6d79ed21907b307a9465b05a862ba079b8049a9bb955f30284d432805b6740342
data/lib/y_petri.rb CHANGED
@@ -1,15 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'active_support/core_ext/module/delegation'
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
- require 'pp' # usef for pretty
12
-
13
3
  # The following are the YSupport components used by YPetri:
14
4
  require 'y_support/local_object' # object aware of its creation scope
15
5
  require 'y_support/respond_to' # Symbol#~@ + RespondTo#===
@@ -22,6 +12,17 @@ require 'y_support/stdlib_ext/matrix' # matrix extensions
22
12
  require 'y_support/abstract_algebra' #
23
13
  require 'y_support/kde' # popup file with kioclient
24
14
 
15
+ # ActiveSupport components:
16
+ require 'active_support/core_ext/module/delegation'
17
+ require 'active_support/core_ext/array/extract_options'
18
+ require 'active_support/inflector'
19
+
20
+ # The following are the Ruby libraries used by YPetri:
21
+ require 'gnuplot' # used for graph visualization
22
+ require 'csv' # not used at the moment
23
+ require 'graphviz' # used for Petri net visualization
24
+ require 'pp' # usef for pretty
25
+
25
26
  require_relative 'y_petri/version'
26
27
  require_relative 'y_petri/fixed_assets'
27
28
  require_relative 'y_petri/world'
@@ -100,8 +100,8 @@ class YPetri::Net::DataSet < Hash
100
100
  end
101
101
  reduced_features = net.State.features *args
102
102
  rf_Record = reduced_features.Record
103
- reduced_features.new_dataset( type: type ).tap do |dataset|
104
- ( events >> records ).each_pair do |event, record|
103
+ reduced_features.new_dataset( type: type ).tap { |dataset|
104
+ ( events >> records ).each_pair { |event, record|
105
105
  absent_features = reduced_features - features()
106
106
  if absent_features.empty? then # it is a subset
107
107
  line = reduced_features.map { |feature| record.fetch feature }
@@ -132,8 +132,8 @@ class YPetri::Net::DataSet < Hash
132
132
  end
133
133
  end
134
134
  dataset.update event => rf_Record.load( line )
135
- end
136
- end
135
+ }
136
+ }
137
137
  end
138
138
 
139
139
  # Returns a subset of this dataset with only the specified marking features
@@ -237,4 +237,19 @@ class YPetri::Net::DataSet < Hash
237
237
  end
238
238
  end
239
239
  end
240
+
241
+ # Returns a string briefly discribing the dataset.
242
+ #
243
+ def to_s
244
+ "#<DataSet: " +
245
+ "#{keys.size} records, " +
246
+ "features: #{features}" +
247
+ ">"
248
+ end
249
+
250
+ # Inspect string of the instance.
251
+ #
252
+ def inspect
253
+ to_s
254
+ end
240
255
  end # YPetri::Net::Dataset
@@ -6,6 +6,8 @@ class YPetri::Net::State::Feature::Delta < YPetri::Net::State::Feature
6
6
  attr_reader :place, :transitions, :step
7
7
 
8
8
  class << self
9
+ # Customization of the Class#parametrize method.
10
+ #
9
11
  def parametrize *args
10
12
  Class.instance_method( :parametrize ).bind( self ).( *args ).tap do |ç|
11
13
  # First, prepare the hash of instances.
@@ -83,6 +85,11 @@ class YPetri::Net::State::Feature::Delta < YPetri::Net::State::Feature
83
85
  alias of new
84
86
  end
85
87
 
88
+ # The constructor of a delta feature takes one ordered argument (place
89
+ # identifier), and one named argument, +:transitions+, expecting an array
90
+ # of transition identifiers, whose contribution is taken into account in
91
+ # this delta feature.
92
+ #
86
93
  def initialize place, transitions: net.tt
87
94
  @place = net.place( place )
88
95
  @transitions = net.transitions( transitions )
@@ -119,11 +126,21 @@ class YPetri::Net::State::Feature::Delta < YPetri::Net::State::Feature
119
126
  ! timed?
120
127
  end
121
128
 
129
+ # A string briefly describing this delta feature.
130
+ #
122
131
  def to_s
123
132
  place.name
124
133
  end
125
134
 
135
+ # Label for the delta feature (to use in graphics etc.)
136
+ #
126
137
  def label
127
138
  "Δ:#{place.name}:#{transitions.size}tt"
128
139
  end
140
+
141
+ # Inspect string of the delta feature.
142
+ #
143
+ def inspect
144
+ "<Feature::Delta Δ:#{place.name || place}:#{transitions.size}tt>"
145
+ end
129
146
  end # class YPetri::Net::State::Feature::Delta
@@ -6,6 +6,8 @@ class YPetri::Net::State::Feature::Firing < YPetri::Net::State::Feature
6
6
  attr_reader :transition
7
7
 
8
8
  class << self
9
+ # Customization of the Class#parametrize method.
10
+ #
9
11
  def parametrize *args
10
12
  Class.instance_method( :parametrize ).bind( self ).( *args ).tap do |ç|
11
13
  ç.instance_variable_set( :@instances,
@@ -38,15 +40,23 @@ class YPetri::Net::State::Feature::Firing < YPetri::Net::State::Feature
38
40
  instances[ id ]
39
41
  end
40
42
 
43
+ # Alias of #new method.
44
+ #
41
45
  def of id
42
46
  new id
43
47
  end
44
48
  end
45
49
 
50
+ # The constructor of a marking feature takes exactly one argument (transition
51
+ # identifier).
52
+ #
46
53
  def initialize transition
47
54
  @transition = net.transition( transition )
48
55
  end
49
56
 
57
+ # Extracts the receiver marking feature from the argument. This can be
58
+ # typically a simulation instance.
59
+ #
50
60
  def extract_from arg, **nn
51
61
  case arg
52
62
  when YPetri::Simulation then
@@ -56,7 +66,21 @@ class YPetri::Net::State::Feature::Firing < YPetri::Net::State::Feature
56
66
  end
57
67
  end
58
68
 
69
+ # A string briefly describing the firing feature.
70
+ #
71
+ def to_s
72
+ label
73
+ end
74
+
75
+ # Label for the firing feature (to use in the graphics etc.)
76
+ #
59
77
  def label
60
78
  "F:#{transition.name}"
61
79
  end
80
+
81
+ # Inspect string of the firing feature.
82
+ #
83
+ def inspect
84
+ "<Feature::Firing of #{transition}>"
85
+ end
62
86
  end # YPetri::Net::State::Feature::Firing
@@ -6,6 +6,8 @@ class YPetri::Net::State::Feature::Flux < YPetri::Net::State::Feature
6
6
  attr_reader :transition
7
7
 
8
8
  class << self
9
+ # Customization of the Class#parametrize method.
10
+ #
9
11
  def parametrize *args
10
12
  Class.instance_method( :parametrize ).bind( self ).( *args ).tap do |ç|
11
13
  ç.instance_variable_set( :@instances,
@@ -38,15 +40,23 @@ class YPetri::Net::State::Feature::Flux < YPetri::Net::State::Feature
38
40
  instances[ id ]
39
41
  end
40
42
 
43
+ # Alias of #new method.
44
+ #
41
45
  def of transition_id
42
46
  new transition_id
43
47
  end
44
48
  end
45
49
 
50
+ # The constructor of a marking feature takes exactly one argument (transition
51
+ # identifier).
52
+ #
46
53
  def initialize id
47
54
  @transition = net.transition( id.is_a?( Flux ) ? id.transition : id )
48
55
  end
49
56
 
57
+ # Extracts the receiver marking feature from the argument. This can be
58
+ # typically a simulation instance.
59
+ #
50
60
  def extract_from arg, **nn
51
61
  case arg
52
62
  when YPetri::Simulation then
@@ -56,7 +66,21 @@ class YPetri::Net::State::Feature::Flux < YPetri::Net::State::Feature
56
66
  end
57
67
  end
58
68
 
69
+ # A string briefly describing the flux feature.
70
+ #
71
+ def to_s
72
+ label
73
+ end
74
+
75
+ # Label for the flux feature (to use in the graphics etc.)
76
+ #
59
77
  def label
60
78
  "Φ:#{transition.name}"
61
79
  end
80
+
81
+ # Inspect string of the flux feature.
82
+ #
83
+ def inspect
84
+ "<Feature::Flux of #{transition}>"
85
+ end
62
86
  end # class YPetri::Net::State::Feature::Flux
@@ -6,6 +6,8 @@ class YPetri::Net::State::Feature::Gradient < YPetri::Net::State::Feature
6
6
  attr_reader :place, :transitions
7
7
 
8
8
  class << self
9
+ # Customization of the Class#parametrize method.
10
+ #
9
11
  def parametrize *args
10
12
  Class.instance_method( :parametrize ).bind( self ).( *args ).tap do |ç|
11
13
  # First, prepare the hash of instances.
@@ -45,21 +47,28 @@ class YPetri::Net::State::Feature::Gradient < YPetri::Net::State::Feature
45
47
 
46
48
  alias __new__ new
47
49
 
50
+ # Constructor #new is redefined to use instance cache.
51
+ #
48
52
  def new *args
49
53
  return instances[ *args ] if args.size == 1
50
54
  instances[ args ]
51
55
  end
52
-
53
- def of *args
54
- new *args
55
- end
56
+ alias of new
56
57
  end
57
58
 
59
+ # The constructor of a gradient feature takes one ordered argument (place
60
+ # identifier), and one named argument, +:transitions+, expecting an array
61
+ # of transition identifiers, whose contribution is taken into account in
62
+ # this gradient feature.
63
+ #
58
64
  def initialize *id
59
65
  @place = net.place id.fetch( 0 )
60
66
  @transitions = net.transitions id.fetch( 1 ).fetch( :transitions )
61
67
  end
62
68
 
69
+ # Extracts the receiver gradient feature from the argument. This can be
70
+ # typically a simulation instance.
71
+ #
63
72
  def extract_from arg, **nn
64
73
  case arg
65
74
  when YPetri::Simulation then
@@ -69,11 +78,21 @@ class YPetri::Net::State::Feature::Gradient < YPetri::Net::State::Feature
69
78
  end
70
79
  end
71
80
 
81
+ # A string briefly describing the gradient feature.
82
+ #
72
83
  def to_s
73
- place.name
84
+ label
74
85
  end
75
86
 
87
+ # Label for the gradient feature (to use in graphics etc.)
88
+ #
76
89
  def label
77
90
  "∂:#{place.name}:#{transitions.size}tt"
78
91
  end
92
+
93
+ # Inspect string of the gradient feature.
94
+ #
95
+ def inspect
96
+ "<Feature::Gradient ∂:#{place.name || place}:#{transitions.size}tt>"
97
+ end
79
98
  end # class YPetri::Net::State::Feature::Gradient
@@ -6,6 +6,8 @@ class YPetri::Net::State::Feature::Marking < YPetri::Net::State::Feature
6
6
  attr_reader :place
7
7
 
8
8
  class << self
9
+ # Customization of the Class#parametrize method.
10
+ #
9
11
  def parametrize *args
10
12
  Class.instance_method( :parametrize ).bind( self ).( *args ).tap do |ç|
11
13
  ç.instance_variable_set( :@instances,
@@ -37,15 +39,23 @@ class YPetri::Net::State::Feature::Marking < YPetri::Net::State::Feature
37
39
  instances[ id ]
38
40
  end
39
41
 
42
+ # Alias of #new method.
43
+ #
40
44
  def of id
41
45
  new id
42
46
  end
43
47
  end
44
48
 
49
+ # The constructor of a marking feature takes exactly one argument (place
50
+ # identifier).
51
+ #
45
52
  def initialize place
46
53
  @place = net.place( place )
47
54
  end
48
55
 
56
+ # Extracts the receiver marking feature from the argument. This can be
57
+ # typically a simulation instance.
58
+ #
49
59
  def extract_from arg, **nn
50
60
  case arg
51
61
  when YPetri::Simulation then
@@ -55,11 +65,21 @@ class YPetri::Net::State::Feature::Marking < YPetri::Net::State::Feature
55
65
  end
56
66
  end
57
67
 
68
+ # A string briefly describing the marking feature.
69
+ #
58
70
  def to_s
59
- place.name
71
+ "m:#{label}"
60
72
  end
61
73
 
74
+ # Label for the marking feature (to use in graphics etc.)
75
+ #
62
76
  def label
63
77
  ":#{place.name}"
64
78
  end
79
+
80
+ # Inspect string of the marking feature.
81
+ #
82
+ def inspect
83
+ "<Feature::Marking of #{place}>"
84
+ end
65
85
  end # YPetri::Net::State::Feature::Marking
@@ -279,4 +279,18 @@ class YPetri::Net::State::Features < Array
279
279
  end
280
280
  end
281
281
  end
282
+
283
+ # Returns a string briefly describing the feature set.
284
+ #
285
+ def to_s
286
+ group_by( &:type )
287
+ .map { |feature_type, ff| "#{feature_type}: #{ff.size}" }
288
+ .join ', '
289
+ end
290
+
291
+ # Inspect string of the instance.
292
+ #
293
+ def inspect
294
+ "#<Features: #{to_s}>"
295
+ end
282
296
  end # YPetri::Net::State::Features
@@ -1,4 +1,4 @@
1
1
  module YPetri
2
- VERSION = "2.1.16"
2
+ VERSION = "2.1.17"
3
3
  DEBUG = false
4
4
  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.1.16
4
+ version: 2.1.17
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-16 00:00:00.000000000 Z
11
+ date: 2013-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: y_support