Mercurial > hg > Database > Christie
comparison scripts/paxos.rb @ 169:1e696b2d3c6d
add paxos.rb paxos.dot
author | akahori |
---|---|
date | Tue, 22 Jan 2019 18:32:13 +0900 |
parents | scripts/ring.rb@77169cd8a5e8 |
children |
comparison
equal
deleted
inserted
replaced
168:c7300be0fff6 | 169:1e696b2d3c6d |
---|---|
1 node_name_list = ["proposer", "acceptor", "learner"] | |
2 | |
3 def create_nodes(name, node_num) | |
4 (0..node_num - 1).map { |i| | |
5 i = name + i.to_s | |
6 } | |
7 end | |
8 | |
9 | |
10 def print_dot(connections) | |
11 puts "digraph paxos {" | |
12 connections.each { |connection| | |
13 print "\t" | |
14 print connection[0] | |
15 print " -> " | |
16 print connection[1] | |
17 print ' [label="' + connection[2] + '"]' | |
18 puts | |
19 } | |
20 puts "}" | |
21 end | |
22 | |
23 node_list = Array.new | |
24 node_name_list.each_with_index { |node_name, i| | |
25 node_num = ARGV.shift | |
26 while !node_num | |
27 printf("input %s num : ", node_name) | |
28 node_num = STDIN.gets.chomp | |
29 end | |
30 node_list << create_nodes(node_name, node_num.to_i) | |
31 } | |
32 connections = Array.new | |
33 | |
34 node_list.each_with_index { |nodes1, i| | |
35 if i == node_name_list.size - 1 | |
36 break | |
37 end | |
38 nodes2 = node_list[i+1] | |
39 nodes1.each_with_index{ |node1, j| | |
40 | |
41 nodes2.each_with_index{ |node2, k| | |
42 connections << [node1, node2, node2] | |
43 if i == 0 | |
44 connections << [node2,node1, node1] | |
45 end | |
46 } | |
47 } | |
48 } | |
49 | |
50 print_dot(connections.sort!) |