y_petri 2.1.37 → 2.1.39
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/net/data_set.rb +21 -5
- data/lib/y_petri/net/state/feature/delta.rb +2 -1
- data/lib/y_petri/net/state/feature/firing.rb +1 -1
- data/lib/y_petri/net/state/feature/flux.rb +1 -1
- data/lib/y_petri/net/state/feature/gradient.rb +2 -1
- data/lib/y_petri/net/state/feature/marking.rb +2 -1
- data/lib/y_petri/net/state/features/record.rb +2 -1
- data/lib/y_petri/net/state/features.rb +31 -2
- data/lib/y_petri/net/state.rb +2 -0
- data/lib/y_petri/simulation/marking_vector.rb +5 -2
- data/lib/y_petri/simulation/timed/recorder.rb +1 -6
- data/lib/y_petri/simulation.rb +4 -3
- 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: ebb46216e3628b410a2044e7e70c45bf30c2171b
|
4
|
+
data.tar.gz: 8a784e74c722d887fcde91472b535b8ae851aaf9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 203b23f6e4e783adf8b2c0c26e3b9bdb9f4a51e858eaf8a980ac88d6218c9d8ef313c7eafe641d8a76d07d689a5af24fed3d546f9e11fd6f12d8025163c1c5a7
|
7
|
+
data.tar.gz: 351303f21b5dca23a3ff11102ee50a338c89465b817961d17c2af61e3b8b2f209633d9d18c55c44d92aced8721002838832ea9edb250c78cba6d4949e9a2a865
|
data/lib/y_petri/net/data_set.rb
CHANGED
@@ -259,14 +259,30 @@ class YPetri::Net::DataSet < Hash
|
|
259
259
|
map { |lbl, rec| [ lbl, *rec ].join ',' }.join "\n"
|
260
260
|
end
|
261
261
|
|
262
|
-
# Plots the dataset. Takes several optional arguments: The list of
|
263
|
-
#
|
262
|
+
# Plots the dataset. Takes several optional arguments: The list of elements
|
263
|
+
# can be supplied as optional first ordered argument, which are then converted
|
264
|
+
# into features using +Net::State::Features.infer_from_elements+ method.
|
265
|
+
# Similarly, the features to exclude can be specifies as a list of elements
|
266
|
+
# (or a feature-specifying hash) supplied under +except:+ keyword. Otherwise,
|
267
|
+
# feature specification can be passed to the method as named arguments. If
|
268
|
+
# no feature specification is explicitly provided, it is assumed that all the
|
269
|
+
# features of this dataset are meant to be plotted.
|
264
270
|
#
|
265
|
-
def plot(
|
271
|
+
def plot( element_ids=nil, time: nil, except: [], **nn )
|
266
272
|
time = nn.may_have :time, syn!: :time_range
|
267
273
|
events = events()
|
268
|
-
|
269
|
-
|
274
|
+
if element_ids.nil? then
|
275
|
+
ff = if nn.empty? then features else net.State.features( nn ) end
|
276
|
+
else
|
277
|
+
ff = net.State.Features.infer_from_elements( element_ids )
|
278
|
+
end
|
279
|
+
xff = case except
|
280
|
+
when Array then net.State.Features.infer_from_elements( except )
|
281
|
+
when Hash then net.State.features( except )
|
282
|
+
else
|
283
|
+
fail TypeError, "Wrong type of :except argument: #{except.class}"
|
284
|
+
end
|
285
|
+
ff -= xff
|
270
286
|
data_ss = series( ff )
|
271
287
|
x_range = if time.nil? then
|
272
288
|
from = events.first || 0
|
@@ -147,6 +147,7 @@ class YPetri::Net::State::Feature::Delta < YPetri::Net::State::Feature
|
|
147
147
|
# Inspect string of the delta feature.
|
148
148
|
#
|
149
149
|
def inspect
|
150
|
-
"<Feature::Delta Δ:#{place.name || place}
|
150
|
+
"<Feature::Delta Δ:#{place.name || place}:[%s]>" %
|
151
|
+
transitions.names( true ).join( ', ' )
|
151
152
|
end
|
152
153
|
end # class YPetri::Net::State::Feature::Delta
|
@@ -87,6 +87,6 @@ class YPetri::Net::State::Feature::Firing < YPetri::Net::State::Feature
|
|
87
87
|
# Inspect string of the firing feature.
|
88
88
|
#
|
89
89
|
def inspect
|
90
|
-
"<Feature::Firing of #{transition}>"
|
90
|
+
"<Feature::Firing of #{transition.name ? transition.name : transition}>"
|
91
91
|
end
|
92
92
|
end # YPetri::Net::State::Feature::Firing
|
@@ -87,6 +87,6 @@ class YPetri::Net::State::Feature::Flux < YPetri::Net::State::Feature
|
|
87
87
|
# Inspect string of the flux feature.
|
88
88
|
#
|
89
89
|
def inspect
|
90
|
-
"<Feature::Flux of #{transition}>"
|
90
|
+
"<Feature::Flux of #{transition.name ? transition.name : transition}>"
|
91
91
|
end
|
92
92
|
end # class YPetri::Net::State::Feature::Flux
|
@@ -99,6 +99,7 @@ class YPetri::Net::State::Feature::Gradient < YPetri::Net::State::Feature
|
|
99
99
|
# Inspect string of the gradient feature.
|
100
100
|
#
|
101
101
|
def inspect
|
102
|
-
"<Feature::Gradient ∂:#{place.name || place}
|
102
|
+
"<Feature::Gradient ∂:#{place.name || place}:[%s]>" %
|
103
|
+
transitions.names( true ).join( ', ' )
|
103
104
|
end
|
104
105
|
end # class YPetri::Net::State::Feature::Gradient
|
@@ -59,6 +59,7 @@ class YPetri::Net::State::Feature::Marking < YPetri::Net::State::Feature
|
|
59
59
|
def extract_from arg, **nn
|
60
60
|
case arg
|
61
61
|
when YPetri::Simulation then
|
62
|
+
# now we have to investigate the case when place.name is A_phase, why the heck does it fail
|
62
63
|
arg.m( [ place ] ).first
|
63
64
|
else
|
64
65
|
fail TypeError, "Argument type not supported!"
|
@@ -86,6 +87,6 @@ class YPetri::Net::State::Feature::Marking < YPetri::Net::State::Feature
|
|
86
87
|
# Inspect string of the marking feature.
|
87
88
|
#
|
88
89
|
def inspect
|
89
|
-
"<Feature::Marking of #{place}>"
|
90
|
+
"<Feature::Marking of #{place.name ? place.name : place}>"
|
90
91
|
end
|
91
92
|
end # YPetri::Net::State::Feature::Marking
|
@@ -110,6 +110,29 @@ class YPetri::Net::State::Features < Array
|
|
110
110
|
new arg.map { |id| Delta id, transitions: transitions }
|
111
111
|
end
|
112
112
|
end
|
113
|
+
|
114
|
+
# Takes an array of the net elements (places and/or transitions), and infers
|
115
|
+
# a feature set from them in the following way: Places or place ids are
|
116
|
+
# converted to marking features. The remaining array elements are treated
|
117
|
+
# as transition ids, and are converted to either flux features (if the
|
118
|
+
# transition is timed), or firing features (if the transition is timeless).
|
119
|
+
#
|
120
|
+
def infer_from_elements( net_elements )
|
121
|
+
new net_elements.map { |e| net.element( e ) }.map { |e|
|
122
|
+
element, element_type = begin
|
123
|
+
[ net.place( e ), :place ]
|
124
|
+
rescue TypeError, NameError
|
125
|
+
[ net.transition( e ), :transition ]
|
126
|
+
end
|
127
|
+
case element_type
|
128
|
+
when :place then Marking( element )
|
129
|
+
when :transition then
|
130
|
+
fail TypeError, "Flux / firing features can only be auto-inferred " +
|
131
|
+
"from S transitions! (#{element} was given)" unless element.S?
|
132
|
+
element.timed? ? Flux( element ) : Firing( element )
|
133
|
+
end
|
134
|
+
}
|
135
|
+
end
|
113
136
|
end
|
114
137
|
|
115
138
|
delegate :State,
|
@@ -131,7 +154,14 @@ class YPetri::Net::State::Features < Array
|
|
131
154
|
# Extracts the features from a given target
|
132
155
|
#
|
133
156
|
def extract_from target, **nn
|
134
|
-
|
157
|
+
values = map { |feat| feat.extract_from( target, **nn ) }
|
158
|
+
new_record( values )
|
159
|
+
end
|
160
|
+
|
161
|
+
# Constructs a new record from these features.
|
162
|
+
#
|
163
|
+
def new_record values
|
164
|
+
Record().load values
|
135
165
|
end
|
136
166
|
|
137
167
|
# Constructs a new dataset from these features.
|
@@ -176,7 +206,6 @@ class YPetri::Net::State::Features < Array
|
|
176
206
|
|
177
207
|
# Returns the subset of marking features.
|
178
208
|
|
179
|
-
|
180
209
|
# Expects a marking feature identifier (place identifier or Marking instance),
|
181
210
|
# and returns the corresponding feature from this feature set. If an array of
|
182
211
|
# marking feature identifiers is supplied, it is mapped to the array of
|
data/lib/y_petri/net/state.rb
CHANGED
@@ -29,6 +29,8 @@ class YPetri::Net::State < Array
|
|
29
29
|
# Returns the feature identified by the argument.
|
30
30
|
#
|
31
31
|
def feature *id
|
32
|
+
puts "Hello from Net::State.feature. id is:"
|
33
|
+
Kernel::p id
|
32
34
|
fail ArgumentError, "No feature identifier!" if id.empty?
|
33
35
|
case id.first
|
34
36
|
when Feature() then id.first
|
@@ -94,8 +94,11 @@ class YPetri::Simulation
|
|
94
94
|
def reset! arg=self.class.starting
|
95
95
|
case arg
|
96
96
|
when Hash then
|
97
|
-
|
98
|
-
|
97
|
+
mp = simulation.PlaceMapping().load( arg )
|
98
|
+
updated = mp.each_with_object self.class.starting do |(place, value), mv|
|
99
|
+
mv.set place, value
|
100
|
+
end
|
101
|
+
reset! updated.column_to_a
|
99
102
|
else # array arg assumed
|
100
103
|
arg.each.to_a.zip( annotation ).map { |value, place| set place, value }
|
101
104
|
end
|
@@ -43,12 +43,7 @@ module YPetri::Simulation::Timed
|
|
43
43
|
t2 = next_time.round( 9 )
|
44
44
|
if t >= t2 then # it's time to sample
|
45
45
|
sample!
|
46
|
-
|
47
|
-
@next_time += sampling
|
48
|
-
rescue NoMethodError => err
|
49
|
-
( puts "Here go error #{err}"; Kernel::p @next_time; Kernel::p sampling )
|
50
|
-
end
|
51
|
-
|
46
|
+
@next_time += sampling
|
52
47
|
end
|
53
48
|
end
|
54
49
|
|
data/lib/y_petri/simulation.rb
CHANGED
@@ -115,7 +115,8 @@ class YPetri::Simulation
|
|
115
115
|
PlaceMapping: PlaceMapping,
|
116
116
|
InitialMarking: InitialMarking,
|
117
117
|
MarkingClamps: MarkingClamps,
|
118
|
-
MarkingVector: MarkingVector },
|
118
|
+
MarkingVector: MarkingVector },
|
119
|
+
with: { simulation: self } )
|
119
120
|
# Place and transition representation classes are their own namespaces.
|
120
121
|
Place().namespace!
|
121
122
|
Transition().namespace!
|
@@ -132,8 +133,8 @@ class YPetri::Simulation
|
|
132
133
|
# Correspondence matrix clamped --> all
|
133
134
|
@c2a = clamped_places.correspondence_matrix( places )
|
134
135
|
# Conditionally extend self depending on net's timedness.
|
135
|
-
|
136
|
-
|
136
|
+
anything_time = settings[:time] || settings[:step] || settings[:sampling]
|
137
|
+
extend( anything_time ? Timed : Timeless )
|
137
138
|
# Initialize the marking vector.
|
138
139
|
@m_vector = MarkingVector().zero
|
139
140
|
# Set up the transitions collection.
|
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.39
|
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-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: y_support
|