java循环交叉,Java中的统一交叉

I am having trouble implementing a uniform crossover in java. This is the algorithm;

// Uniform Crossover

public void UniformCrossover(Individual indi) {

if (RVGA.rand.nextDouble() 

// Put your implementation of uniform crossover here

// For each gene create a random number in   [0,   1].

// If the number is less than   0.5, swap the gene values in

// the parents for this gene; other wise, no swapping .

}

I know I can int tmp and store random number, then if tmp < 0.5 continue with loop

I couldn't manage to make a start any help is appreciated!

This is an example of my one point Crossover just so you know my format.

One point crossover - crossover point is selected, binary string from beginning of chromosome to the crossover point is copied from one parent, the rest is copied from the second parent.

Parent 1 = chromosome and Parent 2 = indi.

I am turning the parents into children inplace

public void onePointCrossover(Individual indi) {

if (SGA.rand.nextDouble() < pc) {

int xoverpoint = SGA.rand.nextInt(length);

int tmp;

for (int i=xoverpoint; i

tmp = chromosome[i];

chromosome[i] = indi.chromosome[i];

indi.chromosome[i] = tmp;

}

}

}

解决方案

With uniform crossover, what you want to do in general is:

For each gene

if rand()<0.5

take from parent a

else

take from parent b

You seem, from your one-point example, to be modifying both parents in-place at the same time. In which case:

For each gene

if rand()<0.5

leave both parents alone

else

swap chromosome[i] with indi.chromosome[i] as before

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值