Mercurial > hg > Database > Christie
view scripts/paxos.rb @ 223:1c37472fc00d
add catch command from editors
author | ichikitakahiro <e165713@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 28 Nov 2019 15:12:37 +0900 |
parents | 1e696b2d3c6d |
children |
line wrap: on
line source
node_name_list = ["proposer", "acceptor", "learner"] def create_nodes(name, node_num) (0..node_num - 1).map { |i| i = name + i.to_s } end def print_dot(connections) puts "digraph paxos {" connections.each { |connection| print "\t" print connection[0] print " -> " print connection[1] print ' [label="' + connection[2] + '"]' puts } puts "}" end node_list = Array.new node_name_list.each_with_index { |node_name, i| node_num = ARGV.shift while !node_num printf("input %s num : ", node_name) node_num = STDIN.gets.chomp end node_list << create_nodes(node_name, node_num.to_i) } connections = Array.new node_list.each_with_index { |nodes1, i| if i == node_name_list.size - 1 break end nodes2 = node_list[i+1] nodes1.each_with_index{ |node1, j| nodes2.each_with_index{ |node2, k| connections << [node1, node2, node2] if i == 0 connections << [node2,node1, node1] end } } } print_dot(connections.sort!)