y_petri 2.1.10 → 2.1.11

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: 1cac00b355a03f2d444b9a4937721d9ad895666d
4
- data.tar.gz: 473f087960a3a4ed4b93cb2bef5262f0a4e8268e
3
+ metadata.gz: 6265e2cf605fc8fcadcbb29f89be1f12284d88dc
4
+ data.tar.gz: 96d5da54420128ee32cad846d1715dfe497a3841
5
5
  SHA512:
6
- metadata.gz: 3c453dbdc36a679375cd5b0439a19ba12c0346847632997fd82c2bffca63827b41d4703454bdef91df863749ba1b933fa7b2987db7f9ec3c4ba8ae71559c5da8
7
- data.tar.gz: d2e5603eb81a1633813beef6938fcccacf4eba4d7b1b8ce55ccda511763e1a414b1b5be671de54a3480add0d2f6a260d612aedafbb6a0943ca8330db1eb8fc80
6
+ metadata.gz: 224b656a992fa458689eebc065da7157f07ec65ea6837fe76b4a317e6fd6fbb80380114394f10a7fd9fe71048c575bc71d37f224dc6cfa31115d4337f96d9c93
7
+ data.tar.gz: 382dfd8a98e9d444902f5055a10953b6a2903e3055695fe65a5aa8451361eb6eb0fcb6e39e8c6be493a4f921c64ea27f3be13fb4e5c5726d1adb36a860f87b2a
@@ -23,7 +23,7 @@ module YPetri::Agent::PetriNetRelated
23
23
 
24
24
  # Elements and selections:
25
25
  #
26
- delegate :place, :transition, :element,
26
+ delegate :place, :transition, :element,
27
27
  :nets, :places, :transitions,
28
28
  to: :world
29
29
 
@@ -112,7 +112,7 @@ module YPetri::Agent::PetriNetRelated
112
112
 
113
113
  # Net constructor: Creates a new Net instance in the current world.
114
114
  #
115
- def Net *ordered, **named, &block
115
+ def Net *args, &block
116
116
  world.Net.send( :new, *ordered, **named, &block )
117
117
  end
118
118
 
@@ -101,10 +101,19 @@ module YPetri::Agent::SimulationRelated
101
101
  :set_clamp_collection, :ncc,
102
102
  :set_initial_marking_collection, :nimc,
103
103
  :set_simulation_settings_collection, :set_ssc,
104
- :new_simulation,
105
- :clamp_cc, :initial_marking_cc, :simulation_settings_cc,
104
+ :new_simulation, :clamp_cc,
105
+ :initial_marking_cc, :simulation_settings_cc,
106
106
  to: :world
107
107
 
108
+ delegate :pm, to: :simulation
109
+
110
+ # Pretty print the state.
111
+ #
112
+ def state
113
+ pp pm
114
+ return nil
115
+ end
116
+
108
117
  # Returns the simulation identified by the argument, or one at simulation
109
118
  # point, if no argument given. The simulation is identified in the same way
110
119
  # as for #simulation_point_to method.
@@ -341,7 +350,7 @@ module YPetri::Agent::SimulationRelated
341
350
  tt = transitions.nil? ? simulation.tt : tranisitions
342
351
  tt = simulation.tt( tt )
343
352
  tt -= simulation.ee( except )
344
- rec.delta( pp, transitions: tt, delta_time: options[:delta_time] )
353
+ rec.delta( pp, transitions: tt, Δt: options[:delta_time] )
345
354
  .plot( title: title, ylabel: ylabel, **options )
346
355
  end
347
356
  end # module YPetri::Agent::SimulationRelated
@@ -212,26 +212,25 @@ class YPetri::Net::DataSet < Hash
212
212
  def plot( time: nil, **nn )
213
213
  events = events()
214
214
  data_ss = series
215
- x_range = if time.is_a? Range then
215
+ x_range = if time.nil? then
216
+ "[#{events.first}:#{events.last}]"
217
+ elsif time.is_a? Range then
216
218
  "[#{time.begin}:#{time.end}]"
217
219
  else
218
220
  "[-0:#{SY::Time.magnitude( time ).amount rescue time}]"
219
221
  end
220
-
221
222
  Gnuplot.open do |gp|
222
223
  Gnuplot::Plot.new gp do |plot|
223
224
  plot.xrange x_range
224
225
  plot.title nn[:title] || "#{net} plot"
225
226
  plot.ylabel nn[:ylabel] || "Values"
226
227
  plot.xlabel nn[:xlabel] || "Time [s]"
227
-
228
- features.labels.zip( data_ss )
229
- .each { |label, data_array|
228
+ features.labels.zip( data_ss ).each do |label, data_array|
230
229
  plot.data << Gnuplot::DataSet.new( [ events, data_array ] ) { |ds|
231
230
  ds.with = "linespoints"
232
231
  ds.title = label
233
232
  }
234
- }
233
+ end
235
234
  end
236
235
  end
237
236
  end
@@ -27,6 +27,13 @@ class YPetri::Net::State::Features::Record < Array
27
27
  features.map { |f| fetch( f ).round( precision ) }
28
28
  end
29
29
 
30
+ # Pretty prints the record with feature names.
31
+ #
32
+ def print gap: 4, precision: 4
33
+ hsh = features.labels >> dump( precision: precision )
34
+ hsh.pretty_print_numeric_values gap: gap, precision: precision
35
+ end
36
+
30
37
  # Returns an identified feature, or fails.
31
38
  #
32
39
  def fetch feature
data/lib/y_petri/place.rb CHANGED
@@ -14,7 +14,6 @@ class YPetri::Place
14
14
 
15
15
  class << self
16
16
  ★ YPetri::World::Dependency
17
-
18
17
  private :new
19
18
  end
20
19
 
@@ -79,7 +78,9 @@ class YPetri::Place
79
78
 
80
79
  # Getter of +@marking+ attribute.
81
80
  #
82
- def m; @marking end
81
+ def m
82
+ @marking
83
+ end
83
84
  alias value m
84
85
 
85
86
  # This method, which acts as a simple getter of +@marking+ attribute if no
@@ -108,11 +109,15 @@ class YPetri::Place
108
109
 
109
110
  # Alias for #marking=
110
111
  #
111
- def value=( marking ); self.marking = marking end
112
+ def value=( marking )
113
+ self.marking = marking
114
+ end
112
115
 
113
116
  # Alias for #marking=
114
117
  #
115
- def m=( marking ); self.marking = marking end
118
+ def m=( marking )
119
+ self.marking = marking
120
+ end
116
121
 
117
122
  # Adds tokens to the place.
118
123
  #
@@ -5,7 +5,7 @@
5
5
  class YPetri::Simulation
6
6
  class Elements < Array
7
7
  ★ Dependency
8
-
8
+
9
9
  class << self
10
10
  # New collection constructor
11
11
  #
@@ -15,13 +15,13 @@ class YPetri::Simulation
15
15
  end
16
16
 
17
17
  delegate :simulation, to: "self.class"
18
-
18
+
19
19
  # Loads elements to this collection.
20
20
  #
21
21
  def load elements
22
22
  elements.each{ |e| push e }
23
23
  end
24
-
24
+
25
25
  # Creates a subset of this collection (of the same class).
26
26
  #
27
27
  def subset element_ids=nil, &block
@@ -4,7 +4,7 @@
4
4
  #
5
5
  module YPetri::Simulation::TransitionRepresentation::Type_A
6
6
  attr_reader :assignment_closure
7
-
7
+
8
8
  # Assignment action -- true for A transitions.
9
9
  #
10
10
  def A?
@@ -19,26 +19,58 @@ module YPetri::Simulation::TransitionRepresentation::Type_A
19
19
  false
20
20
  end
21
21
 
22
+ # Nil for assignment transitions. Though technically timeless, assignment
23
+ # transitions are considered outside the t/T types.
24
+ #
25
+ def T?
26
+ nil
27
+ end
28
+ alias timed? T?
29
+
30
+ # Nil for assignment transitions. Though technically timeless, assignment
31
+ # transitions are considered outside the t/T types.
32
+ #
33
+ def t?
34
+ nil
35
+ end
36
+ alias timeless? t?
37
+
38
+ # Nil for assignment transitions. Though technically timeless, assignment
39
+ # transitions are considered outside the s/S types.
40
+ #
41
+ def S?
42
+ nil
43
+ end
44
+ alias timed? T?
45
+
46
+ # Nil for assignment transitions. Though technically timeless, assignment
47
+ # transitions are considered outside the s/S types.
48
+ #
49
+ def s?
50
+ nil
51
+ end
52
+ alias timeless? t?
53
+
22
54
  # Initialization subroutine.
23
55
  #
24
56
  def init
25
57
  @assignment_closure = to_assignment_closure
26
58
  end
27
-
59
+
28
60
  # Returns the assignments, as they would happen if this A transition fired,
29
61
  # as hash places >> action.
30
62
  #
31
63
  def action
32
64
  act.select { |pl, v| pl.free? }
33
65
  end
34
-
66
+
35
67
  # Returns the assignments to all places, as they would happen if A transition
36
68
  # could change their values.
37
69
  #
38
70
  def act
39
71
  codomain >> Array( function.( *domain_marking ) )
40
72
  end
41
-
73
+
42
74
  # Builds an assignment closure, which, when called, directly affects the
43
75
  # simulation's marking vector (free places only).
44
76
  #
@@ -5,28 +5,28 @@
5
5
  class YPetri::Simulation::TransitionRepresentation
6
6
  module Type_t
7
7
  include Type_a
8
-
8
+
9
9
  # False for timed transitions.
10
10
  #
11
11
  def T?
12
12
  false
13
13
  end
14
14
  alias timed? T?
15
-
15
+
16
16
  # True for timed transitions.
17
17
  #
18
18
  def t?
19
19
  true
20
20
  end
21
21
  alias timeless? t?
22
-
22
+
23
23
  # Initialization subroutine.
24
24
  #
25
25
  def init
26
26
  super
27
27
  @function = source.action_closure
28
28
  end
29
-
29
+
30
30
  # Change, as it would happen if the transition fired, returned as hash
31
31
  # codomain places >> change.
32
32
  #
@@ -27,32 +27,32 @@ class YPetri::Simulation::TransitionRepresentation
27
27
  else fail TypeError, "Unknown tr. type #{source.type}!" end
28
28
  init
29
29
  end
30
-
30
+
31
31
  # The transition's type.
32
32
  #
33
33
  def type
34
34
  return :A if A?
35
35
  if T? then S? ? :TS : :Ts else S? ? :tS : :ts end
36
36
  end
37
-
37
+
38
38
  # Is this a TS transition?
39
39
  #
40
40
  def TS?
41
41
  type == :TS
42
42
  end
43
-
43
+
44
44
  # Is this a Ts transition?
45
45
  #
46
46
  def Ts?
47
47
  type == :Ts
48
48
  end
49
-
49
+
50
50
  # Is this a tS transition?
51
51
  #
52
52
  def tS?
53
53
  type == :tS
54
54
  end
55
-
55
+
56
56
  # Is this a ts transition?
57
57
  #
58
58
  def ts?
@@ -22,7 +22,7 @@ class YPetri::Simulation::Transitions
22
22
  klass.class_exec { include Type_s }
23
23
  end ).load subset( &:s? )
24
24
  end
25
-
25
+
26
26
  # Subset of S type transitions, if any.
27
27
  #
28
28
  def S
@@ -30,7 +30,7 @@ class YPetri::Simulation::Transitions
30
30
  klass.class_exec { include Type_S }
31
31
  end ).load subset( &:S? )
32
32
  end
33
-
33
+
34
34
  # Subset of t type transitions, if any.
35
35
  #
36
36
  def t
@@ -38,7 +38,7 @@ class YPetri::Simulation::Transitions
38
38
  klass.class_exec { include Type_t }
39
39
  end ).load subset( &:t? )
40
40
  end
41
-
41
+
42
42
  # Subset of T type transitions, if any.
43
43
  #
44
44
  def T
@@ -46,7 +46,7 @@ class YPetri::Simulation::Transitions
46
46
  klass.class_exec { include Type_T }
47
47
  end ).load subset( &:T? )
48
48
  end
49
-
49
+
50
50
  # Subset of ts type transitions, if any.
51
51
  #
52
52
  def ts
@@ -54,7 +54,7 @@ class YPetri::Simulation::Transitions
54
54
  klass.class_exec { include Type_ts }
55
55
  end ).load subset( &:ts? )
56
56
  end
57
-
57
+
58
58
  # Subset of tS type transitions, if any.
59
59
  #
60
60
  def tS
@@ -62,7 +62,7 @@ class YPetri::Simulation::Transitions
62
62
  klass.class_exec { include Type_tS }
63
63
  end ).load subset( &:tS? )
64
64
  end
65
-
65
+
66
66
  # Subset of Ts type transitions, if any.
67
67
  #
68
68
  def Ts
@@ -70,7 +70,7 @@ class YPetri::Simulation::Transitions
70
70
  klass.class_exec { include Type_Ts }
71
71
  end ).load subset( &:Ts? )
72
72
  end
73
-
73
+
74
74
  # Subset of TS type transitions, if any.
75
75
  #
76
76
  def TS
@@ -78,7 +78,7 @@ class YPetri::Simulation::Transitions
78
78
  klass.class_exec { include Type_TS }
79
79
  end ).load subset( &:TS? )
80
80
  end
81
-
81
+
82
82
  # Subset of A type transitions, if any.
83
83
  #
84
84
  def A
@@ -86,7 +86,7 @@ class YPetri::Simulation::Transitions
86
86
  klass.class_exec { include Type_A }
87
87
  end ).load subset( &:A? )
88
88
  end
89
-
89
+
90
90
  # Subset of a type transitions, if any.
91
91
  #
92
92
  def a
@@ -1,4 +1,4 @@
1
- #encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
3
  # Transition collection for YPetri::Simulation.
4
4
  #
@@ -1,4 +1,4 @@
1
1
  module YPetri
2
- VERSION = "2.1.10"
2
+ VERSION = "2.1.11"
3
3
  DEBUG = false
4
4
  end
data/lib/y_petri.rb CHANGED
@@ -8,6 +8,7 @@ require 'active_support/inflector'
8
8
  require 'gnuplot' # used for graph visualization
9
9
  require 'csv' # not used at the moment
10
10
  require 'graphviz' # used for Petri net visualization
11
+ require 'pp' # usef for pretty
11
12
 
12
13
  # The following are the YSupport components used by YPetri:
13
14
  require 'y_support/local_object' # object aware of its creation scope
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.10
4
+ version: 2.1.11
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 00:00:00.000000000 Z
11
+ date: 2013-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: y_support