0

I have 2 agent types, boys and girls.

breed [boys boy]
breed [girls girl]

Each turtle has an age from a dataset. Also when an agent is a boy, its boy? is true, and if it is a girl, girl? is true.

turtles-own [ 

    age
     boy?
       girl?

]

They are connected by some random links. Now I want for each boy, I can access its girl neighbors, and the difference between their ages gets calculated. In other words, the age difference of two different breeds. I wrote this, but it does not work.

  ask boys [

    ask link-neighbors with [girls? = true]
    [  
      set Gage age]
       let H abs(item 0 age - item 0 Gage)  
  ]

Edit When I use ask link-neighbors with [girls? = true]the neighbors are considered all together, while I want them to one by one be considered where I can compare their age difference and base on that do some other stuff. Any suggestions? Thanks

user710
  • 161
  • 2
  • 12

1 Answers1

2

This is untested, but I hope it's close enough to get you there if it's not correct.

First, you have some confusion with your breeds and turtles-own sex indicator. It would be much easier to have one or the other. Scrap your turtles-own statement entirely and simply test the breed because then you can't introduce errors where (for example) you have have the flag (girl? or boy?) inconsistent with the breed, or both set to TRUE or whatever. The way you have it set up, it is possible to have a turtle of breed boy but accidentally set its variable boy? to FALSE. There is no need for these variables at all, breed is an automatic variable (like who number or size that is created with the turtle) and you can test on the breed directly.

Getting to your actual error, you are asking the link-neighbors to set their variable Gage rather than setting the value of the original turtle that is doing the asking (that is, the turtle that is the centre of this ego network).

UPDATED from the comments, you want the boy to have a list (called age-diff below) of the difference in age between his own and all the girls he is linked to. The primitive map is used to substract a constant from a list, and asking for the variable values of and agentset constructs the list of those values.

boys-own [age-diff]

ask boys
[ let my-girls link-neighbors with [breed = girls]
  if any? my-girls
  [ set age-diff map [ x -> abs (x - age) [age] of my-girls ] ]
]
JenB
  • 17,620
  • 2
  • 17
  • 45
  • Thanks so much for the response. Can you please elaborate this? – user710 Feb 10 '18 at 18:33
  • "test the breed because then you can't introduce errors where (for example) you have have the flag (girl? or boy?) inconsistent with the breed, or both set to TRUE or whatever" – user710 Feb 10 '18 at 19:18
  • Close to what you mentioned I want each boy to have a variablecalled H that holds the difference (not average) between the age of its girl neighbour with himself. They do not care about boy neighbours. The problem is when I ask boys, to find this difference for all its girl neighbours, I cannot subtract the ages because for doing everything with the variables, Netlogo considers the variables of the `link-neighbors` that were asked later than the boys. – user710 Feb 10 '18 at 19:18
  • I need something like this `ask boys [ ask link-neighbors (one by one) with [breed = girls] let diff [age] of boy i - [age] of link-neighbor j with [breed = boys] ]` – user710 Feb 11 '18 at 00:03
  • Does every boy have exactly one girl neighbour? Or are you wanting a list of all the ages of the girl neighbours? – JenB Feb 11 '18 at 09:19
  • I updated the answer to create the list. Note that if the only thing you are wanting to do with the list is to select the girl with the minimum age difference (for example), then you don't need to create the list explicitly and can use similar code in a `min-one-of` command – JenB Feb 12 '18 at 13:15