class PetriNet::Place
Attributes
capacity[RW]
Token capacity
description[RW]
description
id[RW]
Unique ID
inputs[R]
List of input-arcs
markings[R]
Current token
name[RW]
Human readable name
net[W]
The net this place belongs to
outputs[R]
List of output-arcs
Public Class Methods
new(options = {}) { |self| ... }
click to toggle source
Initialize a new place. Supports block configuration.
# File lib/petri_net/place.rb, line 22 def initialize(options = {}, &block) @id = next_object_id @name = (options[:name] or "Place#{@id}") @description = (options[:description] or "Place #{@id}") @capacity = options[:capacity].nil? ? Float::INFINITY : options[:capacity] @inputs = Array.new @outputs = Array.new @markings = Array.new yield self unless block == nil end
Public Instance Methods
==(object)
click to toggle source
# File lib/petri_net/place.rb, line 106 def ==(object) return true if name == object.name && description = object.description end
add_input(arc)
click to toggle source
Add an input arc
# File lib/petri_net/place.rb, line 35 def add_input(arc) @inputs << arc.id unless (arc.nil? or !validate_input arc) end
add_marking(count = 1)
click to toggle source
# File lib/petri_net/place.rb, line 44 def add_marking(count = 1) if count <= @capacity count.times do @markings << PetriNet::Marking.new end return true else raise "Tried to add more markings than possible" end end
Also aliased as: +
add_output(arc)
click to toggle source
Add an output arc
# File lib/petri_net/place.rb, line 40 def add_output(arc) @outputs << arc.id unless (arc.nil? or !validate_input arc) end
gv_id()
click to toggle source
GraphViz ID
# File lib/petri_net/place.rb, line 73 def gv_id "P#{@id}" end
posttransitions()
click to toggle source
# File lib/petri_net/place.rb, line 92 def posttransitions raise "Not part of a net" if @net.nil? outputs.map{|o| @net.objects[o].source} end
pretransitions()
click to toggle source
# File lib/petri_net/place.rb, line 86 def pretransitions raise "Not part of a net" if @net.nil? transitions = Array.new places << inputs.map{|i| @net.objects[i].source} end
remove_marking(count = 1)
click to toggle source
# File lib/petri_net/place.rb, line 62 def remove_marking(count = 1) if @markings.size >= count ret = @markings.pop(count) return ret unless ret.nil? else raise "Tried to remove more markings that possible" end end
Also aliased as: -
set_marking(count)
click to toggle source
# File lib/petri_net/place.rb, line 55 def set_marking(count) @markings = [] add_marking count end
to_gv()
click to toggle source
GraphViz definition
# File lib/petri_net/place.rb, line 103 def to_gv "\t#{self.gv_id} [ label = \"#{@name} #{@markings.size} \" ];\n" end
to_s()
click to toggle source
Stringify this place.
# File lib/petri_net/place.rb, line 98 def to_s "#{@id}: #{@name} (#{@capacity == nil ? -1 : 0}) #{'*' * @markings.length}" end
validate()
click to toggle source
Validate the setup of this place.
# File lib/petri_net/place.rb, line 78 def validate return false if @id.nil? or @id < 0 return false if @name.nil? or @name.strip.length <= 0 return false if @description.nil? or @description.strip.length <= 0 return false if @capacity.nil? or @capacity < -1 return true end
Private Instance Methods
validate_input(arc)
click to toggle source
# File lib/petri_net/place.rb, line 111 def validate_input(arc) self.inputs.each do |a| return false if ((@net.get_objects[a] <=> arc) == 0) end true end
validate_output(arc)
click to toggle source
# File lib/petri_net/place.rb, line 117 def validate_output(arc) self.outputs.each do |a| return false if ((@net.get_objects[a] <=> arc) == 0) end true end