Class: PetriNet::Graph::Edge

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

Direct Known Subclasses

ReachabilityGraph::Edge

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| ... } ⇒ Edge

Creates an edge for PetriNet::Graph

Yields:

  • (_self)

Yield Parameters:



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/petri_net/graph/edge.rb', line 18

def initialize(graph, options = {}, &block)
    @graph = graph
    @id = next_object_id
    @name = (options[:name] or "Edge#{@id}")
    @description = (options[:description] or "Edge #{@id}")
    @source = options[:source] 
    @destination = options[:destination]
    @label = (options[:label] or @name)
    @probability = options[:probability]
    @transition = (options[:transition] or "")

    yield self unless block.nil?
end

Instance Attribute Details

#destinationObject (readonly)

Destination of the edge



13
14
15
# File 'lib/petri_net/graph/edge.rb', line 13

def destination
  @destination
end

#graphObject

Graph this edge belongs to



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

def graph
  @graph
end

#idObject (readonly)

Unique ID



5
6
7
# File 'lib/petri_net/graph/edge.rb', line 5

def id
  @id
end

#nameObject (readonly)

Human readable name



3
4
5
# File 'lib/petri_net/graph/edge.rb', line 3

def name
  @name
end

#probabilityObject

Probability of the relating transition



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

def probability
  @probability
end

#sourceObject (readonly)

Source of the edge



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

def source
  @source
end

#transitionObject (readonly)

Transition this edge is representing



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

def transition
  @transition
end

Instance Method Details

#==(object) ⇒ Object



41
42
43
44
# File 'lib/petri_net/graph/edge.rb', line 41

def ==(object)
    return false unless object.class.to_s == "PetriNet::ReachabilityGraph::Edge"
    (@source == object.yource && @destination == oject.destination)
end

#to_gvObject



37
38
39
# File 'lib/petri_net/graph/edge.rb', line 37

def to_gv
    "\t#{@source.gv_id} -> #{@destination.gv_id}#{probability_to_gv};\n"
end

#to_sObject



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

def to_s
    "#{@id}: #{@name} #{@source.id} -> #{@destination} )"
end

#validateObject

Validates the data holded by this edge, this will be used while adding the edge to the graph



33
34
35
# File 'lib/petri_net/graph/edge.rb', line 33

def validate
    true
end