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

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] 
    @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



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_idObject



79
80
81
# File 'lib/petri_net/graph/node.rb', line 79

def gv_id
    "N#{@id}"
end

#to_gvObject



83
84
85
# File 'lib/petri_net/graph/node.rb', line 83

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

#to_sObject



125
126
127
# File 'lib/petri_net/graph/node.rb', line 125

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

#validateObject



75
76
77
# File 'lib/petri_net/graph/node.rb', line 75

def validate
    true
end