class PetriNet::Graph::Node

Attributes

graph[RW]

The graph this node belongs to

id[R]

unique ID

inputs[R]

Incoming edges

label[R]

Label of the node

markings[R]

Makking this node represents

name[R]

human readable name

omega_marked[R]

Omega-marked node (unlimited Petrinet -> coverabilitygraph)

outputs[R]

Outgoing edges

start[R]

True if this is the start-marking

Public Class Methods

new(graph, options = {}) { |self| ... } click to toggle source
# File lib/petri_net/graph/node.rb, line 25
def initialize(graph, options = {}, &block)
  @graph = graph
  @id = next_object_id
  @name = (options[:name] || "Node#{@id}")
  @description = (options[:description] || "Node #{@id}")
  @inputs = []
  @outputs = []
  @label = (options[:label] || @name)
  @markings = options[:markings]
  @start = (options[:start] || false)
  raise ArgumentError, 'Every Node needs markings' if @markings.nil?

  @omega_marked = if @markings.include? Float::INFINITY
                    true
                  else
                    false
                  end

  yield self unless block.nil?
end

Public Instance Methods

<=>(object) click to toggle source

Compare-operator, other Operators are available through comparable-mixin

# File lib/petri_net/graph/node.rb, line 105
def <=>(object)
  return nil unless object.class.to_s == 'PetriNet::ReachabilityGraph::Node'
  return 0 if @markings == object.markings

  counter = 0
  less = true
  markings.each do |marking|
    if marking <= object.markings[counter] && less
      less = true
    else
      less = false
      break
    end
    counter += 1
  end
  return -1 if less

  counter = 0
  more = true
  markings.each do |marking|
    if marking >= object.markings[counter] && more
      more = true
    else
      more = false
      break
    end
    counter += 1
  end
  return 1 if more

  nil
end
add_omega(object) click to toggle source

Add an omega-marking to a specified place

# File lib/petri_net/graph/node.rb, line 51
def add_omega(object)
  ret = []
  if object.class.to_s == 'PetriNet::CoverabilityGraph::Node'
    if self < object
      counter = 0
      object.markings.each do |marking|
        if @markings[counter] < marking
          @markings[counter] = Float::INFINITY
          ret << counter
          end
        counter += 1
      end
    else
      return false
    end
  elsif object.class.to_s == 'Array'
    object.each do |place|
      markings[place] = Float::INFINITY
      ret = object
    end
  elsif object.class.to_s == 'Fixnum'
    markings[object] = Float::INFINITY
    ret = [object]
  elsif object.class.to_s == 'PetriNet::ReachabilityGraph::Node'
    raise PetriNet::Graph::InfinityError('ReachabilityGraphs do not support omega-markings')
  end
  @omega_marked = true
  ret
end
gv_id() click to toggle source
# File lib/petri_net/graph/node.rb, line 96
def gv_id
  "N#{@id}"
end
include_place(place) click to toggle source
# File lib/petri_net/graph/node.rb, line 81
def include_place(place)
  places = @graph.net.get_place_list
  included_places = []
  i = 0
  @markings.each do |m|
    included_places << places[i] if m > 0
    i += 1
  end
  included_places.include? place
end
infinite?() click to toggle source
# File lib/petri_net/graph/node.rb, line 46
def infinite?
  @omega_marked
end
to_gv() click to toggle source
# File lib/petri_net/graph/node.rb, line 100
def to_gv
  "\t#{gv_id} [ label = \"#{@markings}\" ];\n"
end
to_s() click to toggle source
# File lib/petri_net/graph/node.rb, line 138
def to_s
  "#{@id}: #{@name} (#{@markings})"
end
validate() click to toggle source
# File lib/petri_net/graph/node.rb, line 92
def validate
  true
end