lib/y_petri/transition.rb in y_petri-1.0.0 vs lib/y_petri/transition.rb in y_petri-2.0.0
- old
+ new
@@ -159,20 +159,13 @@
# Names of upstream places.
#
def domain_pp; domain.map &:name end
alias :upstream_pp :domain_pp
- # Names of upstream places as symbols.
+ # Codomain, 'downstream arcs', or 'action arcs', is a collection of places,
+ # whose marking is directly changed by this transition's firing.
#
- def domain_pp_sym; domain_pp.map &:to_sym end
- alias :upstream_pp_sym :domain_pp_sym
- alias :domain_ppß :domain_pp_sym
- alias :ustream_ppß :domain_pp_sym
-
- # Codomain, 'downstream arcs', or 'action arcs' is a collection of places,
- # whose marking is directly changed by firing the trinsition.
- #
attr_reader :codomain
alias :codomain_arcs :codomain
alias :codomain_places :codomain
alias :downstream :codomain
alias :downstream_arcs :codomain
@@ -182,31 +175,18 @@
# Names of downstream places.
#
def codomain_pp; codomain.map &:name end
alias :downstream_pp :codomain_pp
- # Names of downstream places as symbols.
+ # Union of action arcs and test arcs.
#
- def codomain_pp_sym; codomain_pp.map &:to_sym end
- alias :downstream_pp_sym :codomain_pp_sym
- alias :codomain_ppß :codomain_pp_sym
- alias :downstream_ppß :codomain_pp_sym
-
- # Returns the union of action arcs and test arcs.
- #
def arcs; domain | codomain end
- alias :connectivity :arcs
- # Returns connectivity as names.
+ # Returns names of the (places connected to) the transition's arcs.
#
- def cc; connectivity.map &:name end
+ def aa; arcs.map &:name end
- # Returns connectivity as name symbols.
- #
- def cc_sym; cc.map &:to_sym end
- alias :ccß :cc_sym
-
# Is the transition stoichiometric?
#
def stoichiometric?; @stoichiometric end
alias :s? :stoichiometric?
@@ -395,15 +375,14 @@
# rate: λ { |a| a * 0.5 } )
#
def initialize *args
# do the big work of checking in the arguments
check_in_arguments *args
- # Inform the relevant places that they have been connected:
- upstream.each{ |place| place.send :register_downstream_transition, self }
- downstream.each{ |place| place.send :register_upstream_transition, self }
- # transitions initialize uncocked:
- @cocked = false
+ # Inform upstream and downstream places they have been connected:
+ inform_upstream_places
+ inform_downstream_places
+ @cocked = false # transitions initialize uncocked
end
# Marking of the domain places.
#
def domain_marking
@@ -417,32 +396,32 @@
end
# Result of the transition's "function", regardless of the #enabled? status.
#
def action Δt=nil
- raise AErr, "Δtime argument required for timed transitions!" if
+ raise ArgumentError, "Δtime argument required for timed transitions!" if
timed? and Δt.nil?
# the code here looks awkward, because I was trying to speed it up
if has_rate? then
if stoichiometric? then
rate = rate_closure.( *domain_marking )
- stoichiometry.map{ |coeff| rate * coeff * Δt }
+ stoichiometry.map { |coeff| rate * coeff * Δt }
else # assuming correct return value arity from the rate closure:
- rate_closure.( *domain_marking ).map{ |e| component * Δt }
+ rate_closure.( *domain_marking ).map { |e| component * Δt }
end
else # rateless
if timed? then
if stoichiometric? then
rslt = action_closure.( Δt, *domain_marking )
- stoichiometry.map{ |coeff| rslt * coeff }
+ stoichiometry.map { |coeff| rslt * coeff }
else
action_closure.( Δt, *domain_marking ) # caveat result arity!
end
else # timeless
if stoichiometric? then
rslt = action_closure.( *domain_marking )
- stoichiometry.map{ |coeff| rslt * coeff }
+ stoichiometry.map { |coeff| rslt * coeff }
else
action_closure.( *domain_marking ) # caveat result arity!
end
end
end
@@ -464,11 +443,11 @@
# Assignment actions are always feasible - no need to check:
return act if assignment?
# check if the marking after the action would still be positive
enabled = codomain
.zip( act )
- .all?{ |place, change| place.marking.to_f >= -change.to_f }
+ .all? { |place, change| place.marking.to_f >= -change.to_f }
if enabled then act else
raise "firing of #{self}#{ Δt ? ' with Δtime %s' % Δt : '' } " +
"would result in negative marking"
zero_action
end
@@ -497,11 +476,11 @@
uncock
fire! Δt
return true
end
- # #fire! (with bang) fires the transition regardless of cocked status.
+ # Fires the transition regardless of cocked/uncocked status.
#
def fire!( Δt=nil )
raise AErr, "Δtime required for timed transitions!" if timed? && Δt.nil?
if assignment_action? then
act = Array action( Δt )
@@ -624,18 +603,15 @@
:upstream_places ]
oo.may_have :rate, syn!: [ :flux,
:propensity,
:rate_closure,
:flux_closure,
- :propensity_closure,
- :Φ,
- :φ ]
+ :propensity_closure ]
oo.may_have :action, syn!: :action_closure
oo.may_have :timed
- # was the rate was given?
- @has_rate = oo.has? :rate
+ @has_rate = oo.has? :rate # was the rate was given?
# is the transition stoichiometric (S) or nonstoichiometric (s)?
@stoichiometric = oo.has? :stoichiometry
# downstream description arguments: codomain, stoichiometry (if S)
@@ -668,11 +644,11 @@
c = what_is_collection ? what_is_collection.capitalize : "Collection"
Array( place_collection ).map do |pl_id|
begin
place( pl_id )
rescue NameError
- raise TErr, "#{c} member #{pl_id} does not specify a valid place!"
+ raise TypeError, "#{c} member #{pl_id} does not specify a valid place!"
end
end.aT what_is_collection, "not contain duplicate places" do |collection|
collection == collection.uniq
end
end
@@ -751,12 +727,11 @@
if oo.has? :action then
action_λ = oo[:action].aT_is_a Proc, "supplied action named argument"
if oo.has? :timed then
_timed = oo[:timed]
# Time to worry about the domain_missing
- if domain == :missing then
- # figure user's intent from closure arity
+ if domain == :missing then # figure user's intent from closure arity
_domain = if action_λ.arity == ( _timed ? 1 : 0 ) then
[] # user meant empty domain
else
codomain # user meant domain same as codomain
end
@@ -876,10 +851,22 @@
end
else # if assignment action is not specified, false is
false
end
end
-
+
+ # Informs upstream places that they are connected to this transition.
+ #
+ def inform_upstream_places
+ upstream_places.each { |p| p.send :register_downstream_transition, self }
+ end
+
+ # Informs downstream places that they are connected to this transition.
+ #
+ def inform_downstream_places
+ downstream_places.each { |p| p.send :register_upstream_transition, self }
+ end
+
# Place class pertinent herein. Provided for the purpose of parametrized
# subclassing; expected to be overriden in the subclasses.
#
def Place
::YPetri::Place