1

I have 122 nodes and I want to create a random graph, with node degree being fixed for each node. Is there any way to do it in R? I tried igraph, where I can fix the same degree for all nodes i.e. each of the 122 node will have a degree of 2. But, I want to create a random graph with fixed degree for each node (i.e. node A will have degree 4; node B will have degree 5)

I tried the following code , now it is working:

outdegrees <- c(2, 1, 2, 1, 2)


g <- sample_degseq(outdegrees, method = "Vl")

Thanks

Priya

Priya
  • 65
  • 7

2 Answers2

0

You can use sample_degseq to create a graph with a specified degree sequence.

As an example, assume you want a degree sequence 1, 1, 2, 2, ..., 61, 61. You can use the following code:

> library(igraph)
> deg.seq <- rep(1:61, 2)
> sample_degseq(deg.seq)
IGRAPH 45e3c32 U--- 122 1891 -- Degree sequence random graph
+ attr: name (g/c), method (g/c)
+ edges from 45e3c32:
 [1]  80--121   9-- 82  54--114  57-- 96  52-- 60  16-- 55  38--105  29-- 80
 [9]  69--115   6-- 28  92--111  29-- 49  47-- 67  90--106  49--121  43--114
[17]  40-- 46  47--115 120--122  55--100  98--104  43--109  28-- 98  25--115
[25]  38-- 43  48-- 52  27-- 92  26--107  53--107  60--110  97--110  91--106
[33]  18-- 98 117--119  28-- 51  58--104  61--110  43--105  39-- 51  31-- 95
[41]  84-- 87  94--112  32-- 58  41-- 98  19--113  40-- 47  41-- 50 116--121
[49]  51-- 95  58--118  97--111 100--119  40-- 92  18--114  22--101  46-- 77
[57]  12-- 88  54--109  49-- 58  42-- 61  47-- 53  45--116  31--122  52--102
+ ... omitted several edges
d125q
  • 1,666
  • 12
  • 18
  • I want to specify the degree for each node, like node A will have degree 4, with node A having random connection with any 4 nodes. Similarly , node B will have degree 2 and have random connection with any 2 nodes. Sorry, I forgot to mention that I already have made undirected graph for 122 nodes, for which I want to create random graph. Thanks – Priya Jul 04 '18 at 11:47
0

Here is one approach:

  1. Make a list, L.
  2. For each i put c_i i's in the list.
  3. Shuffle the list.
  4. Connect L[1] with L[2], L[3] with L[4] etc.
  5. If you end up with self-loops (and don't want that) go to 3.
Thomas Ahle
  • 30,774
  • 21
  • 92
  • 114