invictus
invictus

Reputation: 1971

Random graph generator

I am interested in generating weighted, directed random graphs with node constraints. Is there a graph generator in R or Python that is customizable? The only one I am aware of is igraph's erdos.renyi.game() but I am unsure if one can customize it.

Edit: the customizations I want to make are 1) drawing a weighted graph and 2) constraining some nodes from drawing edges.

Upvotes: 1

Views: 3040

Answers (1)

seralouk
seralouk

Reputation: 33147

In igraph python, you can use link the Erdos_Renyi class.

For constraining some nodes from drawing edges, this is controlled by the p value.

Erdos_Renyi(n, p, m, directed=False, loops=False) #these are the defaults

Example:

from igraph import *

g = Graph.Erdos_Renyi(10,0.1,directed=True)
plot(g)

By setting the p=0.1 you can see that some nodes do not have edges.

For the weights you can do something like:

g.ecount() # to find the number of edges
g.es["weights"] = range(1, g.ecount())
g.es["label"] = weights
plot(g)

Result: enter image description here

Upvotes: 1

Related Questions