[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Graphs with decorated edges

Edgardo Hames

3/4/2007 12:08:00 AM

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/...

--
Encontrá a "Tu psicópata favorito" http://tuxmaniac.bl...

The future is not what it used to be.
-- Paul Valéry

2 Answers

Stephen Duncan Jr

3/4/2007 1:05:00 AM

0

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.ruby... 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='png', dotfile='graph')
src = dotfile + '.dot'
dot = 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' => name, 'label' => label,
'fontsize' => fontsize)

And adding edges looks like this:

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

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

-Stephen


On 3/3/07, Edgardo Hames <ehames@gmail.com> wrote:
> 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/...
>
> --
> Encontrá a "Tu psicópata favorito" http://tuxmaniac.bl...
>
> The future is not what it used to be.
> -- Paul Valéry
>
>


--
Stephen Duncan Jr
www.stephenduncanjr.com

Sylvain Joyeux

3/4/2007 3:35:00 PM

0

> 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...

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.
--
Sylvain