Comparing two agent variables

半世苍凉 提交于 2019-12-11 18:42:28

问题


I am currently making a simulation (for homework) using genetic algorithms. What I want to do is compare the fitness of agents on a specific patch and the one with the lowest fitness will die.

I have scoured the net and found this code: if any? breed1-here with [fitness > fitness-of myself] [die]]

But this doesn't seem to work and now I'm completely out of ideas.


回答1:


let goner min-one-of breed1-here [fitness]
if is-turtle? goner [ ask goner [ die ] ]`

the is-turtle? check is necessary because the patch might be empty.




回答2:


Yes, that code is from an old version of the NetLogo language. That line of code should be re-written as:

if any? breed1-here with [fitness > [fitness] of myself] [die]]

Of course, that code will kill all turtles in a patch except for the one(s) with maximum fitness, which is not exactly what you want.



来源:https://stackoverflow.com/questions/14086966/comparing-two-agent-variables

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!