#!/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