igraph-help
[Top][All Lists]

 From: Giuseppe G Subject: [igraph] Question about igraph_linegraph Date: Thu, 16 Feb 2012 16:24:20 +0000 User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.26) Gecko/20120131 Thunderbird/3.1.18

```Hi,

```
I've just started using the C API for a number of purposes and I have a question about the igraph_linegraph function.
```
I need to compute the line graph of a network similar to the following

---
a b
a c
a d
b d
---

```
It is my understanding that igraph does not deal with string entries so I convert the network into numbers
```
--
1 2
1 3
1 4
2 4
--
and store the id->number map elsewhere.

```
Now, I need to compute the line graph of this graph, which is stored in a textfile. I wrote the following code
```
int main(int argc, char **argv) {
if ( argc != 2 ){
fprintf(stderr, "usage: %s filename.in\n", argv[0] );
exit(1);
}
FILE *instream;
igraph_t graph;
igraph_t linegraph;
int result;

instream = fopen(argv[1], "r");
if(instream == 0){
fprintf(stderr, "Can't open input file.\n" );
exit(1);
}
```
result = igraph_read_graph_edgelist(&graph, instream, 0, IGRAPH_UNDIRECTED);
```        if (result != 0) {
fprintf(stderr, "Problems reading the inputstream. Code %d\n",
result);
exit(1);
}
result = igraph_linegraph(&graph, &linegraph);
if (result != 0) {
fprintf(stderr, "Problems obtaining the linegraph. Code %d\n",
result);
exit(1);
}
result = igraph_write_graph_edgelist(&linegraph, stdout);
if (result != 0) {
```
fprintf(stderr, "Problems writing in the outputstream. Code %d\n", result);
```                exit(1);
}
igraph_destroy(&graph);
igraph_destroy(&linegraph);
return 0;
}

this code will print the linegraph on the stdout as follows:

---
0 1
0 2
0 3
1 2
2 3
---

Now I was expecting something like

12 24
12 14
12 13
14 24
13 14

```
instead I'm getting a redefined set of vertices and the mapping between the line graph vertices (0,1,2) and the graph edges is not provided.
```
```
I need to cluster the line graph and then find out which line graph vertices cluster together (ie which of the original ab, bc etc edges cluster together) I was wondering if there's a way to get a different representation of the line graph or another way to achieve this. Thank you!
```
Best
Giuseppe

--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

```