Hi,
1. Working with the Python interface, I would like to generate a
directed weighted graph (without multiple edges and self-loops)
from an adjacency matrix, where the elements of the matrix store
the weight if an edge exists and are otherwise zero. The matrix is
a numpy array or list of lists. How can this be achieved in a most
direct way?
I already submitted a patch to the igraph 0.6 dev tree that
accomplishes this goal (the new graph constructor will be called
Graph.Weighted_Adjacency). If you are willing to hack around with
the igraph source and then recompile igraph, I can send you a patch.
Otherwise, try this simple solution:
edges, weights, vcount = [], [], 0
for v1, line in enumerate(file("adjacency-matrix.dat")):
vcount += 1
parts = map(float, line.strip().split())
for v2, weight in parts:
if v2 > 0:
edges.append((v1,v2))
weights.append(weight)
g = Graph(vcount, edges, directed=True)
g.es["weight"] = weights
I hope this helps. I haven't tried it, but the basic idea should be
correct.
The weights are all positive in my application. Is this implemented
yet in iGraph?
Weighted shortest path lengths will be implemented in igraph 0.6.
Weighted closeness centrality is not implemented directly in the dev
tree yet, but I think it's not too difficult to calculate using the
matrix returned by the weighted shortest path calculations. Weighted
betweenness centrality seems more complicated - I'm not familiar
with the implementation details of igraph_betweenness, maybe Gabor
can comment on it.
If not, do you have suggestions for other fast libraries
implementing these features?
I think the Boost Graph Library implements weighted betweenness
centrality:
http://www.boost.org/doc/libs/1_35_0/libs/graph/doc/betweenness_centrality.html
--
Tamas
_______________________________________________
igraph-help mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/igraph-help