class YPetri::Net::State::Feature::Assignment

Firing of a Petri net A transition.

Attributes

instances[R]
place[R]
transition[R]

Public Class Methods

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

Constructor that enables special syntax of constructing Feature::Assignment instance from a single place, as long as this place has exactly 1 upstream A transition.

# File lib/y_petri/net/state/feature/assignment.rb, line 46
def construct_from_a_place_with_single_upstream_A_transition( place )
  pl = net.place( place )
  aa = pl.upstream_arcs.select( &:A? )
  n = aa.size
  fail TypeError, "When constructing Feature::Assignment from a single" +
    "place, its upstream arcs must contain exactly one A transition! " +
    "(place #{pl} has #{n} upstream A transitions)" unless n == 1
  __new__( pl, transition: aa.first )
end
new(*args) click to toggle source

Constructor new is redefined to use instance cache.

# File lib/y_petri/net/state/feature/assignment.rb, line 58
def new *args
  return instances[ *args ] if args.size == 1
  instances[ args ]
end
Also aliased as: __new__, to
new(place, transition: transition()) click to toggle source

The constructor of an assignment feature takes 1 ordered and 1 named (:transition) argument, which must identify the place and the transitions.

# File lib/y_petri/net/state/feature/assignment.rb, line 68
def initialize place, transition: transition()
  @place = net.place( place )
  @transition = net.transition( transition )
  @place_index_in_codomain = @transition.codomain.index( @place ) or
    fail TypeError, "The place (#@place) must belong to the codomain of " +
      "the supplied A transition (#@transition)!"
end
parametrize(*args) click to toggle source

Customization of the Class#parametrize method.

# File lib/y_petri/net/state/feature/assignment.rb, line 11
def parametrize *args
  Class.instance_method( :parametrize ).bind( self ).( *args ).tap do |ç|
    # Prepare the instance registry.
    hsh = Hash.new do |, id|
      if id.is_a? self then # missing key "id" is an Assignment PS instance
        [ [ id.place, transition: id.transition ] ]
      elsif id.is_a? ç.net.Place then # a single place
        ç.construct_from_a_place_with_single_upstream_A_transition( id )
      elsif id.is_a? Array and id.size == 1 then # single place again
        ç.construct_from_a_place_with_single_upstream_A_transition( id.first )
      elsif id.is_a? Array then
        p = id.fetch( 0 )
        t = id.fetch( 1 ).fetch( :transition )
        if p.is_a? ç.net.Place and t.is_a? ç.net.Transition then
          [ id ] = ç.__new__( p, transition: t )
        else
          [ [ ç.net.place( p ), transition: ç.net.transition( t ) ] ]
        end
      else
        ç.construct_from_a_place_with_single_upstream_A_transition( id )
      end
    end # Hash.new do
    # And assign it to @instances:
    ç.instance_variable_set :@instances, hsh
  end # tap
end
to(*args)
Alias for: new

Public Instance Methods

==(other) click to toggle source

Two assignment features are equal if their place and transition is equal.

# File lib/y_petri/net/state/feature/assignment.rb, line 119
def == other
  other.is_a? net.State.Feature.Assignment and
    place == other.place && transition == other.transition
end
extract_from(arg, **nn) click to toggle source

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

# File lib/y_petri/net/state/feature/assignment.rb, line 79
def extract_from arg, **nn
  case arg
  when YPetri::Simulation then
    # First, let's identify the relevant transition representation
    t = arg.send( :A_transitions, transition ).first
    # Then, let's get its assignment closure
    closure = t.assignment_closure
    # And finally, the feature extraction
    Array( closure.call )[ @place_index_in_codomain ]
  else
    fail TypeError, "Argument type not supported!"
  end
end
inspect() click to toggle source

Inspect string of the firing feature.

# File lib/y_petri/net/state/feature/assignment.rb, line 113
def inspect
  "<Feature::Assignment to #{place.name or place} by #{transition.name or transition}>"
end
label() click to toggle source

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

# File lib/y_petri/net/state/feature/assignment.rb, line 107
def label
  "A:#{place.name}:#{transition.name}"
end
to_s() click to toggle source

A string briefly describing the assignment feature.

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

Type of this feature.

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