Module: Graphos::Weighted::TextFactory

Defined in:
lib/graphos/weighted/text_factory.rb

Class Method Summary collapse

Class Method Details

.read(path) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/graphos/weighted/text_factory.rb', line 4

def self.read path
  lines = IO.readlines(path)
  graph = Graph.new(lines[0].to_i)
  lines[1..-1].each do |line|
    args = line.split(/[ \n]+/)
    graph.add_edge args[0].to_i-1, args[1].to_i-1, args[2].to_f
  end
  graph
end