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 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/graphos/weighted/text_factory.rb', line 4 def self.read path lines = IO.readlines(path) size = lines[0].to_i edges = Array.new(size,0) lines[1..-1].each do |line| args = line.split(/[ \n]+/) edges[args[0].to_i-1] += 1 edges[args[1].to_i-1] += 1 end graph = Graph.new(lines[0].to_i,edges) 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 |