Class: PetriNet::ReachabilityGraph::Node
- Includes:
- Comparable
- Defined in:
- lib/petri_net/reachability_graph/node.rb
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.
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.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/petri_net/reachability_graph/node.rb', line 21 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] 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/reachability_graph/node.rb', line 11 def graph @graph end |
#id ⇒ Object (readonly)
unique ID
7 8 9 |
# File 'lib/petri_net/reachability_graph/node.rb', line 7 def id @id end |
#inputs ⇒ Object (readonly)
Incoming edges
15 16 17 |
# File 'lib/petri_net/reachability_graph/node.rb', line 15 def inputs @inputs end |
#label ⇒ Object (readonly)
Label of the node
19 20 21 |
# File 'lib/petri_net/reachability_graph/node.rb', line 19 def label @label end |
#markings ⇒ Object (readonly)
Makking this node represents
9 10 11 |
# File 'lib/petri_net/reachability_graph/node.rb', line 9 def markings @markings end |
#name ⇒ Object (readonly)
human readable name
5 6 7 |
# File 'lib/petri_net/reachability_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/reachability_graph/node.rb', line 13 def omega_marked @omega_marked end |
#outputs ⇒ Object (readonly)
Outgoing edges
17 18 19 |
# File 'lib/petri_net/reachability_graph/node.rb', line 17 def outputs @outputs end |
Instance Method Details
#<=>(object) ⇒ Object
Compare-operator, other Operators are available through comparable-mixin
78 79 80 81 82 83 84 85 86 87 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 |
# File 'lib/petri_net/reachability_graph/node.rb', line 78 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
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/petri_net/reachability_graph/node.rb', line 42 def add_omega object if object.class.to_s == "PetriNet::ReachabilityGraph::Node" if self > object counter = 0 object.markings.each do |marking| if @markings[counter] < marking @markings[counter] = Fload::INFINITY end counter += 1 end else return false end elsif object.class.to_s == "Array" object.each do |place| markings[place] = Float::INFINITY end elsif object.class.to_s == "Fixnum" markings[object] = Float::INFINITY end @omega_marked = true end |
#gv_id ⇒ Object
69 70 71 |
# File 'lib/petri_net/reachability_graph/node.rb', line 69 def gv_id "N#{@id}" end |
#to_gv ⇒ Object
73 74 75 |
# File 'lib/petri_net/reachability_graph/node.rb', line 73 def to_gv "\t#{self.gv_id} [ label = \"#{@markings}\" ];\n" end |
#to_s ⇒ Object
115 116 117 |
# File 'lib/petri_net/reachability_graph/node.rb', line 115 def to_s "#{@id}: #{@name} (#{@markings})" end |
#validate ⇒ Object
65 66 67 |
# File 'lib/petri_net/reachability_graph/node.rb', line 65 def validate true end |