Linking turtles?

274 views
Skip to first unread message

Hayli Chiu

unread,
Oct 13, 2021, 12:23:19 AM10/13/21
to netlogo-users
Hi, 

Just wanting to ask a bit regarding linking turtles since I am trying to do a simulation on how communication/social network influence ones perception.
Is there anyway I could continue linking different pairs of turtles together randomly (the same linkage between two turtles can happen more than once), then each turtle is able to remember which other turtle it linked with and record the number of times they linked with each turtle in the world? 
As the number of times linked between two turtles increase, their perceptions should become more and more similar something like that.
Thanks!

Hayli

Pradeesh Kumar K V

unread,
Oct 13, 2021, 9:08:57 AM10/13/21
to Hayli Chiu, netlogo-users
Hello Hayli,

Please note the following excerpt from Netlogo Dictionary webpage:

"A node cannot be linked to itself. Also, you cannot have more than one undirected link of the same breed between the same two nodes, nor can you have more than one directed link of the same breed going in the same direction between two nodes.
If you try to create a link where one (of the same breed) already exists, nothing happens. If you try to create a link from a turtle to itself you get a runtime error."

So you could give a weight / strength to the relationship by providing a weight attribute to links. The following code can be used to update weight with each tick

ask turtles [
   
    let x [who] of one-of other turtles ; assuming that connections are made in a random manner
   
    ifelse link-neighbor? turtle x
     
      [ask link [who] of self x [set weight weight + 1]] ; if there is a link between self and turtle x then update link weight
     
      [create-link-with turtle x] ] ; if there is no link, create a link
 
You should initialize weight to 1 before running the above go procedure.

Further coding on perceptions can be based on weight of the links between two turtles.

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/0637a224-78e4-4ce4-8400-7c6e0a636f6an%40googlegroups.com.

Hayli Chiu

unread,
Oct 15, 2021, 8:05:17 PM10/15/21
to Pradeesh Kumar K V, netlogo-users

Hi,

I am completely new to Netlogo and ABM and would like some help in writing out my first model.

I am seeking to measure social contagion of risk perception using the model. Each turtle will first have a random base-line perception. The perception is influenced by:
(1) if disaster occurs (i.e. occur whenever user presses the button of ‘disaster’)
à risk perception will increase exponentially according to ticks, so as tick + 1, baseline perception + baseline perception*0.5, as tick + 2, baseline perception + baseline perception*0.5^2

(2) Communication with other turtles à they can communicate at random, the more the two turtles communicate, the more similar their risk perception value becomes

The model will stop once all individual turtles’ risk perception equals the average risk perceptions of turtles.

I have started writing some codes but there are so many mistakes and it cannot run… would anyone be able to help? Thank you!

Also, it would be grate if anyone could help guide me on writing the disaster occurrence (1) influence part of the codes.

When I try running it in Netlogo, there are also problems of ‘go’ being turtle-only and I do not understand what went wrong, so it would be great if someone could guide me on that.

Thanks so much!

Cheers,

Hayli

--

Codes:

turtles-own

[ baseline-perception ; original perception value --> later turtles will connect with those that have similar original perception first

  influenced-perception ; perception value after being influenced

  weight-of-link ; number of times communicated with specific turtle

]

 

globals

[ influenced?

  clustering-degree

]

 

to setup

  clear-all

  setup-patches

  reset-ticks

  tick

end

 

to go

  earthquake

  communicate

  check-influence

  degree-of-clustering

  if all? turtles [ influenced? ] [ stop ]

  update-turtles

end

 

to setup-patches

  ask patches

  [ sprout 1 ]

  ask turtles

  [ set baseline-perception ( random-float 3 ) ]

  recolor-turtles

end

 

to earthquake

  if ticks true/false

  [ ask turtles

    [ set influenced-perception (baseline-perception + baseline-perception * 0.5 ^ ticks) ]

  ] ;; I am not sure how to write this

end

 

to communicate

  ask turtles [

    let x [who] of one-of other turtles ; assuming connections made in random manner

    ifelse link-neighbor? turtle x

    [ ask link [who] of self x [set weight-of-link weight-of-link + 1]] ; if a link between self and turtle x is set, then update link weight

    [ create-link-with turtle x] ; if no link, create a link

    ]

  set influenced-perception

  baseline-perception + 0.5 ^ weight-of-link

end

 

to check-influence

  ask turtles

  [ set influenced? influenced-perception = (sum [influenced-perception] of turtles-on neighbors) / count turtles-on neighbors ; stop when individual = average

  ]

end

 

to degree-of-clustering

  let degree-of-similar 0

  ask turtles

  [ ifelse (  influenced?  )

    [ set degree-of-similar  count ( turtles-on neighbors ) with [ influenced? = true ] / count turtles-on neighbors ]

    [ set degree-of-similar  count ( turtles-on neighbors ) with [ influenced? = false ] / count turtles-on neighbors ]

    set clustering-degree clustering-degree + degree-of-similar

  ]

  set clustering-degree clustering-degree / count turtles

end


Pradeesh Kumar K V <prade...@gmail.com> 於 2021年10月13日 週三 下午9:08寫道:

Hayli Chiu

unread,
Oct 15, 2021, 8:22:34 PM10/15/21
to Pradeesh Kumar K V, netlogo-users
An updated version of the code here. Would be grateful if anyone could help! Thank you!

Best, 
Hayli
--

turtles-own
[ baseline-perception ; original perception value --> later turtles will connect with those that have similar original perception first
  influenced-perception ; perception value after being influenced
  weight-of-link ; number of times communicated with specific turtle
]

globals
[ influenced?
  clustering-degree
]

to setup
  clear-all
  setup-patches
  reset-ticks
  tick
end

to go
  communicate
  check-influence
  degree-of-clustering
  if all? turtles [ influenced? ] [ stop ]
end

to setup-patches
  ask patches
  [ sprout 1 ]
  ask turtles
  [ set baseline-perception ( random-float 3 ) ]
  recolor-turtles
end

to earthquake
  ask turtles
  [ set influenced-perception ( influenced-perception + (influenced-perception * 0.5) )
  ]

end

to communicate
  ask turtles [
    let x [who] of one-of other turtles ; assuming connections made in random manner
    ifelse link-neighbor? turtle x
    [ ask link [who] of self x [set weight-of-link weight-of-link + 1]] ; if a link between self and turtle x is set, then update link weight
    [ create-link-with turtle x] ; if no link, create a link
    ]
  set influenced-perception
  baseline-perception + 0.5 ^ weight-of-link
recolor-turtles

end

to check-influence
  ask turtles
  [ set influenced? influenced-perception = (sum [influenced-perception] of turtles-on neighbors) / count turtles-on neighbors ; stop when individual = average
  ]
end

to recolor-turtles
  ask turtles
  [ ifelse ( influenced? = TRUE )
    [ set color blue ]
    [ set color red ]
  ]
end

to degree-of-clustering
  set clustering-degree count ( turtles ) with [influenced? = TRUE] / count turtles
end

Hayli Chiu <hayha...@gmail.com> 於 2021年10月16日 週六 上午8:05寫道:
Reply all
Reply to author
Forward
0 new messages