在遗传算法code排名评选 [英] Ranking Selection in Genetic Algorithm code
问题描述
我需要一个遗传算法(http://www.obitko.com/tutorials/genetic-algorithms/selection.php)code的排名评选方法。 我已创建roullete和锦标赛的选择方法,但现在我需要的排名,我被卡住。 我roullete code是在这里(我用原子结构的遗传原子):
const int的轮盘(常量原子* F)
{
INT I;
双和,sumrnd;
总和= 0;
对于(I = 0; I&所述N;我+ +)
总和+ = F(I).fitness + OFFSET;
sumrnd = RND()*总和;
总和= 0;
对于(I = 0; I&所述N;我++){
总和+ = F(I).fitness + OFFSET;
如果(总和> sumrnd)
打破;
}
返回我;
}
其中原子:
typedef结构原子
{
INT格诺[VARS]
双苯氧[VARS]
双健身;
} 原子;
等级的选择是很容易实现的时候,你已经知道了在轮盘赌选择。而不是使用健身为一体的概率为入门选择您使用的等级。因此,对于N方案群的最佳解决方案获得等级N,第二个最好的等级N-1等的最差个体的秩1.现在使用的轮盘赌,并开始选择。
有最佳个体被选择的概率为N /((N *(N + 1))/ 2)或大约为2 / N为最坏的个体是2 /(N *(N + 1) ),或大约2 / N ^ 2。
这就是所谓的线性秩的选择,因为队伍中形成线性的进展。你也可以把队伍形成了几何级数,如如1 / ^ n,其中n是从1为最佳个体到N最坏的打算的。这当然给的概率要高得多,以最佳的个性化。
您可以看一下在的 HeuristicLab 。
I need code for the ranking selection method on a genetic algorithm (http://www.obitko.com/tutorials/genetic-algorithms/selection.php). I have create roullete and tournament selections method but now I need ranking and I am stuck. My roullete code is here (I am using atom struct for genetic atoms) :
const int roulette (const atom *f)
{
int i;
double sum, sumrnd;
sum = 0;
for (i = 0; i < N; i++)
sum += f[i].fitness + OFFSET;
sumrnd = rnd () * sum;
sum = 0;
for (i = 0; i < N; i++) {
sum += f[i].fitness + OFFSET;
if (sum > sumrnd)
break;
}
return i;
}
Where atom :
typedef struct atom
{
int geno[VARS];
double pheno[VARS];
double fitness;
} atom;
Rank selection is easy to implement when you already know on roulette wheel selection. Instead of using the fitness as probability for getting selected you use the rank. So for a population of N solutions the best solution gets rank N, the second best rank N-1, etc. The worst individual has rank 1. Now use the roulette wheel and start selecting.
The probability for the best individual to be selected is N/( (N * (N+1))/2 ) or roughly 2 / N, for the worst individual it is 2 / (N*(N+1)) or roughly 2 / N^2.
This is called linear rank selection, because the ranks form a linear progression. You can also think of ranks forming a geometric progression, such as e.g 1 / 2^n where n is ranging from 1 for the best individual to N for the worst. This of course gives much higher probability to the best individual.
You can look at the implementation of some selection methods in HeuristicLab.
这篇关于在遗传算法code排名评选的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!