[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] undirected graph console output
From: |
Tamas Nepusz |
Subject: |
Re: [igraph] undirected graph console output |
Date: |
Fri, 6 Mar 2015 10:47:42 +0100 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
Hi,
> 1) In the graphml output, for both edges, it is seeing 55657 as the
> source, for which I would have preferred seeing the same order in the
> data source.
The _current_ implementation of igraph happens to list the vertex with the
smaller _internal_ ID as the first one, although this is not guaranteed not to
change in the future. (Note that the internal ID is usually not the same as the
_name_ of the vertex -- the internal ID is always between 0 and |V|-1 and
igraph maintains them; it may even reassign internal IDs if you delete
vertices). If the order of the source and target really matters to you, then
I start to wonder whether your graph is in fact directed and not undirected.
> 2) In the string representation of the graph, why is 59107 seen as the
> source when the graphml file tells otherwise?
Have you posted the full output of the string representation of the graph or
just a snippet? When igraph prints the string representation, it should list
the edge in both directions if the string representation uses the adjacency
list format.
Okay, I think I have to be a bit more detailed here. When you "print" the graph
in the Python console, igraph actually prints a "graph summary", represented by
a GraphSummary object. The GraphSummary object is constructed on-the-fly. So,
print(g) is actually equivalent to summary(g, verbosity=1, width=None), which
in turn invokes print(GraphSummary(g, verbosity=1, width=None)).
Now, the GraphSummary object supports three different formats for representing
the edge list: "edgelist", "compressed" and "adjlist". "compressed" is the
simplest representation where you get a bunch of strings like A--B (or A->B in
case of directed graphs), separated by commas. "adjlist" is the one you see; in
this case, each row represents a vertex (which is put in the front), followed
by "--" or "->", then by the neighbors of the vertex. As a consequence, for
undirected graphs, each edge should appear twice. "edgelist" is the most
verbose representation where every row is a single edge and it even lists the
edge attributes. By default, GraphSummary() chooses a format automatically
based on a few simple properties of the graph (mostly the median out-degree).
However, you can specify a format on your own so you can test it yourself:
>>> g = Graph([(0,1), (0,2)])
>>> g.is_directed()
False
>>> summary(g, verbosity=1, width=None, edge_list_format="compressed")
IGRAPH U--- 3 2 --
+ edges:
0--1 0--2
>>> summary(g, verbosity=1, width=None, edge_list_format="adjlist")
IGRAPH U--- 3 2 --
+ edges:
0 -- 1 2
1 -- 0
2 -- 0
You can see that the "adjlist" format indeed lists each edge twice. I think
this also answers your third question (i.e. whether there is a "pattern" in the
order of the edges).
All the best,
T.