mutateoperator.cpp

来自「粗糙集应用软件」· C++ 代码 · 共 46 行

CPP
46
字号
// MutateOperator.cpp: implementation of the MutateOperator class.
//
//////////////////////////////////////////////////////////////////////

#include <stdafx.h> // Added 980901 by Aleksander 踙rn.
#include "../copyright.h" // Added 000323 by Aleksander 豩rn.

#include "MutateOperator.h"
#include "EABitset.h"
#include "Rand.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

MutateOperator::MutateOperator(int rounds) :times(rounds)
{

}

MutateOperator::~MutateOperator()
{

}

bool MutateOperator::apply(Individual & in, Individual & out)
{
	EABitset * i = (EABitset *)&in;
	EABitset * o = (EABitset *)&out;

	*o = *i;

	if(i->size() <= 0)
		return false;

	for(int ii = 0; ii < times; ii++){
		int point = Rand::i() % i->size();
		o->setP(point, o->getP(point) ? false : true);
	}

	o->reeval = true;
  o->age = 0; // newborn

	return true;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?