From: Horst Duchene Date: 2002-09-23T21:33:06+09:00 Subject: Re: rgl can't produce disconnected graphs ----- Original Message ----- From: "Phlip" > Being a rather simple person, I decided to start by producing the simplest > graph I could possibly make; a graph with no vertices and no edges. > > This proved trivial, so I decided to go to the next level: A graph with one > vertex and no edges: > > dg=RGL::DirectedAdjacencyGraph.new #[1,2 ,2,3 ,2,4, 4,5, 6,4, 1,6] > dg.add_vertex('yo') > dg.write_to_graphic_file('jpg') > system('kview graph.jpg &') > > This produces a graph containing a title, and nothing else. There is no > single vertex. (Graphviz, the back-end for 'write_to_graphic_file', knows > to produce a single vertex here.) > There is one vertex: irb(main):073:0> dg.vertices ["yo"] write_to_graphic_file has a bug. It only shows edges. I fixed it in the latest CVS of rgl/dot.rb. By the way: Support for dot is rather rudimentary. Debugging graph datastructures should better be done using inspect or the graph accessors for vertices and edges. > RGL either has a bug, or its author thinks single vertices are not graphs. > In the above example, if we uncomment the "[1,2 ,2,3 ..." stuff and take > out the .new, we get a graph with 6 vertices. But the 7th is missing. > A graph can have isolated vertices as the above example with the single vertex "yo" shows. The expression dg = RGL::DirectedAdjacencyGraph[1,2, 2,3, 2,4, 4,5, 6,4, 1,6] creates a graph with edges (1-2) (2-3) (2-4) (4-5) (6-4) (1-6), one for each pair in the array given as parameter for the singeleton method RGL::DirectedAdjacencyGraph.[] dg.edges.sort.to_s => "(1-2)(1-6)(2-3)(2-4)(4-5)(6-4)" dg.vertices.sort => [1, 2, 3, 4, 5, 6] The constructor does not take vertices as parameter but edges. Vertices are created internally for the source and target of each edge. Horst