Mercurial > hg > Database > Alice
changeset 38:7e99ae6e4c7d
add tree script
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 20 Jan 2012 19:15:38 +0900 |
parents | ebd44d3e8578 |
children | 3155337e754e |
files | scripts/topology/treen.rb |
diffstat | 1 files changed, 47 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/topology/treen.rb Fri Jan 20 19:15:38 2012 +0900 @@ -0,0 +1,47 @@ +def create_nodes(node_num) + (0..node_num - 1).map { |i| + i = "node" + i.to_s + } +end + +def print_dot(connections) + puts "digraph test {" + connections.each { |connection| + print "\t" + print connection[0] + print " -> " + print connection[1] + print ' [label="' + connection[2] + '"]' + puts + } + puts "}" +end + +node_num = ARGV[0].to_i +child_num = ARGV[1].to_i +nodes = create_nodes(node_num) +connections = Array.new +nodes.each_with_index { |node, i| + child1 = child_num * i + 1 + if child1 >= node_num then + nodes[i] = "cli" + i.to_s + end +} +nodes.each_with_index { |node, i| + parent = (i - 1) / child_num; + child = Array.new + for n in 1..child_num + child[n] = child_num * i + n + end + + if parent >= 0 then + connections << [nodes[i], nodes[parent], "parent"] + end + for n in 1..child_num + if child[n] < node_num then + connections << [nodes[i], nodes[child[n]], "child"+(n-1).to_s] + end + end +} +print_dot(connections) +