V3FIT
ga_niche.f
1  SUBROUTINE ga_niche(myid)
2 c#######################################################################
3 c
4 c Implement "niching" through Goldberg''s multidimensional phenotypic
5 c sharing scheme with a triangular sharing FUNCTION. To find the
6 c multidimensional distance from the best individual, normalize ALL
7 c PARAMETER differences.
8 c
9  USE ga_mod
10  USE mpi_params, ONLY: master
11  IMPLICIT NONE
12  REAL(rprec) :: alpha, del, del2, sigshar, SUMshar, share
13  INTEGER :: nniche, jj, ii, j, k, myid
14  SAVE
15 c
16 c Variable definitions:
17 c
18 c alpha = power law exponent for sharing function; typically = 1.0
19 c del = normalized multidimensional distance between ii and ALL
20 c other members of the population
21 c (equals the square root of del2)
22 c del2 = sum of the squares of the normalized multidimensional
23 c distance between member ii and all other members of
24 c the population
25 c nniche = number of niched parameters
26 c sigshar = normalized distance to be compared with del; in some sense,
27 c 1/sigshar can be viewed as the number of regions over which
28 c the sharing function should focus, e.g. with sigshar=0.1,
29 c the sharing function will try to clump in ten distinct
30 c regions of the phase space. a value of sigshar on the
31 c order of 0.1 seems to work best.
32 c share = sharing function between individual ii and j
33 c sumshar = sum of the sharing functions for individual ii
34 c
35  alpha=1
36  sigshar=0.1_dp
37  nniche=0
38  DO 33 jj=1,nparam
39  nniche=nniche+nichflg(jj)
40  33 CONTINUE
41  IF (nniche.eq.0) THEN
42  IF (myid .eq. master) THEN
43  WRITE(6,1900)
44  WRITE(iunit_ga_out,1900)
45  CLOSE(iunit_ga_out)
46  END IF
47  stop
48  END IF
49  DO 34 ii=1,npopsiz
50  sumshar=0
51  DO 35 j=1,npopsiz
52  del2=0
53  DO 36 k=1,nparam
54  IF (nichflg(k).ne.0) THEN
55  del2=del2+((parent(k,j)-parent(k,ii))/pardel(k))**2
56  END IF
57  36 CONTINUE
58  del=sqrt(del2)/nniche
59  IF (del.lt.sigshar) THEN
60 c share=1.0-((del/sigshar)**alpha)
61  share=1-(del/sigshar)
62  ELSE
63  share=0
64  END IF
65  sumshar=sumshar+share/npopsiz
66  35 CONTINUE
67  IF (sumshar.ne.0.0_dp) fitness(ii)=fitness(ii)/sumshar
68  34 CONTINUE
69 
70  1900 FORMAT(1x,'ERROR: iniche=1 and ALL values in nichflg array = 0'/
71  1 1x,' Do you want to niche or not?')
72 
73  END SUBROUTINE ga_niche