Class: PetriNet::Transition
Overview
Transition
Instance Attribute Summary collapse
-
#description ⇒ Object
Description.
-
#id ⇒ Object
Unique ID.
-
#inputs ⇒ Object
readonly
List of input-arcs.
-
#name ⇒ Object
Huan readable name.
-
#net ⇒ Object
writeonly
The net this transition belongs to.
-
#outputs ⇒ Object
readonly
List of output-arcs.
-
#probability ⇒ Object
Probability of firing (this moment).
Attributes inherited from Base
Instance Method Summary collapse
- #==(object) ⇒ Object
- #activate! ⇒ Object
- #activated? ⇒ Boolean (also: #firable?)
-
#add_input(arc) ⇒ Object
Add an input arc.
-
#add_output(arc) ⇒ Object
Add an output arc.
- #fire ⇒ Object
-
#gv_id ⇒ Object
GraphViz ID.
-
#initialize(options = {}) {|_self| ... } ⇒ Transition
constructor
Create a new transition.
- #postplaces ⇒ Object
- #preplaces ⇒ Object
-
#to_gv ⇒ Object
GraphViz definition.
-
#to_s ⇒ Object
Stringify this transition.
-
#validate ⇒ Object
Validate this transition.
Methods inherited from Base
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Transition
Create a new transition.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/petri_net/transition.rb', line 20 def initialize( = {}, &block) @id = next_object_id @name = ([:name] or "Transition#{@id}") @description = ([:description] or "Transition #{@id}") @inputs = Array.new @outputs = Array.new @probability = [:probability] yield self unless block == nil end |
Instance Attribute Details
#description ⇒ Object
Description
9 10 11 |
# File 'lib/petri_net/transition.rb', line 9 def description @description end |
#id ⇒ Object
Unique ID
5 6 7 |
# File 'lib/petri_net/transition.rb', line 5 def id @id end |
#inputs ⇒ Object (readonly)
List of input-arcs
13 14 15 |
# File 'lib/petri_net/transition.rb', line 13 def inputs @inputs end |
#name ⇒ Object
Huan readable name
7 8 9 |
# File 'lib/petri_net/transition.rb', line 7 def name @name end |
#net=(value) ⇒ Object (writeonly)
The net this transition belongs to
17 18 19 |
# File 'lib/petri_net/transition.rb', line 17 def net=(value) @net = value end |
#outputs ⇒ Object (readonly)
List of output-arcs
15 16 17 |
# File 'lib/petri_net/transition.rb', line 15 def outputs @outputs end |
#probability ⇒ Object
Probability of firing (this moment)
11 12 13 |
# File 'lib/petri_net/transition.rb', line 11 def probability @probability end |
Instance Method Details
#==(object) ⇒ Object
63 64 65 |
# File 'lib/petri_net/transition.rb', line 63 def ==(object) name == object.name && description = object.description end |
#activate! ⇒ Object
90 91 92 93 94 95 96 97 |
# 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? ⇒ Boolean Also known as: firable?
78 79 80 81 82 83 84 85 86 87 |
# 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 |
#add_input(arc) ⇒ Object
Add an input arc
32 33 34 |
# 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) ⇒ Object
Add an output arc
37 38 39 |
# File 'lib/petri_net/transition.rb', line 37 def add_output(arc) @outputs << arc.id unless (arc.nil? or !validate_output arc) end |
#fire ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 |
# 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 ⇒ Object
GraphViz ID
42 43 44 |
# File 'lib/petri_net/transition.rb', line 42 def gv_id "T#{@id}" end |
#postplaces ⇒ Object
73 74 75 76 |
# 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 ⇒ Object
67 68 69 70 71 |
# 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 ⇒ Object
GraphViz definition
59 60 61 |
# 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 ⇒ Object
Stringify this transition.
54 55 56 |
# File 'lib/petri_net/transition.rb', line 54 def to_s "#{@id}: #{@name}" end |
#validate ⇒ Object
Validate this transition.
47 48 49 50 51 |
# 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 |