Class: PetriNet::Graph::Node
- Includes:
- Comparable
- Defined in:
- lib/petri_net/graph/node.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#graph ⇒ Object
The graph this node belongs to.
-
#id ⇒ Object
readonly
unique ID.
-
#inputs ⇒ Object
readonly
Incoming edges.
-
#label ⇒ Object
readonly
Label of the node.
-
#markings ⇒ Object
readonly
Makking this node represents.
-
#name ⇒ Object
readonly
human readable name.
-
#omega_marked ⇒ Object
readonly
Omega-marked node (unlimited Petrinet -> coverabilitygraph).
-
#outputs ⇒ Object
readonly
Outgoing edges.
-
#start ⇒ Object
readonly
True if this is the start-marking.
Attributes inherited from Base
Instance Method Summary collapse
-
#<=>(object) ⇒ Object
Compare-operator, other Operators are available through comparable-mixin.
-
#add_omega(object) ⇒ Object
Add an omega-marking to a specified place.
- #gv_id ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ Node
constructor
A new instance of Node.
- #to_gv ⇒ Object
- #to_s ⇒ Object
- #validate ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Node
Returns a new instance of Node.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/petri_net/graph/node.rb', line 23 def initialize( = {}, &block) @id = next_object_id @name = ([:name] or "Node#{@id}") @description = ([:description] or "Node #{@id}") @inputs = Array.new @outputs = Array.new @label = ([:label] or @name) @markings = [:markings] @start = ([:start] or false) if @markings.nil? raise ArgumentError.new "Every Node needs markings" end if @markings.include? Float::INFINITY @omega_marked = true else @omega_marked = false end yield self unless block.nil? end |
Instance Attribute Details
#graph ⇒ Object
The graph this node belongs to
11 12 13 |
# File 'lib/petri_net/graph/node.rb', line 11 def graph @graph end |
#id ⇒ Object (readonly)
unique ID
7 8 9 |
# File 'lib/petri_net/graph/node.rb', line 7 def id @id end |
#inputs ⇒ Object (readonly)
Incoming edges
15 16 17 |
# File 'lib/petri_net/graph/node.rb', line 15 def inputs @inputs end |
#label ⇒ Object (readonly)
Label of the node
19 20 21 |
# File 'lib/petri_net/graph/node.rb', line 19 def label @label end |
#markings ⇒ Object (readonly)
Makking this node represents
9 10 11 |
# File 'lib/petri_net/graph/node.rb', line 9 def markings @markings end |
#name ⇒ Object (readonly)
human readable name
5 6 7 |
# File 'lib/petri_net/graph/node.rb', line 5 def name @name end |
#omega_marked ⇒ Object (readonly)
Omega-marked node (unlimited Petrinet -> coverabilitygraph)
13 14 15 |
# File 'lib/petri_net/graph/node.rb', line 13 def omega_marked @omega_marked end |
#outputs ⇒ Object (readonly)
Outgoing edges
17 18 19 |
# File 'lib/petri_net/graph/node.rb', line 17 def outputs @outputs end |
#start ⇒ Object (readonly)
True if this is the start-marking
21 22 23 |
# File 'lib/petri_net/graph/node.rb', line 21 def start @start end |
Instance Method Details
#<=>(object) ⇒ Object
Compare-operator, other Operators are available through comparable-mixin
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/petri_net/graph/node.rb', line 88 def <=>(object) return nil unless object.class.to_s == "PetriNet::ReachabilityGraph::Node" if @markings == object.markings return 0 end counter = 0 less = true self.markings.each do |marking| if marking <= object.markings[counter] && less less = true else less = false break end counter += 1 end if less return -1 end counter = 0 more = true self.markings.each do |marking| if marking >= object.markings[counter] && more more = true else more = false break end counter += 1 end if more return 1 end return nil end |
#add_omega(object) ⇒ Object
Add an omega-marking to a specified place
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/petri_net/graph/node.rb', line 45 def add_omega object ret = Array.new 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 ⇒ Object
79 80 81 |
# File 'lib/petri_net/graph/node.rb', line 79 def gv_id "N#{@id}" end |
#to_gv ⇒ Object
83 84 85 |
# File 'lib/petri_net/graph/node.rb', line 83 def to_gv "\t#{self.gv_id} [ label = \"#{@markings}\" ];\n" end |
#to_s ⇒ Object
125 126 127 |
# File 'lib/petri_net/graph/node.rb', line 125 def to_s "#{@id}: #{@name} (#{@markings})" end |
#validate ⇒ Object
75 76 77 |
# File 'lib/petri_net/graph/node.rb', line 75 def validate true end |