freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

基于遺傳算法求解背包問(wèn)題畢業(yè)論文-資料下載頁(yè)

2025-06-24 15:52本頁(yè)面
  

【正文】 sAlreadyExist(hashTable[index].Next,parentGenome[i].Fitness)。 if(NULL==pNode){ pNode = new HASHNODE。 hashTable[index].Diff++。 pNodeNext = hashTable[index].Next。 pNodeFitness = parentGenome[i].Fitness。 if(parentGenome[i].FitnesshashTable[index].maxFitness){ hashTable[index].maxFitness = parentGenome[i].Fitness。 } hashTable[index].Next = pNode。 } } index = maxFitness(hashTable)。 double CPount = hashTable[index].Count/(double)POPSIZE。 double pDiff = hashTable[index].Diff/(double)POPSIZE。 if(CPount= amp。amp。 pDiff=){ sameFlag = false。 } TraverseHashTable(hashTable)。 return sameFlag。}//賭輪選擇函數(shù)代碼段int Begin = 0。int End = 1。//計(jì)算從Begin-End位置的染色體的適應(yīng)度之和int summaryFitness(int Begin,int End){ int summaryF = 0。 if(BeginEnd){ for(int i=Begin。 iEnd 。i++){ summaryF += parentGenome[i].Fitness。 } }else{ for(int i=Begin。 iPOPSIZE 。i++){ summaryF += parentGenome[i].Fitness。 } for(i=0。 iEnd 。i++){ summaryF += parentGenome[i].Fitness。 } } return summaryF。}//賭輪選擇染色體以便于交叉操作int selectIndex(){ double randProb = 。 double crossProb = 。 int summaryBE = 0。 int summaryF = 0。 int index。 bool flag = true。 randProb = rand()%1000/。 summaryF = summaryFitness(0,POPSIZE)。 while(flag){ summaryBE = summaryFitness(Begin,End)。 crossProb = (double)summaryBE/(double)summaryF。 if(crossProbrandProb){ index = End。 Begin = End。 flag = false。 } End++。 if(EndPOPSIZE){ End = 1。 } } return index。}//排序輔助數(shù)組bool visitedFlag[POPSIZE]。//獲取當(dāng)前HASH表中的最大Fitness的索引int selectedMaxFitness(GENE *Genome){ int maxPos = 0。 for(int i=0。 iPOPSIZE 。i++){ if(!visitedFlag[i]){ maxPos = i。 i = POPSIZE。 } } for(i=0。 iPOPSIZE 。i++){ if(!visitedFlag[i]amp。amp。Genome[maxPos].FitnessGenome[i].Fitness){ maxPos = i。 } } return maxPos。}//索引排序void sortFitness(int *indexFitness,GENE *Genome){ memset(visitedFlag,false,NUMG*sizeof(bool))。 for(int i=0。 iPOPSIZE 。i++){ indexFitness[i] = selectedMaxFitness(Genome)。 visitedFlag[indexFitness[i]] = true。 }}//精英策略:保持優(yōu)秀的父染色體void keepBestParents(){ for(int i=POPSIZE*8/10。 iPOPSIZE 。i++){ parentGenome[indexPF[i]].Fitness = parentGenome[indexPF[iPOPSIZE*8/10]].Fitness。 parentGenome[indexPF[i]].Weight = parentGenome[indexPF[iPOPSIZE*8/10]].Weight。 for(int j=0。 jNUMG 。j++){ parentGenome[indexPF[i]].Gene[j] = parentGenome[indexPF[iPOPSIZE*8/10]].Gene[j]。 } }}//更新當(dāng)前的父代染色體void updateGeneration(){ keepBestParents()。 for(int i=0。 iPOPSIZE*8/10 。i++){ parentGenome[indexPF[i]].Fitness = nextGenome[indexCF[i]].Fitness。 parentGenome[indexPF[i]].Weight = nextGenome[indexCF[i]].Weight。 for(int j=0。 jNUMG 。j++){ parentGenome[indexPF[i]].Gene[j] = nextGenome[indexCF[i]].Gene[j]。 } }}//交叉操作void crossOver(){ int partPos。 sortFitness(indexPF,parentGenome)。 for(int i=0。 iPOPSIZE/2 。i++){ partPos = rand()%NUMG。 int Father = selectIndex()。 int Mother = selectIndex()。 for(int j=0。 jpartPos 。j++){ nextGenome[i].Gene[j] = parentGenome[Father].Gene[j]。 nextGenome[i+POPSIZE/2].Gene[j] = parentGenome[Mother].Gene[j]。 } for(。jNUMG。j++){ nextGenome[i].Gene[j] = parentGenome[Father].Gene[j]。 nextGenome[i+POPSIZE/2].Gene[j] = parentGenome[Mother].Gene[j]。 } calculateCapacity(nextGenome,i)。 calculateFitness(nextGenome,i)。 checkCapacity(nextGenome,i)。 calculateCapacity(nextGenome,i+POPSIZE/2)。 calculateFitness(nextGenome,i+POPSIZE/2)。 checkCapacity(nextGenome,i+POPSIZE/2)。 } sortFitness(indexCF,nextGenome)。}//變異操作void mutation(){ for(int i=0。 iPOPSIZE 。i++){ double prob = (rand()%1000)/。 if(probMP){ int partPos = rand()%NUMG。 if(nextGenome[i].Gene[partPos]==1){ nextGenome[i].Gene[partPos]=0。 nextGenome[i].Weight = Weight[partPos]。 nextGenome[i].Fitness = Value[partPos]。 }else{ if(nextGenome[i].Weight+Weight[partPos]CAPACITY){ nextGenome[i].Gene[partPos]=1。 nextGenome[i].Weight += Weight[partPos]。 nextGenome[i].Fitness += Value[partPos]。 }else{ //don39。t mutate! } } } }}//打印所有的父代染色體void printGenome(){ for(int i=0。 iPOPSIZE 。i++){ coutparentGenome[i].Weight。 coutparentGenome[i].Fitness。 for(int j=0。 jNUMG 。j++){ coutparentGenome[i].Gene[j]。 } coutendl。 }}void main(){ int nGenerations = 1000。 int nCount = 0。 bool flag = true。 int indexMaxResult = 0。 //初始化染色體種群 for(int i=0。 iPOPSIZE 。i++){ for(int j=0。 jNUMG 。j++){ if(parentGenome[i].Gene[j]==1){ parentGenome[i].Weight += Weight[j]。 parentGenome[i].Fitness += Value[j]。 } } checkCapacity(parentGenome,i)。 } //generateChromosomes()。用于隨機(jī)產(chǎn)生染色體 //generatePopulation()。//用于隨機(jī)產(chǎn)生種群 printGenome()。 flag = checkFitness()。 coutnCountendl。 while(flagamp。amp。nCountnGenerations){ nCount++。 //當(dāng)前循環(huán)次數(shù) crossOver()。 //交叉 mutation()。 //變異 updateGeneration()。 //更新種群 printGenome()。 //打印種群中染色體 flag = checkFitness()。//產(chǎn)看是否滿足SIM coutnCountendl。 } coutnCountendl。 indexMaxResult = maxFitness(hashTable)。//所得的01背包問(wèn)題的最大值 if(nCountnGenerations){//成功 coutThe maxValue is hashTable[indexMaxResult].maxFitnessendl。 coutThe information in Genome is as below:endl。 printGenome()。 }else{//失敗 coutOH,Sorry!。 coutThe maxValue may be hashTable[indexMaxResult].maxFitnessendl。 coutThe information in Genome is as below:endl。 printGenome()。 }}
點(diǎn)擊復(fù)制文檔內(nèi)容
環(huán)評(píng)公示相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1