Module: Plexus::Labels

Included in:
GraphBuilder
Defined in:
lib/plexus/labels.rb

Overview

This module add support for labels.

The graph labeling process consist in assigning labels, traditionally represented by integers, to the edges or vertices, or both, of a graph. Plexus recommands you abide by this rule and do use integers as labels.

Some algorithms can make use of labeling (sea Search for instance).

Instance Method Summary collapse

Instance Method Details

#[](u) ⇒ Object

Return a label for an edge or vertex.



12
13
14
# File 'lib/plexus/labels.rb', line 12

def [](u)
  (u.is_a? Plexus::Arc) ? edge_label(u) : vertex_label(u)
end

#[]=(u, value) ⇒ Object

Set a label for an edge or vertex.



17
18
19
# File 'lib/plexus/labels.rb', line 17

def []=(u, value)
  (u.is_a? Plexus::Arc) ? edge_label_set(u, value) : vertex_label_set(u, value)
end

#clear_all_labelsObject

Delete all graph labels.



51
52
53
54
# File 'lib/plexus/labels.rb', line 51

def clear_all_labels
  @vertex_labels = {}
  @edge_labels = {}
end

#delete_label(u) ⇒ Object

Delete a label entirely.



22
23
24
# File 'lib/plexus/labels.rb', line 22

def delete_label(u)
  (u.is_a? Plexus::Arc) ? edge_label_delete(u) : vertex_label_delete(u)
end

#edge_label(u, v = nil, n = nil) ⇒ Object

Get the label for an edge.



38
39
40
41
# File 'lib/plexus/labels.rb', line 38

def edge_label(u, v = nil, n = nil)
  u = edge_convert(u,v,n)
  edge_label_dict[u]
end

#edge_label_delete(u, v = nil, n = nil) ⇒ Object

Delete an edge label.



57
58
59
60
# File 'lib/plexus/labels.rb', line 57

def edge_label_delete(u, v = nil, n = nil)
  u = edge_convert(u, v, n)
  edge_label_dict.delete(u)
end

#edge_label_set(u, v = nil, l = nil, n = nil) ⇒ Object

Set the label for an edge.



44
45
46
47
48
# File 'lib/plexus/labels.rb', line 44

def edge_label_set(u, v = nil, l = nil, n = nil)
  u.is_a?(Plexus::Arc) ? l = v : u = edge_convert(u, v, n)
  edge_label_dict[u] = l
  self
end

#vertex_label(v) ⇒ Object

Get the label for an edge.



27
28
29
# File 'lib/plexus/labels.rb', line 27

def vertex_label(v)
  vertex_label_dict[v]
end

#vertex_label_delete(v) ⇒ Object

Delete a vertex label.



63
64
65
# File 'lib/plexus/labels.rb', line 63

def vertex_label_delete(v)
  vertex_label_dict.delete(v)
end

#vertex_label_set(v, l) ⇒ Object

Set the label for an edge.



32
33
34
35
# File 'lib/plexus/labels.rb', line 32

def vertex_label_set(v, l)
  vertex_label_dict[v] = l
  self
end