module YPetri::Simulation::MarkingVector::Access

Public Instance Methods

M(*args;) click to toggle source

Array-returning equivalents of #M_vector and m_vector.

# File lib/y_petri/simulation/marking_vector/access.rb, line 35
def M *args; M_vector( *args ).to_a end
M_vector(array) click to toggle source

Marking of the selected places as a column vector. Expects a single array argument.

# File lib/y_petri/simulation/marking_vector/access.rb, line 10
def M_vector array
  m_vector.select( array )
end
Also aliased as: m_Vector
Marking_vector(array) click to toggle source

Marking vector of free places. Expects an array of places or place ids, for which the marking vectro is returned.

# File lib/y_petri/simulation/marking_vector/access.rb, line 114
def Marking_vector array
  M_vector Free_places( array )
end
P_m(places) click to toggle source

Marking of the indicated places as a hash of { place name => marking } pairs. Expects a single array of places or place ids as an argument.

# File lib/y_petri/simulation/marking_vector/access.rb, line 54
def P_m places
  Places( places ).names( true ) >> M( places )
end
Also aliased as: p_M, Pn_m
Pm(places, **named_args) click to toggle source

Pretty prints marking of the indicated places. Expects an array of places or place ids as an argument. In addition, accepts 2 optional named arguments, :gap and :precision (alias :p), that control the layout of the printed table, like in #pretty_print_numeric_values method.

# File lib/y_petri/simulation/marking_vector/access.rb, line 74
def Pm places, **named_args
  gap = named_args[:gap] || 0
  named_args.may_have :precision, syn!: :pn
  precision = named_args.delete( :precision ) || 3
  P_m( places ).pretty_print_numeric_values gap: gap, precision: precision
end
Pn_m(places)
Alias for: P_m
increment_marking(Δ_free) click to toggle source

Expects a Δ marking vector for free places and performs the specified change on the marking vector of the simulation.

# File lib/y_petri/simulation/marking_vector/access.rb, line 170
def increment_marking Δ_free
  @m_vector += f2a * Δ_free
  return nil
end
m(*args;) click to toggle source
# File lib/y_petri/simulation/marking_vector/access.rb, line 36
def m *args; m_vector( *args ).to_a end
m_Vector(array)
Alias for: M_vector
m_vector(*places) click to toggle source

Convenience method that accepts any number of places or place ids as arguments, and returns their marking as a column vector. If no arguments are supplied, the method returns the simulation's state vector.

# File lib/y_petri/simulation/marking_vector/access.rb, line 26
def m_vector *places
  begin
  return state if places.empty?
  m_vector.select( places )
  end
end
marking_vector(*places) click to toggle source

Marking vector of free places. Expects an arbitrary number of free places or place ids and returns the marking vector for them.

# File lib/y_petri/simulation/marking_vector/access.rb, line 121
def marking_vector *places
  m_vector *free_places( *places )
end
p_M(places)
Alias for: P_m
p_m(*places) click to toggle source

Marking of the indicated places as a hash of { place name => marking } pairs. Expects and arbitrary number of places or place ids and arguments. If no arguments are given, marking of all the places is returned.

# File lib/y_petri/simulation/marking_vector/access.rb, line 64
def p_m *places
  places( *places ).names( true ) >> m( *places )
end
Also aliased as: pn_m
pm(*places, **named_args) click to toggle source

Pretty prints marking of the indicated places. Expects an arbitrary number of places or place ids, and 2 optional named arguments, :gap and :precision (alias :p), that control the layout of the printed table, like in #pretty_print_numeric_values method.

# File lib/y_petri/simulation/marking_vector/access.rb, line 86
def pm *places, **named_args
  return Pm places() if places.empty?
  Pm( places, **named_args )
end
pn_m(*places)
Alias for: p_m
set_m(new_m)
Alias for: update_m
set_marking(new_m)
Alias for: update_marking
state() click to toggle source

Acts as a getter of the simulation's state vector, instance variable +@m_vector+.

# File lib/y_petri/simulation/marking_vector/access.rb, line 18
def state
  @m_vector or fail TypeError, "State not constructed yet!"
end
update_m(new_m) click to toggle source

Modifies the marking vector. Takes one argument. If the argument is a hash of pairs { place => new value }, only the specified places' markings are updated. If the argument is an array, it must match the number of places in the simulation, and all marking values are updated.

# File lib/y_petri/simulation/marking_vector/access.rb, line 96
def update_m new_m
  case new_m
  when Hash then # assume { place => marking } hash
    new_m.each_pair { |id, val| m_vector.set( id, val ) }
  when Array then
    msg = "T be a collection with size == number of net's places!"
    fail TypeError, msg unless new_m.size == places.size
    update_m( places >> new_m )
  else # convert it with #each
    update_m( new_m.each.to_a )
  end
  return nil
end
Also aliased as: set_m
update_marking(new_m) click to toggle source

Modifies the marking vector. Like #update_m, but the places must be free places, and if the argument is an array, it must match the number of free places in the simulation's net.

# File lib/y_petri/simulation/marking_vector/access.rb, line 151
def update_marking new_m
  case new_m
  when Hash then # assume { place => marking } hash
    ( free_places( new_m.keys ) >> new_m.values )
      .each_pair { |id, val| m_vector.set( id, val ) }
  when Array then
    msg = "T be a collection with size == number of net's free places!"
    fail TypeError, msg unless new_m.size == free_places.size
    update_m( free_places >> new_m )
  else # convert it with #each
    update_marking( new_m.each.to_a )
  end
  return nil
end
Also aliased as: set_marking