igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] New user of igraph in C. Basic question about data importa


From: Gábor Csárdi
Subject: Re: [igraph] New user of igraph in C. Basic question about data importation
Date: Sun, 26 Apr 2009 09:44:09 +0200

Paul,

On Sat, Apr 25, 2009 at 10:04 PM, Paul Johnson <address@hidden> wrote:
[...]
>
> Here is my question.  We have agents that are Objective-C objects, and
> each one of them has information about the other agents it has
> encountered.  So it would be possible for me to write out a vector of
> the sort that is displayed in your examples.  This would be a very
> long vector, however.

yes, this is not a good idea, because in that example the vector is
created in the stack, and the stack is rather limited. The vector
should be dynamically allocated instead, to use the heap. If you
choose to create just a long vector with all the edges.

> With 2000 agents or so, most of whom have between 10 and 20 contacts
> with others,  I'm a little worried about the scale of the problem.
> Should I really try to build a vector with 20,000 elements?  Or could
> you show me how to add the vectors one-agent-at-a-time?

You can always add edges/vertices to a graph, see
igraph_add_vertices() and igraph_add_edges(). But remember, that this
operation is O(|V|+|E|),  -- |V| and |E| with respect to the new,
bigger graph -- so it is slow if you add edges one by one. The igraph
data structure is not very good at dynamically changing graphs.

So if you know all the connections, then it is better to create the
graph in one go. To avoid creating a big vector, you can create a
graph with the correct number of vertices, but no edges, transform it
to an igraph_adjlist_t (not surprisingly, an adjacency list), and then
edit the vectors in the adjacency list, and finally create a final
graph from the adjlist. This takes just as much memory as a the long
vector, in fact, even more, but perhaps the code would be more
readable.

> Before I get too far into this, can you please offer me some advice
> about how I should prepare the data that the agents have for
> importation into igraph?
>
>
> I'm also curious why you declare real-valued (double) vectors that
> hold only integer information, but I guess that's a different problem.
>  From one of your examples, I find
>      igraph_real_t  edges[] = { 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 
> 8,
>                               0,10, 0,11, 0,12, 0,13, 0,17, 0,19, 0,21, 0,31,
>                              28,31,28,33,29,32,29,33,30,32,30,33,31,32,31,33,
>                              32,33
>     };
>
> why don't you use igraph_int_t for those declarations?

Because of some old systems that have two-byte ints. But it was
actually a bad decision, igraph would have 50% of the memory footprint
and also would be somewhat faster if we used integers.

It is, however, quite painful to switch now, and most users don't
care, they just want new features, and they would be offended if we
introduced many new bugs because of the double->long int change. But
it will happen, some time, anyway.

Best,
Gabor

[...]
> --
> Paul E. Johnson
> Professor, Political Science
> 1541 Lilac Lane, Room 504
> University of Kansas
>
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help
>



-- 
Gabor Csardi <address@hidden>     UNIL DGM




reply via email to

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