我正在试用Railsback和Grimm的书中的例子(基于代理和基于个人的建模)。我使用第10.4章的说明编写了一个商业模型。我可以成功设置模型,但是当我点击go按钮时,我收到错误
"this code can't be run by a patch
error while turtle 3 running UTILITY-FOR
called by procedure REPOSITION
called by procedure GO
called by Button 'go'"
这是我的代码
patches-own
[
annual-profit
business-risk
]
turtles-own
[
wealth
]
to setup
clear-all
;initializing the profit
ask patches
[
set annual-profit random 1000
set business-risk 1 - risk-probability
set pcolor scale-color green annual-profit 0 1000
]
crt 5 ; created five business spots for test
[
setxy random-xcor random-ycor
set shape "house"
set color red
set wealth random 10000]
reset-ticks
end
to go
ask turtles [reposition]
tick
end
to reposition
let potential-destinations neighbors with
[not any? turtles-here]
;adding the current patch to the potential-destinations
set potential-destinations
(patch-set potential-destinations patch-here)
; Identify the best one of the destinations
let best-patch max-one-of potential-destinations
[utility-for myself]
;Now move there
move-to best-patch
end
to-report utility-for [a-turtle]
; a patch-context reporter that calculates utility
; for turtle "a-turtle" in this patch
; first get the turtle's wealth
let turtles-wealth [wealth] of a-turtle
let profit [annual-profit] of patch-here
let risk [business-risk] of patch-here
; then calculate turtles's utility given its wealth and
; relevant variables
let utility ( turtles-wealth + profit * 5 ) * (risk ^ ticks)
report utility
end
答案 0 :(得分:1)
更改
let profit [annual-profit] of patch-here
let risk [business-risk] of patch-here
到
let profit annual-profit
let risk business-risk
HTH