File: maxbit.f

package info (click to toggle)
pgapack 1.1.1-3
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 2,556 kB
  • ctags: 1,829
  • sloc: ansic: 10,331; fortran: 2,985; sh: 503; makefile: 466; perl: 105
file content (55 lines) | stat: -rw-r--r-- 1,211 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
c     
c     This is a test program for PGAPack.  The objective is to maximize the
c     number of 1-bits in a chromosome.
c     

      include 'pgapackf.h'

      double precision NumberOfSetBits
      external         NumberOfSetBits
      
c     
c     user main program
c     
      integer ctx
      integer       ierror

      call MPI_Init(ierror)

      ctx = PGACreate(PGA_DATATYPE_BINARY, 256, PGA_MAXIMIZE)
      call PGASetRandomSeed(ctx, 1)

      call PGASetUp(ctx)
      call PGARun(ctx, NumberOfSetBits)
      call PGADestroy(ctx)

      call MPI_Finalize(ierror)

      stop
      end


c     
c     user defined evaluation function
c     ctx - contex variable
c     p   - chromosome index in population
c     pop - which population to refer to
c     
      double precision function NumberOfSetBits(ctx, p, pop) 
      include    'pgapackf.h'
      integer ctx
      integer     p, pop
      integer     i, nbits, stringlen

      stringlen = PGAGetStringLength(ctx)
      
      nbits = 0
      do i=1, stringlen
         if (PGAGetBinaryAllele(ctx, p, pop, i) .eq. 1) then
            nbits = nbits + 1
         endif
      enddo

      NumberOfSetBits = dble(nbits)
      return
      end