Class: GraphMatrixDb
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- GraphMatrixDb
- Defined in:
- lib/graphify/graph_matrix_db.rb
Instance Method Summary collapse
- #edges ⇒ Object
- #get_in_edge_matrix(vertex) ⇒ Object
- #get_out_edge_matrix(vertex) ⇒ Object
- #vertices ⇒ Object
Instance Method Details
#edges ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/graphify/graph_matrix_db.rb', line 31 def edges result = [] (0..(@edge_matrix.length - 1)).each do |index| (0..(@edge_matrix.length - 1)).each do |s_index| result << [index, s_index] if @edge_matrix[index][s_index] == 1 end end result end |
#get_in_edge_matrix(vertex) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/graphify/graph_matrix_db.rb', line 14 def get_in_edge_matrix(vertex) return if (vertex < 0 || vertex >= @edge_matrix) vertices = [] (0..(@edge_matrix.length - 1)).each do |index| vertices << index if @edge_matrix[index][vertex] == 1 end vertices end |
#get_out_edge_matrix(vertex) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/graphify/graph_matrix_db.rb', line 5 def get_out_edge_matrix(vertex) return if (vertex < 0 || vertex >= @edge_matrix.length) vertices = [] (0..(@edge_matrix.length - 1)).each do |index| vertices << index if @edge_matrix[vertex][index] == 1 end vertices end |
#vertices ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/graphify/graph_matrix_db.rb', line 23 def vertices vertices = [] (0..(@edge_matrix.length - 1)).each do |index| vertices << index end vertices end |