⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mutateinsert.cpp

📁 c++语言实现的遗传算法的例子,需要的快下啊
💻 CPP
字号:
// 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -