我有一组100位命名位,我只想做这个操作: 100 - absolute_value(#的1的 - #的0)。我尝试了各种形式,其中一种形式如下:
100 - abs (length filter [x -> x = 1] bits - length filter [x -> x = 0] bits)
但无论如何,结果总是100,我不明白为什么因为如果我删除“100 - ”,单独的abs操作的结果与0不同。 任何建议都会被贬低,我也注意到当我连续做一个随机请求时,结果不会改变太多
turtles-own [
bits
fitness
]
to setup
clear-all
create-turtles population-size [
set bits n-values world-width [one-of [0 1]]
ifelse fitness-function?
[ calculate-fitness-alt ]
[ calculate-fitness ]
hide-turtle
]
to calculate-fitness-alt
set fitness 100 - abs (length filter [x -> x = 1 ] bits - length filter [x -> x = 0 ] bits)
end