我正试着在一个名为冬天的多边形内开始一个代理程序,然后在一个名为夏季的多边形中结束。我让代理成功地在冬季多边形内启动,但我正在努力将最终目的地设置为夏季多边形内的一个补丁。我一直在获取目标补丁语句的错误:
"WITH expected a true/false value from (patch 1 63), but got 0 instead.
error while observer running ONE-OF
called by procedure SETUP
called by Button 'setup'"这是我的密码:
extensions [ gis ]
globals [
elevation
vegetation
roads
fence
q
max-energy
dest-patch
winter
summer
]
patches-own [
used?
pelev
veg
is-road?
is-fence?
veg-suitability
resource
elev-suitability
is-winter?
is-summer?
]
turtles-own [
start-patch
target-patch
energy
]
to setup
clear-all
set max-energy 10
set dest-patch one-of patches with [is-summer?] ; **this is where I get my error when I try to setup my model.
set winter gis:load-dataset ("Lowuse_winter.shp")
;gis:set-world-envelope gis:envelope-of winter
ask patches [ set is-winter? false]
ask patches gis:intersecting winter
[ set is-winter? true]
gis:set-drawing-color blue
gis:draw winter 1
set summer gis:load-dataset ("Lowuse_summer.shp")
;gis:set-world-envelope gis:envelope-of summer
ask patches [ set is-summer? false]
ask patches gis:intersecting summer
[ set is-summer? true]
gis:set-drawing-color green
gis:draw summer 1
;; set fence gis:load-dataset ("highfence_project.shp")
;gis:set-world-envelope gis:envelope-of fence
;'ask patches [ set is-fence? false ]
;ask patches gis:intersecting fence
;[ set is-fence? true ]
;gis:set-drawing-color [255 0 0]
;gis:draw roads 1
;ask patches[
; if is-fence? = true [set pcolor red]
;]
crt 15
[
set size 4
set energy random (deer-gain-from-food)
set start-patch patch-here
set color yellow
; set xcor -17
; set ycor -17
move-to one-of patches with [is-winter?]
pen-down
]
reset-ticks
end
to go
ask turtles [
if patch-here = dest-patch [stop]
ifelse energy < deer-gain-from-food / 10 ;; If only 10% of energy
[
ifelse [resource] of patch-here > 0 ;; Is there anything to eat
[; If there is - eat it and restore energy
forage
]
[ ; If not - mvoe to a neighboring patch with resources
forage-move
]
]
[
migrate-move
]
set energy energy - 1
]
paint-resource
tick
end
to forage
set energy energy + deer-gain-from-food
ask patch-here [
; set resource resource - 0.1
set resource 0
]
end
to forage-move
set target-patch max-one-of neighbors with [ veg-suitability > 0] [ resource ]
move-to target-patch ; error for "move-to expected input but got nobody instead"
set used? TRUE
end发布于 2020-04-11 20:48:01
您收到的消息是,“预期值为真/假值(修补程序163),但得到0。”是因为is-summer?被clear-all初始化为0,所以
set dest-patch one-of patches with [is-summer?]为with运算符提供数字0,而不是真/假值。这一行代码应该在安装过程中稍后进行,在之后,补丁程序已经将它们的is-summer?变量设置为true或false,可能就在行之前。
;; set fence gis:load-dataset ("highfence_project.shp")请注意,ZINAN10 10的答案确实消除了错误消息,但将其放置在现在的位置,这相当于说
set dest-patch one-of patches with [0 = true]当然,这从来不是真的。dest-patch将是nobody。通常,如果变量真正具有真/假值,则不应使用=运算符,因为它将精确地隐藏您在这里遇到的错误类型。
发布于 2020-04-11 18:02:08
我不知道你说的最终目的地是什么意思,但从我所看到的来看,我认为也许你在这里应该有一个真伪。
set dest-patch one-of patches with [is-summer? true/false]试一试,或者更清楚你的错误在哪里。
编辑,是的,尝试在那里添加一个真或假,现在它是空的。
https://stackoverflow.com/questions/61161217
复制相似问题