0

I used the following code to create a graph.

How to +add vertices at the run time?

require 'rgl/adjacency'
dg = RGL::DirectedAdjacencyGraph[1,2,3,4,5,6,7]
dg.edges
Nazik
  • 8,696
  • 27
  • 77
  • 123
Guru
  • 1
  • 1

1 Answers1

1

You can directly use

dg.add_vertex 8 

Check it with

dg.vertices

But if you want to see the vertex in edges you need to link it with another vertex You need to do this.

dg.add_edge(7,8)

In your case graph is sort of unbalanced.

After initialization, this is what you get

[(1-2), (3-4), (5-6), (7-)]

All the adjacent vertex pair up to form an edge.

Where vertex 7 forms an edge with nil.

Remove it with

dg.remove_edge(7,nil) 

Please read the manual

egghese
  • 2,193
  • 16
  • 26