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

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

?? gatsp.cpp

?? 《游戲編程中的人工智能技術(shù)》一書中4
?? CPP
?? 第 1 頁(yè) / 共 3 頁(yè)
字號(hào):
	if ( (RandFloat() > m_dCrossoverRate) || (mum == dad)) 
	{
    //make sure baby1 and baby2 are assigned some cities first!
    baby1 = mum;
    baby2 = dad;
    
		return;
	}

  //initialize the babies with minus values so we can tell which positions
  //have been filled later in the algorithm
  baby1.assign(mum.size(), -1);
  baby2.assign(mum.size(), -1);

  int l = baby2.size();

  //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);

    //next city
    Pos += RandInt(1, mum.size()-Pos);
  }
  
  //now we have chosen some cities it's time to copy the selected cities
  //over into the offspring in the same position.
  for (int pos=0; pos<positions.size(); ++pos)
  {
    //baby1 receives from mum
    baby1[positions[pos]] = mum[positions[pos]];

    //baby2 receives from dad
    baby2[positions[pos]] = dad[positions[pos]];
  }

  //fill in the blanks. First create two position markers so we know
  //whereabouts we are in baby1 and baby2
  int c1 = 0, c2 = 0;

  for (pos=0; pos<mum.size(); ++pos)
  {   
    //advance position marker until we reach a free position
    //in baby2
    while( (baby2[c2] > -1) && (c2 < mum.size()))
    {
      ++c2;
    }
    
    //baby2 gets the next city from mum which is not already
    //present
    if ( (!TestNumber(baby2, mum[pos])) )
    {
      baby2[c2] = mum[pos]; 
    }

    //now do the same for baby1
    while((baby1[c1] > -1) && (c1 < mum.size()))
    {      
      ++c1;
    }
    
    //baby1 gets the next city from dad which is not already
    //present
    if ( (!TestNumber(baby1, dad[pos])) )
    {
      baby1[c1] = dad[pos];
    }     
  }
}
//--------------------- Crossover ----------------------------------------
//
//  simple switch statement to perform crossover based on the selected
//  CrossoverType, type
//------------------------------------------------------------------------
void CgaTSP::Crossover(const vector<int>	&mum, 
							         const vector<int>	&dad, 
							         vector<int>        &baby1, 
							         vector<int>        &baby2,
                       CrossoverType      type)
{
  //perform crossover based on type
  switch(type)
  {
  case OBX:

    CrossoverOBX(mum, dad, baby1, baby2);

    break;

  case PMX:

    CrossoverPMX(mum, dad, baby1, baby2);

    break;

  case PBX:

    CrossoverPBX(mum, dad, baby1, baby2);

    break;


  default: break;

  }//end switch
}

//-----------------------CreateStartingPopulation()------------------------
//
//	clears any existing population, fills a vector with a random population
//	of genomes and resets appropriate member variables
//-------------------------------------------------------------------------
void CgaTSP::CreateStartingPopulation()
{
	//make sure the vector of genomes is empty before we
	//start
	m_vecPopulation.clear();
	
	//create a new population of random genomes
	for (int i=0; i<m_iPopSize; ++i)
	{
		m_vecPopulation.push_back(SGenome(m_iChromoLength));
	}

	//make sure variables are initialised correctly
	m_iGeneration	        = 0;
	m_dShortestRoute      = 9999999;
	m_dBestFitness	      = 0;
	m_dWorstFitness       = 9999999;
	m_dAverageFitness     = 0;
	m_iFittestGenome      = 0;
	m_bStarted			      = false;
  m_dBoltzmannTemp      = NUM_CITIES * 2;

}
//-----------------------------------Run-----------------------------------
//
//	This is the function that initializes a new population and sets the
//  ga running 
//------------------------------------------------------------------------
void CgaTSP::Run(HWND hwnd)
{
	//The first thing we have to do is create a random population
	//of genomes
	CreateStartingPopulation();

	m_bStarted = true;

}
//-------------------------Reset()------------------------------
//
//	resets all the relevant variables ready for a new generation
//--------------------------------------------------------------
void CgaTSP::Reset()
{
	//just make the shortest route some excessively large distance
	m_dShortestRoute	= 999999999;
	m_dLongestRoute		= 0;
	m_dTotalFitness		= 0;
	m_dBestFitness		= 0;
	m_dWorstFitness		= 9999999;
	m_dAverageFitness	= 0;
	m_bSorted			    = false;
  m_dSigma          = 1;
}

//------------------------Epoch-------------------------------
//
//	creates a new population of genomes using the selection,
//	mutation and crossover operators
//------------------------------------------------------------
void CgaTSP::Epoch()
{

	//first we reset variables and calculate the fitness of each genome
	Reset();
	
	CalculatePopulationsFitness();

	//if we have found a solution exit
	if ((m_dShortestRoute <= m_pMap->BestPossibleRoute()))
	{
		m_bStarted = false;
		
		return;
	}	

  //perform the appropriate fitness scaling
  FitnessScaleSwitch();

  //if sigma is zero (either set in sigma scaling or in CalculateBestWorstAv
  //then the population are identical and we should stop the run
  if (m_dSigma == 0)
  {
    m_bStarted = false;

    return;
  }
	
	//create a temporary vector for the new population
	vector<SGenome> vecNewPop;
	
  if (m_bElitism)
  {
	  //Now to add a little elitism we shall add in some copies of the
	  //fittest genomes
	  const int CopiesToAdd = 2;
	  const int NBest		  = 4;
	  
	  //make sure we add an EVEN number or the roulette wheel
	  //sampling will crash
	  if (!(CopiesToAdd * NBest % 2))
	  {
		  GrabNBest(NBest, CopiesToAdd, vecNewPop);
	  }
  }

  //SUS selection selects the entire population all at once so we have to
  //handle the epoch slightly differently if SUS is chosen
  if(m_SelectionType != SUS)
  {
	  //now create the remainder of the population
	  while (vecNewPop.size() != m_iPopSize)
	  {
	  
		  SGenome mum, dad;
    
      //switch on selection method
      switch(m_SelectionType)
      {
      case ROULETTE:
  
        //grab two parents dependent on the selection method
		    mum = RouletteWheelSelection();
		    dad = RouletteWheelSelection();

        break;

      case TOURNAMENT:

        mum = TournamentSelection(NUM_TO_COMPARE);
	      dad = TournamentSelection(NUM_TO_COMPARE);

        break;

      case ALT_TOURNAMENT:
 
        mum = AlternativeTournamentSelection();
	      dad = AlternativeTournamentSelection();

        break;
      }

		  //create 2 children
		  SGenome baby1, baby2;
		  
		  //Breed them
      Crossover(mum.vecCities,
                dad.vecCities,
                baby1.vecCities,
                baby2.vecCities,
                m_CrossoverType);

		  //and mutate them
		  Mutate(baby1.vecCities, m_MutationType);
		  Mutate(baby2.vecCities, m_MutationType);

		  //add them to new population
		  vecNewPop.push_back(baby1);
		  vecNewPop.push_back(baby2);
	  }
  }

  //SUS selection
  else
  {
    //select all the individuals
    vector<SGenome> vecSampledPop;

    SUSSelection(vecSampledPop);

    //step through the newly sampled population and apply crossover
    //and mutation operators
    for (int gen=0; gen<vecSampledPop.size(); gen+=2)
    {
      SGenome baby1, baby2;
      
      Crossover(vecSampledPop[gen].vecCities,
                vecSampledPop[gen+1].vecCities,
                baby1.vecCities,
                baby2.vecCities,
                m_CrossoverType);

      Mutate(baby1.vecCities, m_MutationType);
      Mutate(baby2.vecCities, m_MutationType);

      vecNewPop.push_back(baby1);
      vecNewPop.push_back(baby2);      

    }
   
  }

	//copy into next generation
	m_vecPopulation = vecNewPop;

	//increment generation counter
	++m_iGeneration;
}

//-------------------------------Render-------------------------------
//
//	This function does all the drawing and textual output. Called from
// the winproc when it receives a WM_PAINT msg
//--------------------------------------------------------------------
void CgaTSP::Render(HDC surface, int cx, int cy)const
{

		//draw all the cities
	for (int city_num = 0; city_num < m_pMap->m_vecCityCoOrds.size(); ++city_num)
	{
		int x = (int)m_pMap->m_vecCityCoOrds[city_num].x;
		int y = (int)m_pMap->m_vecCityCoOrds[city_num].y;
		
		Ellipse(surface, x-CITY_SIZE, y+CITY_SIZE, x+CITY_SIZE, y-CITY_SIZE);
	}
	
	//draw the fittest route so far
	vector<int> route = m_vecPopulation[m_iFittestGenome].vecCities;
	
	//only display the routes if we are in a run
	if (m_iGeneration != 0)
	{ 
		MoveToEx(surface, (int)m_pMap->m_vecCityCoOrds[route[0]].x, (int)m_pMap->m_vecCityCoOrds[route[0]].y, NULL);
		
		for (int i=1; i<route.size(); ++i)
		{
			int CityX = (int)m_pMap->m_vecCityCoOrds[route[i]].x;
			int CityY = (int)m_pMap->m_vecCityCoOrds[route[i]].y;
			
			LineTo(surface, CityX, CityY);
			
			//draw the numbers representing the order the cities are visited.
			//No point drawing them after about a 100 cities as the display
			//just becomes confused
			if (NUM_CITIES < 100)
			{
				string CityNumber = itos(i);
			
				TextOut(surface, CityX, CityY, CityNumber.c_str(), CityNumber.size());
			}
		}

		//now draw the line from the last city visited back to the starting point
		LineTo(surface, (int)m_pMap->m_vecCityCoOrds[route[0]].x, (int)m_pMap->m_vecCityCoOrds[route[0]].y);
	}	
	
	//print stats
	string sGen = itos(m_iGeneration);
	sGen = "Generation: " + sGen;
	TextOut(surface, 5, cy - 20, sGen.c_str(), sGen.size());


	if (!m_bStarted)
	{
		string Start = "Press Return to start a new run";

		TextOut(surface, cx/2 - (Start.size() * 3), cy - 20, Start.c_str(), Start.size());

    if (m_dSigma == 0)
    {
      string s = "Premature Convergence!";

      TextOut(surface, cx-40 - (Start.size() * 3), cy-20, s.c_str(), s.size());
    }
	}

	else

	{
		string Start = "Space to stop";
		
		TextOut(surface, cx/2 - (Start.size() * 3), cy - 20, Start.c_str(), Start.size());
	}	

 

  //render the current Boltzmann temperature if applicable
  if (m_ScaleType == BOLTZMANN)
  {
    string s = "Boltzmann Temp: " + ftos(m_dBoltzmannTemp);
    TextOut(surface, 400, 5, s.c_str(), s.size());
  }
    
}


?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91精品办公室少妇高潮对白| 蜜桃久久av一区| 亚洲成a人v欧美综合天堂下载| 日韩av一区二| 丁香啪啪综合成人亚洲小说| 色欧美日韩亚洲| 日韩一区二区三区精品视频| 中文字幕第一区综合| 夜夜精品视频一区二区| 另类欧美日韩国产在线| 9人人澡人人爽人人精品| 欧美人妇做爰xxxⅹ性高电影 | 亚洲自拍偷拍图区| 天天av天天翘天天综合网 | 国产日韩欧美精品一区| 亚洲综合在线第一页| 韩国成人精品a∨在线观看| 一本色道久久综合亚洲aⅴ蜜桃 | 91婷婷韩国欧美一区二区| 欧美人妇做爰xxxⅹ性高电影 | 成人午夜伦理影院| 欧美精品久久久久久久多人混战 | 成人三级在线视频| 欧美一区二区三区精品| 亚洲欧美激情小说另类| 国产一区二区主播在线| 欧美日韩免费观看一区三区| 国产午夜亚洲精品羞羞网站| 无码av免费一区二区三区试看| 国产成人在线看| 91精品国产综合久久久久久久| 亚洲欧洲av一区二区三区久久| 激情五月婷婷综合| 欧美日韩不卡一区| 亚洲欧美中日韩| 国产剧情av麻豆香蕉精品| 欧美日韩国产高清一区二区三区 | 波多野结衣中文字幕一区 | 国产精品亚洲综合一区在线观看| 欧美日韩一区 二区 三区 久久精品| 国产午夜精品理论片a级大结局| 视频一区中文字幕| 91成人国产精品| 国产精品久久久久久福利一牛影视| 日韩不卡一区二区三区| 99精品国产99久久久久久白柏| 精品国产电影一区二区| 婷婷国产v国产偷v亚洲高清| 在线日韩av片| 亚洲欧美影音先锋| 国产成人av自拍| 精品国产露脸精彩对白| 美日韩黄色大片| 91麻豆精品国产91久久久久| 夜色激情一区二区| 色婷婷综合久久久| 国产在线不卡视频| 欧美一区二区三区精品| 天天色综合天天| 欧美日韩免费一区二区三区视频 | 欧美高清视频不卡网| 亚洲国产一二三| 日本久久一区二区三区| 国产精品成人免费| 豆国产96在线|亚洲| 国产日韩一级二级三级| 国产精品资源站在线| 日韩欧美一区电影| 看国产成人h片视频| 日韩一卡二卡三卡四卡| 日本不卡一二三| 日韩欧美一区中文| 日本免费新一区视频| 91精品啪在线观看国产60岁| 日韩成人一区二区三区在线观看| 欧美精品在线观看一区二区| 无码av免费一区二区三区试看| 7799精品视频| 另类小说视频一区二区| 欧美精品一区二区三区久久久| 国产一区二区三区香蕉| 久久久久久97三级| 成人免费电影视频| 亚洲女同一区二区| 欧美日韩精品欧美日韩精品| 日韩精品一区第一页| 3d成人h动漫网站入口| 蜜臀av性久久久久蜜臀av麻豆| 26uuu国产电影一区二区| 国产精品亚洲第一| 国产精品国产三级国产三级人妇| 91美女片黄在线| 亚洲福利视频一区二区| 日韩欧美高清一区| 国产成人免费网站| 亚洲激情自拍偷拍| 6080国产精品一区二区| 免费成人结看片| 久久人人超碰精品| 91一区二区三区在线播放| 亚洲国产一区二区三区| 日韩欧美一区二区久久婷婷| 成人性视频网站| 亚洲一区二区三区四区在线| 欧美大胆一级视频| www.视频一区| 95精品视频在线| 欧美aaa在线| 国产精品蜜臀av| 精品污污网站免费看| 精品一区二区三区免费| 中文字幕亚洲区| 欧美一区二区啪啪| 丁香一区二区三区| 亚洲成av人综合在线观看| 精品日韩欧美在线| 色综合久久中文字幕综合网| 老司机免费视频一区二区| 中文字幕一区二区三区四区不卡| 欧美裸体一区二区三区| 丁香另类激情小说| 丝袜亚洲另类欧美| 国产精品国产精品国产专区不蜜 | 青椒成人免费视频| 久久久精品国产免大香伊| 色94色欧美sute亚洲线路二| 韩国精品在线观看| 夜夜操天天操亚洲| 国产欧美一区视频| 欧美一区二区三区在线电影| 91小宝寻花一区二区三区| 精品一区二区av| 亚洲第一主播视频| 国产精品久久久久精k8| 欧美va在线播放| 欧美系列日韩一区| 成人精品gif动图一区| 理论片日本一区| 亚洲高清在线精品| 综合在线观看色| 久久久久国色av免费看影院| 欧美精品v日韩精品v韩国精品v| 99精品一区二区| 国产电影一区在线| 美国三级日本三级久久99| 亚洲精品国产成人久久av盗摄| 久久久激情视频| 日韩久久免费av| 欧美日韩电影在线播放| 一本色道久久加勒比精品| 国产999精品久久久久久 | 久久女同性恋中文字幕| 欧美男男青年gay1069videost| 91丨九色丨国产丨porny| 欧美日韩www| 欧美在线免费观看亚洲| 成人av动漫网站| 国产盗摄一区二区三区| 久久99精品久久只有精品| 无码av中文一区二区三区桃花岛| 一区二区三区 在线观看视频| 国产精品免费观看视频| 国产片一区二区| 国产亚洲短视频| 国产亚洲制服色| 久久久精品国产免费观看同学| 欧美精品一区在线观看| 日韩一级黄色大片| 欧美一区日韩一区| 91精品国产综合久久香蕉的特点| 欧美三级午夜理伦三级中视频| 色综合久久99| 91精品办公室少妇高潮对白| 日本精品视频一区二区三区| 色猫猫国产区一区二在线视频| 色综合久久99| 欧美在线制服丝袜| 欧美私人免费视频| 欧美日韩精品专区| 欧美日韩国产影片| 9191久久久久久久久久久| 51精品秘密在线观看| 欧美一区二区三区免费观看视频 | 国产精品一区二区在线播放| 国产真实乱对白精彩久久| 狠狠色狠狠色合久久伊人| 久久精品国产网站| 国产一区二区剧情av在线| 国产精品一二二区| kk眼镜猥琐国模调教系列一区二区 | 欧美日韩国产精品成人| 91麻豆精品国产91久久久使用方法| 91精品婷婷国产综合久久 | 国产69精品久久99不卡| 成人免费看视频| 日本乱人伦一区| 欧美军同video69gay| 日韩午夜av电影| 国产欧美久久久精品影院| 一区二区中文字幕在线|