|
From: | Richard Geddes |
Subject: | Re: [igraph] Question on importing edgelists |
Date: | Tue, 05 Feb 2008 14:47:46 -0500 |
User-agent: | Thunderbird 2.0.0.6 (X11/20071022) |
G I was really more interested in what effect removing a node or subset of nodes (which may or may not produce more components) might have to the overall quality (and quantitative measures) of a graph. I have a graph with contiguous nodes {0 ... n} in an edgelist text file, and import the file using igraph_read_graph_edgelist and produce some measurements with other igraph routines. Subsequently, I identify some nodes which I'd like to remove to see the effect on the measurements, and want to import that 'reduced edgelist' for measurements and comparison. I'd like to be able to import the reduced edgelist, instead of removing the nodes internally in the igraph environment. My question is less about focusing on a particular component... also, I'm using the C library in a C/C++ environment. I think Tamas may have answered my question, but if you have something to add, I'd be interested. Thanks R Gabor Csardi wrote: Richard, i don't know whether you're using R/Python/C, here are two possible solutions: 1) If you can be sure that in reality there is a single component in your graph, and that has at least two vertices, then you can read the graph with the isolates first and then remove the isolates. Here is a way in R, preserving the original vertex ids as an attribute: 1 5 1 2 2 3 2 6 3 7 1 10g <- read.graph("/tmp/b.txt") V(g)$name <- seq(vcount(g))-1 cl <- clusters(g) g2 <- subgraph(g, which(cl$membership==which.max(cl$csize)-1)-1) V(g2)Vertex sequence: [1] 1 2 3 5 6 7 10 This can be done in Python/C as well, without much trouble. 2) In R, read the file as a matrix of strings, and use graph.edgelist(). This function uses symbolic vertex names if the input matrix contains strings:el <- matrix(scan("/tmp/b.txt", character(0)), nc=2, byrow=TRUE) g <- graph.edgelist(el) V(g)Vertex sequence: [1] "1" "5" "2" "3" "6" "7" "10" Note that the vertex ids are not necessarily assigned the same way for the two solutions. 2) works if your graph has multiple components. Gabor On Mon, Feb 04, 2008 at 06:37:15PM -0500, Richard Geddes wrote:I have an edge list text file, in which edges are defined as a white space separated pairs of integers, each integer representing a node... I think this is standard... however, the node numbers in my dataset are not contiguous... ie for a graph consisting of nodes {0 .. n} some nodes k are missing such that (0 < k < n). It looks like when I import this type of dataset, the "missing" node numbers are included as single node components... the output of the igraph_clusters routine seems to report this. Is there a work around or a routine to re-sequence the node numbers in igraph? Thanks Richard _______________________________________________ igraph-help mailing list address@hidden http://lists.nongnu.org/mailman/listinfo/igraph-help |
[Prev in Thread] | Current Thread | [Next in Thread] |