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

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

?? cgabob.cpp

?? 在WINDOWS環(huán)境下用C語言開發(fā)的尋路程序
?? CPP
字號:
#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
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美理论电影在线| 美女视频网站久久| 91网页版在线| 亚洲免费视频中文字幕| 日本丶国产丶欧美色综合| 亚洲色图在线播放| 欧美这里有精品| 天堂一区二区在线| 日韩欧美激情在线| 高清在线观看日韩| 亚洲欧洲制服丝袜| 欧美美女一区二区在线观看| 日韩电影在线观看网站| 久久久蜜桃精品| av日韩在线网站| 亚洲成人在线网站| 久久综合视频网| 日本久久精品电影| 麻豆国产精品官网| 国产精品麻豆视频| 欧美日韩高清一区| 麻豆精品在线看| 国产精品国产自产拍高清av王其| 一本大道久久a久久综合婷婷| 五月天中文字幕一区二区| 久久久久国产精品人| 在线一区二区视频| 九九热在线视频观看这里只有精品| 国产欧美日韩精品在线| 欧美日产国产精品| 国产精品一品二品| 亚洲午夜在线视频| 国产午夜亚洲精品午夜鲁丝片| 欧美亚洲综合色| 国产盗摄精品一区二区三区在线| 亚洲色图清纯唯美| 精品处破学生在线二十三| 91官网在线免费观看| 国产一本一道久久香蕉| 视频在线观看一区| 亚洲日本在线a| 精品福利一区二区三区免费视频| 色婷婷av一区| 国产成人精品综合在线观看 | 91亚洲永久精品| 中文字幕免费观看一区| 成人国产电影网| 国产三级一区二区| 欧美三级欧美一级| 成人丝袜高跟foot| 精品午夜一区二区三区在线观看| 亚洲免费在线视频| 国产精品欧美经典| 久久久久久日产精品| 91精品婷婷国产综合久久竹菊| av一二三不卡影片| 国产成人在线电影| 激情偷乱视频一区二区三区| 亚洲18影院在线观看| 亚洲美女偷拍久久| 国产精品乱码妇女bbbb| 欧美成人伊人久久综合网| 欧美三级乱人伦电影| 99精品欧美一区二区三区小说 | 久久99久国产精品黄毛片色诱| 亚洲另类中文字| 在线观看91av| 9人人澡人人爽人人精品| 一区二区三区.www| 韩国v欧美v日本v亚洲v| 日日夜夜精品视频天天综合网| 亚洲色图都市小说| 综合久久一区二区三区| 国产精品沙发午睡系列990531| 337p日本欧洲亚洲大胆精品 | 亚洲色图一区二区三区| 国产精品久久久久久户外露出| 亚洲国产精品精华液ab| 中文字幕不卡三区| 中文字幕一区二区三区视频| 国产精品伦理一区二区| 日韩毛片视频在线看| 国产精品电影一区二区| 亚洲欧美日韩综合aⅴ视频| 亚洲人成精品久久久久| 亚洲欧美经典视频| 亚洲主播在线观看| 国产成人在线网站| 九色综合国产一区二区三区| 久久午夜国产精品| 91麻豆精品国产综合久久久久久| 欧美日韩免费视频| 日韩一级免费观看| 337p日本欧洲亚洲大胆精品| 久久精品人人做人人爽人人| 欧美激情综合五月色丁香小说| 国产精品午夜久久| 一区二区三区免费看视频| 亚洲国产成人91porn| 麻豆精品国产传媒mv男同| 国产精品一区二区久久不卡| 不卡视频一二三四| 欧美色手机在线观看| 欧美一卡二卡三卡四卡| 国产午夜一区二区三区| 樱花草国产18久久久久| 秋霞影院一区二区| 成人丝袜视频网| 欧美日韩1234| 国产精品视频观看| 亚洲国产视频a| 国产在线一区二区| 91福利视频网站| 欧美电影精品一区二区| 国产精品九色蝌蚪自拍| 视频一区二区国产| 成人av电影免费观看| 91.成人天堂一区| 国产精品每日更新| 日本一不卡视频| 99re这里只有精品视频首页| 制服丝袜亚洲精品中文字幕| 欧美国产一区二区| 免费在线成人网| 91理论电影在线观看| 精品国产91亚洲一区二区三区婷婷| 国产精品久久久久四虎| 日本亚洲三级在线| 91麻豆精东视频| 久久久不卡网国产精品一区| 亚洲一区二区三区免费视频| 欧美日韩国产经典色站一区二区三区| 日韩欧美一级精品久久| 一区二区三区四区在线| 国产夫妻精品视频| 日韩写真欧美这视频| 亚洲黄色av一区| jiyouzz国产精品久久| 欧美岛国在线观看| 亚洲3atv精品一区二区三区| av成人免费在线| 久久久久久97三级| 久久99精品一区二区三区三区| 欧美在线一区二区| 亚洲人成影院在线观看| 国产成人午夜精品5599| 精品捆绑美女sm三区| 日韩和欧美一区二区三区| 91成人免费电影| 中文字幕日韩av资源站| 懂色av一区二区三区免费观看| 欧美一级日韩不卡播放免费| 亚洲一区二区三区在线看| 不卡的av在线播放| 国产精品午夜春色av| 国产激情精品久久久第一区二区| 日韩丝袜美女视频| 午夜欧美在线一二页| 欧美色大人视频| 亚洲一区免费观看| 色哟哟一区二区| 一区二区三区日韩欧美| 色偷偷久久一区二区三区| 国产精品欧美一级免费| www.亚洲激情.com| 18欧美亚洲精品| 91丨porny丨户外露出| 亚洲少妇中出一区| 91麻豆免费看| 亚洲午夜久久久久中文字幕久| 色综合久久88色综合天天免费| 亚洲欧美日韩中文字幕一区二区三区| www.久久久久久久久| 国产精品白丝在线| 色综合天天视频在线观看| 一区二区在线观看视频| 欧美性受xxxx| 日本女人一区二区三区| 精品国产免费一区二区三区香蕉| 久久精品72免费观看| 国产午夜亚洲精品午夜鲁丝片| 大桥未久av一区二区三区中文| 亚洲欧洲日韩综合一区二区| 一本到一区二区三区| 性做久久久久久免费观看| 欧美一级爆毛片| 粉嫩一区二区三区性色av| 亚洲男人的天堂在线aⅴ视频| 欧美探花视频资源| 蜜臀久久99精品久久久画质超高清| 欧美日韩一区二区三区免费看| 91女厕偷拍女厕偷拍高清| 色伊人久久综合中文字幕| 99视频一区二区三区| 成人午夜免费av| 蜜桃视频一区二区| 精品国产露脸精彩对白| 不卡av电影在线播放| 亚洲成人自拍一区| 欧美大片拔萝卜|