y_petri 2.1.31 → 2.1.33
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/simulation_related.rb +3 -1
- data/lib/y_petri/dsl.rb +2 -0
- data/lib/y_petri/net/data_set.rb +57 -6
- data/lib/y_petri/net/state/features/record.rb +8 -0
- data/lib/y_petri/simulation.rb +1 -1
- data/lib/y_petri/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43e532fceaec5c32c5ee7ca4364a2165f134d94f
|
4
|
+
data.tar.gz: 2ca12cc72e7f7372d513eaccea15f024a6eda626
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab51a968eeb6c30f87d5f12dba00311a32e5bb6042ba0cc8a4d638cdecf352294a32da4dd5737f96f4a3da8220801d858a8cd4b120792f2837124edd9592b549
|
7
|
+
data.tar.gz: 2f4e63e8c7d3ec1d619b8685886bc66cba4a899b46c4ac69f6ca6929df878110e6015970d3b0cc99e696d2b4f994d5855029cc913ba04b05d6ce05bb992e0665
|
data/lib/y_petri/dsl.rb
CHANGED
@@ -42,6 +42,8 @@ module YPetri
|
|
42
42
|
:clamp_cc, :initial_marking_cc, :simulation_settings_cc,
|
43
43
|
:simulation_point_position,
|
44
44
|
:simulation,
|
45
|
+
:pm, # deleg. to simulation
|
46
|
+
:recording, # deleg. to simulation
|
45
47
|
:clamp_collection, :cc,
|
46
48
|
:initial_marking_collection, :imc,
|
47
49
|
:simulation_settings_collection, :ssc,
|
data/lib/y_petri/net/data_set.rb
CHANGED
@@ -41,12 +41,32 @@ class YPetri::Net::DataSet < Hash
|
|
41
41
|
type == :timed
|
42
42
|
end
|
43
43
|
|
44
|
-
# Returns
|
44
|
+
# Returns the Record instance corresponding to the given recorded event.
|
45
45
|
#
|
46
46
|
def record( event )
|
47
47
|
features.load( fetch event )
|
48
48
|
end
|
49
49
|
|
50
|
+
# Returns the nearest event smaller or equal to the supplied event-type
|
51
|
+
# argument. The second optional ordered argument, true by default, controls
|
52
|
+
# whether equality is accepted. If set to false, then the nearest _smaller_
|
53
|
+
# event is sought.
|
54
|
+
#
|
55
|
+
def floor( event, equal_ok=true )
|
56
|
+
e = events.ascending_floor( event, equal_ok )
|
57
|
+
e.nil? ? nil : e
|
58
|
+
end
|
59
|
+
|
60
|
+
# Returns the nearest event greater or equal to the supplied event-type
|
61
|
+
# argument. The second optional ordered argument, true by default, controls
|
62
|
+
# whether equality is accepted. If set to false, then the nearest _greater_
|
63
|
+
# event is sought.
|
64
|
+
#
|
65
|
+
def ceiling( event, equal_ok=true )
|
66
|
+
e = events.ascending_ceiling( event, equal_ok )
|
67
|
+
e.nil? ? nil : e
|
68
|
+
end
|
69
|
+
|
50
70
|
# Revives records from values.
|
51
71
|
#
|
52
72
|
def records
|
@@ -69,18 +89,49 @@ class YPetri::Net::DataSet < Hash
|
|
69
89
|
# Record class instance.
|
70
90
|
#
|
71
91
|
def interpolate( event )
|
72
|
-
# TODO: This whole interpolation thing is unfinished.
|
73
92
|
begin
|
74
93
|
record( event )
|
75
94
|
rescue KeyError => msg
|
76
|
-
timed? or raise TypeError, "Event #{event}
|
95
|
+
timed? or raise TypeError, "Event #{event} not recorded! (%s)" %
|
77
96
|
"simulation type: #{type.nil? ? 'nil' : type}"
|
78
|
-
|
79
|
-
|
80
|
-
|
97
|
+
# (Remark: #floor, #ceiling supported by timed datasets only)
|
98
|
+
fe = floor( event )
|
99
|
+
fail "Event #{event} has no floor!" if fe.nil?
|
100
|
+
f = Matrix.column_vector record( fe )
|
101
|
+
ce = ceiling( event )
|
102
|
+
fail "Event #{event} has no ceiling!" if ce.nil?
|
103
|
+
c = Matrix.column_vector record( ce )
|
104
|
+
rslt = f + ( c - f ) / ( ce - fe ) * ( event - fe )
|
105
|
+
features.load( rslt.column_to_a )
|
81
106
|
end
|
82
107
|
end
|
83
108
|
|
109
|
+
# Resamples the recording.
|
110
|
+
#
|
111
|
+
def resample **nn
|
112
|
+
time_range = nn.may_have( :time_range, syn!: :time ) ||
|
113
|
+
events.first .. events.last
|
114
|
+
sampling = nn.must_have :sampling
|
115
|
+
t0, target_time = time_range.begin, time_range.end
|
116
|
+
t = t0
|
117
|
+
loop.with_object self.class.new do |o|
|
118
|
+
o.update t => interpolate( t )
|
119
|
+
t += sampling
|
120
|
+
return o if t > target_time
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# Computes the distance to another dataset.
|
125
|
+
#
|
126
|
+
def distance( other )
|
127
|
+
sum_of_sq = events
|
128
|
+
.map { |e| [ e, other.interpolate( e ) ] }
|
129
|
+
.map { |rec1, rec2| rec1.euclidean_distance rec2 }
|
130
|
+
.map { |dist| dist * dist }
|
131
|
+
.reduce( :+ )
|
132
|
+
sum_of_sq ** 0.5
|
133
|
+
end
|
134
|
+
|
84
135
|
# Returns the data series for the specified features.
|
85
136
|
#
|
86
137
|
def series arg=nil
|
@@ -162,4 +162,12 @@ class YPetri::Net::State::Features::Record < Array
|
|
162
162
|
end
|
163
163
|
end
|
164
164
|
end
|
165
|
+
|
166
|
+
# Computes the Euclidean distance from another record.
|
167
|
+
#
|
168
|
+
def euclidean_distance other
|
169
|
+
sum_of_sq = features.map { |f|
|
170
|
+
fetch( f ) - other.fetch( f )
|
171
|
+
}.map { |dist| dist * dist }.reduce( :+ )
|
172
|
+
end
|
165
173
|
end # class YPetri::Net::State::Features::Record
|
data/lib/y_petri/simulation.rb
CHANGED
@@ -97,7 +97,7 @@ class YPetri::Simulation
|
|
97
97
|
m = settings[:marking]
|
98
98
|
init_m = settings[:initial_marking] || {}
|
99
99
|
use_default_marking = if settings.has? :use_default_marking then
|
100
|
-
settings[:use_default_marking]
|
100
|
+
settings[ :use_default_marking ]
|
101
101
|
else true end
|
102
102
|
# Time-independent simulation settings received, constructing param. classes
|
103
103
|
param_class!( { Place: PlaceRepresentation,
|
data/lib/y_petri/version.rb
CHANGED
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.
|
4
|
+
version: 2.1.33
|
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
|
+
date: 2013-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: y_support
|