Class: Ogr::GraphAsTriMatrix

Inherits:
GraphAsMatrix show all
Defined in:
lib/ogr/graphs/graph_as_tri_matrix.rb

Overview

Graph implemented as Triangular Matrix

Instance Method Summary collapse

Methods inherited from GraphAsMatrix

#add, #edge?, #get_edge, #neighbors, #remove

Constructor Details

#initializeGraphAsTriMatrix

Returns a new instance of GraphAsTriMatrix.



4
5
6
# File 'lib/ogr/graphs/graph_as_tri_matrix.rb', line 4

def initialize
  @store = TriMatrix.new(0)
end

Instance Method Details

#degree(x) ⇒ Object

Returns vertex degree.



9
10
11
12
13
14
15
16
# File 'lib/ogr/graphs/graph_as_tri_matrix.rb', line 9

def degree(x)
  sum = 0
  vc = (0..@store.size)
  vc.each do |i|
    sum += @store[x, i] if @store[x, i]
  end
  sum
end

#each_edge(vertexes) ⇒ Object

Edge iterator



19
20
21
22
23
24
25
26
# File 'lib/ogr/graphs/graph_as_tri_matrix.rb', line 19

def each_edge(vertexes)
  size = vertexes.size
  (0...size).each do |v0|
    (0...v0).each do |v1|
      yield Edge.new(vertexes[v0], vertexes[v1], @store[v0, v1]) if connected?(v0, v1)
    end
  end
end