⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oxcrossover.m

📁 基于信息熵的免疫算法是一种修正的免疫算法
💻 M
字号:
function [childpath1,childpath2]=OXCrossover(parent1,parent2,Pc)
%顺序交叉,OX
col=length(parent1);
childpath1=parent1;
childpath2=parent2;
tempP=rand(1);
if(tempP<Pc)
    point=randperm(col)-1;
    point1=min(point(1),point(2));
    point2=max(point(1),point(2));
    temppath1=parent1(point1+1:point2);
    temppath2=parent2(point1+1:point2);
    tempparent1=parent1;
    tempparent2=parent2;
    for j=point1+1:point2
        [rowindex,colindex]=find(parent2(j)==parent1);
        tempparent1(colindex)=0;
        [rowindex,colindex]=find(parent1(j)==parent2);
        tempparent2(colindex)=0;
    end
    parent1=tempparent1;
    parent2=tempparent2;
    temppath=parent1;
    while(parent1(point1+1)~=0)
        for j=1:col-1
            temppath(j)=parent1(j+1);
        end
        temppath(col)=parent1(1);
        parent1=temppath;
     end
     temppath=parent2;
     while(parent2(point1+1)~=0)
         for j=1:col-1
             temppath(j)=parent2(j+1);
         end
         temppath(col)=parent2(1);
         parent2=temppath;
        end
        
     
     for j=1:length(find(0==parent1))
         [rowindex,colindex]=find(0==parent1);
         parent1(colindex(1))=[];
     end
     for j=1:length(find(0==parent2))
         [rowindex,colindex]=find(0==parent2);
         parent2(colindex(1))=[];
     end
     if(point1>0)
         childpath1(1:point1)=parent1(1:point1);
         childpath2(1:point1)=parent2(1:point1);
     end
     childpath1(point1+1:point2)=temppath2;
     
     childpath2(point1+1:point2)=temppath1;
         
     if(point2<col)
        childpath1(point2+1:col)=parent1(point1+1:col-(point2-point1));
        childpath2(point2+1:col)=parent2(point1+1:col-(point2-point1));
    end
end






        
            
        
        
        
        
                
            
            
                
            
        
        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -