y_petri 1.0.0 → 2.0.0
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 +4 -4
- data/lib/y_petri/place.rb +1 -3
- data/lib/y_petri/transition.rb +33 -46
- data/lib/y_petri/version.rb +1 -1
- data/lib/y_petri.rb +1 -1
- data/test/y_petri_test.rb +4 -5
- 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: 0bb49f2d95c64d55d7d355f4bed22837fb025e63
|
4
|
+
data.tar.gz: 53eec6b98e60b0f123f023e7378a1045dd90602e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68d61d8dd2010ccf3384fd3675da3f69607016748e61b3167cc85996ec3cba0914d2a3ce33c4af18c413024295d59868467ffc6160dfd59c2511d01f6ee96484
|
7
|
+
data.tar.gz: 1756697847bc3efcc7989c132437856a88b0ffce39883748ee3c5b6850befa28d580d81c309aade3e84cedaa7722d174b549b792aa3a386545984082e4be83ac
|
data/lib/y_petri/place.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# -*- coding: utf-8 -*-
|
3
2
|
# This class represents Petri net places.
|
4
3
|
#
|
5
4
|
class YPetri::Place
|
@@ -63,7 +62,6 @@ class YPetri::Place
|
|
63
62
|
def arcs
|
64
63
|
upstream_arcs | downstream_arcs
|
65
64
|
end
|
66
|
-
alias :connectivity :arcs
|
67
65
|
|
68
66
|
# Returns the union of domains of the transitions associated
|
69
67
|
# with the upstream arcs of this place.
|
data/lib/y_petri/transition.rb
CHANGED
@@ -161,15 +161,8 @@ module YPetri
|
|
161
161
|
def domain_pp; domain.map &:name end
|
162
162
|
alias :upstream_pp :domain_pp
|
163
163
|
|
164
|
-
#
|
165
|
-
#
|
166
|
-
def domain_pp_sym; domain_pp.map &:to_sym end
|
167
|
-
alias :upstream_pp_sym :domain_pp_sym
|
168
|
-
alias :domain_ppß :domain_pp_sym
|
169
|
-
alias :ustream_ppß :domain_pp_sym
|
170
|
-
|
171
|
-
# Codomain, 'downstream arcs', or 'action arcs' is a collection of places,
|
172
|
-
# whose marking is directly changed by firing the trinsition.
|
164
|
+
# Codomain, 'downstream arcs', or 'action arcs', is a collection of places,
|
165
|
+
# whose marking is directly changed by this transition's firing.
|
173
166
|
#
|
174
167
|
attr_reader :codomain
|
175
168
|
alias :codomain_arcs :codomain
|
@@ -184,26 +177,13 @@ module YPetri
|
|
184
177
|
def codomain_pp; codomain.map &:name end
|
185
178
|
alias :downstream_pp :codomain_pp
|
186
179
|
|
187
|
-
#
|
188
|
-
#
|
189
|
-
def codomain_pp_sym; codomain_pp.map &:to_sym end
|
190
|
-
alias :downstream_pp_sym :codomain_pp_sym
|
191
|
-
alias :codomain_ppß :codomain_pp_sym
|
192
|
-
alias :downstream_ppß :codomain_pp_sym
|
193
|
-
|
194
|
-
# Returns the union of action arcs and test arcs.
|
180
|
+
# Union of action arcs and test arcs.
|
195
181
|
#
|
196
182
|
def arcs; domain | codomain end
|
197
|
-
alias :connectivity :arcs
|
198
183
|
|
199
|
-
# Returns
|
184
|
+
# Returns names of the (places connected to) the transition's arcs.
|
200
185
|
#
|
201
|
-
def
|
202
|
-
|
203
|
-
# Returns connectivity as name symbols.
|
204
|
-
#
|
205
|
-
def cc_sym; cc.map &:to_sym end
|
206
|
-
alias :ccß :cc_sym
|
186
|
+
def aa; arcs.map &:name end
|
207
187
|
|
208
188
|
# Is the transition stoichiometric?
|
209
189
|
#
|
@@ -397,11 +377,10 @@ module YPetri
|
|
397
377
|
def initialize *args
|
398
378
|
# do the big work of checking in the arguments
|
399
379
|
check_in_arguments *args
|
400
|
-
# Inform
|
401
|
-
|
402
|
-
|
403
|
-
# transitions initialize uncocked
|
404
|
-
@cocked = false
|
380
|
+
# Inform upstream and downstream places they have been connected:
|
381
|
+
inform_upstream_places
|
382
|
+
inform_downstream_places
|
383
|
+
@cocked = false # transitions initialize uncocked
|
405
384
|
end
|
406
385
|
|
407
386
|
# Marking of the domain places.
|
@@ -419,28 +398,28 @@ module YPetri
|
|
419
398
|
# Result of the transition's "function", regardless of the #enabled? status.
|
420
399
|
#
|
421
400
|
def action Δt=nil
|
422
|
-
raise
|
401
|
+
raise ArgumentError, "Δtime argument required for timed transitions!" if
|
423
402
|
timed? and Δt.nil?
|
424
403
|
# the code here looks awkward, because I was trying to speed it up
|
425
404
|
if has_rate? then
|
426
405
|
if stoichiometric? then
|
427
406
|
rate = rate_closure.( *domain_marking )
|
428
|
-
stoichiometry.map{ |coeff| rate * coeff * Δt }
|
407
|
+
stoichiometry.map { |coeff| rate * coeff * Δt }
|
429
408
|
else # assuming correct return value arity from the rate closure:
|
430
|
-
rate_closure.( *domain_marking ).map{ |e| component * Δt }
|
409
|
+
rate_closure.( *domain_marking ).map { |e| component * Δt }
|
431
410
|
end
|
432
411
|
else # rateless
|
433
412
|
if timed? then
|
434
413
|
if stoichiometric? then
|
435
414
|
rslt = action_closure.( Δt, *domain_marking )
|
436
|
-
stoichiometry.map{ |coeff| rslt * coeff }
|
415
|
+
stoichiometry.map { |coeff| rslt * coeff }
|
437
416
|
else
|
438
417
|
action_closure.( Δt, *domain_marking ) # caveat result arity!
|
439
418
|
end
|
440
419
|
else # timeless
|
441
420
|
if stoichiometric? then
|
442
421
|
rslt = action_closure.( *domain_marking )
|
443
|
-
stoichiometry.map{ |coeff| rslt * coeff }
|
422
|
+
stoichiometry.map { |coeff| rslt * coeff }
|
444
423
|
else
|
445
424
|
action_closure.( *domain_marking ) # caveat result arity!
|
446
425
|
end
|
@@ -466,7 +445,7 @@ module YPetri
|
|
466
445
|
# check if the marking after the action would still be positive
|
467
446
|
enabled = codomain
|
468
447
|
.zip( act )
|
469
|
-
.all?{ |place, change| place.marking.to_f >= -change.to_f }
|
448
|
+
.all? { |place, change| place.marking.to_f >= -change.to_f }
|
470
449
|
if enabled then act else
|
471
450
|
raise "firing of #{self}#{ Δt ? ' with Δtime %s' % Δt : '' } " +
|
472
451
|
"would result in negative marking"
|
@@ -499,7 +478,7 @@ module YPetri
|
|
499
478
|
return true
|
500
479
|
end
|
501
480
|
|
502
|
-
#
|
481
|
+
# Fires the transition regardless of cocked/uncocked status.
|
503
482
|
#
|
504
483
|
def fire!( Δt=nil )
|
505
484
|
raise AErr, "Δtime required for timed transitions!" if timed? && Δt.nil?
|
@@ -626,14 +605,11 @@ module YPetri
|
|
626
605
|
:propensity,
|
627
606
|
:rate_closure,
|
628
607
|
:flux_closure,
|
629
|
-
:propensity_closure
|
630
|
-
:Φ,
|
631
|
-
:φ ]
|
608
|
+
:propensity_closure ]
|
632
609
|
oo.may_have :action, syn!: :action_closure
|
633
610
|
oo.may_have :timed
|
634
611
|
|
635
|
-
# was the rate was given?
|
636
|
-
@has_rate = oo.has? :rate
|
612
|
+
@has_rate = oo.has? :rate # was the rate was given?
|
637
613
|
|
638
614
|
# is the transition stoichiometric (S) or nonstoichiometric (s)?
|
639
615
|
@stoichiometric = oo.has? :stoichiometry
|
@@ -670,7 +646,7 @@ module YPetri
|
|
670
646
|
begin
|
671
647
|
place( pl_id )
|
672
648
|
rescue NameError
|
673
|
-
raise
|
649
|
+
raise TypeError, "#{c} member #{pl_id} does not specify a valid place!"
|
674
650
|
end
|
675
651
|
end.aT what_is_collection, "not contain duplicate places" do |collection|
|
676
652
|
collection == collection.uniq
|
@@ -753,8 +729,7 @@ module YPetri
|
|
753
729
|
if oo.has? :timed then
|
754
730
|
_timed = oo[:timed]
|
755
731
|
# Time to worry about the domain_missing
|
756
|
-
if domain == :missing then
|
757
|
-
# figure user's intent from closure arity
|
732
|
+
if domain == :missing then # figure user's intent from closure arity
|
758
733
|
_domain = if action_λ.arity == ( _timed ? 1 : 0 ) then
|
759
734
|
[] # user meant empty domain
|
760
735
|
else
|
@@ -878,7 +853,19 @@ module YPetri
|
|
878
853
|
false
|
879
854
|
end
|
880
855
|
end
|
881
|
-
|
856
|
+
|
857
|
+
# Informs upstream places that they are connected to this transition.
|
858
|
+
#
|
859
|
+
def inform_upstream_places
|
860
|
+
upstream_places.each { |p| p.send :register_downstream_transition, self }
|
861
|
+
end
|
862
|
+
|
863
|
+
# Informs downstream places that they are connected to this transition.
|
864
|
+
#
|
865
|
+
def inform_downstream_places
|
866
|
+
downstream_places.each { |p| p.send :register_upstream_transition, self }
|
867
|
+
end
|
868
|
+
|
882
869
|
# Place class pertinent herein. Provided for the purpose of parametrized
|
883
870
|
# subclassing; expected to be overriden in the subclasses.
|
884
871
|
#
|
data/lib/y_petri/version.rb
CHANGED
data/lib/y_petri.rb
CHANGED
@@ -13,7 +13,7 @@ require 'y_support/core_ext/hash'
|
|
13
13
|
require 'y_support/core_ext/array'
|
14
14
|
require 'y_support/stdlib_ext/matrix'
|
15
15
|
|
16
|
-
require '
|
16
|
+
require 'y_support/abstract_algebra'
|
17
17
|
|
18
18
|
require 'active_support/core_ext/module/delegation'
|
19
19
|
require 'active_support/core_ext/array/extract_options'
|
data/test/y_petri_test.rb
CHANGED
@@ -56,7 +56,6 @@ describe ::YPetri::Place do
|
|
56
56
|
assert_equal [], @p.downstream_transitions
|
57
57
|
# #arcs & aliasesnn
|
58
58
|
assert_equal [], @p.arcs
|
59
|
-
assert_equal [], @p.connectivity
|
60
59
|
# #precedents & aliases
|
61
60
|
assert_equal [], @p.precedents
|
62
61
|
assert_equal [], @p.upstream_places
|
@@ -303,9 +302,9 @@ describe ::YPetri::Transition do
|
|
303
302
|
describe "6. stoichiometric transitions with rate (SR transitions)" do
|
304
303
|
before do
|
305
304
|
# now this should give standard mass action by magic:
|
306
|
-
@SR1 = @ç.new s: { @p1 => -1, @p2 => -1, @p4 => 1 },
|
305
|
+
@SR1 = @ç.new s: { @p1 => -1, @p2 => -1, @p4 => 1 }, flux: 0.1
|
307
306
|
# while this has custom flux closure
|
308
|
-
@SR2 = @ç.new s: { @p1 => -1, @p3 => 1 },
|
307
|
+
@SR2 = @ç.new s: { @p1 => -1, @p3 => 1 }, flux: λ { |a| a * 0.5 }
|
309
308
|
# while this one even has domain specified:
|
310
309
|
@SR3 = @ç.new s: { @p1 => -1, @p2 => -1, @p4 => 1 }, upstream_arcs: @p3, flux: λ { |a| a * 0.5 }
|
311
310
|
end
|
@@ -599,10 +598,10 @@ describe ::YPetri::Simulation do
|
|
599
598
|
@p5 = @pç.new name: "P5", default_marking: 5
|
600
599
|
@t1 = @tç.new name: "T1",
|
601
600
|
s: { @p1 => -1, @p2 => -1, @p4 => 1 },
|
602
|
-
|
601
|
+
flux: 0.1
|
603
602
|
@t2 = @tç.new name: "T2",
|
604
603
|
s: { @p1 => -1, @p3 => 1 },
|
605
|
-
|
604
|
+
flux: λ { |a| a * 0.5 }
|
606
605
|
@t3 = @tç.new name: "T3",
|
607
606
|
s: { @p1 => -1, @p2 => -1, @p4 => 1 },
|
608
607
|
domain: @p3, flux: λ { |a| a * 0.5 }
|
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:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- boris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: y_support
|