breeds two parent chromosomes into two offspring chromosomes. breeding occurs through crossover. If the crossover probability test yields true (crossover taking place), either one-point or two-point crossover is used, with equal probabilities.
Note
Compatibility with version 1.0: To enforce 100% use of one-point crossover, un-comment appropriate line in source code below
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(pikaia_class), | intent(inout) | :: | me | |||
integer, | intent(inout), | dimension(me%n*me%nd) | :: | gn1 | ||
integer, | intent(inout), | dimension(me%n*me%nd) | :: | gn2 |
subroutine cross(me,gn1,gn2) implicit none class(pikaia_class),intent(inout) :: me integer,dimension(me%n*me%nd),intent(inout) :: gn1 integer,dimension(me%n*me%nd),intent(inout) :: gn2 integer :: i, ispl, ispl2, itmp, t !Use crossover probability to decide whether a crossover occurs if (me%urand()<me%pcross) then !Compute first crossover point ispl=int(me%urand()*me%n*me%nd)+1 !Now choose between one-point and two-point crossover if (me%urand()<0.5_wp) then ispl2=me%n*me%nd else ispl2=int(me%urand()*me%n*me%nd)+1 !Un-comment following line to enforce one-point crossover !ispl2=me%n*me%nd if (ispl2<ispl) then itmp=ispl2 ispl2=ispl ispl=itmp end if end if !Swap genes from ispl to ispl2 do i=ispl,ispl2 t=gn2(i) gn2(i)=gn1(i) gn1(i)=t end do end if end subroutine cross