class Object
Public Instance Methods
load_distance_matrix(graph, file)
click to toggle source
Loads a distance matrix. Rows correspond to source nodes and columns correspond to destination nodes. -1 indicates a non-connection, 0 indicates the same node, and positive values indicate an edge.
# File lib/usearchtree/graphloader.rb, line 23 def load_distance_matrix graph, file File.open(file, 'r') do |f| f.each.reject do |line| line.empty? or line.start_with? '#' end.each.with_index do |line, i| costs = line.split costs = costs.collect &:to_i costs.each.with_index do |cost, j| unless graph.length > j graph.add_node end unless cost.zero? or cost == -1 graph.add_edge i, j, cost end end end end return graph end
load_label_nodes(graph, file)
click to toggle source
Consumes a node_labels.txt file e.g. people.sc.fsu.edu/~jburkardt%20/data/graph_representation/mst_node_labels.txt
# File lib/usearchtree/graphloader.rb, line 3 def load_label_nodes graph, file File.open(file, 'r') do |f| f.lazy.reject do |line| line.chomp.empty? or line.start_with? '#' end.with_index do |line, i| line.chomp! if not line.empty? and not line.start_with? '#' unless graph.length > i graph.add_node end graph.label_node(i, line) end end end return graph end