简体   繁体   中英

Is this considered a fitness function for a genetic algorithm?

I start off with a population. I also have properties each individual in the population can have. If an individual DOES have the property, it's score goes up by 5. If it DOESNT have it, it's score increases by 0. Example code using length as a property:

for x in individual: 
    if len <5:
        score += 5
    if len >=5:
        score += 0

Then I add up the total score and select the individuals I want to continue. Is this a fitness function?

Anything can be a fitness algorithm as long as it gives better points for better DNA. The code you wrote looks like a gene of a DNA rather than a constraint. If it was a constraint, you'd give it a growing score penalty (its a minimization of score?) depending on the distance to the constraint point so that the selection/crossover part could prioritize the closer DNAs to 5. But currently it looks like "anything < 5 works fine" so there will be a lot of random solutions to this with high diversity (unless you apply elitism).

If there are many variables like "len" with equal score, then one gene's failure could be shadowed by another gene's success. To stop this, you can give them different scores like 5,10,20,40,... so that the selection and crossover can know if it actually made progress without any failure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM