Class: PetriNet::Graph::Node

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

Direct Known Subclasses

ReachabilityGraph::Node

Instance Attribute Summary collapse

Attributes inherited from Base

#logger

Instance Method Summary collapse

Methods inherited from Base

#next_object_id, #reset

Constructor Details

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

Returns a new instance of Node.

Yields:

  • (_self)

Yield Parameters:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/petri_net/graph/node.rb', line 23

def initialize(graph, options = {}, &block)
    @graph = graph
    @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] 
    @start = (options[: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

#graphObject

The graph this node belongs to



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

def graph
  @graph
end

#idObject (readonly)

unique ID



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

def id
  @id
end

#inputsObject (readonly)

Incoming edges



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

def inputs
  @inputs
end

#labelObject (readonly)

Label of the node



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

def label
  @label
end

#markingsObject (readonly)

Makking this node represents



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

def markings
  @markings
end

#nameObject (readonly)

human readable name



5
6
7
# File 'lib/petri_net/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/graph/node.rb', line 13

def omega_marked
  @omega_marked
end

#outputsObject (readonly)

Outgoing edges



17
18
19
# File 'lib/petri_net/graph/node.rb', line 17

def outputs
  @outputs
end

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



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/petri_net/graph/node.rb', line 106

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



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/petri_net/graph/node.rb', line 50

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_idObject



97
98
99
# File 'lib/petri_net/graph/node.rb', line 97

def gv_id
    "N#{@id}"
end

#include_place(place) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/petri_net/graph/node.rb', line 80

def include_place(place)
    places = @graph.net.get_place_list
    included_places = Array.new
    i = 0
    @markings.each do |m|
        if m > 0
            included_places << places[i]
        end
        i += 1
    end
    included_places.include? place
end

#infinite?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/petri_net/graph/node.rb', line 45

def infinite?
    @omega_marked
end

#to_gvObject



101
102
103
# File 'lib/petri_net/graph/node.rb', line 101

def to_gv
    "\t#{self.gv_id} [ label = \"#{@markings}\" ];\n"
end

#to_sObject



143
144
145
# File 'lib/petri_net/graph/node.rb', line 143

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

#validateObject



93
94
95
# File 'lib/petri_net/graph/node.rb', line 93

def validate
    true
end