class YPetri::Net::State::Feature::Gradient

Gradient of a Petri net place caused by a certain set of T 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/gradient.rb, line 56
def new *args
  return instances[ *args ] if args.size == 1
  instances[ args ]
end
Also aliased as: __new__, of
new(*id) click to toggle source

The constructor of a gradient 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 gradient feature.

# File lib/y_petri/net/state/feature/gradient.rb, line 68
def initialize *id
  @place = net.place id.fetch( 0 )
  @transitions = net.Transitions id.fetch( 1 ).fetch( :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/gradient.rb, line 12
def parametrize *args
  Class.instance_method( :parametrize ).bind( self ).( *args ).tap do |ç|
    # First, prepare the hash of instances.
    hsh = Hash.new do |, id|
      if id.is_a? self then
        [ [ id.place, transitions: id.transitions.sort_by( &:object_id ) ] ]
      else
        p = id.fetch( 0 )
        tt = id.fetch( 1 ).fetch( :transitions )
        tt_array = Array( tt )
        if tt == tt_array then
          if p.is_a? ç.net.Place and tt.all? { |t| t.is_a? ç.net.Transition }
            tt_sorted = tt.sort_by &:object_id
            if tt == tt_sorted then
              tt = begin
                     ç.net.T_Transitions( tt )
                   rescue TypeError => err
                     msg = "Transitions #{tt} not recognized as T " +
                       "transitions in net #{ç.net}! (%s)"
                     raise TypeError, msg % err
                   end
              [ id ] = ç.__new__( *id )
            else
              [ [ p, transitions: tt.sort_by( &:object_id ) ] ]
            end
          else
            [ [ ç.net.place( p ), transitions: ç.net.Transitions( tt ) ] ]
          end
        else
          [ [ p, transitions: tt_array ] ]
        end
      end
    end
    # And then, assign it to the :@instances variable.
    ç.instance_variable_set :@instances, hsh
  end
end

Public Instance Methods

==(other) click to toggle source

Gradient 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/gradient.rb, line 118
def == other
  other.is_a? net.State.Feature.Gradient and
    place == other.place && transitions == other.transitions
end
extract_from(arg, **nn) click to toggle source

Extracts the receiver gradient feature from the argument. This can be typically a simulation instance.

# File lib/y_petri/net/state/feature/gradient.rb, line 76
def extract_from arg, **nn
  case arg
  when YPetri::Simulation then
    arg.send( :T_Transitions, transitions ).gradient.fetch( place )
  else
    fail TypeError, "Argument type not supported!"
  end
end
inspect() click to toggle source

Inspect string of the gradient feature.

# File lib/y_petri/net/state/feature/gradient.rb, line 110
def inspect
  "<Feature::Gradient ∂:#{place.name || place}:[%s]>" %
    transitions.names( true ).join( ', ' )
end
label() click to toggle source

Label for the gradient feature (to use in graphics etc.)

# File lib/y_petri/net/state/feature/gradient.rb, line 99
def label
  "∂:#{place.name}:%s" %
    if transitions.size == 1 then
      transitions.first.name || transitions.first
    else
      "#{transitions.size}tt"
    end
end
to_s() click to toggle source

A string briefly describing the gradient feature.

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

Type of this feature.

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