cross Subroutine

private subroutine cross(me, gn1, gn2)

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 Bound

pikaia_class

Arguments

Type IntentOptional 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

Calls

proc~~cross~~CallsGraph proc~cross pikaia_class%cross proc~urand pikaia_class%urand proc~cross->proc~urand proc~genrand64_real1 mt19937%genrand64_real1 proc~urand->proc~genrand64_real1 proc~genrand64_int64 mt19937%genrand64_int64 proc~genrand64_real1->proc~genrand64_int64 proc~init_genrand64 mt19937%init_genrand64 proc~genrand64_int64->proc~init_genrand64

Called by

proc~~cross~~CalledByGraph proc~cross pikaia_class%cross proc~pikaia pikaia_class%pikaia proc~pikaia->proc~cross proc~solve_with_pikaia pikaia_class%solve_with_pikaia proc~solve_with_pikaia->proc~pikaia program~test_algen test_algen program~test_algen->proc~solve_with_pikaia

Source Code

    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