class PetriNet::Transition
Attributes
description[RW]
Description
id[RW]
Unique ID
inputs[R]
List of input-arcs
name[RW]
Huan readable name
net[W]
The net this transition belongs to
outputs[R]
List of output-arcs
probability[RW]
Probability of firing (this moment)
Public Class Methods
new(options = {}) { |self| ... }
click to toggle source
Create a new transition.
# File lib/petri_net/transition.rb, line 20 def initialize(options = {}, &block) @id = next_object_id @name = (options[:name] or "Transition#{@id}") @description = (options[:description] or "Transition #{@id}") @inputs = Array.new @outputs = Array.new @probability = options[:probability] yield self unless block == nil end
Public Instance Methods
==(object)
click to toggle source
# File lib/petri_net/transition.rb, line 63 def ==(object) name == object.name && description = object.description end
activate!()
click to toggle source
# File lib/petri_net/transition.rb, line 90 def activate! @inputs.each do |i| source = @net.get_object(i).source source.add_marking(@net.get_object(i).weight - source.markings.size) end #what to do with outputs, if they have a capacity end
activated?()
click to toggle source
# File lib/petri_net/transition.rb, line 78 def activated? raise "Not part of a net" if @net.nil? @inputs.each do |i| return false if @net.get_object(i).source.markings.size < @net.get_object(i).weight end @outputs.each do |o| return false if @net.get_object(o).destination.markings.size + @net.get_object(o).weight > @net.get_object(o).destination.capacity end end
Also aliased as: firable?
add_input(arc)
click to toggle source
Add an input arc
# File lib/petri_net/transition.rb, line 32 def add_input(arc) @inputs << arc.id unless (arc.nil? or !validate_input arc) end
add_output(arc)
click to toggle source
Add an output arc
# File lib/petri_net/transition.rb, line 37 def add_output(arc) @outputs << arc.id unless (arc.nil? or !validate_output arc) end
fire()
click to toggle source
# File lib/petri_net/transition.rb, line 99 def fire raise "Not part of a net" if @net.nil? return false unless activated? @inputs.each do |i| @net.get_object(i).source.remove_marking @net.get_object(i).weight end @outputs.each do |o| @net.get_object(o).destination.add_marking @net.get_object(o).weight end true end
gv_id()
click to toggle source
GraphViz ID
# File lib/petri_net/transition.rb, line 42 def gv_id "T#{@id}" end
postplaces()
click to toggle source
# File lib/petri_net/transition.rb, line 73 def postplaces raise "Not part of a net" if @net.nil? @outputs.map{|o| @net.objects[o].source} end
preplaces()
click to toggle source
# File lib/petri_net/transition.rb, line 67 def preplaces raise "Not part of a net" if @net.nil? places = Array.new places << @inputs.map{|i| @net.objects[i].source} end
to_gv()
click to toggle source
GraphViz definition
# File lib/petri_net/transition.rb, line 59 def to_gv "\t#{self.gv_id} [ label = \"#{@name}#{@probability ? ' ' + @probability.to_s : ''}\" ];\n" end
to_s()
click to toggle source
Stringify this transition.
# File lib/petri_net/transition.rb, line 54 def to_s "#{@id}: #{@name}" end
validate()
click to toggle source
Validate this transition.
# File lib/petri_net/transition.rb, line 47 def validate return false if @id < 1 return false if @name.nil? or @name.length < 1 return true end
Private Instance Methods
validate_input(arc)
click to toggle source
# File lib/petri_net/transition.rb, line 113 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/transition.rb, line 119 def validate_output(arc) self.outputs.each do |a| return false if ((@net.get_objects[a] <=> arc) == 0) end true end