我的代码有问题,我正在制作一个土地利用模型,我想在其中为有剩余的补丁提供新的土地利用。要确定补丁应该改变的土地用途是基于其邻居的吸引力。
拥有的补丁 = 土地使用意愿和吸引力
我想要什么:愿意改变的补丁,应该将他们的土地利用改变为具有最高吸引力的邻居的土地利用(越接近0越有吸引力)
我试图用以下语句来做到这一点:
to askforchange
ask patches [
if Willingstochange = true [change] ;; this ask the patches that are willing to change (have a surpuls) to go and change
]
end
to change
ask neighbors with [Willingstochange = false ] [ ;; this asks if the patch had neigbors with a shortage
set Atractiveneighbor min-one-of patches [atractiveness] ;; this asks to give the neigbor with the lowest patchcount/senario ratio
]
ask patches with [Willingstochange = true] [
set Land-use ([Land-use] of Atractiveneighbor) ;; this asks the patches to change their land-use to the land-use of neigbor with the lowest patchcount/senario ratio
]
end
然而,Netlogo 在运行时报告:“OF 预期输入是海龟代理集或补丁代理集或海龟或补丁,但得到了数字 0。”
任何人建议如何以它的工作方式对其进行编码?
我的整个代码:
extensions [gis]
globals
[
land-use-map
Senario1N ;; the count of patches senario 1 describes
Senario1L
Senario1A
Senario1B
Senario1I
Senario1R
Senario1W
%landusetypeN ;; the amount patches
%landusetypeL
%landusetypeA
%landusetypeB
%landusetypeI
Atractiveneighbor
]
patches-own
[ Land-use ;; Wat kind og landusetype a patch has
Willingstochange ;; If true a patch would like to change (if true the count of patches has a surplus comparing to the sneario, if false they have a shortage)
atractiveness ;; if a patch type is attractive to change in <1 = yess
]
to setup
clear-all
load-gis ;;load the maps
setup-constants
update-global-variables
update-display
reset-ticks
end
to load-gis ;;load the maps
set land-use-map gis:load-dataset "a_LANDUSE_cellsize5.asc" ;;loads the land use map
gis:set-world-envelope-ds gis:envelope-of land-use-map ;;sets the envelope of the world to match that of the GIS dataset
gis:apply-raster land-use-map Land-use ;;patches in the land-use-map have a specific land-use now
ask patches [
if Land-use = 1 [ set pcolor Green ] ; Green = Nature ;; patches have a certain color now
if Land-use = 2 [ set pcolor red ] ; Dark red = Leisure
if Land-use = 3 [ set pcolor Yellow ] ; Yellow = Agriculture
if Land-use = 4 [ set pcolor brown ] ; brouwn = Buildup
if Land-use = 5 [ set pcolor grey ] ; grey = roads
if Land-use = 6 [ set pcolor pink ] ; pink = industry
if Land-use = 7 [ set pcolor blue ] ; Blue = water
]
resize-world 0 1633 0 780
set-patch-size 1
end
to setup-constants
set Senario1N 49174 ;; the count of patches senario 1 describes
set Senario1L 17871
set Senario1A 569970
set Senario1B 34202
set Senario1I 5540
set Senario1R 34968
set Senario1W 65594
end
to go ;; this asks the model to caculate certain variables defined below
askforchange
caculateWILLingtochange
caculateAtrac
tick
end
to update-display
ask patches
[ if Land-use = 1 [ set pcolor Green ] ;; Green = Nature
if Land-use = 2 [ set pcolor red ] ;; Dark red = Leisure
if Land-use = 3 [ set pcolor yellow ] ;; Yellow = Agriculture
if Land-use = 4 [ set pcolor brown ] ;; brouwn = Buildup
if Land-use = 5 [ set pcolor grey ] ;; grey = roads
if Land-use = 6 [ set pcolor pink ] ;; pink = industry
if Land-use = 7 [ set pcolor blue ] ;; Blue = water
] ;; patches have a certain color now
end
to update-global-variables
if count patches > 0
[ set %landusetypeN (count patches with [ Land-use = 1 ] / count patches) * 100
set %landusetypeL (count patches with [ Land-use = 2 ] / count patches) * 100
set %landusetypeA (count patches with [ Land-use = 3 ] / count patches) * 100
set %landusetypeB (count patches with [ Land-use = 4 ] / count patches) * 100
set %landusetypeI (count patches with [ Land-use = 6 ] / count patches) * 100
]
end
to caculateWILLingtochange
Ask patches [
if count patches with [Land-use = 1] > Senario1N [ ask patches with [ Land-use = 1 ][
set Willingstochange True
] ]
if count patches with [Land-use = 2] > Senario1L [ ask patches with [ Land-use = 2 ][
set Willingstochange True
] ]
if count patches with [Land-use = 3] > Senario1A [ ask patches with [ Land-use = 3 ][
set Willingstochange True
] ]
if count patches with [Land-use = 4] > Senario1B [ ask patches with [ Land-use = 4 ][
set Willingstochange True
] ]
if count patches with [Land-use = 5] > Senario1R [ ask patches with [ Land-use = 5 ][
set Willingstochange True
]]
if count patches with [Land-use = 6] > Senario1I [ ask patches with [ Land-use = 6 ][
set Willingstochange True
]]
if count patches with [Land-use = 7] > Senario1W [ ask patches with [ Land-use = 7 ][
set Willingstochange True
] ] ]
end
to caculateAtrac
Ask patches [
if count patches with [Land-use = 1] > Senario1N [ ask patches with [ Land-use = 1 ][
set atractiveness (count patches with [Land-use = 1]/ Senario1N )
] ]
if count patches with [Land-use = 2] > Senario1L [ ask patches with [ Land-use = 2 ][
set atractiveness (count patches with [Land-use = 2]/ Senario1L )
] ]
if count patches with [Land-use = 3] > Senario1A [ ask patches with [ Land-use = 3 ][
set atractiveness (count patches with [Land-use = 3]/ Senario1A )
] ]
if count patches with [Land-use = 4] > Senario1B [ ask patches with [ Land-use = 4 ][
set atractiveness (count patches with [Land-use = 4]/ Senario1B )
] ]
if count patches with [Land-use = 5] > Senario1R [ ask patches with [ Land-use = 5 ][
set atractiveness (count patches with [Land-use = 5]/ Senario1R )
]]
if count patches with [Land-use = 6] > Senario1I [ ask patches with [ Land-use = 6 ][
set atractiveness (count patches with [Land-use = 6]/ Senario1I )
]]
if count patches with [Land-use = 7] > Senario1W [ ask patches with [ Land-use = 7 ][
set atractiveness (count patches with [Land-use = 7]/ Senario1W )
] ] ]
end
to askforchange
ask patches [
if Willingstochange = true [change] ;; this ask the patches that are willing to change (have a surpuls) to go and change
]
end
to change
ask neighbors with [Willingstochange = false ] [ ;; this asks if the patch had neigbors with a shortage
set Atractiveneighbor min-one-of patches [atractiveness] ;; this asks to give the neigbor with the lowest patchcount/senario ratio
]
ask patches with [Willingstochange = true] [
set Land-use ([Land-use] of Atractiveneighbor) ;; this asks the patches to change their land-use to the land-use of neigbor with the lowest patchcount/senario ratio
]
end