亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? cgabob.cpp

?? 《游戲編程中的人工智能技術(shù)》書中源代碼和可執(zhí)行文件
?? CPP
字號(hào):
#include "CgaBob.h"



//--------------------------RouletteWheelSelection-----------------
//
//	selects a member of the population by using roulette wheel 
//	selection as described in the text.
//------------------------------------------------------------------
SGenome& CgaBob::RouletteWheelSelection()
{
	double fSlice	= RandFloat() * m_dTotalFitnessScore;
	
	double cfTotal	= 0.0;
	
	int	SelectedGenome = 0;
	
	for (int i=0; i<m_iPopSize; ++i)
	{
		
		cfTotal += m_vecGenomes[i].dFitness;
		
		if (cfTotal > fSlice) 
		{
			SelectedGenome = i;
			break;
		}
	}
	
	return m_vecGenomes[SelectedGenome];
}

//----------------------------Mutate---------------------------------
//	iterates through each genome flipping the bits acording to the
//	mutation rate
//--------------------------------------------------------------------
void CgaBob::Mutate(vector<int> &vecBits)
{
	for (int curBit=0; curBit<vecBits.size(); curBit++)
	{
		//do we flip this bit?
		if (RandFloat() < m_dMutationRate)
		{
			//flip the bit
			vecBits[curBit] = !vecBits[curBit];
		}
	}//next bit
}

//----------------------------Crossover--------------------------------
//	Takes 2 parent vectors, selects a midpoint and then swaps the ends
//	of each genome creating 2 new genomes which are stored in baby1 and
//	baby2.
//---------------------------------------------------------------------
void CgaBob::Crossover( const vector<int> &mum,
						const vector<int> &dad,
						vector<int>		  &baby1,
						vector<int>		  &baby2)
{
	//just return parents as offspring dependent on the rate
	//or if parents are the same
	if ( (RandFloat() > m_dCrossoverRate) || (mum == dad)) 
	{
		baby1 = mum;
		baby2 = dad;

		return;
	}
	
	//determine a crossover point
	int cp = RandInt(0, m_iChromoLength - 1);

	//swap the bits
	for (int i=0; i<cp; ++i)
	{
		baby1.push_back(mum[i]);
		baby2.push_back(dad[i]);
	}

	for (i=cp; i<mum.size(); ++i)
	{
		baby1.push_back(dad[i]);
		baby2.push_back(mum[i]);
	}
}
//-----------------------------------Run----------------------------------
//
//	This is the function that starts everything. It is mainly another 
//	windows message pump using PeekMessage instead of GetMessage so we
//	can easily and dynamically make updates to the window while the GA is 
//	running. Basically, if there is no msg to be processed another Epoch
//	is performed.
//------------------------------------------------------------------------
void CgaBob::Run(HWND hwnd)
{
	//The first thing we have to do is create a random population
	//of genomes
	CreateStartPopulation();
	
	m_bBusy = true;
		
}
//----------------------CreateStartPopulation---------------------------
//
//-----------------------------------------------------------------------
void CgaBob::CreateStartPopulation()
{
	//clear existing population
	m_vecGenomes.clear();
	
	for (int i=0; i<m_iPopSize; i++)
	{
		m_vecGenomes.push_back(SGenome(m_iChromoLength));
	}

	//reset all variables
	m_iGeneration		 = 0;
	m_iFittestGenome	 = 0;
	m_dBestFitnessScore  = 0;
	m_dTotalFitnessScore = 0;
}
//--------------------------------Epoch---------------------------------
//
//	This is the workhorse of the GA. It first updates the fitness
//	scores of the population then creates a new population of
//	genomes using the Selection, Croosover and Mutation operators
//	we have discussed
//----------------------------------------------------------------------
void CgaBob::Epoch()
{
	
	UpdateFitnessScores();

	//Now to create a new population
	int NewBabies = 0;

	//create some storage for the baby genomes 
	vector<SGenome> vecBabyGenomes;

	while (NewBabies < m_iPopSize)
	{
		//select 2 parents
		SGenome mum = RouletteWheelSelection();
		SGenome dad = RouletteWheelSelection();

		//operator - crossover
		SGenome baby1, baby2;
		Crossover(mum.vecBits, dad.vecBits, baby1.vecBits, baby2.vecBits);

		//operator - mutate
		Mutate(baby1.vecBits);
		Mutate(baby2.vecBits);

		//add to new population
		vecBabyGenomes.push_back(baby1);
		vecBabyGenomes.push_back(baby2);

		NewBabies += 2;
	}

	//copy babies back into starter population
	m_vecGenomes = vecBabyGenomes;

	//increment the generation counter
	++m_iGeneration;
}

//---------------------------UpdateFitnessScores------------------------
//	updates the genomes fitness with the new fitness scores and calculates
//	the highest fitness and the fittest member of the population.
//	Also sets m_pFittestGenome to point to the fittest. If a solution
//	has been found (fitness == 1 in this example) then the run is halted
//	by setting m_bBusy to false
//-----------------------------------------------------------------------
void CgaBob::UpdateFitnessScores()
{
	m_iFittestGenome		= 0;
	m_dBestFitnessScore		= 0;
	m_dTotalFitnessScore	= 0;

	CBobsMap TempMemory;
	 
	//update the fitness scores and keep a check on fittest so far
	for (int i=0; i<m_iPopSize; ++i)
	{
		//decode each genomes chromosome into a vector of directions
		vector<int> vecDirections = Decode(m_vecGenomes[i].vecBits);

		//get it's fitness score
		m_vecGenomes[i].dFitness = m_BobsMap.TestRoute(vecDirections, TempMemory);

		//update total
		m_dTotalFitnessScore += m_vecGenomes[i].dFitness;

		//if this is the fittest genome found so far, store results
		if (m_vecGenomes[i].dFitness > m_dBestFitnessScore)
		{
			m_dBestFitnessScore = m_vecGenomes[i].dFitness;

			m_iFittestGenome = i;

			m_BobsBrain = TempMemory;

			//Has Bob found the exit?
			if (m_vecGenomes[i].dFitness == 1)
			{
				//is so, stop the run
				m_bBusy = false;
			}
		}

		TempMemory.ResetMemory();
	
	}//next genome
}

//---------------------------Decode-------------------------------------
//
//	decodes a vector of bits into a vector of directions (ints)
//
//	0=North, 1=South, 2=East, 3=West
//-----------------------------------------------------------------------
vector<int> CgaBob::Decode(const vector<int> &bits)
{
	vector<int>	directions;

	//step through the chromosome a gene at a time
	for (int gene=0; gene < bits.size(); gene += m_iGeneLength)
	{
		//get the gene at this position
		vector<int> ThisGene;
		
		for (int bit = 0; bit < m_iGeneLength; ++bit)
		{
			ThisGene.push_back(bits[gene+bit]);
		}

		//convert to decimal and add to list of directions
		directions.push_back(BinToInt(ThisGene));
	}

	return directions;
}

//-------------------------------BinToInt-------------------------------
//	converts a vector of bits into an integer
//----------------------------------------------------------------------
int	CgaBob::BinToInt(const vector<int> &vec)
{
	int val = 0;
	int multiplier = 1;
	
	for (int cBit=vec.size(); cBit>0; cBit--)
	{
		val += vec[cBit-1] * multiplier;
		
		multiplier *= 2;
	}

	return val;
}



//------------------------- Render -------------------------------
//
//	given a surface to render to this function renders the map
//	and the best path if relevant. cxClient/cyClient are the 
//	dimensions of the client window.
//----------------------------------------------------------------
void CgaBob::Render(int cxClient, int cyClient, HDC surface)
{
	//render the map
	m_BobsMap.Render(cxClient, cyClient, surface);

	//render the best route
	m_BobsBrain.MemoryRender(cxClient, cyClient, surface);

	//Render additional information
	string s = "Generation: " + itos(m_iGeneration);
	TextOut(surface, 5, 0, s.c_str(), s.size());
	
	if (!m_bBusy)
	{
		string Start = "Press Return to start a new run";
		
		TextOut(surface, cxClient/2 - (Start.size() * 3), cyClient - 20, Start.c_str(), Start.size());
	}
	
	else
		
	{
		string Start = "Space to stop";
		
		TextOut(surface, cxClient/2 - (Start.size() * 3), cyClient - 20, Start.c_str(), Start.size());
	}
	
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
韩国v欧美v亚洲v日本v| 亚洲免费视频中文字幕| 91精品视频网| 欧美性色黄大片| 色噜噜偷拍精品综合在线| www.成人在线| 色婷婷久久久亚洲一区二区三区| 国产成人av影院| 成人av在线一区二区三区| 99久久99久久精品免费观看 | 日韩三级.com| 日韩一区二区三区av| 精品少妇一区二区三区日产乱码 | 国产精品天干天干在观线| 久久久久国产成人精品亚洲午夜| 久久嫩草精品久久久精品| 国产精品视频第一区| 亚洲午夜激情av| 蜜臀精品久久久久久蜜臀 | 色噜噜夜夜夜综合网| 欧美色电影在线| 亚洲精品在线免费观看视频| 国产精品久久久久久亚洲毛片| 亚洲欧美偷拍卡通变态| 日韩成人免费看| 成人网男人的天堂| 欧美美女喷水视频| 欧美精品一区二区三区蜜臀| 国产精品久久久久久久久免费桃花| 亚洲精品福利视频网站| 美女精品一区二区| aa级大片欧美| 日韩欧美一区二区在线视频| 亚洲国产成人私人影院tom| 亚洲一区免费观看| 国产成人免费xxxxxxxx| 欧美性大战xxxxx久久久| 2020国产精品自拍| 婷婷综合久久一区二区三区| 成人免费va视频| 精品处破学生在线二十三| 一区二区三区鲁丝不卡| 国产成人精品亚洲午夜麻豆| 欧美日韩另类一区| 成人免费在线视频观看| 美女网站色91| 欧美色图一区二区三区| 国产精品久久777777| 激情综合色播激情啊| 欧美日韩视频在线一区二区| 成人欧美一区二区三区1314| 狠狠色2019综合网| 日韩欧美卡一卡二| 日本三级韩国三级欧美三级| 色婷婷久久久亚洲一区二区三区| 国产欧美精品一区| 国产真实乱子伦精品视频| 日韩欧美中文字幕公布| 亚洲三级电影网站| 99精品欧美一区二区三区小说 | 蜜臀av一区二区三区| 色吊一区二区三区| 亚洲色图都市小说| 不卡的av电影在线观看| 国产欧美精品国产国产专区| 精品亚洲成a人| 7777精品伊人久久久大香线蕉 | 国产福利视频一区二区三区| 日韩视频免费观看高清完整版| 亚洲午夜精品在线| 在线观看国产一区二区| 一区二区三区在线视频播放| 91丨porny丨最新| 最新中文字幕一区二区三区| www.欧美日韩| 伊人色综合久久天天人手人婷| 91亚洲永久精品| 一区二区三区在线看| 欧洲生活片亚洲生活在线观看| 亚洲欧美激情小说另类| 欧美在线观看18| 午夜精品久久久久久| 日韩一区和二区| 国产精品综合av一区二区国产馆| 欧美变态tickle挠乳网站| 国产精品18久久久久久久久久久久 | 日韩在线一二三区| 欧美日韩国产一级二级| 免费高清在线视频一区·| 日韩久久久精品| 成人av在线观| 亚洲国产精品久久人人爱蜜臀| 91免费在线播放| 视频一区视频二区中文| 日韩一级片在线观看| 国产一区二区三区免费观看| 国产精品毛片大码女人| 欧美日韩午夜在线| 国产一区二区0| 伊人夜夜躁av伊人久久| 日韩一区二区电影在线| 国产91丝袜在线播放| 亚洲国产精品视频| 国产色婷婷亚洲99精品小说| 色天天综合色天天久久| 久久国产人妖系列| 亚洲久草在线视频| www久久精品| 色婷婷久久一区二区三区麻豆| 麻豆国产一区二区| 亚洲免费av在线| 26uuu国产日韩综合| 91香蕉视频污| 国产美女主播视频一区| 曰韩精品一区二区| 国产欧美一区二区三区鸳鸯浴| 91久久一区二区| 成人午夜视频在线| 日本不卡一区二区三区高清视频| 亚洲欧洲精品一区二区精品久久久| 欧美一区二区三区四区高清| www.在线成人| 久久99精品国产| 午夜久久电影网| 综合中文字幕亚洲| 国产人久久人人人人爽| 日韩一区二区三区免费看| 91看片淫黄大片一级| 激情综合亚洲精品| 日韩成人免费看| 亚洲国产中文字幕在线视频综合| 国产日韩成人精品| 2021国产精品久久精品| 日韩一区二区影院| 3d成人动漫网站| 欧美三级视频在线观看| 欧美午夜精品理论片a级按摩| 成人激情开心网| 国产精品伊人色| 极品尤物av久久免费看| 麻豆精品一区二区综合av| 亚洲亚洲人成综合网络| 亚洲免费三区一区二区| 国产精品成人免费| 亚洲天天做日日做天天谢日日欢 | 欧美国产综合色视频| 日韩欧美精品在线| 亚洲精品一线二线三线无人区| 欧美伊人久久久久久久久影院 | 精品日韩99亚洲| 日韩欧美一卡二卡| 精品国产一区二区三区忘忧草 | 盗摄精品av一区二区三区| 国产成人免费av在线| 成人性生交大片免费看视频在线| 国产精品一级二级三级| 国产精品综合视频| 不卡一区中文字幕| 一本色道久久加勒比精品| 9i看片成人免费高清| 一本大道久久a久久精二百 | 久热成人在线视频| 极品少妇一区二区| 高清视频一区二区| 色综合中文综合网| 久久久精品人体av艺术| 国产欧美日韩久久| 亚洲精品自拍动漫在线| 亚洲激情第一区| 日本不卡一区二区三区高清视频| 精品夜夜嗨av一区二区三区| 成人免费高清在线| 91极品视觉盛宴| 欧美一区二区三区四区高清| 久久久久高清精品| 亚洲欧美国产毛片在线| 婷婷激情综合网| 国产成人av自拍| 欧美亚洲一区二区在线| 日韩美女天天操| 亚洲啪啪综合av一区二区三区| 亚洲狠狠爱一区二区三区| 国模套图日韩精品一区二区| 播五月开心婷婷综合| 欧美人狂配大交3d怪物一区 | 99久久婷婷国产精品综合| 欧美亚洲动漫精品| 欧美v国产在线一区二区三区| 亚洲国产高清不卡| 偷窥少妇高潮呻吟av久久免费| 国产精品18久久久久久久久| 在线精品视频小说1| 欧美成人三级电影在线| 一级中文字幕一区二区| 国产主播一区二区三区| 欧美吞精做爰啪啪高潮| 中文字幕一区二区三| 蜜臀久久99精品久久久画质超高清| 91老司机福利 在线| 久久久噜噜噜久久中文字幕色伊伊|