igraph-help
[Top][All Lists]
Advanced

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

[igraph] Read/Write Weighted Grapphs


From: Lorenzo Isella
Subject: [igraph] Read/Write Weighted Grapphs
Date: Tue, 31 Aug 2010 14:38:48 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.9.1.11pre) Gecko/20100623 Spicebird/0.8

Dear All,
Consider the short snippet at the end of the email.
Its purpose is to produce a simple weighted graph save it as an edgelist and a file giving the weights of each link. However, I must be doing something wrong, since when I read the two files, I finally get a different strength distribution.
How comes? Am I making a mistake?
Any help is really appreciated.
Best Regards

Lorenzo


########################################################################

library(igraph)

set.seed(1234)

g_ini <- erdos.renyi.game(50, 1/10)

E(g_ini)$weight <- seq(ecount(g_ini))
sorted_str <- sort(graph.strength(g_ini))


write.graph(g_ini, "initial_graph.dat", format="edgelist" )


write.table(E(g_ini)$weight, "wlist.dat",col.names=FALSE,row.names=FALSE )

##############################################################
#Now try reading the saved files into a new graph

weights <- read.table("wlist.dat", header=FALSE)
weights <- as.matrix(weights)


g_fin <- read.graph("initial_graph.dat", "edgelist")
g_fin <- as.undirected(g_fin)
g_fin <- simplify(g_fin)


E(g_fin)$weight <- weights


sorted_str_fin <- sort(graph.strength(g_fin))



reply via email to

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