class YPetri::Net::State::Feature::Delta
Change of a Petri net place caused by a certain set of transitions.
Attributes
Public Class Methods
Constructor new is redefined to use instance cache.
# File lib/y_petri/net/state/feature/delta.rb, line 89 def new *args return instances[ *args ] if args.size == 1 instances[ args ] end
The constructor of a delta feature takes one ordered argument (place identifier), and one named argument, :transitions
, expecting an array of transition identifiers, whose contribution is taken into account in this delta feature.
# File lib/y_petri/net/state/feature/delta.rb, line 101 def initialize place, transitions: net.tt @place = net.place( place ) @transitions = net.Transitions( transitions ) end
Customization of the Class#parametrize method.
# File lib/y_petri/net/state/feature/delta.rb, line 12 def parametrize *args Class.instance_method( :parametrize ).bind( self ).( *args ).tap do |ç| # First, prepare the instance registry. hsh = Hash.new do |ꜧ, id| if id.is_a? self then # missing key "id" is a Delta instance ꜧ[ [ id.place, transitions: id.transitions.sort_by( &:object_id ) ] ] else p = id.fetch( 0 ) tt = id.fetch( 1 ).fetch( :transitions ) # value of :transitions key tt_array = Array( tt ) if tt == tt_array then if p.is_a? ç.net.Place and tt.all? { |t| t.is_a? ç.net.Transition } if tt == tt.sort_by( &:object_id ) then # Cache the instance. ꜧ[ id ] = if tt.all? &:timed? then ç.timed( *id ) elsif tt.all? &:timeless? then fail TypeError, "Net::State::Feature::Delta does " + "not admit A transitions!" if tt.any? &:A? ç.timeless( *id ) else fail TypeError, "Net::State::Feature::Delta only " + "admits the transition sets that are either " + "all timed, or all timeless!" end else ꜧ[ [ p, transitions: tt.sort_by( &:object_id ) ] ] end else # convert place and transition ids to places and transitions ꜧ[ [ ç.net.place( p ), transitions: ç.net.Transitions( tt ) ] ] end else ꜧ[ [ p, transitions: tt_array ] ] end end end # Then, assign it to the :@instances variable. ç.instance_variable_set :@instances, hsh end # tap end
Timed delta feature constructor. Takes a place, and an array of timed transition identifiers supplied as +:transitions: parameter.
# File lib/y_petri/net/state/feature/delta.rb, line 60 def timed place, transitions: net.T_tt tt = begin net.T_Transitions( transitions ) rescue TypeError => err msg = "Transitions #{transitions} not recognized as timed " + "transitions in #{net}! (%s)" raise TypeError, msg % err end __new__( place, transitions: tt ) .tap { |inst| inst.instance_variable_set :@timed, true } end
Timeless delta feature constructor. Takes a place, and an array of timeless transition identifiers as +:transitions: parameter.
# File lib/y_petri/net/state/feature/delta.rb, line 75 def timeless place, transitions: net.t_tt tt = begin net.t_Transitions( transitions ) rescue TypeError => err msg = "Transitions #{transitions} not recognized as timed " + "transitions in #{net}! (%s)" raise TypeError, msg % err end __new__( place, transitions: net.t_Transitions( transitions ) ) .tap { |inst| inst.instance_variable_set :@timed, false } end
Public Instance Methods
Delta
features are equal if they are of equal PS and refer to the same place and transition set.
# File lib/y_petri/net/state/feature/delta.rb, line 169 def == other other.is_a? net.State.Feature.Delta and place == other.place && transitions == other.transitions end
Extracts the value of this feature from the target (eg. a simulation). If the receiver delta feature is timed, this method requires an additional named argument :delta_time
, alias +:Δt+.
# File lib/y_petri/net/state/feature/delta.rb, line 110 def extract_from arg, **named_args case arg when YPetri::Simulation then if timed? then arg.send( :T_Transitions, transitions ) .delta( named_args.must_have :delta_time, syn!: :Δt ).fetch( place ) else arg.send( :t_Transitions, transitions ).delta.fetch( place ) end else fail TypeError, "Argument type not supported!" end end
Inspect string of the delta feature.
# File lib/y_petri/net/state/feature/delta.rb, line 161 def inspect "<Feature::Delta Δ:#{place.name || place}:[%s]>" % transitions.names( true ).join( ', ' ) end
Label for the delta feature (to use in graphics etc.)
# File lib/y_petri/net/state/feature/delta.rb, line 150 def label "Δ:#{place.name}:%s" % if transitions.size == 1 then transitions.first.name || transitions.first else "#{transitions.size}tt" end end
Is the delta feature timed?
# File lib/y_petri/net/state/feature/delta.rb, line 126 def timed? @timed end
Opposite of #timed?
.
# File lib/y_petri/net/state/feature/delta.rb, line 132 def timeless? ! timed? end
A string briefly describing this delta feature.
# File lib/y_petri/net/state/feature/delta.rb, line 144 def to_s label end
Type of this feature.
# File lib/y_petri/net/state/feature/delta.rb, line 138 def type :delta end