mutation.cs
来自「c#编写」· CS 代码 · 共 31 行
CS
31 行
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 + =
减小字号Ctrl + -
显示快捷键?