I have turtles with 0 < AD < 1, and with 0 < opinion < 1. Each turtle is linked (undirected) to a given number of others. I want turtles low in AD (< 0.3) to adopt the opinion of another one high in AD (> 0.7) belonging to their neighborhood of links. The code I have figured out adopts all the opinions from all turtles with high AD within their extended network. Any thoughts on how to make this so that it only adopts the opinion of one in the neighborhood, if there is one (there may not be)?
This is related to a previous question (Netlogo, changing link-with to link-to)
to opinion-formation
ask turtles [
let leaders turtles with [AD > 0.7]
if (AD < 0.3) and (link-neighbor? one-of leaders) [set opinion1 [opinion] of turtles with [link-neighbor? one-of leaders ]]
]
end
Another thing I have tried, here the problem is that my turtles never adopt anyone's opinion...
to opinion-formation
ask turtles [
let leaders turtles with [AD > 0.7]
if (count leaders with [member? self link-neighbors] > 0) and AD < 0.3 [
set opinion1 [opinion] of one-of leaders with [member? self link-neighbors]
]
]
end
You may want to use the nw
extension for this, as it allows you to use the nw:turtles-in-radius X
primitive to return turtles within a connected distance. For a very simple example, have a look at this code:
extensions [ nw ]
turtles-own [ AD ]
to setup
ca
crt 10
ask turtles [
set AD random-float 1
set color scale-color blue AD 0 1
setxy random 20 - 10 random 20 - 10
create-link-with one-of other turtles
]
reset-ticks
end
to check-leadership
ask turtles [
let my-nearby-turtles nw:turtles-in-radius 2
let my-nearby-leader one-of my-nearby-turtles with [ AD > 0.7 ]
if my-nearby-leader != nobody [
let new-AD [AD] of my-nearby-leader
show word "I have a leader, my new AD is " new-AD
set AD new-AD
set color scale-color blue AD 0 1
]
]
end