Class: PetriNet::Place
Instance Attribute Summary collapse
-
#capacity ⇒ Object
Token capacity.
-
#description ⇒ Object
description.
-
#id ⇒ Object
Unique ID.
-
#inputs ⇒ Object
readonly
List of input-arcs.
-
#markings ⇒ Object
readonly
Current token.
-
#name ⇒ Object
Human readable name.
-
#net ⇒ Object
writeonly
The net this place belongs to.
-
#outputs ⇒ Object
readonly
List of output-arcs.
Attributes inherited from Base
Instance Method Summary collapse
- #==(object) ⇒ Object
-
#add_input(arc) ⇒ Object
Add an input arc.
- #add_marking(count = 1) ⇒ Object (also: #+)
-
#add_output(arc) ⇒ Object
Add an output arc.
-
#gv_id ⇒ Object
GraphViz ID.
-
#initialize(options = {}) {|_self| ... } ⇒ Place
constructor
Initialize a new place.
- #posttransitions ⇒ Object
- #pretransitions ⇒ Object
- #remove_marking(count = 1) ⇒ Object (also: #-)
- #set_marking(count) ⇒ Object
-
#to_gv ⇒ Object
GraphViz definition.
-
#to_s ⇒ Object
Stringify this place.
-
#validate ⇒ Object
Validate the setup of this place.
Methods inherited from Base
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Place
Initialize a new place. Supports block configuration.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/petri_net/place.rb', line 22 def initialize( = {}, &block) @id = next_object_id @name = ([:name] or "Place#{@id}") @description = ([:description] or "Place #{@id}") @capacity = [:capacity].nil? ? Float::INFINITY : [:capacity] @inputs = Array.new @outputs = Array.new @markings = Array.new yield self unless block == nil end |
Instance Attribute Details
#capacity ⇒ Object
Token capacity
11 12 13 |
# File 'lib/petri_net/place.rb', line 11 def capacity @capacity end |
#description ⇒ Object
description
9 10 11 |
# File 'lib/petri_net/place.rb', line 9 def description @description end |
#id ⇒ Object
Unique ID
3 4 5 |
# File 'lib/petri_net/place.rb', line 3 def id @id end |
#inputs ⇒ Object (readonly)
List of input-arcs
13 14 15 |
# File 'lib/petri_net/place.rb', line 13 def inputs @inputs end |
#markings ⇒ Object (readonly)
Current token
17 18 19 |
# File 'lib/petri_net/place.rb', line 17 def markings @markings end |
#name ⇒ Object
Human readable name
7 8 9 |
# File 'lib/petri_net/place.rb', line 7 def name @name end |
#net=(value) ⇒ Object (writeonly)
The net this place belongs to
19 20 21 |
# File 'lib/petri_net/place.rb', line 19 def net=(value) @net = value end |
#outputs ⇒ Object (readonly)
List of output-arcs
15 16 17 |
# File 'lib/petri_net/place.rb', line 15 def outputs @outputs end |
Instance Method Details
#==(object) ⇒ Object
106 107 108 |
# File 'lib/petri_net/place.rb', line 106 def ==(object) return true if name == object.name && description = object.description end |
#add_input(arc) ⇒ Object
Add an input arc
35 36 37 |
# 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) ⇒ Object Also known as: +
44 45 46 47 48 49 50 51 52 53 |
# 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 |
#add_output(arc) ⇒ Object
Add an output arc
40 41 42 |
# 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 ⇒ Object
GraphViz ID
73 74 75 |
# File 'lib/petri_net/place.rb', line 73 def gv_id "P#{@id}" end |
#posttransitions ⇒ Object
92 93 94 95 |
# 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 ⇒ Object
86 87 88 89 90 |
# 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) ⇒ Object Also known as: -
62 63 64 65 66 67 68 69 |
# 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 |
#set_marking(count) ⇒ Object
55 56 57 58 |
# File 'lib/petri_net/place.rb', line 55 def set_marking(count) @markings = [] add_marking count end |
#to_gv ⇒ Object
GraphViz definition
103 104 105 |
# File 'lib/petri_net/place.rb', line 103 def to_gv "\t#{self.gv_id} [ label = \"#{@name} #{@markings.size} \" ];\n" end |
#to_s ⇒ Object
Stringify this place.
98 99 100 |
# File 'lib/petri_net/place.rb', line 98 def to_s "#{@id}: #{@name} (#{@capacity == nil ? -1 : 0}) #{'*' * @markings.length}" end |
#validate ⇒ Object
Validate the setup of this place.
78 79 80 81 82 83 84 |
# 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 |