我正在试用由Railsback和Grimm (基于Agent和基于个人的建模)书中的示例。在使用第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发布于 2015-12-08 19:05:12
变化
let profit [annual-profit] of patch-here
let risk [business-risk] of patch-here至
let profit annual-profit
let risk business-riskhth
https://stackoverflow.com/questions/34155218
复制相似问题