Graphs with decorated edges

E

Edgardo Hames

Hello dear rubyists,

I'm working on an application that simulates several components
interacting with each other. I would like to represent this situation
using a graph, where each component is a vertex and the interaction of
2 components is an edge between them.

I've taking using RGL [0] to handle graphs and it seems very nice.
However, I don't find a way to add a label or a list of labels to the
edges.

Have I overlooked this functionality in RGL? Can you suggest an
alternative lib to handle graphs?

Thanks and kind regards,
Ed

[0] http://rgl.rubyforge.org/rgl/index.html

--=20
Encontr=E1 a "Tu psic=F3pata favorito" http://tuxmaniac.blogspot.com

The future is not what it used to be.
-- Paul Val=E9ry
 
S

Stephen Duncan

I've just recently worked on something similar (making a picture of
the graph of components configured in an XML file). I ended up using
GRATR, which is just a fork of RGL: http://gratr.rubyforge.org/ It
also didn't seem to handle the labels for edges, so I used the
DOT::DOTDigraph class directly instead of the actual graph object.

I added the following directly to that class to get the output using
DOT functionality:

class DOT::DOTDigraph
def write_to_graphic_file(fmt=3D'png', dotfile=3D'graph')
src =3D dotfile + '.dot'
dot =3D dotfile + '.' + fmt

File.open(src, 'w') {|f| f << self.to_s << "\n"}

system( "dot -T#{fmt} #{src} -o #{dot}" )
dot
end
end

Adding nodes looks like this:

@graph << DOT::DOTNode.new('name' =3D> name, 'label' =3D> label,
'fontsize' =3D> fontsize)

And adding edges looks like this:

@graph << DOT::DOTDirectedArc.new('from' =3D> from, 'to' =3D> to, 'label'
=3D> label, 'fontsize' =3D> fontsize)

There may be a better way to do it, but that's what I came up with.

-Stephen


Hello dear rubyists,

I'm working on an application that simulates several components
interacting with each other. I would like to represent this situation
using a graph, where each component is a vertex and the interaction of
2 components is an edge between them.

I've taking using RGL [0] to handle graphs and it seems very nice.
However, I don't find a way to add a label or a list of labels to the
edges.

Have I overlooked this functionality in RGL? Can you suggest an
alternative lib to handle graphs?

Thanks and kind regards,
Ed

[0] http://rgl.rubyforge.org/rgl/index.html

--
Encontr=E1 a "Tu psic=F3pata favorito" http://tuxmaniac.blogspot.com

The future is not what it used to be.
-- Paul Val=E9ry


--=20
Stephen Duncan Jr
www.stephenduncanjr.com
 
S

Sylvain Joyeux

I've taking using RGL [0] to handle graphs and it seems very nice.
However, I don't find a way to add a label or a list of labels to the
edges.

Have I overlooked this functionality in RGL? Can you suggest an
alternative lib to handle graphs?
You can check the wrapper around boost::graph I wrote for one of my projets.
Check the documentation of the BGL module at
http://www.laas.fr/~sjoyeux/doc/api/roby/

The main features are:
* a vertex can be any Ruby object
* a vertex can be part of many graphs (see Vertex#each_graph)
* edges can be decorated ('info' parameter to Graph#link and Vertex#[])
* availability of basic boost::graph algorithms: component, DFS, BFS. I
usually add more when I need them ...

You can also check Roby::RelationGraph and Roby::DirectedRelationSupport,
which are specific extensions to the graph API I use for the Roby project.

If you find it useful, I can create a separate project for it.
 
K

Kim T.

Using GRATR, you can add labels to the edges of the graph by adding a
third parameter when you do that add_edge! which is a Hash of options
for that edge. E.g. g.add_edge!(node1, node2, :label => "My edge
label")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,260
Messages
2,571,039
Members
48,768
Latest member
first4landlord

Latest Threads

Top