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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? gatsp.cpp

?? 開發游戲人工智能的王道書
?? CPP
?? 第 1 頁 / 共 3 頁
字號:
  for (int i=0; i<N; ++i)
  {
    int ThisTry = RandInt(0, m_iPopSize-1);

    if (m_vecPopulation[ThisTry].dFitness > BestFitnessSoFar)
    {
      ChosenOne = ThisTry;

      BestFitnessSoFar = m_vecPopulation[ThisTry].dFitness;
    }
  }

  //return the champion
  return m_vecPopulation[ChosenOne];
}

//-------------------------- AlternativeTournamentSelection---------------
//
//  variation of tournament selection described in chapter 5 of the book
//------------------------------------------------------------------------
SGenome& CgaTSP::AlternativeTournamentSelection()
{
  //allocate two indexes into the population
  int g1 = RandInt(0, m_vecPopulation.size()-1);
  int g2 = RandInt(0, m_vecPopulation.size()-1);

  //make sure they are different
  while(g1 == g2)
  {
    g2 = RandInt(0, m_vecPopulation.size()-1);
  }

  //grab a random number between 0 and 1
  float Rand = RandFloat();

  //now return the chosen individual based on CTOURNAMENT
  if(Rand < CTOURNAMENT)
  {
    //return the fitter of the two
    if (m_vecPopulation[g1].dFitness > m_vecPopulation[g2].dFitness)
    {
      return m_vecPopulation[g1];
    }
    else
    {
      return m_vecPopulation[g2];
    }
  }

  else
  {
    //return the weaker
    if (m_vecPopulation[g1].dFitness < m_vecPopulation[g2].dFitness)
    {
      return m_vecPopulation[g1];
    }
    else
    {
      return m_vecPopulation[g2];
    }
  }
}

//-----------------------------ChooseSection----------------------------
//
//	given a max span size and a min span size, this will calculate a 
//  random beginning and end point within the span. Used mainly in 
//  mutation and crossover operators
//----------------------------------------------------------------------
void ChooseSection(int       &beg,
                   int       &end,
                   const int max_span,
                   const int min_span)
{
	
	beg = RandInt(0, max_span-min_span);
	
	end = beg;
	
	//find an end
	while (end <= beg)
	{
		end = RandInt(0, max_span);
	}
}
//---------------------------MutateEM-----------------------------
//
//	Mutates the chromosome by choosing two random genes and swapping
//	their position.
//-----------------------------------------------------------------
void CgaTSP::MutateEM(vector<int> &chromo)
{
	//return dependent upon mutation rate
	if (RandFloat() > m_dMutationRate) return;

	//choose first gene
	int pos1 = RandInt(0, chromo.size()-1);

	//choose second
	int pos2 = pos1;

	while (pos1 == pos2)
	{
		pos2 = RandInt(0, chromo.size()-1);
	}

	//swap their positions
	swap(chromo[pos1], chromo[pos2]);
}

//--------------------------MutateIM------------------------------
//
//	Chooses a random gene and inserts displaced back into the
//	chromosome
//-----------------------------------------------------------------
void CgaTSP::MutateIM(vector<int> &chromo)
{
	//return dependent upon mutation rate
	if (RandFloat() > m_dMutationRate) return;

	//create an iterator for us to work with
	vector<int>::iterator curPos;

	//choose a gene to move
	curPos = chromo.begin() + RandInt(0, chromo.size()-1);

	//keep a note of the genes value
	int CityNumber = *curPos;

	//remove from the chromosome
	chromo.erase(curPos);

	//move the iterator to the insertion location
	curPos = chromo.begin() + RandInt(0, chromo.size()-1);

	chromo.insert(curPos, CityNumber);
}
//------------------------MutateSM--------------------------------
//
//	chooses a random start and point then scrambles the genes 
//	between them
//----------------------------------------------------------------
void CgaTSP::MutateSM(vector<int> &chromo)
{
	//return dependent upon mutation rate
	if (RandFloat() > m_dMutationRate) return;

	//first we choose a section of the chromosome
	const int MinSpanSize = 3;

	//these will hold the beginning and end points of the span
  int beg, end;

	ChooseSection(beg, end, chromo.size()-1, MinSpanSize);

	int span = end - beg;

	//now we just swap randomly chosen genes with the beg/end
	//range a few times to scramble them
	int NumberOfSwapsRqd = span;

	while(--NumberOfSwapsRqd)
	{
		vector<int>::iterator gene1 = chromo.begin();
		vector<int>::iterator gene2 = chromo.begin();

		//choose two loci within the range
		advance(gene1, beg + RandInt(0, span));
		advance(gene2, beg + RandInt(0, span));

		//exchange them
		swap(*gene1, *gene2);
		
	}//repeat
}

//-------------------------MutateDM-------------------------------------
//
//	Select two random points, grab the chunk of chromosome between them 
//	and then insert it back into the chromosome in a random position 
//	displaced from the original.
//----------------------------------------------------------------------
void CgaTSP::MutateDM(vector<int> &chromo)
{
	//return dependent upon mutation rate
	if (RandFloat() > m_dMutationRate) return;

	//first we choose a section of the chromosome
	const int MinSpanSize = 3;
	
	//these will hold the beginning and end points of the span
  int beg, end;
	
	ChooseSection(beg, end, chromo.size()-1, MinSpanSize);

	//setup iterators for our beg/end points
	vector<int>::iterator SectionStart = chromo.begin() + beg;
	vector<int>::iterator SectionEnd   = chromo.begin() + end;

	//hold on to the section we are moving
	vector<int> TheSection;
	TheSection.assign(SectionStart, SectionEnd);

	//erase from current position
	chromo.erase(SectionStart, SectionEnd);

	//move an iterator to a random insertion location
	vector<int>::iterator curPos;
	curPos = chromo.begin() + RandInt(0, chromo.size()-1);

	//re-insert the section
	chromo.insert(curPos, TheSection.begin(), TheSection.end());
	
}

//---------------------------Mutate-----------------------------
//
//	feeds the chromo into the correct mutation function according
//	to its type
//--------------------------------------------------------------
void CgaTSP::Mutate(vector<int> &chromo, MutationType &type)
{
	switch (type)
	{
	case EM:

		MutateEM(chromo);
		
		break;

	case SM:

		MutateSM(chromo);

		break;

	case IM:

		MutateIM(chromo);
		
		break;

  case DM:

		MutateDM(chromo);
		
		break;

	default: break;
	}//end switch
}

//-------------------------CrossoverPMX---------------------------------
//
// crossover operator based on 'partially matched crossover' as 
// defined in the text
//-------------------------------------------------------------------
void CgaTSP::CrossoverPMX(	const vector<int>	&mum, 
							              const vector<int>	&dad, 
							              vector<int>			&baby1, 
							              vector<int>			&baby2)
{
	baby1 = mum;
	baby2 = dad;
	
	//just return dependent on the crossover rate or if the
	//chromosomes are the same.
	if ( (RandFloat() > m_dCrossoverRate) || (mum == dad)) 
	{
		return;
	}

	//first we choose a section of the chromosome
	int beg = RandInt(0, mum.size()-2);
	
	int end = beg;
	
	//find an end
	while (end <= beg)
	{
		end = RandInt(0, mum.size()-1);
	}

	//now we iterate through the matched pairs of genes from beg
	//to end swapping the places in each child
	vector<int>::iterator posGene1, posGene2;

	for (int pos = beg; pos < end+1; ++pos)
	{
		//these are the genes we want to swap
		int gene1 = mum[pos];
		int gene2 = dad[pos];

		if (gene1 != gene2)
		{
			//find and swap them in baby1
			posGene1 = find(baby1.begin(), baby1.end(), gene1);
			posGene2 = find(baby1.begin(), baby1.end(), gene2);

			swap(*posGene1, *posGene2);

			//and in baby2
			posGene1 = find(baby2.begin(), baby2.end(), gene1);
			posGene2 = find(baby2.begin(), baby2.end(), gene2);
			
			swap(*posGene1, *posGene2);
		}
		
	}//next pair
}	

//-------------------------CrossoverOBX---------------------------------
//
// Order Based operator as described in Chapter 5
//-------------------------------------------------------------------
void CgaTSP::CrossoverOBX(	const vector<int>	&mum, 
							              const vector<int>	&dad, 
							              vector<int>			&baby1, 
							              vector<int>			&baby2)
{
  baby1 = mum;
	baby2 = dad;
	
	//just return dependent on the crossover rate or if the
	//chromosomes are the same.
	if ( (RandFloat() > m_dCrossoverRate) || (mum == dad)) 
	{
		return;
	}
 
  //holds the chosen cities
  vector<int> tempCities;

  //holds the positions of the chosen cities
  vector<int> positions;

  //first city position
  int Pos = RandInt(0, mum.size()-2);

  //keep adding random cities until we can add no more
  //record the positions as we go
  while (Pos < mum.size())
  {
    positions.push_back(Pos);

    tempCities.push_back(mum[Pos]);

    //next city
    Pos += RandInt(1, mum.size()-Pos);
  }

  //so now we have n amount of cities from mum in the tempCities
  //vector we can impose their order in dad.
  int cPos = 0;

  for (int cit=0; cit<baby2.size(); ++cit)
  {
    for (int i=0; i<tempCities.size(); ++i)
    {
      if (baby2[cit]==tempCities[i])
      {
         baby2[cit] = tempCities[cPos];

         ++cPos;

         break;
      }
    }
  }

   //now vice versa
  tempCities.clear();
  cPos = 0;

  //first grab the cities from the same positions in dad
  for(int i=0; i<positions.size(); ++i)
  {
    tempCities.push_back(dad[positions[i]]);
  }

  //and impose their order in mum
  for (cit=0; cit<baby1.size(); ++cit)
  {
    for (int i=0; i<tempCities.size(); ++i)
    {
      if (baby1[cit]==tempCities[i])
      {
         baby1[cit] = tempCities[cPos];

         ++cPos;

         break;
      }
    }
  }    
}

//----------------------- CrossoverPBX -----------------------------------
//
//  Position Based Crossover as described in Chapter 5
//------------------------------------------------------------------------
void CgaTSP::CrossoverPBX(	const vector<int>	&mum, 
							              const vector<int>	&dad, 
							              vector<int>			&baby1, 
							              vector<int>			&baby2)
{	
	//Return dependent on the crossover rate or if the
	//chromosomes are the same.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲午夜精品在线| 悠悠色在线精品| 7777精品伊人久久久大香线蕉超级流畅| 日韩电影在线一区| 亚洲欧美区自拍先锋| 精品久久久三级丝袜| 欧美日韩国产综合视频在线观看 | 亚洲成人手机在线| 国产精品每日更新在线播放网址| 在线观看亚洲精品| 99久久99精品久久久久久| 激情久久五月天| 三级久久三级久久| 五月天一区二区| 亚洲成人激情综合网| 一区二区三区国产精品| 亚洲日本免费电影| 中文字幕一区免费在线观看| 中文字幕在线播放不卡一区| 国产免费成人在线视频| 亚洲国产精品传媒在线观看| 久久久91精品国产一区二区三区| 欧美mv日韩mv国产| 欧美国产亚洲另类动漫| 亚洲免费观看高清完整版在线 | 国产成人av电影在线观看| 成人精品视频.| 欧美艳星brazzers| 欧美精品一区二区不卡| 欧洲av一区二区嗯嗯嗯啊| 99久久综合国产精品| 波多野结衣中文一区| 91麻豆国产精品久久| 在线播放中文一区| 久久久久久久久久久电影| 国产日韩欧美精品在线| 亚洲人成小说网站色在线 | 国产精品嫩草久久久久| 亚洲精品成人少妇| 狂野欧美性猛交blacked| 国产精品一卡二卡在线观看| 色欲综合视频天天天| 日韩一区二区三区电影| 国产精品久久综合| 日本午夜一本久久久综合| 国产盗摄精品一区二区三区在线| 91农村精品一区二区在线| 欧美va亚洲va| 综合亚洲深深色噜噜狠狠网站| 免费三级欧美电影| 欧美性做爰猛烈叫床潮| 久久精品亚洲麻豆av一区二区| 午夜久久久久久久久| av中文字幕在线不卡| 精品黑人一区二区三区久久| 亚洲精品高清视频在线观看| 国产一区二区三区免费在线观看| 欧美精品99久久久**| 亚洲免费观看高清完整版在线观看熊 | 一区二区三区高清| 成人免费视频国产在线观看| 精品国产百合女同互慰| 天天综合网天天综合色 | 日韩欧美国产三级电影视频| 亚洲亚洲精品在线观看| 色吧成人激情小说| 一区二区三区视频在线观看| 成人的网站免费观看| 国产精品网曝门| 成人ar影院免费观看视频| 欧美高清在线精品一区| 丰满岳乱妇一区二区三区| 国产视频亚洲色图| av激情综合网| 亚洲一区二区三区在线| 欧美日韩视频专区在线播放| 亚洲国产精品久久艾草纯爱| 欧美日韩mp4| 国产一区二区美女诱惑| 中文字幕不卡在线| 9人人澡人人爽人人精品| 亚洲国产欧美在线| 日韩一级完整毛片| 国产高清成人在线| 天天影视涩香欲综合网 | 日韩高清欧美激情| 国产日韩精品视频一区| 在线精品视频免费播放| 免费成人av资源网| 最新日韩在线视频| 日韩欧美在线观看一区二区三区| 国产精品系列在线观看| 亚洲一区二区不卡免费| 欧美成人a∨高清免费观看| 97成人超碰视| 国产一区二区在线观看视频| 亚洲色图丝袜美腿| 欧美激情一区二区三区在线| 欧美人伦禁忌dvd放荡欲情| 国产91丝袜在线18| 奇米精品一区二区三区四区| 亚洲综合免费观看高清在线观看| 精品日韩av一区二区| 精品视频免费在线| 97成人超碰视| 99天天综合性| 成人免费毛片a| 国产精品一卡二| 国产精品亚洲成人| 国产精品香蕉一区二区三区| 理论片日本一区| 韩国一区二区三区| 国产99久久久国产精品 | 欧美性猛片aaaaaaa做受| 色综合久久中文综合久久牛| 色婷婷久久综合| 欧美日韩精品系列| 精品久久五月天| 中文字幕在线一区免费| 亚洲综合色网站| 韩国成人精品a∨在线观看| 国产大片一区二区| 欧美视频在线一区| 欧美大胆人体bbbb| 亚洲卡通欧美制服中文| 蜜臀精品一区二区三区在线观看| 成人免费毛片高清视频| 7878成人国产在线观看| 国产精品污网站| 久久精品免费观看| 日本丶国产丶欧美色综合| 精品入口麻豆88视频| 亚洲一区欧美一区| 91一区一区三区| 欧美性大战xxxxx久久久| 久久免费的精品国产v∧| 午夜精品成人在线视频| 99精品久久久久久| 中文字幕不卡在线观看| 精东粉嫩av免费一区二区三区| 欧美在线观看禁18| 亚洲色图在线看| 国产精品自拍在线| 精品日产卡一卡二卡麻豆| 日韩精品一二三| 欧美日韩国产精品成人| 91精品国产综合久久久久久 | 久久久99精品久久| 亚洲自拍都市欧美小说| 国产.欧美.日韩| 一区二区三区在线不卡| 久草精品在线观看| 91精品国产综合久久久蜜臀粉嫩| 国产精品久久久久婷婷| 美女一区二区三区| 欧美精品一二三| 亚洲最大成人网4388xx| av一区二区三区黑人| 国产区在线观看成人精品| 国产精品99精品久久免费| 欧美一区二区美女| 午夜精品123| 日韩无一区二区| 免费观看成人鲁鲁鲁鲁鲁视频| 欧美男人的天堂一二区| 一个色妞综合视频在线观看| 色哟哟国产精品| 亚洲一区二区三区在线播放| 色婷婷激情综合| 五月激情综合婷婷| 欧美日韩精品一区二区三区| 婷婷综合五月天| 日韩亚洲欧美中文三级| 日本不卡123| 久久精品一区蜜桃臀影院| 韩国女主播一区二区三区| www激情久久| 99久久精品免费看国产| 午夜不卡av在线| 精品国产免费一区二区三区香蕉| 国产精品自在在线| 亚洲欧美日韩国产成人精品影院| 91麻豆免费看| 亚洲二区在线视频| 精品乱人伦一区二区三区| 国产精品亚洲人在线观看| 亚洲天堂成人在线观看| 欧美日韩一区视频| 激情久久五月天| 亚洲欧美偷拍另类a∨色屁股| 欧美日韩一卡二卡| 国产99久久精品| 午夜视频在线观看一区二区| 精品国产制服丝袜高跟| 99久久精品情趣| 青青草97国产精品免费观看无弹窗版| 精品91自产拍在线观看一区| 97精品国产97久久久久久久久久久久| 日韩精彩视频在线观看| 国产精品久久久久永久免费观看 |