module YPetri::Simulation::Nodes::Access

Public Instance Methods

Nn( array ) click to toggle source

Nodes of the simulation (belonging to the net). Expects a single array of nodes (places / transitions) or node ids and returns an array of the corresponding nodes in the underlying net.

# File lib/y_petri/simulation/nodes/access.rb, line 29
def Nn( array )
  Nodes( array ).sources
end
include?( id )
Alias for: includes?
includes?( id ) click to toggle source

Does a node belong to the simulation?

# File lib/y_petri/simulation/nodes/access.rb, line 10
def includes?( id )
  includes_place?( id ) || includes_transition?( id )
end
Also aliased as: include?
n( node ) click to toggle source

Node of the simulation belonging to the net. Each simulation has its representations of places and transitions, which are based on the places and transitions of the underlying net. This method takes one argument, which (place, place name, transition, or transition name) and returns the corresponding node of the underlying net.

# File lib/y_petri/simulation/nodes/access.rb, line 21
def n( node )
  node( node ).source
end
nn( *nodes ) click to toggle source

Without arguments, returns all the nodes of the underlying net. Otherwise, it accepts an arbitrary number of nodes or node ids as arguments, and returns an array of the corresponding nodes of the underlying net.

# File lib/y_petri/simulation/nodes/access.rb, line 37
def nn( *nodes )
  nodes( *nodes ).sources
end
nnn(*nodes) click to toggle source

Names of the simulation's nodes. Arguments, if any, are treated analogically to the #nodes method.

# File lib/y_petri/simulation/nodes/access.rb, line 44
def nnn *nodes
  nnn( *nodes ).names
end

Protected Instance Methods

Nodes( array ) click to toggle source

Expects a single array of nodes (places / transitions) or node ids and returns an array of the corresponding node instances.

# File lib/y_petri/simulation/nodes/access.rb, line 61
def Nodes( array )
  # NOTE: At the moment, the Simulation instance does not have a
  # parametrized subclass of Simulation::Nodes class, the following
  # statement is thus made to return a plain array of elements.
  NodesPS().load array.map &method( :node )
end
node( node ) click to toggle source

Node instance identification.

# File lib/y_petri/simulation/nodes/access.rb, line 52
def node( node )
  return place node if include_place? node
  return transition node if include_transition? node
  fail TypeError, "No node #{node} in the simulation!"
end
nodes( *nodes ) click to toggle source

Without arguments, returns all the nodes (places / transitions) of the simulation. Otherwise, it accepts an arbitrary number of nodes or node ids as arguments, and returns an array of the corresponding nodes of the simulation.

# File lib/y_petri/simulation/nodes/access.rb, line 73
def nodes( *nodes )
  return places + transitions if nodes.empty?
  Nodes( nodes )
end