Sha256: f67a28c41650cdcf24447125fa9e26364b73ec0ef4a96ba06b20e664492de3fb

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

#!/usr/bin/env ruby

require 'graphshaper'

if ARGV.length == 0 || ARGV[0] == "--help"
  puts "  Usage: graphshaper SIZE"
elsif ARGV[0].to_i < 21
  puts "Please choose a size of at least 21"
else
  number_of_vertices = ARGV[0].to_i
  inner_vertices = 20
  
  vertex_output_file = File.new "vertices.csv", "w"
  edge_output_file = File.new "edges.csv", "w"
  logger = Graphshaper::LoggingAdapter.new vertex_output_file, edge_output_file
  
  avocado_db = Graphshaper::AvocadoDbAdapter.new "vertices", "edges"
  
  start_time = Time.now
  graph = Graphshaper::UndirectedGraph.without_orphans_with_order_of inner_vertices, adapters: [logger, avocado_db]
  (number_of_vertices - inner_vertices).times do
    graph.add_vertex do |preferential_attachment|
      preferential_attachment > rand
    end
  end
  end_time = Time.now
  
  ellapsed_time = end_time - start_time
  
  puts "#{graph.order} vertices (saved to vertices.csv)"
  puts "#{graph.size} edges (saved to edges.csv)"
  
  if ellapsed_time < 2
    puts "Generated and saved in about one second"
  elsif ellapsed_time < 60
    puts "Generated and saved in about #{ellapsed_time.round} seconds"
  else
    puts "Generated and saved in about #{ellapsed_time.round / 60} minutes and #{ellapsed_time.round % 60} seconds"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
graphshaper-0.2.1 bin/graphshaper