簡體   English   中英

在遺傳算法中永遠不會達到 100%

[英]never reach 100% in Genetic algorithm

我的主程序,我認為那是正確的,誰能告訴我我的錯誤在哪里,我從來沒有得到 100% 的健康

我很沮喪,如果你知道,請回答我

void mutate(population *parent,int ratio){

for(unsigned int i=0; i<sizeof(parent[0].gen); i++){
    int condition = (rand()%11);
    int temp0 = (int)parent[0].gen[i];
    int temp1 = (int)parent[1].gen[i];

    if(condition < ratio){
        if(temp0+10 <127 ){
            parent[0].gen[i] = char(temp0 + 10);
            //cout<<temp0<<endl;
        }else{
            temp0 = temp0 + 10 - 80;
            parent[0].gen[i] = char(temp0);
           // cout<<(int)parent[0].gen[i]<<endl;
        }

        if(temp1+10 <127 ){
            parent[1].gen[i] = char(temp1 + 10);
            //cout<<temp0<<endl;
        }else{
            temp1 = temp1 + 10 - 80;
            parent[1].gen[i] = char(temp1);
        }
    }
}

這是我的突變示例代碼,下圖中的完整程序

遺傳算法_1遺傳算法_1

從您的問題中不清楚您正在解決什么樣的問題,但很可能是 NP 完備性,其他類型的問題可以在沒有機器學習的情況下更有效地解決。 但是你必須明白, NP 完備性問題的精確解需要窮舉所有可能的解 機器學習無法避免這個問題,因此實現 100% 准確率並不比基於 brutfors 的方法更容易。 機器學習,特別是遺傳算法的目標是在可接受的時間內找到可接受的解決方案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM