简体   繁体   English

健身功能

[英]Fitness function

Whilst searching on Google about Genetic Algorithms, I came across OneMax Problem, my search showed that this is one of the very first problem that the Genetic Algorithm was applied to. 在Google上搜索遗传算法时,我遇到了OneMax问题,但搜索结果表明这是遗传算法应用于的第一个问题。 However, I am not exactly sure what is OneMax problem. 但是,我不能完全确定OneMax问题是什么。 Can anyone explain. 谁能解释。

Any help is appreciated 任何帮助表示赞赏

The goal of One-Max problem is to create a binary string of length n where every single gene contains a 1. The fitness function is very simple, you just iterate through your binary string counting all ones. One-Max问题的目的是创建一个长度为n的二进制字符串,其中每个单个基因都包含一个1。适应度函数非常简单,您只需遍历所有二进制二进制字符串即可。 This is what the sum represents in the formula you provided with your post. 这就是您的帖子提供的公式中的总和。 It is just the number of ones in the binary string. 它只是二进制字符串中一个的数目。 You could also represent the fitness as a percentage, by dividing the number of ones by n * 0.01 . 您也可以将适应度用百分比表示,将位数除以n * 0.01 A higher fitness would have a higher percentage. 较高的适应性将具有较高的百分比。 Eventually you will get a string of n ones with a fitness of 100% at some generation. 最终,您将在某代获得一串n且适应度为100%的n

double fitness(List<int> chromosome) {
  int ones = chromosome.stream().filter(g -> g == 1).count();
  return ones / chromosome.size() * 0.01;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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