Netlogo: Alternative turtle breed / death - netlogo

Is there a way to have a population of turtles breed / die in sets instead of individually?
For example: Say for each tick I'd like one population of turtles to increase by 5 and another population to decrease by 4.

I think you can do something like this
ifelse your condition come here
[ ask n-of 4 breed_type_1 [ die ]
create-breed_type_2 5
]
[ ask n-of 4 breed_type_2 [ die ]
create-breed_type_1 5
]
I am not sure if my syntax is error-free.

Related

Connect turtles who are within a certain radius

I use the nw extension in NetLogo to create a network.
My aim is the following:
Check if any turtles are close by
If any turtles are close by (I tried with next 3 patches, but that might change), connect to them + there is an upper limit of possible links
I tried (and, I think, succeeded) to implement the approach, described here. Which means that the upper limit works. However, I am not able to only link to the turtles close by. I also need something to catch the error if no turtle is close by. I tried to use the in-radius command but for some reasons, it doesn't do what I want.
extensions [nw]
breed [ AT1s AT1]
turtles-own [ friends ]
to setup
ca
create-AT1s 20 [
setxy random-xcor random-ycor
set friends 3
set color green
get-radius-friends friends AT1s
]
end
to get-radius-friends [ x AgentT]
let lonely AgentT with [count my-links < x]
let candidates other AgentT with [ any? AgentT in-radius 3 AND count my-links < x ]
let new-links x - count my-links
if new-links > 0 AND any? AgentT in-radius 3
[ let chosen n-of min (list new-links count other candidates) other candidates
create-links-with chosen [ hide-link ]
set candidates other candidates
ask chosen [ if my-links = x [ set candidates other candidates ] ]
]
end
I also found the neighbors and the distance commands but these only consider the immediate surroundings which isn't what I need.
Actually, that's not the best question to pull from if you want to spatially restrict the turtles. And there's a serious problem with having the connection within the turtle creation block because there are no potential friends for the turtles created first. Unless you have a very large number of turtles, you probably don't need to worry about efficiency.
I also think the variable 'x' is unnecessary because you have the variable 'friends' available (which appears to be the number of links you want the turtle to have). And there is a new reporter up-to-n-of which makes the whole list and min unnecessary.
I think this does what you want. You may want to test is without the hide-link so you can see what it does.
breed [ AT1s AT1]
turtles-own [ friends ]
to setup
clear-all
create-AT1s 100
[ setxy random-xcor random-ycor
set friends 3
set color green
]
get-radius-friends 10 AT1s
end
to get-radius-friends [ #radius #breed ]
let linkers turtles with [breed = #breed ]
ask linkers
[ let new-links friends - count my-links
if new-links > 0
[ let candidates other linkers with [ count my-links < friends ] in-radius #radius
let chosen up-to-n-of new-links candidates
create-links-with chosen [ hide-link ]
]
]
end

Turtles not reseting under a conditional

I'm trying to have turtles match based on attraction parameters, however I only get either one match or one mismatch and won't count anymore turtles matching, as well as not moving the counter forward.
to new-couple
set countdown2 5
ask turtles [
;; CREATE NEW COUPLE
ifelse countdown2 <= 0
[ die ]
[ set countdown2 countdown2 - 1 ] ]
end
The code that you have provided does not have an error. Try this version of it and you will see that the new-couple code correctly reduces the countdown 5 times and then kills the rest of the turtles. So it's not producing the problem that you describe of things only happening once.
to testme
clear-all
create-turtles 10
type "Start turtles: " print count turtles
new-couple
type "End turtles: " print count turtles
end
to new-couple
let countdown2 5
ask turtles [
;; CREATE NEW COUPLE
ifelse countdown2 <= 0
[ die ]
[ set countdown2 countdown2 - 1 ] ]
end
Could you please provide more of your code. Also, an explanation of what the countdown is supposed to achieve could be useful. At the moment it basically selects the number of turtles that don't die and there are easier ways to achieve that.

Making undirected links from an agent to an agentset

I am trying to create links from agents (in my case, towers) with a certain property to other towers with another set of properties. Only some of them should be linked, yet when I ask the observer, it says they all seem to have that link.
to setup-links
print count towers with [ any? tower-communications ]
ask towers with [ heading = 0 ] [ ; first consider the communications between different areas
create-tower-communications-with other towers with [ heading = 0 ] ; between two towers that are still standing
in-radius tower-communication-radius ; and link towers to each other if they are close enough
with [ heading = 0 ]
[set color green]
end
print count( tower-communications with [ color = green ])
print count( towers with [ any? tower-communications ])
The first print statement gives as expected, the number of links between these pairs. The second should print out the number of towers that have a link between them, but it gives me the full number of towers in the system instead. What is going wrong? I only want the set of agents that have tower-communications with at least one other agent.
I think the problem is the way you are counting the turtles with links, not the way you are creating the links. Here is a full example (note that I took out the second with [heading = 0].
globals [tower-communication-radius]
to setup
clear-all
create-turtles 25
[ setxy random-xcor random-ycor
set heading 0
]
set tower-communication-radius 5
setup-links
end
to setup-links
print count turtles with [ any? links ]
ask turtles with [ heading = 0 ]
[ create-links-with other turtles with [ heading = 0 ]
in-radius tower-communication-radius
[set color green]
]
print count turtles
print count turtles with [ any? links ]
print count turtles with [ any? my-links ]
end
Your count is print count turtles with [ any? links ]. However, the test you are asking is whether there are any links in the model, not whether there are any links attached to the turtle (or tower). You need my-links or link-neighbors to apply to the specific turtle.

How to add to score after a turtle dies

So my go procedure right now is
to Go
ask turtles with [is-moving?]
[
if any? other turtles-here [
ask other turtles-here [
die
]
]
]
end
(is-moving? is just a turtles-own variable to specify the only turtle that i want to move)
I wanted to add 5 points to the score everytime it went through the go procedure and a turtle died. I already set a global variable to score. Thanks!
If score is global variable just add set score Score + 5
to Go
ask turtles with [is-moving?]
[
if any? other turtles-here [
ask other turtles-here [
set score Score + 5
die
]
]
]
end
Update:
I think you dont need to multiply it since all turtles will update the score value ! (my mistake! )To monitor Score :

Ask a specific number of turtles to die in NetLogo

I'm constructing a model of cockle growth for fisheries. One aspect of cockle biology is predation. I want to ask a specified number of turtles in a patch to die each tick. The Dictionary doesn't really provide the answer and I don't know how to model this. Any suggestions?
Thanks a lot!
Supposing you want five turtles on each patch to die, then:
ask patches [
let limit count turtles-here
ask n-of (min 5 limit) turtles-here [
die
]
]
The use of min is necessary because if I just said n-of 5 turtles-here, I would get an error on any patches with fewer than five.
You might also write:
ask patches [
repeat 5 [
if any? turtles-here [
ask one-of turtles-here [
die
]
]
]
]
which amounts to the same thing, but the n-of version should run faster.
If you want to kill 'n' turtles (replace 'n' in the code by an integer)
to kill-n-turtles
repeat 'n' [
ask one-of turtles [die]
]
end