class Petri::Net

Attributes

arcs[R]
places[R]
transitions[R]

Public Class Methods

new() click to toggle source
# File lib/petri/net.rb, line 7
def initialize
  @transitions = []
  @places = []
  @arcs = []
  @data = {}
end

Public Instance Methods

[](key) click to toggle source
# File lib/petri/net.rb, line 86
def [](key)
  @data[key]
end
[]=(k, v) click to toggle source
# File lib/petri/net.rb, line 90
def []=(k, v)
  @data[k] = v
end
arc_by_guard(guard) click to toggle source

@param guard [String] @return [Arc, nil]

# File lib/petri/net.rb, line 72
def arc_by_guard(guard)
  return if guard.blank?

  guard = Arc.normalize_guard(guard)
  @arcs.each { |arc| return arc if arc.normalized_guard == guard }
  nil
end
automated_transitions() click to toggle source

@return [Array<Transition>]

# File lib/petri/net.rb, line 15
def automated_transitions
  transitions.select(&:automated?)
end
inspect() click to toggle source
# File lib/petri/net.rb, line 94
def inspect
  "Petri::Net#{hash}"
end
messages() click to toggle source

@return [Array<Message>]

# File lib/petri/net.rb, line 20
def messages
  transitions.select { |transition| transition.is_a?(Petri::Message) }
end
node_by_identifier(identifier) click to toggle source

@param identifier [String] @return [Node, nil]

# File lib/petri/net.rb, line 82
def node_by_identifier(identifier)
  place_by_identifier(identifier) || transition_by_identifier(identifier)
end
place_by_identifier(identifier) click to toggle source

@param identifier [String] @return [Place, nil]

# File lib/petri/net.rb, line 39
def place_by_identifier(identifier)
  identifier = identifier.to_s
  @places.each { |node| return node if node.identifier == identifier }
  nil
end
start_place() click to toggle source

@return [Place]

# File lib/petri/net.rb, line 25
def start_place
  start_places = @places.select(&:start?).select do |place|
    place.identifier.blank? ||
      places_by_identifier(place.identifier).select(&:finish?).empty?
  end

  raise ArgumentError, 'There are more than one start places' if start_places.many?
  raise ArgumentError, 'There is no start place' if start_places.empty?

  start_places.first
end
transition_by_identifier(identifier, automated: nil) click to toggle source

@param identifier [String] @return [Transition, nil]

# File lib/petri/net.rb, line 47
def transition_by_identifier(identifier, automated: nil)
  identifier = identifier.to_s
  transitions = @transitions.select do |transition|
    if automated
      transition.automated?
    elsif automated == false
      !transition.automated?
    else
      true
    end
  end

  transitions.each { |node| return node if node.identifier == identifier }

  nil
end
transitions_by_identifier(identifier) click to toggle source

@param identifier [String] @return [Array<Transition>]

# File lib/petri/net.rb, line 66
def transitions_by_identifier(identifier)
  @transitions.select { |node| node.identifier == identifier }
end

Protected Instance Methods

node_by_guid(guid) click to toggle source

@param guid [String] @return [Node, nil]

# File lib/petri/net.rb, line 102
def node_by_guid(guid)
  @places.each { |node| return node if node.guid == guid }
  @transitions.each { |node| return node if node.guid == guid }
  nil
end
places_by_identifier(identifier) click to toggle source

@param identifier [String] @return [Array<Place>]

# File lib/petri/net.rb, line 110
def places_by_identifier(identifier)
  identifier = identifier.to_s
  @places.select { |node| node.identifier == identifier }
end