0

How to convert following graph into 'set'. Because i have one graph. i need to check that graph is subset of this graph.

require 'rgl/adjacency'
dg = RGL::DirectedAdjacencyGraph[1,2,3,4,5,6,3,2,4]

thanks.

Naren Sisodiya
  • 7,158
  • 2
  • 24
  • 35
Guru
  • 1
  • 1

1 Answers1

1

The to_set method will do it for you.

require 'rgl/adjacency'

dg = RGL::DirectedAdjacencyGraph[1,2,3,4,5,6,3,2,4]
dg_subgraph =  RGL::DirectedAdjacencyGraph[1,2]

dg_subgraph.to_set.subset? dg.to_set # => true

Why?

As per https://github.com/javanthropus/rgl/blob/master/lib/rgl/adjacency.rb#L11

The class for representing the adjacency list of a vertex is, by default, a Set

unless you have configured it otherwise.

egghese
  • 2,193
  • 16
  • 26
  • i have one more problem. ie) values in dg is => [(1,2), (2,3), (3,4), (4,5), (5,6), (3,2), (2,4)]. i need to change this output as [[1,2],[2,3],[3,4],[4,5],[5,6],[3,2],[2,4]]. I mean, want to change graph into array. Thanks in advance. – Guru Mar 25 '13 at 12:04
  • `dg.edges.map { |edge| edge.to_a }` – egghese Mar 26 '13 at 04:56
  • Well you will get the result as a return from the above expression, this needs to be assigned to a variable. i.e. `edge_list_a = dg.edges.map { |edge| edge.to_a }` – egghese Mar 26 '13 at 20:09