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

- (Object) [](u)

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

- (Object) []=(u, value)

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

- (Object) clear_all_labels

Delete all graph labels.



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

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

- (Object) delete_label(u)

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

- (Object) edge_label(u, v = nil, n = nil)

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

- (Object) edge_label_delete(u, v = nil, n = nil)

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

- (Object) edge_label_set(u, v = nil, l = nil, n = nil)

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

- (Object) vertex_label(v)

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

- (Object) vertex_label_delete(v)

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

- (Object) vertex_label_set(v, l)

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