Random Complete Regular graphs in Netlogo?

45 views
Skip to first unread message

Hayli Chiu

unread,
Mar 30, 2022, 8:43:31 PM3/30/22
to netlogo-users
Dear all, 

I have been trying to generate a random complete regular graph(i.e. all nodes have the same degree) yet came across the issue of some turtles being isolated from the rest of the other nodes when desired degree = 2, would be grateful for any advise. 
The codes I used is below:

to R-link-turtles
  ca
  create-turtles 4 [
    layout-circle (sort turtles) max-pxcor - 1 ]
  ask turtles
    [ link-turtle-friends ]
end

to link-turtle-friends
  ;; loop until this turtle has the right number of links, but
  ;;   break out if the number of loops exceeds a limit
  let counter 0 ;; counter to prevent infinite looping
  while [(count my-links) < number-of-friends and 10 * number-of-friends > counter]
  [
    set counter counter + 1
    let other-guy one-of other turtles with [count link-neighbors < number-of-friends]
    ;; this might be an already-linked turtle, which won't create a new link
    if nobody != other-guy [create-link-with other-guy]
  ]
end

Thanks and looking forward to your reply.

Best, 
Hayli

Pradeesh Kumar K V

unread,
Mar 31, 2022, 7:25:50 AM3/31/22
to Hayli Chiu, netlogo-users
Hello Hayli,

The reason for the isolated turtle is due to the fact that your code permits three network configurations with node degree = 2 as shown below:

image.png

One of these is a triangle with one node left out. Even though one node is left out, the other three nodes have degree 2.

What I feel is that you should modify the code to ask the node to search first for another node with degree 0 and make a link with such a node. If there is no node with degree 0, then try for nodes with degree 1. This ensures that all nodes are covered.

I have modified your code slightly to reflect this change and have used '2' instead of 'number-of-friends'. The modified code is given below:

to  R-link-turtles
  ca
  create-turtles 4 [
    layout-circle (sort turtles) max-pxcor - 1 ]
  ask turtles
    [ link-turtle-friends ]
end

to link-turtle-friends
  ;; loop until this turtle has the right number of links, but
  ;;   break out if the number of loops exceeds a limit
  let counter 0 ;; counter to prevent infinite looping
  while [(count my-links) < 2 and 10 * 2 > counter]

  [
    set counter counter + 1
    let other-guy one-of other turtles with [count link-neighbors < 1] ;check if there are nodes with degree 0
    if other-guy = nobody [
    set other-guy one-of other turtles with [count link-neighbors < 2] ;check if there are nodes with degree 1
    ]  

    ;; this might be an already-linked turtle, which won't create a new link
    if nobody != other-guy [create-link-with other-guy]
  ]
end

The above code eliminates the triangle configuration.

Hope this helps.

Best,

Pradeesh

--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/7b9766c5-b8d8-4576-bd2e-a668f2ae50f2n%40googlegroups.com.

Michael Tamillow

unread,
Mar 31, 2022, 10:12:00 AM3/31/22
to Pradeesh Kumar K V, Hayli Chiu, netlogo-users
Or add edges to the turtle with the fewest edges first. It’s identical, only you are not asking a node to search for the node with degree zero, you are just finding that node yourself.

Sent from my iPhone

On Mar 31, 2022, at 6:26 AM, Pradeesh Kumar K V <prade...@gmail.com> wrote:



James Steiner

unread,
Mar 31, 2022, 9:14:35 PM3/31/22
to Hayli Chiu, netlogo-users
Hi!

Traditional programming methods, like using for-loops or while-loops and "doing things yourself" are often harder to code, to read, and give undesirable results.

Here's the idiosyncratic NetLogo "way" to build a network like you need:

let number-of-nodes 4
let number-of-links 2
create-turtles number-of-nodes
[ let link-count count my-links
create-links-with n-of (number-of-links - link-count ) (other (nodes with [ count my-links < number-of-links ]))
]

Hi twice on the way down to come here


--
Reply all
Reply to author
Forward
0 new messages