annotate scripts/topology/ring.rb @ 31:5c704b9a9a87

add ring script
author kazz <kazz@cr.ie.u-ryukyu.ac.jp>
date Tue, 17 Jan 2012 20:24:46 +0900
parents scripts/ring.rb@414fcce36e90
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 def create_nodes(node_num)
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 (0..node_num - 1).map { |i|
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 i = "node" + i.to_s
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 }
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 end
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 def print_dot(connections)
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 puts "digraph test {"
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 connections.each { |connection|
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 print "\t"
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 print connection[0]
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 print " -> "
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 print connection[1]
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 print ' [label="' + connection[2] + '"]'
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 puts
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 }
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 puts "}"
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 end
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 node_num = ARGV[0].to_i
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 nodes = create_nodes(node_num)
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 connections = Array.new
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 nodes.each_with_index { |node, i|
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 connections << [nodes[i], nodes[(i + 1) % node_num], "right"]
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 connections << [nodes[i], nodes[i - 1], "left"]
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 }
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 print_dot(connections)
414fcce36e90 add output dot file scripts
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28