class YPetri::Net::State::Features::Record

A collection of values for a given set of state features.

Public Class Methods

load(values) click to toggle source

Constructs a new Record object from a given collection of values.

# File lib/y_petri/net/state/features/record.rb, line 13
def load values
  new( values.dup )
end

Public Instance Methods

Assignment(array, transition: L!) click to toggle source

Returns the values for a set of assignment features selected from this record's feature set. Expects a single array argument, optionally qualified by :transition named argument.

# File lib/y_petri/net/state/features/record.rb, line 190
def Assignment array, transition: L!
  return array.map { |id| fetch net.State.Feature.Assignment( id ) } if
    transition.local_object?
  array.map { |id|
    fetch net.State.Feature.Assignment( id, transition: transition )
  }
end
Delta(array, transitions: nil) click to toggle source

Returns the values for a set of delta features selected from this record's feature set. Expects a single array argument, optionally qualified by by :transitions named argument, defaulting to all the transitions in the net.

# File lib/y_petri/net/state/features/record.rb, line 166
def Delta array, transitions: nil
  array.map { |id|
    fetch( net.State.Feature.Delta id, transitions: net.tt( transitions ) )
  }
end
Firing(array) click to toggle source

Expects a single aarray of firing feature identifiers, and selects the corresponding values from the reciever record.

# File lib/y_petri/net/state/features/record.rb, line 124
def Firing array
  array.map { |id| fetch( net.State.Feature.Firing id ) }
end
Flux(array) click to toggle source

Expects a single aarray of flux feature identifiers, and selects the corresponding values from the reciever record.

# File lib/y_petri/net/state/features/record.rb, line 108
def Flux array
  array.map { |id| fetch( net.State.Feature.Flux id ) }
end
Gradient(array, transitions: nil) click to toggle source

Expects a single array of gradient feature identifiers, optionally qualified by the :transitions named argument, defaulting to all T transitions in the net.

# File lib/y_petri/net/state/features/record.rb, line 141
def Gradient array, transitions: nil
 array.map { |id|
    fetch( net.State.Feature.Gradient id, transitions: transitions )
  }
end
Marking(array) click to toggle source

Expects a single array of marking feture identifiers, and selects the corresponding values from the reciever record.

# File lib/y_petri/net/state/features/record.rb, line 90
def Marking array
  array.map { |id| fetch( net.State.Feature.Marking id ) }
  # possible TODO - maybe a new feature instance and reloading the record
  # through it woud be in place. Not doing now.
end
assignment(*ids, transition: L!) click to toggle source

Returns the values for a set of assignment features selected from this record's feature set. Expects an arbitrary number of arguments, optinally qualified by :transition named argument. Without arguments, returns values for all the assignment features.

# File lib/y_petri/net/state/features/record.rb, line 203
def assignment *ids, transition: L!
  if transition.local_object? then
    return Assignment( ids ) unless ids.empty?
    Assignment features.assignment
  else
    return Assignment( ids, transition: transition ) unless ids.empty?
    Assignment features.assignment, transition: transition
  end
end
delta(*delta_features, transitions: nil) click to toggle source

Returns the values for a set of delta features selected from this record's feature set. Expects an arbitrary number of arguments, optionally qualified by :transitions named argument, defaulting to all the transitions in the net. Without arguments, returns values for all the delta features.

# File lib/y_petri/net/state/features/record.rb, line 177
def delta *delta_features, transitions: nil
  return Delta( delta_features, transitions: transitions ) unless
    delta_features.empty?
  return Delta( features.delta ) if transitions.nil?
  Delta( features.delta.select do |f|
           f.transitions == transitions.map { |t| net.transition t }
         end )
end
dump(precision: nil) click to toggle source

Outputs the record as a plain array.

# File lib/y_petri/net/state/features/record.rb, line 26
def dump precision: nil
  return features.map &method( :fetch ) if precision.nil?
  features.map { |f| fetch( f ).round( precision ) }
end
euclidean_distance( other ) click to toggle source

Computes the Euclidean distance from another record.

# File lib/y_petri/net/state/features/record.rb, line 215
def euclidean_distance( other )
  fail TypeError unless features == other.features
  sum_of_squares = zip( other )
    .map { |a, b| a - b }
    .map { |d| d * d }
    .reduce( 0.0, :+ )
  sum_of_squares ** 0.5
end
fetch(feature) click to toggle source

Returns an identified feature, or fails.

Calls superclass method
# File lib/y_petri/net/state/features/record.rb, line 40
def fetch feature
  super begin
          Integer( feature )
        rescue TypeError
          feat = net.State.Feature( feature )
          features.index( feat )
        end
end
firing(*firing_features) click to toggle source

Expects an arbitrary number of firing feature identifiers and returns the corresponding values from the reciever record. If no arguments are given, values for all the firing features are returned.

# File lib/y_petri/net/state/features/record.rb, line 132
def firing *firing_features
  return Firing( features.firing ) if firing_features.empty?
  Firing( firing_features )
end
flux(*flux_features) click to toggle source

Expects an arbitrary number of flux feature identifiers and returns the corresponding values from the reciever record. If no arguments are given, values for all the flux features are returned.

# File lib/y_petri/net/state/features/record.rb, line 116
def flux *flux_features
  return Flux( features.flux ) if flux_features.empty?
  Flux( flux_features )
end
gradient(*gradient_features, transitions: nil) click to toggle source

Expects an arbitrary number of gradient feature identifiers, optionally qualified by the :transitions named argument, defaulting to all T transitions in the net. If no arguments are given, values for all the gradient features are defined.

# File lib/y_petri/net/state/features/record.rb, line 152
def gradient *gradient_features, transitions: nil
  return Gradient( gradient_features, transitions: transitions ) unless
    gradient_features.empty?
  return Gradient( features.gradient ) if transitions.nil?
  Gradient( features.gradient.select do |f|
              f.transitions == transitions.map { |t| net.transition t }
            end )
end
marking(*marking_features) click to toggle source

Expects an arbitrary number of marking feature identifiers and returns the corresponding values from the reciever record. If no arguments are given, values for all the marking features are returned.

# File lib/y_petri/net/state/features/record.rb, line 100
def marking *marking_features
  return Marking( features.marking ) if marking_features.empty?
  Marking( marking_features )
end
print(gap: 4, precision: 4) click to toggle source

Pretty prints the record with feature names.

reconstruct(marking_clamps: {}) click to toggle source

Given a set of marking clamps complementary to the marking features of this record, reconstructs a Simulation instance with the corresponding state. If the net is timed, or if the construction of the simulation from the net has need for any special settings, these must be supplied to this method. (Timed nets eg. require :time named argument for successful construction.)

# File lib/y_petri/net/state/features/record.rb, line 78
def reconstruct marking_clamps: {}, **settings
  clamped_places = net.Places( marking_clamps.keys )
  ff = features.marking - net.State.Features.Marking( clamped_places )
  m_hsh =
    ff.map { |f| f.place } >>
    marking
  net.simulation marking_clamps: marking_clamps, marking: m_hsh, **settings
end
state(marking_clamps: {}) click to toggle source

Returns the state instance implied by the receiver record, and a set of complementary marking clamps supplied as the argument.

# File lib/y_petri/net/state/features/record.rb, line 52
def state marking_clamps: {}
  cc = marking_clamps.with_keys { |k| net.place k }.with_values! do |v|
    case v
    when YPetri::Place then v.marking
    when ~:call then v.call
    else v end
  end
  own = features.marking.map &:place
  from_clamps = net.Places cc.keys
  fail TypeError, "Marking clamps supplied in the argument together with " +
    "this record's markings must complete the full state of the net!" unless
    net.places - own - from_clamps == []
  array = net.places.map do |place|
    begin; cc.fetch place; rescue IndexError
      fetch place
    end
  end
  State().new array
end