Class: GraphReader::Graph
- Inherits:
-
Object
- Object
- GraphReader::Graph
- Includes:
- ReadHelper
- Defined in:
- lib/graph-reader.rb
Instance Attribute Summary collapse
-
#adj_matrix ⇒ Object
Returns the value of attribute adj_matrix.
-
#edges ⇒ Object
Returns the value of attribute edges.
-
#nodes ⇒ Object
Returns the value of attribute nodes.
Instance Method Summary collapse
-
#initialize(edge_path) ⇒ Graph
constructor
A new instance of Graph.
- #neighbor?(n1, n2) ⇒ Boolean
Methods included from ReadHelper
Constructor Details
#initialize(edge_path) ⇒ Graph
Returns a new instance of Graph.
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_matrix ⇒ Object
Returns the value of attribute adj_matrix.
8 9 10 |
# File 'lib/graph-reader.rb', line 8 def adj_matrix @adj_matrix end |
#edges ⇒ Object
Returns the value of attribute edges.
8 9 10 |
# File 'lib/graph-reader.rb', line 8 def edges @edges end |
#nodes ⇒ Object
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
25 26 27 |
# File 'lib/graph-reader.rb', line 25 def neighbor?(n1, n2) @adj_matrix[@adj_map[n1]][@adj_map[n2]] == 1 end |