I'm trying to put together a "social network" of sorts in NetLogo. A group of people of different age groups who are connected by links.
I'm having trouble with how to put it together because I'm still not fully familiar with some parts of NetLogo's syntax. I only started using breeds in my code in the last week and I haven't fully worked them out yet. Or I'm over complicating them, I'm not sure.
The relevant code is below with the function in question being the "create-network" one. I need to ask each agent (there will be about 800 in total) to connect to a certain amount of each type of other agent (so long as that other agent isn't full up). If the turtle is of the breed toddler for example it will have 10 links in total, 5 of which are to other toddlers, 2 to children, 2 to adults and 1 to over45s. If the first node is a toddler and it connects to an adult, I will need to decrement the number of toddlers that the adult node will try to connect to when I get to it too, if that makes sense.
I can't work out how to ask the current turtle what breed it is, so that I can link to the right amount of the right breeds. If anyone could help me out I'd be insanely grateful. This is only a small section of the code but its been driving me crazy for days now
Every time I try something it results in errors and I'm all out of ideas and the will to live. Thanks so much in advance for your time. Even if you have any thoughts on a better algorithm but not code it would be very welcome too
breed [toddlers toddler]
breed [children child]
breed [adults adult]
breed [over45s over45]
globals
[
num-nodes
]
toddlers-own
[
tod-total-connections
tod-tods
tod-children
tod-adults
tod-over45s
]
children-own
[
child-total-connections
child-tods
child-children
child-adults
child-over45s
]
adults-own
[
adult-total-connections
adult-tods
adult-children
adult-adults
adult-over45s
]
over45s-own
[
over45-total-connections
over45-tods
over45-children
over45-adults
over45-over45s
]
to generate
clear-all
create-toddlers num-toddlers
create-children num-children
create-adults num-adults
create-over45s num-over45
create-network
setup
reset-ticks
end
to setup
ask turtles
[reset-node]
ask links
[set color gray + 1.5]
ask adults
[set shape "circle"
set size 4]
ask toddlers
[set shape "face happy"
set size 4]
ask over45s
[set shape "triangle"
set size 4]
;;INITIALISE BREEDS
;;Initialise Toddlers
ask toddlers [set total-connections 10]
ask toddlers [set tod-tods 5]
ask toddlers [set tod-children 2]
ask toddlers [set tod-adults 2]
ask toddlers [set tod-over45s 1]
;;Initialise Children
ask children [set total-connections 17]
ask children [set child-tods 3]
ask children [set child-children 8]
ask children [set child-adults 5]
ask children [set child-over45s 1]
;;Initialise Adults
ask adults [set total-connections 13]
ask adults [set adult-tods 1]
ask adults [set adult-children 3]
ask adults [set adult-adults 6]
ask adults [set adult-over45s 3]
;;Initialise Over45s
ask over45s [set total-connections 12]
ask over45s [set over45-tods 1]
ask over45s [set over45-children 1]
ask over45s [set over45-adults 5]
ask over45s [set over45-over45s 5]
;; Layout turtles:
layout-circle (sort turtles) max-pxcor - 8
ask turtles
[
facexy 0 0
if who mod 2 = 0 [fd 4]
]
display
end
;; THIS IS THE PROBLEM FUNCTION
to create-network
let q 0
let n 0
while [q < count turtles]
[
let m 1
while [m < count turtles]
[
make-link-between turtle n
turtle ((n + m) mod count turtles)
set m m + 1
;;results in a fully connected network which I don't want
]
set n n + 1
set q q + 1
]
end
;; connects the two nodes
to make-link-between [node1 node2]
ask node1 [
create-link-with node2
[ set color gray + 1.5]
]
end
I'm also wondering whether it would be possible have a function to "pause" the links between agents. For example to turn off a number of or all of the links between children. I know that links have a tie-mode attribute but I'm not sure that this is able to do this. From what I read it seems to be more about holding moving agents together? Could I use untie as a way to turn off the link but to have a it still present?
Edit: Hide link may be more appropriate. How to hide the right links is the next thing