[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: [igraph] simple question

**From**: |
Tamas Nepusz |

**Subject**: |
Re: [igraph] simple question |

**Date**: |
Mon, 15 Apr 2013 10:09:40 +0200 |

**User-agent**: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 |

Hi,
>* Let's say the vertexes are from 1 to N,*
igraph vertex and edge indices are zero-based (which is the standard
convention in C anyway so I guess this did not strike you as a surprise ;)).
>* the edges, but I don't understand what is the format that igraph accepts.*
>* For instance, one way would be to put all the edges in a huge array of pairs*
>* (X, Y) where there is an edge from X to Y. The array would contain: 0, 1, 0,*
>* 2, 1, 3, 1, 4 etc where (0, 1), (0, 2), (1, 3), (1, 4) etc are all edges.*
This is the format that igraph requires. Use an igraph_vector_t to store the
edge list and then call igraph_create to construct your graph:
http://igraph.sourceforge.net/doc/html/ch09s01.html#igraph_create
An alternative way you could use is an adjacency list where you will
basically have 80 million vectors, and the ith vector stores the neighbors
of vertex i. The constructor to use is igraph_adjlist:
http://igraph.sourceforge.net/doc/html/ch09s01.html#igraph_adjlist
igraph_adjlist requires you to use our igraph_adjlist_t data structure,
though. You have to construct an empty adjacency list first with
igraph_adjlist_init_empty -- this also created all the 80 million vectors
for you. You can then get the i-th vector using igraph_adjlist_get and add
new neighbors to it using igraph_vector_push_back. Once you set up the
adjacency list, you can call igraph_adjlist to turn that into an igraph_t
(which is an indexed edge list by the way, but this is an implementation
detail that you shouldn't care about). Finally, you can throw the
igraph_adjlist_t away by calling igraph_adjlist_destroy. Relevant links from
the documentation:
http://igraph.sourceforge.net/doc/html/igraph-Adjlists.html
http://igraph.sourceforge.net/doc/html/igraph-Vectors.html
--
T.