You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by da...@apache.org on 2017/05/28 18:31:51 UTC

svn commit: r1796518 [4/19] - in /spamassassin/trunk/build/pga: ./ docs/ examples/ examples/c/ examples/fortran/ examples/mgh/ examples/templates/ include/ lib/ lib/linux/ man/ man/man1/ man/man2/ man/man3/ man/man4/ man/man5/ man/man6/ man/man7/ man/m...

Added: spamassassin/trunk/build/pga/examples/Makefile
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/Makefile?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/Makefile (added)
+++ spamassassin/trunk/build/pga/examples/Makefile Sun May 28 18:31:49 2017
@@ -0,0 +1,27 @@
+# Generated automatically from Makefile.in by configure.
+FC    = f77
+RM    = /bin/rm -f
+SHELL = /bin/sh
+
+default:
+	@echo "Making C examples"
+	@make C
+	@echo "Making fortran examples"
+	@make Fortran
+
+C:
+	@cd c; make
+
+Fortran:
+	@if test -n "$(FC)" ; then\
+		cd fortran; make; cd ..;\
+		cd mgh; make;\
+	else\
+		echo "Fortran compiler unavailable";\
+	fi
+
+clean:
+	@cd c; make clean
+	@cd fortran; make clean
+	@cd mgh; make clean
+

Added: spamassassin/trunk/build/pga/examples/Makefile.in
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/Makefile.in?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/Makefile.in (added)
+++ spamassassin/trunk/build/pga/examples/Makefile.in Sun May 28 18:31:49 2017
@@ -0,0 +1,26 @@
+FC    = @FC@
+RM    = @RM@
+SHELL = @SHELL@
+
+default:
+	@echo "Making C examples"
+	@make C
+	@echo "Making fortran examples"
+	@make Fortran
+
+C:
+	@cd c; make
+
+Fortran:
+	@if test -n "$(FC)" ; then\
+		cd fortran; make; cd ..;\
+		cd mgh; make;\
+	else\
+		echo "Fortran compiler unavailable";\
+	fi
+
+clean:
+	@cd c; make clean
+	@cd fortran; make clean
+	@cd mgh; make clean
+

Added: spamassassin/trunk/build/pga/examples/README
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/README?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/README (added)
+++ spamassassin/trunk/build/pga/examples/README Sun May 28 18:31:49 2017
@@ -0,0 +1,7 @@
+This is the top-level parallel examples directory.  Under it are the
+three following directories:
+
+c         -- contains example programs in C
+fortran   -- contains example programs in FORTRAN
+mgh       -- contains the More, Garbow, and Hillstrom test suite
+templates -- contains stub routines for all the user defined routines

Added: spamassassin/trunk/build/pga/examples/c/Makefile
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/c/Makefile?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/c/Makefile (added)
+++ spamassassin/trunk/build/pga/examples/c/Makefile Sun May 28 18:31:49 2017
@@ -0,0 +1,55 @@
+# Generated automatically from Makefile.in by configure.
+CC          = cc
+PRECFLAGS   = -O 
+CPPFLAGS    = -I/usr/local/pga/include -Dlinux -DWL=32 -DFORTRANUNDERSCORE -DOPTIMIZE -DFAKE_MPI 
+FC          = f77
+RM          = /bin/rm -f
+LDFLAGS     = -s  -L/usr/local/pga/lib/linux  -lpgaO  -lm
+SHELL       = /bin/sh
+
+#    "$@" expands to the target; "$?" expands to the dependency list
+CFLAGS      = -o $@ $? $(PRECFLAGS)
+
+LINK.c      = @echo "  Compiling $@" ; $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
+
+default:
+	@make classic
+	@make dejong
+	@make example
+	@make maxbit
+	@make maxchar
+	@make maxint
+	@make name
+	@make namefull
+	@make udtstr
+
+classic: classic.c
+	$(LINK.c)
+
+dejong: dejong.c
+	$(LINK.c)
+
+example: example.c
+	$(LINK.c)
+
+maxbit: maxbit.c
+	$(LINK.c)
+
+maxchar: maxchar.c
+	$(LINK.c)
+
+maxint: maxint.c
+	$(LINK.c)
+
+name: name.c
+	$(LINK.c)
+
+namefull: namefull.c
+	$(LINK.c)
+
+udtstr: udtstr.c
+	$(LINK.c)
+
+clean: 
+	@$(RM) classic dejong example maxbit maxchar maxint name namefull \
+	       udtstr *.o

Added: spamassassin/trunk/build/pga/examples/c/Makefile.in
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/c/Makefile.in?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/c/Makefile.in (added)
+++ spamassassin/trunk/build/pga/examples/c/Makefile.in Sun May 28 18:31:49 2017
@@ -0,0 +1,54 @@
+CC          = @CC@
+PRECFLAGS   = @CFLAGS@
+CPPFLAGS    = @CPPFLAGS@
+FC          = @FC@
+RM          = @RM@
+LDFLAGS     = @LDFLAGS@
+SHELL       = @SHELL@
+
+#    "$@" expands to the target; "$?" expands to the dependency list
+CFLAGS      = -o $@ $? $(PRECFLAGS)
+
+LINK.c      = @echo "  Compiling $@" ; $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
+
+default:
+	@make classic
+	@make dejong
+	@make example
+	@make maxbit
+	@make maxchar
+	@make maxint
+	@make name
+	@make namefull
+	@make udtstr
+
+classic: classic.c
+	$(LINK.c)
+
+dejong: dejong.c
+	$(LINK.c)
+
+example: example.c
+	$(LINK.c)
+
+maxbit: maxbit.c
+	$(LINK.c)
+
+maxchar: maxchar.c
+	$(LINK.c)
+
+maxint: maxint.c
+	$(LINK.c)
+
+name: name.c
+	$(LINK.c)
+
+namefull: namefull.c
+	$(LINK.c)
+
+udtstr: udtstr.c
+	$(LINK.c)
+
+clean: 
+	@$(RM) classic dejong example maxbit maxchar maxint name namefull \
+	       udtstr *.o

Added: spamassassin/trunk/build/pga/examples/c/README
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/c/README?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/c/README (added)
+++ spamassassin/trunk/build/pga/examples/c/README Sun May 28 18:31:49 2017
@@ -0,0 +1,31 @@
+Eight example C programs come with PGAPack.  What follows is a listing 
+of the names of the programs and a brief description of their function.
+
+classic.c  -- Optimizes Griewank's, Rastrigin's or Schwefel's test function.
+              All use a real valued datatype.  The problems are:
+		1.  Griewank
+		2.  Rastrigin
+		3.  Schwefel
+
+dejong.c   -- This program optimizes one of the five functions from the DeJong
+              test suite with a binary string as the chromosome.  Graycoding is
+              an option.
+
+example.c  -- An example from the User's Guide.
+
+maxbit.c   -- A very simple example that maximizes the number of 1's in a
+              binary string.  Does no I/O.
+
+maxchar.c  -- Maximizes the number of z's in a character string.  Does I/O.
+
+maxint.c   -- Maximizes the sum of all alleles in the gene.
+
+name.c     -- Evolves a character string to match a hard-coded string.  Does
+              no I/O, but shows how to use userfunctions InitString, Mutation,
+              and Done.  Also uses an elitist model of evolution with no
+              crossover.
+
+namefull.c -- Same idea as name.c, but uses all native user defined functions.
+
+udtstr.c   -- Uses a user-defined datatype, a single structure.
+

Added: spamassassin/trunk/build/pga/examples/c/classic
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/c/classic?rev=1796518&view=auto
==============================================================================
Binary file - no diff available.

Propchange: spamassassin/trunk/build/pga/examples/c/classic
------------------------------------------------------------------------------
    svn:executable = *

Propchange: spamassassin/trunk/build/pga/examples/c/classic
------------------------------------------------------------------------------
    svn:mime-type = application/x-executable

Added: spamassassin/trunk/build/pga/examples/c/classic.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/c/classic.c?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/c/classic.c (added)
+++ spamassassin/trunk/build/pga/examples/c/classic.c Sun May 28 18:31:49 2017
@@ -0,0 +1,132 @@
+/*  Miscelaneous test functions.
+ *
+ *  Rather than deal with parallel I/O, we just list the tests here:
+ *     1.  Griewank
+ *     2.  Rastrigin
+ *     3.  Schwefel
+ *
+ */
+#include <pgapack.h>
+
+#ifndef M_PI
+#define M_PI 3.14159265354
+#endif
+
+double griewank(PGAContext *, int, int);
+double rastrigin(PGAContext *, int, int);
+double schwefel(PGAContext *, int, int);
+void   printResultInterpretation(PGAContext *, int);
+int    GetIntegerParameter(char *query);
+
+int    NumCoords[3]  = { 10, 20, 10 };
+double Lower[3]      = { -512.0, -5.12, -512.0 };
+double Upper[3]      = { 511.0, 5.11, 511.0 };
+
+/*******************************************************************
+ *                   user main program                              *
+ *******************************************************************/
+void main( int argc, char **argv ) {
+    PGAContext *ctx;     /* the context variable */
+    int testnum;         /* the DeJong test to run */
+    int maxiter;         /* the maximum number of iterations */
+    double l[20], u[20]; /* for initializing lu ranges */
+    int i;
+
+    MPI_Init(&argc, &argv); 
+
+    testnum = GetIntegerParameter("Which test? (1-Griewank, 2-Rastrigin, 3-Schwefel)\n") - 1;
+    maxiter = GetIntegerParameter("How many iterations?\n");
+
+    for (i=0; i<20; i++) {
+	l[i] = Lower[testnum];
+	u[i] = Upper[testnum];
+    }
+
+
+    ctx = PGACreate(&argc, argv, PGA_DATATYPE_REAL, 
+		    NumCoords[testnum], PGA_MINIMIZE);
+    
+    PGASetRandomSeed(ctx, 1);
+
+    PGASetRealInitRange(ctx, l, u);
+    PGASetMaxGAIterValue(ctx, maxiter);
+    
+    PGASetUp(ctx);
+
+    if (testnum == 0)    PGARun(ctx, griewank);
+    if (testnum == 1)    PGARun(ctx, rastrigin);
+    if (testnum == 2)    PGARun(ctx, schwefel);
+
+    PGADestroy(ctx);
+    
+    MPI_Finalize();
+}
+
+
+double griewank(PGAContext *ctx, int p, int pop) {
+    int i, len;
+    double term, sum, product;
+
+    sum = 0;
+    product = 1;
+    len = PGAGetStringLength(ctx);
+    for (i = 0; i < len; i++) {
+        term = PGAGetRealAllele(ctx, p, pop, i);
+        sum = sum + term * term / 4000.0;
+        product = product * cos(term / sqrt(((double)i + 1)));
+    }
+
+    return (1 + sum - product);
+}
+
+
+double rastrigin(PGAContext *ctx, int p, int pop)
+{
+    int i, len;
+    double term, sum;
+
+    sum = 0;
+    len = PGAGetStringLength(ctx);
+    for (i = 0; i < len; i++) {
+        term = PGAGetRealAllele(ctx, p, pop, i);
+        sum = sum + term * term - 10 * cos(2 * M_PI * term);
+    }
+    return (len * 10 + sum);
+}
+
+
+double schwefel(PGAContext *ctx, int p, int pop) {
+    int i, len;
+    double term, sum;
+
+    sum = 0;
+    len = PGAGetStringLength(ctx);
+    for (i = 0; i < len; i++) {
+        term = PGAGetRealAllele(ctx, p, pop, i);
+        sum = sum - term * sin(sqrt(fabs(term)));
+    }
+    return (sum);
+}
+
+
+
+/*  Get an integer parameter from the user.  Since this is
+ *  typically a parallel program, we must only do I/O on the
+ *  "master" process -- process 0.  Once we read the parameter,
+ *  we broadcast it to all the other processes, then every 
+ *  process returns the correct value.
+ */
+int GetIntegerParameter(char *query) {
+    int  rank, tmp;
+
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    if (rank == 0) {
+        printf(query);
+        scanf("%d", &tmp);
+    }
+    MPI_Bcast(&tmp, 1, MPI_INT, 0, MPI_COMM_WORLD);
+    return(tmp);
+}
+
+
+

Added: spamassassin/trunk/build/pga/examples/c/dejong
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/c/dejong?rev=1796518&view=auto
==============================================================================
Binary file - no diff available.

Propchange: spamassassin/trunk/build/pga/examples/c/dejong
------------------------------------------------------------------------------
    svn:executable = *

Propchange: spamassassin/trunk/build/pga/examples/c/dejong
------------------------------------------------------------------------------
    svn:mime-type = application/x-executable

Added: spamassassin/trunk/build/pga/examples/c/dejong.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/c/dejong.c?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/c/dejong.c (added)
+++ spamassassin/trunk/build/pga/examples/c/dejong.c Sun May 28 18:31:49 2017
@@ -0,0 +1,202 @@
+/*  The DeJong test suite.
+ *
+ */
+#include <pgapack.h>
+
+double dejong1(PGAContext *, int, int);
+double dejong2(PGAContext *, int, int);
+double dejong3(PGAContext *, int, int);
+double dejong4(PGAContext *, int, int);
+double dejong5(PGAContext *, int, int);
+void   printResultInterpretation(PGAContext *, int);
+int    GetIntegerParameter(char *query);
+
+int    gray_on;
+
+int    BinLen[5]     = { 10, 12, 10, 8, 17 };
+int    NumCoords[5]  = { 3, 2, 5, 30, 2 };
+double Lower[5]      = { -5.12, -2.048, -5.12, -1.28, -65.536 };
+double Upper[5]      = { 5.11, 2.047, 5.11, 1.27, 65.535 };
+
+/*******************************************************************
+ *                   user main program                              *
+ *******************************************************************/
+void main( int argc, char **argv ) {
+    PGAContext *ctx;    /* the context variable */
+    int testnum;        /* the DeJong test to run */
+    int maxiter;        /* the maximum number of iterations */
+
+    MPI_Init(&argc, &argv); 
+
+    testnum = GetIntegerParameter("Which test? (1 - 5)\n") - 1;
+    gray_on = GetIntegerParameter("Gray-coded? (0 = no)\n");
+    maxiter = GetIntegerParameter("How many iterations?\n");
+
+    ctx = PGACreate(&argc, argv, PGA_DATATYPE_BINARY, 
+		    BinLen[testnum]*NumCoords[testnum], PGA_MINIMIZE);
+    
+    PGASetMaxGAIterValue(ctx, maxiter);
+    PGASetRandomSeed(ctx, 1);
+    
+    PGASetUp(ctx);
+
+    if (testnum == 0)    PGARun(ctx, dejong1);
+    if (testnum == 1)    PGARun(ctx, dejong2);
+    if (testnum == 2)    PGARun(ctx, dejong3);
+    if (testnum == 3)    PGARun(ctx, dejong4);
+    if (testnum == 4)    PGARun(ctx, dejong5);
+
+    printResultInterpretation(ctx, testnum);
+
+    PGADestroy(ctx);
+    
+    MPI_Finalize();
+}
+
+
+double GetTerm(PGAContext *ctx, int p, int pop, int t, int problem) {
+    double    x;
+    int       len;
+    double    l, u;
+
+    len = BinLen[problem];
+    l   = Lower[problem];
+    u   = Upper[problem];
+
+    if (gray_on) 
+	x = PGAGetRealFromGrayCode(ctx, p, pop, t*len, (t+1)*len-1, l, u);
+    else
+	x = PGAGetRealFromBinary(ctx, p, pop, t*len, (t+1)*len-1, l, u);
+    return(x);
+}
+
+
+double dejong1(PGAContext *ctx, int p, int pop) {
+    int i;
+    double term, sum = 0;
+    
+    for(i = 0; i < NumCoords[0]; i++) {
+	term = GetTerm(ctx, p, pop, i, 0);
+	sum += (term * term);
+    }
+    
+    return (sum);
+}
+
+
+double dejong2(PGAContext *ctx, int p, int pop) {
+    double x1, x2, p1, p2;
+    
+    x1 = GetTerm(ctx, p, pop, 0, 1);
+    x2 = GetTerm(ctx, p, pop, 1, 1);
+
+    p1 = x1 * x1 - x2;
+    p2 = 1 - x1;
+    
+    return (100 * p1 * p1 + p2 * p2);
+}
+
+double dejong3(PGAContext *ctx, int p, int pop) {
+    int i;
+    double sum = 0;
+    
+    for(i = 0; i < NumCoords[2]; i++)
+	sum += floor(GetTerm(ctx, p, pop, i, 2));
+
+    return (sum);
+}
+
+double dejong4(PGAContext *ctx, int p, int pop) {
+    int i;
+    double term, sum = 0;
+    
+    for(i = 0; i < NumCoords[3]; i++) {
+	term = GetTerm(ctx, p, pop, i, 3);
+	sum += ((i + 1) * term * term * term * term);
+    }
+    
+    return (sum + PGARandomGaussian(ctx, 0, 1));
+}
+
+double dejong5(PGAContext *ctx, int p, int pop) {
+    int    a[2][25];
+    int    i, j;
+    double sum_over_i = 0, sum_over_j = 0;
+
+    for (i=0; i<5; i++) {
+        a[0][5*i]   = -32;
+        a[1][i]     = -32;
+
+        a[0][5*i+1] = -16;
+        a[1][i+5]   = -16;
+
+        a[0][5*i+2] = 0;
+        a[1][i+10]  = 0;
+
+        a[0][5*i+3] = 16;
+        a[1][i+15]  = 16;
+
+        a[0][5*i+4] = 32;
+        a[1][i+20]  = 32;
+    }
+
+    for (j = 0; j < 25; j++) {
+	sum_over_i =
+	    pow(GetTerm(ctx, p, pop, 0, 4) - a[0][j], 6) +
+	    pow(GetTerm(ctx, p, pop, 1, 4) - a[1][j], 6);
+	sum_over_j += (1.0 / (j + sum_over_i));
+    }
+    
+    return (1.0 / (0.002 + sum_over_j));
+}
+
+
+void printResultInterpretation(PGAContext *ctx, int problem) {
+    int      best, i;
+    double   value;
+
+    if (PGAGetRank(ctx, MPI_COMM_WORLD) == 0) {
+	best = PGAGetBestIndex(ctx, PGA_OLDPOP);
+	
+	printf("The real interpretation:\n");
+	for (i = 0; i < NumCoords[problem]; i++) {
+	    value = GetTerm(ctx, best, PGA_OLDPOP, i, problem);
+	    
+	    switch ( i % 5 ) {
+	    case 0:
+		printf ("#%4d: [%11.7g]", i, value);
+		break;
+	    case 1:
+	    case 2:
+	    case 3:
+		printf (", [%11.7g]", value);
+		break;
+	    case 4:
+		printf (", [%11.7g]", value);
+		if (i+1 < NumCoords[problem])
+		    printf ("\n");
+		break;
+	    }
+	}
+	printf("\n");
+    }
+}
+
+
+/*  Get an integer parameter from the user.  Since this is
+ *  typically a parallel program, we must only do I/O on the
+ *  "master" process -- process 0.  Once we read the parameter,
+ *  we broadcast it to all the other processes, then every 
+ *  process returns the correct value.
+ */
+int GetIntegerParameter(char *query) {
+    int  rank, tmp;
+
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    if (rank == 0) {
+        printf(query);
+        scanf("%d", &tmp);
+    }
+    MPI_Bcast(&tmp, 1, MPI_INT, 0, MPI_COMM_WORLD);
+    return(tmp);
+}

Added: spamassassin/trunk/build/pga/examples/c/example
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/c/example?rev=1796518&view=auto
==============================================================================
Binary file - no diff available.

Propchange: spamassassin/trunk/build/pga/examples/c/example
------------------------------------------------------------------------------
    svn:executable = *

Propchange: spamassassin/trunk/build/pga/examples/c/example
------------------------------------------------------------------------------
    svn:mime-type = application/x-executable

Added: spamassassin/trunk/build/pga/examples/c/example.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/c/example.c?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/c/example.c (added)
+++ spamassassin/trunk/build/pga/examples/c/example.c Sun May 28 18:31:49 2017
@@ -0,0 +1,42 @@
+#include <pgapack.h>
+
+double evaluate (PGAContext *ctx, int p, int pop);
+int myMutation  (PGAContext *, int, int, double);
+
+int main( int argc, char **argv )
+{
+     PGAContext *ctx; 
+     int i, lower[10], upper[10];
+
+     for (i=0; i<10; i++) {
+	 lower[i] = 1;
+	 upper[i] = 10;
+     }
+     ctx = PGACreate (&argc, argv, PGA_DATATYPE_INTEGER, 10, PGA_MAXIMIZE);
+     PGASetUserFunction (ctx, PGA_USERFUNCTION_MUTATION, (void *)myMutation);
+     PGASetIntegerInitRange(ctx, lower, upper);
+     PGASetUp              (ctx);
+     PGARun                (ctx, evaluate);
+     PGADestroy            (ctx);
+     return(0);
+}
+int myMutation(PGAContext *ctx, int p, int pop, double pm)
+{
+    int stringlen, i, k, count = 0;
+    stringlen = PGAGetStringLength(ctx);
+    for (i = 0; i < stringlen; i++)
+    if (PGARandomFlip(ctx, pm)) {
+        k = PGARandomInterval(ctx, 1, stringlen);
+        PGASetIntegerAllele(ctx, p, pop, i, k);
+        count++;
+    }
+    return ((double) count);
+}
+double evaluate(PGAContext *ctx, int p, int pop)
+{
+     int stringlen, i, sum = 0;
+     stringlen = PGAGetStringLength(ctx);
+     for (i = 0; i < stringlen; i++)
+         sum += PGAGetIntegerAllele(ctx, p, pop, i);
+     return ((double)sum);
+}

Added: spamassassin/trunk/build/pga/examples/c/maxbit
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/c/maxbit?rev=1796518&view=auto
==============================================================================
Binary file - no diff available.

Propchange: spamassassin/trunk/build/pga/examples/c/maxbit
------------------------------------------------------------------------------
    svn:executable = *

Propchange: spamassassin/trunk/build/pga/examples/c/maxbit
------------------------------------------------------------------------------
    svn:mime-type = application/x-executable

Added: spamassassin/trunk/build/pga/examples/c/maxbit.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/c/maxbit.c?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/c/maxbit.c (added)
+++ spamassassin/trunk/build/pga/examples/c/maxbit.c Sun May 28 18:31:49 2017
@@ -0,0 +1,45 @@
+/*
+ *  This is a test program for PGAPack.  The objective is to maximize the
+ *  number of 1-bits in a chromosome.
+ */
+
+#include <pgapack.h>
+
+double NumberOfSetBits(PGAContext *, int, int);
+
+/*******************************************************************
+*                   user main program                              *
+*******************************************************************/
+int main( int argc, char **argv ) {
+    PGAContext *ctx;
+    
+    ctx = PGACreate(&argc, argv, PGA_DATATYPE_BINARY, 256, PGA_MAXIMIZE);
+    PGASetRandomSeed(ctx, 1);
+    
+    PGASetUp(ctx);
+    PGARun(ctx, NumberOfSetBits);
+    PGADestroy(ctx);
+    
+    return(0);
+}
+
+
+/*******************************************************************
+*               user defined evaluation function                   *
+*   ctx - contex variable                                          *
+*   p   - chromosome index in population                           *
+*   pop - which population to refer to                             *
+*******************************************************************/
+double NumberOfSetBits(PGAContext *ctx, int p, int pop) {
+    int i, nbits, stringlen;
+
+    stringlen = PGAGetStringLength(ctx);
+    
+    nbits = 0;
+    for ( i=0; i<stringlen; i++ )
+	if ( PGAGetBinaryAllele(ctx, p, pop, i) )
+	    nbits++;
+    
+    return((double) nbits);
+}
+

Added: spamassassin/trunk/build/pga/examples/c/maxchar
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/c/maxchar?rev=1796518&view=auto
==============================================================================
Binary file - no diff available.

Propchange: spamassassin/trunk/build/pga/examples/c/maxchar
------------------------------------------------------------------------------
    svn:executable = *

Propchange: spamassassin/trunk/build/pga/examples/c/maxchar
------------------------------------------------------------------------------
    svn:mime-type = application/x-executable

Added: spamassassin/trunk/build/pga/examples/c/maxchar.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/c/maxchar.c?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/c/maxchar.c (added)
+++ spamassassin/trunk/build/pga/examples/c/maxchar.c Sun May 28 18:31:49 2017
@@ -0,0 +1,103 @@
+/*
+ *  This is a test program for PGAPack.  The objective is to maximize the
+ *  number of 'z's in a chromosome.
+ */
+
+#include <pgapack.h>
+
+double NumberOfZs(PGAContext *, int, int);
+int    myMutation(PGAContext *, int, int, double);
+int    GetIntegerParameter(char *query);
+
+/*******************************************************************
+*                   user main program                              *
+*******************************************************************/
+int main( int argc, char **argv )
+{
+     PGAContext *ctx;
+     int         len, maxiter;
+
+
+     MPI_Init(&argc, &argv);
+
+     len = GetIntegerParameter("String length?\n");
+     maxiter = GetIntegerParameter("How many iterations?\n");
+
+     ctx = PGACreate(&argc, argv, PGA_DATATYPE_CHARACTER, len, PGA_MAXIMIZE);
+
+     PGASetRandomSeed(ctx, 1);
+     PGASetMaxGAIterValue(ctx, maxiter);
+     PGASetUserFunction(ctx, PGA_USERFUNCTION_MUTATION, (void *)myMutation);
+
+     PGASetUp(ctx);
+     PGARun(ctx, NumberOfZs);
+     PGADestroy(ctx);
+
+     MPI_Finalize();
+
+     return(0);
+}
+
+
+/*******************************************************************
+*               user defined evaluation function                   *
+*   ctx - contex variable                                          *
+*   p   - chromosome index in population                           *
+*   pop - which population to refer to                             *
+*******************************************************************/
+double NumberOfZs(PGAContext *ctx, int p, int pop) {
+     int i, nzs;
+     int stringlen;
+
+     stringlen = PGAGetStringLength(ctx);
+     
+     nzs = 0;
+     for ( i=0; i<stringlen; i++ )
+	  if (PGAGetCharacterAllele(ctx, p, pop, i) == 'z')
+	       nzs++;
+     
+     return((double) nzs);
+}
+
+
+/*  Custom mutation function.  Searches for an unset bit, 
+ *  then sets it.  Returns the number of bits that are changed.
+ */
+int myMutation(PGAContext *ctx, int p, int pop, double mr) {
+    int         i, count;
+    char        c;
+
+    count = 0;
+    for (i=PGAGetStringLength(ctx)-1; i>=0; i--) {
+	if (PGARandomFlip(ctx, mr)) {
+	    c = PGAGetCharacterAllele(ctx, p, pop, i);
+	    if (c != 'z') {
+		PGASetCharacterAllele(ctx, p, pop, i, c+1);
+		count++;
+	    }
+	}
+    }
+    return(count);
+}
+
+
+
+/*  Get an integer parameter from the user.  Since this is
+ *  typically a parallel program, we must only do I/O on the
+ *  "master" process -- process 0.  Once we read the parameter,
+ *  we broadcast it to all the other processes, then every 
+ *  process returns the correct value.
+ */
+int GetIntegerParameter(char *query) {
+    int  rank, tmp;
+
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    if (rank == 0) {
+        printf(query);
+        scanf("%d", &tmp);
+    }
+    MPI_Bcast(&tmp, 1, MPI_INT, 0, MPI_COMM_WORLD);
+    return(tmp);
+}
+
+

Added: spamassassin/trunk/build/pga/examples/c/maxint
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/c/maxint?rev=1796518&view=auto
==============================================================================
Binary file - no diff available.

Propchange: spamassassin/trunk/build/pga/examples/c/maxint
------------------------------------------------------------------------------
    svn:executable = *

Propchange: spamassassin/trunk/build/pga/examples/c/maxint
------------------------------------------------------------------------------
    svn:mime-type = application/x-executable

Added: spamassassin/trunk/build/pga/examples/c/maxint.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/c/maxint.c?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/c/maxint.c (added)
+++ spamassassin/trunk/build/pga/examples/c/maxint.c Sun May 28 18:31:49 2017
@@ -0,0 +1,94 @@
+/*
+ *  This is a test program for PGAPack.  The objective is to maximize each
+ *  allele.  The evaluation function sums all allele values.
+ */
+#include <pgapack.h>
+
+double evaluate(PGAContext *, int, int);
+int    myMutation(PGAContext *, int, int, double);
+int    GetIntegerParameter(char *query);
+
+
+int main(int argc, char **argv) {
+     PGAContext *ctx;
+     int         len, maxiter;
+
+     MPI_Init(&argc, &argv);
+
+     len     = GetIntegerParameter("String length?\n");
+     maxiter = GetIntegerParameter("How many iterations?\n");
+
+     ctx = PGACreate(&argc, argv, PGA_DATATYPE_INTEGER, len, PGA_MAXIMIZE);
+
+     PGASetRandomSeed(ctx, 1);
+     PGASetUserFunction(ctx, PGA_USERFUNCTION_MUTATION, (void *)myMutation);
+     PGASetIntegerInitPermute(ctx, 1, len);
+
+     PGASetMaxGAIterValue(ctx, maxiter);
+     PGASetNumReplaceValue(ctx, 90);
+     PGASetMutationAndCrossoverFlag(ctx, PGA_TRUE);
+     PGASetPrintOptions(ctx, PGA_REPORT_AVERAGE);
+
+     PGASetUp(ctx);
+
+     PGARun(ctx, evaluate);
+     PGADestroy(ctx);
+
+     MPI_Finalize();
+
+     return(0);
+}
+
+
+int myMutation(PGAContext *ctx, int p, int pop, double mr) {
+    int         stringlen, i, v, count;
+
+    stringlen = PGAGetStringLength(ctx);
+    count     = 0;
+
+    for (i=stringlen-1; i>=0; i--) {
+	if (PGARandomFlip(ctx, mr)) {
+	    v = PGARandomInterval(ctx, 1, stringlen);
+            PGASetIntegerAllele(ctx, p, pop, i, v);
+	    count++;
+	}
+    }
+    return((double)count);
+}
+
+
+
+double evaluate(PGAContext *ctx, int p, int pop) {
+     int  stringlen, i, sum;
+
+     stringlen = PGAGetStringLength(ctx);
+     sum       = 0;
+     
+     for (i=stringlen-1; i>=0; i--)
+	  sum += PGAGetIntegerAllele(ctx, p, pop, i);
+
+     return((double)sum);
+}
+
+
+
+/*  Get an integer parameter from the user.  Since this is
+ *  typically a parallel program, we must only do I/O on the
+ *  "master" process -- process 0.  Once we read the parameter,
+ *  we broadcast it to all the other processes, then every 
+ *  process returns the correct value.
+ */
+int GetIntegerParameter(char *query) {
+    int  rank, tmp;
+
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    if (rank == 0) {
+        printf(query);
+        scanf("%d", &tmp);
+    }
+    MPI_Bcast(&tmp, 1, MPI_INT, 0, MPI_COMM_WORLD);
+    return(tmp);
+}
+
+
+

Added: spamassassin/trunk/build/pga/examples/c/name
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/c/name?rev=1796518&view=auto
==============================================================================
Binary file - no diff available.

Propchange: spamassassin/trunk/build/pga/examples/c/name
------------------------------------------------------------------------------
    svn:executable = *

Propchange: spamassassin/trunk/build/pga/examples/c/name
------------------------------------------------------------------------------
    svn:mime-type = application/x-executable

Added: spamassassin/trunk/build/pga/examples/c/name.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/c/name.c?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/c/name.c (added)
+++ spamassassin/trunk/build/pga/examples/c/name.c Sun May 28 18:31:49 2017
@@ -0,0 +1,124 @@
+/*  PGAPack test program.
+ *
+ *  The objective is to evolve a string of characters to match a string
+ *  supplied by the user.  We will stop evolving when either we run out
+ *  of iterations (500), or when the best string has the same evaluation
+ *  value for 100 generations.
+ *
+ *  One problem with this implementation is that ' ' is not in
+ *  PGA_DATATYPE_CHAR if we limit it using PGA_CINIT_MIXED, PGA_CINIT_LOWER,
+ *  or PGA_CINIT_UPPER.  To fix this, we must define our own interval, and
+ *  thus, our own mutation, initialization operators.
+ *
+ *  A user function is also used to check the "done" condition; we are 
+ *  done if we've done more than 1000 iterations, or the evolved string
+ *  is correct.
+ *
+ *  Created 28 Sep 95, Brian P. Walenz.  Thanks to Dan Ashlock for the idea.
+ */
+
+#include "pgapack.h"
+
+void   N_InitString(PGAContext *ctx, int p, int pop);
+int    N_Mutation(PGAContext *ctx, int p, int pop, double mr);
+int    N_StopCond(PGAContext *ctx);
+double EvalName(PGAContext *ctx, int p, int pop);
+void   GetStringParameter(char *query, char *string);
+
+/*  Global, because we use it in EvalName.  */
+char   Name[42];
+
+void main(int argc, char **argv) {
+    PGAContext *ctx;
+
+    MPI_Init(&argc, &argv);
+
+    /*  Rather than deal with standard io and strings, we'll just set
+     *  this explicitly.
+     */
+    strcpy(Name,"Levine, Hallstrom, Noelle, Walenz");
+
+    ctx = PGACreate(&argc, argv, PGA_DATATYPE_CHARACTER, strlen(Name),
+		    PGA_MAXIMIZE);
+    
+    PGASetRandomSeed(ctx, 1);
+    
+    PGASetUserFunction(ctx, PGA_USERFUNCTION_INITSTRING, (void *)N_InitString);
+    PGASetUserFunction(ctx, PGA_USERFUNCTION_MUTATION,   (void *)N_Mutation);
+    PGASetUserFunction(ctx, PGA_USERFUNCTION_STOPCOND,   (void *)N_StopCond);
+
+    PGASetPopSize(ctx, 100);
+    PGASetNumReplaceValue(ctx, 75);
+    PGASetPopReplaceType(ctx, PGA_POPREPL_BEST);
+    
+    PGASetCrossoverProb(ctx, 0.0);
+    PGASetMutationOrCrossoverFlag(ctx, PGA_TRUE);
+    PGASetMaxGAIterValue(ctx, 100);
+    
+    PGASetUp(ctx);
+    PGARun(ctx, EvalName);
+    PGADestroy(ctx);
+
+    MPI_Finalize();
+}
+
+
+/*  Function to randomly initialize a PGA_DATATYPE_CHARACTER string using
+ *  all printable ASCII characters for the range.
+ */
+void N_InitString(PGAContext *ctx, int p, int pop) {
+    int               i;
+    
+    for(i=0; i<PGAGetStringLength(ctx); i++)
+	PGASetCharacterAllele(ctx, p, pop, i, 
+			      PGARandomInterval(ctx, 32, 126));
+}
+
+
+/*  Function to muatate a PGA_DATATYPE_CHARACTER string.  This is done
+ *  by simply picking allele locations, and replacing whatever was there
+ *  with a new value.  Again, legal values are all printable ASCII characters.
+ */
+int N_Mutation(PGAContext *ctx, int p, int pop, double mr) {
+    int               i, count=0;
+    
+    for(i=0; i<PGAGetStringLength(ctx); i++)
+	if (PGARandomFlip(ctx, mr)) {
+	    PGASetCharacterAllele(ctx, p, pop, i,
+				  PGARandomInterval(ctx, 32, 126));
+            count++;
+	}
+    return(count);
+}
+
+
+int N_StopCond(PGAContext *ctx) {
+    int   done, best;
+
+    done = PGACheckStoppingConditions(ctx);
+
+    best = PGAGetBestIndex(ctx, PGA_OLDPOP);
+    if ((done == PGA_FALSE) && 
+	(PGAGetEvaluation(ctx, best, PGA_OLDPOP) ==
+	 PGAGetStringLength(ctx)))
+	done = PGA_TRUE;
+
+    return(done);
+}
+
+    
+/*  Evaluate the string.  A highly fit string will have many of
+ *  the characters matching Name.
+ */
+double EvalName(PGAContext *ctx, int p, int pop) {
+    int     i, count;
+    
+    count = 0;
+    for (i=PGAGetStringLength(ctx)-1; i>=0; i--) {
+	if (PGAGetCharacterAllele(ctx, p, pop, i) == Name[i])
+	    count++;
+    }
+    
+    return((double)count);
+}
+

Added: spamassassin/trunk/build/pga/examples/c/namefull
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/c/namefull?rev=1796518&view=auto
==============================================================================
Binary file - no diff available.

Propchange: spamassassin/trunk/build/pga/examples/c/namefull
------------------------------------------------------------------------------
    svn:executable = *

Propchange: spamassassin/trunk/build/pga/examples/c/namefull
------------------------------------------------------------------------------
    svn:mime-type = application/x-executable

Added: spamassassin/trunk/build/pga/examples/c/namefull.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/c/namefull.c?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/c/namefull.c (added)
+++ spamassassin/trunk/build/pga/examples/c/namefull.c Sun May 28 18:31:49 2017
@@ -0,0 +1,242 @@
+/*  PGAPack test program.
+ *
+ *  The objective is to evolve a string of characters to match a string
+ *  supplied by the user.  We will stop evolving when either we run out
+ *  of iterations (500), or when the best string has the same evaluation
+ *  value for 100 generations.
+ *
+ *  One problem with this implementation is that ' ' is not in
+ *  PGA_DATATYPE_CHAR if we limit it using PGA_CINIT_MIXED, PGA_CINIT_LOWER,
+ *  or PGA_CINIT_UPPER.  To fix this, we must define our own interval, and
+ *  thus, our own mutation, initialization operators.
+ *
+ *  A user function is also used to check the "done" condition; we are 
+ *  done if we've done more than 1000 iterations, or the evolved string
+ *  is correct.
+ *
+ *  Created 28 Sep 95, Brian P. Walenz.  Thanks to Dan Ashlock for the idea.
+ *
+ *  Be warned that duplicate checking will sometimes go into an infinite
+ *  loop.
+ */
+
+#include "pgapack.h"
+
+void   N_InitString (PGAContext *, int, int);
+int    N_Mutation   (PGAContext *, int, int, double);
+int    N_StopCond   (PGAContext *);
+void   N_Crossover  (PGAContext *ctx, int, int, int, int, int, int);
+int    N_Duplicate  (PGAContext *, int, int, int, int);
+void   N_PrintString(PGAContext *, FILE *, int, int);
+void   N_EndOfGen   (PGAContext *);
+double EvalName     (PGAContext *, int, int);
+void   GetStringParameter(char *, char *);
+
+/*  Global, because we use it in EvalName.  */
+char   Name[70];
+
+void main(int argc, char **argv) {
+    PGAContext *ctx;
+
+    MPI_Init(&argc, &argv);
+
+    /*  Rather than deal with standard io and strings, we'll just set
+     *  this explicitly.
+     */
+    strcpy(Name, "David M. Levine, Philip L. Hallstrom, David M. Noelle, "
+                 "Brian P. Walenz");
+
+    ctx = PGACreate(&argc, argv, PGA_DATATYPE_CHARACTER, strlen(Name),
+		    PGA_MAXIMIZE);
+    
+    PGASetRandomSeed(ctx, 42);
+    
+    PGASetUserFunction(ctx, PGA_USERFUNCTION_INITSTRING, (void *)N_InitString);
+    PGASetUserFunction(ctx, PGA_USERFUNCTION_MUTATION,   (void *)N_Mutation);
+    PGASetUserFunction(ctx, PGA_USERFUNCTION_CROSSOVER,  (void *)N_Crossover);
+    PGASetUserFunction(ctx, PGA_USERFUNCTION_DUPLICATE,  (void *)N_Duplicate);
+    PGASetUserFunction(ctx, PGA_USERFUNCTION_STOPCOND,   (void *)N_StopCond);
+    PGASetUserFunction(ctx, PGA_USERFUNCTION_PRINTSTRING,(void *)N_PrintString);
+    PGASetUserFunction(ctx, PGA_USERFUNCTION_ENDOFGEN,   (void *)N_EndOfGen);
+
+    /*  We don't want to report anything.  */
+    PGASetPrintFrequencyValue(ctx, 10000);
+    PGASetPopSize(ctx, 100);
+    PGASetNumReplaceValue(ctx, 90);
+    PGASetPopReplaceType(ctx, PGA_POPREPL_BEST);
+    PGASetNoDuplicatesFlag(ctx, PGA_TRUE);
+    PGASetMaxGAIterValue(ctx, 100);
+    
+    PGASetUp(ctx);
+    PGARun(ctx, EvalName);
+    PGADestroy(ctx);
+
+    MPI_Finalize();
+}
+
+
+/*  Function to randomly initialize a PGA_DATATYPE_CHARACTER string using
+ *  all printable ASCII characters for the range.
+ */
+void N_InitString(PGAContext *ctx, int p, int pop) {
+    int               i;
+    
+    for(i=PGAGetStringLength(ctx)-1; i>=0; i--)
+	PGASetCharacterAllele(ctx, p, pop, i, 
+			      PGARandomInterval(ctx, 32, 126));
+}
+
+
+
+/*  Function to crossover two name strings.  Quite an interesting
+ *  crossover, too.  Works like a normal uniform crossover, except
+ *  that, if one of the strings matches the correct value, we set
+ *  BOTH children to the correct value 50% of the time.
+ */
+void N_Crossover(PGAContext *ctx, int p1, int p2, int pop1, int c1, 
+		 int c2, int pop2) {
+    int           i, length;
+    char          a, b;
+	    
+    length = PGAGetStringLength(ctx);
+
+    for (i=0; i<length; i++) {
+	a = PGAGetCharacterAllele(ctx, p1, pop1, i);
+	b = PGAGetCharacterAllele(ctx, p2, pop1, i);
+	if ((a == Name[i]) || (b == Name[i]))
+	    a = b = Name[i];
+
+	if (PGARandomFlip(ctx, 0.5) == PGA_TRUE) {
+            PGASetCharacterAllele(ctx, c1, pop2, i, a);
+            PGASetCharacterAllele(ctx, c2, pop2, i, b);
+	} else {
+            PGASetCharacterAllele(ctx, c1, pop2, i, b);
+            PGASetCharacterAllele(ctx, c2, pop2, i, a);
+        }
+    }
+}
+
+
+
+/*  Function to compare two strings.  Strings are "equalivalent"
+ *  if they match Name at the same alleles (and, thus, disagree at the
+ *  same alleles).  We don't care what the disagreement is, just that
+ *  it is there.
+ *
+ *  NOTE that because it is possible to get stuck in an infinite
+ *  loop while doing duplicate checking on this string (assuming that
+ *  the mutation operator is always beneficial), we ALWAYS return PGA_FALSE.
+ *  The code is left as an example (and for testing).
+ */
+int N_Duplicate(PGAContext *ctx, int p1, int pop1, int p2, int pop2) {
+    int          i, match;
+    char         a, b, c;
+    
+    match = PGA_TRUE;
+
+    for (i=PGAGetStringLength(ctx)-1; match && i>=0; i--) {
+	a = PGAGetCharacterAllele(ctx, p1, pop1, i);
+	b = PGAGetCharacterAllele(ctx, p2, pop2, i);
+	c = Name[i];
+	if (((a == c) && (b != c)) || ((a != c) && (b == c))) 
+	    match = PGA_FALSE;
+    }
+
+    return(match);
+}
+
+
+/*  Function to muatate a PGA_DATATYPE_CHARACTER string.  This is done
+ *  by simply picking allele locations and replacing whatever was there.
+ *  Again, legal values are all printable ASCII characters.
+ */
+int N_Mutation(PGAContext *ctx, int p, int pop, double mr) {
+    int               i, count;
+
+    count = 0;
+    for(i=PGAGetStringLength(ctx)-1; i>=0; i--)
+	if (PGAGetCharacterAllele(ctx, p, pop, i) != Name[i]) {
+	    if (PGARandomFlip(ctx, mr) == PGA_TRUE) {
+		PGASetCharacterAllele(ctx, p, pop, i,
+				      PGARandomInterval(ctx, 32, 126));
+		count++;
+	    }
+	}
+    return(count);
+}
+
+
+/*  Function to print a string.  Since fortran does NOT support
+ *  C file handles, we just print normally.  If we we're in C,
+ *  we would print to the file "file".
+ */
+void N_PrintString(PGAContext *ctx, FILE *file, int p, int pop) {
+    int          i;
+    char         string[71];
+
+    for (i=PGAGetStringLength(ctx)-1; i>=0; i--)
+	string[i] = PGAGetCharacterAllele(ctx, p, pop, i);
+    string[70] = 0;
+
+    fprintf(file," :%s:\n", string);
+}
+
+
+/*  Function to check "doneness" of the GA.  We check the iteration
+ *  count (by calling PGACheckStoppingConditions), then check if we have found
+ *  the string yet.
+ */
+int N_StopCond(PGAContext *ctx) {
+    int   done, best;
+
+    done = PGACheckStoppingConditions(ctx);
+
+    best = PGAGetBestIndex(ctx, PGA_OLDPOP);
+    if ((done == PGA_FALSE) && 
+	(PGAGetEvaluation(ctx, best, PGA_OLDPOP) ==
+	 PGAGetStringLength(ctx)))
+	done = PGA_TRUE;
+
+    return(done);
+}
+
+
+
+/*  After each generation, this routine is called.  What is done here,
+ *  is to print the best string in our own format, then check if the
+ *  best string is close to the correct value.  If it is, duplicate
+ *  checking is tunred off.  This is critical, as the mutation operator
+ *  will not degrade a string, so when the strings get near the correct
+ *  solution, they all become duplicates, but none can be changed!
+ *
+ *  Other applications have done such things as send the best string 
+ *  to another process to be visualized.  For here, we just call our
+ *  print string function to print the best string.
+ */
+void N_EndOfGen(PGAContext *ctx) {
+    int best;
+
+    best = PGAGetBestIndex(ctx, PGA_NEWPOP);
+    N_PrintString(ctx, stdout, best, PGA_NEWPOP);
+
+    if (PGAGetEvaluation(ctx, best, PGA_NEWPOP) >=
+	PGAGetStringLength(ctx)-10) 
+	PGASetNoDuplicatesFlag(ctx, PGA_FALSE);
+}
+
+    
+/*  Evaluate the string.  A highly fit string will have many of
+ *  the characters matching Name.
+ */
+double EvalName(PGAContext *ctx, int p, int pop) {
+    int     i, count;
+    
+    count = 0;
+    for (i=PGAGetStringLength(ctx)-1; i>=0; i--) {
+	if (PGAGetCharacterAllele(ctx, p, pop, i) == Name[i])
+	    count++;
+    }
+    
+    return((double)count);
+}
+

Added: spamassassin/trunk/build/pga/examples/c/test.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/c/test.c?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/c/test.c (added)
+++ spamassassin/trunk/build/pga/examples/c/test.c Sun May 28 18:31:49 2017
@@ -0,0 +1,40 @@
+From levine@mcs.anl.gov Mon Nov 27 16:53:21 1995
+Received: from jadoube (jadoube.mcs.anl.gov [140.221.7.137]) by antares.mcs.anl.gov (8.6.10/8.6.10)  with ESMTP
+	id QAA23813 for <wa...@mcs.anl.gov>; Mon, 27 Nov 1995 16:53:21 -0600
+From: David Levine <le...@mcs.anl.gov>
+Date: Mon, 27 Nov 1995 16:53:19 -0600
+Message-Id: <19...@jadoube>
+To: walenz@mcs.anl.gov
+Status: R
+
+
+#include "pgapack.h"
+double evaluate (PGAContext *ctx, int p, int pop);
+
+int main(int argc, char **argv)
+{
+    PGAContext *ctx;
+    int rank;
+
+    ctx = PGACreate(&argc, argv, PGA_DATATYPE_BINARY, 100, PGA_MAXIMIZE);
+    PGASetUp   (ctx);
+    rank = PGAGetRank(ctx, MPI_COMM_WORLD);
+    PGAEvaluate(ctx, PGA_OLDPOP, evaluate, MPI_COMM_WORLD);
+    if ( rank == 0 )
+        PGAFitness (ctx, PGA_OLDPOP);
+    while(!PGADone(ctx, MPI_COMM_WORLD)) {
+        if ( rank == 0 ) {
+            PGASelect                 (ctx, PGA_OLDPOP);
+            PGARunMutationAndCrossover(ctx, PGA_OLDPOP, PGA_NEWPOP);
+        }
+        PGAEvaluate(ctx, PGA_OLDPOP, evaluate, MPI_COMM_WORLD);
+        if ( rank == 0 )
+            PGAFitness                (ctx, PGA_NEWPOP);
+        PGAUpdateGeneration           (ctx, MPI_COMM_WORLD);
+        if ( rank == 0 )
+            PGAPrintReport            (ctx, stdout, PGA_OLDPOP);
+    }
+    PGADestroy(ctx);
+    return(0);
+}
+

Added: spamassassin/trunk/build/pga/examples/c/udtstr
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/c/udtstr?rev=1796518&view=auto
==============================================================================
Binary file - no diff available.

Propchange: spamassassin/trunk/build/pga/examples/c/udtstr
------------------------------------------------------------------------------
    svn:executable = *

Propchange: spamassassin/trunk/build/pga/examples/c/udtstr
------------------------------------------------------------------------------
    svn:mime-type = application/x-executable

Added: spamassassin/trunk/build/pga/examples/c/udtstr.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/c/udtstr.c?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/c/udtstr.c (added)
+++ spamassassin/trunk/build/pga/examples/c/udtstr.c Sun May 28 18:31:49 2017
@@ -0,0 +1,271 @@
+/*****************************************************************************
+ * The chromosome in this example is a structure containing three doubles    *
+ * representing a translation along each of the x-, y-, and z-axes; three    *
+ * doubles representing a rotation about each the axes; and forty ints       *
+ * representing an index to side chain rotations.  This is a simple          *
+ * illustration of how to set up a molecular docking problem.                *
+ *****************************************************************************/
+#include <pgapack.h>
+
+double       energy           (double *, int *);
+double       Evaluate         (PGAContext *, int, int);
+void         CreateString     (PGAContext *, int, int, int);
+int          Mutation         (PGAContext *, int, int, double);
+void         Crossover        (PGAContext *, int, int, int, int, int, int);
+void         WriteString      (PGAContext *, FILE *, int, int);
+void         CopyString       (PGAContext *, int, int, int, int);
+int          DuplicateString  (PGAContext *, int, int, int, int);
+MPI_Datatype BuildDT          (PGAContext *, int, int);
+
+typedef struct {
+    double t[6];          /* ligand translation and rotation */
+    int    sc[40];        /* ligand sidechain rotations      */
+} ligand;
+
+int main(int argc, char **argv) {
+    PGAContext *ctx;
+
+    ctx = PGACreate(&argc, argv, PGA_DATATYPE_USER, 46, PGA_MINIMIZE);
+    PGASetRandomSeed    (ctx, 1);
+    PGASetMaxGAIterValue(ctx, 5000);
+    PGASetUserFunction  (ctx, PGA_USERFUNCTION_CREATESTRING,  (void *)CreateString);
+    PGASetUserFunction  (ctx, PGA_USERFUNCTION_MUTATION,      (void *)Mutation);
+    PGASetUserFunction  (ctx, PGA_USERFUNCTION_CROSSOVER,     (void *)Crossover);
+    PGASetUserFunction  (ctx, PGA_USERFUNCTION_PRINTSTRING,   (void *)WriteString);
+    PGASetUserFunction  (ctx, PGA_USERFUNCTION_COPYSTRING,    (void *)CopyString);
+    PGASetUserFunction  (ctx, PGA_USERFUNCTION_DUPLICATE,     (void *)DuplicateString);
+    PGASetUserFunction  (ctx, PGA_USERFUNCTION_BUILDDATATYPE, (void *)BuildDT);
+    PGASetUp            (ctx);
+    PGARun              (ctx, Evaluate);
+    PGADestroy          (ctx);
+    return (0);
+}
+
+
+/*****************************************************************************
+ * CreateString allocates and initializes a chromosome.  If InitFlag is      *
+ * set to true, then it will randomly initialize the chromosome; otherwise,  *
+ * it sets each double to 0.0 and each int to 0.                             *
+ *****************************************************************************/
+void CreateString(PGAContext *ctx, int p, int pop, int InitFlag) {
+    int i;
+    ligand *ligand_ptr;
+    PGAIndividual *new;
+
+    new = PGAGetIndividual(ctx, p, pop);
+    if (!(new->chrom = malloc(sizeof(ligand)))) {
+        fprintf(stderr, "No room for new->chrom");
+        exit(1);
+    }
+    ligand_ptr = (ligand *)new->chrom;
+    if (InitFlag) {
+        for (i = 0; i < 3; i++)
+            ligand_ptr->t[i] = PGARandom01(ctx, 0) * 20.0 - 10.0;
+        for (i = 3; i < 6; i++)
+            ligand_ptr->t[i] = PGARandom01(ctx, 0) * 6.28 - 3.14;
+        for (i = 0; i < 40; i++)
+            ligand_ptr->sc[i] = PGARandomInterval(ctx, -20, 20);
+    } else {
+        for (i = 0; i < 6; i++)
+            ligand_ptr->t[i] = 0.0;
+        for (i = 0; i < 40; i++)
+            ligand_ptr->sc[i] = 0;
+    }
+}
+
+
+/*****************************************************************************
+ * Mutation performs mutation on a chromosome.  Each allele has a mr         *
+ * probability of being changed.  Mutation here perturbs each double by one  *
+ * tenth and each int by 1.                                                  *
+ *****************************************************************************/
+int Mutation(PGAContext *ctx, int p, int pop, double mr) {
+    ligand *ligand_ptr;
+    int i, count = 0;
+
+    ligand_ptr = (ligand *)PGAGetIndividual(ctx, p, pop)->chrom;
+    for (i = 0; i < 6; i++)
+        if (PGARandomFlip(ctx, mr)) {
+            if (PGARandomFlip(ctx, 0.5))
+                ligand_ptr->t[i] += 0.1*ligand_ptr->t[i];
+            else
+                ligand_ptr->t[i] -= 0.1*ligand_ptr->t[i];
+            count++;
+        }
+    for (i = 0; i < 40; i++)
+        if (PGARandomFlip(ctx, mr)) {
+            if (PGARandomFlip(ctx, 0.5))
+                ligand_ptr->sc[i] += 1;
+            else
+                ligand_ptr->sc[i] -= 1;
+            count++;
+        }
+    return (count);
+}
+
+
+/*****************************************************************************
+ * Crossover implements uniform crossover on the chromosome.                 *
+ *****************************************************************************/
+void Crossover(PGAContext *ctx, int p1, int p2, int pop1, int t1, int t2,
+               int pop2) {
+    int i;
+    ligand *parent1, *parent2, *child1, *child2;
+    double pu;
+
+    parent1 = (ligand *)PGAGetIndividual(ctx, p1, pop1)->chrom;
+    parent2 = (ligand *)PGAGetIndividual(ctx, p2, pop1)->chrom;
+    child1  = (ligand *)PGAGetIndividual(ctx, t1, pop2)->chrom;
+    child2  = (ligand *)PGAGetIndividual(ctx, t2, pop2)->chrom;
+
+    pu = PGAGetUniformCrossoverProb(ctx);
+
+    for (i = 0; i < 6; i++)
+            if (PGARandomFlip(ctx, pu)) {
+                child1->t[i] = parent1->t[i];
+                child2->t[i] = parent2->t[i];
+            } else {
+                child1->t[i] = parent2->t[i];
+                child2->t[i] = parent1->t[i];
+            }
+    for (i = 0; i < 40; i++)
+            if (PGARandomFlip(ctx, pu)) {
+                child1->sc[i] = parent1->sc[i];
+                child2->sc[i] = parent2->sc[i];
+            } else {
+                child1->sc[i] = parent2->sc[i];
+                child2->sc[i] = parent1->sc[i];
+            }
+}
+
+
+/*****************************************************************************
+ * WriteString sends a visual representation of the chromosome to the file   *
+ * fp.                                                                       *
+ *****************************************************************************/
+void WriteString(PGAContext *ctx, FILE *fp, int p, int pop) {
+    ligand *ligand_ptr;
+    int i;
+
+    ligand_ptr = (ligand *)PGAGetIndividual(ctx, p, pop)->chrom;
+    
+    fprintf(fp, "Position: [%11.7g, %11.7g, %11.7g]\n", 
+	    ligand_ptr->t[0], ligand_ptr->t[1], ligand_ptr->t[2]);
+    fprintf(fp, "Rotation: [%11.7g, %11.7g, %11.7g]\n", 
+	    ligand_ptr->t[3], ligand_ptr->t[4], ligand_ptr->t[5]);
+
+    fprintf(fp, "Sidechains:\n");
+    for (i=0; i<40; i+=8) {
+	fprintf(fp,"%2d: [%4ld] [%4ld] [%4ld] [%4ld]"
+		       " [%4ld] [%4ld] [%4ld] [%4ld]\n", i, 
+		ligand_ptr->sc[i+0], ligand_ptr->sc[i+2], 
+		ligand_ptr->sc[i+2], ligand_ptr->sc[i+3], 
+		ligand_ptr->sc[i+4], ligand_ptr->sc[i+5], 
+		ligand_ptr->sc[i+6], ligand_ptr->sc[i+7]);
+    }
+
+    fprintf ( fp, "\n" );
+}
+
+
+/*****************************************************************************
+ * CopyString makes a copy of the chromosome at (p1, pop1) and puts it at    *
+ * (p2, pop2).                                                               *
+ *****************************************************************************/
+void CopyString(PGAContext *ctx, int p1, int pop1, int p2, int pop2) {
+    void *d, *s;
+
+     s = PGAGetIndividual(ctx, p1, pop1)->chrom;
+     d = PGAGetIndividual(ctx, p2, pop2)->chrom;
+     memcpy(d, s, sizeof(ligand));
+}
+
+
+/*****************************************************************************
+ * DuplicateString compares two chromosomes and returns 1 if they are the    *
+ * same and 0 if they are different.                                         *
+ *****************************************************************************/
+int DuplicateString(PGAContext *ctx, int p1, int pop1, int p2, int pop2) {
+    void *a, *b;
+
+     a = PGAGetIndividual(ctx, p1, pop1)->chrom;
+     b = PGAGetIndividual(ctx, p2, pop2)->chrom;
+     return (!memcmp(a, b, sizeof(ligand)));
+}
+
+
+/*****************************************************************************
+ * BuildDatattype builds an MPI datatype for sending strings to other        *
+ * processors.  Consult your favorite MPI manual for more information.       *
+ *****************************************************************************/
+MPI_Datatype BuildDT(PGAContext *ctx, int p, int pop) {
+  int             counts[5];
+  MPI_Aint        displs[5];
+  MPI_Datatype    types[5];
+  MPI_Datatype    DT_PGAIndividual;
+  PGAIndividual  *P;
+  ligand         *S;
+
+  P = PGAGetIndividual(ctx, p, pop);
+  S = (ligand *)P->chrom;
+
+  /*  Build the MPI datatype.  Every user defined function needs these.
+   *  The first two calls are stuff that is internal to PGAPack, but 
+   *  the user still must include it.  See pgapack.h for details one the
+   *  fields (under PGAIndividual)
+   */
+  MPI_Address(&P->evalfunc, &displs[0]);
+  counts[0] = 2;
+  types[0]  = MPI_DOUBLE;
+
+  /*  Next, we have an integer, evaluptodate.  */  
+  MPI_Address(&P->evaluptodate, &displs[1]);
+  counts[1] = 1;
+  types[1]  = MPI_INT;
+
+  /*  Finally, we have the actual user-defined string.  */
+  MPI_Address(S->t, &displs[2]);
+  counts[2] = 6;
+  types[2]  = MPI_DOUBLE;
+
+  MPI_Address(S->sc, &displs[3]);
+  counts[3] = 40;
+  types[3]  = MPI_INT;
+
+  MPI_Type_struct(4, counts, displs, types, &DT_PGAIndividual);
+  MPI_Type_commit(&DT_PGAIndividual);
+  return(DT_PGAIndividual);
+}
+
+
+
+double Evaluate(PGAContext *ctx, int p, int pop) {
+    int     i;
+    double  x[6];
+    int     sc[40];
+    ligand *lig;
+
+    lig = (ligand *)PGAGetIndividual(ctx, p, pop)->chrom;
+    for (i = 0; i < 6; i++)
+        x[i] = lig->t[i];
+    for (i = 0; i < 40; i++)
+        sc[i] = lig->sc[i];
+    return ( energy(x,sc) );
+}
+
+
+#define SQ(z)  ((z)*(z))
+
+/*  For now just return distance from some fixed point plus
+ *  a penalty for not being aligned to the x, y and z axes.
+ *  The angles are divided by two so that we are in a range
+ *  that only has one zero.
+ */
+double energy(double *x, int *sc) {
+    double d;
+
+    d = sqrt( SQ(x[0]-1) + SQ(x[1]-2) + SQ(x[2]-3)) +
+	SQ(sin(x[3]/2)) + SQ(sin(x[4]/2)) + SQ(sin(x[5]/2));
+
+    return (d);
+}

Added: spamassassin/trunk/build/pga/examples/fortran/Makefile
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/fortran/Makefile?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/fortran/Makefile (added)
+++ spamassassin/trunk/build/pga/examples/fortran/Makefile Sun May 28 18:31:49 2017
@@ -0,0 +1,53 @@
+# Generated automatically from Makefile.in by configure.
+FC           = f77
+PREFFLAGS    = -w
+RM           = /bin/rm -f
+LDFLAGS      = -s  -L/usr/local/pga/lib/linux  -lpgaO  -lm
+SHELL        = /bin/sh
+
+#    "$@" expands to the target; "$?" expands to the dependency list
+FFLAGS      = -o $@ $? $(PREFFLAGS)
+
+LINK.f       = if test -n "$(FC)"; \
+                   then echo "  Compiling $@" ; $(FC) $(FFLAGS) $(LDFLAGS); \
+               else \
+                   echo "$@: Fortran compiler unavailable"; fi
+
+default:
+	@make classic
+	@make dejong
+	@make example
+	@make maxbit
+	@make maxchar
+	@make maxint 
+	@make name
+	@make namefull
+
+
+classic: classic.f
+	@$(LINK.f)
+
+dejong: dejong.f
+	@$(LINK.f)
+
+example: example.f
+	@$(LINK.f)
+
+maxbit: maxbit.f
+	@$(LINK.f)
+
+maxchar: maxchar.f
+	@$(LINK.f)
+
+maxint: maxint.f
+	@$(LINK.f)
+
+name: name.f
+	@$(LINK.f)
+
+namefull: namefull.f
+	@$(LINK.f)
+
+clean: 
+	@$(RM) classic dejong example maxbit maxchar maxint name namefull *.o
+

Added: spamassassin/trunk/build/pga/examples/fortran/Makefile.in
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/fortran/Makefile.in?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/fortran/Makefile.in (added)
+++ spamassassin/trunk/build/pga/examples/fortran/Makefile.in Sun May 28 18:31:49 2017
@@ -0,0 +1,52 @@
+FC           = @FC@
+PREFFLAGS    = @FFLAGS@
+RM           = @RM@
+LDFLAGS      = @LDFLAGS@
+SHELL        = @SHELL@
+
+#    "$@" expands to the target; "$?" expands to the dependency list
+FFLAGS      = -o $@ $? $(PREFFLAGS)
+
+LINK.f       = if test -n "$(FC)"; \
+                   then echo "  Compiling $@" ; $(FC) $(FFLAGS) $(LDFLAGS); \
+               else \
+                   echo "$@: Fortran compiler unavailable"; fi
+
+default:
+	@make classic
+	@make dejong
+	@make example
+	@make maxbit
+	@make maxchar
+	@make maxint 
+	@make name
+	@make namefull
+
+
+classic: classic.f
+	@$(LINK.f)
+
+dejong: dejong.f
+	@$(LINK.f)
+
+example: example.f
+	@$(LINK.f)
+
+maxbit: maxbit.f
+	@$(LINK.f)
+
+maxchar: maxchar.f
+	@$(LINK.f)
+
+maxint: maxint.f
+	@$(LINK.f)
+
+name: name.f
+	@$(LINK.f)
+
+namefull: namefull.f
+	@$(LINK.f)
+
+clean: 
+	@$(RM) classic dejong example maxbit maxchar maxint name namefull *.o
+

Added: spamassassin/trunk/build/pga/examples/fortran/README
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/fortran/README?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/fortran/README (added)
+++ spamassassin/trunk/build/pga/examples/fortran/README Sun May 28 18:31:49 2017
@@ -0,0 +1,27 @@
+Seven example FORTRAN programs come with PGAPack.  What follows is a listing 
+of the names of the programs and a brief description of their function.
+
+classic.f  -- Optimizes one of Griewank;s test function, Rastrigin's test
+              function, or Schwefel's test function.  All use a real valued
+	      datatype.
+
+dejong.f   -- This program optimizes one of the five functions from the DeJong
+              test suite with a binary string as the chromosome.  Graycoding is
+              an option.
+
+example.f  -- An example from the User's Guide.
+
+maxbit.f   -- A very simple example that maximizes the number of 1's in a
+              binary string.  Does no I/O.
+
+maxchar.f  -- Maximizes the number of z's in a character string.  Does I/O.
+
+maxint.f   -- Maximizes the sum of all alleles in the gene.
+
+name.f     -- Evolves a character string to match a hard-coded string.  Does
+              no I/O, but shows how to use userfunctions InitString, Mutation,
+              and Done.  Also uses an elitist model of evolution with no
+              crossover.
+
+namefull.f -- Same idea as above, but uses all native user defined functions.
+

Added: spamassassin/trunk/build/pga/examples/fortran/classic
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/fortran/classic?rev=1796518&view=auto
==============================================================================
Binary file - no diff available.

Propchange: spamassassin/trunk/build/pga/examples/fortran/classic
------------------------------------------------------------------------------
    svn:executable = *

Propchange: spamassassin/trunk/build/pga/examples/fortran/classic
------------------------------------------------------------------------------
    svn:mime-type = application/x-executable

Added: spamassassin/trunk/build/pga/examples/fortran/classic.f
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/fortran/classic.f?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/fortran/classic.f (added)
+++ spamassassin/trunk/build/pga/examples/fortran/classic.f Sun May 28 18:31:49 2017
@@ -0,0 +1,157 @@
+c     Miscelaneous test functions.
+c
+c     Rather than deal with parallel I/O, we just list the tests here:
+c       1.  Griewank
+c       2.  Rastrigin
+c       3.  Schwefel
+c
+      include 'pgapackf.h'
+      include 'mpif.h'
+
+      double precision  griewank, rastrigin, schwefel
+      external          griewank, rastrigin, schwefel
+      
+      integer           GetIntegerParameter
+      external          GetIntegerParameter
+
+      double precision  Lower(3), Upper(3)
+      integer           NumCoords(3)
+      common /data/     Lower, Upper, NumCoords
+
+      integer ctx
+      integer           testnum, maxiter, i, ierror
+      double precision  l(20), u(20)
+
+c
+c                   user main program                              
+c
+
+      call MPI_Init(ierror)
+
+c     Yes, it's ugly, but it does work...
+      testnum = GetIntegerParameter('Which test? (1-Griewank, 2-Rastrigi
+     &n, 3-Schwefel) ')
+      maxiter = GetIntegerParameter('How many iterations?               
+     &               ')
+
+      do i=1, 20
+         l(i) = Lower(testnum)
+         u(i) = Upper(testnum)
+      enddo
+
+      ctx = PGACreate(PGA_DATATYPE_REAL, NumCoords(testnum),
+     &                PGA_MINIMIZE)
+    
+      call PGASetRandomSeed(ctx, 1)
+
+      call PGASetRealInitRange(ctx, l, u)
+      call PGASetMaxGAIterValue(ctx, maxiter)
+    
+      call PGASetUp(ctx)
+
+      if (testnum .eq. 1)    call PGARun(ctx, griewank)
+      if (testnum .eq. 2)    call PGARun(ctx, rastrigin)
+      if (testnum .eq. 3)    call PGARun(ctx, schwefel)
+
+      call PGADestroy(ctx)
+    
+      call MPI_Finalize(ierror)
+
+      stop
+      end
+
+
+      double precision function griewank(ctx, p, pop)
+      include          'pgapackf.h'
+      integer ctx
+      integer           p, pop, i, len
+      double precision  allele, sum, product
+
+      sum = 0.
+      product = 1.
+      len = PGAGetStringLength(ctx)
+      do i=1, len
+         allele = PGAGetRealAllele(ctx, p, pop, i)
+         sum = sum + (allele * allele / 4000.)
+         product = product * dcos(allele / sqrt((dble(i))))
+      enddo
+
+      griewank = 1. + sum - product
+      return
+      end
+
+
+      double precision function rastrigin(ctx, p, pop)
+      include          'pgapackf.h'
+      integer ctx
+      integer           p, pop, i, len
+      double precision  allele, sum
+
+      sum = 0.
+      len = PGAGetStringLength(ctx)
+      do i=1, len
+         allele = PGAGetRealAllele(ctx, p, pop, i)
+         sum = sum + allele * allele - 10.d0 * 
+     &        dcos(6.28318530718d0 * allele)
+      enddo
+
+      rastrigin = dble(len-1) + sum
+      return
+      end
+
+
+
+      double precision function schwefel(ctx, p, pop)
+      include          'pgapackf.h'
+      integer ctx
+      integer           p, pop, i, len
+      double precision  allele, sum
+
+      sum = 0.
+      len = PGAGetStringLength(ctx)
+      do i=1, len
+         allele = PGAGetRealAllele(ctx, p, pop, i)
+         sum = sum - allele * dsin(dsqrt(dabs(allele)))
+      enddo
+     
+      schwefel = sum
+      return
+      end
+
+
+
+c     Get an integer parameter from the user.  Since this is
+c     typically a parallel program, we must only do I/O on the
+c     "master" process -- process 0.  Once we read the parameter,
+c     we broadcast it to all the other processes, then every 
+c     process returns the correct value.
+c     
+      integer function GetIntegerParameter(query)
+      include 'pgapackf.h'
+      include 'mpif.h'
+      character*52 query
+      integer  rank, tmp, ierror
+
+      call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierror)
+      if (rank .eq. 0) then
+         print *, query
+         read *, tmp
+      endif
+      call MPI_Bcast(tmp, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierror)
+
+      GetIntegerParameter = tmp
+      return
+      end
+
+
+      block data
+      integer i
+      double precision Lower(3), Upper(3)
+      integer NumCoords(3)
+      common /data/    Lower, Upper, NumCoords
+
+      data (NumCoords(i), i=1,3) / 10, 20, 10 /
+      data (Lower(i), i=1,3)     / -512.0, -5.12, -512.0 /
+      data (Upper(i), i=1,3)     / 511.0, 5.11, 511.0 /
+
+      end

Added: spamassassin/trunk/build/pga/examples/fortran/dejong
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/fortran/dejong?rev=1796518&view=auto
==============================================================================
Binary file - no diff available.

Propchange: spamassassin/trunk/build/pga/examples/fortran/dejong
------------------------------------------------------------------------------
    svn:executable = *

Propchange: spamassassin/trunk/build/pga/examples/fortran/dejong
------------------------------------------------------------------------------
    svn:mime-type = application/x-executable

Added: spamassassin/trunk/build/pga/examples/fortran/dejong.f
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/fortran/dejong.f?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/fortran/dejong.f (added)
+++ spamassassin/trunk/build/pga/examples/fortran/dejong.f Sun May 28 18:31:49 2017
@@ -0,0 +1,310 @@
+c  The DeJong test suite.
+c
+c
+
+      include 'pgapackf.h'
+      include 'mpif.h'
+
+      double precision  dejong1, dejong2, dejong3, dejong4, dejong5
+      external          dejong1, dejong2, dejong3, dejong4, dejong5
+
+      integer           GetIntegerParameter
+      external          GetIntegerParameter
+
+      integer           gray_on
+      integer           BinLen(5), NumCoords(5)
+      double precision  Lower(5), Upper(5)
+
+      common /data/     BinLen, NumCoords, Lower, Upper, gray_on
+
+      integer ctx
+      integer           testnum, maxiter, ierror
+
+
+c
+c                   user main program
+c
+
+      call MPI_Init(ierror)
+
+      testnum = GetIntegerParameter('Which test? (1 - 5)        ')
+      gray_on = GetIntegerParameter('Gray-coded? (1=yes, 0 = no)')
+      maxiter = GetIntegerParameter('How many iterations?       ')
+
+      ctx = PGACreate(PGA_DATATYPE_BINARY, 
+     &     BinLen(testnum)*NumCoords(testnum), PGA_MINIMIZE)
+
+      call PGASetMaxGAIterValue(ctx, maxiter)
+      call PGASetRandomSeed(ctx, 1)
+    
+      call PGASetUp(ctx)
+
+      if (testnum .eq. 1)    call PGARun(ctx, dejong1)
+      if (testnum .eq. 2)    call PGARun(ctx, dejong2)
+      if (testnum .eq. 3)    call PGARun(ctx, dejong3)
+      if (testnum .eq. 4)    call PGARun(ctx, dejong4)
+      if (testnum .eq. 5)    call PGARun(ctx, dejong5)
+
+      call printResultInterpretation(ctx, testnum)
+
+      call PGADestroy(ctx)
+    
+      call MPI_Finalize(ierror)
+
+      stop
+      end
+
+
+      double precision function GetTerm(ctx, p, pop, t, problem) 
+      include           'pgapackf.h'
+      integer ctx
+      integer            p, pop, t, problem, len
+      integer            gray_on, BinLen(5), NumCoords(5)
+      double precision   Lower(5), Upper(5)
+      common /data/      BinLen, NumCoords, Lower, Upper, gray_on
+      double precision   x, l, u
+
+      len = BinLen(problem)
+      l   = Lower(problem)
+      u   = Upper(problem)
+
+      if (gray_on .eq. 1) then
+         x = PGAGetRealFromGrayCode(ctx, p, pop, (t-1)*len+1,
+     &        t*len, l, u)
+      else
+         x = PGAGetRealFromBinary(ctx, p, pop, (t-1)*len+1, 
+     &        t*len, l, u)
+      endif
+
+      GetTerm = x
+      return
+      end
+
+
+      double precision function dejong1(ctx, p, pop) 
+      include          'pgapackf.h'
+      integer ctx
+      integer           p, pop
+      double precision  GetTerm
+      external          GetTerm 
+      integer           gray_on, BinLen(5), NumCoords(5)
+      double precision  Lower(5), Upper(5)
+      common /data/     BinLen, NumCoords, Lower, Upper, gray_on
+      integer           i
+      double precision  term, sum
+
+      sum = 0.
+    
+      do i=1, NumCoords(1)
+         term = GetTerm(ctx, p, pop, i, 1)
+         sum = sum + (term * term)
+      enddo
+      
+      dejong1 = sum
+      return
+      end
+
+
+      double precision function dejong2(ctx, p, pop) 
+      include          'pgapackf.h'
+      integer ctx
+      integer           p, pop
+      double precision  GetTerm
+      external          GetTerm
+      integer           gray_on, BinLen(5), NumCoords(5)
+      double precision  Lower(5), Upper(5)
+      common /data/     BinLen, NumCoords, Lower, Upper, gray_on
+      double precision  x1, x2, p1, p2
+    
+      x1 = GetTerm(ctx, p, pop, 1, 2)
+      x2 = GetTerm(ctx, p, pop, 2, 2)
+      p1 = x1 * x1 - x2
+      p2 = 1 - x1
+
+      dejong 2 = 100 * p1 * p1 + p2 * p2
+      return
+      end
+
+
+      double precision function dejong3(ctx, p, pop) 
+      include          'pgapackf.h'
+      integer ctx
+      integer           p, pop, i
+      double precision  GetTerm
+      external          GetTerm
+      double precision  sum
+      external          ffloor
+      integer           gray_on, BinLen(5), NumCoords(5)
+      double precision  Lower(5), Upper(5)
+      common /data/     BinLen, NumCoords, Lower, Upper, gray_on
+      double precision  ffloor
+
+      sum = 0.
+    
+      do i=1, NumCoords(3)
+         sum = sum + ffloor(GetTerm(ctx, p, pop, i, 3)) 
+      enddo
+         
+      dejong3 = sum
+      return
+      end
+
+
+
+      double precision function dejong4(ctx, p, pop) 
+      include          'pgapackf.h'
+      integer ctx
+      integer           p, pop
+      double precision  GetTerm
+      external          GetTerm
+      integer           gray_on, BinLen(5), NumCoords(5)
+      double precision  Lower(5), Upper(5)
+      common /data/     BinLen, NumCoords, Lower, Upper, gray_on
+      integer           i
+      double precision  term, sum
+      
+      sum = 0.
+      do i=1, NumCoords(4)
+         term = GetTerm(ctx, p, pop, i, 4)
+         sum = sum + (i * term * term * term * term)
+      enddo
+    
+      
+      dejong4 = sum + PGARandomGaussian(ctx, 0d0, 1d0)
+      return
+      end
+
+
+      double precision function dejong5(ctx, p, pop) 
+      include          'pgapackf.h'
+      integer ctx
+      integer           p, pop, i, j
+      double precision  GetTerm
+      external          GetTerm
+      integer           gray_on, BinLen(5), NumCoords(5)
+      double precision  Lower(5), Upper(5)
+      common /data/     BinLen, NumCoords, Lower, Upper, gray_on
+      double precision  a(2,25)
+      double precision  sum_over_i, sum_over_j
+
+      sum_over_i = 0.
+      sum_over_j = 0.
+
+      do i=0, 4
+         a(1,5*i+1)   = -32.
+         a(2,i+1)     = -32.
+         
+         a(1,5*i+2) = -16.
+         a(2,i+6)   = -16.
+         
+         a(1,5*i+3) = 0.
+         a(2,i+11)  = 0.
+         
+         a(1,5*i+4) = 16.
+         a(2,i+16)  = 16.
+         
+         a(1,5*i+5) = 32.
+         a(2,i+21)  = 32.
+      enddo
+      
+      
+      do j=1, 25
+         sum_over_i =
+     &        (GetTerm(ctx, p, pop, 1, 5) - a(1,j)) ** 6 +
+     &        (GetTerm(ctx, p, pop, 2, 5) - a(2,j)) ** 6
+         sum_over_j = sum_over_j + (1.0d0 / (dble(j-1) + sum_over_i))
+      enddo
+    
+      dejong5 = 1.0d0 / (0.002d0 + sum_over_j)
+      return
+      end
+
+
+
+c     Since the linker searches this file first, if this function were
+c     called just "floor", PGAPack would break.  (PGAPack uses a floor
+c     function also).
+c
+      double precision function ffloor(x)
+      double precision  x, y
+
+      y = int(x)
+      if (x .lt. 0 .and. x .ne. y) then
+         y = y - 1
+      endif
+      ffloor = y
+
+      end
+
+
+
+
+
+      subroutine printResultInterpretation(ctx, problem)
+      include          'pgapackf.h'
+      include          'mpif.h'
+      integer ctx
+      integer           problem, best, i
+      double precision  GetTerm
+      external          GetTerm
+      integer           gray_on, BinLen(5), NumCoords(5)
+      double precision  Lower(5), Upper(5)
+      common /data/     BinLen, NumCoords, Lower, Upper, gray_on
+      double precision  value
+      integer comm
+
+
+      comm = PGAGetCommunicator(ctx)
+      if (PGAGetRank(ctx, comm) .eq. 0) then
+c      if (PGAGetRank(ctx, MPI_COMM_WORLD) .eq. 0) then
+         best = PGAGetBestIndex(ctx, PGA_OLDPOP)
+	
+         print *, 'The real interpretation:'
+         do i=1, NumCoords(problem)
+	    value = GetTerm(ctx, best, PGA_OLDPOP, i, problem)
+	    
+            print *, '#', i, ': ', value
+         enddo
+
+      endif
+
+      return
+      end
+
+
+c     Get an integer parameter from the user.  Since this is
+c     typically a parallel program, we must only do I/O on the
+c     "master" process -- process 0.  Once we read the parameter,
+c     we broadcast it to all the other processes, then every 
+c     process returns the correct value.
+c     
+      integer function GetIntegerParameter(query)
+      include      'pgapackf.h'
+      include      'mpif.h'
+      character*27  query
+      integer       rank, tmp, ierror
+
+      call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierror)
+      if (rank .eq. 0) then
+         print *, query
+         read *, tmp
+      endif
+      call MPI_Bcast(tmp, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierror)
+
+      GetIntegerParameter = tmp
+      return
+      end
+
+
+      block data
+      integer i
+      double precision Lower(5), Upper(5)
+      integer gray_on, BinLen(5), NumCoords(5)
+      common /data/ BinLen, NumCoords, Lower, Upper, gray_on
+
+      data (BinLen(i), i=1,5)    / 10, 12, 10, 8, 17 /
+      data (NumCoords(i), i=1,5) / 3, 2, 5, 30, 2 /
+      data (Lower(i), i=1,5)     / -5.12,-2.048,-5.12,-1.28,-65.536 /
+      data (Upper(i), i=1,5)     / 5.11, 2.047, 5.11, 1.27, 65.535 /
+
+      end

Added: spamassassin/trunk/build/pga/examples/fortran/example
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/fortran/example?rev=1796518&view=auto
==============================================================================
Binary file - no diff available.

Propchange: spamassassin/trunk/build/pga/examples/fortran/example
------------------------------------------------------------------------------
    svn:executable = *

Propchange: spamassassin/trunk/build/pga/examples/fortran/example
------------------------------------------------------------------------------
    svn:mime-type = application/x-executable

Added: spamassassin/trunk/build/pga/examples/fortran/example.f
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/fortran/example.f?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/fortran/example.f (added)
+++ spamassassin/trunk/build/pga/examples/fortran/example.f Sun May 28 18:31:49 2017
@@ -0,0 +1,66 @@
+      include 'pgapackf.h'
+
+      double precision evaluate
+      integer          myMutation
+      external         evaluate, myMutation
+      
+      integer ctx
+      integer          i, ierror
+      integer          lower(10), upper(10)
+
+      do i=1, 10
+         lower(i) = 1
+         upper(i) = 10
+      enddo
+
+      call MPI_Init(ierror)
+
+      ctx = PGACreate         (PGA_DATATYPE_INTEGER, 10, PGA_MAXIMIZE)
+      call PGASetUserFunction (ctx, PGA_USERFUNCTION_MUTATION,
+     &                         myMutation)
+      call PGASetIntegerInitRange(ctx, lower, upper)
+      call PGASetUp              (ctx)
+      call PGARun                (ctx, evaluate)
+      call PGADestroy            (ctx)
+
+      call MPI_Finalize(ierror)
+
+      stop
+      end
+
+
+      integer function myMutation(ctx, p, pop, pm)
+      include          'pgapackf.h'
+      integer ctx
+      integer           p, pop
+      double precision  pm
+      integer           stringlen, i, k, count
+
+      count = 0
+      stringlen = PGAGetStringLength(ctx)
+      do i=1, stringlen
+         if (PGARandomFlip(ctx, pm) .eq. PGA_TRUE) then
+            k = PGARandomInterval(ctx, 1, stringlen)
+            call PGASetIntegerAllele(ctx, p, pop, i, k)
+            count = count + 1
+         endif
+      enddo
+      myMutation = count
+      return
+      end
+
+
+      double precision function evaluate(ctx, p, pop)
+      include          'pgapackf.h'
+      integer ctx
+      integer          p, pop
+      integer          stringlen, i, sum
+
+      sum = 0
+      stringlen = PGAGetStringLength(ctx)
+      do i=1, stringlen
+         sum = sum + PGAGetIntegerAllele(ctx, p, pop, i)
+      enddo
+      evaluate = sum
+      return
+      end

Added: spamassassin/trunk/build/pga/examples/fortran/maxbit
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/fortran/maxbit?rev=1796518&view=auto
==============================================================================
Binary file - no diff available.

Propchange: spamassassin/trunk/build/pga/examples/fortran/maxbit
------------------------------------------------------------------------------
    svn:executable = *

Propchange: spamassassin/trunk/build/pga/examples/fortran/maxbit
------------------------------------------------------------------------------
    svn:mime-type = application/x-executable

Added: spamassassin/trunk/build/pga/examples/fortran/maxbit.f
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/fortran/maxbit.f?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/fortran/maxbit.f (added)
+++ spamassassin/trunk/build/pga/examples/fortran/maxbit.f Sun May 28 18:31:49 2017
@@ -0,0 +1,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

Added: spamassassin/trunk/build/pga/examples/fortran/maxchar
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/fortran/maxchar?rev=1796518&view=auto
==============================================================================
Binary file - no diff available.

Propchange: spamassassin/trunk/build/pga/examples/fortran/maxchar
------------------------------------------------------------------------------
    svn:executable = *

Propchange: spamassassin/trunk/build/pga/examples/fortran/maxchar
------------------------------------------------------------------------------
    svn:mime-type = application/x-executable

Added: spamassassin/trunk/build/pga/examples/fortran/maxchar.f
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/fortran/maxchar.f?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/fortran/maxchar.f (added)
+++ spamassassin/trunk/build/pga/examples/fortran/maxchar.f Sun May 28 18:31:49 2017
@@ -0,0 +1,123 @@
+c     Does not work, run it and see what happens.
+
+
+c       
+c     This is a test program for PGAPack.  The objective is to 
+c     maximize the number of 'z's in a chromosome.
+c       
+
+      include 'pgapackf.h'
+      include 'mpif.h'
+      
+      double precision NumberOfZs
+      integer          myMutation
+      integer          GetIntegerParameter
+      external         NumberOfZs
+      external         myMutation
+      external         GetIntegerParameter
+      
+      integer ctx
+      integer          len, maxiter, ierror
+      
+c     
+c     user main program
+c     
+      call MPI_Init(ierror)
+      
+      len     = GetIntegerParameter('String length?      ')
+      maxiter = GetIntegerParameter('How many iterations?')
+      
+      ctx     = PGACreate(PGA_DATATYPE_CHARACTER, len, PGA_MAXIMIZE)
+      
+      call PGASetRandomSeed(ctx, 1)
+      call PGASetMaxGAIterValue(ctx, maxiter)
+      call PGASetUserFunction(ctx, PGA_USERFUNCTION_MUTATION,
+     &     myMutation)
+      
+      call PGASetUp(ctx)
+      call PGARun(ctx, NumberOfZs)
+      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 NumberOfZs(ctx, p, pop)
+      include     'pgapackf.h'
+      integer ctx
+      integer      p, pop, i, nzs, stringlen
+      
+      stringlen = PGAGetStringLength(ctx)
+      
+      nzs = 0
+      do i=1, stringlen
+         if (PGAGetCharacterAllele(ctx, p, pop, i) .eq. 'z') then
+            nzs = nzs + 1
+         endif
+      enddo
+      
+      NumberOfZs = dble(nzs)
+      return
+      end
+
+
+
+c     Custom mutation function.  Searches for an unset bit, 
+c     then sets it.  Returns the number of bits that are changed.
+c     
+      integer function myMutation(ctx, p, pop, mr)
+      include          'pgapackf.h'
+      integer ctx
+      integer           p, pop, i, count
+      character         c
+      double precision  mr
+
+
+      count = 0
+      do i=PGAGetStringLength(ctx), 1, -1
+         if (PGARandomFlip(ctx, mr) .eq. 1) then
+            c = PGAGetCharacterAllele(ctx, p, pop, i)
+            if (c .ne. 'z') then
+               call PGASetCharacterAllele(ctx, p, pop, i,
+     &              char(ichar(c)+1))
+               count = count + 1
+            endif
+         endif
+      enddo
+      
+      myMutation = count
+      return
+      end
+
+
+c     Get an integer parameter from the user.  Since this is
+c     typically a parallel program, we must only do I/O on the
+c     "master" process -- process 0.  Once we read the parameter,
+c     we broadcast it to all the other processes, then every 
+c     process returns the correct value.
+c     
+      integer function GetIntegerParameter(query)
+      include      'pgapackf.h'
+      include      'mpif.h'
+      character*20  query
+      integer       rank, tmp
+
+      call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierror)
+      if (rank .eq. 0) then
+         print *, query
+         read *, tmp
+      endif
+      call MPI_Bcast(tmp, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierror)
+
+      GetIntegerParameter = tmp
+      return
+      end

Added: spamassassin/trunk/build/pga/examples/fortran/maxint
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/fortran/maxint?rev=1796518&view=auto
==============================================================================
Binary file - no diff available.

Propchange: spamassassin/trunk/build/pga/examples/fortran/maxint
------------------------------------------------------------------------------
    svn:executable = *

Propchange: spamassassin/trunk/build/pga/examples/fortran/maxint
------------------------------------------------------------------------------
    svn:mime-type = application/x-executable

Added: spamassassin/trunk/build/pga/examples/fortran/maxint.f
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/fortran/maxint.f?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/fortran/maxint.f (added)
+++ spamassassin/trunk/build/pga/examples/fortran/maxint.f Sun May 28 18:31:49 2017
@@ -0,0 +1,113 @@
+c     
+c     This is a test program for PGAPack.  The objective is to 
+c     maximize each allele.  The evaluation function sums all allele
+c     values.
+c     
+
+      include 'pgapackf.h'
+      include 'mpif.h'
+
+      double precision evaluate
+      integer          myMutation
+      integer          GetIntegerParameter
+      external         GetIntegerParameter, evaluate, myMutation
+
+c     
+c     user main program
+c     
+      integer ctx
+      integer    len, maxiter, ierror
+
+
+      call MPI_Init(ierror)
+
+      len     = GetIntegerParameter('String length?      ')
+      maxiter = GetIntegerParameter('How many iterations?')
+
+      ctx = PGACreate(PGA_DATATYPE_INTEGER, len, PGA_MAXIMIZE)
+
+      call PGASetRandomSeed(ctx, 1)
+      call PGASetUserFunction(ctx, PGA_USERFUNCTION_MUTATION,
+     &     myMutation)
+      call PGASetIntegerInitPermute(ctx, 1, len)
+
+      call PGASetMaxGAIterValue(ctx, maxiter)
+      call PGASetNumReplaceValue(ctx, 90)
+      call PGASetMutationAndCrossoverFlag(ctx, PGA_TRUE)
+      call PGASetPrintOptions(ctx, PGA_REPORT_AVERAGE)
+
+      call PGASetUp(ctx)
+
+      call PGARun(ctx, evaluate)
+      call PGADestroy(ctx)
+
+      call MPI_Finalize(ierror)
+
+      stop
+      end
+
+c     Custom mutation function.  Searches for an unset bit, 
+c     then sets it.  Returns the number of bits that are changed.
+c     
+      integer function myMutation(ctx, p, pop, mr)
+      include          'pgapackf.h'
+      integer ctx, p, pop
+      double precision  mr
+      integer           stringlen, i, v, count
+
+      stringlen = PGAGetStringLength(ctx)
+      count     = 0
+
+      do i=stringlen, 1, -1
+         if (PGARandomFlip(ctx, mr) .eq. PGA_TRUE) then
+	    v = PGARandomInterval(ctx, 1, stringlen)
+            call PGASetIntegerAllele(ctx, p, pop, i, v)
+	    count = count + 1
+         endif
+      enddo
+
+      myMutation = count
+      return
+      end
+
+
+      double precision function evaluate(ctx, p, pop)
+      include  'pgapackf.h'
+      integer ctx, p, pop
+      integer   stringlen, i, sum
+
+
+      stringlen = PGAGetStringLength(ctx)
+      sum       = 0
+
+      do i=stringlen, 1, -1
+         sum = sum + PGAGetIntegerAllele(ctx, p, pop, i) 
+      enddo
+
+      evaluate = dble(sum)
+      return
+      end
+
+
+c     Get an integer parameter from the user.  Since this is
+c     typically a parallel program, we must only do I/O on the
+c     "master" process -- process 0.  Once we read the parameter,
+c     we broadcast it to all the other processes, then every 
+c     process returns the correct value.
+c     
+      integer function GetIntegerParameter(query)
+      include      'pgapackf.h'
+      include      'mpif.h'
+      character*20  query
+      integer       rank, tmp, ierror
+
+      call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierror)
+      if (rank .eq. 0) then
+         print *, query
+         read *, tmp
+      endif
+      call MPI_Bcast(tmp, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierror)
+
+      GetIntegerParameter = tmp
+      return
+      end

Added: spamassassin/trunk/build/pga/examples/fortran/mpif.h
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/examples/fortran/mpif.h?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/examples/fortran/mpif.h (added)
+++ spamassassin/trunk/build/pga/examples/fortran/mpif.h Sun May 28 18:31:49 2017
@@ -0,0 +1 @@
+link ../../include/mpif.h
\ No newline at end of file