igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] : Simplify() use


From: Gábor Csárdi
Subject: Re: [igraph] : Simplify() use
Date: Sun, 16 Nov 2014 10:32:44 -0500

On Sun, Nov 16, 2014 at 12:35 AM, patricia <address@hidden> wrote:
> Got it, but this solution in my view has two problems, the first is how to
> ensure that the graph generated by igraph_erdos_renyi_game function has the
> average degree that I need;

You explicitly set the number of edges, which is equivalent to setting
the average degree. E.g. a graph with 10 vertices and 20 edges will
have average degree 4. In R:

library(igraph)
g <- erdos.renyi.game(10, 20, type = "gnm")
mean(degree(g))
#> [1] 4

> second I do not understand how to add (attach)
> the weights in this graph generated by the function erdos_renyi.     The
> weights are stored in a square matrix (dimensions: number of examples).

Yes, you query the edges of the graph, go over them and add the
weights. Again, in R this is:

el <- get.edgelist(g)
myv <- numeric(ecount(g))
for (i in seq_len(nrow(el))) {
    myw[i] <- W[el[i,1], el[i,2]]
}
E(g)$weight <- myw

assuming that your weights are in the matrix W.

> Is there any function in igraph library, that before adding an edge to a
> graph checks if it already exists?

igraph_are_connected() if I remember well, but you are better off the other way.

Gabor

> Sorry to bother you and thanks for your help.
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/igraph-help
>



reply via email to

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