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 [17/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/restart.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/source/restart.c?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/source/restart.c (added)
+++ spamassassin/trunk/build/pga/source/restart.c Sun May 28 18:31:49 2017
@@ -0,0 +1,306 @@
+/*
+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: restart.c: This file contains the routines needed to handle
+* the restart operator, and restarting the GA.
+*
+* Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle,
+* Brian P. Walenz
+*****************************************************************************/
+
+#include "pgapack.h"
+
+/*U****************************************************************************
+ PGARestart - reseeds a population from the best string
+
+ Category: Operators
+
+ Inputs:
+ val - the probability of changing an allele when copying the
+ best string to the new population
+ source_pop - the source population
+ dest_pop - symbolic constant of the destination population
+
+ Outputs:
+ dest_pop is modified by side-effect.
+
+ Example:
+ Perform an unspecified test to determine if the current evolution is
+ not evolving fast enough, and if so, restart the evolution.
+
+ PGAContext *ctx; PGAEvaluateMS(ctx, PGA_OLDPOP, f, comm);
+ PGAFitness (ctx, PGA_OLDPOP);
+ }
+
+ :
+ if (StagnantEvolution()) {
+ PGARestart(ctx, PGA_OLDPOP, PGA_NEWPOP);
+ PGAEvaluate(ctx, PGA_NEWPOP, EvalFunc);
+ PGAUpdateGeneration(ctx);
+ }
+
+****************************************************************************U*/
+void PGARestart(PGAContext *ctx, int source_pop, int dest_pop)
+{
+ /* For integers and reals, the amount by which to change is set with
+ PGASetMutationIntegerValue and PGASetMutationRealValue, respectively.
+ For binary strings, the bits are complemented. */
+
+ int dest_p, old_mut_type, source_p;
+ double val;
+
+ PGADebugEntered("PGARestart");
+
+ printf("Restarting the algorithm . . . \n");
+ fflush(stdout);
+ source_p = PGAGetBestIndex(ctx, source_pop);
+ if (source_p != 0 || source_pop != dest_pop)
+ PGACopyIndividual(ctx, source_p, source_pop, 0, dest_pop);
+ PGASetEvaluationUpToDateFlag(ctx, 0, dest_pop, PGA_FALSE);
+ old_mut_type = PGAGetMutationType(ctx);
+ ctx->ga.MutationType = PGA_MUTATION_UNIFORM;
+ val = ctx->ga.restartAlleleProb;
+
+ if (ctx->fops.Mutation) {
+ for (dest_p = 2; dest_p <= ctx->ga.PopSize; dest_p++) {
+ PGACopyIndividual(ctx, 0, dest_pop, dest_p-1, dest_pop);
+ (*ctx->fops.Mutation)(&ctx, &dest_p, &dest_pop, &val);
+ PGASetEvaluationUpToDateFlag(ctx, dest_p-1, dest_pop, PGA_FALSE);
+ }
+ } else {
+ for (dest_p = 1; dest_p < ctx->ga.PopSize; dest_p++) {
+ PGACopyIndividual(ctx, 0, dest_pop, dest_p, dest_pop);
+ (*ctx->cops.Mutation)(ctx, dest_p, dest_pop, val);
+ PGASetEvaluationUpToDateFlag(ctx, dest_p, dest_pop, PGA_FALSE);
+ }
+ }
+ ctx->ga.MutationType = old_mut_type;
+
+ PGADebugExited("PGARestart");
+}
+
+/*U****************************************************************************
+ PGASetRestartFlag - specifies whether the algorithm should employ
+ the restart operator
+
+ Category: Operators
+
+ Inputs:
+ ctx - context variable
+ val - boolean variable
+
+ Outputs:
+ None
+
+ Example:
+ PGAContext *ctx;
+ :
+ PGASetRestartFlag(ctx, PGA_TRUE);
+
+****************************************************************************U*/
+void PGASetRestartFlag(PGAContext *ctx, int val)
+{
+ PGADebugEntered("PGASetRestartFlag");
+
+ switch (val)
+ {
+ case PGA_TRUE:
+ case PGA_FALSE:
+ ctx->ga.restart = val;
+ break;
+ default:
+ PGAError(ctx, "PGASetRestartFlag: Invalid value for restart:",
+ PGA_FATAL, PGA_INT, (void *) &val);
+ break;
+ }
+
+ PGADebugExited("PGASetRestartFlag");
+}
+
+/*U****************************************************************************
+ PGAGetRestartFlag - returns whether the algorithm should employ the
+ restart operator
+
+ Category: Operators
+
+ Inputs:
+ ctx - context variable
+
+ Outputs:
+ PGA_TRUE if restarting is enabled, otherwise PGA_FALSE.
+
+ Example:
+ PGAContext *ctx;
+ int val;
+ :
+ val = PGAGetRestartFlag(ctx);
+
+****************************************************************************U*/
+int PGAGetRestartFlag(PGAContext *ctx)
+{
+ PGADebugEntered("PGAGetRestartFlag");
+ PGAFailIfNotSetUp("PGAGetRestartFlag");
+
+ PGADebugExited("PGAGetRestartFlag");
+
+ return (ctx->ga.restart);
+}
+
+/*U****************************************************************************
+ PGASetRestartFrequencyValue - specifies the number of iterations of no
+ change in the best string after which the algorithm should restart
+
+ Category: Operators
+
+ Inputs:
+ ctx - context variable
+ numiter - number of changeless iterations
+
+ Outputs:
+ None
+
+ Example:
+ PGAContext *ctx;
+ :
+ PGASetRestartFrequencyValue(ctx, 100);
+
+****************************************************************************U*/
+void PGASetRestartFrequencyValue(PGAContext *ctx, int numiter)
+{
+ PGADebugEntered("PGASetRestartFrequencyValue");
+
+ if (numiter > 0)
+ ctx->ga.restartFreq = numiter;
+ else
+ PGAError(ctx, "PGASetRestartFrequencyValue: Invalid value for "
+ "restart freqency:", PGA_FATAL, PGA_INT, (void *) &numiter);
+
+ PGADebugExited("PGASetRestartFrequencyValue");
+}
+
+/*U****************************************************************************
+ PGAGetRestartFrequencyValue - returns the number of iterations of no
+ change in the best string after which the algorithm should restart
+
+ Category: Operators
+
+ Inputs:
+ ctx - context variable
+ numiter - number of changeless iterations
+
+ Outputs:
+ The number of iteration of no change required for a restart.
+
+ Example:
+ PGAContext *ctx;
+ :
+ numiter = PGAGetRestartFrequencyValue(ctx);
+
+****************************************************************************U*/
+int PGAGetRestartFrequencyValue(PGAContext *ctx)
+{
+ PGADebugEntered("PGAGetRestartFrequencyValue");
+ PGAFailIfNotSetUp("PGAGetRestartFrequencyValue");
+
+ PGADebugExited("PGAGetRestartFrequencyValue");
+
+ return (ctx->ga.restartFreq);
+}
+
+/*U****************************************************************************
+ PGASetRestartAlleleChangeProb - specifies the probability with which
+ an allele will be mutated during a restart
+
+ Category: Operators
+
+ Inputs:
+ ctx - context variable
+ prob - probability of mutation
+
+ Outputs:
+ None
+
+ Example:
+ PGAContext *ctx;
+ :
+ PGASetRestartAlleleChangeProb(ctx, 0.5);
+
+****************************************************************************U*/
+void PGASetRestartAlleleChangeProb(PGAContext *ctx, double prob)
+{
+ PGADebugEntered("PGASetRestartAlleleChangeProb");
+
+ if (prob >= 0.0 && prob <= 1.0)
+ ctx->ga.restartAlleleProb = prob;
+ else
+ PGAError(ctx, "PGASetRestartAlleleChangeProb: Invalid probability:",
+ PGA_FATAL, PGA_DOUBLE, (void *) &prob);
+
+ PGADebugExited("PGASetRestartAlleleChangeProb");
+}
+
+/*U****************************************************************************
+ PGAGetRestartAlleleChangeProb - returns the probability with which
+ an allele will be mutated during a restart
+
+ Category: Operators
+
+ Inputs:
+ ctx - context variable
+
+ Outputs:
+ The probability of mutating an allele during a restart.
+
+ Example:
+ PGAContext *ctx;
+ :
+ prob = PGASetRestartAlleleChangeProb(ctx);
+
+****************************************************************************U*/
+double PGAGetRestartAlleleChangeProb(PGAContext *ctx)
+{
+ PGADebugEntered("PGAGetRestartAlleleChangeProb");
+ PGAFailIfNotSetUp("PGAGetRestartAlleleChangeProb");
+
+ PGADebugExited("PGAGetRestartAlleleChangeProb");
+
+ return (ctx->ga.restartAlleleProb);
+}
+
Added: spamassassin/trunk/build/pga/source/select.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/source/select.c?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/source/select.c (added)
+++ spamassassin/trunk/build/pga/source/select.c Sun May 28 18:31:49 2017
@@ -0,0 +1,478 @@
+/*
+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: select.c: This file contains the routines that have to do with
+* selection
+*
+* Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle,
+* Brian P. Walenz
+*****************************************************************************/
+
+#include "pgapack.h"
+
+/*U****************************************************************************
+ PGASelect - performs genetic algorithm selection using either the default
+ selection scheme or that specified with PGASetSelectType(). Valid selection
+ methods are proportional, stochastic universal, tournament, or probabilistic
+ tournament selection, PGA_SELECT_PROPORTIONAL, PGA_SELECT_SUS,
+ PGA_SELECT_TOURNAMENT, and PGA_SELECT_PTOURNAMENT, respectively. This
+ function updates an internal array with the indices of members of popix
+ selected for recombination. These indices may be accessed with
+ PGASelectNextIndex()
+
+ Category: Operators
+
+ Inputs:
+ ctx - context variable
+ popix - symbolic constant of population to select from
+
+ Outputs:
+ An array used by PGASelectNextIndex() is created which contains the
+ population indices of the selected individuals.
+
+ Example:
+ PGAContext *ctx,
+ :
+ PGASelect(ctx, PGA_OLDPOP);
+
+****************************************************************************U*/
+void PGASelect( PGAContext *ctx, int popix )
+{
+ int i; /* not to intefere with dummy argument */
+ int j; /* random number */
+ int temp; /* for shuffling selected indices US */
+ PGAIndividual *pop; /* pointer to appropriate population */
+
+ PGADebugEntered("PGASelect");
+
+ pop = PGAGetIndividual(ctx, 0, popix);
+
+ switch (ctx->ga.SelectType) {
+
+ case PGA_SELECT_PROPORTIONAL: /* proportional selection */
+ for (i=0; i<ctx->ga.PopSize; i++)
+ ctx->ga.selected[i] = PGASelectProportional( ctx, pop );
+ break;
+ case PGA_SELECT_SUS: /* stochastic universal selection */
+ PGASelectSUS( ctx, pop );
+ break;
+ case PGA_SELECT_TOURNAMENT: /* tournament selection */
+ for (i=0; i<ctx->ga.PopSize; i++)
+ ctx->ga.selected[i] = PGASelectTournament( ctx, pop );
+ break;
+ case PGA_SELECT_PTOURNAMENT: /* probabilistic tournament selection */
+ for (i=0; i<ctx->ga.PopSize; i++)
+ ctx->ga.selected[i] = PGASelectPTournament( ctx, pop );
+ break;
+ default:
+ PGAError( ctx,
+ "PGASelect: Invalid value of SelectType:",
+ PGA_FATAL,
+ PGA_INT,
+ (void *) &(ctx->ga.SelectType) );
+ break;
+ }
+
+ /* randomize selected string locations */
+ for (i=0; i<ctx->ga.PopSize; i++) {
+ j = PGARandomInterval(ctx, 0,ctx->ga.PopSize-1);
+ temp = ctx->ga.selected[j];
+ ctx->ga.selected[j] = ctx->ga.selected[i];
+ ctx->ga.selected[i] = temp;
+ }
+
+ PGADebugExited("PGASelect");
+}
+
+/*U****************************************************************************
+ PGASelectNextIndex - returns the index of next individual in
+ internal array that contains the indices determined by PGASelect
+
+ Category: Operators
+
+ Inputs:
+ ctx - context variable
+
+ Outputs:
+ A population index for the next selected creature.
+
+ Example:
+ PGAContext *ctx;
+ int l;
+ :
+ l = PGASelectNextIndex(ctx, PGA_OLDPOP);
+
+****************************************************************************U*/
+int PGASelectNextIndex ( PGAContext *ctx )
+{
+ PGADebugEntered("PGASelectNextIndex");
+
+ if (ctx->ga.SelectIndex < ctx->ga.PopSize) {
+ PGADebugExited("PGASelectNextIndex");
+ return(ctx->ga.selected[ctx->ga.SelectIndex++]);
+ }
+
+ /* Oops. We never found the index. Fatal error. (return is here
+ * so that compilers will be quiet.)
+ */
+ PGAError( ctx, "PGASelectNextIndex: SelectIndex >= ctx->ga.PopSize",
+ PGA_FATAL, PGA_INT, (void *) &ctx->ga.SelectIndex );
+ return(0);
+}
+
+/*U****************************************************************************
+ PGASetSelectType - specify the type of selection to use. Valid choices
+ are PGA_SELECT_PROPORTIONAL, PGA_SELECT_SUS, PGA_SELECT_TOURNAMENT, and
+ PGA_SELECT_PTOURNAMENT for proportional, stochastic universal selection,
+ tournament, and probabilistic tournament selection, respectively. The
+ default is PGA_SELECT_TOURNAMENT.
+
+ Category: Operators
+
+ Inputs:
+ ctx - context variable
+ select_type - symbolic constant to specify selection type
+
+ Outputs:
+ None
+
+ Example:
+ PGAContext *ctx;
+ :
+ PGASetSelectType(ctx, PGA_SELECT_SUS);
+
+****************************************************************************U*/
+void PGASetSelectType( PGAContext *ctx, int select_type)
+{
+
+ PGADebugEntered("PGASetSelectType");
+
+ switch (select_type) {
+ case PGA_SELECT_PROPORTIONAL:
+ case PGA_SELECT_SUS:
+ case PGA_SELECT_TOURNAMENT:
+ case PGA_SELECT_PTOURNAMENT:
+ ctx->ga.SelectType = select_type;
+ break;
+ default:
+ PGAError ( ctx, "PGASetSelectType: Invalid value of select_type:",
+ PGA_FATAL, PGA_INT, (void *) &select_type);
+ break;
+ }
+
+ PGADebugExited("PGASetSelectType");
+}
+
+/*U***************************************************************************
+ PGAGetSelectType - Returns the type of selection selected
+
+ Category: Operators
+
+ Inputs:
+ ctx - context variable
+
+ Outputs:
+ Returns the integer corresponding to the symbolic constant
+ used to specify the type of selection specified
+
+ Example:
+ PGAContext *ctx;
+ int selecttype;
+ :
+ selecttype = PGAGetSelectType(ctx);
+ switch (selecttype) {
+ case PGA_SELECT_PROPORTIONAL:
+ printf("Selection Type = PGA_SELECT_PROPORTIONAL\n");
+ break;
+ case PGA_SELECT_SUS:
+ printf("Selection Type = PGA_SELECT_SUS\n");
+ break;
+ case PGA_SELECT_TOURNAMENT:
+ printf("Selection Type = PGA_SELECT_TOURNAMENT\n");
+ break;
+ case PGA_SELECT_PTOURNAMENT:
+ printf("Selection Type = PGA_SELECT_PTOURNAMENT\n");
+ break;
+ }
+
+***************************************************************************U*/
+int PGAGetSelectType (PGAContext *ctx)
+{
+ PGADebugEntered("PGAGetSelectType");
+ PGAFailIfNotSetUp("PGAGetSelectType");
+
+ PGADebugExited("PGAGetSelectType");
+
+ return(ctx->ga.SelectType);
+}
+
+
+/*U****************************************************************************
+ PGASetPTournamentProb - Specifies the probability that the string that wins
+ a binary tournament will be selected. This function will have no effect
+ unless PGA_SELECT_PTOURNAMENT was specified as the type of selection to
+ use with PGASetSelectType. The default value is 0.6.
+
+ Category: Operators
+
+ Inputs:
+ ctx - context variable
+ p - the probability of selecting the better string
+
+ Outputs:
+ None
+
+ Example:
+ PGAContext *ctx;
+ :
+ PGASetPTournamentProb(ctx,0.8);
+
+****************************************************************************U*/
+void PGASetPTournamentProb(PGAContext *ctx, double ptournament_prob)
+{
+ PGADebugEntered("PGASetPTournamentProb");
+
+ ctx->ga.PTournamentProb = ptournament_prob;
+
+ PGADebugExited("PGASetPTournamentProb");
+}
+
+/*U***************************************************************************
+ PGAGetPTournamentProb - returns the probability of selecting the best
+ string in a probabilistic binary tournament
+
+ Category: Operators
+
+ Inputs:
+ ctx - context variable
+
+ Outputs:
+ The probabilistic binary tournament selection probability
+
+ Example:
+ PGAContext *ctx;
+ double pt;
+ :
+ pt = PGAGetPTournamentProb(ctx);
+
+***************************************************************************U*/
+double PGAGetPTournamentProb(PGAContext *ctx)
+{
+ PGADebugEntered("PGAGetPTournamentProb");
+ PGAFailIfNotSetUp("PGAGetPTournamentProb");
+
+ PGADebugExited("PGAGetPTournamentProb");
+
+ return ctx->ga.PTournamentProb;
+}
+
+
+/*I****************************************************************************
+ PGASelectProportional - selects a parent for the next generation using a
+ linear search through a (fitness) weighted ``roulette wheel''. The
+ probability of selection is given by p_i = f_i/sum(i)f_i
+ Ref: D. Goldberg, Genetic Algorithms, pg.
+
+ Inputs:
+ ctx - context variable
+ popix - symbolic constant of population to select from
+
+ Outputs:
+ index of the selected string
+
+ Example:
+ PGAContext *ctx,
+ int l;
+ :
+ l = PGASelectProportional(ctx, PGA_OLDPOP);
+
+****************************************************************************I*/
+int PGASelectProportional(PGAContext *ctx, PGAIndividual *pop)
+{
+ double sum, sumfitness, r;
+ int i;
+
+ PGADebugEntered("PGASelectProportional");
+
+ sumfitness = 0.0;
+ for (i=0; i<ctx->ga.PopSize; i++)
+ sumfitness += (pop+i)->fitness;
+
+ i = 0;
+ sum = (pop+i)->fitness;
+
+ r = sumfitness * PGARandom01(ctx, 0);
+ while(r > sum || i==ctx->ga.PopSize) {
+ i++;
+ sum += (pop+i)->fitness;
+ }
+
+ PGADebugExited("PGASelectProportional");
+
+ return(i);
+}
+
+/*I****************************************************************************
+ PGASelectSUS - A select routine using stochastic universal sampling
+ Ref: J. Baker, Reducing Bias and Inefficiency in the Selection Algorithm.
+ Second GA conference, pp 14-21 (page 16)
+
+ Inputs:
+ ctx - context variable
+ popix - symbolic constant of population to select from
+
+ Outputs:
+ the array ga.selected[] created via side effect. I.e., this routine
+ creates the entire selected population with one call
+
+ Example:
+ PGAContext *ctx,
+ :
+ PGASelectSUS(ctx, PGA_OLDPOP);
+
+****************************************************************************I*/
+void PGASelectSUS( PGAContext *ctx, PGAIndividual *pop )
+{
+ int i;
+ int k; /* index to fill samples array */
+ double davg; /* population average fitness */
+ double sum; /* running sum of expected values */
+ double r; /* random number */
+
+ PGADebugEntered("PGASelectSUS");
+
+ /* fill the expected value array */
+ davg = 0.0;
+ for(i=0;i<ctx->ga.PopSize;i++)
+ davg += (pop+i)->fitness;
+ davg /= (double) ctx->ga.PopSize;
+ for(i=0;i<ctx->ga.PopSize;i++)
+ ctx->scratch.dblscratch[i] = (pop+i)->fitness / davg;
+
+ /* select ctx->ga.PopSize as follows */
+ sum = 0;
+ k = 0;
+ r = PGARandom01(ctx, 0);
+ for(i=0;i<ctx->ga.PopSize;i++)
+ for( sum+=ctx->scratch.dblscratch[i]; sum>r; r++ )
+ ctx->ga.selected[k++] = i;
+
+ PGADebugExited("PGASelectSUS");
+}
+
+
+/*I****************************************************************************
+ PGASelectTournament - chooses two strings randomly and returns the one with
+ higher fitness
+ Ref: D. Goldberg, Genetic Algorithms, pg. 121
+
+ Inputs:
+ ctx - context variable
+ popix - symbolic constant of population to select from
+
+ Outputs:
+ index of the selected string
+
+ Example:
+ PGAContext *ctx,
+ int l;
+ :
+ l = PGASelectTournament(ctx, PGA_OLDPOP);
+
+****************************************************************************I*/
+int PGASelectTournament( PGAContext *ctx, PGAIndividual *pop )
+{
+ int m1, m2;
+
+ PGADebugEntered("PGASelectTournament");
+
+ m1 = PGARandomInterval(ctx, 0, ctx->ga.PopSize-1);
+ m2 = PGARandomInterval(ctx, 0, ctx->ga.PopSize-1);
+
+ PGADebugExited("PGASelectTournament");
+
+ return( ((pop+m1)->fitness > (pop+m2)->fitness) ? m1 : m2);
+}
+
+/*I****************************************************************************
+ PGASelectPTournament - chooses two strings randomly and returns the one with
+ higher fitness with a specified probability
+ Ref: D. Goldberg, Genetic Algorithms, pg. 121
+
+ Inputs:
+ ctx - context variable
+ popix - symbolic constant of population to select from
+
+ Outputs:
+ index of the selected string
+
+ Example:
+ PGAContext *ctx,
+ int l;
+ :
+ l = PGASelectPTournament(ctx, PGA_OLDPOP);
+
+****************************************************************************I*/
+int PGASelectPTournament( PGAContext *ctx, PGAIndividual *pop )
+{
+ int m1, m2;
+ int RetVal;
+
+ PGADebugEntered("PGASelectPTournament");
+
+ m1 = PGARandomInterval(ctx, 0, ctx->ga.PopSize-1);
+ m2 = PGARandomInterval(ctx, 0, ctx->ga.PopSize-1);
+
+ if ( (pop+m1)->fitness > (pop+m2)->fitness )
+ if ( (double) PGARandom01(ctx, 0) < ctx->ga.PTournamentProb )
+ RetVal = m1;
+ else
+ RetVal = m2;
+ else
+ if ( (double) PGARandom01(ctx, 0) < ctx->ga.PTournamentProb )
+ RetVal = m2;
+ else
+ RetVal = m1;
+
+ PGADebugExited("PGASelectPTournament");
+ return(RetVal);
+}
+
+
Added: spamassassin/trunk/build/pga/source/stop.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/source/stop.c?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/source/stop.c (added)
+++ spamassassin/trunk/build/pga/source/stop.c Sun May 28 18:31:49 2017
@@ -0,0 +1,354 @@
+/*
+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: stop.c: This file contains routines related to the stopping
+* conditions for the GA.
+*
+* Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle,
+* Brian P. Walenz
+*****************************************************************************/
+
+#include "pgapack.h"
+
+/*U****************************************************************************
+ PGADone - Returns PGA_TRUE if the stopping conditions have been met,
+ otherwise returns false. Calls exactly one of the user defined C or
+ fortran or system (PGACheckStoppingConditions) stopping condition functions.
+
+ Category: Generation
+
+ Inputs:
+ ctx - context variable
+ comm - an MPI communicator
+
+ Outputs:
+ returns PGA_TRUE if at least one of the termination conditions has been
+ met. Otherwise, returns PGA_FALSE
+
+ Example:
+ PGAContext *ctx;
+ :
+ PGADone(ctx, comm);
+
+****************************************************************************U*/
+int PGADone(PGAContext *ctx, MPI_Comm comm)
+{
+ int rank, size, done;
+
+ PGADebugEntered("PGADone");
+
+ rank = PGAGetRank(ctx, comm);
+ size = PGAGetNumProcs(ctx, comm);
+
+ if (rank == 0) {
+ if (ctx->fops.StopCond)
+ done = (*ctx->fops.StopCond)(&ctx);
+ else if (ctx->cops.StopCond)
+ done = (*ctx->cops.StopCond)(ctx);
+ else
+ done = PGACheckStoppingConditions(ctx);
+ }
+
+ if (size > 1)
+ MPI_Bcast(&done, 1, MPI_INT, 0, comm);
+
+ PGADebugExited("PGADone");
+
+ return(done);
+}
+
+/*U****************************************************************************
+ PGACheckStoppingConditions - returns boolean to indicate if the PGAPack
+ termination conditions -- PGA_STOP_MAXITER, PGA_STOP_TOOSIMILAR,
+ PGA_STOP_NOCHANGE -- have been met.
+
+ Category: Generation
+
+ Inputs:
+ ctx - context variable
+
+ Outputs:
+ returns PGA_TRUE if at least one of the termination conditions has been
+ met. Otherwise, returns PGA_FALSE
+
+ Example:
+ PGAContext *ctx;
+ :
+ PGACheckStoppingConditions(ctx);
+
+****************************************************************************U*/
+int PGACheckStoppingConditions( PGAContext *ctx)
+{
+ int done = PGA_FALSE;
+
+ PGADebugEntered("PGACheckStoppingConditions");
+
+ if (((ctx->ga.StoppingRule & PGA_STOP_MAXITER) == PGA_STOP_MAXITER) &&
+ (ctx->ga.iter > ctx->ga.MaxIter))
+ done |= PGA_TRUE;
+
+ if (((ctx->ga.StoppingRule & PGA_STOP_NOCHANGE) == PGA_STOP_NOCHANGE) &&
+ (ctx->ga.ItersOfSame >= ctx->ga.MaxNoChange))
+ done |= PGA_TRUE;
+
+ if (((ctx->ga.StoppingRule & PGA_STOP_TOOSIMILAR) == PGA_STOP_TOOSIMILAR) &&
+ (ctx->ga.PercentSame >= ctx->ga.MaxSimilarity))
+ done |= PGA_TRUE;
+
+ PGADebugExited("PGACheckStoppingConditions");
+ return(done);
+}
+
+/*U****************************************************************************
+ PGASetStoppingRuleType - specify a stopping criterion. If called more than
+ once the different stopping criterion are ORed together. Valid choices
+ are PGA_STOP_MAXITER, PGA_STOP_TOOSIMILAR, or PGA_STOP_NOCHANGE to
+ specify iteration limit reached, population too similar, or no change in
+ the best solution found in a given number of iterations, respectively.
+ The default is to stop when a maximum iteration limit is reached (by
+ default, 1000 iterations).
+
+ Category: Generation
+
+ Inputs:
+ ctx - context variable
+ stoprule - symbolic constant to specify stopping rule
+
+ Outputs:
+ None
+
+ Example:
+ PGAContext *ctx;
+ :
+ PGASetStoppingRuleType(ctx, PGA_STOP_TOOSIMILAR);
+
+****************************************************************************U*/
+void PGASetStoppingRuleType (PGAContext *ctx, int stoprule)
+{
+
+ PGADebugEntered("PGASetStoppingRuleType");
+ PGAFailIfSetUp("PGASetStoppingRuleType");
+
+ switch (stoprule) {
+ case PGA_STOP_MAXITER :
+ case PGA_STOP_NOCHANGE :
+ case PGA_STOP_TOOSIMILAR :
+ ctx->ga.StoppingRule |= stoprule;
+ break;
+ default:
+ PGAError( ctx,
+ "PGASetStoppingRuleType: Invalid value of stoprule:",
+ PGA_FATAL, PGA_INT, (void *) &stoprule );
+ }
+
+ PGADebugExited("PGASetStoppingRuleType");
+}
+
+/*U***************************************************************************
+ PGAGetStoppingRuleType - Returns a symbolic constant that defines the
+ termination criteria.
+
+ Category: Generation
+
+ Inputs:
+ ctx - context variable
+
+ Outputs:
+ Returns an integer which is an ORed mask of the symbolic constants
+ used to specify the stopping rule(s).
+
+ Example:
+ PGAContext *ctx;
+ int stop;
+ :
+ stop = PGAGetStoppingRuleType(ctx);
+ if (stop & PGA_STOP_MAXITER)
+ printf("Stopping Rule = PGA_STOP_MAXITER\n");
+ if (stop & PGA_STOP_NOCHANGE)
+ printf("Stopping Rule = PGA_STOP_NOCHANGE\n");
+ if (stop & PGA_STOP_TOOSIMILAR)
+ printf("Stopping Rule = PGA_STOP_TOOSIMILAR\n");
+
+***************************************************************************U*/
+int PGAGetStoppingRuleType (PGAContext *ctx)
+{
+ PGADebugEntered("PGAGetStoppingRuleType");
+ PGAFailIfNotSetUp("PGAGetStoppingRuleType");
+
+ PGADebugExited("PGAGetStoppingRuleType");
+
+ return(ctx->ga.StoppingRule);
+}
+
+/*U****************************************************************************
+ PGASetMaxGAIterValue - specify the maximum number of iterations for the
+ stopping rule PGA_STOP_MAXITER (which, by itself, is the default stopping
+ rule and is always in effect). The default value is 1000 iterations.
+
+ Category: Generation
+
+ Inputs:
+ ctx - context variable
+ maxiter - the maximum number of GA iterations to run before stopping
+
+ Outputs:
+ None
+
+ Example:
+ PGAContext *ctx;
+ :
+ PGASetMaxGAIterValue(ctx,5000);
+
+****************************************************************************U*/
+void PGASetMaxGAIterValue(PGAContext *ctx, int maxiter)
+{
+
+ PGADebugEntered("PGASetMaxGAIterValue");
+ PGAFailIfSetUp("PGASetMaxGAIterValue");
+
+ if (maxiter < 1)
+ PGAError( ctx, "PGASetMaxGAIterValue: Invalid value of maxiter:",
+ PGA_FATAL, PGA_INT, (void *) &maxiter );
+ else
+ ctx->ga.MaxIter = maxiter;
+
+ PGADebugExited("PGASetMaxGAIterValue");
+}
+
+/*U***************************************************************************
+ PGAGetMaxGAIterValue - Returns the maximum number of iterations to run
+
+ Category: Generation
+
+ Inputs:
+ ctx - context variable
+
+ Outputs:
+ The maximum number of iterations to run
+
+ Example:
+ PGAContext *ctx;
+ int maxiter;
+ :
+ maxiter = PGAGetMaxGAIterValue(ctx);
+
+***************************************************************************U*/
+int PGAGetMaxGAIterValue (PGAContext *ctx)
+{
+ PGADebugEntered("PGAGetMaxGAIterValue");
+ PGAFailIfNotSetUp("PGAGetMaxGAIterValue");
+
+ PGADebugExited("PGAGetMaxGAIterValue");
+
+ return(ctx->ga.MaxIter);
+}
+
+/*U****************************************************************************
+ PGASetMaxNoChangeValue - specifiy maximum number of iterations of no change
+ in the evaluation function value of the best string before stopping. The
+ default value is 50. The stopping rule PGA_STOP_NOCHANGE must have been
+ set by PGASetStoppingRuleType for this function call to have any effect.
+
+ Category: Generation
+
+ Inputs:
+ ctx - context variable
+ maxiter - the maximum number of GA iterations allowed with no change
+ in the best evaluation function value.
+
+ Outputs:
+ None
+
+ Example:
+ PGAContext *ctx;
+ :
+ PGASetMaxGAIterValue(ctx,5000);
+
+****************************************************************************U*/
+void PGASetMaxNoChangeValue(PGAContext *ctx, int max_no_change)
+{
+ PGADebugEntered("PGASetMaxNoChangeValue");
+ PGAFailIfSetUp("PGASetMaxNoChangeValue");
+
+ if (max_no_change <= 0)
+ PGAError(ctx, "PGASetMaxNoChangeValue: max_no_change invalid",
+ PGA_FATAL, PGA_INT, (void *)&max_no_change);
+
+ ctx->ga.MaxNoChange = max_no_change;
+
+ PGADebugExited("PGASetMaxNoChangeValue");
+}
+
+/*U****************************************************************************
+ PGASetMaxSimilarityValue - Specifiy the maximum percent of homogeneity of
+ the population before stopping. The similarity measure is the same
+ evaluation function value. The default value is 95 percent. The stopping
+ rule PGA_STOP_TOOSIMILAR must have been set by PGASetStoppingRuleType for
+ this function call to have any effect.
+
+ Category: Generation
+
+ Inputs:
+ ctx - context variable
+ max_similarity - the maximum percent of the population that can share
+ the same evaluation function value
+
+ Outputs:
+ None
+
+ Example:
+ PGAContext *ctx;
+ :
+ PGASetMaxSimilarityValue(ctx,99);
+
+****************************************************************************U*/
+void PGASetMaxSimilarityValue(PGAContext *ctx, int max_similarity)
+{
+ PGADebugEntered("PGASetMaxSimilarityValue");
+ PGAFailIfSetUp("PGASetMaxSimilarityValue");
+
+ if ((max_similarity <= 0) || (max_similarity > 100))
+ PGAError(ctx, "PGASetMaxSimilarityValue: max_similarity invalid",
+ PGA_FATAL, PGA_INT, (void *) &max_similarity);
+
+ ctx->ga.MaxSimilarity = max_similarity;
+
+ PGADebugExited("PGASetMaxSimilarityValue");
+}
Added: spamassassin/trunk/build/pga/source/system.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/source/system.c?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/source/system.c (added)
+++ spamassassin/trunk/build/pga/source/system.c Sun May 28 18:31:49 2017
@@ -0,0 +1,353 @@
+/*
+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: system.c: This file contains systme routines such as errors and
+* exits
+*
+* Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle,
+* Brian P. Walenz
+*****************************************************************************/
+
+#include "pgapack.h"
+
+char PGAProgram[100]; /* Holds argv[0] for PGAUsage() call */
+
+/*U****************************************************************************
+ PGAError - reports error messages. Prints out the message supplied, and
+ the value of a piece of data. Terminates if PGA_FATAL.
+
+ Category: System
+
+ Inputs:
+ ctx - context variable
+ msg - the error message to print
+ level - PGA_WARNING or PGA_FATAL to indicate the error's severity
+ datatype - the data type of the following argument
+ data - the address of the data to be written out, cast as a void
+ pointer
+
+ Outputs:
+ None
+
+ Example:
+ PGAContext *ctx;
+ int val;
+ :
+ PGAError(ctx, "Some Non Fatal Error: val = ", PGA_WARNING, PGA_INT,
+ (void *) &val);
+ :
+ PGAError(ctx, "A Fatal Error!", PGA_FATAL, PGA_VOID, NULL);
+
+****************************************************************************U*/
+void PGAError( PGAContext *ctx, char *msg,
+ int level, int datatype, void *data )
+{
+
+ PGADebugEntered("PGAError");
+
+ switch (datatype) {
+ case PGA_INT:
+ fprintf(stderr, "%s %d\n", msg, *(int *) data);
+ break;
+ case PGA_DOUBLE:
+ fprintf(stderr, "%s %f\n", msg, *(double *) data);
+ break;
+ case PGA_CHAR:
+ fprintf(stderr, "%s %s\n", msg, (char *) data);
+ break;
+ case PGA_VOID:
+ fprintf(stderr, "%s\n", msg);
+ break;
+ }
+ if ( level == PGA_FATAL ) {
+ fprintf(stderr, "PGAError: Fatal\n");
+ PGADestroy(ctx);
+ exit(-1);
+ }
+ PGADebugExited("PGAError");
+}
+
+/*U****************************************************************************
+ PGADestroy - deallocate memory for this instance of PGAPack, if this context
+ initialized MPI, finalize MPI as well.
+
+ Category: Generation
+
+ Inputs:
+ ctx - context variable
+
+ Outputs:
+ None
+
+ Example:
+ PGAContext *ctx;
+ :
+ PGADestroy(ctx);
+
+****************************************************************************U*/
+void PGADestroy (PGAContext *ctx)
+{
+ int i;
+
+ PGADebugEntered("PGADestroy");
+
+ /* These are allocated by PGASetUp. Free then only if PGASetUp
+ * was called.
+ */
+ if (ctx->sys.SetUpCalled == PGA_TRUE) {
+ /* Free the population...fly little birdies! You're FREE!!! */
+ for ( i = 0; i < ctx->ga.PopSize + 2; i++ ) {
+ free ( ctx->ga.oldpop[i].chrom );
+ free ( ctx->ga.newpop[i].chrom );
+ }
+ free ( ctx->ga.oldpop );
+ free ( ctx->ga.newpop );
+
+ /* Free the scratch space. */
+ free ( ctx->scratch.intscratch );
+ free ( ctx->scratch.dblscratch );
+ free ( ctx->ga.selected );
+ free ( ctx->ga.sorted );
+ }
+
+ /* These are allocated by PGACreate */
+ if (ctx->ga.datatype == PGA_DATATYPE_REAL)
+ {
+ free ( ctx->init.RealMax );
+ free ( ctx->init.RealMin );
+ }
+ else if (ctx->ga.datatype == PGA_DATATYPE_INTEGER)
+ {
+ free ( ctx->init.IntegerMax );
+ free ( ctx->init.IntegerMin );
+ }
+
+ /* We want to finalize MPI only if it was not started for us (as
+ * fortran would do) AND it is actually running. It would not be
+ * running if, for example, -pgahelp is specified on the command
+ * line.
+ */
+ MPI_Initialized(&i);
+ if ((ctx->par.MPIAlreadyInit == PGA_FALSE) && i)
+ MPI_Finalize();
+
+ /* We really should perform a PGADebugPrint here, but we can't;
+ * we've already deallocated most of the stuff we need!!
+ */
+ free ( ctx );
+}
+
+/*U***************************************************************************
+ PGAGetMaxMachineIntValue - returns the largest integer of the current
+ machine
+
+ Category: System
+
+ Inputs:
+ ctx - context variable
+
+ Outputs:
+ The largest integer of the given machine
+
+ Example:
+ PGAContext *ctx;
+ int intmax;
+ :
+ intmax = PGAGetMaxMachineIntValue(ctx);
+
+***************************************************************************U*/
+int PGAGetMaxMachineIntValue (PGAContext *ctx)
+{
+ PGADebugEntered("PGAGetMaxMachineIntValue");
+
+ PGADebugExited("PGAGetMaxMachineIntValue");
+
+ return(ctx->sys.PGAMaxInt);
+}
+
+/*U***************************************************************************
+ PGAGetMaxMachineIntValue - returns the smallest integer of the current
+ machine
+
+ Category: System
+
+ Inputs:
+ ctx - context variable
+
+ Outputs:
+ The smallest integer of the given machine
+
+ Example:
+ PGAContext *ctx;
+ int intmin;
+ :
+ intmin = PGAGetMinMachineIntValue(ctx);
+
+***************************************************************************U*/
+int PGAGetMinMachineIntValue (PGAContext *ctx)
+{
+ PGADebugEntered("PGAGetMinMachineIntValue");
+
+ PGADebugExited("PGAGetMinMachineIntValue");
+
+ return(ctx->sys.PGAMinInt);
+}
+
+/*U***************************************************************************
+ PGAGetMaxMachineDoubleValue - returns the largest double of the current
+ machine
+
+ Category: System
+
+ Inputs:
+ ctx - context variable
+
+ Outputs:
+ The largest double of the given machine
+
+ Example:
+ PGAContext *ctx;
+ double big;
+ :
+ big = PGAGetMaxMachineDoubleValue(ctx);
+
+***************************************************************************U*/
+double PGAGetMaxMachineDoubleValue (PGAContext *ctx)
+{
+ PGADebugEntered("PGAGetMaxMachineDoubleValue");
+
+ PGADebugExited("PGAGetMaxMachineDoubleValue");
+
+ return(ctx->sys.PGAMaxDouble);
+}
+
+/*U***************************************************************************
+ PGAGetMaxMachineDoubleValue - returns the smallest double of the current
+ machine
+
+ Category: System
+
+ Inputs:
+ ctx - context variable
+
+ Outputs:
+ The smallest double of the given machine
+
+ Example:
+ PGAContext *ctx;
+ double small;
+ :
+ small = PGAGetMinMachineDoubleValue(ctx);
+
+***************************************************************************U*/
+double PGAGetMinMachineDoubleValue (PGAContext *ctx)
+{
+ PGADebugEntered("PGAGetMinMachineDoubleValue");
+
+ PGADebugExited("PGAGetMinMachineDoubleValue");
+
+ return(ctx->sys.PGAMinDouble);
+}
+
+
+/*U****************************************************************************
+ PGAUsage - print list of available parameters and quit
+
+ Inputs:
+ ctx - context variable
+
+ Outputs:
+ list of available parametersNone
+
+ Example:
+ PGAContext ctx;
+ :
+ PGAUsage(ctx);
+
+****************************************************************************U*/
+void PGAUsage( PGAContext *ctx )
+{
+ /* Print the usage info out if MPI isn't running (thus, only one process
+ * is probably running), or if we actually are the master.
+ */
+ if (!ctx->par.MPIAlreadyInit || (PGAGetRank(ctx, MPI_COMM_WORLD) == 0)) {
+ PGAPrintVersionNumber( ctx );
+ printf("PGAPack usage: %s [pga options]\n", PGAProgram);
+ printf("Valid PGAPack options:\n");
+ printf("\t-pgahelp \tget this message\n");
+ printf("\t-pgahelp debug \tlist of debug options\n");
+ printf("\t-pgadbg <option> \tset debug option\n");
+ printf("\t-pgadebug <option>\tset debug option\n");
+ printf("\t-pgaversion \tprint current PGAPack version number\n");
+ printf("\n");
+ }
+ PGADestroy(ctx);
+ exit(-1);
+}
+
+/*U****************************************************************************
+ PGAPrintVersionNumber - print PGAPack version number
+
+ Inputs:
+ ctx - context variable
+
+ Outputs:
+ PGAPack version number
+
+ Example:
+ PGAContext ctx;
+ :
+ PGAPrintVersionNumber(ctx);
+
+****************************************************************************U*/
+void PGAPrintVersionNumber( PGAContext *ctx )
+{
+ if (!ctx->par.MPIAlreadyInit || (PGAGetRank(ctx, MPI_COMM_WORLD) == 0)) {
+#ifdef FAKE_MPI
+#define PRINT1 "Sequential"
+#else
+#define PRINT1 "Parallel"
+#endif
+ printf("\nPGAPack version 1.0: (%s, %s)\n\n",
+ (OPTIMIZE) ? "Optimized" : "Debug",
+ PRINT1 );
+ }
+}
+
Added: spamassassin/trunk/build/pga/source/user.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/source/user.c?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/source/user.c (added)
+++ spamassassin/trunk/build/pga/source/user.c Sun May 28 18:31:49 2017
@@ -0,0 +1,170 @@
+/*
+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: user.c: This file contains a function to set user functions.
+*
+* Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle,
+* Brian P. Walenz
+*****************************************************************************/
+
+#include "pgapack.h"
+
+/*U****************************************************************************
+ PGASetUserFunction - specifies the name of a user-written function
+ call to provide a specific GA capability (e.g., crossover,
+ mutation, etc.). This function MUST be used when using a non-native
+ datatype and must be called once for each of:
+ PGA_USERFUNCTION_CREATESTRING -- String creation
+ PGA_USERFUNCTION_MUTATION -- Mutation
+ PGA_USERFUNCTION_CROSSOVER -- Crossover
+ PGA_USERFUNCTION_PRINTSTRING -- String Output
+ PGA_USERFUNCTION_COPYSTRING -- Duplication
+ PGA_USERFUNCTION_DUPLICATE -- Duplicate Checking
+ PGA_USERFUNCTION_INITSTRING -- Initialization
+ PGA_USERFUNCTION_BUILDDATATYPE -- MPI Datatype creation
+ PGA_USERFUNCTION_STOPCOND -- Stopping conditions
+ PGA_USERFUNCTION_ENDOFGEN -- Auxiliary functions at the end
+ of each generation
+ It MAY be called when using a native datatype to replace the built-in
+ functions PGAPack has for that datatype (For example, if the Integer data
+ type is used for a traveling salesperson problem, the user may want to
+ provide their own custom crossover operator). See the user guide and the
+ examples in the examples directory for more details.
+
+ Category: Generation
+
+ Inputs:
+ ctx - context variable
+ constant - symbolic constant of the user function to set
+ f - name of the function to use
+
+ Outputs:
+ None
+
+ Example:
+ void MyStringInit(PGAContext *, void *);
+ PGAContext *ctx;
+ :
+ PGASetUserFunction(ctx, PGA_USERFUNCTION_INITSTRING, MyStringInit);
+
+****************************************************************************U*/
+void PGASetUserFunction(PGAContext *ctx, int constant, void *f)
+{
+ PGADebugEntered("PGASetUserFunction");
+
+ if (f == NULL)
+ PGAError ( ctx, "PGASetUserFunction: Invalid function",
+ PGA_FATAL, PGA_VOID, NULL);
+
+ switch (constant) {
+ case PGA_USERFUNCTION_CREATESTRING:
+ if (ctx->sys.UserFortran)
+ PGAError(ctx, "PGASetUserFunction: Cannot call "
+ "PGA_USERFUNCTION_CREATESTRING from Fortran.",
+ PGA_FATAL, PGA_VOID, NULL);
+ else
+ ctx->cops.CreateString = (void(*)(PGAContext *, int, int, int))f;
+ break;
+ case PGA_USERFUNCTION_MUTATION:
+ if (ctx->sys.UserFortran)
+ ctx->fops.Mutation = (int(*)(void *, void *, void *, void *))f;
+ else
+ ctx->cops.Mutation = (int(*)(PGAContext *, int, int, double))f;
+ break;
+ case PGA_USERFUNCTION_CROSSOVER:
+ if (ctx->sys.UserFortran)
+ ctx->fops.Crossover = (void(*)(void *, void *, void *, void *, void *, void *, void *))f;
+ else
+ ctx->cops.Crossover = (void(*)(PGAContext *, int, int, int, int, int, int))f;
+ break;
+ case PGA_USERFUNCTION_PRINTSTRING:
+ if (ctx->sys.UserFortran)
+ ctx->fops.PrintString = (void(*)(void *, void *, void *, void *))f;
+ else
+ ctx->cops.PrintString = (void(*)(PGAContext *, FILE *, int, int))f;
+ break;
+ case PGA_USERFUNCTION_COPYSTRING:
+ if (ctx->sys.UserFortran)
+ PGAError(ctx, "PGASetUserFunction: Cannot call "
+ "PGA_USERFUNCTION_COPYSTRING from Fortran.",
+ PGA_FATAL, PGA_VOID, NULL);
+ else
+ ctx->cops.CopyString = (void(*)(PGAContext *, int, int, int, int))f;
+ break;
+ case PGA_USERFUNCTION_DUPLICATE:
+ if (ctx->sys.UserFortran)
+ ctx->fops.Duplicate = (int(*)(void *, void *, void *, void *, void *))f;
+ else
+ ctx->cops.Duplicate = (int(*)(PGAContext *, int, int, int, int))f;
+ break;
+ case PGA_USERFUNCTION_INITSTRING:
+ if (ctx->sys.UserFortran)
+ ctx->fops.InitString = (void(*)(void *, void *, void *))f;
+ else
+ ctx->cops.InitString = (void(*)(PGAContext *, int, int))f;
+ break;
+ case PGA_USERFUNCTION_BUILDDATATYPE:
+ if (ctx->sys.UserFortran)
+ PGAError(ctx, "PGASetUserFunction: Cannot call "
+ "PGA_USERFUNCTION_BUILDDATATYPE from Fortran.",
+ PGA_FATAL, PGA_VOID, NULL);
+ else
+ ctx->cops.BuildDatatype = (MPI_Datatype(*)(PGAContext *, int, int))f;
+ break;
+ case PGA_USERFUNCTION_STOPCOND:
+ if (ctx->sys.UserFortran)
+ ctx->fops.StopCond = (int(*)(void *))f;
+ else
+ ctx->cops.StopCond = (int(*)(PGAContext *))f;
+ break;
+ case PGA_USERFUNCTION_ENDOFGEN:
+ if (ctx->sys.UserFortran)
+ ctx->fops.EndOfGen = (void(*)(void *))f;
+ else
+ ctx->cops.EndOfGen = (void(*)(PGAContext *))f;
+ break;
+ default:
+ PGAError(ctx, "PGASetUserFunction: Invalid constant:",
+ PGA_FATAL, PGA_INT, (void *) &constant);
+ break;
+ }
+
+ PGADebugExited("PGASetUserFunction");
+}
Added: spamassassin/trunk/build/pga/source/utility.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/source/utility.c?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/source/utility.c (added)
+++ spamassassin/trunk/build/pga/source/utility.c Sun May 28 18:31:49 2017
@@ -0,0 +1,616 @@
+/*
+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: utility.c: This file contains routines that perform utility
+* functions.
+*
+* Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle,
+* Brian P. Walenz
+*****************************************************************************/
+
+#include <pgapack.h>
+
+/*U****************************************************************************
+ PGAMean - calculates the mean value of an array of elements
+
+ Category: Utility
+
+ Inputs:
+ ctx - context variable
+ a - array to take the mean of
+ n - number of elements in array a
+
+ Outputs:
+ The mean of the n elements in array a
+
+ Example:
+ PGAContext *ctx;
+ double a[100], mean;
+ :
+ mean = PGAMean(ctx, a, 100);
+
+****************************************************************************U*/
+double PGAMean ( PGAContext *ctx, double *a, int n)
+{
+ int i;
+ double result;
+
+ PGADebugEntered("PGAMean");
+
+ result = 0.;
+ for( i=n-1; i>=0; i-- )
+ result += a[i];
+
+ PGADebugExited("PGAMean");
+
+ return (result / (double) n );
+}
+
+
+/*U****************************************************************************
+ PGAStddev - calculates the standard deviation of an array of elements
+
+ Category: Utility
+
+ Inputs:
+ ctx - context variable
+ a - array to take the standard deviation of
+ n - number of elements in array a
+ mean - the mean of the elements in array a
+
+ Outputs:
+ The standard deviation of the n elements in array a
+
+ Example:
+ PGAContext *ctx;
+ double a[100], mean, sigma;
+ :
+ mean = PGAMean(ctx, a, 100);
+ sigma = PGAStddev(ctx, a, 100, mean);
+
+****************************************************************************U*/
+double PGAStddev ( PGAContext *ctx, double *a, int n, double mean)
+{
+ int i;
+ double result;
+
+ PGADebugEntered("PGAStddev");
+
+ result = 0;
+ for(i=n-1; i>=0; i--)
+ result += (a[i] - mean) * (a[i] - mean);
+ result = sqrt(result/n);
+
+ PGADebugExited("PGAStddev");
+ return (result);
+}
+
+/*U****************************************************************************
+ PGARound - Mathematically round a double to an integer, using 0.5 as the
+ cutoff value.
+
+ Category: Utility
+
+ Inputs:
+ ctx - context variable
+ x - the number to be rounded
+
+ Outputs:
+ The rounded number.
+
+ Example:
+ PGAContext *ctx;
+ int y;
+ y = PGARound(ctx, -78.6);
+
+****************************************************************************U*/
+int PGARound(PGAContext *ctx, double x)
+{
+ double ipart, frac;
+
+ PGADebugEntered("PGARound");
+
+ frac = modf(x, &ipart);
+ if (frac <= -0.5)
+ ipart--;
+ else if (frac >= 0.5)
+ ipart++;
+
+ PGADebugExited("PGARound");
+
+ return ((int)ipart);
+}
+
+/*U****************************************************************************
+ PGACopyIndividual - copies string p1 in population pop1 to position p2 in
+ population pop2
+
+ Category: Generation
+
+ 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 is an exact copy of string p1.
+
+ Example:
+ PGAContext *ctx;
+ int i,j;
+ :
+ PGACopyIndividual(ctx, i, PGA_OLDPOP, j, PGA_NEWPOP);
+
+****************************************************************************U*/
+void PGACopyIndividual( PGAContext *ctx, int p1, int pop1, int p2, int pop2)
+{
+ PGAIndividual *source, *dest;
+
+ PGADebugEntered("PGACopyIndividual");
+
+ source = PGAGetIndividual ( ctx, p1, pop1 );
+ dest = PGAGetIndividual ( ctx, p2, pop2 );
+
+ dest->evalfunc = source->evalfunc;
+ dest->fitness = source->fitness;
+ dest->evaluptodate = source->evaluptodate;
+
+ (*ctx->cops.CopyString)(ctx, p1, pop1, p2, pop2);
+
+ PGADebugExited("PGACopyIndividual");
+}
+
+/*U****************************************************************************
+ PGACheckSum - maps a string to a number to be used a verification check
+ PGA_DATATYPE_USER is not supported.
+
+ Category: Utility
+
+ Inputs:
+ ctx - context variable
+ p - string index
+ pop - symbolic constant for the population
+
+ Outputs:
+ An integer representing the "value" of the string.
+
+ Example:
+ PGAContext *ctx;
+ int p, sum;
+ :
+ sum = PGACheckSum(ctx, p, PGA_NEWPOP);
+
+****************************************************************************U*/
+int PGACheckSum(PGAContext *ctx, int p, int pop)
+{
+ long stringlen, totalchars, charbits, i, j, checksum, totalbytes, out_bit;
+ unsigned char *message, specimen;
+
+ PGADebugEntered("PGACheckSum");
+
+ stringlen = PGAGetStringLength(ctx);
+ switch (ctx->ga.datatype) {
+ case PGA_DATATYPE_BINARY:
+ totalbytes = ctx->ga.tw * sizeof(PGABinary);
+ break;
+ case PGA_DATATYPE_INTEGER:
+ totalbytes = stringlen * sizeof(PGAInteger);
+ break;
+ case PGA_DATATYPE_REAL:
+ totalbytes = stringlen * sizeof(PGAReal);
+ break;
+ case PGA_DATATYPE_CHARACTER:
+ totalbytes = stringlen * sizeof(PGACharacter);
+ break;
+ default:
+ totalbytes = 0;
+ PGAError(ctx, "PGACheckSum: User datatype checksum may be invalid.",
+ PGA_WARNING, PGA_VOID, NULL);
+ break;
+ }
+
+ message = (unsigned char *)PGAGetIndividual(ctx, p, pop)->chrom;
+ totalchars = totalbytes / sizeof(unsigned char);
+ charbits = sizeof(unsigned char) * 8;
+ checksum = 0;
+ for (i = 0; i < totalchars; i++) {
+ specimen = *(message + i);
+ for (j = 0; j < charbits; j++) {
+ out_bit = (checksum & 0x80000000) == 1;
+ checksum = (checksum << 1) + ((specimen & 0x80) == 0x80);
+ if (out_bit)
+ checksum ^= 0x04c11db7;
+ specimen <<= 1;
+ }
+ }
+
+ PGADebugExited("PGACheckSum");
+
+ return (checksum);
+}
+
+/*U***************************************************************************
+ PGAGetWorstIndex - returns the index of the string with the worst
+ evaluation function value in population pop
+
+ Category: Utility
+
+ Inputs:
+ ctx - context variable
+ pop - symbolic constant of the population to find the worst string in
+
+ Outputs:
+ Index of the string with the worst evaluation function value
+
+ Example:
+ PGAContext *ctx;
+ int worst;
+ :
+ worst = PGAGetWorstIndex(ctx,PGA_OLDPOP);
+
+***************************************************************************U*/
+int PGAGetWorstIndex(PGAContext *ctx, int pop)
+{
+ int p, worst_indx = 0;
+ double eval, worst_eval;
+
+ PGADebugEntered("PGAGetWorstIndex");
+
+ for (p = 0; p < ctx->ga.PopSize; p++)
+ if (!PGAGetEvaluationUpToDateFlag(ctx, p, pop))
+ PGAError(ctx, "PGAGetWorstIndex: Evaluate function not up to "
+ "date:", PGA_FATAL, PGA_INT, (void *) &p);
+
+ worst_eval = PGAGetEvaluation(ctx, 0, pop);
+ switch (PGAGetOptDirFlag(ctx)) {
+ case PGA_MAXIMIZE:
+ for (p = 1; p < ctx->ga.PopSize; p++) {
+ eval = PGAGetEvaluation(ctx, p, pop);
+ if (eval < worst_eval) {
+ worst_indx = p;
+ worst_eval = eval;
+ }
+ }
+ break;
+
+ case PGA_MINIMIZE:
+ for (p = 1; p < ctx->ga.PopSize; p++) {
+ eval = PGAGetEvaluation(ctx, p, pop);
+ if (eval > worst_eval) {
+ worst_indx = p;
+ worst_eval = eval;
+ }
+ }
+ break;
+ }
+
+ PGADebugExited("PGAGetWorstIndex");
+
+ return (worst_indx);
+}
+
+/*U***************************************************************************
+ PGAGetBestIndex - returns the index of the string with the best evaluation
+ function value in population pop
+
+ Category: Utility
+
+ Inputs:
+ ctx - context variable
+ pop - symbolic constant of the population to find the best string in
+
+ Outputs:
+ Index of the string with the best evaluation function value
+
+ Example:
+ PGAContext *ctx;
+ int best;
+ :
+ best = PGAGetBestIndex(ctx,PGA_OLDPOP);
+
+***************************************************************************U*/
+int PGAGetBestIndex(PGAContext *ctx, int pop)
+{
+ int p, Best_indx = 0;
+ double eval, Best_eval;
+
+ PGADebugEntered("PGAGetBestIndex");
+
+ for (p = 0; p < ctx->ga.PopSize; p++)
+ if (!PGAGetEvaluationUpToDateFlag(ctx, p, pop))
+ PGAError(ctx, "PGAGetBestIndex: Evaluate function not up to "
+ "date:", PGA_FATAL, PGA_INT, (void *) &p);
+
+ Best_eval = PGAGetEvaluation(ctx, 0, pop);
+
+ switch (PGAGetOptDirFlag(ctx)) {
+ case PGA_MAXIMIZE :
+ for (p = 1; p < ctx->ga.PopSize; p++) {
+ eval = PGAGetEvaluation(ctx, p, pop);
+ if (eval > Best_eval) {
+ Best_indx = p;
+ Best_eval = eval;
+ }
+ }
+ break;
+ case PGA_MINIMIZE :
+ for (p = 1; p < ctx->ga.PopSize; p++) {
+ eval = PGAGetEvaluation(ctx, p, pop);
+ if (eval < Best_eval) {
+ Best_indx = p;
+ Best_eval = eval;
+ }
+ }
+ break;
+ }
+
+ PGADebugExited("PGAGetBestIndex");
+
+ return (Best_indx);
+}
+
+
+/*I****************************************************************************
+ PGAGetIndividual - translate string index and population symbolic constant
+ into pointer to an individual
+
+ Inputs:
+ ctx - context variable
+ p - string index
+ pop - symbolic constant of the population the string is in
+
+ Outputs:
+ Address of the PGAIndividual structure for string p in population pop
+
+ Example:
+ PGAIndividual *source;
+ PGAContext *ctx;
+ int p;
+ :
+ source = PGAGetIndividual ( ctx, p, PGA_NEWPOP );
+
+****************************************************************************I*/
+PGAIndividual *PGAGetIndividual ( PGAContext *ctx, int p, int pop)
+{
+ PGAIndividual *ind;
+
+ PGADebugEntered("PGAGetIndividual");
+
+#ifdef OPTIMIZE
+ ind = (pop == PGA_OLDPOP) ? ctx->ga.oldpop : ctx->ga.newpop;
+
+ if (p>=0)
+ ind += p;
+ else
+ ind += (p == PGA_TEMP1) ? ctx->ga.PopSize : ctx->ga.PopSize+1;
+#else
+ if (pop == PGA_OLDPOP)
+ ind = ctx->ga.oldpop;
+ else
+ if (pop == PGA_NEWPOP)
+ ind = ctx->ga.newpop;
+ else
+ PGAError(ctx, "PGAGetIndividual: Invalid value of pop:",
+ PGA_FATAL, PGA_INT, (void *) &pop );
+
+ if (p>0 && p<ctx->ga.PopSize)
+ ind += p;
+ else
+ if (p == PGA_TEMP1)
+ ind += ctx->ga.PopSize;
+ else
+ if (p == PGA_TEMP2)
+ ind += ctx->ga.PopSize + 1;
+ else
+ PGAError(ctx, "PGAGetIndividual: Invalid value of p:",
+ PGA_FATAL, PGA_INT, (void *) &p );
+#endif
+
+ PGADebugExited("PGAGetIndividual");
+
+ return(ind);
+}
+
+
+/*I****************************************************************************
+ PGAUpdateAverage - Updates the average fitness statistic for reporting.
+
+ Inputs:
+ ctx - context variable
+ pop - symbolic constant of the population
+
+ Outputs:
+
+ Example:
+
+**************************************************************************I*/
+void PGAUpdateAverage(PGAContext *ctx, int pop)
+{
+ double ThisGensTotal = 0;
+ int p;
+
+ PGADebugEntered("PGAUpdateAverage");
+
+ for (p = 0; p < ctx->ga.PopSize; p++)
+ if (!PGAGetEvaluationUpToDateFlag(ctx, p, pop))
+ PGAError(ctx, "PGAUpdateOnline: Evaluate function not up to "
+ "date:", PGA_FATAL, PGA_INT, (void *) &p);
+
+ for (p = 0; p < ctx->ga.PopSize; p++)
+ ThisGensTotal += PGAGetEvaluation(ctx, p, pop);
+
+ ctx->rep.Average = ThisGensTotal / (double)ctx->ga.PopSize;
+
+ PGADebugExited("PGAUpdateAverage");
+}
+
+
+/*I****************************************************************************
+ PGAUpdateOnline - Updates the online value based on the results in
+ the new generation
+
+ Inputs:
+ ctx - context variable
+ pop - symbolic constant of the population whose statistics to use
+
+ Outputs:
+ Updates an internal field in the context variable
+
+ Example:
+ PGAContext *ctx;
+ :
+ PGAUpdateOnline(ctx,PGA_NEWPOP);
+
+**************************************************************************I*/
+void PGAUpdateOnline(PGAContext *ctx, int pop)
+{
+ double ThisGensTotal = 0;
+ int p;
+
+ PGADebugEntered("PGAUpdateOnline");
+
+ for (p = 0; p < ctx->ga.PopSize; p++)
+ if (!PGAGetEvaluationUpToDateFlag(ctx, p, pop))
+ PGAError(ctx, "PGAUpdateOnline: Evaluate function not up to "
+ "date:", PGA_FATAL, PGA_INT, (void *) &p);
+
+ for (p = 0; p < ctx->ga.PopSize; p++)
+ ThisGensTotal += PGAGetEvaluation(ctx, p, pop);
+
+ PGADebugPrint(ctx, PGA_DEBUG_PRINTVAR, "PGAUpdateOnline",
+ "ThisGensTotal = ", PGA_DOUBLE, (void *) &ThisGensTotal);
+
+ ctx->rep.Online = (ctx->rep.Online * ctx->ga.PopSize * (ctx->ga.iter - 1)
+ + ThisGensTotal) / ctx->ga.iter / ctx->ga.PopSize;
+
+ PGADebugExited("PGAUpdateOnline");
+
+}
+
+/*I****************************************************************************
+ PGAUpdateOffline - Updates the offline value based on the results in
+ the new generation
+
+ Inputs:
+ ctx - context variable
+ pop - symbolic constant of the population whose statistics to use
+
+ Outputs:
+ Updates an internal field in the context variable
+
+ Example:
+ PGAContext *ctx;
+ :
+ PGAUpdateOffline(ctx,PGA_NEWPOP);
+
+**************************************************************************I*/
+void PGAUpdateOffline(PGAContext *ctx, int pop)
+{
+ int p;
+
+ PGADebugEntered("PGAUpdateOffline");
+
+ for (p = 0; p < ctx->ga.PopSize; p++)
+ if (!PGAGetEvaluationUpToDateFlag(ctx, p, pop))
+ PGAError(ctx, "PGAUpdateOffline: Evaluate function not up to "
+ "date:", PGA_FATAL, PGA_INT, (void *) &p);
+
+ p = PGAGetBestIndex(ctx, pop);
+
+ ctx->rep.Offline = ((ctx->ga.iter - 1) * ctx->rep.Offline +
+ PGAGetEvaluation(ctx, p, pop)) / ctx->ga.iter;
+
+ PGADebugExited("PGAUpdateOffline");
+}
+
+/*I****************************************************************************
+ PGAComputeSimilarity - computes the percentage of the population that have
+ the same evaluation function
+
+ Inputs:
+ ctx - context variable
+ pop - symbolic constant of the population whose statistics to use
+
+ Outputs:
+ returns a count of the number of population members that have the same
+ evaluation function value
+
+ Example:
+ PGAContext *ctx;
+ :
+ PGAComputeSimilarity(ctx,PGA_NEWPOP);
+
+**************************************************************************I*/
+int PGAComputeSimilarity(PGAContext *ctx, PGAIndividual *pop)
+{
+ int max = 0, curr = 1, i;
+ double prev;
+
+ PGADebugEntered("PGAComputeSimilarity");
+
+ for(i=0; i < ctx->ga.PopSize; i++)
+ {
+ ctx->scratch.dblscratch[i] = (pop + i)->evalfunc;
+ ctx->scratch.intscratch[i] = i;
+ }
+
+ PGADblHeapSort(ctx, ctx->scratch.dblscratch, ctx->scratch.intscratch,
+ ctx->ga.PopSize);
+
+ prev = ctx->scratch.dblscratch[0];
+
+ for(i = 1; i < ctx->ga.PopSize; i++)
+ {
+ if (ctx->scratch.dblscratch[i] == prev)
+ curr++;
+ else
+ {
+ if (curr > max)
+ max = curr;
+ curr = 1;
+ }
+ }
+
+ PGADebugExited("PGAComputeSimilarity");
+
+ return(100 * max / ctx->ga.PopSize);
+}
Added: spamassassin/trunk/build/pga/test/Makefile
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/test/Makefile?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/test/Makefile (added)
+++ spamassassin/trunk/build/pga/test/Makefile Sun May 28 18:31:49 2017
@@ -0,0 +1,28 @@
+# Generated automatically from Makefile.in by configure.
+CC = cc
+FC = f77
+PRECFLAGS = -O
+PREFFLAGS = -w
+CPPFLAGS = -I/usr/local/pga/include -Dlinux -DWL=32 -DFORTRANUNDERSCORE -DOPTIMIZE -DFAKE_MPI
+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)
+FFLAGS = -o $@ $? $(PREFFLAGS)
+
+LINK.c = @echo " Compiling $@" ; $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
+LINK.f = @if test -n "$(FC)"; \
+ then echo " Compiling $@" ; $(FC) $(FFLAGS) $(LDFLAGS); \
+ else \
+ echo "$@: Fortran compiler unavailable"; fi
+
+default:
+ @make instverf
+
+instverf: instverf.c
+ $(LINK.c)
+
+clean:
+ @$(RM) instverf instverf.o
Added: spamassassin/trunk/build/pga/test/Makefile.in
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/test/Makefile.in?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/test/Makefile.in (added)
+++ spamassassin/trunk/build/pga/test/Makefile.in Sun May 28 18:31:49 2017
@@ -0,0 +1,27 @@
+CC = @CC@
+FC = @FC@
+PRECFLAGS = @CFLAGS@
+PREFFLAGS = @FFLAGS@
+CPPFLAGS = @CPPFLAGS@
+RM = @RM@
+LDFLAGS = @LDFLAGS@
+SHELL = @SHELL@
+
+# "$@" expands to the target; "$?" expands to the dependency list
+CFLAGS = -o $@ $? $(PRECFLAGS)
+FFLAGS = -o $@ $? $(PREFFLAGS)
+
+LINK.c = @echo " Compiling $@" ; $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
+LINK.f = @if test -n "$(FC)"; \
+ then echo " Compiling $@" ; $(FC) $(FFLAGS) $(LDFLAGS); \
+ else \
+ echo "$@: Fortran compiler unavailable"; fi
+
+default:
+ @make instverf
+
+instverf: instverf.c
+ $(LINK.c)
+
+clean:
+ @$(RM) instverf instverf.o
Added: spamassassin/trunk/build/pga/test/README
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/test/README?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/test/README (added)
+++ spamassassin/trunk/build/pga/test/README Sun May 28 18:31:49 2017
@@ -0,0 +1,45 @@
+This is the test directory README.
+
+instverf:
+--------
+
+A simple program to test the accuracy of an installation. It runs five
+distinct genetic algorithms, and stores the results from each. After all
+five are run, it will compare the computed results to those known to be
+correct, stored on disk as "instverf.data". If any errors are found, the
+problem number is reported.
+
+The problems tested are
+ 0: Binary datatype
+ 1: Integer datatype
+ 2: Character datatype
+ 3: Real datatype
+ 4: Binary datatype using PGAGetRealFrom*
+
+
+SanityChecks:
+------------
+
+Contains several programs designed to test the sanity of PGAPack. Under
+normal circumstances, they should not be needed. ST_* will call most
+every PGAPack function. PT_* will test the parallel code -- it must
+be run with at least three processors!
+This directory contains several programs that exist only to test the
+sanity of PGAPack. They are very useful for testing the fortran to C
+interface, and that sending and receiving strings work.
+
+ST_c.c and ST_f.f simply call (most) every function in PGAPack. They
+also run several GA's which do nothing other than use every type of
+crossover and mutation for each native datatype.
+
+PT_c.c and PT_f.f test high-level stuff. It tests (not in this order) if
+sending/receiving of strings works, PGARun, PGARunGM, PGARunIM and PGARunNM
+(the last two aren't implemented yet, though), and a user defined
+run routine. A real version of MPI _MUST_ be used for PT_c and PT_f.
+
+instverf.c will run several GA's, one for each native datatype, and check
+the output computed versus that stored on disk. If any differences are
+found, it will give a warning.
+
+These programs are the development testing suite.
+
Added: spamassassin/trunk/build/pga/test/instverf
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/test/instverf?rev=1796518&view=auto
==============================================================================
Binary file - no diff available.
Propchange: spamassassin/trunk/build/pga/test/instverf
------------------------------------------------------------------------------
svn:executable = *
Propchange: spamassassin/trunk/build/pga/test/instverf
------------------------------------------------------------------------------
svn:mime-type = application/x-executable