📄 mutation.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
namespace GA_RPS.GAKernel
{
class Mutation
{
public Population[] mutateOp(Population[] p)
{
Roulette r = new Roulette();
int mutNum = (int)((double)GAControl.POP_NUM * (double)GAControl.POP_SIZE * GAControl.MUT_RATIO);
r.resetBallot(GAControl.POP_NUM * GAControl.POP_SIZE);
for (int i = 0; i < mutNum; i++)
{
int mutPoint = r.lot() + 1;
int mutPop = mutPoint / GAControl.POP_SIZE; // the population where mutation point located
int mutPos = mutPoint - mutPop * GAControl.POP_SIZE; // the position of the mutation point in the population
if (mutPos == 0) mutPop--;
else mutPos--;
//System.Windows.Forms.MessageBox.Show(Convert.ToString(mutPoint), "Mutate Point");
//System.Windows.Forms.MessageBox.Show(Convert.ToString(mutPop), "Mutate Population");
//System.Windows.Forms.MessageBox.Show(Convert.ToString(mutPos), "Mutate Position");
r.resetBallot(3);
p[mutPop].GaArray[mutPos] = r.ranRPS(p[mutPop].GaArray[mutPos]);
}
return p;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -