資源簡介
PMX算法,部分匹配交叉算法.
代碼片段和文件信息
function?[newVanewVb]=PMX(VaVb)?
????startXorPoint=mod(ceil(rand(1)*10)length(Va)?);?
????if?startXorPoint==0?
????????startXorPoint=startXorPoint+1;?
????end????
????xorLength=mod(floor(rand(1)*10)length(Va));?
????endXorPoint=startXorPoint+xorLength;?
????while(endXorPoint>length(Vb)?)?
????????xorLength=mod(floor(rand(1)*10)length(Va));?
????????endXorPoint=startXorPoint+xorLength;?
????end????
????tempa=Va(startXorPoint:endXorPoint);?
????tempb=Vb(startXorPoint:endXorPoint);?
????%找出映射關系
????for?ix=1:length(tempa)?
????????aMappingb(ix1:2)=[Va(startXorPoint+ix-1)Vb(startXorPoint+ix-1)];
????end
????for?ix=1:length(tempa)?
????????bMappinga(ix1:2)=[Vb(startXorPoint+ix-1)Va(startXorPoint+ix-1)];
????end
????%交換子串
????Va(startXorPoint:endXorPoint)=tempb;?
????Vb(startXorPoint:endXorPoint)=tempa;?
????
????%對Va進行沖突檢測
????indexVa?=?1;
????while(indexVa ????????singleGene?=??Va(indexVa);
????????while(?ismember(singleGenetempb)?==?1?)
????????????conflictIndex?=?find(tempb==singleGene);
????????????singleGene?=?bMappinga(conflictIndex2);
????????end
????????V
- 上一篇:矩陣的QR分解基于施密特正交化
- 下一篇:能量算子解調(diào)程序
評論
共有 條評論