make turtles move only on specific patches - netlogo

I"m fairly new at netlogo so it might seem like a dumb question but here it is :
I have a world with patch with specific attributes that represents parks, buildings, streets (2 types small and large), etc. I want my turtles to move towards a specific point (I managed to do that) using only the patches representing streets but with a tendency to move towards parks and green spaces.
I was wondering if you could help me to make them use only the patches representing the streets.
here is the way I set up my world and created my turtles :
extensions
[
gis
]
globals
[
Batiments
ChemindeFer
Cimetiere
Densite
Eau
Ponts
Routes
TerrainSports
Vegetations
]
patches-own
[
Cheminferroviaire
Bati
pont
TerraindeSport
Vege
cimetary
water
road
densitepop
Npatchvert
]
breed [ Renards renard]
breed [ Proies proie]
Renards-own
[
stress
poids
]
Proies-own
[
weight
]
to setup
ca
initialiserGIS
creerRenard
creerProie
move
reset-ticks
end
to initialiserGIS
; ---------------------- chargement densité ----------------------------
set Densite gis:load-dataset "desite_ind_g.asc"
gis:apply-raster Densite densitepop
let min-Densite gis:minimum-of Densite
let max-Densite gis:maximum-of Densite
ask patches
[
ifelse densitepop >= 1.5
[ set pcolor scale-color grey densitepop 1.5 6]
[ set pcolor white ]
]
;------------------- chargement des chemin de fer ----------------
set ChemindeFer gis:load-dataset "chdefer_g.asc"
gis:apply-raster ChemindeFer Cheminferroviaire
ask patches with [Cheminferroviaire = 1]
[set pcolor grey]
;--------------------- chargement batiments --------------------
set Batiments gis:load-dataset "batiment_g.asc"
gis:apply-raster Batiments Bati
ask patches with [Bati = 1]
[set pcolor brown]
;--------------------- chargement des ponts --------------------
set Ponts gis:load-dataset "ponts_g.asc"
gis:apply-raster Ponts pont
ask patches with [ pont = 1]
[set pcolor 87]
;--------------------- chargement de l'eau ----------------------
set Eau gis:load-dataset "eau_g.asc"
gis:apply-raster Eau water
ask patches with [ water = 1]
[set pcolor blue]
;--------------------- sports field -----------------
set TerrainSports gis:load-dataset "terrain_sport_g.asc"
gis:apply-raster TerrainSports TerraindeSport
ask patches with [ TerraindeSport = 1]
[set pcolor green]
;--------------------- végétation --------------------
set Vegetations gis:load-dataset "vegetation_g.asc"
gis:apply-raster Vegetations Vege
ask patches with [ vege = 1 ]
[set pcolor green]
;--------------------- cimetary --------------------
set Cimetiere gis:load-dataset "cimetiere_g.asc"
gis:apply-raster Cimetiere cimetary
ask patches with [ cimetary = 1 ]
[set pcolor green]
;---------------------- roads ---------------------------
set Routes gis:load-dataset "routes_g.asc"
gis:apply-raster Routes road
ask patches with
[ road = 4] [set pcolor 87]
ask patches with
[ road = 3] [set pcolor 104]
ask patches with
[ road = 0] [set pcolor green]
end
to creerRenard
create-Renards 10
end
to move
; --- 1st mouvement (towards campus) ---
ask renards
[ set heading towardsxy 10 101
fd 1 ]
end
I hope this isn't too much information ... Thank you in advance !

Related

How to restrict Old vs. Young: in netlogo?

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

How to get turtles to move to the target?

I'm stumped with an issue in my model. I have a model that looks to simulate an office environment, where there are two breeds: employees and citizens. The employees stay in the office, denoted by grey coloured patches, and the citizensstay in the outside world denoted by black colour patches.
In the middle of the world patch 0 0 there is an office, where employees go to pick up money. There are 4 service-desks where both employees and citizens are to meet for a transfer of money to occur. Here is the full code:
globals [ office-space ]
breed [ offices office ]
breed [ service-desks service-desk ]
breed [ employees employee ]
breed [ citizens citizen ]
offices-own [ money ]
employees-own [ money-held ]
citizens-own [ money-received ]
to setup
clear-all
create-offices 1
ask offices [
set shape "building institution"
set size 4
set color yellow
set money num-of-money ]
create-employees num-of-employees
ask employees [
set shape "person"
set size 1.5
set color blue
setxy random-xcor random-ycor ]
create-citizens num-of-citizens
ask citizens [
set shape "person"
set size 1.5
set color white
setxy random-xcor random-ycor ]
;; create four service desks
ask patch 0 8 [
sprout 1 [
set breed service-desks
set shape "building institution"
set color pink
set size 3 ]
]
ask patch 0 -8 [
sprout 1 [
set breed service-desks
set shape "building institution"
set color pink
set size 3 ]
]
ask patch -8 0 [
sprout 1 [
set breed service-desks
set shape "building institution"
set color pink
set size 3 ]
]
ask patch 8 0 [
sprout 1 [
set breed service-desks
set shape "building institution"
set color pink
set size 3 ]
]
;; create office space
set office-space patches with [ pxcor <= 8 and pxcor >= -8 and pycor <= 8 and pycor >= -8 ]
ask office-space [ set pcolor grey]
place-on-color-employees ;; sets all employees randomly within the grey square
place-on-color-citizens ;; sets citizens randomly outside of the grey box
reset-ticks
end
to place-on-color-employees
let _patches (patches with [pcolor = grey])
ask employees [
move-to one-of (_patches with [not any? turtles-here])
]
end
to place-on-color-citizens
let _patches (patches with [pcolor = black])
ask citizens [
move-to one-of (_patches with [not any? turtles-here])
]
end
to go
employee-movement
employee-take-money
citizen-movement
tick
end
to employee-movement
ask employees [
ifelse [pcolor] of patch-ahead 1 = black
[ rt random-float 360]
[ forward 1 ]
let target one-of citizens
if money-held > 0 [
set heading (towards target)
]
]
end
to citizen-movement
;; citizens walk only in the black patches, they do not go into the office area
ask citizens [
ifelse [pcolor] of patch-ahead 1 = grey
[ rt random-float 360]
[ forward 1 ]
;; if they have no money, then the citizens will walk to one of the service-desks
let target one-of service-desks
if money-received = 0 [
set heading (towards target )
]
]
end
to employee-take-money ;; asks employees to go to the main office and get money
ask employees [
if any? turtles-here with [ shape = "building institution" and color = yellow] [
set money-held money-held + 1
set color green ]
]
end
The issue I have is that within the employee-movement function, the employees will not move towards their targets. Whereas, the citizens will move to their targets. The code for both breeds is basically the same. The employees tend to congregate around the central patch, rather than moving to the targets.
Edited after receiving the full code:
The problem lies with how you define target as a local variable (let target one-of service-desks) each time you call the code. However, since there is more than one service-desk, nothing is forcing them to choose the same service-desk each time. This means that the employees, who are standing in the middle of the four service-desks, are basically taking a step in a random direction at each tick. The citizens on the other hand stand outside of the square on which the service-desks are located. Because of that, all of the service-desks are roughly in the same direction for them, so their general movement also goes in that direction.
I see two different options for working around this. The first one is to not use let target one-of service-desks but use let target min-one-of service-desks [distance myself]. This moves them to the closest service-desk rather than to a random service desk.
The other option would be to set target as a turtles-own variable, and not letting them choose a new one all the time.
Finally I streamlined your setup a little bit, reducing the amount of code you needed.
globals [
office-space
num-of-money
num-of-employees
num-of-citizens
]
breed [ offices office ]
breed [ service-desks service-desk ]
breed [ employees employee ]
breed [ citizens citizen ]
offices-own [ money ]
employees-own [ money-held ]
citizens-own [ money-received ]
to setup
clear-all
set num-of-money 100
set num-of-employees 5
set num-of-citizens 5
create-offices 1 [
set shape "building institution"
set size 4
set color yellow
set money num-of-money
]
create-employees num-of-employees [
set shape "person"
set size 1.5
set color blue
setxy random-xcor random-ycor
]
create-citizens num-of-citizens [
set shape "person"
set size 1.5
set color white
setxy random-xcor random-ycor
]
;; create four service desks
let service-desk-patches (patch-set patch 0 8 patch 8 0 patch 0 -8 patch -8 0)
ask service-desk-patches [
sprout-service-desks 1 [
set shape "building institution"
set color pink
set size 3
]
]
;; create office space
set office-space patches with [ pxcor <= 8 and pxcor >= -8 and pycor <= 8 and pycor >= -8 ]
ask office-space [ set pcolor grey]
place-on-color-employees ;; sets all employees randomly within the grey square
place-on-color-citizens ;; sets citizens randomly outside of the grey box
reset-ticks
end
to place-on-color-employees
let _patches (patches with [pcolor = grey])
ask employees [
move-to one-of (_patches with [not any? turtles-here])
]
end
to place-on-color-citizens
let _patches (patches with [pcolor = black])
ask citizens [
move-to one-of (_patches with [not any? turtles-here])
]
end
to go
employee-movement
employee-take-money
citizen-movement
tick
end
to employee-movement
ask employees [
ifelse [pcolor] of patch-ahead 1 = black
[ rt random-float 360]
[ forward 1 ]
let target min-one-of citizens [distance myself]
if money-held > 0 [
set heading (towards target)
]
]
end
to citizen-movement
;; citizens walk only in the black patches, they do not go into the office area
ask citizens [
ifelse [pcolor] of patch-ahead 1 = grey
[ rt random-float 360]
[ forward 1 ]
;; if they have no money, then the citizens will walk to one of the service-desks
let target min-one-of service-desks [distance myself]
if money-received = 0 [
set heading (towards target )
]
]
end
to employee-take-money ;; asks employees to go to the main office and get money
ask employees [
if any? offices-here [
set money-held money-held + 1
set color green ]
]
end

Each Turtle need to pick different agents from the same agentset

i got a problem with my breed (amministrazione spurgatori).
I need each one of them to pick a different target from the same agentset (manholes with segnalato? = true) but they all head to the same patch.
I think the problem is the code in "to direzione amministrazione" but i am not sure.
Any suggestions?
Thank you in advance
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;; CARATTERISTICHE ;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
globals
[
grid-x-inc ;;per definire la grandezza degli isolati (quadrati verd)
grid-y-inc
intersections
manholesO ;; tombini sulle strade orizzontali
manholesV ;; tombini sulle strade verticali
roads
valore-Scenario-degrado
]
turtles-own
[
ufficio
segnalati
work
house
goal
speed
applicazione?
]
breed [cittadini cittadino]
breed [amministrazione spurgatore]
patches-own
[
intersection? ;;vero se è intersezione tra due strade ;;vero se è tombino
ostruzione-da-rifiuti ;; da definire bene
segnalato?
]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;; PROCEDURA DI SETUP ;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup
ca
reset-ticks
setup-globals
setup-patches
set-Scenario-Degrado
let goal-candidates patches with [
pcolor = 37 and any? neighbors with [ pcolor = white]
]
create-cittadini n-of-cittadini
[
set size 1
set color black
set shape "car"
set speed 0.07
set house one-of goal-candidates ;;crea la tartaruga casa
set work one-of goal-candidates with [ self != [ house ] of myself] ;;crea una localizzazione diversa per ogni tartaruga
set goal work ;;crea direzione attuale
move-to house
set applicazione? false
]
ask n-of NOALLATESSERADELTIFOSO cittadini [set applicazione? true]
create-amministrazione n-of-spurgatori
[
set size 1
set color red
set shape "person"
set speed speed
set ufficio one-of goal-candidates
set goal ufficio
move-to ufficio
]
end
;;con setup globals si definiscono le dimensioni della griglia in questo caso non è modificabile
to setup-globals
set grid-x-inc world-width / 7
set grid-y-inc world-height / 7
end
;;con ask patches definisco le pacth che rappresentano i quadrati intorno alle strade con set road le strade
to setup-patches
ask patches ;;caratteristiche generali delle patch verdi
[ set intersection? false
set pcolor 37
]
set roads patches with ;;definisco quali sono le strade attraverso le coordinate
[(floor((pxcor + max-pxcor - floor(grid-x-inc - 0))
mod grid-x-inc) = 0) or
(floor((pycor + max-pycor) mod grid-y-inc) = 0)]
ask roads [ set pcolor white ]
;;vado a definire le intersezioni, capire bene
set intersections roads with ;; definisco quali sono le intersezioni attraverso le coordinate
[(floor((pxcor + max-pxcor - floor(grid-x-inc - 0)) mod grid-x-inc) = 0) and
(floor((pycor + max-pycor) mod grid-y-inc) = 0)]
set manholesO roads with ;;definisco quali sono i tombini sulle strade orizzonatli
[(floor((pxcor + max-pxcor - floor(grid-x-inc - 0)) mod grid-x-inc) = 4) and
(floor((pycor + max-pycor) mod grid-y-inc) = 0 )]
set manholesV roads with ;;definisco quali sono i tombini sulle strade verticali
[(floor((pycor + max-pycor - floor(grid-y-inc - 0)) mod grid-y-inc) = 4) and
(floor((pxcor + max-pxcor) mod grid-x-inc) = 0 )]
setup-intersections
setup-manholesO
setup-manholesV
end
to setup-intersections
ask intersections
[
set intersection? true
]
end
to setup-manholesO
if setup-manholes? [
ask manholesO
[ set pcolor 109
set segnalato? false
set ostruzione-da-rifiuti 0
]
]
end
to setup-manholesV
if setup-manholes? [
ask manholesV
[ set pcolor 109
set segnalato? false
set ostruzione-da-rifiuti 0
]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;; PROCUDERA DI AVVIO ;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:
to go
tick
network
go-cittadini
go-amministrazione
ask manholesO [ ;;il tempo di svuotamento aumento di 1 ogni tick
ostruzioneO
]
ask manholesV
[
ostruzioneV
]
attappamento
end
to network
if Metodo-diffusione-applicazione = "Passaparola"
[
ask cittadini with [applicazione? = true]
[if any? cittadini in-radius 1 with [applicazione? = false] and random-float 1.0 < Probabilità-connessione
[create-link-with one-of other cittadini in-radius 1 with [ applicazione? = false ]
]
]
]
end
to segnalazione
ask cittadini with [applicazione? = true]
[
if [pcolor] of patch-ahead 2 = 103 [
ask patch-ahead 2 [set segnalato? true]
]
]
end
to go-cittadini
ask cittadini
[face next-patch ;;per andare verso la direzione quindi definisce il movimento (forse non serve up-car?)
fd speed
variation-speed
direzione-cittadini
segnalazione
ask link-neighbors [ set applicazione? true ]
]
ask cittadini with [applicazione? = true][ ask in-link-neighbors
[ set applicazione? true]
]
end
to go-amministrazione
ask amministrazione
[
face next-patch2
fd 0.05
direzione-amministrazione
]
end
to direzione-cittadini
if goal = house and (member? patch-here [ neighbors4 ] of house) [ set goal work ]
if goal = work and (member? patch-here [ neighbors4 ] of work) [ set goal house ]
end
to direzione-amministrazione
set segnalati patches with [segnalato? = true]
if not any? patches with [segnalato? = true] [set goal ufficio]
if any? patches with [segnalato? = true ] [set goal one-of segnalati]
if count patches with [segnalato? = true] > 1 [
set goal min-one-of (patches with [segnalato? = true]) [distance myself]
]
spurgo
end
to spurgo
ask amministrazione [
if [segnalato?] of patch-here = true [
set ostruzione-da-rifiuti 0
set segnalato? false
]
]
end
to variation-speed
if rain? [
ifelse [pcolor] of patch-ahead 2 = 103
[set speed 0]
[ifelse pcolor = 107
[set speed 0.025]
[set speed 0.05]
]
]
end
to ostruzioneO ;; il tombino cambia colore in base al livello di ostruzione
if setup-manholes? [
ifelse ostruzione-da-rifiuti >= 600
[ifelse ostruzione-da-rifiuti >= 1200
[set pcolor 103]
[set pcolor 107]
]
[set pcolor 109]
]
end
to ostruzioneV ;; il tombino cambia colore in base al livello di ostruzione
if setup-manholes? [
ifelse ostruzione-da-rifiuti >= 600
[ifelse ostruzione-da-rifiuti >= 1200
[set pcolor 103]
[set pcolor 107]
]
[set pcolor 109]
]
end
to attappamento
ask cittadini [ if any? cittadini-on manholesO [set ostruzione-da-rifiuti ostruzione-da-rifiuti + valore-Scenario-degrado] ]
ask cittadini [ if any? cittadini-on manholesV [set ostruzione-da-rifiuti ostruzione-da-rifiuti + valore-Scenario-degrado] ]
end
to set-Scenario-degrado
if Scenario-degrado = "Basso" [
set valore-Scenario-degrado random-float (2 - 0) + 0
]
if Scenario-degrado = "Medio" [
set valore-Scenario-degrado random (4 - 2) + 2
]
if Scenario-degrado = "Alto" [
set valore-Scenario-degrado random-float (6 - 4) + 4
]
end
to-report next-patch
let choices neighbors with [ pcolor = white or pcolor = 109 or pcolor = 107 or pcolor = 103] ;;qui per farli passare sui tombini modificare con i colori che si impostano
let choice min-one-of choices [ distance [goal] of myself ] ;;fai fare la distanza alla tartaruga
report choice
end
to-report next-patch2
let choices neighbors with [ pcolor = white or pcolor = 109 or pcolor = 107 or pcolor = 103 ] ;;qui per farli passare sui tombini modificare con i colori che si impostano
let choice min-one-of choices [ distance [goal] of myself ] ;;fai fare la distanza alla tartaruga
report choice
end
First, please edit your question rather than write an answer with your updates. Here is a cleaner version of your code.
to go-amministrazione
ask amministrazione
[ face next-patch2
fd 0.05
direzione-amministrazione
]
end
to direzione-amministrazione
set segnalati patches with [segnalato?]
if-else any? segnalati
[ set goal one-of segnalati
set goal min-one-of segnalati [distance myself]
]
[ set goal ufficio ]
spurgo
end
What I have done is:
replaced first patches with [segnalato? = true] with patches with [segnalato?] - you don't need the =true bit (and you can say not instead of =false too)
replaced all the other patches with [segnalato? = true] with segnalati (since you actually define this patch-set - once it's defined, you should just use the name so that NetLogo doesn't have to keep recreating the patch-set to count it
recognise that if there's only one segnalato then it's also the closest segnalato
combine the logic flow into a single if-else statement so NetLogo only has one truth test to assess rather than three
Looking at this code, you can obviously delete the line set goal one-of segnalati and have the same effect.
Having said all that, I can't see anything logically wrong with this code. Each amministrazione should be choosing the closest segnalato as its goal.
What I would do is create many more segnalato and then manually inspect several amministrazione that are near a segnalato to see whether it is choosing the correct one. It may be that you happened to create your segnalato in locations that are not near any amministrazione to so the amministrazione end up mostly choosing the same segnalato because it happens to be central.

How can i make my model count ticks faster vs the actions they are doing using NetLogo?

I'm modeling a critical situation that's happening in my city (Viña del Mar, Chile), where the "metro" (subway)can have serious problems if a tsunami occurs because the evacuation exits are not well prepared nor well managed.
This example is a simple model of the real one, but i was having really big problems trying to make the turtles move from the subway (blue patches), using the door (lime patch) and then jumping into the railways (gray patches). When i finally made them do those actions i found 2 problems: (1) the ticks aren't working the way i need them to work. I need it to run like it was a clock, counting seconds. (2) i create 3 actions called "check-vecinos-azul/lime/gray" where they need to check if there's any turtle arround them (neighbors). If there's an empty space arround a turtle it moves to that empty spot, otherwise it stands until it finds an empty one.
I'd be so glad if anyone of you could give me a help/tip with my model.
Thank you guys,
Kind regards,
Felipe.
breed [pasajeros pasajero]
turtles-own [
distancia
speed
speed-limit
speed-min
evacuacion
]
patches-own
[
pvacio
]
to setup
ca
setup-patches
setup-pasajeros
reset-ticks
end
to setup-patches
ask patches with [pycor <= 0]
[set pcolor blue - 1]
ask patches with [pycor > 0]
[set pcolor gray + 2]
ask patch 0 0 [set pcolor lime]
end
to setup-pasajeros
ask n-of num-pasajeros (patches with [pcolor = blue - 1])
[
sprout-pasajeros 1
[set size 1
set color orange
set speed 0.1 + random-float 0.9
set speed-limit 1
set speed-min 0
set evacuacion 0
]
]
end
to go
ask pasajeros [
ifelse evacuar?
[
go-puerta
salir-puerta
move-chancado
]
[
stop
]
]
tick
end
to go-puerta
ask turtles with [pcolor = blue - 1]
[
set evacuacion 1
if evacuacion = 1
[
check-vecinos-azul
face min-one-of patches with [pcolor = lime][distance myself]
fd speed ;;
]
]
end
to salir-puerta
ask turtles with [pcolor = lime]
[
set evacuacion 1
if evacuacion = 1
[
check-vecinos-lime
face min-one-of patches with [pcolor = gray + 2][distance myself]
fd speed
]
]
end
to move-chancado
ask turtles with [pcolor = gray + 2]
[
set evacuacion 1
check-vecinos-gray
]
end
to check-vecinos-azul
ifelse not any? turtles-on one-of neighbors
[
wait 0
move-to min-one-of patches with [pcolor = blue - 1][distance myself]
fd speed
]
[
wait 0.5
]
end
to check-vecinos-lime
ifelse not any? turtles-on one-of neighbors
[
wait 0
face one-of patches with [pcolor = gray + 2]
fd speed
]
[
wait 0.5
]
end
to check-vecinos-gray
ifelse not any? turtles-on one-of neighbors
[
wait 0
face min-one-of patches with [pcolor = gray + 2][distance myself]
fd speed
]
[
wait 0.5
]
end

How can I create territories for several groups of agents in netlogo?

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