Skip to content

Commit 826f1d8

Browse files
committed
*修改描述,使其更加贴切
1 parent b0870ef commit 826f1d8

File tree

1 file changed

+10
-10
lines changed
  • Chapter7/GeneticAlgorithm/GeneticAlgorithm

1 file changed

+10
-10
lines changed

Chapter7/GeneticAlgorithm/GeneticAlgorithm/Program.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ enum ChooseType
4949
static void Main(string[] args)
5050
{
5151
Console.WriteLine("遗传算法");
52-
Console.WriteLine("下面举例来说明遗传算法用以求函数最大值函数为y = -x*x+1024的最大值,-32<=x<=31");
52+
Console.WriteLine("下面举例来说如何应用遗传算法求函数y = -x*x+1024的最大值,-32<=x<=31");
5353
// f(x)=-x*x+1024
5454
// 迭代次数
5555
int totalTime = 5;
@@ -172,7 +172,7 @@ static void Init()
172172
chromosomes[0].probability = chromosomes[0].fitValuePercent;
173173
for (int i = 1; i < chromosomes.Count; i++)
174174
{
175-
//上一个的累计概率加上自己的概率,得到自己的累计概率
175+
//上一个的累积概率加上自己的概率,得到自己的累积概率
176176
chromosomes[i].probability = chromosomes[i - 1].probability + chromosomes[i].fitValuePercent;
177177
}
178178
}
@@ -228,11 +228,11 @@ static void UpdateNext()
228228
Console.WriteLine("fitValuePercent " + i + " " + chromosomes[i].fitValuePercent);
229229
}
230230
//计算累积概率
231-
// 第一个的累计概率就是自己的概率
231+
// 第一个的累积概率就是自己的概率
232232
chromosomes[0].probability = chromosomes[0].fitValuePercent;
233233
for (int i = 1; i < chromosomes.Count; i++)
234234
{
235-
// 上一个的累计概率加上自己的概率,得到自己的累计概率
235+
// 上一个的累积概率加上自己的概率,得到自己的累积概率
236236
chromosomes[i].probability = chromosomes[i - 1].probability + chromosomes[i].fitValuePercent;
237237

238238
}
@@ -285,17 +285,17 @@ static void ChooseChromosome()
285285
/// </summary>
286286
static void CrossOperate()
287287
{
288-
/** bit[5]~bit[0] fit
289-
* 4 000 110 12
290-
* 3 001 010 9
291-
* child1 000 010 14
292-
* child2 001 110 5
288+
/** bit[5]~bit[0] fit
289+
* 4 000 110 12 //第一条
290+
* 3 001 010 9 //第二条
291+
* child1 000 010 14 //第三条
292+
* child2 001 110 5 //第四条
293293
*/
294294
int rand = new Random(GetSeed()).Next(0, 6); //0-5;
295295
Console.WriteLine("交叉的rand " + rand);
296296
for (int i = 0; i < rand; i++)
297297
{
298-
//将第0个给第2个;
298+
//将第一条(下标0)给第三条(下标2)
299299
chromosomes[2].bits[i] = chromosomes[0].bits[i]; //第一条和第三条交叉
300300
chromosomes[3].bits[i] = chromosomes[1].bits[i]; //第二条和第四条交叉
301301
}

0 commit comments

Comments
 (0)