因此,当使用我创建的报告器过程进行计算时,我尝试根据它的值对列表进行排序。代码如下:
globals [ goal Smin Smax distWeight colorWeight ]
turtles-own [ S Ac ]
to setup
ca
set Smin 2
set Smax 6
set distWeight 2
set colorWeight 3
ask n-of n patches [
sprout 1 [
set color one-of [ red blue ]
set heading one-of [ 90 270 ]
set S []
]
]
reset-ticks
end
to go
ask turtles [
foreach sort other turtles [
ask ? [
if Smin < Sim myself ? [
if Sim myself ? < Smax [
set S lput ? S
]
]
]
]
;how do I do this? this does not work
set Ac max-one-of S [Sim myself ?]
]
tick
end
to-report Sim [Ame Ao]
report (Sfcolor Ame Ao * colorWeight) + (Sfdistance Ame Ao * distWeight)
end
to-report Sfcolor [Ame Ao]
ifelse [color] of Ame = [color] of Ao
[ report 1 ]
[ report 0 ]
end
to-report Sfdistance [Ame Ao]
report 1 / euclidean-distance [xcor] of Ame [ycor] of Ame [xcor] of Ao [ycor] of Ao
end
to-report euclidean-distance [x y x1 y1]
report sqrt ((x1 - x) ^ 2 + (y1 - y) ^ 2)
end
to-report Gain [ SimVal ]
report ( Smax - Smin ) / Smax - SimVal
end现在,我想要一个名为Ac的变量来包含turtle,它是S的一个元素,具有最高的Sim值。我试着这样做
set Ac max-one-of S [Sim myself ?]但它不起作用。
发布于 2013-06-20 02:56:36
如果你确切地说出它不起作用的原因,那会有所帮助。
但是对于初学者来说,这条语句在foreach循环之外,所以呢?不会有任何意义。
https://stackoverflow.com/questions/17072613
复制相似问题