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 [9/19] - in /spamassassin/trunk/build/pga: ./ docs/
examples/ examples/c/ examples/fortran/ examples/mgh/ examples/templates/
include/ lib/ lib/linux/ man/ man/man1/ man/man2/ man/man3/ man/man4/
man/man5/ man/man6/ man/man7/ man/m...
Added: spamassassin/trunk/build/pga/man/man8/PGASetMaxGAIterValue.8
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/man/man8/PGASetMaxGAIterValue.8?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/man/man8/PGASetMaxGAIterValue.8 (added)
+++ spamassassin/trunk/build/pga/man/man8/PGASetMaxGAIterValue.8 Sun May 28 18:31:49 2017
@@ -0,0 +1,40 @@
+.TH PGASetMaxGAIterValue 8 "05/01/95" " " "PGAPack"
+.SH NAME
+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).
+.SH DESCRIPTION
+The default value is 1000 iterations.
+.SH INPUT PARAMETERS
+.PD 0
+.TP
+ctx
+- context variable
+.PD 0
+.TP
+maxiter
+- the maximum number of GA iterations to run before stopping
+.PD 1
+.SH OUTPUT PARAMETERS
+.PD 0
+.TP
+none
+
+.PD 1
+.SH SYNOPSIS
+.nf
+#include "pgapack.h"
+void PGASetMaxGAIterValue(ctx, maxiter)
+PGAContext *ctx
+int maxiter
+.fi
+.SH LOCATION
+stop.c
+.SH EXAMPLE
+.nf
+Example:
+PGAContext *ctx;
+:
+PGASetMaxGAIterValue(ctx,5000);
+
+.fi
Added: spamassassin/trunk/build/pga/man/man8/PGASetMaxNoChangeValue.8
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/man/man8/PGASetMaxNoChangeValue.8?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/man/man8/PGASetMaxNoChangeValue.8 (added)
+++ spamassassin/trunk/build/pga/man/man8/PGASetMaxNoChangeValue.8 Sun May 28 18:31:49 2017
@@ -0,0 +1,42 @@
+.TH PGASetMaxNoChangeValue 8 "05/01/95" " " "PGAPack"
+.SH NAME
+PGASetMaxNoChangeValue \- specifiy maximum number of iterations of no change
+in the evaluation function value of the best string before stopping.
+.SH DESCRIPTION
+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.
+.SH INPUT PARAMETERS
+.PD 0
+.TP
+ctx
+- context variable
+.PD 0
+.TP
+maxiter
+- the maximum number of GA iterations allowed with no change
+in the best evaluation function value.
+.PD 1
+.SH OUTPUT PARAMETERS
+.PD 0
+.TP
+none
+
+.PD 1
+.SH SYNOPSIS
+.nf
+#include "pgapack.h"
+void PGASetMaxNoChangeValue(ctx, max_no_change)
+PGAContext *ctx
+int max_no_change
+.fi
+.SH LOCATION
+stop.c
+.SH EXAMPLE
+.nf
+Example:
+PGAContext *ctx;
+:
+PGASetMaxGAIterValue(ctx,5000);
+
+.fi
Added: spamassassin/trunk/build/pga/man/man8/PGASetMaxSimilarityValue.8
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/man/man8/PGASetMaxSimilarityValue.8?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/man/man8/PGASetMaxSimilarityValue.8 (added)
+++ spamassassin/trunk/build/pga/man/man8/PGASetMaxSimilarityValue.8 Sun May 28 18:31:49 2017
@@ -0,0 +1,43 @@
+.TH PGASetMaxSimilarityValue 8 "05/01/95" " " "PGAPack"
+.SH NAME
+PGASetMaxSimilarityValue \- Specifiy the maximum percent of homogeneity of
+the population before stopping.
+.SH DESCRIPTION
+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.
+.SH INPUT PARAMETERS
+.PD 0
+.TP
+ctx
+- context variable
+.PD 0
+.TP
+max_similarity
+- the maximum percent of the population that can share
+the same evaluation function value
+.PD 1
+.SH OUTPUT PARAMETERS
+.PD 0
+.TP
+none
+
+.PD 1
+.SH SYNOPSIS
+.nf
+#include "pgapack.h"
+void PGASetMaxSimilarityValue(ctx, max_similarity)
+PGAContext *ctx
+int max_similarity
+.fi
+.SH LOCATION
+stop.c
+.SH EXAMPLE
+.nf
+Example:
+PGAContext *ctx;
+:
+PGASetMaxSimilarityValue(ctx,99);
+
+.fi
Added: spamassassin/trunk/build/pga/man/man8/PGASetMutationAndCrossoverFlag.8
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/man/man8/PGASetMutationAndCrossoverFlag.8?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/man/man8/PGASetMutationAndCrossoverFlag.8 (added)
+++ spamassassin/trunk/build/pga/man/man8/PGASetMutationAndCrossoverFlag.8 Sun May 28 18:31:49 2017
@@ -0,0 +1,40 @@
+.TH PGASetMutationAndCrossoverFlag 8 "05/01/95" " " "PGAPack"
+.SH NAME
+PGASetMutationAndCrossoverFlag \- A boolean flag to indicate if
+recombination uses both crossover and mutation on selected strings
+.SH INPUT PARAMETERS
+.PD 0
+.TP
+ctx
+- context variable
+.PD 0
+.TP
+flag
+- PGA_TRUE (default) or PGA_FALSE
+.PD 1
+.SH OUTPUT PARAMETERS
+.PD 0
+.TP
+none
+
+.PD 1
+.SH SYNOPSIS
+.nf
+#include "pgapack.h"
+void PGASetMutationAndCrossoverFlag(ctx, flag)
+PGAContext *ctx
+int flag
+.fi
+.SH LOCATION
+pga.c
+.SH EXAMPLE
+.nf
+Example:
+Set the genetic algorithm to use both crossover and mutation when
+reproducing strings.
+
+PGAContext *ctx;
+:
+PGASetMutationAndCrossoverFlag(ctx,PGA_FALSE);
+
+.fi
Added: spamassassin/trunk/build/pga/man/man8/PGASetMutationOrCrossoverFlag.8
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/man/man8/PGASetMutationOrCrossoverFlag.8?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/man/man8/PGASetMutationOrCrossoverFlag.8 (added)
+++ spamassassin/trunk/build/pga/man/man8/PGASetMutationOrCrossoverFlag.8 Sun May 28 18:31:49 2017
@@ -0,0 +1,40 @@
+.TH PGASetMutationOrCrossoverFlag 8 "05/01/95" " " "PGAPack"
+.SH NAME
+PGASetMutationOrCrossoverFlag \- A boolean flag to indicate if recombination
+uses exactly one of crossover or mutation on selected strings.
+.SH INPUT PARAMETERS
+.PD 0
+.TP
+ctx
+- context variable
+.PD 0
+.TP
+flag
+- PGA_TRUE (default) or PGA_FALSE
+.PD 1
+.SH OUTPUT PARAMETERS
+.PD 0
+.TP
+none
+
+.PD 1
+.SH SYNOPSIS
+.nf
+#include "pgapack.h"
+void PGASetMutationOrCrossoverFlag(ctx, flag)
+PGAContext *ctx
+int flag
+.fi
+.SH LOCATION
+pga.c
+.SH EXAMPLE
+.nf
+Example:
+Set the genetic algorithm to use mutation only when crossover is
+not used.
+
+PGAContext *ctx;
+:
+PGASetMutationOrCrossoverFlag(ctx,PGA_FALSE);
+
+.fi
Added: spamassassin/trunk/build/pga/man/man8/PGASetNoDuplicatesFlag.8
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/man/man8/PGASetNoDuplicatesFlag.8?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/man/man8/PGASetNoDuplicatesFlag.8 (added)
+++ spamassassin/trunk/build/pga/man/man8/PGASetNoDuplicatesFlag.8 Sun May 28 18:31:49 2017
@@ -0,0 +1,42 @@
+.TH PGASetNoDuplicatesFlag 8 "05/01/95" " " "PGAPack"
+.SH NAME
+PGASetNoDuplicatesFlag \- A boolean flag to indicate if duplicate strings are
+allowed in the population.
+.SH DESCRIPTION
+Valid choices are PGA_TRUE and PGA_FALSE. The
+default is PGA_FALSE -- allow duplicates.
+.SH INPUT PARAMETERS
+.PD 0
+.TP
+ctx
+- context variable
+.PD 0
+.TP
+flag
+- PGA_TRUE or PGA_FALSE
+.PD 1
+.SH OUTPUT PARAMETERS
+.PD 0
+.TP
+none
+
+.PD 1
+.SH SYNOPSIS
+.nf
+#include "pgapack.h"
+void PGASetNoDuplicatesFlag(ctx, no_dup)
+PGAContext *ctx
+int no_dup
+.fi
+.SH LOCATION
+duplcate.c
+.SH EXAMPLE
+.nf
+Example:
+Set the NoDuplicates flag to require that all strings are unique.
+
+PGAContext *ctx;
+:
+PGASetNoDuplicatesFlag(ctx,PGA_TRUE);
+
+.fi
Added: spamassassin/trunk/build/pga/man/man8/PGASetNumReplaceValue.8
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/man/man8/PGASetNumReplaceValue.8?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/man/man8/PGASetNumReplaceValue.8 (added)
+++ spamassassin/trunk/build/pga/man/man8/PGASetNumReplaceValue.8 Sun May 28 18:31:49 2017
@@ -0,0 +1,39 @@
+.TH PGASetNumReplaceValue 8 "05/01/95" " " "PGAPack"
+.SH NAME
+PGASetNumReplaceValue \- specifies the number of new strings to create each
+generation.
+.SH DESCRIPTION
+The default is ten percent of the population size
+.SH INPUT PARAMETERS
+.PD 0
+.TP
+ctx
+- context variable
+.PD 0
+.TP
+pop_replace
+- the genetic algorithm population size to use
+.PD 1
+.SH OUTPUT PARAMETERS
+.PD 0
+.TP
+none
+
+.PD 1
+.SH SYNOPSIS
+.nf
+#include "pgapack.h"
+void PGASetNumReplaceValue(ctx, pop_replace)
+PGAContext *ctx
+int pop_replace
+.fi
+.SH LOCATION
+pop.c
+.SH EXAMPLE
+.nf
+Example:
+PGAContext *ctx;
+:
+PGASetNumReplaceValue(ctx, 35);
+
+.fi
Added: spamassassin/trunk/build/pga/man/man8/PGASetPopReplaceType.8
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/man/man8/PGASetPopReplaceType.8?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/man/man8/PGASetPopReplaceType.8 (added)
+++ spamassassin/trunk/build/pga/man/man8/PGASetPopReplaceType.8 Sun May 28 18:31:49 2017
@@ -0,0 +1,44 @@
+.TH PGASetPopReplaceType 8 "05/01/95" " " "PGAPack"
+.SH NAME
+PGASetPopReplaceType \- Choose method of sorting strings to copy from old
+population to new population.
+.SH DESCRIPTION
+Valid choices are PGA_POPREPL_BEST,
+PGA_POPREPL_RANDOM_NOREP, or PGA_POPREPL_RANDOM_REP for copying the best
+strings, or random string, with or without replacement, respectively,
+from the old population into the new population. The default is
+PGA_POPREPL_BEST.
+.SH INPUT PARAMETERS
+.PD 0
+.TP
+ctx
+- context variable
+.PD 0
+.TP
+pop_replace
+- symbolic constant to specify the population replacement
+strategy
+.PD 1
+.SH OUTPUT PARAMETERS
+.PD 0
+.TP
+none
+
+.PD 1
+.SH SYNOPSIS
+.nf
+#include "pgapack.h"
+void PGASetPopReplaceType(ctx, pop_replace)
+PGAContext *ctx
+int pop_replace
+.fi
+.SH LOCATION
+pop.c
+.SH EXAMPLE
+.nf
+Example:
+PGAContext *ctx;
+:
+PGASetPopReplaceType(ctx, PGA_POPREPL_RANDOM_NOREP);
+
+.fi
Added: spamassassin/trunk/build/pga/man/man8/PGASetPopSize.8
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/man/man8/PGASetPopSize.8?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/man/man8/PGASetPopSize.8 (added)
+++ spamassassin/trunk/build/pga/man/man8/PGASetPopSize.8 Sun May 28 18:31:49 2017
@@ -0,0 +1,38 @@
+.TH PGASetPopSize 8 "05/01/95" " " "PGAPack"
+.SH NAME
+PGASetPopSize \- Specifies the size of the genetic algorithm population.
+.SH DESCRIPTION
+The default population size is 100.
+.SH INPUT PARAMETERS
+.PD 0
+.TP
+ctx
+- context variable
+.PD 0
+.TP
+popsize
+- the genetic algorithm population size to use
+.PD 1
+.SH OUTPUT PARAMETERS
+.PD 0
+.TP
+none
+
+.PD 1
+.SH SYNOPSIS
+.nf
+#include "pgapack.h"
+void PGASetPopSize(ctx, popsize)
+PGAContext *ctx
+int popsize
+.fi
+.SH LOCATION
+pop.c
+.SH EXAMPLE
+.nf
+Example:
+PGAContext *ctx;
+:
+PGASetPopSize(ctx, 200);
+
+.fi
Added: spamassassin/trunk/build/pga/man/man8/PGASetStoppingRuleType.8
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/man/man8/PGASetStoppingRuleType.8?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/man/man8/PGASetStoppingRuleType.8 (added)
+++ spamassassin/trunk/build/pga/man/man8/PGASetStoppingRuleType.8 Sun May 28 18:31:49 2017
@@ -0,0 +1,44 @@
+.TH PGASetStoppingRuleType 8 "05/01/95" " " "PGAPack"
+.SH NAME
+PGASetStoppingRuleType \- specify a stopping criterion.
+.SH DESCRIPTION
+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).
+.SH INPUT PARAMETERS
+.PD 0
+.TP
+ctx
+- context variable
+.PD 0
+.TP
+stoprule
+- symbolic constant to specify stopping rule
+.PD 1
+.SH OUTPUT PARAMETERS
+.PD 0
+.TP
+none
+
+.PD 1
+.SH SYNOPSIS
+.nf
+#include "pgapack.h"
+void PGASetStoppingRuleType(ctx, stoprule)
+PGAContext *ctx
+int stoprule
+.fi
+.SH LOCATION
+stop.c
+.SH EXAMPLE
+.nf
+Example:
+PGAContext *ctx;
+:
+PGASetStoppingRuleType(ctx, PGA_STOP_TOOSIMILAR);
+
+.fi
Added: spamassassin/trunk/build/pga/man/man8/PGASetUp.8
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/man/man8/PGASetUp.8?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/man/man8/PGASetUp.8 (added)
+++ spamassassin/trunk/build/pga/man/man8/PGASetUp.8 Sun May 28 18:31:49 2017
@@ -0,0 +1,39 @@
+.TH PGASetUp 8 "05/01/95" " " "PGAPack"
+.SH NAME
+PGASetUp \- set all uninitialized variables to default values and initialize
+some internal arrays.
+.SH DESCRIPTION
+Must be called after PGACreate() and before the GA
+is started.
+.SH INPUT PARAMETERS
+.PD 0
+.TP
+ctx
+- context variable
+.PD 1
+.SH OUTPUT PARAMETERS
+.PD 0
+.TP
+none
+
+.PD 1
+.SH SYNOPSIS
+.nf
+#include "pgapack.h"
+void PGASetUp(ctx)
+PGAContext *ctx
+.fi
+.SH LOCATION
+create.c
+.SH EXAMPLE
+.nf
+Example:
+PGAContext *ctx;
+:
+PGACreate(ctx, ...);
+:
+// Set options here
+:
+PGASetUp(ctx);
+
+.fi
Added: spamassassin/trunk/build/pga/man/man8/PGASetUserFunction.8
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/man/man8/PGASetUserFunction.8?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/man/man8/PGASetUserFunction.8 (added)
+++ spamassassin/trunk/build/pga/man/man8/PGASetUserFunction.8 Sun May 28 18:31:49 2017
@@ -0,0 +1,64 @@
+.TH PGASetUserFunction 8 "05/01/95" " " "PGAPack"
+.SH NAME
+PGASetUserFunction \- specifies the name of a user-written function
+call to provide a specific GA capability (e.g., crossover,
+mutation, etc.).
+
+.SH DESCRIPTION
+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.
+.SH INPUT PARAMETERS
+.PD 0
+.TP
+ctx
+- context variable
+.PD 0
+.TP
+constant
+- symbolic constant of the user function to set
+.PD 0
+.TP
+f
+- name of the function to use
+.PD 1
+.SH OUTPUT PARAMETERS
+.PD 0
+.TP
+none
+
+.PD 1
+.SH SYNOPSIS
+.nf
+#include "pgapack.h"
+void PGASetUserFunction(ctx, constant, f)
+PGAContext *ctx
+int constant
+void *f
+.fi
+.SH LOCATION
+user.c
+.SH EXAMPLE
+.nf
+Example:
+void MyStringInit(PGAContext *, void *);
+PGAContext *ctx;
+:
+PGASetUserFunction(ctx, PGA_USERFUNCTION_INITSTRING, MyStringInit);
+
+.fi
Added: spamassassin/trunk/build/pga/man/man8/PGASortPop.8
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/man/man8/PGASortPop.8?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/man/man8/PGASortPop.8 (added)
+++ spamassassin/trunk/build/pga/man/man8/PGASortPop.8 Sun May 28 18:31:49 2017
@@ -0,0 +1,59 @@
+.TH PGASortPop 8 "05/01/95" " " "PGAPack"
+.SH NAME
+PGASortPop \- Creates an (internal) array of indices according to one of
+three criteria.
+.SH DESCRIPTION
+If PGA_POPREPL_BEST is used (the default) the array is
+sorted from most fit to least fit. If PGA_POPREPL_RANDOM_REP is
+used the indices in the array are selected randomly with replacement.
+If PGA_POPREPL_RANDOM_NOREP is used the indices in the array are selected
+randomly without replacement. The function PGASetPopReplaceType() is used
+to specify which strategy is used. The indices of the sorted population
+members may then be accessed from the internal array via
+PGAGetSortedPopIndex(). This routine is typically used during population
+replacement.
+.SH INPUT PARAMETERS
+.PD 0
+.TP
+ctx
+- context variable
+.PD 0
+.TP
+popindex
+- symbolic constant of the population from which to create
+the srted array.
+.PD 1
+.SH OUTPUT PARAMETERS
+.PD 0
+.TP
+none
+
+.PD 1
+.SH SYNOPSIS
+.nf
+#include "pgapack.h"
+void PGASortPop(ctx, pop)
+PGAContext *ctx
+int pop
+.fi
+.SH LOCATION
+pop.c
+.SH EXAMPLE
+.nf
+Example:
+Copy the five best strings from the old population into the new
+population. The rest of the new population will be created by
+recombination, and is not shown.
+
+PGAContext *ctx;
+int i,j;
+:
+PGASetPopReplaceType(ctx,PGA_POPREPL_BEST)
+:
+PGASortPop(ctx, PGA_OLDPOP);
+for ( i=0; i < 5; i++) {
+j = PGAGetSortedPopIndex(ctx, i);
+PGACopyIndividual (ctx, j, PGA_OLDPOP, i, PGA_NEWPOP);
+:
+
+.fi
Added: spamassassin/trunk/build/pga/man/man8/PGAUpdateGeneration.8
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/man/man8/PGAUpdateGeneration.8?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/man/man8/PGAUpdateGeneration.8 (added)
+++ spamassassin/trunk/build/pga/man/man8/PGAUpdateGeneration.8 Sun May 28 18:31:49 2017
@@ -0,0 +1,41 @@
+.TH PGAUpdateGeneration 8 "05/01/95" " " "PGAPack"
+.SH NAME
+PGAUpdateGeneration \- updates internal data structures for the next
+genetic algorithm iteration, and checks if the termination conditions, both
+user and PGAPack, have been met.
+.SH DESCRIPTION
+This routine must be called by both
+master and slave processes at the end of each GA generation.
+.SH INPUT PARAMETERS
+.PD 0
+.TP
+ctx
+- context variable
+.PD 0
+.TP
+comm
+- an MPI communicator
+.PD 1
+.SH OUTPUT PARAMETERS
+.PD 0
+.TP
+none
+
+.PD 1
+.SH SYNOPSIS
+.nf
+#include "pgapack.h"
+void PGAUpdateGeneration(ctx, comm)
+PGAContext *ctx
+MPI_Comm comm
+.fi
+.SH LOCATION
+pga.c
+.SH EXAMPLE
+.nf
+Example:
+PGAContext *ctx;
+:
+PGAUpdateGeneration(ctx, MPI_COMM_WORLD);
+
+.fi
Added: spamassassin/trunk/build/pga/man/mandesc
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/man/mandesc?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/man/mandesc (added)
+++ spamassassin/trunk/build/pga/man/mandesc Sun May 28 18:31:49 2017
@@ -0,0 +1,11 @@
+no default sections
+1(1)Fitness & Evaluation
+2(2)Initialization
+3(3)Operators
+4(4)Parallel
+5(5)Utility
+6(6)System
+7(7)Reporting
+8(8)Generation
+l(l)Debugging
+
Added: spamassassin/trunk/build/pga/man/manl/PGAClearDebugLevel.l
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/man/manl/PGAClearDebugLevel.l?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/man/manl/PGAClearDebugLevel.l (added)
+++ spamassassin/trunk/build/pga/man/manl/PGAClearDebugLevel.l Sun May 28 18:31:49 2017
@@ -0,0 +1,39 @@
+.TH PGAClearDebugLevel 3 "05/01/95" " " "PGAPack"
+.SH NAME
+PGAClearDebugLevel \- Turn off a debul level.
+.SH DESCRIPTION
+Only valid if PGAPack
+was compiled to include debugging calls. See the user guide for details.
+.SH INPUT PARAMETERS
+.PD 0
+.TP
+ctx
+- context variable
+.PD 0
+.TP
+level
+- the debug level to set to PGA_FALSE.
+.PD 1
+.SH OUTPUT PARAMETERS
+.PD 0
+.TP
+none
+
+.PD 1
+.SH SYNOPSIS
+.nf
+#include "pgapack.h"
+void PGAClearDebugLevel(ctx, level)
+PGAContext *ctx
+int level
+.fi
+.SH LOCATION
+debug.c
+.SH EXAMPLE
+.nf
+Example:
+PGAContext *ctx;
+:
+PGAClearDebugLevel(ctx, 70)
+
+.fi
Added: spamassassin/trunk/build/pga/man/manl/PGAClearDebugLevelByName.l
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/man/manl/PGAClearDebugLevelByName.l?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/man/manl/PGAClearDebugLevelByName.l (added)
+++ spamassassin/trunk/build/pga/man/manl/PGAClearDebugLevelByName.l Sun May 28 18:31:49 2017
@@ -0,0 +1,35 @@
+.TH PGAClearDebugLevelByName 3 "05/01/95" " " "PGAPack"
+.SH NAME
+PGAClearDebugLevelByName \- Turn off debugging of the named function.
+.SH INPUT PARAMETERS
+.PD 0
+.TP
+ctx
+- context variable
+.PD 0
+.TP
+funcname
+- name of the function to turn on debugging output
+.PD 1
+.SH OUTPUT PARAMETERS
+.PD 0
+.TP
+none
+
+.PD 1
+.SH SYNOPSIS
+.nf
+#include "pgapack.h"
+void PGAClearDebugLevelByName(ctx, funcname)
+PGAContext *ctx
+char *funcname
+.fi
+.SH LOCATION
+debug.c
+.SH EXAMPLE
+.nf
+PGAContext *ctx;
+:
+PGAClearDebugLevelByName(ctx, "PGAGetBinaryAllele");
+
+.fi
Added: spamassassin/trunk/build/pga/man/manl/PGADebugPrint.l
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/man/manl/PGADebugPrint.l?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/man/manl/PGADebugPrint.l (added)
+++ spamassassin/trunk/build/pga/man/manl/PGADebugPrint.l Sun May 28 18:31:49 2017
@@ -0,0 +1,68 @@
+.TH PGADebugPrint 3 "05/01/95" " " "PGAPack"
+.SH NAME
+PGADebugPrint \- Write debugging information
+.SH INPUT PARAMETERS
+.PD 0
+.TP
+ctx
+- context variable
+.PD 0
+.TP
+level
+- a symbolic constant that maps to the type of print requested
+(e.g., an entry or exit print). Valid values are
+PGA_DEBUG_ENTERED, PGA_DEBUG_EXIT, PGA_DEBUG_MALLOC,
+PGA_DEBUG_PRINTVAR, PGA_DEBUG_SEND, and PGA_DEBUG_RECV.
+.PD 0
+.TP
+funcname
+- the name of the function that called this routine
+.PD 0
+.TP
+msg
+- message to print
+.PD 0
+.TP
+datatype
+- a symbolic constant that maps to the data type of the
+parameter data. Valid choices are PGA_INT, PGA_DOUBLE,
+PGA_CHAR and PGA_VOID (no data).
+.PD 0
+.TP
+data
+- a pointer, whose contents will be interpreted based upon the
+datatype parameter (or NULL, if PGA_VOID).
+.PD 1
+.SH OUTPUT PARAMETERS
+.PD 0
+.TP
+none
+
+.PD 1
+.SH SYNOPSIS
+.nf
+#include "pgapack.h"
+void PGADebugPrint(ctx, level, funcname, msg, datatype, data)
+PGAContext *ctx
+int level
+char *funcname
+char *msg
+int datatype
+void *data
+.fi
+.SH LOCATION
+debug.c
+.SH EXAMPLE
+.nf
+Example:
+If the debugging level includes printing variables (level 82), print the
+value of the integer variable num as a debugging tool in the routine
+Add2Nums
+
+PGAContext *ctx;
+int num;
+:
+PGADebugPrint(ctx, PGA_DEBUG_PRINTVAR, "Add2Nums", "num = ", PGA_INT,
+(void *) &num);
+
+.fi
Added: spamassassin/trunk/build/pga/man/manl/PGASetDebugLevel.l
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/man/manl/PGASetDebugLevel.l?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/man/manl/PGASetDebugLevel.l (added)
+++ spamassassin/trunk/build/pga/man/manl/PGASetDebugLevel.l Sun May 28 18:31:49 2017
@@ -0,0 +1,39 @@
+.TH PGASetDebugLevel 3 "05/01/95" " " "PGAPack"
+.SH NAME
+PGASetDebugLevel \- Turn on a debug level.
+.SH DESCRIPTION
+Only valid if PGAPack
+was compiled to include debugging calls. See the user guide for details.
+.SH INPUT PARAMETERS
+.PD 0
+.TP
+ctx
+- context variable
+.PD 0
+.TP
+level
+- the debug level to set to PGA_TRUE.
+.PD 1
+.SH OUTPUT PARAMETERS
+.PD 0
+.TP
+none
+
+.PD 1
+.SH SYNOPSIS
+.nf
+#include "pgapack.h"
+void PGASetDebugLevel(ctx, level)
+PGAContext *ctx
+int level
+.fi
+.SH LOCATION
+debug.c
+.SH EXAMPLE
+.nf
+Example:
+PGAContext *ctx;
+:
+PGASetDebugLevel(ctx, 70)
+
+.fi
Added: spamassassin/trunk/build/pga/man/manl/PGASetDebugLevelByName.l
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/man/manl/PGASetDebugLevelByName.l?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/man/manl/PGASetDebugLevelByName.l (added)
+++ spamassassin/trunk/build/pga/man/manl/PGASetDebugLevelByName.l Sun May 28 18:31:49 2017
@@ -0,0 +1,35 @@
+.TH PGASetDebugLevelByName 3 "05/01/95" " " "PGAPack"
+.SH NAME
+PGASetDebugLevelByName \- Turn on debugging of the named function.
+.SH INPUT PARAMETERS
+.PD 0
+.TP
+ctx
+- context variable
+.PD 0
+.TP
+funcname
+- name of the function to turn on debugging output
+.PD 1
+.SH OUTPUT PARAMETERS
+.PD 0
+.TP
+none
+
+.PD 1
+.SH SYNOPSIS
+.nf
+#include "pgapack.h"
+void PGASetDebugLevelByName(ctx, funcname)
+PGAContext *ctx
+char *funcname
+.fi
+.SH LOCATION
+debug.c
+.SH EXAMPLE
+.nf
+PGAContext *ctx;
+:
+PGASetDebugLevelByName(ctx, "PGAGetBinaryAllele");
+
+.fi
Added: spamassassin/trunk/build/pga/source/Makefile
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/source/Makefile?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/source/Makefile (added)
+++ spamassassin/trunk/build/pga/source/Makefile Sun May 28 18:31:49 2017
@@ -0,0 +1,131 @@
+# Generated automatically from Makefile.in by configure.
+CC = cc
+PRECFLAGS = -O
+CPPFLAGS = -I/usr/local/pga/include -Dlinux -DWL=32 -DFORTRANUNDERSCORE -DOPTIMIZE -DFAKE_MPI
+HEADERS = /usr/local/pga/include/pgapack.h
+PGA_LIB_DIR = ../lib/linux
+PGA_LIB = pgaO
+RM = /bin/rm -f
+OBJS = $(PGA_LIB_DIR)/binary.o \
+ $(PGA_LIB_DIR)/char.o \
+ $(PGA_LIB_DIR)/cmdline.o \
+ $(PGA_LIB_DIR)/create.o \
+ $(PGA_LIB_DIR)/cross.o \
+ $(PGA_LIB_DIR)/debug.o \
+ $(PGA_LIB_DIR)/duplcate.o \
+ $(PGA_LIB_DIR)/evaluate.o \
+ $(PGA_LIB_DIR)/fitness.o \
+ $(PGA_LIB_DIR)/hamming.o \
+ $(PGA_LIB_DIR)/heap.o \
+ $(PGA_LIB_DIR)/integer.o \
+ $(PGA_LIB_DIR)/mutation.o \
+ $(PGA_LIB_DIR)/parallel.o \
+ $(PGA_LIB_DIR)/pga.o \
+ $(PGA_LIB_DIR)/pop.o \
+ $(PGA_LIB_DIR)/random.o \
+ $(PGA_LIB_DIR)/real.o \
+ $(PGA_LIB_DIR)/report.o \
+ $(PGA_LIB_DIR)/restart.o \
+ $(PGA_LIB_DIR)/select.o \
+ $(PGA_LIB_DIR)/stop.o \
+ $(PGA_LIB_DIR)/system.o \
+ $(PGA_LIB_DIR)/user.o \
+ $(PGA_LIB_DIR)/utility.o $(PGA_LIB_DIR)/f2c.o $(PGA_LIB_DIR)/mpi_stub.o
+SHELL = /bin/sh
+RANLIB = ranlib
+
+CFLAGS = -o $@ -c $(PRECFLAGS)
+COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS)
+
+########################################################
+# The Target #
+########################################################
+
+$(PGA_LIB_DIR)/lib$(PGA_LIB).a: $(OBJS)
+ ar ruv $(PGA_LIB_DIR)/lib$(PGA_LIB).a $(OBJS)
+ $(RANLIB) $(PGA_LIB_DIR)/lib$(PGA_LIB).a
+
+########################################################
+# The Source code #
+########################################################
+
+$(PGA_LIB_DIR)/binary.o: binary.c $(HEADERS)
+ $(COMPILE.c) binary.c
+
+$(PGA_LIB_DIR)/char.o: char.c $(HEADERS)
+ $(COMPILE.c) char.c
+
+$(PGA_LIB_DIR)/cmdline.o: cmdline.c $(HEADERS)
+ $(COMPILE.c) cmdline.c
+
+$(PGA_LIB_DIR)/create.o: create.c $(HEADERS)
+ $(COMPILE.c) create.c
+
+$(PGA_LIB_DIR)/cross.o: cross.c $(HEADERS)
+ $(COMPILE.c) cross.c
+
+$(PGA_LIB_DIR)/debug.o: debug.c $(HEADERS)
+ $(COMPILE.c) debug.c
+
+$(PGA_LIB_DIR)/duplcate.o: duplcate.c $(HEADERS)
+ $(COMPILE.c) duplcate.c
+
+$(PGA_LIB_DIR)/evaluate.o: evaluate.c $(HEADERS)
+ $(COMPILE.c) evaluate.c
+
+$(PGA_LIB_DIR)/fitness.o: fitness.c $(HEADERS)
+ $(COMPILE.c) fitness.c
+
+$(PGA_LIB_DIR)/f2c.o: f2c.c $(HEADERS)
+ $(COMPILE.c) f2c.c
+
+$(PGA_LIB_DIR)/hamming.o: hamming.c $(HEADERS)
+ $(COMPILE.c) hamming.c
+
+$(PGA_LIB_DIR)/heap.o: heap.c $(HEADERS)
+ $(COMPILE.c) heap.c
+
+$(PGA_LIB_DIR)/integer.o: integer.c $(HEADERS)
+ $(COMPILE.c) integer.c
+
+$(PGA_LIB_DIR)/mpi_stub.o: mpi_stub.c $(HEADERS)
+ $(COMPILE.c) mpi_stub.c
+
+$(PGA_LIB_DIR)/mutation.o: mutation.c $(HEADERS)
+ $(COMPILE.c) mutation.c
+
+$(PGA_LIB_DIR)/parallel.o: parallel.c $(HEADERS)
+ $(COMPILE.c) parallel.c
+
+$(PGA_LIB_DIR)/pga.o: pga.c $(HEADERS)
+ $(COMPILE.c) pga.c
+
+$(PGA_LIB_DIR)/pop.o: pop.c $(HEADERS)
+ $(COMPILE.c) pop.c
+
+$(PGA_LIB_DIR)/random.o: random.c $(HEADERS)
+ $(COMPILE.c) random.c
+
+$(PGA_LIB_DIR)/real.o: real.c $(HEADERS)
+ $(COMPILE.c) real.c
+
+$(PGA_LIB_DIR)/report.o: report.c $(HEADERS)
+ $(COMPILE.c) report.c
+
+$(PGA_LIB_DIR)/restart.o: restart.c $(HEADERS)
+ $(COMPILE.c) restart.c
+
+$(PGA_LIB_DIR)/select.o: select.c $(HEADERS)
+ $(COMPILE.c) select.c
+
+$(PGA_LIB_DIR)/stop.o: stop.c $(HEADERS)
+ $(COMPILE.c) stop.c
+
+$(PGA_LIB_DIR)/system.o: system.c $(HEADERS)
+ $(COMPILE.c) system.c
+
+$(PGA_LIB_DIR)/user.o: user.c $(HEADERS)
+ $(COMPILE.c) user.c
+
+$(PGA_LIB_DIR)/utility.o: utility.c $(HEADERS)
+ $(COMPILE.c) utility.c
Added: spamassassin/trunk/build/pga/source/Makefile.in
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/source/Makefile.in?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/source/Makefile.in (added)
+++ spamassassin/trunk/build/pga/source/Makefile.in Sun May 28 18:31:49 2017
@@ -0,0 +1,104 @@
+CC = @CC@
+PRECFLAGS = @CFLAGS@
+CPPFLAGS = @CPPFLAGS@
+HEADERS = @HEADERS@
+PGA_LIB_DIR = @PGA_LIB_DIR@
+PGA_LIB = @PGA_LIB@
+RM = @RM@
+OBJS = @OBJS@
+SHELL = @SHELL@
+RANLIB = @RANLIB@
+
+CFLAGS = -o $@ -c $(PRECFLAGS)
+COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS)
+
+########################################################
+# The Target #
+########################################################
+
+$(PGA_LIB_DIR)/lib$(PGA_LIB).a: $(OBJS)
+ ar ruv $(PGA_LIB_DIR)/lib$(PGA_LIB).a $(OBJS)
+ $(RANLIB) $(PGA_LIB_DIR)/lib$(PGA_LIB).a
+
+########################################################
+# The Source code #
+########################################################
+
+$(PGA_LIB_DIR)/binary.o: binary.c $(HEADERS)
+ $(COMPILE.c) binary.c
+
+$(PGA_LIB_DIR)/char.o: char.c $(HEADERS)
+ $(COMPILE.c) char.c
+
+$(PGA_LIB_DIR)/cmdline.o: cmdline.c $(HEADERS)
+ $(COMPILE.c) cmdline.c
+
+$(PGA_LIB_DIR)/create.o: create.c $(HEADERS)
+ $(COMPILE.c) create.c
+
+$(PGA_LIB_DIR)/cross.o: cross.c $(HEADERS)
+ $(COMPILE.c) cross.c
+
+$(PGA_LIB_DIR)/debug.o: debug.c $(HEADERS)
+ $(COMPILE.c) debug.c
+
+$(PGA_LIB_DIR)/duplcate.o: duplcate.c $(HEADERS)
+ $(COMPILE.c) duplcate.c
+
+$(PGA_LIB_DIR)/evaluate.o: evaluate.c $(HEADERS)
+ $(COMPILE.c) evaluate.c
+
+$(PGA_LIB_DIR)/fitness.o: fitness.c $(HEADERS)
+ $(COMPILE.c) fitness.c
+
+@FORTWRAP@
+
+$(PGA_LIB_DIR)/hamming.o: hamming.c $(HEADERS)
+ $(COMPILE.c) hamming.c
+
+$(PGA_LIB_DIR)/heap.o: heap.c $(HEADERS)
+ $(COMPILE.c) heap.c
+
+$(PGA_LIB_DIR)/integer.o: integer.c $(HEADERS)
+ $(COMPILE.c) integer.c
+
+@MPICOMP@
+
+$(PGA_LIB_DIR)/mutation.o: mutation.c $(HEADERS)
+ $(COMPILE.c) mutation.c
+
+$(PGA_LIB_DIR)/parallel.o: parallel.c $(HEADERS)
+ $(COMPILE.c) parallel.c
+
+$(PGA_LIB_DIR)/pga.o: pga.c $(HEADERS)
+ $(COMPILE.c) pga.c
+
+$(PGA_LIB_DIR)/pop.o: pop.c $(HEADERS)
+ $(COMPILE.c) pop.c
+
+$(PGA_LIB_DIR)/random.o: random.c $(HEADERS)
+ $(COMPILE.c) random.c
+
+$(PGA_LIB_DIR)/real.o: real.c $(HEADERS)
+ $(COMPILE.c) real.c
+
+$(PGA_LIB_DIR)/report.o: report.c $(HEADERS)
+ $(COMPILE.c) report.c
+
+$(PGA_LIB_DIR)/restart.o: restart.c $(HEADERS)
+ $(COMPILE.c) restart.c
+
+$(PGA_LIB_DIR)/select.o: select.c $(HEADERS)
+ $(COMPILE.c) select.c
+
+$(PGA_LIB_DIR)/stop.o: stop.c $(HEADERS)
+ $(COMPILE.c) stop.c
+
+$(PGA_LIB_DIR)/system.o: system.c $(HEADERS)
+ $(COMPILE.c) system.c
+
+$(PGA_LIB_DIR)/user.o: user.c $(HEADERS)
+ $(COMPILE.c) user.c
+
+$(PGA_LIB_DIR)/utility.o: utility.c $(HEADERS)
+ $(COMPILE.c) utility.c
Added: spamassassin/trunk/build/pga/source/binary.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/source/binary.c?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/source/binary.c (added)
+++ spamassassin/trunk/build/pga/source/binary.c Sun May 28 18:31:49 2017
@@ -0,0 +1,873 @@
+/*
+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: binary.c: This file contains routines specific to the binary
+* datatype.
+*
+* Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle,
+* Brian P. Walenz
+*****************************************************************************/
+
+#include "pgapack.h"
+
+/*U****************************************************************************
+ PGASetBinaryAllele - sets a binary allele to the specified value.
+
+ Category: Fitness & Evaluation
+
+ Inputs:
+ ctx - context variable
+ p - string index
+ pop - symbolic constant of the population the string is in
+ i - allele index
+ val - binary value (either 1 or 0) to set the allele to
+
+ Outputs:
+ The allele is changed by side-effect.
+
+ Example:
+ Copies the alleles from member p in PGA_OLDPOP to member q PGA_NEWPOP.
+ Assumes strings are of the same length.
+
+ PGAContext *ctx;
+ int p, q, i;
+ :
+ for (i=PGAGetStringLength(ctx)-1; i>=0; i--)
+ PGASetBinaryAllele(ctx, q, PGA_NEWPOP, i,
+ PGAGetBinaryAllele(ctx, p, PGA_OLDPOP, i))
+
+****************************************************************************U*/
+void PGASetBinaryAllele ( PGAContext *ctx, int p, int pop, int i, int val )
+{
+ int windex; /* index of the computer word allele i is in */
+ int bix; /* bit position in word chrom[windex] of allele i */
+ PGAIndividual *ind;
+ PGABinary *chrom;
+
+ PGADebugEntered("PGASetBinaryAllele");
+ PGACheckDataType("PGAGetBinaryAllele", PGA_DATATYPE_BINARY);
+
+ INDEX( windex,bix,i,WL );
+ ind = PGAGetIndividual ( ctx, p, pop );
+ chrom = (PGABinary *)ind->chrom;
+ if ( val == 0 )
+ UNSET( bix, chrom[windex] );
+ else
+ SET( bix, chrom[windex] );
+
+ PGADebugExited("PGASetBinaryAllele");
+}
+
+/*U****************************************************************************
+ PGAGetBinaryAllele - returns the value of a (binary) allele in a
+ PGA_DATATYPE_BINARY string
+
+ 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 the ith allele of string p in population pop.
+
+ Example:
+ Copies the alleles from member p in PGA_OLDPOP to member q PGA_NEWPOP.
+ Assumes the strings are of the same length.
+
+ PGAContext *ctx;
+ int p, q, i;
+ :
+ for (i=PGAGetStringLength(ctx)-1; i>=0; i--)
+ PGASetBinaryAllele(ctx, q, PGA_NEWPOP, i,
+ PGAGetBinaryAllele(ctx, p, PGA_OLDPOP, i))
+
+****************************************************************************U*/
+int PGAGetBinaryAllele ( PGAContext *ctx, int p, int pop, int i )
+{
+
+ int windex; /* index of the computer word allele i is in */
+ int bix; /* bit position in word chrom[windex] of allele i */
+ PGAIndividual *ind;
+ PGABinary *chrom;
+
+ PGADebugEntered("PGAGetBinaryAllele");
+ PGACheckDataType("PGAGetBinaryAllele", PGA_DATATYPE_BINARY);
+
+ INDEX( windex,bix,i,WL );
+ ind = PGAGetIndividual ( ctx, p, pop );
+ chrom = (PGABinary *)ind->chrom;
+
+ PGADebugExited("PGAGetBinaryAllele");
+ return( BIT(bix, chrom[windex]) != 0 );
+}
+
+/*U****************************************************************************
+ PGASetBinaryInitProb - specify the probability of initializing an allele to
+ "1" when creating a PGA_DATATYPE_BINARY string. The default value is 0.5.
+
+ Category: Initialization
+
+ Inputs:
+ ctx - context variable
+ p - the binary initialization probability
+
+ Outputs:
+ None
+
+ Example:
+ Set approximately 1 percent of all binary alleles to "1" when randomly
+ initializing the population.
+
+ PGAContext *ctx;
+ :
+ PGASetBinaryInitProb(ctx, 0.01);
+
+****************************************************************************U*/
+void PGASetBinaryInitProb ( PGAContext *ctx, double probability )
+{
+ PGADebugEntered("PGASetBinaryInitProb");
+ PGAFailIfSetUp("PGASetBinaryInitProb");
+ PGACheckDataType("PGASetBinaryInitProb", PGA_DATATYPE_BINARY);
+
+ if ( (probability <= 1.0) && (probability >= 0.0) )
+ ctx->init.BinaryProbability = probability;
+ else
+ PGAError( ctx, "PGASetBinaryInitProb: Invalid value of probability:",
+ PGA_FATAL, PGA_DOUBLE, (void *) &probability );
+
+ PGADebugExited("PGASetBinaryInitProb");
+}
+
+/*U***************************************************************************
+ PGAGetBinaryInitProb - Returns the probability that an allele will be
+ randomly initialized to "1" in a PGA_DATATYPE_BINARY string.
+
+ Category: Initialization
+
+ Inputs:
+ ctx - context variable
+
+ Outputs:
+ The probability that a bit will be randomly initialized to one
+
+ Example:
+ PGAContext *ctx;
+ double prob;
+ :
+ prob = PGAGetBinaryInitProb(ctx);
+
+***************************************************************************U*/
+double PGAGetBinaryInitProb (PGAContext *ctx)
+{
+ PGADebugEntered("PGAGetBinaryInitProb");
+ PGAFailIfNotSetUp("PGAGetBinaryInitProb");
+ PGACheckDataType("PGAGetBinaryInitProb", PGA_DATATYPE_BINARY);
+
+ PGADebugExited("PGAGetBinaryInitProb");
+ return(ctx->init.BinaryProbability);
+}
+
+
+/*I****************************************************************************
+ PGABinaryCreateString - Allocate a PGA_DATATYPE_BINARY string for member
+ p of population pop. If initflag is PGA_TRUE, randomly initialize all
+ alleles, otherwise clear all alleles.
+
+ Inputs:
+ ctx - context variable
+ p - string index
+ pop - symbolic constant of the population string p is in
+ initflag - a flag, if set, randomly initialize, else clear alleles
+
+ Outputs:
+ Member p in population pop is allocated and initialized.
+
+ Example:
+ Allocates and clears alleles for all strings in PGA_NEWPOP
+
+ PGAContext *ctx;
+ int p;
+ :
+ for (p=PGAGetPopSize(ctx)-1; p>=0; p--)
+ PGABinaryCreateString( ctx, p, PGA_NEWPOP, PGA_FALSE );
+
+****************************************************************************I*/
+void PGABinaryCreateString(PGAContext *ctx, int p, int pop, int initflag)
+{
+ int i, fp;
+ PGABinary *s;
+ PGAIndividual *new = PGAGetIndividual(ctx, p, pop);
+
+ PGADebugEntered("PGABinaryCreateString");
+ PGADebugPrint( ctx, PGA_DEBUG_PRINTVAR, "PGABinaryCreateString",
+ "initflag = ", PGA_INT, (void *) &initflag );
+
+ new->chrom = (void *)malloc(ctx->ga.tw * sizeof(PGABinary));
+ if (new->chrom == NULL)
+ PGAError(ctx, "PGABinaryCreateString: No room to allocate "
+ "new->chrom", PGA_FATAL, PGA_VOID, NULL);
+
+ s = (PGABinary *)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=0; i<ctx->ga.tw; i++ )
+ s[i] = 0;
+
+ PGADebugExited("PGABinaryCreateString");
+}
+
+/*I****************************************************************************
+ PGABinaryMutation - randomly mutates a bit with a specified probability.
+ This routine is called from PGAMutation.
+
+ Inputs:
+ ctx - context variable
+ p - string index
+ pop - symbolic constant for the population string p is in
+ mr - probability of mutating (toggling) a bit
+
+ Outputs:
+ Returns the number of mutations
+
+ Example:
+ Mutates string p in population PGA_NEWPOP with a probability of 0.001
+ for each bit.
+
+ PGAContext *ctx;
+ int p;
+ :
+ PGABinaryMutation( ctx, p, PGA_NEWPOP, .001 );
+
+****************************************************************************I*/
+int PGABinaryMutation( PGAContext *ctx, int p, int pop, double mr )
+{
+ int i,wi;
+ int count = 0;
+ PGABinary *c;
+
+ PGADebugEntered("PGABinaryMutation");
+
+ c = (PGABinary *)PGAGetIndividual(ctx, p, pop)->chrom;
+ for(wi=0; wi<ctx->ga.fw; wi++)
+ for(i=0; i<WL; ++i)
+ if ( PGARandomFlip(ctx, mr) )
+ {
+ TOGGLE(i,c[wi]);
+ count++;
+ }
+
+ /* clean up the partial word if eb > 0 */
+ if (ctx->ga.eb > 0 )
+ for(i=0;i<ctx->ga.eb;++i)
+ if ( PGARandomFlip(ctx, mr) )
+ {
+ TOGGLE(i,c[ctx->ga.fw]);
+ count++;
+ }
+
+ PGADebugExited("PGABinaryMutation");
+ return(count);
+
+}
+
+/*I****************************************************************************
+ PGABinaryOneptCrossover - performs one-point crossover on two parent strings
+ to create 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 p1 and p2
+ c1 - the first child string
+ c2 - the second child string
+ pop2 - symbolic constant of the population containing c1 and c2
+
+ Outputs:
+ None.
+
+ Example:
+ Performs crossover on the two parent strings m and d, producing
+ children s and b.
+
+ PGAContext *ctx;
+ int m, d, s, b;
+ :
+ PGABinaryOneptCrossover( ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP );
+
+****************************************************************************I*/
+void PGABinaryOneptCrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1,
+ int c2, int pop2)
+{
+ PGABinary *parent1 = (PGABinary *)PGAGetIndividual(ctx, p1, pop1)->chrom;
+ PGABinary *parent2 = (PGABinary *)PGAGetIndividual(ctx, p2, pop1)->chrom;
+ PGABinary *child1 = (PGABinary *)PGAGetIndividual(ctx, c1, pop2)->chrom;
+ PGABinary *child2 = (PGABinary *)PGAGetIndividual(ctx, c2, pop2)->chrom;
+
+ /*
+ If the bits are numbered from 0 as follows:
+
+ b b b b b b b b b b
+ 0 1 2 3 4 5 6 7 30 31
+
+ Then if the cross site is bit 5 (which is the sixth bit by our
+ numbering scheme) we would get
+
+ o o o o o n n n n n
+ 0 1 2 3 4 5 6 7 30 31
+
+ where o indicates the original bit and n is a new bit from the crossover
+ operator.
+ */
+
+ PGABinary mask;
+ int windex; /* index of the word the crossover bit position is in */
+ int bix; /* bit position to perform crossover (mod WL) */
+ int i;
+ int xsite;
+
+ PGADebugEntered("PGABinaryOneptCrossover");
+
+ xsite = PGARandomInterval(ctx, 1,ctx->ga.StringLen-1);
+
+ INDEX(windex,bix,xsite,WL);
+
+ for(i=0;i<windex;i++) {
+ child1[i] = parent1[i];
+ child2[i] = parent2[i];
+ }
+
+ mask = ~0;
+ mask = mask >> bix;
+
+ child1[windex] = (~mask & parent1[windex])|(mask & parent2[windex]);
+ child2[windex] = (~mask & parent2[windex])|(mask & parent1[windex]);
+
+ for(i=windex+1;i<ctx->ga.tw;i++) {
+ child1[i] = parent2[i];
+ child2[i] = parent1[i];
+ }
+
+ PGADebugExited("PGABinaryOneptCrossover");
+}
+
+
+/*I****************************************************************************
+ PGABinaryTwoptCrossover - 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:
+ None.
+
+ Example:
+ Performs crossover on the two parent strings m and d, producing
+ children s and b.
+
+ PGAContext *ctx;
+ int m, d, s, b;
+ :
+ PGABinaryTwoptCrossover( ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP );
+
+****************************************************************************I*/
+void PGABinaryTwoptCrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1,
+ int c2, int pop2)
+{
+ PGABinary *parent1 = (PGABinary *)PGAGetIndividual(ctx, p1, pop1)->chrom;
+ PGABinary *parent2 = (PGABinary *)PGAGetIndividual(ctx, p2, pop1)->chrom;
+ PGABinary *child1 = (PGABinary *)PGAGetIndividual(ctx, c1, pop2)->chrom;
+ PGABinary *child2 = (PGABinary *)PGAGetIndividual(ctx, c2, pop2)->chrom;
+
+ PGABinary mask, mask1, mask2;
+ int windex1, windex2;
+ int bix1, bix2;
+ int i;
+ int xsite1, xsite2;
+ int temp;
+
+ PGADebugEntered("PGABinaryTwoptCrossover");
+
+ /* 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;
+ }
+
+ INDEX(windex1,bix1,xsite1,WL);
+ INDEX(windex2,bix2,xsite2,WL);
+
+ if ( windex1 == windex2 ) { /* both cross sites in the same word */
+
+ for(i=0;i<windex1;i++) {
+ child1[i] = parent1[i];
+ child2[i] = parent2[i];
+ }
+
+ mask1 = ~0;
+ if (bix1 == 0)
+ mask1 = 0;
+ else
+ mask1 = mask1 << (WL-bix1);
+ mask2 = ~0;
+ mask2 = mask2 >> bix2;
+ mask = mask1 | mask2;
+
+ child1[windex1] = (mask & parent1[windex1])|(~mask & parent2[windex1]);
+ child2[windex1] = (mask & parent2[windex1])|(~mask & parent1[windex1]);
+
+ for(i=windex1+1;i<ctx->ga.tw;i++) {
+ child1[i] = parent1[i];
+ child2[i] = parent2[i];
+ }
+ }
+ else { /* cross sites in different words */
+
+ for(i=0;i<windex1;i++) {
+ child1[i] = parent1[i];
+ child2[i] = parent2[i];
+ }
+
+ mask = ~0;
+ mask = mask >> bix1;
+
+ child1[windex1] = (~mask & parent1[windex1])|(mask & parent2[windex1]);
+ child2[windex1] = (~mask & parent2[windex1])|(mask & parent1[windex1]);
+
+ for(i=windex1+1; i<windex2; i++) {
+ child1[i] = parent2[i];
+ child2[i] = parent1[i];
+ }
+
+ mask = ~0;
+ mask = mask >> bix2;
+
+ child1[windex2] = (mask & parent1[windex2])|(~mask & parent2[windex2]);
+ child2[windex2] = (mask & parent2[windex2])|(~mask & parent1[windex2]);
+
+ for(i=windex2+1; i<ctx->ga.tw; i++) {
+ child1[i] = parent1[i];
+ child2[i] = parent2[i];
+ }
+ }
+
+ PGADebugExited("PGABinaryTwoptCrossover");
+}
+
+
+/*I****************************************************************************
+ PGABinaryUniformCrossover - 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:
+ None.
+
+ Example:
+ Performs crossover on the two parent strings m and d, producing
+ children s and b.
+
+ PGAContext *ctx;
+ int m, d, s, b;
+ :
+ PGABinaryUniformCrossover( ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP );
+
+****************************************************************************I*/
+void PGABinaryUniformCrossover(PGAContext *ctx, int p1, int p2, int pop1,
+ int c1, int c2, int pop2)
+{
+ PGABinary *parent1 = (PGABinary *)PGAGetIndividual(ctx, p1, pop1)->chrom;
+ PGABinary *parent2 = (PGABinary *)PGAGetIndividual(ctx, p2, pop1)->chrom;
+ PGABinary *child1 = (PGABinary *)PGAGetIndividual(ctx, c1, pop2)->chrom;
+ PGABinary *child2 = (PGABinary *)PGAGetIndividual(ctx, c2, pop2)->chrom;
+ PGABinary mask;
+ int j,wi;
+
+ PGADebugEntered("PGABinaryUniformCrossover");
+
+ for(wi=0;wi<ctx->ga.tw;wi++) {
+ if ( parent1[wi] == parent2[wi] ) {
+ child1[wi] = parent1[wi];
+ child2[wi] = parent2[wi];
+ }
+ else {
+ mask = 0;
+ for (j=0;j<WL;j++)
+ if(PGARandomFlip(ctx, ctx->ga.UniformCrossProb))
+ SET(j,mask);
+ child1[wi] = (mask & parent1[wi])|(~mask & parent2[wi]);
+ child2[wi] = (mask & parent2[wi])|(~mask & parent1[wi]);
+ }
+ }
+
+ PGADebugExited("PGABinaryUniformCrossover");
+}
+
+/*I****************************************************************************
+ PGABinaryPrintString - writes a bit string to a file.
+
+ Inputs:
+ ctx - context variable
+ fp - file pointer to file to write bit string to
+ p - index of the string to write out
+ pop - symbolic constant of the population string p is in
+
+ Outputs:
+ None.
+
+ Example:
+ Write string s to stdout.
+
+ PGAContext *ctx;
+ int s;
+ :
+ PGABinaryPrintString( ctx, stdout, s, PGA_NEWPOP );
+
+****************************************************************************I*/
+void PGABinaryPrintString( PGAContext *ctx, FILE *fp, int p, int pop )
+{
+ PGABinary *c = (PGABinary *)PGAGetIndividual(ctx, p, pop)->chrom;
+ int i;
+
+ PGADebugEntered("PGABinaryPrintString");
+
+ for( i=0; i<ctx->ga.fw; i++ ) {
+ fprintf(fp,"[ ");
+ PGABinaryPrint( ctx, fp, (c+i), WL );
+ fprintf(fp," ]\n");
+ }
+ if ( ctx->ga.eb > 0 ) {
+ fprintf(fp,"[ ");
+ PGABinaryPrint( ctx, fp, (c+ctx->ga.fw), ctx->ga.eb );
+ fprintf(fp," ]");
+ }
+
+ PGADebugExited("PGABinaryPrintString");
+}
+
+/*I****************************************************************************
+ PGABinaryCopyString - Copy one bit 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:
+ None.
+
+ Example:
+ Copy bit string x to y (both are implicitly assumed to have the same
+ length).
+
+ PGAContext *ctx;
+ int x, y
+ :
+ PGABinaryCopyString ( ctx, x, PGA_OLDPOP, y, PGA_NEWPOP );
+
+****************************************************************************I*/
+void PGABinaryCopyString (PGAContext *ctx, int p1, int pop1, int p2, int pop2)
+{
+ PGABinary *source = (PGABinary *)PGAGetIndividual(ctx, p1, pop1)->chrom;
+ PGABinary *dest = (PGABinary *)PGAGetIndividual(ctx, p2, pop2)->chrom;
+ int i;
+
+ PGADebugEntered("PGABinaryCopyString");
+
+ for (i = ctx->ga.tw-1; i>=0; i--)
+ dest[i] = source[i];
+
+ PGADebugExited("PGABinaryCopyString");
+}
+
+/*I****************************************************************************
+ PGABinaryDuplicate - Returns true if bit string a is a duplicate of bit
+ 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 bit string x with y and print a message if they are the same.
+
+ PGAContext *ctx;
+ int x, y;
+ :
+ if ( PGABinaryDuplicate( ctx, x, PGA_NEWPOP, y, PGA_NEWPOP ) )
+ printf("strings are duplicates\n");
+
+****************************************************************************I*/
+int PGABinaryDuplicate( PGAContext *ctx, int p1, int pop1, int p2, int pop2)
+{
+ PGABinary *a = (PGABinary *)PGAGetIndividual(ctx, p1, pop1)->chrom;
+ PGABinary *b = (PGABinary *)PGAGetIndividual(ctx, p2, pop2)->chrom;
+ int wi;
+
+ PGADebugEntered("PGABinaryDuplicate");
+
+ wi = ctx->ga.tw-1;
+ if (a[0] == b[0])
+ for (; (wi>0) && (a[wi] == b[wi]); wi--);
+
+ PGADebugExited("PGABinaryDuplicate");
+
+ return((wi==0) ? PGA_TRUE : PGA_FALSE);
+}
+
+/*I****************************************************************************
+ PGABinaryInitString - randomly initialize a string of type PGABinary
+
+ Inputs:
+ ctx - context variable
+ p - index of string to randomly initialize
+ pop - symbolic constant of the population string p is in
+
+ Outputs:
+
+ Example:
+ PGAContext *ctx;
+ int p;
+ :
+ PGABinaryInitString ( ctx, p, PGA_NEWPOP );
+
+****************************************************************************I*/
+void PGABinaryInitString(PGAContext *ctx, int p, int pop)
+{
+ PGABinary *c = (PGABinary *)PGAGetIndividual(ctx, p, pop)->chrom;
+ int i;
+ int windex; /* index of the computer word allele i is in */
+ int bix; /* binary position in word chrom[windex] of allele i */
+
+ PGADebugEntered("PGABinaryInitString");
+
+ for (i = 0; i < ctx->ga.tw; i++)
+ c[i] = 0;
+ for (i = 0; i < ctx->ga.StringLen; i++)
+ {
+ INDEX(windex,bix,i,WL);
+ if ( PGARandomFlip(ctx, ctx->init.BinaryProbability) )
+ SET ( bix, c[windex] );
+ }
+
+ PGADebugExited("PGABinaryInitString");
+}
+
+
+/*I****************************************************************************
+ PGABinaryBuildDatatype - Build an MPI_Datatype for a binary string
+ datatype.
+
+ Inputs:
+ ctx - context variable
+ p - index of the string to build a datatype from
+ pop - symbolic constant of the population string p is in
+
+ Outputs:
+ MPI_Datatype.
+
+ Example:
+ Called only by MPI routines. Not for user consumption.
+
+****************************************************************************I*/
+MPI_Datatype PGABinaryBuildDatatype(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("PGABinaryBuildDatatype");
+
+ 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.tw;
+ types[3] = MPI_UNSIGNED_LONG;
+
+ MPI_Type_struct(4, counts, displs, types, &individualtype);
+ MPI_Type_commit(&individualtype);
+
+ PGADebugExited("PGABinaryBuildDatatype");
+
+ return (individualtype);
+}
+
+
+/*I****************************************************************************
+ PGABinaryHammingDistance - Returns the Hamming distance between two strings
+
+ Inputs:
+ ctx - context variable
+ s1 - the first string to compare
+ s2 - the second string to compare
+
+ Outputs:
+ The Hamming distance between two strings
+
+ Example:
+ Returns the Hamming distance between bit strings x and y.
+
+ PGAContext *ctx;
+ PGABinary *x, *y;
+ int d;
+ :
+ d = PGABinaryHammingDistance( ctx, x, y );
+
+****************************************************************************I*/
+int PGABinaryHammingDistance ( PGAContext *ctx, PGABinary *s1, PGABinary *s2 )
+{
+ int j, wi, distance;
+ PGABinary t1, t2, mask;
+
+ PGADebugEntered("PGABinaryHammingDistance");
+
+ distance = 0;
+ for(wi=0; wi<ctx->ga.tw; wi++) /* step through each word in the string */
+ if ( s1[wi] != s2[wi] ) { /* if equal, no bits are different */
+ /*fprintf(stdout,"s1[wi] = %x, s2[wi] = %x\n",s1[wi],s2[wi]);*/
+ mask = 1;
+ for(j=0;j<WL;++j) { /* not equal, compare all bits */
+ /* Build bit mask in position j. Mask bit from each */
+ /* string into t1 and t2 and test if bits are the same */
+ t1 = s1[wi] & mask;
+ t2 = s2[wi] & mask;
+ /*fprintf(stdout,"mask = %u, t1 = %u, t2 = %u, j = %d, wi = %d\n",mask,t1,t2,j,wi);*/
+ if ( t1 != t2 )
+ distance++;
+ mask <<= 1; /* shift mask 1 position */
+ }
+ }
+
+ PGADebugExited("PGABinaryHammingDistance");
+
+ return(distance);
+}
+
+/*I****************************************************************************
+ PGABinaryPrint - writes a bit string to a file. Puts the binary
+ representation of the bit string pointed to by chrom into a character
+ string and writes that out. Assumes the maximum length of string to
+ print is WL, and that all bits are in the same word.
+
+ Inputs:
+ ctx - context variable
+ fp - file to write the bit string to
+ chrom - pointer to the bit string to write
+ nb - number of bits to write out
+
+ Outputs:
+
+ Example:
+ Internal function. Use PGABinaryPrintString to print a binary string.
+
+****************************************************************************I*/
+void PGABinaryPrint( PGAContext *ctx, FILE *fp, PGABinary *chrom, int nb )
+{
+ char *s, string[WL+1];
+ PGABinary mask;
+ int i;
+
+ PGADebugEntered("PGABinaryPrint");
+
+ mask = ((PGABinary)1)<<(WL-1);
+ s = string;
+ for(i=0; i<nb; mask>>=1,i++) /* mask each bit and set the */
+ *s++ = (mask&(*chrom)?'1':'0'); /* appropriate character */
+ *s=0; /* string terminator */
+ fprintf(fp, "%s", string); /* print out character string */
+
+ PGADebugExited("PGABinaryPrint");
+}
+
+
Added: spamassassin/trunk/build/pga/source/char.c
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/pga/source/char.c?rev=1796518&view=auto
==============================================================================
--- spamassassin/trunk/build/pga/source/char.c (added)
+++ spamassassin/trunk/build/pga/source/char.c Sun May 28 18:31:49 2017
@@ -0,0 +1,691 @@
+/*
+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: char.c: This file contains the routines specific to the
+ * character datatype.
+ *
+ * Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle,
+ * Brian P. Walenz
+ *****************************************************************************/
+
+#include <pgapack.h>
+
+/*U****************************************************************************
+ PGASetCharacterAllele - sets the value of an allele in a
+ PGA_DATATYPE_CHARACTER string.
+
+ Category: Fitness & Evaluation
+
+ Inputs:
+ ctx - context variable
+ p - string index
+ pop - symbolic constant of the population the string is in
+ i - allele index
+ val - character value to set the allele to
+
+ Outputs:
+ The allele is changed by side-effect.
+
+ Example:
+ Copies the alleles from member p in PGA_OLDPOP to member q in PGA_NEWPOP.
+ Assumes the strings are of the same length.
+
+ PGAContext *ctx;
+ int p, q, i;
+ :
+ for (i=PGAGetStringLength(ctx)-1; i>=0; i--)
+ PGASetCharacterAllele(ctx, q, PGA_NEWPOP, i,
+ PGAGetCharacterAllele(ctx, p, PGA_OLDPOP, i))
+
+****************************************************************************U*/
+void PGASetCharacterAllele (PGAContext *ctx, int p, int pop, int i, char value)
+{
+ PGAIndividual *ind;
+
+ PGADebugEntered("PGASetCharacterAllele");
+ PGACheckDataType("PGASetCharacterAllele", PGA_DATATYPE_CHARACTER);
+
+ ind = PGAGetIndividual ( ctx, p, pop );
+ ((PGACharacter *)ind->chrom)[i] = value;
+
+ PGADebugExited("PGASetCharacterAllele");
+}
+
+/*U****************************************************************************
+ PGAGetCharacterAllele: returns the value of character allele in a
+ PGA_DATATYPE_CHARACTER string
+
+ 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 in string p.
+
+ Example:
+ Copies the alleles from member p in PGA_OLDPOP to member q in PGA_NEWPOP.
+ Assumes the strings are of the same length.
+
+ PGAContext *ctx;
+ int p, q, i;
+ :
+ for (i=PGAGetStringLength(ctx, p, PGA_NEWPOP)-1; i>=0; i--)
+ PGASetCharacterAllele(ctx, q, PGA_NEWPOP, i,
+ PGAGetCharacterAllele(ctx, p, PGA_OLDPOP, i))
+
+****************************************************************************U*/
+char PGAGetCharacterAllele (PGAContext *ctx, int p, int pop, int i)
+{
+ PGAIndividual *ind;
+
+ PGADebugEntered("PGAGetCharacterAllele");
+ PGACheckDataType("PGAGetCharacterAllele", PGA_DATATYPE_CHARACTER);
+
+ ind = PGAGetIndividual ( ctx, p, pop );
+
+ PGADebugExited("PGAGetCharacterAllele");
+
+ return (((PGACharacter *)ind->chrom)[i]);
+}
+
+
+/*U****************************************************************************
+ PGASetCharacterInitType - sets a flag to specify whether the character
+ strings will be exclusively lowercase, exclusively uppercase, or a mixure
+ of both cases. Legal flags are PGA_CINIT_UPPER, PGA_CINIT_LOWER, and
+ PGA_CINIT_MIXED. Default is PGA_CINIT_LOWER.
+
+ Category: Initialization
+
+ Inputs:
+ ctx - context variable
+ value - symbolic constant specifying which case
+
+ Outputs:
+
+ Example:
+ Set program to generate exclusively uppercase letters
+
+ PGAContext *ctx;
+ :
+ PGASetCharacterInitType(ctx, PGA_CINIT_UPPER);
+
+****************************************************************************U*/
+void PGASetCharacterInitType(PGAContext *ctx, int value)
+{
+ PGADebugEntered("PGASetCharacterInitType");
+ PGACheckDataType("PGASetCharacterInitType", PGA_DATATYPE_CHARACTER);
+
+ switch (value)
+ {
+ case PGA_CINIT_UPPER:
+ case PGA_CINIT_LOWER:
+ case PGA_CINIT_MIXED:
+ ctx->init.CharacterType = value;
+ break;
+ default:
+ PGAError(ctx, "PGASetCharacterInitType: Invalid case type:",
+ PGA_FATAL, PGA_INT, (void *)&value);
+ break;
+ }
+
+ PGADebugExited("PGASetCharacterInitType");
+}
+
+/*I****************************************************************************
+ PGACharacterCreateString - Allocate memory for a string of type PGACharacter
+
+ 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:
+ Member p in population pop is allocated and initialized.
+
+ Example:
+ Allocates memory and assigns the address of the allocated memory to
+ the string field (ind->chrom) of the individual. Additionally, the
+ string is initialized to zero.
+
+ PGAContext *ctx;
+ int p;
+ :
+ PGACharacterCreateString( ctx, p, PGA_NEWPOP, PGA_FALSE );
+
+****************************************************************************I*/
+void PGACharacterCreateString (PGAContext *ctx, int p, int pop, int InitFlag)
+{
+ int i, fp;
+ PGACharacter *c;
+ PGAIndividual *new = PGAGetIndividual(ctx, p, pop);
+
+ PGADebugEntered("PGACharacterCreateString");
+
+ new->chrom = (void *)malloc(ctx->ga.StringLen * sizeof(PGACharacter));
+ if (new->chrom == NULL)
+ PGAError(ctx, "PGACharacterCreateString: No room to allocate "
+ "new->chrom", PGA_FATAL, PGA_VOID, NULL);
+ c = (PGACharacter *)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=0; i<ctx->ga.StringLen; i++)
+ c[i] = 0;
+
+ PGADebugExited("PGACharacterCreateString");
+}
+
+/*I****************************************************************************
+ PGACharacterMutation - randomly mutates a character-valued gene with a
+ specified probability. This routine is called from PGAMutation.
+
+ Inputs:
+ ctx - context variable
+ p - string index
+ pop - symbolic constant of the population string p is in
+ mr - probability of mutating an character-valued gene
+
+ Outputs:
+ Returns the number of mutations
+
+ Example:
+ PGAContext *ctx;
+ int p;
+ int NumMutations;
+ :
+ NumMutations = PGACharacterMutation(ctx, p, PGA_NEWPOP, 0.01);
+****************************************************************************I*/
+int PGACharacterMutation( PGAContext *ctx, int p, int pop, double mr )
+{
+ PGACharacter *c;
+ int i, j;
+ int count = 0;
+
+ PGADebugEntered("PGACharacterMutation");
+
+ c = (PGACharacter *)PGAGetIndividual(ctx, p, pop)->chrom;
+ for(i=0; i<ctx->ga.StringLen; i++)
+ if ( PGARandomFlip(ctx, mr) ) /* randomly choose an allele */
+ {
+ switch (ctx->init.CharacterType)
+ {
+ case PGA_CINIT_LOWER:
+ c[i] = PGARandomInterval(ctx, 'a', 'z');
+ break;
+ case PGA_CINIT_UPPER:
+ c[i] = PGARandomInterval(ctx, 'A', 'Z');
+ break;
+ case PGA_CINIT_MIXED:
+ j = PGARandomInterval(ctx, 0, 51);
+ if (j < 26)
+ c[i] = 'A' + j;
+ else
+ c[i] = 'a' + j - 26;
+ break;
+ }
+ count++;
+ }
+
+ PGADebugExited("PGACharacterMutation");
+
+ return (count);
+}
+
+/*I****************************************************************************
+ PGACharacterOneptCrossover - performs one-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:
+
+ Example:
+ Performs crossover on the two parent strings m and d, producing
+ children s and b.
+
+ PGAContext *ctx;
+ int m, d, s, b;
+ :
+ PGACharacterOneptCrossover( ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP );
+
+****************************************************************************I*/
+void PGACharacterOneptCrossover(PGAContext *ctx, int p1, int p2, int pop1,
+ int c1, int c2, int pop2)
+{
+ PGACharacter *parent1, *parent2, *child1, *child2;
+ int i, xsite;
+
+ PGADebugEntered("PGACharacterOneptCrossover");
+
+ parent1 = (PGACharacter *)PGAGetIndividual(ctx, p1, pop1)->chrom;
+ parent2 = (PGACharacter *)PGAGetIndividual(ctx, p2, pop1)->chrom;
+ child1 = (PGACharacter *)PGAGetIndividual(ctx, c1, pop2)->chrom;
+ child2 = (PGACharacter *)PGAGetIndividual(ctx, c2, pop2)->chrom;
+ 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("PGACharacterOneptCrossover");
+}
+
+/*I****************************************************************************
+ PGACharacterTwoptCrossover - 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:
+
+ Example:
+ Performs crossover on the two parent strings m and d, producing
+ children s and b.
+
+ PGAContext *ctx;
+ int m, d, s, b;
+ :
+ PGACharacterTwoptCrossover( ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP );
+
+****************************************************************************I*/
+void PGACharacterTwoptCrossover( PGAContext *ctx, int p1, int p2, int pop1,
+ int c1, int c2, int pop2)
+{
+ PGACharacter *parent1, *parent2, *child1, *child2;
+ int i, temp, xsite1, xsite2;
+
+ PGADebugEntered("PGACharacterTwoptCrossover");
+
+ parent1 = (PGACharacter *)PGAGetIndividual(ctx, p1, pop1)->chrom;
+ parent2 = (PGACharacter *)PGAGetIndividual(ctx, p2, pop1)->chrom;
+ child1 = (PGACharacter *)PGAGetIndividual(ctx, c1, pop2)->chrom;
+ child2 = (PGACharacter *)PGAGetIndividual(ctx, c2, pop2)->chrom;
+ /* 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("PGACharacterTwoptCrossover");
+}
+
+
+/*I****************************************************************************
+ PGACharacterUniformCrossover - 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:
+
+ Example:
+ Performs crossover on the two parent strings m and d, producing
+ children s and b.
+
+ PGAContext *ctx;
+ int m, d, s, b;
+ :
+ PGACharacterUniformCrossover( ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP );
+
+****************************************************************************I*/
+void PGACharacterUniformCrossover(PGAContext *ctx, int p1, int p2, int pop1,
+ int c1, int c2, int pop2)
+{
+ PGACharacter *parent1, *parent2, *child1, *child2;
+ int i;
+
+ PGADebugEntered("PGACharacterUniformCrossover");
+
+ parent1 = (PGACharacter *)PGAGetIndividual(ctx, p1, pop1)->chrom;
+ parent2 = (PGACharacter *)PGAGetIndividual(ctx, p2, pop1)->chrom;
+ child1 = (PGACharacter *)PGAGetIndividual(ctx, c1, pop2)->chrom;
+ child2 = (PGACharacter *)PGAGetIndividual(ctx, c2, pop2)->chrom;
+
+ 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("PGACharacterUniformCrossover");
+}
+
+/*I****************************************************************************
+ PGACharacterPrintString - writes a character-valued string to a file.
+
+ 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 p;
+ :
+ PGACharacterPrintString( ctx, stdout, p, PGA_NEWPOP );
+
+****************************************************************************I*/
+void PGACharacterPrintString ( PGAContext *ctx, FILE *fp, int p, int pop)
+{
+ PGACharacter *c;
+ int i, pos, len;
+
+ PGADebugEntered("PGACharacterPrintString");
+
+ c = (PGACharacter *)PGAGetIndividual(ctx, p, pop)->chrom;
+ len = PGAGetStringLength(ctx);
+
+ pos = 0;
+ while (len > 0) {
+ fprintf(fp, "#%5d: [", pos);
+ for (i=0; i<50 && len>0; i++,len--,c++)
+ fputc(*c, fp);
+ pos+=50;
+ fprintf(fp, "]\n");
+ }
+ fprintf(fp, "\n");
+
+ PGADebugExited("PGACharacterPrintString");
+}
+
+/*I****************************************************************************
+ PGACharacterCopyString - Copy one character-valued string to another
+ Assumes the strings are of the same length.
+
+ 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:
+
+ Example:
+ Copy character string x to y (both are implicitly assumed to be the same
+ length)
+
+ PGAContext *ctx;
+ int x, y;
+ :
+ PGACharacterCopyString ( ctx, x, PGA_OLDPOP, y, PGA_NEWPOP );
+
+****************************************************************************I*/
+void PGACharacterCopyString (PGAContext *ctx, int p1, int pop1, int p2,
+ int pop2)
+{
+ void *source, *dest;
+ int len;
+
+ PGADebugEntered("PGACharacterCopyString");
+
+ source = PGAGetIndividual(ctx, p1, pop1)->chrom;
+ dest = PGAGetIndividual(ctx, p2, pop2)->chrom;
+ len = PGAGetStringLength(ctx);
+ memcpy(dest, source, len * sizeof(PGACharacter));
+
+ PGADebugExited("PGACharacterCopyString");
+}
+
+/*I****************************************************************************
+ PGACharacterDuplicate - Returns true if string p1 in pop1 is a dublicate
+ of string p2 in pop2, else returns false.
+ Assumes the strings are the same length.
+
+ 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 if strings are duplicates.
+
+ Example:
+ Compare string x with y to see if they are duplicates
+
+ PGAContext *ctx;
+ int x, y;
+ :
+ if ( PGACharacterDuplicate( ctx, x, PGA_NEWPOP, y, PGA_NEWPOP ) )
+ printf("strings are duplicates\n");
+
+****************************************************************************I*/
+int PGACharacterDuplicate( PGAContext *ctx, int p1, int pop1, int p2, int pop2)
+{
+ void *a, *b;
+ int len;
+
+ PGADebugEntered("PGACharacterDuplicate");
+
+ a = PGAGetIndividual(ctx, p1, pop1)->chrom;
+ b = PGAGetIndividual(ctx, p2, pop2)->chrom;
+ len = PGAGetStringLength(ctx);
+
+ PGADebugExited("PGACharacterDuplicate");
+
+ return (!memcmp(a, b, len * sizeof(PGACharacter)));
+}
+
+/*I****************************************************************************
+ PGACharacterInitString - randomly initialize a string of type PGACharacter
+
+ Inputs:
+ ctx - context variable
+ p - index of string to randomly initialize
+ pop - symbolic constant of the population string p is in
+
+ Outputs:
+
+ Example:
+ PGAContext *ctx;
+ int p;
+ :
+ PGACharacterInitString ( ctx, p, PGA_NEWPOP );
+
+****************************************************************************I*/
+void PGACharacterInitString(PGAContext *ctx, int p, int pop)
+{
+ int len, i, j;
+ PGACharacter *c;
+
+ PGADebugEntered("PGACharacterInitString");
+
+ len = ctx->ga.StringLen;
+ c = (PGACharacter *)PGAGetIndividual(ctx, p, pop)->chrom;
+ switch (ctx->init.CharacterType)
+ {
+ case PGA_CINIT_LOWER:
+ for (i = 0; i < len; i++)
+ c[i] = PGARandomInterval(ctx, 'a', 'z');
+ break;
+ case PGA_CINIT_UPPER:
+ for (i = 0; i < len; i++)
+ c[i] = PGARandomInterval(ctx, 'A', 'Z');
+ break;
+ case PGA_CINIT_MIXED:
+ for (i = 0; i < len; i++)
+ {
+ j = PGARandomInterval(ctx, 0, 51);
+ if (j < 26)
+ c[i] = 'A' + j;
+ else
+ c[i] = 'a' + j - 26;
+ }
+ break;
+ }
+ PGADebugExited("PGACharacterInitString");
+}
+
+/*I****************************************************************************
+ PGACharacterBuildDatatype - Build an MPI_Datatype for a character string.
+
+ Inputs:
+ ctx - context variable
+ p - index of the string to build a datatype from
+ pop - symbolic constant of the population string p is in
+
+ Outputs:
+ MPI_Datatype
+
+ Example:
+ Called only by MPI routines. Not for user consumption.
+
+****************************************************************************I*/
+MPI_Datatype PGACharacterBuildDatatype(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("PGACharacterBuildDatatype");
+
+ 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_CHAR;
+
+ MPI_Type_struct(4, counts, displs, types, &individualtype);
+ MPI_Type_commit(&individualtype);
+
+ PGADebugExited("PGACharacterBuildDatatype");
+
+ return (individualtype);
+}