igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] Adjacency list format


From: Tamas Nepusz
Subject: Re: [igraph] Adjacency list format
Date: Tue, 08 Nov 2011 14:01:06 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1

Hello,

There is no built-in loader for this format in igraph, but it is fairly easy
to convert between this format and LGL; e.g., by using the following Python
script:

#!/usr/bin/env python
import sys

for line in sys.stdin:
    parts = line.strip().split()
    print "# %s" % parts.pop(0)
    for part in parts:
        print part

Alternatively, you can wrap up a loader for these lines in a few lines of
code in Python (if you are using the Python interface). This is completely
untested but shows the general idea:

#!/usr/bin/env python
from igraph import Graph, UniqueIdGenerator

def load_adjlist(filename, directed=True):
    edgelist = []
    names = UniqueIdGenerator()
    for line in open(filename):
        parts = line.strip().split()
        u = names[parts.pop(0)]
        edgelist.append((u, names[v]) for v in parts)
    g = Graph(edgelist, directed=directed)
    g.vs["name"] = names.values()
    return g

> The unofficial python tutorial page has listed LGL as "aka Adjacency
> list" but this is not the same notion of adjacency list as networkx's.
Yes, the LGL format was originally used by the Large Graph Layout package
(hence its name), we have just implemented this in igraph straight away.

> It would be great if someone would put simple examples of all of the
> igraph supported file formats on one of the websites. None of the
> resources I found (e.g. python tutorial, read() method documentation)
> had a complete list of examples, only descriptions.
Thanks for the suggestion; I will add such examples to the documentation
where it makes sense.

Cheers,
Tamas



reply via email to

[Prev in Thread] Current Thread [Next in Thread]