class YPetri::Net::State::Feature::Delta

Change of a Petri net place caused by a certain set of transitions.

Attributes

instances[R]
place[R]
transitions[R]
tt[R]

Public Class Methods

__new__(*args)
Alias for: new
new(*args) click to toggle source

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
Also aliased as: __new__, of
new(place, transitions: net.tt) click to toggle source

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
of(*args)
Alias for: new
parametrize(*args) click to toggle source

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(place, transitions: net.T_tt) click to toggle source

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(place, transitions: net.t_tt) click to toggle source

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

==(other) click to toggle source

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
extract_from(arg, **named_args) click to toggle source

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() click to toggle source

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() click to toggle source

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
timed?() click to toggle source

Is the delta feature timed?

# File lib/y_petri/net/state/feature/delta.rb, line 126
def timed?
  @timed
end
timeless?() click to toggle source

Opposite of #timed?.

# File lib/y_petri/net/state/feature/delta.rb, line 132
def timeless?
  ! timed?
end
to_s() click to toggle source

A string briefly describing this delta feature.

# File lib/y_petri/net/state/feature/delta.rb, line 144
def to_s
  label
end
type() click to toggle source

Type of this feature.

# File lib/y_petri/net/state/feature/delta.rb, line 138
def type
  :delta
end