问题
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