Hi Juan,

Juan Manuel Tirado wrote:
> Hi everyone,
> 
>    I've been working around with graph-tool and I have found a strange
> behaviour.
> 
>    A have this input .dot file
> 
> graph G {
> 0 ;
> 10 ;
> 200 ;
> 1000 ;
> 0--200 ;
> 10--200 ;
> 1000--200 ;
> 1000--10 ;
> }
> 
> I load the graph in graph_tool using g=load_graph("example.dot") and
> everything is OK. Now I want to know the output_degree of the node with
> identifier 200 (index 2). I use:
> 
> g.vertex(2).out_degree() that returns 2
> 
> Obviously vertex with identifier 200 (index 2) must return 3.

There is no promise that the ordering in the dot file will correspond to
the indexes, since no implicit ordering in the dot format can always be
assumed; the vertex list may even be absent.

You may check which vertex is which with the "vertex_name" property
which is always loaded with .dot files:

    name = g.vertex_properties['vertex_name']
    for v in g.vertices():
        print int(v), name[v]

Which outputs:

    0 0
    1 10
    2 1000
    3 200

So, vertex 200 is g.vertex(3), which has out_degree 3, as expected.

> I have executed g.save("graphtool_dump.dot") with the following output:
> graph G {
> 0;
> 10;
> 1000;
> 200;
> 0--200 ;
> 10--200 ;
> 1000--200 ;
> 1000--10 ;
> }
>
> The nodes have been reordered (probably following alphabetic order) and now
> the vertex with identifier "200" is in position 3 instead of 2. This
> behaviour can be very annoying in some cases, and can lead to confusion.
> Does exist any way to avoid this reordering?

Not really, since this is the way that Boost loads dot files. Note that
it shouldn't matter which index a node has, since its identity is stored
in the 'vertex_name' property shown above. But, if you want more strict
ordering in the output file, I recommend using the graphml format.

Cheers,
Tiago

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
graph-tool mailing list
graph-tool@forked.de
http://lists.forked.de/mailman/listinfo/graph-tool

Reply via email to