Class: PetriNet::ReachabilityGraph::Node

Inherits:
Base
  • Object
show all
Includes:
Comparable
Defined in:
lib/petri_net/reachability_graph/node.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#logger

Instance Method Summary collapse

Methods inherited from Base

#next_object_id, #reset

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Node

Returns a new instance of Node.

Yields:

  • (_self)

Yield Parameters:



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(options = {}, &block)
    @id = next_object_id
    @name = (options[:name] or "Node#{@id}")
    @description = (options[:description] or "Node #{@id}")
    @inputs = Array.new
    @outputs = Array.new
    @label = (options[:label] or @name)
    @markings = options[: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

#graphObject

The graph this node belongs to



11
12
13
# File 'lib/petri_net/reachability_graph/node.rb', line 11

def graph
  @graph
end

#idObject (readonly)

unique ID



7
8
9
# File 'lib/petri_net/reachability_graph/node.rb', line 7

def id
  @id
end

#inputsObject (readonly)

Incoming edges



15
16
17
# File 'lib/petri_net/reachability_graph/node.rb', line 15

def inputs
  @inputs
end

#labelObject (readonly)

Label of the node



19
20
21
# File 'lib/petri_net/reachability_graph/node.rb', line 19

def label
  @label
end

#markingsObject (readonly)

Makking this node represents



9
10
11
# File 'lib/petri_net/reachability_graph/node.rb', line 9

def markings
  @markings
end

#nameObject (readonly)

human readable name



5
6
7
# File 'lib/petri_net/reachability_graph/node.rb', line 5

def name
  @name
end

#omega_markedObject (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

#outputsObject (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_idObject



69
70
71
# File 'lib/petri_net/reachability_graph/node.rb', line 69

def gv_id
    "N#{@id}"
end

#to_gvObject



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_sObject



115
116
117
# File 'lib/petri_net/reachability_graph/node.rb', line 115

def to_s
    "#{@id}: #{@name} (#{@markings})"
end

#validateObject



65
66
67
# File 'lib/petri_net/reachability_graph/node.rb', line 65

def validate
    true
end