169
|
1 node_name_list = ["proposer", "acceptor", "learner"]
|
|
2
|
|
3 def create_nodes(name, node_num)
|
140
|
4 (0..node_num - 1).map { |i|
|
169
|
5 i = name + i.to_s
|
140
|
6 }
|
|
7 end
|
|
8
|
169
|
9
|
140
|
10 def print_dot(connections)
|
169
|
11 puts "digraph paxos {"
|
140
|
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
|
169
|
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 }
|
140
|
32 connections = Array.new
|
169
|
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 }
|
140
|
48 }
|
|
49
|
169
|
50 print_dot(connections.sort!) |