NETLOGO: turtles-own except for breed1 - netlogo

I do have several breeds: breed1, breed2, breed3, breed4, breed5.
Now I would like to define several variables belonging to the turtles for all breeds except breed1.
So do I have to write separately
breed2-own [variable1 variable2 variable3]
breed3-own [variable1 variable2 variable3]
breed4-own [variable1 variable2 variable3]
breed5-own [variable1 variable2 variable3]
or is there a possibility to say something like
turtles-own (except for breed1) [variable1 variable2 variable3]
???

The short answer is: no, there is not.
But the real question is: if you have four different breeds with the same variables, do they really need to be separate breeds? It depends on the details of your model, of course, but instead of separate breeds with the same variables, you could have one breed with a kind variable used to differentiate turtles within that breed.

Related

Counting breeds within an agentset

If I have an agentset called zoo belonging to turtle 1, how do I count all the breed of camels in the zoo? NetLogo has a breed-on command, but not a breed-in. So this won't work, although it will illustrate what I'd like:
ask turtle 1 [let c count camels-in zoo]
Thanks.
Best guess is you want something like:
let c count ([zoo] of turtle 1) with [breed = camels]
But an example of a zoo turtleset would be very helpful in understanding what you are trying to do. Perhaps also what your turtles are representing?

Find the difference between two variables of the agents of two different breeds - Netlogo

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
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 ] ]
]

Removing an agentset from another agentset (the agents from the first set which are also present in the second set)

in my netlogo code I have a network with companies (that is my breed). I want to ask the companies to share information with their neighbors and their neighbors and so on, this works (see code below, the agentsets are b, c and d).
However when I ask for information on the third level neighbors my agentset also includes the first level neighbors (obviously since it takes all neighbors into acount), so I want to remove these first level neighbors from the third level neighbors agentset. In the code this means I want to remove agents present in D which are also present in B
But I cant find the way to do it, other doesnt work since it is not the agent asking which has to be removed. And remove also doesnt seem to do the job. I also tried != not equal to the first level but this reports a true or false and I just want to remove these agents from the third level agentset so I dont double count them.
ask companies [
let i who
let b link-neighbors
ask b [ let c link-neighbors
ask c [ let d link-neighbors
ask companies with [who = i] [
set iburen [who] of b
set iiburen [who] of other c
set iiiburen [who] of d
]
]
]
]
can somebody help me with this?
I think what you want is the member? primitive. If D and B are agentsets, the following should give you the members of D that are not members of B.
let DminusB D with [not member? self B]
Many things to say here:
Charles' answer is technically correct.
If a and b are agentsets, a with [ not member? self b ] will give you agents from a that are not already in b.
But I think there are better ways to accomplish what you are trying to do. I will come back to that, but first, a general piece of advice:
Don't use who!
The who primitive has some (very few) legitimate usages, but it's mostly evil. It tends to lead to brittle, inefficient code. For example, when you do:
let i who
; ...
ask companies with [who = i] [ ... ]
NetLogo has to scan all companies to find the one with that specific who number.
NetLogo can store agent references directly. Use that instead! For example:
let this-company self
; ...
ask this-company [ ... ]
Especially don't use lists of who numbers!
NetLogo is adequate for manipulating lists, but its awesome for manipulating agentsets. If you do something like this:
set iburen [who] of b
set iiburen [who] of other c
set iiiburen [who] of d
You are forfeiting the power of agentsets. I don't know why you want to store the three different levels separately, but supposing it's OK to store all your neighbors together, you could do:
set my-neighbors other (turtle-set b c d)
The use of other will exclude the original company and turtle-set will make sure that each agent in the set is unique (as agentsets can only contain unique agents anyway).
If you really want three separate variables, use Charles' answer, but make sure to store agentsets, not lists of who numbers!
If you don't need separate variables, however, I think the best solution would be to:
Use nw:turtles-in-radius.
NetLogo's Networks extension has a primitive that does exactly what I think you want to do:
ask companies [ set my-neighbors nw:turtles-in-radius 3 ]
That's it.

Average values of a group of turtles

The deal is this:
I have three types of turtles.
Every type of turtles contain three turtles
Each turtle has three variable with its own value
How could i ask netlogo to get the average value of each group of turtles
I think you mean something like
let type1-average-x mean [x] of turtles with [type = "1"]
You'll want to do this for each type and for each variable that you'd like the measure of.

NetLogo - compare single agent against many agents (expected input not list)

I am first time poster, six month reader. I love this site and am grateful for the vast array of topics covered. Now that I am feeling a bit more competent using NetLogo, I've tried some harder stuff and got stuck...
Basically, I have created a membership function which measures agents against one another on a vector containing two variables (opinions on rock and hip-hop):
to-report membership [ agent1 agent2 ]
let w 0.5
let w2 sq w
report exp (- d2 agent1 agent2 / w2)
end
where
;;;;;;;;;;;;;;Shortcut functions;;;;;;;;;;;;;;;;;;;;;;;;;;;
to-report d2 [agent1 agent2 ]
report ( (sq ([rock] of agent1 - [rock] of agent2)) + (sq ([hip-hop] of agent1 - [hip-hop] of agent2)) )
end
to-report sq [ x ]
report x * x
end
This all works fine, and I am able to compare any two agents without problem.
However, my trouble arises when I try to compare a single agent [agent1] with all of the agents within his neighbourhood.
to go
ask turtles [
let neighbours turtle-set turtles in-radius neighbourhood
show membership self neighbours]
end
Whenever I run this model I receive an error that the d2 reporter expected an input not a list - which I theoretically understand - by having a neighbourhood of 1+ agent(s), the calculation is receiving for example [0.1 0.8] [0.2 0.4] [0.5 0.6]..............
I was just wondering, is there any way that the procedure can consider all of the neighbours and arrive at one single membership number? I have searched extensively through posts and a couple of netlogo books I have, but no luck so far. Thank you for taking the time to read this post and for any helpful comments.
Your understanding of what is happening is correct: your membership reporter expects two individual agents and you are passing it an agent and an agentset. To calculate each membership individually, and get back a list of membership values, you can use of:
to go
ask turtles [
let neighbours turtle-set turtles in-radius 10
show [ membership myself self ] of neighbours
]
end
Notice the use of myself and self, which can sometimes be tricky to understand. In this case, self is the neighbour and myself is the outer asking turtle.
So now you have a list of membership numbers, but you wonder:
is there any way that the procedure can consider all of the neighbours and arrive at one single membership number?
There are plenty of ways! But we can't really tell you which one to use: it depends on your model and what you want to do with it.
If you wanted something very straightforward, you could just take the mean of the list:
show mean [ membership myself self ] of neighbours
...but I don't know if it makes sense in your context. In any case, NetLogo has plenty of
mathematical primitives that you should be able to use to arrive at the number you want.