I'm working on a model where there is sexual reproduction of offspring, so there are two agent types, males and females. I ask the agents to reproduce once they reach a certain age: 400 ticks and continue to do so every 400th tick.
Females should only produce one child provided there are males. The model works for the first few generations but then the population explodes. With a starting population of one female and one male the numbers proceed as follows: 2, 3, 7, 19, 575. I don't know why it suddenly increases from 19 to 575.
It looks like some of the female offspring reproduce immediately after birth despite having an age = 0 i.e. they're not following this command:
ask females [
if age > 0 and age mod 400 = 0 [
reproduce
]
Here's the full model:
turtles-own [age]
breed[males male]
breed[females female]
females-own [ mates max-mate-count mate-count availa-males mother father]
to setup
clear-all
crt 2 [
ifelse random 2 = 1 [set breed males] [set breed females]
]
ask females [set color grey
setxy random-xcor random-ycor
]
ask males [set color red
setxy random-xcor random-ycor
]
reset-ticks
end
to go
ask turtles [increment-age]
ask females [
if age > 0 and age mod 400 = 0 [
choose-mates
]
]
ask females [
if age > 0 and age mod 400 = 0 [
reproduce
]
]
tick
end
to increment-age
set age (1 + age)
end
to choose-mates
ask females [
set mates males in-radius 100 with [age >= 400]
]
end
to reproduce
ask females with [count mates > 0 ] [
hatch 1 [
set mother myself
set father one-of [mates] of mother
ifelse random 2 = 1 [set breed males
set color red
move-to one-of patches with [pcolor = black]
set age 0
]
[set breed females
set color grey
move-to one-of patches with [pcolor = black]
set mate-count 0
set age 0
]]]
end
Hope you can help!
Don't ask females in the reproduce proc. See below. I've made some other suggestions as well.
turtles-own [age]
breed[males male]
breed[females female]
females-own [ mates max-mate-count mate-count availa-males mother father]
to setup
clear-all
create-males 1 [init-male]
create-females 1 [init-female]
reset-ticks
end
to init
set age 0
move-to one-of patches with [pcolor = black]
ifelse (breed = males) [init-male][init-female]
end
to init-male
set color red
end
to init-female
set color gray
set mate-count 0
end
to-report fertile
report (age > 0 and age mod 400 = 0)
end
to go
ask turtles [increment-age]
let _fertile (females with [fertile])
ask _fertile [choose-mates]
ask _fertile [reproduce]
tick
end
to increment-age
set age (1 + age)
end
to choose-mates
;ask females [ ;DONT DO THIS!
set mates (males in-radius 100 with [age >= 400])
;]
end
to reproduce ;female proc
;ask females with [count mates > 0 ] [ ;DON'T DO THIS!!
if (count mates > 0) [ ;DO THIS INSTEAD
hatch 1 [
set mother myself
set father one-of [mates] of mother
set breed one-of (list males females)
init
]
]
end
Related
I am trying to simulate the following situation. Young and old agents.
The old have few social contacts, slower and at the same time have a greater chance of dying.
Young people have more contacts .
Which group should be vaccinated first ?
I created two groups, assigned an infection algorithm, and assigned a social distance. But at the same time I do not see the relationship, the agents behave identically, where is the error?
I'm a beginner and don't want to complicate the model. please don't answer difficult I'm just learning
my code
;;breed [humans human]
;;humans-own [ old young ]
breed [young p-young]
breed [old p-old]
young-own [
days-after-infected
days-of-sick
]
old-own [
days-after-infected
days-of-sick ]
to setup
clear-all
setup-old
setup-young
setup-patches
reset-ticks
end
to setup-old
create-old population-old
[
setxy random-xcor random-ycor
set color 4
set shape "person"
]
end
to setup-young
create-young population-young
[
setxy random-xcor random-ycor
set shape "person"
set color 96
]
end
to setup-patches
ask patches [set pcolor 61]
end
;:ask old [random 360]
;;ask young [forward 1]
to go
move-old
move-young
transmission-old
transmission-young
incubation
sickness
tick
end
to move-old
ask old [
right random 360
forward 1
]
end
to move-young
ask young [
right random 360
forward 3
]
end
to add-carrier
ask one-of young
[set color orange]
end
to transmission-old
ask young with [color = orange]
[let susceptible-person one-of old in-radius 3 with [color = 4]
if susceptible-person != nobody
[ask susceptible-person
[if random 100 < transmission_rate
[set color orange]
]
]
]
end
to transmission-young
ask young with [color = orange]
[let susceptible-person one-of young in-radius 2 with [color = 96]
if susceptible-person != nobody
[ask susceptible-person
[if random 100 < transmission_rate
[set color orange]
]
]
]
end
to incubation
ask old with [color = orange]
[ ifelse days-after-infected < incubation_period
[set days-after-infected days-after-infected + 1]
[set color red]
]
ask young with [color = orange]
[ ifelse days-after-infected < incubation_period
[set days-after-infected days-after-infected + 1]
[set color red ]
]
end
to sickness
ask old with [ color = red ]
[ifelse days-of-sick < 14
[set days-of-sick days-of-sick + 1]
[ifelse random 100 < mortality
[die]
[ set color blue ]
]
]
ask young with [ color = red ]
[ifelse days-of-sick < 14
[set days-of-sick days-of-sick + 1]
[ifelse random 100 < mortality
[die]
[ set color blue ]
]
]
end
I am trying to infect some agents from others, while I am not interested in the incubation period and trying to link age (less movement and less contact) with morbidity.
But I see that the result is not presentable, there is no dependence on age and morbidity.
The transmission-old is your problem. You copypasted from transmission-young but forgot to replace ask young with ask old
to transmission-old
ask old with [color = orange]
[let susceptible-person one-of old in-radius 3 with [color = 4]
if susceptible-person != nobody
[ask susceptible-person
[if random 100 < transmission_rate
[set color orange]
]
]
]
end
I've been fighting for a week, I changed the concept, I think it's easier. How to describe the last block. If there is one infectious neighbor, he will transmit his infection with faithfulness....
breed [olds humanA]
breed [youngs humanB]
globals
[
humans
]
to setup
clear-all
create-olds humans_number * shareA
[
set color 64
set xcor random-xcor
set ycor random-ycor
set shape "person"
]
create-youngs humans_number * (1 - shareA)
[
set color 45
set xcor random-xcor
set ycor random-ycor
set shape "person"
]
set humans (turtle-set olds youngs)
ask olds
[
create-links-with (up-to-n-of (links_number_old * homophily_old) (other olds))
create-links-with (up-to-n-of (links_number_old * ( 1 - homophily_old)) (other
humans))
]
ask youngs
[
create-links-with (up-to-n-of (links_number_young * homophily_young) (other
youngs))
create-links-with (up-to-n-of (links_number_young * ( 1 - homophily_young))
(other humans))
ask patches
[
]
ask n-of 1 humans
[
set infected 1
set color red
]
reset-ticks
end
*to go
ask humans
[
if any? link-neighbors != red ]
[
set humans ......*
end
I'm very new to Netlogo, and this is my very first post in a forum.
I need to create animal agent groups which move in habitats or territories. The territories can overlap. More precisely I need male agents that move in different territories and several groups of female agents which move in other territories.
This is what I did so far. I created a territory just for one group of females and one group of males. Thats not exactly what I need.
globals [fragments]
breed [preys prey]
breed [femaletigers femaletiger]
breed [kids kid]
breed [maletigers maletiger]
turtles-own
[
energy
age
gender
territory
]
to setup
clear-all
setup-fragments
;setup-habitats
setup-turtles
reset-ticks
end
to setup-fragments
ask patches[set pcolor 67]
repeat 50
[
ask one-of patches
[
set pcolor brown
repeat 30
[
let a random 360
let b random 5
ask patch-at-heading-and-distance a b
[
ask neighbors [ set pcolor brown]
set pcolor brown
]
]
]
]
end
to setup-turtles
set-default-shape femaletigers "default" ; default shape (dreieck)
create-femaletigers 10
[
set color red
set size 1.5
set energy 100
set age random 20
set gender "female"
set territory patches-in-territory patch 10 6 15
move-to one-of territory with [pcolor = 67 ] ; tigers start in territory but not on fragmented areas
]
set-default-shape maletigers "default" ; default shape (dreieck)
create-maletigers 10
[
set color blue
set size 1.5
set energy random 100
set age random 20
set gender "male"
set territory patches-in-territory patch 40 15 10
move-to one-of territory with [pcolor = 67 ] ; tigers start in territory but not on fragmented areas
]
set-default-shape preys "circle"
create-preys 100
[
move-to one-of patches with [pcolor = 67] ;preys don't start in fragmented areas
set color 114
set size 0.75
]
end
to-report patches-in-territory [Center rd]
let ptr []
ask Center [set ptr patches in-radius 20]
report ptr
end
I'm thankful for any help.
Maria
welcome to Stack Overflow. When posting on here, in general you will be better served by restricting your code to just the bare minimum needed to demonstrate your issue (see the MCVE guidelines here); for example you could remove your to-report, prey breeds, etc just to make it very obvious what you're trying to solve.
I'm not following your code exactly as I'm not sure of some of your overall goal- instead I give an alternative example that will hopefully illustrate one way to accomplish what you're after. I'll show an example of territories that can overlap for females in this example and of territories that cannot overlap, for males in this example. Using these variables and setup:
breed [ femaletigers femaletiger ]
breed [ maletigers maletiger ]
turtles-own [ territory ]
patches-own [ maleclaimed? ]
to setup
ca
ask patches [
set maleclaimed? false
]
create-maletigers 3 [
set shape "triangle"
set size 1.5
move-to one-of patches with [ maleclaimed? = false ]
pd
set territory patches in-radius 5 with [ maleclaimed? = false ]
ask territory [
set maleclaimed? true
]
]
create-femaletigers 3 [
set shape "square"
setxy random-xcor random-ycor
pd
set territory patches in-radius 3
hatch 1 + random 3 [
rt random 360
fd 1
]
]
reset-ticks
end
In the setup, the patches-own boolean indicates if a patch has been claimed by a male- set it to false to start so that a male can check, as it sets up its territory, whether a patch is already claimed or not. Tigers then set up their territories similar to how you did, except males will not select territory from another male. Females set up their territory then hatch a few more females that will share the territory of the "mother".
To move within their territory, just restrict turtles such that they can only move to one of their territory patches- here is one way to do that:
to go
ask turtles [
let target one-of territory in-radius 1.5
if target != nobody [
face target
fd 1
]
]
tick
end
If you want to confirm that the turtles stay within a territory, run something like:
to territory-check
ask turtles [
let col color + 2 + random 3
ask territory [
set pcolor col
]
]
end
Thanks again. What is when the tigers reproduce and I want their kids to create a new territoy and the territories should not overlap?
to move-male
ask maletigers [
let target1 one-of territory in-radius 2
if target1 != nobody [
face target1
fd 1]]
end
to reproduce-tiger
if age >= 48 and any? maletigers-on patch-here and pcolor = 67 [
hatch random 1 + random (5 - 1) [
set gender one-of [ "male" "female" ]
set breed kids
fd random-float 2 ]]
end
to search-territory-male
ask maletigers with [ territory = nobody ] [
if maleclaimed? = false [
set territory patches in-radius 18 with [ maleclaimed? = false ]
ask territory [ set maleclaimed? true ]]]
end
I'd like to use Netlogo Web to open my Netlogo (Desktop version) model, but it does not seem to work. I get a 'TO or TO-REPORT expected' error when I try to upload my model. Not sure what I'm doing wrong. I've inserted the code below. It is supposed to model a cellular process, in which cells divide, filaments of cells branch, and cells change shape as they grow older (procedures 'divide', 'branch', 'transform'). Help please?
to setup
clear-all
setup-turtles
reset-ticks
ask turtles [ set size 1 ]
end
to setup-turtles
create-threads 1
ask turtles [
setxy random-xcor random-ycor
set shape "line"
set color 65
]
end
turtles-own [age]
to go
add-age
divide
branch
transform
tick
ask turtles [ set size 1 ]
end
breed [threads thread]
breed [cylinders cylinder]
breed [circles circle]
to add-age
ask turtles [
set age age + 1
ifelse show-age?
[ set label age ]
[ set label "" ]
]
end
to divide
ask turtles [
if breed = threads or breed = cylinders [
ifelse random 100 < 50
[if (not any? other turtles-on patch-ahead 1) and
(not any? other turtles-on patch-right-and-ahead 10 1) and
(not any? other turtles-on patch-left-and-ahead 10 1)
[hatch 1
[let turn-degree (random(20) - 10)
rt turn-degree
fd 1
set age age - 1
]
]
]
[if (not any? other turtles-on patch-right-and-ahead 180 1) and
(not any? other turtles-on patch-right-and-ahead 170 1) and
(not any? other turtles-on patch-right-and-ahead 190 1)
[hatch 1
[let turn-degree (170 + random(20))
rt turn-degree
fd 1
set age age - 1
]
]
]
]]
end
to branch
ask circles [
if random 1000 < 2[
ifelse random 100 < 50
[if not any? other turtles-on patch-right-and-ahead 90 1
[hatch-threads 1
[right 90
fd 1
set age 0
set shape "line"]
]
]
[if not any? other turtles-on patch-left-and-ahead 90 1
[hatch-threads 1
[left 90
fd 1
set age 0
set shape "line"]
]
]
]]
end
to transform
ask threads[
if (age > 50) and (random 100 < 50)[
set breed cylinders
set shape "cylinder1"
]
]
ask cylinders[
if (age > 100) and (random 100 < 50) [
set breed circles
set shape "circle"
]
]
end
NetLogo Web is stricter about order of declaration (and so will be future versions of NetLogo Desktop).
Just move your turtles-own and breed statements to the top of your code and you should be all right.
I am trying to simulate the differentiation pattern of a simple organism. This is how I'd like my breeds and variables to work:
Breeds: vegetatives and heterocysts. Vegetatives can divide, heterocysts can't. Vegetatives can become heterocysts. Ideally, once a heterocyst is formed, the closer a vegetative is to it, the less likely it is for it to become a heterocyst in turn.
Variables:
age: + 1 per tick, - 1 for newly-hatched turtles
bump: A means by which to displace all the turtles located 'ahead' of a newly-hatched turtle, so they don't overlap. I imagined the system a bit like a Newton's Cradle (http://s.hswstatic.com/gif/newtons-cradle-1.jpg)
pro: promoter. Accumulates partially randomly. Once it reaches a certain value ('concentration'), a vegetative would change breed to become a heterocyst. Value decreased by inh.
proL: label for pro, with rounded values.
inh: inhibitor. Ideally this value should form a 'gradient' (highest in turtles near heterocysts, lowest further away).
The obvious problem that I can see is that I get a lot of contiguous heterocysts. Which is sort of what I've been trying to avoid. But I can't see what went wrong...Please help?
to setup
clear-all
setup-turtles
reset-ticks
ask turtles [ set size 1 ]
end
to setup-turtles
create-vegetatives 1
ask turtles [
setxy random-xcor random-ycor
set shape "circle"
set color 65]
end
to go
divide
add-age
move
differentiate
tick
end
turtles-own [age
bump
inh
pro
proL]
breed [vegetatives vegetative]
breed [heterocysts heterocyst]
to add-age
ask turtles [
set age age + 1
ifelse show-age?
[ set label age ]
[ set label "" ]
]
end
to divide
ask vegetatives [
if random 100 < 2 [
hatch 1[
set bump 1
set age age - 1
set inh 0
]
]]
end
;;Trying to get only one turtle per patch, making the others move
to move
ask turtles[
while [bump = 1] [
ifelse not any? turtles-on patch-right-and-ahead 180 1[
rt 180
fd 1
set bump 0
if any? other turtles-here[
ask other turtles-here
[set bump 1]
]
]
[fd 1
set bump 0
if any? other turtles-here[
ask other turtles-here[
set bump 1]
]
]
]]
end
to differentiate
ask turtles[
set pro (pro - inh + (random 2))
set proL round pro
ifelse show-proL?
[ set label proL ]
[ set label "" ]
create-links-with other turtles-on patch-ahead 1
create-links-with other turtles-on patch-right-and-ahead 180 1
if breed = vegetatives [
if any? link-neighbors[
ifelse any? link-neighbors with [breed = heterocysts]
[]
[set inh mean [inh] of link-neighbors]
]
if any? vegetatives with [pro > 50]
[ask vegetatives with [pro > 50]
[set breed heterocysts
set color brown
set shape "circle"
if any? link-neighbors[
ask link-neighbors with [breed != heterocysts]
[set inh 2]]
]]
]]
clear-links
end
I want to ask if I want to ask female to hatch after X number of ticks.
the female and male mated in March or April and give birth in January or February.
at the begining I made the code that they mate and have children in january and february
the code
to-report parents-here?
report any? turtles-here with [gender = "male"]
and
any? turtles-here with [gender = "female"]
end
to go
if ticks mod 12 <= 2 [
ask patches with [parents-here?] [
ask one-of turtles-here with [gender = "female"] [
hatch 1 [
set gender one-of ["male" "female"]
]
]
]
tick
end
but how can I ask them if parents here now so after exact number of ticks this female can hatch (pregnancy time)
the problem that when I make gestaton 0 then + 1 they still count even after hatching.
Thanks in advance for the help and sorry for my bad English
This may not be exactly what you're asking for, but you might be able to achieve the desired result by having a turtles own variable that you use as a gestation countdown:
turtles-own [ gestation ]
to-report parents-here?
report any? turtles-here with [gender = "male"]
and
any? turtles-here with [gender = "female"]
end
to go
if ticks mod 12 <= 2 [
ask patches with [parents-here?] [
ask one-of turtles-here with [gender = "female"] [
set gestation 10
]
]
]
ask turtles with [gestation > 0] [
if [gestation = 1] [
hatch 1 [ set gender one-of ["male" "female"] ]
]
set gestation (gestation - 1)
]
tick
end