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:
patches with [segnalato? = true]
with patches with [segnalato?]
- you don't need the =true bit (and you can say not
instead of =false too)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 itif-else
statement so NetLogo only has one truth test to assess rather than threeLooking 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.