Class: Trixer::Matrix
- Inherits:
-
Object
- Object
- Trixer::Matrix
- Defined in:
- lib/trixer/matrix.rb
Class Method Summary collapse
Class Method Details
.from_adjacency_list(adjacency_list:, objects:) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/trixer/matrix.rb', line 6 def from_adjacency_list(adjacency_list:, objects:) matrix = Array.new(objects.size) { Array.new(objects.size) { 0 } } objects.each_with_index do |obj, i| adjacency_list[obj].each do |linked_obj| j = objects.index(linked_obj) matrix[i][j] = 1 if j end end matrix end |