0

I have a random graph of 10 nodes (possibly there can be more than 1000 nodes). I have write the following code.

g <- erdos.renyi.game(10,1,type = "gnp",directed = FALSE)
degree(g)
[1] 9 9 9 9 9 9 9 9 9 9

The network diagram is as follows. enter image description here

Now, I want to make a change that every node must have 6 degree. Put simply, Degree of every node must be 6, neither more than 6 nor less than 6.

Phil
  • 7,287
  • 3
  • 36
  • 66
Hamid Alvi
  • 43
  • 4
  • in `igraph` you can generate random graphs with given degree using `sample_degseq` https://igraph.org/r/doc/sample_degseq.html – desval Jun 07 '20 at 17:03

1 Answers1

0
set.seed(1234)
g = sample_degseq(out.deg = rep(6,10), method = "simple.no.multiple")
degree(g)
[1] 6 6 6 6 6 6 6 6 6 6
G5W
  • 36,531
  • 10
  • 47
  • 80
  • Here, What does mean by Set.seed(1234) – Hamid Alvi Jun 07 '20 at 17:33
  • is this graph would be connected? – Hamid Alvi Jun 07 '20 at 17:41
  • I used `set.seed` so that the example would be reproducible. `sample_degseq` generates random numbers and without `set.seed` you would get a different answer than the one that I got.. With 10 nodes and degree 6, yes, the graph must be connected. However, with other combinations of numbers there is no guarantee of connectivity. – G5W Jun 07 '20 at 19:03
  • I have to make a graph with 4000 nodes and every node must have 6 neighbors. Can I do this for above code? – Hamid Alvi Jun 08 '20 at 14:48
  • If you change the 10 in the above code to 4000, it will work. After running the above code, run `table(components(g)$membership)` to see that there is a single component. Technically, it is possible that it could have more than one component, but the probability of that happening is _very small_. – G5W Jun 08 '20 at 15:09