mutateinsert.cpp
来自「c++语言实现的遗传算法的例子,需要的快下啊」· C++ 代码 · 共 46 行
CPP
46 行
// MutateInsert.cpp: implementation of the MutateInsert class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MutateInsert.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
MutateInsert::MutateInsert(double p,int d):Mutate(p,d)
{
}
void MutateInsert::Mutation(Popular * pop,Rand * r)
{
if(r->random(1)<pm)
{
double * pp=pop->GetPop();
int mm=r->randint(dimension);
int nn=r->randint(dimension);
if(nn<mm)
for(int i=mm;i>nn;i--)
{
double temp=pp[mm];
pp[mm]=pp[i-1];
pp[i-1]=temp;
}
else
for(int i=mm;i<nn;i++)
{
double temp=pp[mm];
pp[mm]=pp[i+1];
pp[i+1]=temp;
}
pop->SetPop(pp);
delete[] pp;
}
}
MutateInsert::~MutateInsert()
{
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?