Module: YPetri::Place::Features

Defined in:
lib/y_petri/place/features.rb

Overview

Place instance methods concerned with state and/or simulation features.

Instance Method Summary collapse

Instance Method Details

#Delta(array, net: world.net( :Top )) ⇒ Object

Expects an array of transitions, and :net named argument. Returns a single delta feature belonging to the net for this place, and those upstream T transitions, that are also in the included in the array. If no ordered arguments are given, complete set of upstream T transitions is assumed. If no :net is given, Top is assumed.



59
60
61
62
63
64
# File 'lib/y_petri/place/features.rb', line 59

def Delta array, net: world.net( :Top )
  fail TypeError, "#{self} must be included in the net!" unless
    net.include? self
  transitions = upstream_arcs.select { |t| array.include? t }.select( &:T? )
  net.State.Feature.Delta( self, transitions: transitions )
end

#delta(*transitions, net: world.net( :Top )) ⇒ Object

Expects an arbitrary number of transitions, and :net named argument. Returns a single delta feature belonging to the net for this place, and those upstream T transitions, that are also in the included among the arguments. If no ordered arguments are given, complete set of upstream T transitions is assumed. If no :net is given, Top is assumed.



72
73
74
75
# File 'lib/y_petri/place/features.rb', line 72

def delta *transitions, net: world.net( :Top )
  return Delta upstream_arcs, net: net if transitions.empty?
  Delta transitions, net: net
end

#Deltas(array, net: world.net( :Top )) ⇒ Object

Expects an array of transitions, and :net named argument. Returns a feature set belonging to the net, consisting of the features for this place, and those upstream T transitions, that are also included in the array. If no :net is given, Top is assumed.



82
83
84
85
86
87
# File 'lib/y_petri/place/features.rb', line 82

def Deltas array, net: world.net( :Top )
  fail TypeError, "#{self} must be included in the net!" unless
    net.include? self
  transitions = upstream_arcs.select { |t| array.include? t }.select( &:T? )
  net.State.Features( transitions.map { |t| delta t, net: net } )
end

#deltas(*transitions, net: world.net( :Top )) ⇒ Object

Expects an arbitrary number of transitions, and :net named argument. Returns a feature set belonging to the net, constisting of the features for this place, and those upstream T transitions, that are also included in the array. If no ordered arguments are given, complete set of upstream T transitions is assumed. If no :net is given, Top is assumed.



95
96
97
98
# File 'lib/y_petri/place/features.rb', line 95

def deltas *transitions, net: world.net( :Top )
  return Deltas upstream_arcs, net: net if transitions.empty?
  Deltas transitions, net: net
end

#gradient(*transitions, net: world.net( :Top )) ⇒ Object

Expects an arbitrary number of transitions, and :net named argument. Returns a single gradient feature belonging to the net for this place, and those upstream T transitions, that are also in the included among the arguments. If no ordered arguments are given, complete set of upstream T transitions is assumed. If no :net is given, Top is assumed.



25
26
27
28
# File 'lib/y_petri/place/features.rb', line 25

def gradient *transitions, net: world.net( :Top )
  return Gradient upstream_arcs, net: net if transitions.empty?
  Gradient transitions, net: net
end

#Gradient(array, net: world.net( :Top )) ⇒ Object

Expects an array of transitions, and :net named argument. Returns a single gradient feature belonging to the net for this place, and those upstream T transitions, that are also in the included in the array. If no ordered arguments are given, complete set of upstream T transitions is assumed. If no :net is given, Top is assumed.



12
13
14
15
16
17
# File 'lib/y_petri/place/features.rb', line 12

def Gradient array, net: world.net( :Top )
  fail TypeError, "#{self} must be included in the net!" unless
    net.include? self
  transitions = upstream_arcs.select { |t| array.include? t }.select( &:T? )
  net.State.Feature.Gradient( self, transitions: transitions )
end

#gradients(*transitions, net: world.net( :Top )) ⇒ Object

Expects an arbitrary number of transitions, and :net named argument. Returns a feature set belonging to the net, constisting of the features for this place, and those upstream T transitions, that are also included in the array. If no ordered arguments are given, complete set of upstream T transitions is assumed. If no :net is given, Top is assumed.



48
49
50
51
# File 'lib/y_petri/place/features.rb', line 48

def gradients *transitions, net: world.net( :Top )
  return Gradients upstream_arcs, net: net if transitions.empty?
  Gradients transitions, net: net
end

#Gradients(array, net: world.net( :Top )) ⇒ Object

Expects an array of transitions, and :net named argument. Returns a feature set belonging to the net, consisting of the features for this place, and those upstream T transitions, that are also included in the array. If no :net is given, Top is assumed.



35
36
37
38
39
40
# File 'lib/y_petri/place/features.rb', line 35

def Gradients array, net: world.net( :Top )
  fail TypeError, "#{self} must be included in the net!" unless
    net.include? self
  transitions = upstream_arcs.select { |t| array.include? t }.select( &:T? )
  net.State.Features( transitions.map { |t| gradient t, net: net } )
end

#pd(simulation = world.simulation, precision: 8, **nn) ⇒ Object

Convenience method. Prints deltas under current simulation.



109
110
111
112
113
114
# File 'lib/y_petri/place/features.rb', line 109

def pd simulation=world.simulation, precision: 8, **nn
  nn.may_have :delta_time, syn!: :Δt
  delta_time = nn.delete( :delta_time ) || world.simulation.step
  ( deltas >> deltas % [ simulation, delta_time: delta_time ] )
    .pretty_print_numeric_values precision: precision, **nn
end

#pg(simulation = world.simulation, precision: 8, **nn) ⇒ Object

Convenience method. Prints gradients under curent simulation.



102
103
104
105
# File 'lib/y_petri/place/features.rb', line 102

def pg simulation=world.simulation, precision: 8, **nn
  ( gradients >> gradients % simulation )
    .pretty_print_numeric_values precision: precision, **nn
end