Having turtle-specific variables from two different breeds of the same name - netlogo

I have a quick question.
Say I wanted to have two breeds, defined by
breed [humans human]
breed [mosquitoes mosquito]
and wanted to have turtle specific variables of the same name for those breeds. So
humans-own
[
infected
]
mosquitoes-own
[
infected
]
and I wanted to call the procedure later (pretend that a setup has been made, with infected to be set at the initial boolean value false), like
to infect
set infected true
end
. I understand that it would call set both mosquito and human-specific 'infected' variables to be true, but what if I wanted to do this:
to specific-infect
if turtles = humans
[
set infected true
]
if turtles = mosquitoes
[
set infected true
]
end
. Would it check if the turtle was human, and if it was, then set human-specific 'infected' to true, or do both? Essentially, what I am asking is that can you have turtle-specific variables of the same name and have it be viable for code?

Breeds can certainly have "own" variables with the same name, but as with turtles in general, essentially only a breed can change the value of one of its variables, and you need to ask it to so. So, if you wanted to set infected to true for all humans and to false for all mosquitoes, you would do it as follows:
ask humans [set infected true]
ask mosquitoes [set infected false]
Or, for just certain humans
ask humans with [some characteristic] [set infected true]
Similarly you would have the agents in the breeds each report the values of their variables.
show [infected] of human with [some characteristic]
Check out the NetLogo primitives ask, of, and with for some examples.

at the individual turtle level, the turtle 'knows' the own breed. so you can add
if breed = humans [do human infection thing]
if breed = musquitos [do musquito infection thing]

Related

How can I address the attributes of other turtles in the "procedure-calling" turtle's radius and how long they stay there? In Netlogo

I am building a model in Netlogo where I am simulating the spread of a virus. I have looked at other virus models but so far haven't found a solution to my problem.
I would like each agent interaction to have a specific transmission-probability, based on the susceptible agent's susceptibility (agent attribute), the infected agent's (can be more than one) probability of transmitting the virus (agent attribute), as well as the time spent in proximity. Basically P(getting infected)= infectivity * time in proximity * susceptibility. So for each tick that a susceptible turtle is close to a infected one the probability of getting infected should increase. So far I have only managed to use susceptibility when creating the procedure with susceptible agents as callers.
Here is my code for this procedure so far:
to transmit; procedure for transmitting the disease to nearby people, inspired by epiDEM
let caller self ; adress the susceptible turtle by the name caller
if susceptible? = TRUE
[
let nearby-infected turtles in-radius 2 with [infected? = TRUE]
if nearby-infected != nobody
[
let transmission-risk age-susceptibility ;here I want to include protective-measures (attribute of the possibly several infected turtles) and time-exposed
if random-float 1 < transmission-risk[
set infected? TRUE set susceptible? FALSE]
]
]
end
I am really having a hard time on how to go about this, I am not sure how to address the attributes of the turtles within the radius and how I could measure the time of exposure. I was thinking of creating links that have exposure time as an attribute that will die when the infected is no longer in the radius. But I am not sure how to ask the links to die when the turtles are further away from each other than a 2 patch radius. Also I would prefer to not use links to keep the model runnning faster so if there is another solution I would be very happy to hear it :)
For the option with the links I wanted to try something like this:
to transmit; procedure for transmitting the disease to nearby people
ifelse link-neighbors (in-radius 2 = FALSE)
[ask link [die]]
[set link-age link-age + 1]
let caller self ; adress the susceptible turtle by the name caller
if susceptible? = TRUE
[
let nearby-infected turtles in-radius 2 with [infected? = TRUE]
if nearby-infected != nobody
[create-links-with nearby-infected
let transmission-risk age-susceptibility ;include protective-measures and time-exposed using links to address the turtles
if random-float 1 < transmission-risk[
set infected? TRUE set susceptible? FALSE]
]
]
However I for starters just don't understand how to address the links of the turtles further away to ask them to die, I have changed it after the error messages I've gotten but just can't seem to get it to work.
Is it even possible to do what I want in Netlogo?
Very thankful for any hints!

How to check if 2 different breeds of turtles are on the same patch

The final part of my design involves me recording down anytime a car breed drives into or in netlogo terms, is on the same patch or X and Y coordinate as the people breed as they navigate across the edge of the screen. Had this been java I could've done something like
if Car.xPostion == Person.xPostion
(Do something...)
But unfortunately I do not know how to do the same in NetLogo, all I've been able to do so far is just ask the two breeds by giving every turtle a boolean variable called movable and setting them to true and the rest to false, is there anyway I can check the two coordinates of two different turtles on Netlogo? This is all I 've been able to do so far.
to record-accidents
ask turtles with [movable? = true]
[
]
If you tried something like your java approach, it would fail because turtle positions are continuous and floating numbers are nearly always not equal.
If I have understood your question correctly, you have given a boolean variable called movable? set to true for cars and false for all other breeds. You don't need to do this, turtles know their own breed so you can do ask cars.
To answer your specific question, there are several ways to approach it depending on the perspective (sort of, which agent is in charge).
You could identify patches where there are accidents:, which is the answer to your question in the title (about identifying patches with two breeds).
let accident-locations patches with [any? people-here and any? cars-here]
if any? accident-locations
[ ask accident-locations
[ <do something>
But you can also take a turtle perspective. You could start from pedestrians who have been hit. This takes advantage of the fact that turtles can automatically access the patch variables (like turtles-here) for the patch where they are located:
let hit people with [any? cars-here]
if any? hit
[ ask hit...
or from cars:
let hitters cars with [any? people-here]
if any? hitters
[ ask hitters...

Netlogo: randomly transform breed

I'm working on a rebellion simulation and I'm trying to use Netlogo but I'm new to it so I'm running into some issues. I'm working off a modified wolf sheep model and I have three turtle types: police, rebels, and civilians. I have the general set up working but I'm trying to incorporate a civilian collateral damage element.
I want to model the police imperfectly differentiating rebels and civilians. When police mistakenly arrest a civilian, that causes n other number of random civilians to then become rebels. Where I get lost is interacting the police's actions with the civilian breed type. Below is my police procedure for civilian arrests:
to collateral-damage ;police procedure
let prey one-of civilians-here
if prey != nobody and random 100 < prob-collateral
[ ask prey [ die ] ]
Any help is super appreciated!
Breed can be set like any other turtle owned variable, with a set statement. There's not quite enough detail to give you a definitive answer, but I think you want something like:
let prey one-of civilians-here
if prey != nobody and random 100 < prob-collateral
[ ask prey [set breed rebels]
ask n-of min (list 5 count civilians) [set breed rebels]
]

find the nearest node that has one-of data

i have two breeds
breed[nodes]
breed [messages]
nodes-own [data]
messages-own [basedata]
i have a network with n nodes. each node has a specific data. im selecting a random turtle as sink.in my network data distributed from a turtle(first all turtles are nodes) to sink.each node that is in the way becomes a message.and each message has a memory space too keep those data that pass from that message.messages basedata keep the original data.
i want sink find the nearest node that has for example "D1".
to setup
setup1
setup-spatially-clustered-network ;create links
ask links [set color white]
end
to setup1
__clear-all-and-reset-ticks
create-nodes number-of-nodes
[
setxy (random-xcor * 0.95) (random-ycor * 0.95)
set shape "circle"
set color green
set value ["D1" "D2" "D3" "D4" "D5" "D6"]
set data one-of value
set label data
set dontpick false
set visit false
]
end
to test1
ask one-of turtles
[
set color red
set label "sink"
set nodenumberdestination who
]
ask min-one-of turtles with [(data = "D1") or (basedata = "D1")][distance turtle nodenumberdestination]
[
]
error : NODES breed does not own variable BASEDATA
There is a conflict between your stated goals in your question and your code, which suggests you have not finished thinking through what you are doing. (The code you posted is also incomplete; for example, it does not include your globals declaration nor setup-messages.) So first a question: did you really mean to use turtles instead of nodes in test1? If yes, that means you allow a message to become your sink. So I'll assume no, as suggested by your actual question. Introduce a new global sink and
to test1a
ask one-of nodes [ ;move this to setup!
set sink self
set label "sink" set color red
]
ask sink [
let _choice min-one-of (other nodes with [data = "D1"]) [distance myself]
ask _choice [] ;do something
]
end
That answers your question as asked. If you really wanted a choice out of all turtles, as suggested by your posted code, you'll have to ask a new question.
the problem is when you do
ask min-one-of turtle with [(data = "D1") or (basedata = "D1")]
it could refers to either nodes and message, while each other doesn't share the same variable.
For example: when it runs on nodes, it will return error when checking [(basedata="D1")] since it doesn't own basedata. Likewise, when it runs on message it will return error when checking [(data="D1")] as well. However, since you haven't created any messages so it will always returning error : NODES breed does not own variable BASEDATA
So, you need to be specific when referring to agentset because any command blocks including variable used will be sensitive to as whose the variables are belong to.

Netlogo - working with nested breed

I have a breed of turtle that owns another breed of turtle.
I need to do something like:
set my-turtle-set breed1 "owned by" breed2 with [some-attribute = 1]
So i need to put in a turtleset some turtle of the breed1 if they are owned by the turtle of the breed 2 with some characteristic.
Clarifying
Maybe thre was a misunderstanding:
I have already the breed2 owning the breed1:
breed2-own [my-owner]
and i can correctly put my breed1 turtles inside my breed2 turtles.
The problem is that i need to make hidden? some breed1 turtles basing on who onws them.
SO updating to the example (i remove my-turtle-set for being more clear):
ask breed1 ("owned by" breed2 with [some-attribute = 1]) [set hidden? true]
So the turtles already own correctly the other breed just i dont know, given a breed1 tutle, how to call its ower.
for this reason i need something like "owned by".
To Clarify even more
I have the breed2 that are part of a tree (network). At every step i set an attribute leaf? true to the leaf.
now each breed2 owns a breed1 and to every turn I need to set hidden? false toe the breed1 which are not onwed by a leaf, instead to set hidden? true to the breed1 which are owned by a leaf
If breed2 is the breed that owns, then this line:
breed2-own [my-owner]
doesn't make sense; the wording implies the relationship goes in the other direction. I'll assume you mean:
breed2-own [owned]
Then one way to solve your problem is:
ask breed1 [
set hidden? any? breed2 with [owned = myself]
]
If the number of agents in your model is fairly small, this should be fine.
If you have lots of agents, then you may start having speed problems, because in the above code, each breed1 does its own independent search through all breed2 agents.
Two possible ways to fix that:
Do what Mars suggests in his answer.
Get rid of the owned variable altogether, and use links to represent the owning relationships.
How about giving the owner breed a turtles-own variable that stores turtle-set containing the turtles it owns? You can also store a reference to the owner in each breed1, if that will make the code that uses this information simpler.
breed1-own [my-owner]
breed2-own [my-owned]
...
ask breed2 with [some-attribute = 1]
[set my-owned my-turtle-set
ask my-turtle-set [set my-owner myself]
Here myself refers to the breed2 turtle from the outer ask. (If you used self, instead, that would refer to the breed1 turtle from the inner ask.)
(Don't use both kinds of references unless you need both, though, because having breed1s and breed2s refer to each other means that when your code changes references of one kind, it has to change corresponding references of the other kind as well.)