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 [16/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/...

Added: spamassassin/trunk/build/pga/source/random.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/source/random.c?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/source/random.c (added)
+++ spamassassin/trunk/build/pga/source/random.c Sun May 28 18:31:49 2017
@@ -0,0 +1,380 @@
+/*
+COPYRIGHT
+
+The following is a notice of limited availability of the code, and disclaimer
+which must be included in the prologue of the code and in all source listings
+of the code.
+
+(C) COPYRIGHT 2008 University of Chicago
+
+Permission is hereby granted to use, reproduce, prepare derivative works, and
+to redistribute to others. This software was authored by:
+
+D. Levine
+Mathematics and Computer Science Division 
+Argonne National Laboratory Group
+
+with programming assistance of participants in Argonne National 
+Laboratory's SERS program.
+
+GOVERNMENT LICENSE
+
+Portions of this material resulted from work developed under a
+U.S. Government Contract and are subject to the following license: the
+Government is granted for itself and others acting on its behalf a paid-up,
+nonexclusive, irrevocable worldwide license in this computer software to
+reproduce, prepare derivative works, and perform publicly and display
+publicly.
+
+DISCLAIMER
+
+This computer code material was prepared, in part, as an account of work
+sponsored by an agency of the United States Government. Neither the United
+States, nor the University of Chicago, nor any of their employees, makes any
+warranty express or implied, or assumes any legal liability or responsibility
+for the accuracy, completeness, or usefulness of any information, apparatus,
+product, or process disclosed, or represents that its use would not infringe
+privately owned rights.
+*/
+
+/*****************************************************************************
+*     FILE: random.c: This file contains routines to generate randomness.
+*
+*     Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle,
+*              Brian P. Walenz
+*****************************************************************************/
+
+#include "pgapack.h"
+
+/*U****************************************************************************
+   PGARandomFlip - flip a biased coin and return PGA_TRUE if the coin is
+   a "winner."  Otherwise, return PGA_FALSE.
+
+   Category: Utility
+
+   Inputs:
+      ctx - context variable
+      p   - biased probability (.5 is a fair coin)
+
+   Outputs:
+      PGA_TRUE or PGA_FALSE
+
+   Example:
+      To return PGA_TRUE approximately seventy percent of the time, use
+
+      PGAContext *ctx;
+      int p;
+      :
+      PGARandomFlip(ctx, 0.7)
+
+****************************************************************************U*/
+int PGARandomFlip ( PGAContext *ctx, double p )
+{
+    PGADebugEntered("PGARandomFlip");
+
+    PGADebugExited("PGARandomFlip");
+
+    return( (PGARandom01(ctx, 0) < p) ? PGA_TRUE : PGA_FALSE);
+}
+
+
+/*U****************************************************************************
+   PGARandomInterval - returns a uniform random number on the specified
+   interval
+
+   Category: Utility
+
+   Inputs:
+      ctx - context variable
+      start - starting (integer) value of the interval
+      end   - ending   (integer) value of the interval
+
+   Outputs:
+      A uniformly distributed random number in the interval [start, end].
+
+   Example:
+      Generate a value uniformly random from the interval [0,99]
+
+      PGAContext *ctx;
+      :
+      PGARandomInterval(ctx, 0, 99);
+
+****************************************************************************U*/
+int PGARandomInterval( PGAContext *ctx, int start, int end)
+{
+    PGADebugEntered("PGARandomInterval");
+    
+    PGADebugExited("PGARandomInterval");
+
+    return( (int)floor(PGARandom01(ctx, 0) * (double)(end-start+1) ) + start );
+    
+/*
+   The original call...
+
+   return(ceil( (double)(end-start+1) * PGARandom01(ctx, 0) )+start-1);
+*/
+}
+
+
+/*****************************************************************************
+*  This is a C language implementation of the universal random number        *
+*  generator proposed by G. Marsaglia and A. Zaman and translated from       *
+*  F. James' version.                                                        *
+*                                                                            *
+*  F. James                                                                  *
+*  A review of pseudorandom number generators                                *
+*  Computer Physics Communication                                            *
+*  60 (1990) 329-344                                                         *
+*                                                                            *
+*  G. Marsaglia, A. Zaman, W. Tseng                                          *
+*  Stat Prob. Letter                                                         *
+*  9 (1990) 35.                                                              *
+*                                                                            *
+*  G. Marsaglia, A. Zaman                                                    *
+*  FSU-SCRI-87-50                                                            *
+*                                                                            *
+*  This algorithm is a combination of a lagged Fibonacci and arithmetic      *
+*  sequence (F. James) generator with period of 2^144.  It provides 32-bit   *
+*  floating point numbers in the range from zero to one.  It is claimed to   *
+*  be portable and provides bit-identical results on all machines with at    *
+*  least 24-bit mantissas.                                                   *
+*                                                                            *
+*  PGARandom01 should be initialized with a 32-bit integer seed such that    *
+*  0 <= seed <= 900,000,000.  Each of these 900,000,000 values gives rise    *
+*  to an independent sequence of ~ 10^30.                                    *
+*                                                                            *
+*  warning on use of static storage class on thread shared memory machines   *
+*****************************************************************************/
+/*U****************************************************************************
+   PGARandom01 - generates a uniform random number on the interval [0,1)
+   If the second argument is 0 it returns the next random number in the
+   sequence.  Otherwise, the second argument is used as a new seed for the
+   population
+
+   Category: Utility
+
+   Inputs:
+      ctx     - context variable
+      newseed - either 0 to get the next random number, or nonzero
+                to reseed
+   Outputs:
+      A random number on the interval [0,1)
+
+   Example:
+      To get the next random number use
+
+      PGAContext *ctx;
+      double r;
+      :
+      r = PGARandom01(ctx,0);
+
+****************************************************************************U*/
+double PGARandom01( PGAContext *ctx, int newseed )
+{
+
+    /* initialization variables */
+    int ij, kl, i, j, k, l, m, ii, jj;
+    float s, t;
+
+    /* random number variables */
+    static int seed=1;      /* default seed if none specified */
+    static int i96, j96;
+    static float u[97], uni, c, cd, cm;
+
+
+    PGADebugEntered("PGARandom01");
+
+    /* initialization */
+/*     printf("i96 = %d\tj96 = %d\n", i96, j96); */
+
+    if ( newseed != 0 ) {
+
+        seed = newseed % 900000000;
+        ij   = seed / 30082;
+        kl   = seed - 30082 * ij;
+        i    = ( (ij/177) % 177 ) + 2;
+        j    = (  ij      % 177 ) + 2;
+        k    = ( (kl/169) % 178 ) + 1;
+        l    = (  kl      % 169 );
+
+        for ( ii=0; ii<97; ii++ ) {
+
+            s = 0.0;
+            t = 0.5;
+
+            for ( jj=0; jj<24; jj++ ) {
+
+                m = ( ((i*j) % 179) * k ) % 179;
+                i = j;
+                j = k;
+                k = m;
+                l = ( (53*l) + 1 ) % 169;
+                if ( ( (l*m) % 64 ) >= 32 )
+                    s += t;
+                t *= .5;
+            }
+
+            u[ii] = s;
+        }
+
+        c   = 362436.  /16777216.;
+        cd  = 7654321. /16777216.;
+        cm  = 16777213./16777216.;
+        i96 = 96;
+        j96 = 32;
+    }
+
+    /* random number generation */
+    uni = u[i96] - u[j96];
+    if ( uni < 0. ) uni += 1.0;
+    u[i96] = uni;
+    i96--;
+    if ( i96 < 0  ) i96 = 96;
+    j96--;
+    if ( j96 < 0  ) j96 = 96;
+    c   -= cd;
+    if ( c   < 0. ) c += cm;
+    uni -= c;
+    if ( uni < 0. ) uni += 1.0;
+
+    PGADebugExited("PGARandom01");
+    return( (double) uni);
+}
+
+/*U****************************************************************************
+   PGARandomUniform - returns a uniform random number on the interval
+   [start,end]
+
+   Category: Utility
+
+   Inputs:
+      ctx - context variable
+      start - starting (double) value of the interval
+      end   - ending   (double) value of the interval
+
+   Outputs:
+      A random number on the interval [start,end]
+
+   Example:
+      Generate a uniform random number on the interval [-0.5, 1.5]
+
+      PGAContext *ctx;
+      double r;
+      :
+      r = PGARandomUniform(ctx, -0.5, 1.5);
+
+****************************************************************************U*/
+double PGARandomUniform( PGAContext *ctx, double start, double end)
+{
+    double val, r;
+
+    PGADebugEntered("PGARandomUniform");
+
+    r = PGARandom01(ctx, 0);
+    val = (end-start) * r + start;
+
+    PGADebugExited("PGARandomUniform");
+
+    return(val);
+}
+
+
+/*U****************************************************************************
+   PGARandomGaussian - returns an approximation to a Gaussian random number
+
+   Category: Utility
+
+   Inputs:
+       mean  - the mean of the Gaussian distribution
+       sigma - the standard deviation of the Gaussian distribution
+
+   Outputs:
+      A random number selected from a Gaussian distribution with given
+      mean and standard deviation
+
+   Example:
+      To generate a Gaussian random number with mean 0.0 and standard
+      deviation 1.0 use
+
+      PGAContext *ctx;
+      :
+      r = PGARandomGaussian(ctx, 0.0, 1.0);
+
+****************************************************************************U*/
+double PGARandomGaussian( PGAContext *ctx, double mean, double sigma)
+{
+    int i;
+    double sum = 0.;
+
+    PGADebugEntered("PGARandomGaussian");
+
+    for (i=11;i>=0; i--)
+        sum += PGARandom01(ctx, 0);
+
+    PGADebugExited("PGARandomGaussian");
+
+    return ( (sum-6.0) * sigma + mean );
+}
+
+/*U***************************************************************************
+   PGAGetRandomSeed - returns the integer to seed random numbers with
+
+   Category: Utility
+
+   Inputs:
+      ctx - context variable
+
+   Outputs:
+      The seed for the random number generator
+
+   Example:
+      PGAContext *ctx;
+      int seed;
+      :
+      seed = PGAGetRandomSeed(ctx);
+
+***************************************************************************U*/
+int PGAGetRandomSeed(PGAContext *ctx)
+{
+    PGADebugEntered("PGAGetRandomSeed");
+
+    PGADebugExited("PGAGetRandomSeed");
+
+    return(ctx->init.RandomSeed);
+}
+
+/*U****************************************************************************
+   PGASetRandomSeed - set a seed for the random number generator.  The
+   default is to use a random seed.  Specifying a seed exlicitly allows
+   for reproducibility of runs.
+
+   Category: Utility
+
+   Inputs:
+      ctx  - context variable
+      seed - seed  for the random number generator
+
+   Outputs:
+      None
+
+   Example:
+      PGAContext *ctx;
+      :
+      PGASetRandomSeed(ctx,1);
+
+****************************************************************************U*/
+void PGASetRandomSeed(PGAContext *ctx, int seed)
+{
+#define MAX_PROCESSORS 2048
+
+    PGADebugEntered("PGASetRandomSeed");
+    PGAFailIfSetUp("PGASetRandomSeed");
+
+    if ((seed < 1) || (seed + MAX_PROCESSORS > 900000000))
+	PGAError ( ctx, "PGASetRandomSeed: Invalid value of seed:",
+		  PGA_FATAL, PGA_INT, (void *) &seed);
+    else
+	ctx->init.RandomSeed = seed;
+    
+    PGADebugExited("PGASetRandomSeed");
+}

Added: spamassassin/trunk/build/pga/source/real.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/source/real.c?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/source/real.c (added)
+++ spamassassin/trunk/build/pga/source/real.c Sun May 28 18:31:49 2017
@@ -0,0 +1,920 @@
+/*
+COPYRIGHT
+
+The following is a notice of limited availability of the code, and disclaimer
+which must be included in the prologue of the code and in all source listings
+of the code.
+
+(C) COPYRIGHT 2008 University of Chicago
+
+Permission is hereby granted to use, reproduce, prepare derivative works, and
+to redistribute to others. This software was authored by:
+
+D. Levine
+Mathematics and Computer Science Division 
+Argonne National Laboratory Group
+
+with programming assistance of participants in Argonne National 
+Laboratory's SERS program.
+
+GOVERNMENT LICENSE
+
+Portions of this material resulted from work developed under a
+U.S. Government Contract and are subject to the following license: the
+Government is granted for itself and others acting on its behalf a paid-up,
+nonexclusive, irrevocable worldwide license in this computer software to
+reproduce, prepare derivative works, and perform publicly and display
+publicly.
+
+DISCLAIMER
+
+This computer code material was prepared, in part, as an account of work
+sponsored by an agency of the United States Government. Neither the United
+States, nor the University of Chicago, nor any of their employees, makes any
+warranty express or implied, or assumes any legal liability or responsibility
+for the accuracy, completeness, or usefulness of any information, apparatus,
+product, or process disclosed, or represents that its use would not infringe
+privately owned rights.
+*/
+
+/*****************************************************************************
+*     FILE: real.c: This file contains the routines specific to the floating
+*                   point data structure
+*
+*     Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle,
+*              Brian P. Walenz
+*****************************************************************************/
+
+#include <pgapack.h>
+
+/*U****************************************************************************
+   PGASetRealAllele - sets the value of real-valued allele i in string p
+   in population pop
+
+   Category: Fitness & Evaluation
+
+   Inputs:
+      ctx - context variable
+      p   - string index
+      pop - symbolic constant of the population the string is in
+      i   - allele index
+      val - real value to set the allele to
+
+   Outputs:
+      The specified allele in p is modified by side-effect.
+
+   Example:
+      Sets the value of the ith allele of string p in population PGA_NEWPOP
+      to 1.57
+
+      PGAContext *ctx;
+      int i, p;
+      :
+      PGASetRealAllele ( ctx, p, PGA_NEWPOP, i, 1.57)
+
+****************************************************************************U*/
+void PGASetRealAllele (PGAContext *ctx, int p, int pop, int i, double value)
+{
+    PGAIndividual *ind;
+    PGAReal      *chrom;
+
+    PGADebugEntered("PGASetRealAllele");
+    PGACheckDataType("PGASetRealAllele", PGA_DATATYPE_REAL);
+
+    ind = PGAGetIndividual ( ctx, p, pop );
+    chrom = (PGAReal *)ind->chrom;
+    chrom[i] = value;
+
+    PGADebugExited("PGASetRealAllele");
+}
+
+/*U****************************************************************************
+   PGAGetRealAllele - returns the value of real-valued allele i in string p
+   in population pop
+
+   Category: Fitness & Evaluation
+
+   Inputs:
+      ctx - context variable
+      p   - string index
+      pop - symbolic constant of the population the string is in
+      i   - allele index
+
+   Outputs:
+      The value of allele i
+
+   Example:
+      Returns the value of the ith real-valued allele of string p
+      in population PGA_NEWPOP
+
+      PGAContext *ctx;
+      int p, i, r;
+      r =  PGAGetRealAllele (ctx, p, PGA_NEWPOP, i)
+
+****************************************************************************U*/
+double PGAGetRealAllele (PGAContext *ctx, int p, int pop, int i)
+{
+    PGAIndividual *ind;
+    PGAReal      *chrom;
+
+    PGADebugEntered("PGAGetRealAllele");
+    PGACheckDataType("PGAGetRealAllele", PGA_DATATYPE_REAL);
+
+    ind = PGAGetIndividual ( ctx, p, pop );
+    chrom = (PGAReal *)ind->chrom;
+
+    PGADebugExited("PGAGetRealAllele");
+
+    return( (double) chrom[i] );
+}
+
+/*U****************************************************************************
+  PGASetRealInitPercent - sets the upper and lower bounds for randomly
+  initializing real-valued genes.  For each gene these bounds define an
+  interval from which the initial allele value is selected uniformly randomly.
+  With this routine the user specifies a median value and a percent offset
+  for each allele.
+
+  Category: Initialization
+
+  Inputs:
+     ctx     - context variable
+     median  - an array containing the mean value of the interval
+     percent - an array containing the percent offset to add and subtract to
+               the median to define the interval
+
+  Outputs:
+
+  Example:
+     Set the initialization routines to select a value for each real-valued
+     gene i uniformly randomly from the interval [i-v,i+v], where $v = i/2$.
+     Assumes all strings are the same length.
+
+     PGAContext *ctx;
+     double *median, *percent;
+     int i, stringlen;
+     :
+     stringlen = PGAGetStringLength(ctx);
+     median  = (double *) malloc(stringlen*sizeof(double));
+     percent = (double *) malloc(stringlen*sizeof(double));
+     for(i=0;i<stringlen;i++) {
+        median[i]  = (double) i;
+        percent[i] = 0.5;
+     }
+     PGASetRealInitPercent(ctx, median, percent);
+
+****************************************************************************U*/
+void PGASetRealInitPercent ( PGAContext *ctx, double *median, double *percent)
+{
+     int i;
+     int stringlen;
+     double offset;
+
+    PGADebugEntered("PGASetRealInitPercent");
+    PGAFailIfSetUp("PGASetRealInitPercent");
+    PGACheckDataType("PGASetRealInitPercent", PGA_DATATYPE_REAL);
+
+    stringlen = PGAGetStringLength(ctx);
+    for (i=0; i<stringlen; i++) {
+    }
+    for (i=0; i<stringlen; i++) {
+         offset = fabs(median[i] * percent[i]);
+         ctx->init.RealMin[i] = median[i] - offset;
+         ctx->init.RealMax[i] = median[i] + offset;
+         
+    }
+    ctx->init.RealType = PGA_RINIT_PERCENT;
+
+    PGADebugExited("PGASetRealInitPercent");
+}
+
+/*U****************************************************************************
+  PGASetRealInitRange - sets the upper and lower bounds for randomly
+  initializing real-valued genes.  For each gene these bounds define an
+  interval from which the initial allele value is selected uniformly randomly.
+  The user specifies two arrays containing lower and bound for each gene to
+  define the interval.  This is the default strategy for initializing
+  real-valued strings.  The default interval is $[0,1.0]$ for each gene.
+
+  Category: Initialization
+
+  Inputs:
+     ctx - context variable
+     min - array containing the lower bound of the interval for each gene
+     mac - array containing the upper bound of the interval for each gene
+
+  Outputs:
+
+  Example:
+     Set the initialization routines to select a value for each real-valued
+     gene i uniformly randomly from the interval [-10.,i]
+     Assumes all strings are of the same length.
+
+     PGAContext *ctx;
+     double *low, *high;
+     int i, stringlen;
+     :
+     stringlen = PGAGetStringLength(ctx);
+     low  = (double *) malloc(stringlen*sizeof(double));
+     high = (double *) malloc(stringlen*sizeof(double));
+     for(i=0;i<stringlen;i++) {
+        low[i]  = -10.0;
+        high[i] = i;
+     }
+     PGASetRealInitRange(ctx, low, high);
+
+****************************************************************************U*/
+void PGASetRealInitRange (PGAContext *ctx, double *min, double *max)
+{
+     int i;
+    PGADebugEntered("PGASetRealInitRange");
+    PGAFailIfSetUp("PGASetRealInitRange");
+    PGACheckDataType("PGASetRealInitRange", PGA_DATATYPE_REAL);
+
+    for (i=ctx->ga.StringLen-1; i>=0; i--) {
+         if (max[i] < min[i])
+              PGAError(ctx, "PGASetRealInitRange: Lower bound exceeds upper "
+                       "bound for allele #", PGA_FATAL, PGA_INT, (void *) &i);
+         else
+         {
+              ctx->init.RealMin[i] = min[i];
+              ctx->init.RealMax[i] = max[i];
+         }
+    }
+    ctx->init.RealType = PGA_RINIT_RANGE;
+
+    PGADebugExited("PGASetRealInitRange");
+}
+
+
+/*U***************************************************************************
+  PGAGetMinRealInitValue - returns the minimum value used to randomly
+  initialize allele i in a real string
+
+   Category: Initialization
+
+   Inputs:
+      ctx - context variable
+      i   - an allele position
+
+   Outputs:
+      The minimum value used to randomly initialize allele i
+
+   Example:
+      PGAContext *ctx;
+      int min;
+      :
+      min = PGAGetMinRealInitValue(ctx, 0);
+
+***************************************************************************U*/
+double PGAGetMinRealInitValue (PGAContext *ctx, int i)
+{
+    PGADebugEntered("PGAGetMinRealInitValue");
+    PGAFailIfNotSetUp("PGAGetMinRealInitValue");
+    PGACheckDataType("PGAGetMinRealInitValue", PGA_DATATYPE_REAL);
+
+    if (i < 0 || i >= ctx->ga.StringLen)
+         PGAError(ctx, "PGAGetMinRealInitValue: Index out of range:",
+                  PGA_FATAL, PGA_INT, (int *) &i);
+
+    PGADebugExited("PGAGetMinRealInitValue");
+
+    return(ctx->init.RealMin[i]);
+}
+
+/*U***************************************************************************
+  PGAGetMaxRealInitValue - returns the maximum value used to randomly
+  initialize allele i in a real string
+
+   Category: Initialization
+
+   Inputs:
+      ctx - context variable
+      i   - an allele position
+
+   Outputs:
+      The maximum value used to randomly initialize allele i
+
+   Example:
+      PGAContext *ctx;
+      int max;
+      :
+      max = PGAGetMaxRealInitValue(ctx, 0);
+
+***************************************************************************U*/
+double PGAGetMaxRealInitValue (PGAContext *ctx, int i)
+{
+    PGADebugEntered("PGAGetMaxRealInitValue");
+    PGAFailIfNotSetUp("PGAGetMaxRealInitValue");
+    PGACheckDataType("PGAGetMaxRealInitValue", PGA_DATATYPE_REAL);
+
+    if (i < 0 || i >= ctx->ga.StringLen)
+         PGAError(ctx, "PGAGetMaxRealInitValue: Index out of range:",
+                  PGA_FATAL, PGA_INT, (int *) &i);
+
+    PGADebugExited("PGAGetMaxRealInitValue");
+
+    return(ctx->init.RealMax[i]);
+}
+
+
+/*U***************************************************************************
+  PGAGetRealInitType - returns the type of scheme used to randomly
+  initialize strings of data type PGA_DATATYPE_REAL.
+
+   Category: Initialization
+
+   Inputs:
+      ctx - context variable
+
+   Outputs:
+      Returns the integer corresponding to the symbolic constant
+      used to specify the scheme used to initialize real strings
+
+   Example:
+      PGAContext *ctx;
+      int inittype;
+      :
+      inittype = PGAGetRealInitType(ctx);
+      switch (inittype) {
+      case PGA_RINIT_PERCENT:
+          printf("Data Type = PGA_RINIT_PERCENT\n");
+          break;
+      case PGA_RINIT_RANGE:
+          printf("Data Type = PGA_RINIT_RANGE\n");
+          break;
+      }
+
+***************************************************************************U*/
+int PGAGetRealInitType (PGAContext *ctx)
+{
+    PGADebugEntered("PGAGetRealInitType");
+    PGAFailIfNotSetUp("PGAGetRealInitType");
+    PGACheckDataType("PGAGetRealInitType", PGA_DATATYPE_REAL);
+
+    PGADebugExited("PGAGetRealInitType");
+
+    return(ctx->init.RealType);
+}
+
+
+/*I****************************************************************************
+   PGARealCreateString - Allocate memory for a string of type PGAReal
+
+   Inputs:
+      ctx      - context variable
+      p        - string index
+      pop      - symbolic constant of the population string p is in
+      initflag - A true/false flag used in conjunction with ctx->ga.RandomInit
+                 to initialize the string either randomly or set to zero
+
+   Outputs:
+
+   Example:
+      Allocates memory and assigns the address of the allocated memory to
+      the real string field (ind->chrom) of the individual.  Also, clears
+      the string.
+
+      PGAContext *ctx;
+      int p;
+      :
+      PGARealCreateString( ctx, p, PGA_NEWPOP, PGA_FALSE );
+
+****************************************************************************I*/
+void PGARealCreateString (PGAContext *ctx, int p, int pop, int initflag)
+{
+    PGAIndividual *new = PGAGetIndividual(ctx, p, pop);
+    int i, fp;
+    PGAReal *c;
+    
+    PGADebugEntered("PGARealCreateString");
+    
+    new->chrom = (void *) malloc (ctx->ga.StringLen * sizeof(PGAReal));
+    if (new->chrom == NULL)
+	PGAError(ctx, "PGARealCreateString: No room to allocate new->chrom",
+		 PGA_FATAL, PGA_VOID, NULL);
+    c = (PGAReal *)new->chrom;
+    if (initflag)
+	if (ctx->fops.InitString) {
+	    fp = ((p == PGA_TEMP1) || (p == PGA_TEMP2)) ? p : p+1;
+	    (*ctx->fops.InitString)(&ctx, &fp, &pop);
+	} else {
+	    (*ctx->cops.InitString)(ctx, p, pop);
+	}
+    else
+	for (i=ctx->ga.StringLen-1; i>=0; i--)
+	    c[i] = 0.0;
+    
+    PGADebugExited("PGARealCreateString");
+}
+
+/*I****************************************************************************
+   PGARealMutation - randomly mutates a floating point string with probability
+   mr.  Three of the four mutation operators are of the form v = v +- p*v.
+   That is, the new value of v (allele i) is the old value + or - a percentage,
+   p, of the old value. There are three possibilities for choosing p: (1)
+   constant value (0.01 by default), (2) selected uniformly on (0,UB) (UB is
+   .1 by default), and (3) selected from a Gaussian distribution (with mean 0
+   and standard deviation .1 be default).  The change to an allele, p*v, is
+   added or subtracted to the old value with a probability of .5. The fourth
+   option is to replace v with a value selected uniformly random from the
+   initialization range of that gene. Alleles to mutate are randomly selected.
+   The value set by the routine PGASetMutationRealValue is used as p, UB, and
+   sigma in cases 1,2, and 3, respectively.
+
+   Inputs:
+      ctx - context variable
+      p        - string index
+      pop      - symbolic constant of the population string p is in
+      mr  - probability of mutating a real-valued gene
+
+   Outputs: The number of mutations performed.
+
+   Example:
+      Sets the value of the ith gene of string p
+      in population PGA_NEWPOP to one
+
+      PGAContext *ctx;
+      int NumMutations, p;
+      :
+      NumMutations = PGARealMutation( ctx, p, PGA_NEWPOP, .001 );
+
+****************************************************************************I*/
+int PGARealMutation( PGAContext *ctx, int p, int pop, double mr )
+{
+     PGAReal *c;
+     int i;
+     int count = 0;
+     double val;
+
+     PGADebugEntered("PGARealMutation");
+
+     c = (PGAReal *)PGAGetIndividual(ctx, p, pop)->chrom;
+     for(i=0; i<ctx->ga.StringLen; i++) {
+
+         /* randomly choose an allele   */
+         if ( PGARandomFlip(ctx, mr) ) {
+
+             /* generate on range, or calculate multplier */
+             switch (ctx->ga.MutationType) {
+             case PGA_MUTATION_RANGE:
+                 c[i] = PGARandomUniform(ctx, ctx->init.RealMin[i],
+                                              ctx->init.RealMax[i]);
+                 break;
+             case PGA_MUTATION_CONSTANT:
+                 val = ctx->ga.MutateRealValue;
+                 break;
+             case PGA_MUTATION_UNIFORM:
+                 val = PGARandomUniform (ctx, 0.0, ctx->ga.MutateRealValue);
+                 break;
+             case PGA_MUTATION_GAUSSIAN:
+                 val = PGARandomGaussian(ctx, 0.0, ctx->ga.MutateRealValue);
+                 break;
+             default:
+                  PGAError(ctx, "PGARealMutation: Invalid value of "
+                           "ga.MutationType:", PGA_FATAL, PGA_INT,
+                           (void *) &(ctx->ga.MutationType));
+                  break;
+             }
+
+             /* apply multiplier calculated in switch above */
+             if ( (ctx->ga.MutationType == PGA_MUTATION_CONSTANT) ||
+                  (ctx->ga.MutationType == PGA_MUTATION_UNIFORM)  ||
+                  (ctx->ga.MutationType == PGA_MUTATION_GAUSSIAN)
+                ) {
+                 /* add/subtract from allele */
+                 if ( PGARandomFlip(ctx, .5) )
+                     c[i] += val*c[i];
+                 else
+                     c[i] -= val*c[i];
+             }
+
+             /* reset to min/max if bounded flag true and outside range */
+             if( ctx->ga.MutateBoundedFlag == PGA_TRUE ) {
+                if( c[i] < ctx->init.RealMin[i])
+                    c[i] = ctx->init.RealMin[i];
+                if( c[i] > ctx->init.RealMax[i])
+                    c[i] = ctx->init.RealMax[i];
+             }
+
+             /* increment mutation count */
+             count++;
+         }
+     }
+
+     PGADebugExited("PGARealMutation");
+
+     return(count);
+}
+
+/*I****************************************************************************
+   PGARealOneptCrossover - this routine performs one point crossover on two
+   parent strings, producing (via side effect) the crossed children child1 and
+   child2
+
+   Inputs:
+      ctx  - context variable
+      p1   - the first parent string
+      p2   - the second parent string
+      pop1 - symbolic constant of the population containing string p1 and p2
+      c1   - the first child string
+      c2   - the second child string
+      pop2 - symbolic constant of the population to contain string c1 and c2
+
+   Outputs:
+      c1 and c2 in population pop2 are modified by side-effect.
+
+   Example:
+      Performs crossover on the two parent strings m and d, producing
+      children s and b.
+
+      PGAContext *ctx;
+      int m, d, s, b;
+      :
+      PGARealOneptCrossover( ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP );
+
+****************************************************************************I*/
+void PGARealOneptCrossover( PGAContext *ctx, int p1, int p2, int pop1,
+                           int c1, int c2, int pop2)
+{
+     PGAReal *parent1 = (PGAReal *)PGAGetIndividual(ctx, p1,
+                                                    pop1)->chrom;
+     PGAReal *parent2 = (PGAReal *)PGAGetIndividual(ctx, p2,
+                                                    pop1)->chrom;
+     PGAReal *child1  = (PGAReal *)PGAGetIndividual(ctx, c1,
+                                                    pop2)->chrom;
+     PGAReal *child2  = (PGAReal *)PGAGetIndividual(ctx, c2,
+                                                    pop2)->chrom;
+     int i, xsite;
+
+    PGADebugEntered("PGARealOneptCrossover");
+
+    xsite = PGARandomInterval(ctx, 1,ctx->ga.StringLen-1);
+
+    for(i=0;i<xsite;i++) {
+        child1[i] = parent1[i];
+        child2[i] = parent2[i];
+    }
+
+    for(i=xsite;i<ctx->ga.StringLen;i++) {
+        child1[i] = parent2[i];
+        child2[i] = parent1[i];
+    }
+
+    PGADebugExited("PGARealOneptCrossover");
+}
+
+
+/*I****************************************************************************
+   PGARealTwoptCrossover - performs two-point crossover on two parent strings
+   producing two children via side-effect
+
+   Inputs:
+      ctx  - context variable
+      p1   - the first parent string
+      p2   - the second parent string
+      pop1 - symbolic constant of the population containing string p1 and p2
+      c1   - the first child string
+      c2   - the second child string
+      pop2 - symbolic constant of the population to contain string c1 and c2
+
+   Outputs:
+      c1 and c2 in population pop2 are modified by side-effect.
+
+   Example:
+      Performs crossover on the two parent strings m and d, producing
+      children s and b.
+
+      PGAContext *ctx;
+      int m, d, s, b;
+      :
+      PGARealTwoptCrossover( ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP );
+
+****************************************************************************I*/
+void PGARealTwoptCrossover( PGAContext *ctx, int p1, int p2, int pop1,
+                           int c1, int c2, int pop2)
+{
+     PGAReal *parent1 = (PGAReal *)PGAGetIndividual(ctx, p1,
+                                                    pop1)->chrom;
+     PGAReal *parent2 = (PGAReal *)PGAGetIndividual(ctx, p2,
+                                                    pop1)->chrom;
+     PGAReal *child1  = (PGAReal *)PGAGetIndividual(ctx, c1,
+                                                    pop2)->chrom;
+     PGAReal *child2  = (PGAReal *)PGAGetIndividual(ctx, c2,
+                                                    pop2)->chrom;
+     int i, temp, xsite1, xsite2;
+
+    PGADebugEntered("PGARealTwoptCrossover");
+
+    /* pick two cross sites such that xsite2 > xsite1 */
+    xsite1 = PGARandomInterval(ctx, 1,ctx->ga.StringLen-1);
+    xsite2 = xsite1;
+    while ( xsite2 == xsite1 )
+        xsite2 = PGARandomInterval(ctx, 1,ctx->ga.StringLen-1);
+    if ( xsite1 > xsite2 ) {
+        temp   = xsite1;
+        xsite1 = xsite2;
+        xsite2 = temp;
+    }
+
+    for(i=0;i<xsite1;i++) {
+        child1[i] = parent1[i];
+        child2[i] = parent2[i];
+    }
+
+    for(i=xsite1;i<xsite2;i++) {
+        child1[i] = parent2[i];
+        child2[i] = parent1[i];
+    }
+
+    for(i=xsite2;i<ctx->ga.StringLen;i++) {
+        child1[i] = parent1[i];
+        child2[i] = parent2[i];
+    }
+
+    PGADebugExited("PGARealTwoptCrossover");
+}
+
+
+/*I****************************************************************************
+   PGARealUniformCrossover - performs uniform crossover on two parent strings
+   producing two children via side-effect
+
+   Inputs:
+      ctx  - context variable
+      p1   - the first parent string
+      p2   - the second parent string
+      pop1 - symbolic constant of the population containing string p1 and p2
+      c1   - the first child string
+      c2   - the second child string
+      pop2 - symbolic constant of the population to contain string c1 and c2
+
+   Outputs:
+      c1 and c2 in population pop2 are modified by side-effect.
+
+   Example:
+      Performs crossover on the two parent strings m and d, producing
+      children s and b.
+
+      PGAContext *ctx;
+      int m, d, s, b;
+      :
+      PGARealUniformCrossover( ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP );
+
+****************************************************************************I*/
+void PGARealUniformCrossover( PGAContext *ctx, int p1, int p2, int pop1,
+                             int c1, int c2, int pop2)
+{
+     PGAReal *parent1 = (PGAReal *)PGAGetIndividual(ctx, p1,
+                                                    pop1)->chrom;
+     PGAReal *parent2 = (PGAReal *)PGAGetIndividual(ctx, p2,
+                                                    pop1)->chrom;
+     PGAReal *child1  = (PGAReal *)PGAGetIndividual(ctx, c1,
+                                                    pop2)->chrom;
+     PGAReal *child2  = (PGAReal *)PGAGetIndividual(ctx, c2,
+                                                    pop2)->chrom;
+     int i;
+
+    PGADebugEntered("PGARealUniformCrossover");
+
+    for(i=0;i<ctx->ga.StringLen;i++) {
+        if ( parent1[i] == parent2[i] ) {
+            child1[i] = parent1[i];
+            child2[i] = parent2[i];
+        }
+        else {
+            if(PGARandomFlip(ctx, ctx->ga.UniformCrossProb)) {
+                child1[i] = parent1[i];
+                child2[i] = parent2[i];
+            }
+            else {
+                child1[i] = parent2[i];
+                child2[i] = parent1[i];
+            }
+        }
+    }
+
+    PGADebugExited("PGARealUniformCrossover");
+}
+
+/*I****************************************************************************
+   PGARealPrintString - writes a real-valued string to a file.  This routine
+   casts the void string pointer it is passed as the second argument.
+
+   Inputs:
+      ctx - context variable
+      fp  - file pointer to file to write the string to
+      p   - index of the string to write out
+      pop - symbolic constant of the population string p is in
+
+   Outputs:
+
+   Example:
+      Write string s to stdout.
+
+      PGAContext *ctx;
+      int s;
+      :
+      PGARealPrintString( ctx, stdout, s, PGA_NEWPOP );
+
+****************************************************************************I*/
+void PGARealPrintString (PGAContext *ctx, FILE *fp, int p, int pop)
+{
+    PGAReal *c = (PGAReal *)PGAGetIndividual(ctx, p, pop)->chrom;
+    int i;
+
+    PGADebugEntered("PGARealPrintString");
+
+    for(i = 0; i < ctx->ga.StringLen; i++)
+    {
+        switch ( i % 5 )
+        {
+        case 0:
+            fprintf ( fp, "#%4d: [%11.7g]",i,c[i]);
+            break;
+        case 1:
+        case 2:
+        case 3:
+            fprintf ( fp, ", [%11.7g]",c[i]);
+            break;
+        case 4:
+            fprintf ( fp, ", [%11.7g]",c[i]);
+            if (i+1 < ctx->ga.StringLen)
+                fprintf ( fp, "\n");
+            break;
+        }
+    }
+    fprintf ( fp, "\n" );
+
+    PGADebugExited("PGARealPrintString");
+}
+
+
+/*I****************************************************************************
+   PGARealCopyString - Copy one real-valued string string to another
+
+   Inputs:
+      ctx - context variable
+      p1   - string to copy
+      pop1 - symbolic constant of population containing string p1
+      p2   - string to copy p1 to
+      pop2 - symbolic constant of population containing string p2
+
+   Outputs:
+      String p2 in population pop2 is modified to be a copy of string
+      p1 in population pop1.
+
+   Example:
+      Copy string x to y.
+
+      PGAContext *ctx;
+      int x, y;
+      :
+      PGARealCopyString (ctx, x, PGA_OLDPOP, y, PGA_NEWPOP);
+
+****************************************************************************I*/
+void PGARealCopyString ( PGAContext *ctx, int p1, int pop1, int p2, int pop2)
+{
+    PGAReal *source = (PGAReal *)PGAGetIndividual(ctx, p1, pop1)->chrom;
+    PGAReal *dest   = (PGAReal *)PGAGetIndividual(ctx, p2, pop2)->chrom;
+    int i;
+
+    PGADebugEntered("PGARealCopyString");
+
+    for (i=ctx->ga.StringLen-1; i>=0; i--)
+        *(dest++) = *(source++);
+
+    PGADebugExited("PGARealCopyString");
+}
+
+
+/*I****************************************************************************
+   PGARealDuplicate - Returns true if real-valued string a is a duplicate of
+   real-valued string b, else returns false.
+
+   Inputs:
+      ctx - context variable
+      p1   - string index of the first string to compare
+      pop1 - symbolic constant of the population string p1 is in
+      p2   - string index of the second string to compare
+      pop2 - symbolic constant of the population string p2 is in
+
+   Outputs:
+      Returns true/false if strings are duplicates
+
+   Example:
+      Compare strings x with y to see if they are duplicates
+
+      PGAContext *ctx;
+      int x, y;
+      :
+      if ( PGARealDuplicate( ctx, x, PGA_OLDPOP, y, PGA_OLDPOP ) )
+          printf("strings are duplicates\n");
+
+****************************************************************************I*/
+int PGARealDuplicate( PGAContext *ctx, int p1, int pop1, int p2, int pop2)
+{
+     PGAReal *a = (PGAReal *)PGAGetIndividual(ctx, p1, pop1)->chrom;
+     PGAReal *b = (PGAReal *)PGAGetIndividual(ctx, p2, pop2)->chrom;
+     int i;
+
+    PGADebugEntered("PGARealDuplicate");
+
+     i = ctx->ga.StringLen-1;
+     if (a[0] == b[0])
+       for(; (i>0) && (a[i] == b[i]); i--);
+
+    PGADebugExited("PGARealDuplicate");
+
+     return((i==0) ? PGA_TRUE : PGA_FALSE);
+}
+
+/*I****************************************************************************
+   PGARealInitString - randomly initialize a string of type PGAReal
+
+   Inputs:
+      ctx - context variable
+      p   - index of string to randomly initialize
+      pop - symbolic constant of the population string p is in
+
+   Outputs:
+      String p in population pop is randomly initialized by side-effect.
+
+   Example:
+      PGAContext *ctx;
+      int p;
+      :
+      PGARealInitString (ctx, p, PGA_NEWPOP);
+
+****************************************************************************I*/
+void PGARealInitString ( PGAContext *ctx, int p, int pop)
+{
+     int i;
+     PGAReal *c = (PGAReal *)PGAGetIndividual(ctx, p, pop)->chrom;
+
+     PGADebugEntered("PGARealInitString");
+
+     for (i = 0; i < ctx->ga.StringLen; i++)
+          c[i] = PGARandomUniform(ctx, ctx->init.RealMin[i],
+                                  ctx->init.RealMax[i]);
+
+     PGADebugExited("PGARealInitString");
+}
+
+/*I****************************************************************************
+  PGARealBuildDatatype - Build an MPI datatype for a string.
+
+  Inputs:
+     ctx   - context variable
+     p     - index of string
+     pop   - symbolic constant of population string p is in
+
+  Outputs:
+     An MPI_Datatype.
+
+  Example:
+     PGAContext   *ctx;
+     int           p;
+     MPI_Datatype  dt;
+     :
+     dt = PGARealBuildDatatype(ctx, p, pop);
+
+****************************************************************************I*/
+MPI_Datatype PGARealBuildDatatype(PGAContext *ctx, int p, int pop)
+{
+
+     int            counts[4];      /* Number of elements in each
+                                       block (array of integer) */
+     MPI_Aint       displs[4];      /* byte displacement of each
+                                       block (array of integer) */
+     MPI_Datatype   types[4];       /* type of elements in each block (array
+                                       of handles to datatype objects) */
+     MPI_Datatype   individualtype; /* new datatype (handle) */
+     PGAIndividual *traveller;      /* address of individual in question */
+
+    PGADebugEntered("PGARealBuildDatatype");
+
+     traveller = PGAGetIndividual(ctx, p, pop);
+     MPI_Address(&traveller->evalfunc, &displs[0]);
+     counts[0] = 1;
+     types[0]  = MPI_DOUBLE;
+
+     MPI_Address(&traveller->fitness, &displs[1]);
+     counts[1] = 1;
+     types[1]  = MPI_DOUBLE;
+
+     MPI_Address(&traveller->evaluptodate, &displs[2]);
+     counts[2] = 1;
+     types[2]  = MPI_INT;
+
+     MPI_Address(traveller->chrom, &displs[3]);
+     counts[3] = ctx->ga.StringLen;
+     types[3]  = MPI_DOUBLE;
+
+     MPI_Type_struct(4, counts, displs, types, &individualtype);
+     MPI_Type_commit(&individualtype);
+
+    PGADebugExited("PGARealBuildDatatype");
+
+     return (individualtype);
+}

Added: spamassassin/trunk/build/pga/source/report.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/source/report.c?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/source/report.c (added)
+++ spamassassin/trunk/build/pga/source/report.c Sun May 28 18:31:49 2017
@@ -0,0 +1,1332 @@
+/*
+COPYRIGHT
+
+The following is a notice of limited availability of the code, and disclaimer
+which must be included in the prologue of the code and in all source listings
+of the code.
+
+(C) COPYRIGHT 2008 University of Chicago
+
+Permission is hereby granted to use, reproduce, prepare derivative works, and
+to redistribute to others. This software was authored by:
+
+D. Levine
+Mathematics and Computer Science Division 
+Argonne National Laboratory Group
+
+with programming assistance of participants in Argonne National 
+Laboratory's SERS program.
+
+GOVERNMENT LICENSE
+
+Portions of this material resulted from work developed under a
+U.S. Government Contract and are subject to the following license: the
+Government is granted for itself and others acting on its behalf a paid-up,
+nonexclusive, irrevocable worldwide license in this computer software to
+reproduce, prepare derivative works, and perform publicly and display
+publicly.
+
+DISCLAIMER
+
+This computer code material was prepared, in part, as an account of work
+sponsored by an agency of the United States Government. Neither the United
+States, nor the University of Chicago, nor any of their employees, makes any
+warranty express or implied, or assumes any legal liability or responsibility
+for the accuracy, completeness, or usefulness of any information, apparatus,
+product, or process disclosed, or represents that its use would not infringe
+privately owned rights.
+*/
+
+/******************************************************************************
+ *     FILE: report.c: This file contains functions for reporting on GA
+ *                     parameters, and execution.
+ *
+ *     Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle
+ *              Brian P. Walenz
+ ******************************************************************************/
+
+#include "pgapack.h"
+
+/*U****************************************************************************
+   PGAPrintReport - prints genetic algorithm statistics.  The statistics
+   that are printed are determined by PGASetPrintOptions().
+
+   Category: Reporting
+
+   Inputs:
+      ctx - context variable
+      fp  - file pointer to print the output to
+      pop - symbolic constant of the population whose statistics are printed
+
+   Outputs:
+      genetic algorithm statistics are printed to fp
+
+   Example:
+      PGAContext *ctx;
+      int p;
+      :
+      PGAPrintReport(ctx, stdout, PGA_NEWPOP);
+
+****************************************************************************U*/
+void PGAPrintReport(PGAContext *ctx, FILE *fp, int pop)
+{
+     int p, best_p;
+     double e, best_e;
+
+    PGADebugEntered("PGAPrintReport");
+
+    /*
+     * edd  07 Feb 2007  this prints unconditionally, so let's change it
+     *                    WAS:  if (ctx->ga.iter == 1)
+     */
+     if ((ctx->rep.PrintFreq >=0) && !(ctx->ga.iter % ctx->rep.PrintFreq))
+/*       fprintf (fp, "Iter #     Field      Value           Time\n");  */
+         fprintf (fp, "Iter #     Field      Value\n");
+
+
+     best_p = PGAGetBestIndex(ctx, pop);
+     best_e = PGAGetEvaluation(ctx, best_p, pop);
+    /*
+     * edd  07 Feb 2007  this prints unconditionally, so let's change it
+     *                    WAS:  (!(ctx->ga.iter % ctx->rep.PrintFreq) || ctx->ga.iter == 1)
+     */
+     if ((ctx->rep.PrintFreq >=0) && !(ctx->ga.iter % ctx->rep.PrintFreq))
+     {
+          fprintf(fp, "%-11dBest       %e\n", PGAGetGAIterValue(ctx), best_e);
+/*        fprintf(fp, "      %ld\n", time(NULL) - ctx->rep.starttime);  */
+          if ((ctx->rep.PrintOptions & PGA_REPORT_WORST) == PGA_REPORT_WORST)
+          {
+               p = PGAGetWorstIndex(ctx, pop);
+               e = PGAGetEvaluation(ctx, p, pop);
+               fprintf(fp, "           Worst      %e\n", e);
+          }
+
+          if ((ctx->rep.PrintOptions & PGA_REPORT_AVERAGE) == PGA_REPORT_AVERAGE)
+               fprintf(fp, "           Average    %e\n", ctx->rep.Average);
+
+          if ((ctx->rep.PrintOptions & PGA_REPORT_OFFLINE)
+               == PGA_REPORT_OFFLINE)
+               fprintf(fp, "           Offline    %e\n", ctx->rep.Offline);
+
+          if ((ctx->rep.PrintOptions & PGA_REPORT_ONLINE) == PGA_REPORT_ONLINE)
+               fprintf(fp, "           Online     %e\n", ctx->rep.Online);
+
+          if((ctx->rep.PrintOptions & PGA_REPORT_HAMMING)
+             == PGA_REPORT_HAMMING)
+               fprintf(fp, "           Hamming    %e\n",
+                       PGAHammingDistance(ctx, pop));
+          if ((ctx->rep.PrintOptions & PGA_REPORT_STRING) == PGA_REPORT_STRING)
+               PGAPrintString(ctx, fp, best_p, pop);
+     }
+     fflush(fp);
+
+    PGADebugExited("PGAPrintReport");
+}
+
+/*U****************************************************************************
+   PGASetPrintOptions - set flags to indicate what GA statistics should be
+   printed whenever output is printed.  May be called more than once to
+   specify different report options.  Valid choices are PGA_REPORT_AVERAGE,
+   PGA_REPORT_OFFLINE, PGA_REPORT_ONLINE, PGA_REPORT_WORST, PGA_REPORT_HAMMING,
+   and PGA_REPORT_STRING to specify offline analysis, online analysis, the
+   worst string in the population, the Hamming distance of the population, and
+   the actual allele values of the best string.  The best string is always
+   printed. 
+
+   Category: Reporting
+
+   Inputs:
+      ctx    - context variable
+      option - symbolic constant to specify a print option
+
+   Outputs:
+      None
+
+   Example:
+      PGAContext *ctx;
+      :
+      PGASetPrintOptions(ctx, PGA_REPORT_WORST);
+
+****************************************************************************U*/
+void PGASetPrintOptions (PGAContext *ctx, int option)
+{
+    PGADebugEntered("PGASetPrintOptions");
+
+  switch (option) {
+    case PGA_REPORT_AVERAGE:
+    case PGA_REPORT_OFFLINE:
+    case PGA_REPORT_ONLINE:
+    case PGA_REPORT_WORST:
+    case PGA_REPORT_HAMMING:
+    case PGA_REPORT_STRING:
+      ctx->rep.PrintOptions |= option;
+      break;
+    default:
+      PGAError (ctx, "PGASetPrintOption: Invalid value of option:",
+                PGA_FATAL, PGA_INT, (void *) &option);
+      break;
+  }
+
+    PGADebugExited("PGASetPrintOptions");
+}
+
+/*U****************************************************************************
+   PGASetPrintFrequencyValue - Specifies the frequency with which genetic
+   algorithm statistics are reported.  The default is every 10 GA iterations.
+   Used only if PGARun() is used to run the GA.
+
+   Category: Reporting
+
+   Inputs:
+      ctx        - context variable
+      print_freq - the genetic algorithm population size to use
+
+   Outputs:
+      None
+
+   Example:
+      PGAContext *ctx;
+      :
+      PGASetPrintFrequencyValue(ctx,1);
+
+****************************************************************************U*/
+void PGASetPrintFrequencyValue( PGAContext *ctx, int print_freq)
+{
+    PGADebugEntered("PGASetPrintFrequencyValue");
+
+    if (print_freq < 0)
+        PGAError ( ctx,
+                  "PGASetPrintFrequencyValue: Invalid value of print_freq:",
+                   PGA_FATAL,
+                   PGA_INT,
+                  (void *) &print_freq);
+    else
+        ctx->rep.PrintFreq = print_freq;
+
+    PGADebugExited("PGASetPrintFrequencyValue");
+}
+
+/*U***************************************************************************
+   PGAGetPrintFrequencyValue - returns how often to print statistics reports
+
+   Category: Reporting
+
+   Inputs:
+      ctx - context variable
+
+   Outputs:
+      The frequency of printing output
+
+   Example:
+      PGAContext *ctx;
+      int freq;
+      :
+      freq = PGAGetPrintFrequencyValue(ctx);
+
+***************************************************************************U*/
+int PGAGetPrintFrequencyValue (PGAContext *ctx)
+{
+    PGADebugEntered("PGAGetPrintFrequencyValue");
+    PGAFailIfNotSetUp("PGAGetPrintFrequencyValue");
+
+    PGADebugExited("PGAGetPrintFrequencyValue");
+
+    return(ctx->rep.PrintFreq);
+}
+
+/*U****************************************************************************
+   PGAPrintPopulation - Calls PGAPrintIndividual to print each member of a
+   population
+
+   Category: Reporting
+
+   Inputs:
+      ctx - context variable
+      fp  - file pointer to print the output to
+      pop - symbolic constant of the population to be printed
+
+   Outputs:
+      The strings and associated fields that make up a population member are
+      printed to fp.
+
+   Example:
+      PGAContext *ctx;
+      :
+      PGAPrintPopulation(ctx, stdout, PGA_NEWPOP);
+
+****************************************************************************U*/
+void PGAPrintPopulation ( PGAContext *ctx, FILE *fp, int pop )
+{
+    int i;
+
+
+    PGADebugEntered("PGAPrintPopulation");
+
+    for ( i=0; i < ctx->ga.PopSize; i++ )
+         PGAPrintIndividual ( ctx, fp,  i, pop );
+    fprintf(fp,"\n");
+
+    PGADebugExited("PGAPrintPopulation");
+}
+
+/*U****************************************************************************
+   PGAPrintIndividual - prints the allele values of a string and associated
+   fields (evaluation, fitness, etc.) of a string
+
+   Category: Reporting
+
+   Inputs:
+      ctx - context variable
+      fp  - file pointer to print the output to
+      p   - string index
+      pop - symbolic constant of the population string p is in
+
+   Outputs:
+      The allele values of string p and associated fields are printed to fp
+
+   Example:
+      PGAContext *ctx;
+      int p;
+      :
+      PGAPrintIndividual(ctx, stdout, p, PGA_NEWPOP);
+
+****************************************************************************U*/
+void PGAPrintIndividual ( PGAContext *ctx, FILE *fp, int p, int pop )
+{
+    PGAIndividual *ind;
+
+    PGADebugEntered("PGAPrintIndividual");
+
+    ind = PGAGetIndividual ( ctx, p, pop );
+
+    fprintf( fp,"%d  %e %e ", p, ind->evalfunc, ind->fitness);
+    if ( ind->evaluptodate )
+        fprintf( fp, "T\n" );
+    else
+        fprintf( fp, "F\n" );
+    PGAPrintString ( ctx, fp, p, pop );
+
+    PGADebugExited("PGAPrintIndividual");
+}
+
+/*U****************************************************************************
+   PGAPrintString - write the allele values in a string to a file
+
+   Category: Reporting
+
+   Inputs:
+      ctx - context variable
+      fp  - pointer to file to write the string to
+      p   - index of the string to write out
+      pop - symbolic constant of the population string p is in
+
+   Outputs:
+      None
+
+   Example:
+      PGAContext *ctx;
+      int p;
+      :
+      PGAPrintString(ctx, stdout, p, PGA_OLDPOP);
+
+****************************************************************************U*/
+void PGAPrintString ( PGAContext *ctx, FILE *file, int p, int pop )
+{
+    int fp;
+
+    PGADebugEntered("PGAPrintString");
+    PGADebugPrint( ctx, PGA_DEBUG_PRINTVAR,"PGAPrintString",
+                  "p   = ", PGA_INT, (void *) &p );
+    PGADebugPrint( ctx, PGA_DEBUG_PRINTVAR,"PGAPrintString",
+                  "pop = ", PGA_INT, (void *) &pop );
+    
+    if (ctx->fops.PrintString) {
+        fp = ((p == PGA_TEMP1) || (p == PGA_TEMP2)) ? p : p+1;
+        (*ctx->fops.PrintString)(&ctx, NULL, &fp, &pop);
+    } else {
+        (*ctx->cops.PrintString)(ctx, file, p, pop);
+    }
+    fprintf(file,"\n");
+
+    PGADebugExited("PGAPrintString");
+}
+
+/*U****************************************************************************
+   PGAPrintContextVariable - prints the value of all the fields in the context
+   variable.
+
+   Category: Reporting
+
+   Inputs:
+      ctx - context variable
+      fp  - file pointer to print the output to
+
+   Outputs:
+      The value of all the fields in the context variable are printed to fp.
+
+   Example:
+      PGAContext *ctx;
+      :
+      PGAPrintContextVariable(ctx, stdout);
+
+****************************************************************************U*/
+void PGAPrintContextVariable ( PGAContext *ctx, FILE *fp )
+{
+    PGADebugEntered("PGAPrintContextVariable");
+
+     fprintf( fp,"Algorithm Parameters (Static)\n");
+
+     fprintf( fp,"    Data type                      : ");
+     switch(ctx->ga.datatype)
+     {
+     case PGA_DATATYPE_BINARY:
+          fprintf( fp,"Binary\n");
+          /*fprintf( fp,"    Bit Type Total Words           : ");
+          switch(ctx->ga.tw)
+          {
+          case PGA_UNINITIALIZED_INT:
+               fprintf( fp,"*UNINITIALIZED*\n");
+               break;
+          default:
+               fprintf( fp,"%d\n",ctx->ga.tw);
+               break;
+          };
+          fprintf( fp,"    Bit Type Full Words            : ");
+          switch(ctx->ga.fw)
+          {
+          case PGA_UNINITIALIZED_INT:
+               fprintf( fp,"*UNINITIALIZED*\n");
+               break;
+          default:
+               fprintf( fp,"%d\n",ctx->ga.fw);
+               break;
+          };
+          fprintf( fp,"    Bit Type Extra Bits            : ");
+          switch(ctx->ga.eb)
+          {
+          case PGA_UNINITIALIZED_INT:
+               fprintf( fp,"*UNINITIALIZED*\n");
+               break;
+          default:
+               fprintf( fp,"%d\n",ctx->ga.eb);
+               break;
+          };*/
+          break;
+     case PGA_DATATYPE_INTEGER:
+          fprintf( fp,"Integer\n");
+          break;
+     case PGA_DATATYPE_REAL:
+          fprintf( fp,"Real\n");
+          break;
+     case PGA_DATATYPE_CHARACTER:
+          fprintf( fp,"Character\n");
+          break;
+     case PGA_DATATYPE_USER:
+          fprintf( fp,"User Defined\n");
+          break;
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"!ERROR!  =(%d)?\n", ctx->ga.datatype);
+          break;
+     };
+
+     fprintf( fp,"    Optimization Direction         : ");
+     switch(ctx->ga.optdir)
+     {
+     case PGA_MAXIMIZE:
+          fprintf( fp,"Maximize\n");
+          break;
+     case PGA_MINIMIZE:
+          fprintf( fp,"Minimize\n");
+          break;
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"!ERROR!  =(%d)?\n", ctx->ga.optdir);
+          break;
+     };
+
+     fprintf( fp,"    Population Size                : ");
+     switch(ctx->ga.PopSize)
+     {
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"%d\n",ctx->ga.PopSize);
+          break;
+     };
+
+     fprintf( fp,"    String Length                  : ");
+     switch(ctx->ga.StringLen)
+     {
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"%d\n",ctx->ga.StringLen);
+          break;
+     };
+     
+
+     fprintf( fp,"    Copy to Next Population        : ");
+     switch(ctx->ga.PopReplace)
+     {
+     case PGA_POPREPL_BEST:
+          fprintf( fp,"Best\n");
+          break;
+     case PGA_POPREPL_RANDOM_NOREP:
+          fprintf( fp,"Random without replacement\n");
+          break;
+     case PGA_POPREPL_RANDOM_REP:
+          fprintf( fp,"Random with replacement\n");
+          break;
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"!ERROR!  =(%d)?\n", ctx->ga.PopReplace);
+          break;
+     };
+
+     
+     /*fprintf( fp,"    Stopping Rule (s)              :\n");
+     if ((ctx->ga.StoppingRule & PGA_STOP_MAXITER) == PGA_STOP_MAXITER)
+          fprintf(fp, "%50s", "Maximum iterations\n");
+     if ((ctx->ga.StoppingRule & PGA_STOP_NOCHANGE) == PGA_STOP_NOCHANGE)
+          fprintf(fp, "%49s", "No change in best\n");
+     if ((ctx->ga.StoppingRule & PGA_STOP_TOOSIMILAR) == PGA_STOP_TOOSIMILAR)
+          fprintf(fp, "%54s", "Population Homogeneity\n");
+     if (ctx->ga.StoppingRule == PGA_UNINITIALIZED_INT)
+          fprintf(fp, "%47s", "*UNINITIALIZED*\n");*/
+
+     fprintf( fp,"    Stop: Maximum Iterations       : ");
+     if ((ctx->ga.StoppingRule & PGA_STOP_MAXITER) == PGA_STOP_MAXITER)
+         fprintf( fp,"On\n");
+     else
+         fprintf( fp,"Off\n");
+
+
+     fprintf( fp,"        Maximum Iterations         : ");
+     switch(ctx->ga.MaxIter)
+     {
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"%d\n",ctx->ga.MaxIter);
+          break;
+     };
+
+
+     fprintf( fp,"    Stop: No Change                : ");
+     if ((ctx->ga.StoppingRule & PGA_STOP_NOCHANGE) == PGA_STOP_NOCHANGE)
+         fprintf( fp,"On\n");
+     else
+         fprintf( fp,"Off\n");
+
+     
+     fprintf(fp, "        Max No Change Iterations   : ");
+     switch(ctx->ga.MaxNoChange)
+     {
+     case PGA_UNINITIALIZED_INT:
+          fprintf(fp, "*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf(fp, "%d\n", ctx->ga.MaxNoChange);
+          break;
+     }
+
+     fprintf( fp,"    Stop: Too Similar              : ");
+     if ((ctx->ga.StoppingRule & PGA_STOP_TOOSIMILAR) == PGA_STOP_TOOSIMILAR)
+         fprintf( fp,"On\n");
+     else
+         fprintf( fp,"Off\n");
+
+
+     fprintf(fp, "        Percent Similarity         : ");
+     switch(ctx->ga.MaxSimilarity)
+     {
+     case PGA_UNINITIALIZED_INT:
+          fprintf(fp, "*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf(fp, "%d\n", ctx->ga.MaxSimilarity);
+          break;
+     }
+
+     fprintf( fp,"    No. Strings Replaced per Iter  : ");
+     switch(ctx->ga.NumReplace)
+     {
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"%d\n",ctx->ga.NumReplace);
+          break;
+     };
+
+
+     fprintf( fp,"    Mutate [And,Or] Crossover      : ");
+     switch(ctx->ga.MutateOnlyNoCross)
+     {
+     case PGA_TRUE:
+          fprintf( fp,"Or\n");
+          break;
+     case PGA_FALSE:
+          fprintf( fp,"And\n");
+          break;
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"!ERROR!  =(%d)?\n", ctx->ga.MutateOnlyNoCross);
+          break;
+     };
+
+     
+     fprintf( fp,"    Crossover Type                 : ");
+     switch(ctx->ga.CrossoverType)
+     {
+     case PGA_CROSSOVER_ONEPT:
+          fprintf( fp,"One Point\n");
+          break;
+     case PGA_CROSSOVER_TWOPT:
+          fprintf( fp,"Two Point\n");
+          break;
+     case PGA_CROSSOVER_UNIFORM:
+          fprintf( fp,"Uniform\n");
+          break;
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"!ERROR!  =(%d)?\n", ctx->ga.CrossoverType);
+          break;
+     };
+
+     
+     fprintf( fp,"    Crossover Probability          : ");
+     if (ctx->ga.CrossoverProb == PGA_UNINITIALIZED_DOUBLE)
+          fprintf( fp,"*UNINITIALIZED*\n");
+     else
+          fprintf( fp,"%f\n",ctx->ga.CrossoverProb);
+
+    
+     fprintf( fp,"    Uniform Crossover Prob.        : ");
+     if (ctx->ga.UniformCrossProb == PGA_UNINITIALIZED_DOUBLE)
+          fprintf( fp,"*UNINITIALIZED*\n");
+     else
+          fprintf( fp,"%f\n",ctx->ga.UniformCrossProb);
+
+     
+     fprintf( fp,"    Mutation Type                  : ");
+     switch(ctx->ga.datatype)
+     {
+     case PGA_DATATYPE_BINARY:
+          fprintf( fp,"Binary\n");
+          break;
+     case PGA_DATATYPE_CHARACTER:
+          fprintf( fp,"Character\n");
+          break;
+     case PGA_DATATYPE_REAL:
+     case PGA_DATATYPE_INTEGER:
+         switch(ctx->ga.MutationType)
+         {
+         case PGA_MUTATION_CONSTANT:
+              fprintf( fp,"Constant\n");
+              break;
+         case PGA_MUTATION_RANGE:
+              fprintf( fp,"Range\n");
+              break;
+         case PGA_MUTATION_UNIFORM:
+              fprintf( fp,"Uniform\n");
+              break;
+         case PGA_MUTATION_GAUSSIAN:
+              fprintf( fp,"Gaussian\n");
+              break;
+         case PGA_MUTATION_PERMUTE:
+              fprintf( fp,"Permutation\n");
+              break;
+         case PGA_UNINITIALIZED_INT:
+              fprintf( fp,"*UNINITIALIZED*\n");
+              break;
+         default:
+              fprintf( fp,"!ERROR!  =(%d)?\n", ctx->ga.MutationType);
+              break;
+         };
+     default:
+         break;
+     };
+
+     
+     fprintf( fp,"    Mutation Probability           : ");
+     if (ctx->ga.MutationProb == PGA_UNINITIALIZED_DOUBLE)
+          fprintf( fp,"*UNINITIALIZED*\n");
+     else
+          fprintf( fp,"%f\n",ctx->ga.MutationProb);
+
+     
+     fprintf( fp,"    Real Mutation Constant         : ");
+     if (ctx->ga.MutationProb == PGA_UNINITIALIZED_DOUBLE)
+          fprintf( fp,"*UNINITIALIZED*\n");
+     else
+          fprintf( fp,"%f\n",ctx->ga.MutateRealValue);
+
+
+     fprintf(fp, "    Integer Mutation Constant      : ");
+     switch(ctx->ga.MutateIntegerValue)
+     {
+     case PGA_UNINITIALIZED_INT:
+          fprintf(fp, "*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf(fp, "%d\n", ctx->ga.MutateIntegerValue);
+          break;
+     }
+
+     
+     fprintf( fp,"    Mutation Range Bounded         : ");
+     switch(ctx->ga.MutateBoundedFlag)
+     {
+     case PGA_TRUE:
+          fprintf( fp,"On\n");
+          break;
+     case PGA_FALSE:
+          fprintf( fp,"Off\n");
+          break;
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"!ERROR!  =(%d)?\n", ctx->ga.MutateBoundedFlag);
+          break;
+     };
+
+     
+     fprintf( fp,"    Selection Type                 : ");
+     switch(ctx->ga.SelectType)
+     {
+     case PGA_SELECT_PROPORTIONAL:
+          fprintf( fp,"Proportional\n");
+          break;
+     case PGA_SELECT_SUS:
+          fprintf( fp,"Stochastic Universal\n");
+          break;
+     case PGA_SELECT_TOURNAMENT:
+          fprintf( fp,"Binary Tournament\n");
+          break;
+     case PGA_SELECT_PTOURNAMENT:
+          fprintf( fp,"Probabilistic Binary Tournament\n");
+          break;
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"!ERROR!  =(%d)?\n", ctx->ga.SelectType);
+          break;
+     };
+
+     
+     fprintf( fp,"    Tournament Selection Param     : ");
+     if (ctx->ga.PTournamentProb == PGA_UNINITIALIZED_DOUBLE)
+          fprintf( fp,"*UNINITIALIZED*\n");
+     else
+          fprintf( fp,"%f\n",ctx->ga.PTournamentProb);
+    
+     
+
+     fprintf( fp,"    Restart Operator               : ");
+     switch(ctx->ga.restart)
+     {
+     case PGA_TRUE:
+          fprintf( fp,"On\n");
+          break;
+     case PGA_FALSE:
+          fprintf( fp,"Off\n");
+          break;
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"!ERROR!  =(%d)?\n", ctx->ga.restart);
+          break;
+     };
+
+     fprintf( fp,"    Restart Frequency              : ");
+     switch(ctx->ga.restartFreq)
+     {
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"%d\n",ctx->ga.restartFreq);
+          break;
+     };
+
+     fprintf( fp,"    Restart Allele Change Prob     : ");
+     if (ctx->ga.restartAlleleProb == PGA_UNINITIALIZED_DOUBLE)
+          fprintf( fp,"*UNINITIALIZED*\n");
+     else
+          fprintf( fp,"%f\n",ctx->ga.restartAlleleProb);
+
+     
+     fprintf( fp,"    Allow Duplicates               : ");
+     switch(ctx->ga.NoDuplicates)
+     {
+     case PGA_TRUE:
+          fprintf( fp,"No\n");
+          break;
+     case PGA_FALSE:
+          fprintf( fp,"Yes\n");
+          break;
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"!ERROR!  =(%d)?\n", ctx->ga.NoDuplicates);
+          break;
+     };
+
+
+     fprintf( fp,"    Fitness Type                   : ");
+     switch(ctx->ga.FitnessType)
+     {
+     case PGA_FITNESS_RAW:
+          fprintf( fp,"Raw\n");
+          break;
+     case PGA_FITNESS_NORMAL:
+          fprintf( fp,"Linear Normalization\n");
+          break;
+     case PGA_FITNESS_RANKING:
+          fprintf( fp,"Linear Ranking\n");
+          break;
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"!ERROR!  =(%d)?\n", ctx->ga.FitnessType);
+          break;
+     };
+
+     
+     if ( ctx->ga.optdir == PGA_MINIMIZE )
+     {
+          fprintf( fp,"    Fitness Type(Minimization)     : ");
+          switch(ctx->ga.FitnessMinType) {
+          case PGA_FITNESSMIN_RECIPROCAL:
+               fprintf( fp,"Reciprocal\n");
+               break;
+          case PGA_FITNESSMIN_CMAX:
+               fprintf( fp,"CMax\n");
+               break;
+          case PGA_UNINITIALIZED_INT:
+               fprintf( fp,"*UNINITIALIZED*\n");
+               break;
+          default:
+               fprintf( fp,"!ERROR!  =(%d)?\n", ctx->ga.FitnessMinType);
+               break;
+          };
+     }
+
+     
+     fprintf( fp,"    Fitness Ranking Parameter      : ");
+     if (ctx->ga.FitnessRankMax == PGA_UNINITIALIZED_DOUBLE)
+          fprintf( fp,"*UNINITIALIZED*\n");
+     else
+          fprintf( fp,"%f\n",ctx->ga.FitnessRankMax);
+     
+
+     fprintf( fp,"    Fitness CMAX Parameter         : ");
+     if (ctx->ga.FitnessCmaxValue == PGA_UNINITIALIZED_DOUBLE)
+          fprintf( fp,"*UNINITIALIZED*\n");
+     else
+          fprintf( fp,"%f\n",ctx->ga.FitnessCmaxValue);
+
+     
+     fprintf( fp,"Algorithm Parameters (Dynamic)\n");
+
+     
+     fprintf( fp,"    Current Generation             : ");
+     switch(ctx->ga.iter)
+     {
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"%d\n",ctx->ga.iter);
+          break;
+     };
+
+     fprintf(fp, "    Num Iters With No Change       : ");
+     switch(ctx->ga.ItersOfSame)
+     {
+     case PGA_UNINITIALIZED_INT:
+          fprintf(fp, "*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf(fp, "%d\n", ctx->ga.ItersOfSame);
+          break;
+     }
+
+     fprintf(fp, "    Percent Similarity In Pop      : ");
+     switch(ctx->ga.PercentSame)
+     {
+     case PGA_UNINITIALIZED_INT:
+          fprintf(fp, "?UNINITIALZED?\n");
+          break;
+     default:
+          fprintf(fp, "%d\n", ctx->ga.PercentSame);
+          break;
+     }
+
+     fprintf( fp,"    Selection Index                : ");
+     switch(ctx->ga.SelectIndex)
+     {
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"%d\n",ctx->ga.SelectIndex);
+          break;
+     };
+
+     
+/* initialization */
+     fprintf( fp,"Initialization\n");
+
+     fprintf( fp,"    Random Initialization          : ");
+     switch(ctx->init.RandomInit)
+     {
+     case PGA_TRUE:
+          fprintf( fp,"On\n");
+          break;
+     case PGA_FALSE:
+          fprintf( fp,"Off\n");
+          break;
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"!ERROR!  =(%d)?\n", ctx->init.RandomInit);
+          break;
+     };
+
+     fprintf( fp,"    Initialization Binary Prob     : ");
+     if (ctx->init.BinaryProbability == PGA_UNINITIALIZED_DOUBLE)
+          fprintf( fp,"*UNINITIALIZED*\n");
+     else
+          fprintf( fp,"%f\n",ctx->init.BinaryProbability);
+
+
+     fprintf( fp,"    Initialization Real            : ");
+     switch(ctx->init.RealType)
+     {
+     case PGA_RINIT_RANGE:
+          fprintf( fp,"Range\n");
+          break;
+     case PGA_RINIT_PERCENT:
+          fprintf( fp,"Percent Offset\n");
+          break;
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"!ERROR!  =(%d)?\n", ctx->init.RealType);
+          break;
+     };
+
+     fprintf( fp,"    Initialization Integer         : ");
+     switch(ctx->init.IntegerType)
+     {
+     case PGA_IINIT_RANGE:
+          fprintf( fp,"Range\n");
+          break;
+     case PGA_IINIT_PERMUTE:
+          fprintf( fp,"Permutation\n");
+          break;
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"!ERROR!  =(%d)?\n", ctx->init.IntegerType);
+          break;
+     };
+
+     fprintf( fp,"    Initialization Character       : ");
+     switch(ctx->init.CharacterType)
+     {
+     case PGA_CINIT_LOWER:
+          fprintf( fp,"Lower Case\n");
+          break;
+     case PGA_CINIT_UPPER:
+          fprintf( fp,"Upper Case\n");
+          break;
+     case PGA_CINIT_MIXED:
+          fprintf( fp,"Mixed Case\n");
+          break;
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"!ERROR!  =(%d)?\n", ctx->init.CharacterType);
+          break;
+     };
+     
+     fprintf( fp,"    Random Number Seed             : ");
+     switch(ctx->init.RandomSeed)
+     {
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"%d\n", ctx->init.RandomSeed);
+          break;
+     };
+
+     PGADebugExited("PGAPrintContextVariable");
+
+
+/* par */
+    fprintf( fp,"Parallel\n");
+
+    fprintf( fp,"    MPI Library Used               : ");
+     switch(ctx->par.MPIStubLibrary)
+     {
+     case PGA_TRUE:
+          fprintf( fp,"Sequential\n");
+          break;
+     case PGA_FALSE:
+          fprintf( fp,"Parallel\n");
+          break;
+     default:
+          fprintf( fp,"!ERROR!  =(%d)?\n", ctx->par.MPIStubLibrary);
+          break;
+     };
+
+
+     fprintf( fp,"    MPI Initialized by PGAPack     : ");
+     switch(ctx->par.MPIAlreadyInit)
+     {
+     case PGA_TRUE:
+          fprintf( fp,"Yes\n");
+          break;
+     case PGA_FALSE:
+          fprintf( fp,"No\n");
+          break;
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"!ERROR!  =(%d)?\n", ctx->par.MPIAlreadyInit);
+          break;
+     };
+
+     /*fprintf(fp, "    Number Islands                 : ");
+     switch(ctx->par.NumIslands)
+     {
+     case PGA_UNINITIALIZED_INT:
+          fprintf(fp, "*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf(fp, "%d\n", ctx->par.NumIslands);
+          break;
+     }
+
+     fprintf(fp, "    Number Demes                   : ");
+     switch(ctx->par.NumDemes)
+     {
+     case PGA_UNINITIALIZED_INT:
+          fprintf(fp, "*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf(fp, "%d\n", ctx->par.NumDemes);
+          break;
+     }*/
+
+     fprintf(fp, "    Default Communicator           : ");
+     if (ctx->par.DefaultComm == NULL) 
+	 fprintf(fp, "NULL\n");
+     else if (ctx->par.DefaultComm == MPI_COMM_WORLD)
+         fprintf(fp, "MPI_COMM_WORLD\n");
+     else
+	 fprintf(fp, "User Defined\n");
+ 
+
+
+/* report */
+     fprintf( fp,"Report\n");
+
+     fprintf( fp,"    Print Frequency                : ");
+     switch(ctx->rep.PrintFreq)
+     {
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"%d\n",ctx->rep.PrintFreq);
+          break;
+     };
+
+     fprintf( fp,"    Print Worst Evaluation         : ");
+     if ((ctx->rep.PrintOptions & PGA_REPORT_WORST) == PGA_REPORT_WORST)
+         fprintf( fp,"On\n");
+     else
+         fprintf( fp,"Off\n");
+
+     fprintf( fp,"    Print Average Evaluation       : ");
+     if ((ctx->rep.PrintOptions & PGA_REPORT_AVERAGE) == PGA_REPORT_AVERAGE)
+         fprintf( fp,"On\n");
+     else
+         fprintf( fp,"Off\n");
+
+     fprintf( fp,"    Print Offline Statistics       : ");
+     if ((ctx->rep.PrintOptions & PGA_REPORT_OFFLINE) == PGA_REPORT_OFFLINE)
+         fprintf( fp,"On\n");
+     else
+         fprintf( fp,"Off\n");
+
+     fprintf( fp,"    Print Online Statistics        : ");
+     if ((ctx->rep.PrintOptions & PGA_REPORT_ONLINE) == PGA_REPORT_ONLINE)
+         fprintf( fp,"On\n");
+     else
+         fprintf( fp,"Off\n");
+
+     fprintf( fp,"    Print Hamming Distance         : ");
+     if ((ctx->rep.PrintOptions & PGA_REPORT_HAMMING) == PGA_REPORT_HAMMING)
+         fprintf( fp,"On\n");
+     else
+         fprintf( fp,"Off\n");
+
+/* system */
+     fprintf( fp,"System\n");
+
+     fprintf( fp,"    Maximum Integer                : ");
+     switch(ctx->sys.PGAMaxInt)
+     {
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"%d\n",ctx->sys.PGAMaxInt);
+          break;
+     };
+
+     fprintf( fp,"    Minimum Integer                : ");
+     switch(ctx->sys.PGAMinInt)
+     {
+     case PGA_UNINITIALIZED_INT:
+          fprintf( fp,"*UNINITIALIZED*\n");
+          break;
+     default:
+          fprintf( fp,"%d\n",ctx->sys.PGAMinInt);
+          break;
+     };
+
+     fprintf( fp,"    Maximum Double                 : ");
+     if (ctx->sys.PGAMaxDouble == PGA_UNINITIALIZED_DOUBLE)
+          fprintf( fp,"*UNINITIALIZED*\n");
+     else
+          fprintf( fp,"%e\n",ctx->sys.PGAMaxDouble);
+
+     fprintf( fp,"    Minimum Double                 : ");
+     if (ctx->sys.PGAMinDouble == PGA_UNINITIALIZED_DOUBLE)
+          fprintf( fp,"*UNINITIALIZED*\n");
+     else
+          fprintf( fp,"%e\n",ctx->sys.PGAMinDouble);
+
+
+
+/* ops */
+    fprintf( fp,"Operations\n");
+
+    fprintf( fp,"    CreateString  function         : ");
+    if (ctx->cops.CreateString == NULL)
+	fprintf( fp,"NULL\n");
+    else if (ctx->cops.CreateString == PGABinaryCreateString)
+	fprintf( fp,"PGABinaryCreateString\n");
+    else if (ctx->cops.CreateString == PGAIntegerCreateString)
+	fprintf( fp,"PGAIntegerCreateString\n");
+    else if (ctx->cops.CreateString == PGARealCreateString)
+	fprintf( fp,"PGARealCreateString\n");
+    else if (ctx->cops.CreateString == PGACharacterCreateString)
+	fprintf( fp,"PGACharacterCreateString\n");
+    else
+	fprintf( fp,"C User Defined: %p\n",ctx->cops.CreateString);
+
+    
+    fprintf( fp,"    InitString    function         : ");
+    if (ctx->cops.InitString) {
+        if (ctx->cops.InitString == PGABinaryInitString)
+	    fprintf( fp,"PGABinaryInitString\n");
+        else if (ctx->cops.InitString == PGAIntegerInitString)
+            fprintf( fp,"PGAIntegerInitString\n");
+        else if (ctx->cops.InitString == PGARealInitString)
+    	    fprintf( fp,"PGARealInitString\n");
+        else if (ctx->cops.InitString == PGACharacterInitString)
+    	    fprintf( fp,"PGACharacterInitString\n");
+        else
+	    fprintf( fp,"C User Defined: %p\n",ctx->cops.InitString);
+    } else {
+	if (ctx->fops.InitString) 
+	    fprintf( fp,"Fortran User Defined: %p\n",ctx->fops.InitString);
+	else
+	    fprintf( fp,"NULL\n");
+    }
+    
+
+    fprintf( fp,"    BuildDatatype function         : ");
+    if (ctx->cops.BuildDatatype == NULL)
+	fprintf( fp,"NULL\n");
+    else if (ctx->cops.BuildDatatype == PGABinaryBuildDatatype)
+	fprintf( fp,"PGABinaryBuildDatatype\n");
+    else if (ctx->cops.BuildDatatype == PGAIntegerBuildDatatype)
+	fprintf( fp,"PGAIntegerBuildDatatype\n");
+    else if (ctx->cops.BuildDatatype == PGARealBuildDatatype)
+	fprintf( fp,"PGARealBuildDatatype\n");
+    else if (ctx->cops.BuildDatatype == PGACharacterBuildDatatype)
+	fprintf( fp,"PGACharacterBuildDatatype\n");
+    else
+	fprintf( fp,"C User Defined: %p\n",ctx->cops.BuildDatatype);
+
+    
+    fprintf( fp,"    Mutation      function         : ");
+    if (ctx->cops.Mutation) {
+	if (ctx->cops.Mutation == PGABinaryMutation)
+	    fprintf( fp,"PGABinaryMutation\n");
+	else if (ctx->cops.Mutation == PGAIntegerMutation)
+	    fprintf( fp,"PGAIntegerMutation\n");
+	else if (ctx->cops.Mutation == PGARealMutation)
+	    fprintf( fp,"PGARealMutation\n");
+	else if (ctx->cops.Mutation == PGACharacterMutation)
+	    fprintf( fp,"PGACharacterMutation\n");
+	else
+	    fprintf( fp,"C User Defined: %p\n",ctx->cops.Mutation);
+    } else {
+	if (ctx->fops.Mutation) 
+	    fprintf( fp,"Fortran User Defined: %p\n",ctx->fops.Mutation);
+	else
+	    fprintf( fp,"NULL\n");
+    }
+
+    
+    fprintf( fp,"    Crossover     function         : ");
+    if (ctx->cops.Crossover) {
+	if (ctx->cops.Crossover == PGABinaryOneptCrossover)
+	    fprintf( fp,"PGABinaryOneptCrossover\n");
+	else if (ctx->cops.Crossover == PGAIntegerOneptCrossover)
+	    fprintf( fp,"PGAIntegerOneptCrossover\n");
+	else if (ctx->cops.Crossover == PGARealOneptCrossover)
+	    fprintf( fp,"PGARealOneptCrossover\n");
+	else if (ctx->cops.Crossover == PGACharacterOneptCrossover)
+	    fprintf( fp,"PGACharacterOneptCrossover\n");
+	else if (ctx->cops.Crossover == PGABinaryTwoptCrossover)
+	    fprintf( fp,"PGABinaryTwoptCrossover\n");
+	else if (ctx->cops.Crossover == PGAIntegerTwoptCrossover)
+	    fprintf( fp,"PGAIntegerTwoptCrossover\n");
+	else if (ctx->cops.Crossover == PGARealTwoptCrossover)
+	    fprintf( fp,"PGARealTwoptCrossover\n");
+	else if (ctx->cops.Crossover == PGACharacterTwoptCrossover)
+	    fprintf( fp,"PGACharacterTwoptCrossover\n");
+	else if (ctx->cops.Crossover == PGABinaryUniformCrossover)
+	    fprintf( fp,"PGABinarytUniformCrossover\n");
+	else if (ctx->cops.Crossover == PGAIntegerUniformCrossover)
+	    fprintf( fp,"PGAIntegerUniformCrossover\n");
+	else if (ctx->cops.Crossover == PGARealUniformCrossover)
+	    fprintf( fp,"PGARealUniformCrossover\n");
+	else if (ctx->cops.Crossover == PGACharacterUniformCrossover)
+	    fprintf( fp,"PGACharacterUniformCrossover\n");
+	else
+	    fprintf( fp,"C User Defined: %p\n",ctx->cops.Crossover);
+    } else {
+	if (ctx->fops.Crossover) 
+	    fprintf( fp,"Fortran User Defined: %p\n",ctx->fops.Crossover);
+	else
+	    fprintf( fp,"NULL\n");
+    }
+
+    
+    fprintf( fp,"    PrintString   function         : ");
+    if (ctx->cops.PrintString) {
+	if (ctx->cops.PrintString == PGABinaryPrintString)
+	    fprintf( fp,"PGABinaryPrintString\n");
+	else if (ctx->cops.PrintString == PGAIntegerPrintString)
+	    fprintf( fp,"PGAIntegerPrintString\n");
+	else if (ctx->cops.PrintString == PGARealPrintString)
+	    fprintf( fp,"PGARealPrintString\n");
+	else if (ctx->cops.PrintString == PGACharacterPrintString)
+	    fprintf( fp,"PGACharacterPrintString\n");
+	else
+	    fprintf( fp,"C User Defined: %p\n",ctx->cops.PrintString);
+    } else {
+	if (ctx->fops.PrintString)
+	    fprintf( fp,"Fortran User Defined: %p\n",ctx->fops.PrintString);
+	else
+	    fprintf( fp,"NULL\n");
+    }
+    
+
+    fprintf( fp,"    CopyString    function         : ");
+    if (ctx->cops.CopyString) {
+	if (ctx->cops.CopyString == PGABinaryCopyString)
+	    fprintf( fp,"PGABinaryCopyString\n");
+	else if (ctx->cops.CopyString == PGAIntegerCopyString)
+	    fprintf( fp,"PGAIntegerCopyString\n");
+	else if (ctx->cops.CopyString == PGARealCopyString)
+	    fprintf( fp,"PGARealCopyString\n");
+	else if (ctx->cops.CopyString == PGACharacterCopyString)
+	    fprintf( fp,"PGACharacterCopyString\n");
+	else
+	    fprintf( fp,"C User Defined: %p\n",ctx->cops.CopyString);
+    } else {
+	if (ctx->cops.CopyString)
+	    fprintf( fp,"Fortran User Defined: %p\n",ctx->fops.CopyString);
+	else
+	    fprintf( fp,"NULL\n");
+    }
+
+    
+    fprintf( fp,"    Duplicate     function         : ");
+    if (ctx->cops.Duplicate) {
+	if (ctx->cops.Duplicate == PGABinaryDuplicate)
+	    fprintf( fp,"PGABinaryDuplicate\n");
+	else if (ctx->cops.Duplicate == PGAIntegerDuplicate)
+	    fprintf( fp,"PGAIntegerDuplicate\n");
+	else if (ctx->cops.Duplicate == PGARealDuplicate)
+	    fprintf( fp,"PGARealDuplicate\n"); 
+	else if (ctx->cops.Duplicate == PGACharacterDuplicate)
+	    fprintf( fp,"PGACharacterDuplicate\n"); 
+	else
+	    fprintf( fp,"C User Defined: %p\n",ctx->cops.Duplicate);
+    } else {
+	if (ctx->fops.Duplicate)
+	    fprintf( fp,"Fortran User Defined: %p\n",ctx->fops.Duplicate);
+	else
+	    fprintf( fp,"NULL\n");
+    }
+
+
+    fprintf( fp,"    Stopping      function         : ");
+    if (ctx->cops.StopCond)
+	fprintf( fp,"C User Defined: %p\n",ctx->cops.StopCond);
+    else
+	if (ctx->fops.StopCond)
+	    fprintf( fp,"Fortran User Defined: %p\n",ctx->fops.StopCond);
+	else
+	    fprintf( fp,"PGACheckStoppingConditions\n");
+
+
+    fprintf( fp,"    End of Generation function     : ");
+    if (ctx->cops.EndOfGen)
+	fprintf( fp,"C User Defined: %p\n",ctx->cops.EndOfGen);
+    else
+	if (ctx->cops.EndOfGen)
+	    fprintf( fp,"Fortran User Defined: %p\n",ctx->fops.EndOfGen);
+	else
+	    fprintf( fp,"NULL\n");
+    
+
+}