Netlogo &引用;Can';不要在观察者上下文中使用XXX,因为“仅修补程序”;
我的一部分代码遇到了一些问题。Netlogo reort“无法在观察者上下文中使用GO,因为只有补丁” 我的猜测是,这是因为在围棋部分,我要求一个程序(CACULATEWILANDATRAC),它不是以“询问补丁”开头的。然而,(CACULATEWILANDATRAC)生成的是计算补丁自身的变量之一,因此ask补丁似乎不适合这里 我仍然试图通过将ask补丁放在procure之前来解决它,但是 我在运行模型时遇到另一个错误:“只有观察者可以询问所有补丁集。 修补程序1079 509运行ASK时出错 由以下程序调用(匿名命令:[[the Land use the Senario]->ask patches[if count patches with[the Land use]>the Senario[set Willingstochange True]]])调用:caculatewilandatarac“ 因此,问题在于在何处调用CACULATEWILANDATRAC程序? 它现在是go过程的一部分,但这会导致错误“不能在观察者上下文中使用XXX,因为只有海龟” 我的全部代码:Netlogo &引用;Can';不要在观察者上下文中使用XXX,因为“仅修补程序”;,netlogo,observers,Netlogo,Observers,我的一部分代码遇到了一些问题。Netlogo reort“无法在观察者上下文中使用GO,因为只有补丁” 我的猜测是,这是因为在围棋部分,我要求一个程序(CACULATEWILANDATRAC),它不是以“询问补丁”开头的。然而,(CACULATEWILANDATRAC)生成的是计算补丁自身的变量之一,因此ask补丁似乎不适合这里 我仍然试图通过将ask补丁放在procure之前来解决它,但是 我在运行模型时遇到另一个错误:“只有观察者可以询问所有补丁集。 修补程序1079 509运行ASK时出错
> 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
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
Atractiveneighbor
]
patches-own
[ Land-use ;; Wat kind og landusetype a patch has
]
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
givecountlansusetypes
askforchange
caculateWILandAtrac
tick
end
to givecountlansusetypes ;; here the cuurent amount of patches is shown
show count patches with [Land-use = 1]
show count patches with [Land-use = 2]
show count patches with [Land-use = 3]
show count patches with [Land-use = 4]
show count patches with [Land-use = 5]
show count patches with [Land-use = 6]
show count patches with [Land-use = 7]
end
to update-display
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
]
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 caculateWILandAtrac
;; Sets Willingness to change true if patches are with more fellowpatches than the senario decribes
(foreach list (Land-use = 1) (Land-use = 2)[49174 17871]
[ [the-Land-use the-Senario] -> ask patches [if count patches with [the-Land-use] > the-Senario [ set Willingstochange True ] ] ])
;; gives score to the patches attractiveness based on the ratio patches/senario
(foreach list (Land-use = 1) (Land-use = 2)[49174 17871]
[ [the-Land-use the-Senario] -> ask patches [ set atractiveness (count patches with [the-Land-use]/ the-Senario) ] ])
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 [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
扩展[gis]
全局变量
[
土地利用图
senario;senario 1描述的补丁计数
塞纳里奥
Senario1A
塞纳里奥1b
塞纳里奥1
Senario1R
Senario1W
%土地使用类型;补丁的数量
%兰多斯泰普尔
%土地利用类型
%landusetypeB
%土地利用类型
Willingstochange;;如果为true,则修补程序希望更改(如果为true,则修补程序的计数与sneario相比有盈余,如果为false,则修补程序的计数有短缺)
a活动性;;如果修补程序类型有吸引力在0中更改
[设置%landusetypeN(使用[Land use=1]计算斑块数量)/计算斑块数量)*100
设置%landusetypeL(使用[Land use=2]/计数面片数计算面片数)*100
设置%landusetypeA(使用[Land use=3]/计算补丁数计算补丁数)*100
设置%landusetypeB(使用[Land use=4]/计算补丁数计算补丁数)*100
设置%landusetypeI(使用[Land use=6]/计算补丁数计算补丁数)*100
]
结束
恶作剧
;如果斑块的同胞斑块比senario描述的多,则愿意改变
(每个清单(土地使用=1)(土地使用=2)[49174 17871]
[[Land use the Senario]->询问补丁[if count patches with[Land use]>Senario[set Willingstochange True]]
;根据补丁/塞纳里奥的比例对补丁的吸引力进行评分
(每个清单(土地使用=1)(土地使用=2)[49174 17871]
[[TheLand use the Senario]->询问补丁[设置活动(使用[TheLand use]/TheSenario]计算补丁)])
结束
要求改变
询问补丁[
如果Willingstochange=true[change];;这将要求愿意改变(有惊喜)的补丁去改变
]
结束
改变
用[Willingstochange=false]询问邻居;这询问补丁是否有缺少的邻居
[将atractivenieghbor设置为至少一个补丁[atractiveness];;这要求为邻居提供最低的补丁计数/传感器比率
询问斑块[设置土地利用(ATRActivenieghbor的[土地利用]);这要求斑块将其土地利用更改为斑块数/塞纳里奥比率最低的邻近区域的土地利用
结束
在您的最后一行代码中,当前询问的补丁(在askforchange中询问)要求所有补丁相应地设置其土地使用。我认为这就是您的问题所在 如果您将最后一行替换为以下内容,可能会解决您的问题:
set Land-use ([Land-use] of Atractiveneighbor)
有了这个,当前被要求的补丁会相应地改变它的土地用途。但是我不太确定,如果这是你想要的程序在那里做的