Class: GraphReader::Graph

Inherits:
Object
  • Object
show all
Includes:
ReadHelper
Defined in:
lib/graph-reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ReadHelper

#adding_edges, #init_edges

Constructor Details

#initialize(edge_path) ⇒ Graph

Returns a new instance of Graph.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/graph-reader.rb', line 10

def initialize(edge_path)
  raise ArgumentError, "expect (String), got #{edge_path.class}" unless edge_path.instance_of? String
  @nodes = []
  @edges = []
  
  init_edges(edge_path)

  @adj_map = {}
  set_adj_map(@adj_map)

  @adj_matrix = init_adj_matrix(@nodes.size)
  set_adj_matrix(@adj_matrix)
  @dim = @edges.first.attrs.size
end

Instance Attribute Details

#adj_matrixObject

Returns the value of attribute adj_matrix.



8
9
10
# File 'lib/graph-reader.rb', line 8

def adj_matrix
  @adj_matrix
end

#edgesObject

Returns the value of attribute edges.



8
9
10
# File 'lib/graph-reader.rb', line 8

def edges
  @edges
end

#nodesObject

Returns the value of attribute nodes.



8
9
10
# File 'lib/graph-reader.rb', line 8

def nodes
  @nodes
end

Instance Method Details

#neighbor?(n1, n2) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/graph-reader.rb', line 25

def neighbor?(n1, n2)
  @adj_matrix[@adj_map[n1]][@adj_map[n2]] == 1
end