Class: PetriNet::CoverabilityGraph

Inherits:
Base
  • Object
show all
Defined in:
lib/petri_net/coverability_graph/graph.rb

Defined Under Namespace

Classes: Edge, Node

Instance Attribute Summary

Attributes inherited from Base

#logger

Instance Method Summary collapse

Methods inherited from Base

#next_object_id, #reset

Constructor Details

#initialize(net, options = Hash.new) ⇒ CoverabilityGraph

Returns a new instance of CoverabilityGraph.



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/petri_net/coverability_graph/graph.rb', line 4

def initialize(net, options = Hash.new)
    @objects = Array.new
    @nodes = Hash.new
    @edges = Hash.new
    @name = net.name
    if options['unlimited'].nil? 
        @unlimited = true 
    else 
        @unlimited = options['unlimited']
    end
end

Instance Method Details

#add_node(node) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/petri_net/coverability_graph/graph.rb', line 16

def add_node(node)
    double = false
    inf = false
    @nodes.each_value do |n|
        begin
            if node > @objects[n]
                if @unlimited
                    double = n
                    break
                    #return @objects[n].id *-1
                else
                    raise PetriNet::Graph::InfiniteReachabilityGraphError
                end
            end
            if -Float::INFINITY == (node <=> @objects[n])
                inf = true
            end
        rescue ArgumentError
            #just two different markings, completly ok
        end
    end
    # if there was a smaller marking
    return (@objects[double].id * -1) if double
    node_index = @objects.index node
    # if there already is a node with this marking
    return @objects[node_index].id * -1 unless node_index.nil?

    return -Float::INFINITY if inf

    if (node.validate && (!@nodes.include? node.name))
        @objects[node.id] = node
        @nodes[node.name] = node.id
        node.graph = self
        return node.id
    end
    return false
end