Netlogo:计算自己和其他代理之间的距离
Netlogo: calculate distance between self and other agent
你好:我正在使用 Netlogo 并希望代理计算他们自己与他们之前选择的另一个代理之间的距离。我不断收到下面 "expected a literal value." 代码的错误。求助说距离"distance agent: Reports the distance from this agent to the given turtle or patch."的这个reporter 因为我之前定义了"myneighbor,"所以搞不懂哪里不对。非常感谢任何帮助。
turtles-own [
myneighbor ;; closest other male frog to myself
mycall ;; the amplitude (loudness) of my own call
myminthresh ;; when my neighbor's call is below this threshold, I move toward him
mymaxthresh ;; when my neighbor's call is above this threshold, I move away from him
myNND ;; the distance to my nearest neighbor
settle? ;; true if male decides to create a territory and stop moving
]
to setup
clear-all
create-turtles population [ ;; use the population slider to choose number of males
set size 1.5 ;; easy to see but is it actual agent size or just agent image size?
setxy random-xcor random-ycor ;; distribute frogs randomly in the landscape
set mycall random 100 ;; choose the amplitude of my own call from a random distribution 0 to 100
set color scale-color red mycall 0 100 ;; allows easy visualization of variability in call amplitude
;; lighter color is a higher amplitude
set myminthresh inputminthresh ;; use the input on interface to set the min-threshold
set mymaxthresh inputmaxthresh ;; use the input on the interface to set the max-threshold
set myNND 0 ;; initialize nearest neighbor distance for all
]
reset-ticks
end
to go
choose-neighbors
move-turtles
tick
end
to choose-neighbors
ask turtles [
set myneighbor min-one-of other turtles [distance myself] ;; choose my nearest neighbor based on distance
set myNND [ distance myneighbor ]
]
end
to move-turtles
ask turtles [
face myneighbor
;;set heading (random 360)
fd 5
pendown
]
end
问题行是:
set myNND [ distance myneighbor ]
改为:
set myNND distance myneighbor
NetLogo 的 [] 约定可能有些晦涩难懂。
你好:我正在使用 Netlogo 并希望代理计算他们自己与他们之前选择的另一个代理之间的距离。我不断收到下面 "expected a literal value." 代码的错误。求助说距离"distance agent: Reports the distance from this agent to the given turtle or patch."的这个reporter 因为我之前定义了"myneighbor,"所以搞不懂哪里不对。非常感谢任何帮助。
turtles-own [
myneighbor ;; closest other male frog to myself
mycall ;; the amplitude (loudness) of my own call
myminthresh ;; when my neighbor's call is below this threshold, I move toward him
mymaxthresh ;; when my neighbor's call is above this threshold, I move away from him
myNND ;; the distance to my nearest neighbor
settle? ;; true if male decides to create a territory and stop moving
]
to setup
clear-all
create-turtles population [ ;; use the population slider to choose number of males
set size 1.5 ;; easy to see but is it actual agent size or just agent image size?
setxy random-xcor random-ycor ;; distribute frogs randomly in the landscape
set mycall random 100 ;; choose the amplitude of my own call from a random distribution 0 to 100
set color scale-color red mycall 0 100 ;; allows easy visualization of variability in call amplitude
;; lighter color is a higher amplitude
set myminthresh inputminthresh ;; use the input on interface to set the min-threshold
set mymaxthresh inputmaxthresh ;; use the input on the interface to set the max-threshold
set myNND 0 ;; initialize nearest neighbor distance for all
]
reset-ticks
end
to go
choose-neighbors
move-turtles
tick
end
to choose-neighbors
ask turtles [
set myneighbor min-one-of other turtles [distance myself] ;; choose my nearest neighbor based on distance
set myNND [ distance myneighbor ]
]
end
to move-turtles
ask turtles [
face myneighbor
;;set heading (random 360)
fd 5
pendown
]
end
问题行是:
set myNND [ distance myneighbor ]
改为:
set myNND distance myneighbor
NetLogo 的 [] 约定可能有些晦涩难懂。