0

I am new to RGL. I want to show a graph of all parent and children type relations. I have written the following code.

My code is as:
require 'rgl/adjacency'
require 'rgl/dot'
input_arr = [1,2,2,3,2,4,4,5,6,4,1,6]

We need to give input as following to generate graph. dg=RGL::DirectedAdjacencyGraph[1,2,2,3,2,4,4,5,6,4,1,6]
dg.write_to_graphic_file('jpg')

But I want to give the array dynamically, ie I want to pass input_arr. But it is not working. can anybody explain how to go?

VenkatK
  • 1,295
  • 1
  • 9
  • 21

1 Answers1

2

Eventually I could solve my issue.

I have written like the folowing:
I have processed my main_arr variable something like this.
main_arr=[[1,2],[2,3],[2,4],[4,5],[6,4],[1,6]]
dg=RGL::DirectedAdjacencyGraph[]
main_arr.each do |ma|
  dg.add_edge ma[0],ma[1]
end

Now it is working fine. Now I can pass any dynamic values to generate graph.

VenkatK
  • 1,295
  • 1
  • 9
  • 21