y_petri 2.1.40 → 2.1.42

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6659d702646cc5152a102789cf4cb6ddc5f8daba
4
- data.tar.gz: 87b61e7babacfe37ce61c18060cda4dab75751ee
3
+ metadata.gz: 9369cc58d87b6dc7099f4852e0c1d65b6a115389
4
+ data.tar.gz: 7fb31e526e167b754b573a16e8d5cd0157beafa0
5
5
  SHA512:
6
- metadata.gz: 9763731c1823a33bfa7855b7841da3161fb53ec63c13bed00cb75620ace66b9bdd9c9ca25e2af906ed2afb5dbadb5256c6735a0389c311d9834551c404edc4d6
7
- data.tar.gz: a9d02f80ec783ac589e7d57ef089dc138c83ac15738a77d016f636bf47762fd8f97d78b0d29ef2c881a216d81c521c186ecde76d67a85809910666d032ba878d
6
+ metadata.gz: 90562c12028bb711b27e2cfce1e3436d0100da72c9aae434ed87c38146e7d85974a5fbda2c3ac953e7b093055aa1fff1c13e9d07878045e05a2b95d785068d91
7
+ data.tar.gz: 77d2083ca5e0db3c5c5c95ec214f0804608f65857e228e77fc1d32d13396be48c1fee4d84254eb600d43025cbc2d2c6c1788eceae651f1bdbaba637b49773d43
@@ -33,7 +33,8 @@ class YPetri::Net::DataSet < Hash
33
33
  :Marking, :Firing, :Flux, :Gradient, :Delta,
34
34
  to: "self.class"
35
35
 
36
- attr_reader :type # more like event_type, idea not matured yet
36
+ attr_reader :type, # more like event_type, idea not matured yet
37
+ :settings
37
38
 
38
39
  # Type of the dataset.
39
40
  #
@@ -75,9 +76,10 @@ class YPetri::Net::DataSet < Hash
75
76
 
76
77
  # Recreates the simulation at a given event label.
77
78
  #
78
- def reconstruct event: (fail "No event given!"),
79
- **settings # settings include marking clamps
79
+ def reconstruct event: (fail "No event given!"), **settings
80
+ # settings may include marking clamps, marking, inital marking...
80
81
  rec = interpolate( event )
82
+ settings = settings().merge settings if settings()
81
83
  if timed? then
82
84
  rec.reconstruct time: event, **settings
83
85
  else
@@ -136,6 +138,7 @@ class YPetri::Net::DataSet < Hash
136
138
  # Returns the data series for the specified features.
137
139
  #
138
140
  def series arg=nil
141
+
139
142
  return records.transpose if arg.nil?
140
143
  reduce_features( State().features( arg ) ).series
141
144
  end
@@ -174,12 +177,10 @@ class YPetri::Net::DataSet < Hash
174
177
  end
175
178
  end
176
179
  else
177
- line = reduced_features.map do |feature|
178
- if absent_features.include? feature then
179
- feature.extract_from( sim )
180
- else
181
- record.fetch feature
182
- end
180
+ line = reduced_features.map do |feat|
181
+ if absent_features.include? feat then
182
+ feat.extract_from( sim )
183
+ else record.fetch( feat ) end
183
184
  end
184
185
  end
185
186
  end
@@ -272,7 +273,8 @@ class YPetri::Net::DataSet < Hash
272
273
  time = nn.may_have :time, syn!: :time_range
273
274
  events = events()
274
275
  if element_ids.nil? then
275
- ff = if nn.empty? then features else net.State.features( nn ) end
276
+ nn_ff = nn.slice [ :marking, :flux, :firing, :gradient, :delta ]
277
+ ff = nn_ff.empty? ? features : net.State.features( nn_ff )
276
278
  else
277
279
  ff = net.State.Features.infer_from_elements( element_ids )
278
280
  end
@@ -297,6 +299,11 @@ class YPetri::Net::DataSet < Hash
297
299
  Gnuplot.open do |gp|
298
300
  Gnuplot::Plot.new gp do |plot|
299
301
  plot.xrange x_range
302
+ if nn.has? :yrange, syn!: :y_range then
303
+ if nn[:yrange].is_a? Range then
304
+ plot.yrange "[#{nn[:yrange].begin}:#{nn[:yrange].end}]"
305
+ else fail TypeError, "Argument :yrange is not a range!" end
306
+ end
300
307
  plot.title nn[:title] || "#{net} plot"
301
308
  plot.ylabel nn[:ylabel] || "Values"
302
309
  plot.xlabel nn[:xlabel] || "Time [s]"
@@ -71,9 +71,10 @@ class YPetri::Net::State::Features::Record < Array
71
71
  # has need for any special settings, these must be supplied to this method.
72
72
  # (Timed nets eg. require +:time+ named argument for successful construction.)
73
73
  #
74
- def reconstruct marking_clamps: {}, **settings
74
+ def reconstruct **settings
75
+ marking_clamps = settings[:marking_clamps] || {}
75
76
  m_hsh = features.marking.map { |feat| feat.place } >> marking
76
- net.simulation marking_clamps: {}, marking: m_hsh, **settings
77
+ net.simulation marking_clamps: marking_clamps, marking: m_hsh, **settings
77
78
  end
78
79
 
79
80
  # Expects a marking feature identifier (place identifier or Marking instance),
@@ -11,7 +11,14 @@ class YPetri::Simulation::Recorder
11
11
 
12
12
  SAMPLING_DECIMAL_PLACES = 5
13
13
 
14
- attr_reader :features, :recording
14
+ attr_reader :features
15
+
16
+ def recording
17
+ @recording.tap { |ds|
18
+ ds.instance_variable_set :@settings, simulation.settings( true )
19
+ }
20
+ end
21
+
15
22
  delegate :simulation, to: "self.class"
16
23
  delegate :reconstruct, :reduce, to: :recording
17
24
 
@@ -26,7 +33,7 @@ class YPetri::Simulation::Recorder
26
33
  if recording then reset! recording: recording else reset! end
27
34
  end
28
35
 
29
- # Construct a new recording based on +features+.
36
+ # Construct a new recording based on the parametrized class Recording().
30
37
  #
31
38
  def new_recording
32
39
  features.new_dataset
@@ -152,6 +152,7 @@ module YPetri::Simulation::Timed
152
152
  # +@recorder+ attribute.
153
153
  #
154
154
  def init **settings
155
+ method = settings[:method] # the simulation method
155
156
  if settings.has? :time, syn!: :time_range then # time range given
156
157
  case settings[:time]
157
158
  when Range then
@@ -175,6 +176,7 @@ module YPetri::Simulation::Timed
175
176
  reset_time!
176
177
  @step = settings[:step] || time_unit
177
178
  @default_sampling = settings[:sampling] || step
179
+ @core = Core().new( method: method, guarded: guarded )
178
180
  @recorder = Recorder().new sampling: settings[:sampling]
179
181
  end
180
182
 
@@ -19,7 +19,9 @@ class YPetri::Simulation
19
19
  # and initializes the +@recorder+ attribute.
20
20
  #
21
21
  def init **settings
22
+ method = settings[:method] # the simulation method
22
23
  init_core_and_recorder_subclasses
24
+ @core = Core().new( method: method, guarded: guarded )
23
25
  @recorder = Recorder().new # init the recorder
24
26
  end
25
27
 
@@ -99,11 +99,10 @@ class YPetri::Simulation
99
99
  # arguments has to be set for timed simulations.
100
100
  #
101
101
  def initialize **settings
102
- method = settings[:method] # the simulation method
103
102
  @guarded = settings[:guarded] # guarding on / off
104
103
  m_clamps = settings[:marking_clamps] || {}
105
104
  m = settings[:marking]
106
- init_m = settings[:initial_marking] || m || {}
105
+ init_m = settings[:initial_marking] || {}
107
106
  use_default_marking = if settings.has? :use_default_marking then
108
107
  settings[ :use_default_marking ]
109
108
  else true end
@@ -125,7 +124,17 @@ class YPetri::Simulation
125
124
  # Clamped places' mapping to the clamp values.
126
125
  @marking_clamps = MarkingClamps().load( m_clamps )
127
126
  # Free places' mapping to the initial marking values.
128
- @initial_marking = InitialMarking().load( init_m )
127
+
128
+ # Use :marking as :initial_marking when possible.
129
+ if m then
130
+ init_m_from_init_m = PlaceMapping().load( init_m )
131
+ init_m_from_marking = PlaceMapping().load( m )
132
+ rslt = init_m_from_marking.merge init_m_from_init_m
133
+ @initial_marking = InitialMarking().load( rslt )
134
+ else
135
+ @initial_marking = InitialMarking().load( init_m )
136
+ end
137
+
129
138
  # Set up the place and transition collections.
130
139
  @places.complete_initial_marking( use_default_marking: use_default_marking )
131
140
  # Correspondence matrix free --> all
@@ -157,8 +166,6 @@ class YPetri::Simulation
157
166
  @Ts_gradient_closure = transitions.Ts.gradient_closure
158
167
  @TS_rate_closure = transitions.TS.rate_closure
159
168
  end
160
- # Init the core.
161
- @core = Core().new( method: method, guarded: guarded )
162
169
  # Reset.
163
170
  if m then reset! marking: m else reset! end
164
171
  end
@@ -1,4 +1,4 @@
1
1
  module YPetri
2
- VERSION = "2.1.40"
2
+ VERSION = "2.1.42"
3
3
  DEBUG = false
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: y_petri
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.40
4
+ version: 2.1.42
5
5
  platform: ruby
6
6
  authors:
7
7
  - boris