changeset 29:414fcce36e90

add output dot file scripts
author kazz <kazz@cr.ie.u-ryukyu.ac.jp>
date Tue, 17 Jan 2012 14:17:13 +0900
parents 98ab26e09a98
children b5a21baf0b07
files scripts/ring.rb scripts/test.dot scripts/tree.rb
diffstat 3 files changed, 74 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/ring.rb	Tue Jan 17 14:17:13 2012 +0900
@@ -0,0 +1,28 @@
+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
+nodes = create_nodes(node_num)
+connections = Array.new
+nodes.each_with_index { |node, i|
+  connections << [nodes[i], nodes[(i + 1) % node_num], "right"]
+  connections << [nodes[i], nodes[i - 1], "left"]
+}
+print_dot(connections)
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/test.dot	Tue Jan 17 14:17:13 2012 +0900
@@ -0,0 +1,8 @@
+digraph ring {
+	node0 -> node1 [label="right"]
+	node1 -> node0 [label="left"]
+	node1 -> node2 [label="right"]
+	node2 -> node1 [label="left"]
+	node2 -> node0 [label="right"]
+	node0 -> node2 [label="left"]
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/tree.rb	Tue Jan 17 14:17:13 2012 +0900
@@ -0,0 +1,38 @@
+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
+nodes = create_nodes(node_num)
+connections = Array.new
+nodes.each_with_index { |node, i|
+  parent = (i - 1) / 2;
+  child1 = 2 * i + 1;
+  child2 = 2 * i + 2;
+  if parent < i - 1 then
+    connections << [nodes[i], nodes[parent], "parent"]
+  end
+  if child1 < node_num then
+    connections << [nodes[i], nodes[child1], "child1"]
+  end
+  if child2 < node_num then
+    connections << [nodes[i], nodes[child2], "child2"]
+  end
+}
+print_dot(connections)
+