I'm trying to do the following:
- Ask turtles (
households
here) to check whether there are any patches that have (1)is-home = true
and (2) cost less than the household's money; - Take as
my-home
the patch id of the first patch that meets these qualifications; - Pass the household id to the patch's
patch-owner
variable; and - Move to that patch.
- If they don't find a patch that meets the criteria, the household dies and the displaced counter increments by 1.
UPDATE: Thanks for the assists so far. Now after adding the condition and not any? households-here
to prevent households from occupying the same patches, pressing Go
triggers the error MOVE-TO expected input to be an agent but got NOBODY instead.
Sorry to reopen this question, but can anyone provide further guidance?
breed [ households household ]
globals [
homes
num-households
number-displaced
]
households-own
[
my-home
money
owner?
]
patches-own
[
is-home?
cost
occupied?
patch-owner
]
to-report random-exponential-in-bounds [mid mmin mmax]
let result random-exponential mid
if result < mmin or result > mmax
[ report random-exponential-in-bounds mid mmin mmax ]
report result
end
to setup-households
ask households
[ set money round random-exponential-in-bounds 50000 0 1000000 ]
end
to setup-patches
ask n-of 100 patches
[ set is-home? one-of [ true false ]
set cost 500 ];random-normal 173000 43000 ]
end
to setup
ca
set-default-shape households "person"
set num-households 100
create-households num-households
setup-households
setup-patches
reset-ticks
end
to choose-house
ifelse any? patches with [ is-home? = true and cost <= [money] of myself and not any? households-here ]
[ ask households [ move-to one-of patches
with [ is-home? = true and cost <= [money] of myself and not any? households-here ]
set owner? true
set my-home patch-here
]
set occupied? TRUE
set patch-owner households-here
]
[ set number-displaced number-displaced + 1
die ]
end
to go
ask households [ choose-house ]
tick
end