[Top][All Lists]

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

Re: [igraph] How can i add the edges?

From: Gábor Csárdi
Subject: Re: [igraph] How can i add the edges?
Date: Sat, 20 Feb 2010 09:53:27 +0100


On Sat, Feb 20, 2010 at 12:48 AM, Vladimir Petrov <address@hidden> wrote:
> Hello!
> I have a problem with edges
> /*file igraph_add_edges.c from "sample" folder*/
>  igraph_t g;
>  igraph_vector_t v;
>  int ret;
>  /* Create graph */
>  igraph_vector_init(&v, 8);
>  VECTOR(v)[0]=0; VECTOR(v)[1]=1;
>  VECTOR(v)[2]=1; VECTOR(v)[3]=2;
>  VECTOR(v)[4]=2; VECTOR(v)[5]=3;
>  VECTOR(v)[6]=2; VECTOR(v)[7]=2;
>  igraph_create(&g, &v, 0, 1);
>  /* Add edges */
>  igraph_vector_resize(&v, 4);
>  VECTOR(v)[0]=2; VECTOR(v)[1]=1; // <--- What does it mean?
>  VECTOR(v)[2]=3; VECTOR(v)[3]=3;
>  igraph_add_edges(&g, &v, 0);
> /*************************/
> A quote from "igraph_create" function help:
> "const igraph_vector_t *edges
> The edges to add, the first two elements are the first edge, etc."
> What does it mean "first edge"? The edge between what vertexes?

Exactly. An edge is a pair of vertices. Ordered in the directed case,
unordered in the nondirected case.

> What should i write if i want, for example, add an edge between
> second and fifth vertexes? Or create self-loop on 8th vertex?
> What sense does have statement "VECTOR(v)[2]=3"? The edges from vertex
> number "2" to vertex number "3"?

There is a misunderstanding here. igraph_add_edges takes a vector and
the elements of that vector define the edges to add. E.g. if you have
[2,5,8,8] in your vector, then two edges will be added, one from
vertex 2 to vertex 5, and one from vertex 8 to itself. The format is
the same as for the 'edges' argument in the 'igraph_create' function.

Gabor Csardi <address@hidden>     UNIL DGM

reply via email to

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