I am new to NetLogo programming and I am trying to build a model in which humans are moved back and forth between some certain patches, named "house"
(yellow) and "workplace"
(gray).
Program accepts house numbers and calendar parameters including vacations from a CSV-file as indicated on the picture and builds the world based on house numbers coming from file, and adds up new houses as the area grows.
Humans are allowed to go "outside"
(black patches) on vacations. All the decisions are made via calendar parameter that is taking value as "none", "newyear", "holiday", "weekend",
and "official"
. Humans asked to go "workplace"
on routine weekdays, however they are asked to go back at the end of the day, in this case, before the next tick. So they are going back and forth quickly before the next tick. However things change on weekend and vacation days such as holidays or official days off which are usually leads spending more time away. The ultimate aim is to calculate the rate of activities such as "eat-and-drink", "clean-up",
and "maintenance"
.
Humans are asked to look for if the vacation continues, so they don’t come back home early. However, my code is kind a buggy since "Outsiders", "Weekenders"
and "Vacationists"
sliders work occasionally. Normally all the humans should stay at home when sliders put on zero, and should go outside when it is one.
My to go
code that is just currently a beginner’s mess, selects the next sub routine based on the value of "data-vacation"
. I know that it must be something much more simple but I can’t figure out how to do that. Besides, there are redundancies about programming logic. But I can’t imagine how to fix them.
to go
if (data-vacation != "none" and data-vacationOLD = "" )
[
set vacationist-humans n-of (Vacationists * number-of-humans) humans
ask patches with [pcolor = yellow]
[
set insiders humans-here
set number-of-insiders count insiders
]
ask humans-on patches with [ pcolor = yellow] [clean-up ]
ask vacationist-humans [move-to one-of patches with [pcolor = black]]
ask humans-on patches with [ pcolor = yellow] [eat-and-drink]
ask humans-on patches with [ pcolor = yellow] [clean-up ]
ask humans-on patches with [ pcolor = yellow] [eat-and-drink]
ask humans-on patches with [ pcolor = yellow] [get-maintenance ]
]
if (data-vacation != "none" and data-vacationOLD != "" )
[
set vacationist-humans n-of (Vacationists * number-of-humans) humans
set-daily-strategies
ask patches with [pcolor = yellow]
[
set insiders humans-here
set number-of-insiders count insiders
]
ask humans-on patches with [ pcolor = yellow] [clean-up ]
ask humans-on patches with [ pcolor = yellow] [eat-and-drink]
ask humans-on patches with [ pcolor = yellow] [clean-up ]
ask humans-on patches with [ pcolor = black] [move-to house ]
ask humans-on patches with [ pcolor = yellow] [eat-and-drink]
ask humans-on patches with [ pcolor = yellow] [get-maintenance ]
]
if (data-weekday = "Saturday")
[
set weekender-humans n-of (Weekenders * number-of-humans) humans
set-daily-strategies
ask patches with [pcolor = yellow]
[
set insiders humans-here
set number-of-insiders count insiders
]
ask humans-on patches with [ pcolor = yellow] [clean-up ]
ask weekender-humans [if (clmt-strtgy = "outsider") [move-to one-of patches with [pcolor = black]]]
ask humans-on patches with [ pcolor = yellow] [eat-and-drink]
ask humans-on patches with [ pcolor = yellow] [clean-up ]
ask humans-on patches with [ pcolor = yellow] [eat-and-drink]
ask humans-on patches with [ pcolor = yellow] [get-maintenance ]
]
if (data-weekday = "Sunday")
[
set weekender-humans n-of (Weekenders * number-of-humans) humans
set-daily-strategies
ask patches with [pcolor = yellow]
[
set insiders humans-here
set number-of-insiders count insiders
]
ask humans-on patches with [ pcolor = yellow] [clean-up ]
ask humans-on patches with [ pcolor = yellow] [eat-and-drink]
ask humans-on patches with [ pcolor = yellow] [clean-up ]
ask humans-on patches with [ pcolor = yellow] [eat-and-drink]
ask humans-on patches with [ pcolor = yellow] [get-maintenance ]
ask humans-on patches with [ pcolor = black or pcolor = gray] [move-to house ]
]
if (data-weekday != "Sunday" or data-weekday != "Saturday")
[
set workingPeople humans with [ pcolor = yellow and workplace != 0 ]
set-daily-strategies
ask patches with [pcolor = yellow]
[
set insiders humans-here
set number-of-insiders count insiders
]
ask humans-on patches with [ pcolor = yellow] [clean-up ]
ask workingPeople [if (clmt-strtgy = "outsider") [move-to workplace]]
ask humans-on patches with [ pcolor = yellow] [eat-and-drink]
ask humans-on patches with [ pcolor = yellow] [clean-up ]
ask humans-on patches with [ pcolor = yellow] [eat-and-drink]
ask humans-on patches with [ pcolor = black ] [move-to house ]
ask humans-on patches with [ pcolor = yellow] [clean-up ]
ask humans-on patches with [ pcolor = yellow] [get-maintenance ]
]
set number-of-humans count humans
set number-of-houses count patches with [pcolor = yellow]
get-next-record
tick
end
to set-daily-strategies
ifelse (data-weekday = "Saturday" or data-weekday = "Sunday" )
[ ask weekender-humans [ set daily-strtgy "weekender"] ]
[ ask workingPeople [ set daily-strtgy "outsider" ] ]
if (data-vacation != "none")
[ ask vacationist-humans [ set daily-strtgy "vacationist" ]
set data-vacationOLD data-vacation ]
end
cemba is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.