pgapack-1.1.1/0000755000175000017500000000000011211106556011170 5ustar eddeddpgapack-1.1.1/man/0000755000175000017500000000000007034447274011760 5ustar eddeddpgapack-1.1.1/man/man3/0000755000175000017500000000000011033025521012573 5ustar eddeddpgapack-1.1.1/man/man3/PGAGetMutationIntegerValue.30000644000175000017500000000077107034447274020012 0ustar eddedd.TH PGAGetMutationIntegerValue 3 "05/01/95" " " "PGAPack" .SH NAME PGAGetMutationIntegerValue \- Returns the value of the multiplier used to mutate PGA_DATATYPE_INTEGER strings with. .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" int PGAGetMutationIntegerValue(ctx) PGAContext *ctx .fi .SH LOCATION mutation.c .SH EXAMPLE .nf Example: PGAContext *ctx; int ival; : ival = PGAGetMutationIntegerValue(ctx); .fi pgapack-1.1.1/man/man3/PGASelectNextIndex.30000644000175000017500000000076007034447274016303 0ustar eddedd.TH PGASelectNextIndex 3 "05/01/95" " " "PGAPack" .SH NAME PGASelectNextIndex \- returns the index of next individual in internal array that contains the indices determined by PGASelect .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" int PGASelectNextIndex(ctx) PGAContext *ctx .fi .SH LOCATION select.c .SH EXAMPLE .nf Example: PGAContext *ctx; int l; : l = PGASelectNextIndex(ctx, PGA_OLDPOP); .fi pgapack-1.1.1/man/man3/PGAGetMutationRealValue.30000644000175000017500000000075607034447274017303 0ustar eddedd.TH PGAGetMutationRealValue 3 "05/01/95" " " "PGAPack" .SH NAME PGAGetMutationRealValue \- Returns the value of the multiplier used to mutate PGA_DATATYPE_REAL strings with. .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" double PGAGetMutationRealValue(ctx) PGAContext *ctx .fi .SH LOCATION mutation.c .SH EXAMPLE .nf Example: PGAContext *ctx; double val; : val = PGAGetMutationRealValue(ctx); .fi pgapack-1.1.1/man/man3/PGASetUniformCrossoverProb.30000644000175000017500000000140511033024771020041 0ustar eddedd.TH PGASetUniformCrossoverProb 3 "05/01/95" " " "PGAPack" .SH NAME PGASetUniformCrossoverProb \- Probability used in uniform crossover to specify that an allele value value be selected from a particular parent. .SH DESCRIPTION The default is 0.6. The crossover type must have been set to PGA_CROSSOVER_UNIFORM with PGASetCrossoverType for this function call to have any effect. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - the crossover probability .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGASetUniformCrossoverProb(ctx, uniform_cross_prob) PGAContext *ctx double uniform_cross_prob .fi .SH LOCATION cross.c .SH EXAMPLE .nf Example: PGAContext *ctx; : PGASetUniformCrossoverProb(ctx,0.9); .fi pgapack-1.1.1/man/man3/PGASetCrossoverProb.30000644000175000017500000000111711033024654016501 0ustar eddedd.TH PGASetCrossoverProb 3 "05/01/95" " " "PGAPack" .SH NAME PGASetCrossoverProb \- Probability that a selected string will undergo crossover. .SH DESCRIPTION The default is 0.85. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - the crossover probability .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGASetCrossoverProb(ctx, crossover_prob) PGAContext *ctx double crossover_prob .fi .SH LOCATION cross.c .SH EXAMPLE .nf Example: Make crossover happen infrequently. PGAContext *ctx; : PGASetCrossoverProb(ctx,0.001); .fi pgapack-1.1.1/man/man3/PGACrossover.30000644000175000017500000000222711033024414015177 0ustar eddedd.TH PGACrossover 3 "05/01/95" " " "PGAPack" .SH NAME PGACrossover \- performs crossover on two parent strings to create two child strings (via side-effect). .SH DESCRIPTION The type of crossover performed is either the default or that specified by PGASetCrossoverType .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p1 - the first parent string .PD 0 .TP p2 - the second parent string .PD 0 .TP pop1 - symbolic constant of the population containing string p1 and p2 .PD 0 .TP c1 - the first child string .PD 0 .TP c2 - the second child string .PD 0 .TP pop2 - symbolic constant of the population to contain string c1 and c2 .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGACrossover(ctx, p1, p2, pop1, c1, c2, pop2) PGAContext *ctx int p1 int p2 int pop1 int c1 int c2 int pop2 .fi .SH LOCATION cross.c .SH EXAMPLE .nf Example: Perform crossover on the two parent strings mom and dad in population PGA_OLDPOP, and insert the child strings, child1 and child1, in population PGA_NEWPOP. PGAContext *ctx; int mom, dad, child1, child2; : PGACrossover(ctx, mom, dad, PGA_OLDPOP, child1, child2, PGA_NEWPOP); .fi pgapack-1.1.1/man/man3/PGASetRestartFlag.30000644000175000017500000000075107034447274016127 0ustar eddedd.TH PGASetRestartFlag 3 "05/01/95" " " "PGAPack" .SH NAME PGASetRestartFlag \- specifies whether the algorithm should employ the restart operator .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP val - boolean variable .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGASetRestartFlag(ctx, val) PGAContext *ctx int val .fi .SH LOCATION restart.c .SH EXAMPLE .nf Example: PGAContext *ctx; : PGASetRestartFlag(ctx, PGA_TRUE); .fi pgapack-1.1.1/man/man3/PGASetCrossoverType.30000644000175000017500000000142711033024666016527 0ustar eddedd.TH PGASetCrossoverType 3 "05/01/95" " " "PGAPack" .SH NAME PGASetCrossoverType \- specify the type of crossover to use. .SH DESCRIPTION Valid choices are PGA_CROSSOVER_ONEPT, PGA_CROSSOVER_TWOPT, or PGA_CROSSOVER_UNIFORM for one-point, two-point, and uniform crossover, respectively. The default is PGA_CROSSOVER_TWOPT. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP crossover_type - symbolic constant to specify crossover type .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGASetCrossoverType(ctx, crossover_type) PGAContext *ctx int crossover_type .fi .SH LOCATION cross.c .SH EXAMPLE .nf Example: Use uniform crossover when crossingover strings. PGAContext *ctx; : PGASetCrossoverType(ctx, PGA_CROSSOVER_UNIFORM); .fi pgapack-1.1.1/man/man3/PGASetMutationBoundedFlag.30000644000175000017500000000151111033024714017557 0ustar eddedd.TH PGASetMutationBoundedFlag 3 "05/01/95" " " "PGAPack" .SH NAME PGASetMutationBoundedFlag \- If this flag is set to PGA_TRUE, then for Integer and Real strings whenever a gene is mutated, if it underflows (overflows) the lower (upper)bound it is reset to the lower (upper) bound. .SH DESCRIPTION In this way all allele values remain within the range the integer strings were initialized on. If this flag is PGA_FALSE (the default), the alleles may take any values. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP flag - either PGA_TRUE or PGA_FALSE .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGASetMutationBoundedFlag(ctx, val) PGAContext *ctx int val .fi .SH LOCATION mutation.c .SH EXAMPLE .nf Example: PGAContext *ctx; : PGASetMutationBoundedFlag(ctx, PGA_TRUE); .fi pgapack-1.1.1/man/man3/PGAGetUniformCrossoverProb.30000644000175000017500000000100307034447274020034 0ustar eddedd.TH PGAGetUniformCrossoverProb 3 "05/01/95" " " "PGAPack" .SH NAME PGAGetUniformCrossoverProb \- returns the probability of a bit being selected from the first child string in uniform crossover .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" double PGAGetUniformCrossoverProb(ctx) PGAContext *ctx .fi .SH LOCATION cross.c .SH EXAMPLE .nf Example: PGAContext *ctx; double pu; : pu = PGAGetUniformCrossoverProb(ctx); .fi pgapack-1.1.1/man/man3/PGAGetSelectType.30000644000175000017500000000143007034447274015751 0ustar eddedd.TH PGAGetSelectType 3 "05/01/95" " " "PGAPack" .SH NAME PGAGetSelectType \- Returns the type of selection selected .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" int PGAGetSelectType(ctx) PGAContext *ctx .fi .SH LOCATION select.c .SH EXAMPLE .nf 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; } .fi pgapack-1.1.1/man/man3/PGAGetRestartFlag.30000644000175000017500000000067507034447274016120 0ustar eddedd.TH PGAGetRestartFlag 3 "05/01/95" " " "PGAPack" .SH NAME PGAGetRestartFlag \- returns whether the algorithm should employ the restart operator .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" int PGAGetRestartFlag(ctx) PGAContext *ctx .fi .SH LOCATION restart.c .SH EXAMPLE .nf Example: PGAContext *ctx; int val; : val = PGAGetRestartFlag(ctx); .fi pgapack-1.1.1/man/man3/PGAGetMutationProb.30000644000175000017500000000065007034447274016316 0ustar eddedd.TH PGAGetMutationProb 3 "05/01/95" " " "PGAPack" .SH NAME PGAGetMutationProb \- Returns the probability of mutation. .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" double PGAGetMutationProb(ctx) PGAContext *ctx .fi .SH LOCATION mutation.c .SH EXAMPLE .nf Example: PGAContext *ctx; double pm; : pm = PGAGetMutateProb(ctx); .fi pgapack-1.1.1/man/man3/PGAGetMutationBoundedFlag.30000644000175000017500000000106307034447274017565 0ustar eddedd.TH PGAGetMutationBoundedFlag 3 "05/01/95" " " "PGAPack" .SH NAME PGAGetMutationBoundedFlag \- returns PGA_TRUE or PGA_FALSE to indicate whether mutated integer strings remain in the range specified when initialized with PGASetIntegerInitRange. .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" int PGAGetMutationBoundedFlag(ctx) PGAContext *ctx .fi .SH LOCATION mutation.c .SH EXAMPLE .nf Example: PGAContext *ctx; int val; : val = PGAGetMutationBoundedFlag(ctx); .fi pgapack-1.1.1/man/man3/PGAMutate.30000644000175000017500000000145211033024624014453 0ustar eddedd.TH PGAMutate 3 "05/01/95" " " "PGAPack" .SH NAME PGAMutate \- This routine performs mutation on a string. .SH DESCRIPTION The type of mutation depends on the data type. Refer to the user guide for data-specific examples. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - index of string to mutate .PD 0 .TP pop - symbolic constant of the population containing p .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" int PGAMutate(ctx, p, pop) PGAContext *ctx int p int pop .fi .SH LOCATION mutation.c .SH EXAMPLE .nf Example: Mutate the best string in the population, until 10 or more mutations have occured. PGAContext *ctx; int p, count = 0; : p = PGAGetBestIndex(ctx, PGA_NEWPOP); while (count < 10) { count += PGAMutate(ctx, p, PGA_NEWPOP); } .fi pgapack-1.1.1/man/man3/PGAGetPTournamentProb.30000644000175000017500000000075107034447274016774 0ustar eddedd.TH PGAGetPTournamentProb 3 "05/01/95" " " "PGAPack" .SH NAME PGAGetPTournamentProb \- returns the probability of selecting the best string in a probabilistic binary tournament .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" double PGAGetPTournamentProb(ctx) PGAContext *ctx .fi .SH LOCATION select.c .SH EXAMPLE .nf Example: PGAContext *ctx; double pt; : pt = PGAGetPTournamentProb(ctx); .fi pgapack-1.1.1/man/man3/PGASetRestartAlleleChangeProb.30000644000175000017500000000105607034447274020404 0ustar eddedd.TH PGASetRestartAlleleChangeProb 3 "05/01/95" " " "PGAPack" .SH NAME PGASetRestartAlleleChangeProb \- specifies the probability with which an allele will be mutated during a restart .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP prob - probability of mutation .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGASetRestartAlleleChangeProb(ctx, prob) PGAContext *ctx double prob .fi .SH LOCATION restart.c .SH EXAMPLE .nf Example: PGAContext *ctx; : PGASetRestartAlleleChangeProb(ctx, 0.5); .fi pgapack-1.1.1/man/man3/PGASetMutationIntegerValue.30000644000175000017500000000126111033024722020000 0ustar eddedd.TH PGASetMutationIntegerValue 3 "05/01/95" " " "PGAPack" .SH NAME PGASetMutationIntegerValue \- Set multiplier to mutate PGA_DATATYPE_INTEGER strings with. .SH DESCRIPTION The use of this value depends on the type of mutation being used. The default value is 1. See the user guide for more details. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP val - the mutation value to use for Integer mutation .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGASetMutationIntegerValue(ctx, val) PGAContext *ctx int val .fi .SH LOCATION mutation.c .SH EXAMPLE .nf Example: PGAContext *ctx; : PGASetMutationIntegerValue(ctx, 5); .fi pgapack-1.1.1/man/man3/PGASetSelectType.30000644000175000017500000000143111033024763015752 0ustar eddedd.TH PGASetSelectType 3 "05/01/95" " " "PGAPack" .SH NAME PGASetSelectType \- specify the type of selection to use. .SH DESCRIPTION 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. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP select_type - symbolic constant to specify selection type .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGASetSelectType(ctx, select_type) PGAContext *ctx int select_type .fi .SH LOCATION select.c .SH EXAMPLE .nf Example: PGAContext *ctx; : PGASetSelectType(ctx, PGA_SELECT_SUS); .fi pgapack-1.1.1/man/man3/PGAGetRestartAlleleChangeProb.30000644000175000017500000000076507034447274020376 0ustar eddedd.TH PGAGetRestartAlleleChangeProb 3 "05/01/95" " " "PGAPack" .SH NAME PGAGetRestartAlleleChangeProb \- returns the probability with which an allele will be mutated during a restart .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" double PGAGetRestartAlleleChangeProb(ctx) PGAContext *ctx .fi .SH LOCATION restart.c .SH EXAMPLE .nf Example: PGAContext *ctx; : prob = PGASetRestartAlleleChangeProb(ctx); .fi pgapack-1.1.1/man/man3/PGAGetCrossoverType.30000644000175000017500000000131107034447274016515 0ustar eddedd.TH PGAGetCrossoverType 3 "05/01/95" " " "PGAPack" .SH NAME PGAGetCrossoverType \- Returns the type of crossover selected .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" int PGAGetCrossoverType(ctx) PGAContext *ctx .fi .SH LOCATION cross.c .SH EXAMPLE .nf Example: PGAContext *ctx; int crosstype; : crosstype = PGAGetCrossoverType(ctx); switch (crosstype) { case PGA_CROSSOVER_ONEPT: printf("Crossover Type = PGA_CROSSOVER_ONEPT\n"); break; case PGA_CROSSOVER_TWOPT: printf("Crossover Type = PGA_CROSSOVER_TWOPT\n"); break; case PGA_CROSSOVER_UNIFORM: printf("Crossover Type = PGA_CROSSOVER_UNIFORM\n"); break; } .fi pgapack-1.1.1/man/man3/PGAGetRestartFrequencyValue.30000644000175000017500000000107507034447274020200 0ustar eddedd.TH PGAGetRestartFrequencyValue 3 "05/01/95" " " "PGAPack" .SH NAME PGAGetRestartFrequencyValue \- returns the number of iterations of no change in the best string after which the algorithm should restart .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP numiter - number of changeless iterations .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" int PGAGetRestartFrequencyValue(ctx) PGAContext *ctx .fi .SH LOCATION restart.c .SH EXAMPLE .nf Example: PGAContext *ctx; : numiter = PGAGetRestartFrequencyValue(ctx); .fi pgapack-1.1.1/man/man3/PGAGetCrossoverProb.30000644000175000017500000000065007034447274016503 0ustar eddedd.TH PGAGetCrossoverProb 3 "05/01/95" " " "PGAPack" .SH NAME PGAGetCrossoverProb \- Returns the crossover probability .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" double PGAGetCrossoverProb(ctx) PGAContext *ctx .fi .SH LOCATION cross.c .SH EXAMPLE .nf Example: PGAContext *ctx; double pc; : pc = PGAGetCrossoverProb(ctx); .fi pgapack-1.1.1/man/man3/PGARestart.30000644000175000017500000000166007034447274014661 0ustar eddedd.TH PGARestart 3 "05/01/95" " " "PGAPack" .SH NAME PGARestart \- reseeds a population from the best string .SH INPUT PARAMETERS .PD 0 .TP val - the probability of changing an allele when copying the best string to the new population .PD 0 .TP source_pop - the source population .PD 0 .TP dest_pop - symbolic constant of the destination population .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP side -effect. .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGARestart(ctx, source_pop, dest_pop) PGAContext *ctx int source_pop int dest_pop .fi .SH LOCATION restart.c .SH EXAMPLE .nf 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); } .fi pgapack-1.1.1/man/man3/PGASetPTournamentProb.30000644000175000017500000000136411033024743016773 0ustar eddedd.TH PGASetPTournamentProb 3 "05/01/95" " " "PGAPack" .SH NAME PGASetPTournamentProb \- Specifies the probability that the string that wins a binary tournament will be selected. .SH DESCRIPTION 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. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - the probability of selecting the better string .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGASetPTournamentProb(ctx, ptournament_prob) PGAContext *ctx double ptournament_prob .fi .SH LOCATION select.c .SH EXAMPLE .nf Example: PGAContext *ctx; : PGASetPTournamentProb(ctx,0.8); .fi pgapack-1.1.1/man/man3/PGASetMutationRealValue.30000644000175000017500000000124611033024735017275 0ustar eddedd.TH PGASetMutationRealValue 3 "05/01/95" " " "PGAPack" .SH NAME PGASetMutationRealValue \- Set multiplier to mutate PGA_DATATYPE_REAL strings with. .SH DESCRIPTION The use of this value depends on the type of mutation being used. The default value is 0.1. See the user guide for more details. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP val - the mutation value to use for Real mutation .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGASetMutationRealValue(ctx, val) PGAContext *ctx double val .fi .SH LOCATION mutation.c .SH EXAMPLE .nf Example: PGAContext *ctx; : PGASetMutationRealValue(ctx,50.0); .fi pgapack-1.1.1/man/man3/PGASelect.30000644000175000017500000000167311033024641014437 0ustar eddedd.TH PGASelect 3 "05/01/95" " " "PGAPack" .SH NAME PGASelect \- performs genetic algorithm selection using either the default selection scheme or that specified with PGASetSelectType(). .SH DESCRIPTION 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() .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP popix - symbolic constant of population to select from .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGASelect(ctx, popix) PGAContext *ctx int popix .fi .SH LOCATION select.c .SH EXAMPLE .nf Example: PGAContext *ctx, : PGASelect(ctx, PGA_OLDPOP); .fi pgapack-1.1.1/man/man3/PGASetRestartFrequencyValue.30000644000175000017500000000112007034447274020203 0ustar eddedd.TH PGASetRestartFrequencyValue 3 "05/01/95" " " "PGAPack" .SH NAME PGASetRestartFrequencyValue \- specifies the number of iterations of no change in the best string after which the algorithm should restart .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP numiter - number of changeless iterations .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGASetRestartFrequencyValue(ctx, numiter) PGAContext *ctx int numiter .fi .SH LOCATION restart.c .SH EXAMPLE .nf Example: PGAContext *ctx; : PGASetRestartFrequencyValue(ctx, 100); .fi pgapack-1.1.1/man/man3/PGAGetMutationType.30000644000175000017500000000155507034447274016342 0ustar eddedd.TH PGAGetMutationType 3 "05/01/95" " " "PGAPack" .SH NAME PGAGetMutationType \- Returns the type of mutation used .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" int PGAGetMutationType(ctx) PGAContext *ctx .fi .SH LOCATION mutation.c .SH EXAMPLE .nf Example: PGAContext *ctx; int mutatetype; : mutatetype = PGAGetMutationType(ctx); switch (mutatetype) { case PGA_MUTATION_CONSTANT: printf("Mutation Type = PGA_MUTATION_CONSTANT\n"); break; case PGA_MUTATION_RANGE: printf("Mutation Type = PGA_MUTATION_RANGE\n"); break; case PGA_MUTATION_UNIFORM: printf("Mutation Type = PGA_MUTATION_UNIFORM\n"); break; case PGA_MUTATION_GAUSSIAN: printf("Mutation Type = PGA_MUTATION_GAUSSIAN\n"); break; case PGA_MUTATION_PERMUTE: printf("Mutation Type = PGA_MUTATION_PERMUTE\n"); break; } .fi pgapack-1.1.1/man/man3/PGASetMutationProb.30000644000175000017500000000127711033024727016324 0ustar eddedd.TH PGASetMutationProb 3 "05/01/95" " " "PGAPack" .SH NAME PGASetMutationProb \- Specifies the probability that a given allele will be mutated. .SH DESCRIPTION If this is called without calling PGASetMutationType(), the default mutation type is PGA_MUTATION_FIXED. The default probability is the reciprocal of the string length. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - the mutation probability .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGASetMutationProb(ctx, mutation_prob) PGAContext *ctx double mutation_prob .fi .SH LOCATION mutation.c .SH EXAMPLE .nf Example: PGAContext *ctx; : PGASetMutationProb(ctx,0.001); .fi pgapack-1.1.1/man/mandesc0000644000175000017500000000023607034447274013316 0ustar eddeddno 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 pgapack-1.1.1/man/man1/0000755000175000017500000000000011033025521012571 5ustar eddeddpgapack-1.1.1/man/man1/PGAEncodeRealAsGrayCode.10000644000175000017500000000222107034447274017126 0ustar eddedd.TH PGAEncodeRealAsGrayCode 1 "05/01/95" " " "PGAPack" .SH NAME PGAEncodeRealAsGrayCode \- encodes a real value as a binary reflected Gray code sequence .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - string index .PD 0 .TP pop - symbolic constant of the population the string is in .PD 0 .TP start - starting bit position in p to encode val in .PD 0 .TP end - ending bit position in p to encode val in .PD 0 .TP low - lower bound of the interval the val is defined on .PD 0 .TP high - lower bound of the interval the val is defined on .PD 0 .TP val - the real number to be represented as a binary string .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP side -effect. .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGAEncodeRealAsGrayCode(ctx, p, pop, start, end, low, high, val) PGAContext *ctx int p int pop int start int end double low double high double val .fi .SH LOCATION evaluate.c .SH EXAMPLE .nf Encode 3.14 from the interval [0,10] in 30 bits in bit positions 0--29 in string p in population PGA_NEWPOP as a binary reflected Gray code sequence. PGAContext *ctx; int p; : PGAEncodeRealAsGrayCode(ctx, p, PGA_NEWPOP, 0, 29, 0.0, 10.0, 3.14); .fi pgapack-1.1.1/man/man1/PGAGetFitness.10000644000175000017500000000104507034447274015301 0ustar eddedd.TH PGAGetFitness 1 "05/01/95" " " "PGAPack" .SH NAME PGAGetFitness \- returns the fitness value for a string .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - string index .PD 0 .TP pop - symbolic constant of the population the string is in .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" double PGAGetFitness(ctx, p, pop) PGAContext *ctx int p int pop .fi .SH LOCATION fitness.c .SH EXAMPLE .nf Example: PGAContext *ctx; int p; double fit; : fit = PGAGetFitness(ctx, p, PGA_NEWPOP); .fi pgapack-1.1.1/man/man1/PGAGetCharacterAllele.10000644000175000017500000000153510765325032016675 0ustar eddedd.TH PGAGetCharacterAllele 1 "05/01/95" " " "PGAPack" .SH NAME PGAGetCharacterAllele \- Returns the value of character allele in a PGA_DATATYPE_CHARACTER string .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - string index .PD 0 .TP pop - symbolic constant of the population the string is in .PD 0 .TP i - allele index .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" char PGAGetCharacterAllele(ctx, p, pop, i) PGAContext *ctx int p int pop int i .fi .SH LOCATION char.c .SH EXAMPLE .nf 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)) .fi pgapack-1.1.1/man/man1/PGASetMaxFitnessRank.10000644000175000017500000000144011033025304016552 0ustar eddedd.TH PGASetMaxFitnessRank 1 "05/01/95" " " "PGAPack" .SH NAME PGASetMaxFitnessRank \- The value of the parameter Max when using linear ranking for fitness determination. .SH DESCRIPTION The default value is 1.2. The value must be from the interval [1.0, 2.0]. The fitness type must have been set to PGA_FITNESS_RANKING with PGASetFitnessType for this function call to have any effect. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP max - the value of the parameter Max when using linear ranking .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGASetMaxFitnessRank(ctx, fitness_rank_max) PGAContext *ctx double fitness_rank_max .fi .SH LOCATION fitness.c .SH EXAMPLE .nf Example: PGAContext *ctx; : PGASetMaxFitnessRank(ctx, 1.1); .fi pgapack-1.1.1/man/man1/PGAEncodeRealAsBinary.10000644000175000017500000000211207034447274016654 0ustar eddedd.TH PGAEncodeRealAsBinary 1 "05/01/95" " " "PGAPack" .SH NAME PGAEncodeRealAsBinary \- encodes a real value as a binary string .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - string index .PD 0 .TP pop - symbolic constant of the population the string is in .PD 0 .TP start - starting bit position in p to encode val in .PD 0 .TP end - ending bit position in p to encode val in .PD 0 .TP low - lower bound of the interval the val is defined on .PD 0 .TP high - lower bound of the interval the val is defined on .PD 0 .TP val - the real number to be represented as a binary string .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP side -effect. .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGAEncodeRealAsBinary(ctx, p, pop, start, end, low, high, val) PGAContext *ctx int p int pop int start int end double low double high double val .fi .SH LOCATION evaluate.c .SH EXAMPLE .nf Encode 3.14 from the interval [0,10] in 30 bits in bit positions 0--29 in string p in population PGA_NEWPOP. PGAContext *ctx; int p; : PGAEncodeRealAsBinary(ctx, p, PGA_NEWPOP, 0, 29, 0.0, 10.0, 3.14); .fi pgapack-1.1.1/man/man1/PGAGetRealFromGrayCode.10000644000175000017500000000227007034447274017014 0ustar eddedd.TH PGAGetRealFromGrayCode 1 "05/01/95" " " "PGAPack" .SH NAME PGAGetRealFromGrayCode \- interpets a binary reflected Gray code sequence in a binary string as encoding a real value and returns the real value it represents. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - string index .PD 0 .TP pop - symbolic constant of the population the string is in .PD 0 .TP start - starting bit position in the binary representation .PD 0 .TP end - ending bit position in the binary representation .PD 0 .TP lower - lower bound of the interval the real number is defined on .PD 0 .TP upper - lower bound of the interval the real number is defined on .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" double PGAGetRealFromGrayCode(ctx, p, pop, start, end, lower, upper) PGAContext *ctx int p int pop int start int end double lower double upper .fi .SH LOCATION evaluate.c .SH EXAMPLE .nf Example: Decode a real value from the string p in population PGA_NEWPOP. The value to decode lies on the interval [-10,20] and is represented using the 20 bits in bit positions 10--29. double x; : x = PGAGetRealFromGrayCode(ctx, p, PGA_NEWPOP, 10, 29, -10.0, 20.0); .fi pgapack-1.1.1/man/man1/PGAEncodeIntegerAsGrayCode.10000644000175000017500000000172707034447274017652 0ustar eddedd.TH PGAEncodeIntegerAsGrayCode 1 "05/01/95" " " "PGAPack" .SH NAME PGAEncodeIntegerAsGrayCode \- encodes a real value as a binary reflected Gray code sequence .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - string index .PD 0 .TP pop - symbolic constant of the population the string is in .PD 0 .TP start - starting bit position in p to encode val in .PD 0 .TP end - ending bit position in p to encode val in .PD 0 .TP val - the integer value to be represented as a binary reflected Gray code sequence .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP side -effect. .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGAEncodeIntegerAsGrayCode(ctx, p, pop, start, end, val) PGAContext *ctx int p int pop int start int end int val .fi .SH LOCATION evaluate.c .SH EXAMPLE .nf Encode an integer v in 20 bits in bit positions 0--19 in string p in population PGA_NEWPOP using Gray code. PGAContext *ctx; int v, p; : PGAEncodeIntegerAsGrayCode(ctx, p, PGA_NEWPOP, 0, 19, 7); .fi pgapack-1.1.1/man/man1/PGAEncodeIntegerAsBinary.10000644000175000017500000000162607034447274017377 0ustar eddedd.TH PGAEncodeIntegerAsBinary 1 "05/01/95" " " "PGAPack" .SH NAME PGAEncodeIntegerAsBinary \- encodes an integer value as a binary string .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - string index .PD 0 .TP pop - symbolic constant of the population the string is in .PD 0 .TP start - starting bit position in p to encode val in .PD 0 .TP end - ending bit position in p to encode val in .PD 0 .TP val - the integer value to be represented as a binary string .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP side -effect. .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGAEncodeIntegerAsBinary(ctx, p, pop, start, end, val) PGAContext *ctx int p int pop int start int end int val .fi .SH LOCATION evaluate.c .SH EXAMPLE .nf Encode an integer v in 20 bits in bit positions 0--19 in string p in population PGA_NEWPOP. PGAContext *ctx; int v, p; : PGAEncodeIntegerAsBinary(ctx, p, PGA_NEWPOP, 0, 19, v); .fi pgapack-1.1.1/man/man1/PGASetCharacterAllele.10000644000175000017500000000161307034447274016716 0ustar eddedd.TH PGASetCharacterAllele 1 "05/01/95" " " "PGAPack" .SH NAME PGASetCharacterAllele \- sets the value of an allele in a PGA_DATATYPE_CHARACTER string. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - string index .PD 0 .TP pop - symbolic constant of the population the string is in .PD 0 .TP i - allele index .PD 0 .TP val - character value to set the allele to .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP side -effect. .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGASetCharacterAllele(ctx, p, pop, i, value) PGAContext *ctx int p int pop int i char value .fi .SH LOCATION char.c .SH EXAMPLE .nf 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)) .fi pgapack-1.1.1/man/man1/PGAGetFitnessType.10000644000175000017500000000126307034447274016145 0ustar eddedd.TH PGAGetFitnessType 1 "05/01/95" " " "PGAPack" .SH NAME PGAGetFitnessType \- Returns the type of fitness transformation used. .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" int PGAGetFitnessType(ctx) PGAContext *ctx .fi .SH LOCATION fitness.c .SH EXAMPLE .nf Example: PGAContext *ctx; int fittype; : fittype = PGAGetFitnessType(ctx); switch (fittype) { case PGA_FITNESS_RAW: printf("Fitness Type = PGA_FITNESS_RAW\n"); break; case PGA_FITNESS_NORMAL: printf("Fitness Type = PGA_FITNESS_NORMAL\n"); break; case PGA_FITNESS_RANKING: printf("Fitness Type = PGA_FITNESS_RANKING\n"); break; } .fi pgapack-1.1.1/man/man1/PGAGetEvaluation.10000644000175000017500000000112207034447274015771 0ustar eddedd.TH PGAGetEvaluation 1 "05/01/95" " " "PGAPack" .SH NAME PGAGetEvaluation \- returns the evaluation function value for string p in population pop .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - string index .PD 0 .TP pop - symbolic constant of the population the string is in .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" double PGAGetEvaluation(ctx, p, pop) PGAContext *ctx int p int pop .fi .SH LOCATION evaluate.c .SH EXAMPLE .nf Example: PGAContext *ctx; int p; double eval; : eval = PGAGetEvaluation(ctx, p, PGA_NEWPOP); .fi pgapack-1.1.1/man/man1/PGAGetBinaryAllele.10000644000175000017500000000147307034447274016236 0ustar eddedd.TH PGAGetBinaryAllele 1 "05/01/95" " " "PGAPack" .SH NAME PGAGetBinaryAllele \- returns the value of a (binary) allele in a PGA_DATATYPE_BINARY string .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - string index .PD 0 .TP pop - symbolic constant of the population the string is in .PD 0 .TP i - allele index .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" int PGAGetBinaryAllele(ctx, p, pop, i) PGAContext *ctx int p int pop int i .fi .SH LOCATION binary.c .SH EXAMPLE .nf 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)) .fi pgapack-1.1.1/man/man1/PGAGetFitnessCmaxValue.10000644000175000017500000000072707034447274017115 0ustar eddedd.TH PGAGetFitnessCmaxValue 1 "05/01/95" " " "PGAPack" .SH NAME PGAGetFitnessCmaxValue \- returns the value of the multiplier used by PGAFitnessMinCmax. .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" double PGAGetFitnessCmaxValue(ctx) PGAContext *ctx .fi .SH LOCATION fitness.c .SH EXAMPLE .nf Example: PGAContext *ctx; double cmax; : cmax = PGAGetFitnessCmaxValue(ctx); .fi pgapack-1.1.1/man/man1/PGAGetFitnessMinType.10000644000175000017500000000133407034447274016610 0ustar eddedd.TH PGAGetFitnessMinType 1 "05/01/95" " " "PGAPack" .SH NAME PGAGetFitnessMinType \- Returns the type of fitness transformation used for minimization problems. .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" int PGAGetFitnessMinType(ctx) PGAContext *ctx .fi .SH LOCATION fitness.c .SH EXAMPLE .nf for minimization problems Example: PGAContext *ctx; int fitmintype; : fitmintype = PGAGetFitnessMinType(ctx); switch (fitmintype) { case PGA_FITNESSMIN_RECIPROCAL: printf("Fitness Minimization Type = PGA_FITNESSMIN_RECIPROCAL\n"); break; case PGA_FITNESSMIN_CMAX: printf("Fitness Minimization Type = PGA_FITNESSMIN_CMAX\n"); break; } .fi pgapack-1.1.1/man/man1/PGAGetMaxFitnessRank.10000644000175000017500000000071107034447274016562 0ustar eddedd.TH PGAGetMaxFitnessRank 1 "05/01/95" " " "PGAPack" .SH NAME PGAGetMaxFitnessRank \- returns the maximum value used in rank-based fitness. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP rank -based fitness .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" double PGAGetMaxFitnessRank(ctx) PGAContext *ctx .fi .SH LOCATION fitness.c .SH EXAMPLE .nf PGAContext *ctx; double max; : max = PGAGetMaxFitnessRank(ctx); .fi pgapack-1.1.1/man/man1/PGASetFitnessType.10000644000175000017500000000136711033025273016147 0ustar eddedd.TH PGASetFitnessType 1 "05/01/95" " " "PGAPack" .SH NAME PGASetFitnessType \- Set the type of fitness algorithm to use. .SH DESCRIPTION Valid choices are PGA_FITNESS_RAW, PGA_FITNESS_NORMAL, or PGA_FITNESS_RANKING for raw fitness (the evaluation function value), linear normalization, or linear ranking, respectively. The default is PGA_FITNESS_RAW. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP fitness_type - symbolic constant to specify fitness type .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGASetFitnessType(ctx, fitness_type) PGAContext *ctx int fitness_type .fi .SH LOCATION fitness.c .SH EXAMPLE .nf Example: PGAContext *ctx; : PGASetFitnessType(ctx, PGA_FITNESS_RANKING); .fi pgapack-1.1.1/man/man1/PGAGetRealAllele.10000644000175000017500000000130307034447274015665 0ustar eddedd.TH PGAGetRealAllele 1 "05/01/95" " " "PGAPack" .SH NAME PGAGetRealAllele \- returns the value of real-valued allele i in string p in population pop .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - string index .PD 0 .TP pop - symbolic constant of the population the string is in .PD 0 .TP i - allele index .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" double PGAGetRealAllele(ctx, p, pop, i) PGAContext *ctx int p int pop int i .fi .SH LOCATION real.c .SH EXAMPLE .nf Example: Returns the value of the ith real-valued allele of string p in population PGA_NEWPOP PGAContext *ctx; int p, i, r; r = PGAGetRealAllele (ctx, p, PGA_NEWPOP, i) .fi pgapack-1.1.1/man/man1/PGASetEvaluation.10000644000175000017500000000146111033025241015767 0ustar eddedd.TH PGASetEvaluation 1 "05/01/95" " " "PGAPack" .SH NAME PGASetEvaluation \- Set the evaluation function value for a string to a specified value. .SH DESCRIPTION Also sets the evaulation up to date flag to PGA_TRUE. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - string index .PD 0 .TP pop - symbolic constant of the population string p is in .PD 0 .TP val - the (user) evaluation value to assign to string p .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGASetEvaluation(ctx, p, pop, val) PGAContext *ctx int p int pop double val .fi .SH LOCATION evaluate.c .SH EXAMPLE .nf Example: Set the evaluation function value of string p in population PGA_NEWPOP to 123.456. PGAContext *ctx; int p; : PGASetEvaluation(ctx, p, PGA_NEWPOP, 123.456); .fi pgapack-1.1.1/man/man1/PGAFitness.10000644000175000017500000000225511033025142014621 0ustar eddedd.TH PGAFitness 1 "05/01/95" " " "PGAPack" .SH NAME PGAFitness \- Maps the user's evaluation function value to a fitness value. .SH DESCRIPTION First, the user's evaluation function value is translated to all positive values if any are negative. Next, this positive sequence is translated to a maximization problem if the user's optimization direction was minimization. This positive sequence is then mapped to a fitness value using linear ranking, linear normalization fitness, or the identity (i.e., the evaluation function value). This routine is usually used after PGAEvaluate is called. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP pop - symbolic constant of the population to calculate fitness for .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGAFitness(ctx, popindex) PGAContext *ctx int popindex .fi .SH LOCATION fitness.c .SH EXAMPLE .nf Example: Calculate the fitness of all strings in population PGA_NEWPOP after calling PGAEvaluate to calculate the strings evaluation value. double energy(PGAContext *ctx, int p, int pop); PGAContext *ctx; : PGAEvaluate(ctx, PGA_NEWPOP, energy); PGAFitness (ctx, PGA_NEWPOP); .fi pgapack-1.1.1/man/man1/PGAGetEvaluationUpToDateFlag.10000644000175000017500000000143707034447274020202 0ustar eddedd.TH PGAGetEvaluationUpToDateFlag 1 "05/01/95" " " "PGAPack" .SH NAME PGAGetEvaluationUpToDateFlag \- returns true/false to indicate whether the evaluate function value is up to date .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - string index .PD 0 .TP pop - symbolic constant of the population the string is in .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" int PGAGetEvaluationUpToDateFlag(ctx, p, pop) PGAContext *ctx int p int pop .fi .SH LOCATION evaluate.c .SH EXAMPLE .nf Example: PGAContext *ctx; int uptodate; : uptodate = PGAGetEvaluationUpToDateFlag(ctx); switch (uptodate) { case PGA_TRUE: printf("Evaluation function value current\n"); break; case PGA_FALSE: printf("Evaluation function value out-of-date\n"); break; } .fi pgapack-1.1.1/man/man1/PGASetFitnessMinType.10000644000175000017500000000164011033025265016606 0ustar eddedd.TH PGASetFitnessMinType 1 "05/01/95" " " "PGAPack" .SH NAME PGASetFitnessMinType \- sets the type of algorithm used if a minimization problem is specified to determine how values are remapped for maximization. .SH DESCRIPTION Valid choices are PGA_FITNESSMIN_RECIPROCAL and PGA_FITNESSMIN_CMAX to do the mapping using the reciprocal of the evaluation function, or by subtracting the worst evaluation function value from each evaluation function value, respectively. The default is PGA_FITNESSMIN_CMAX .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP fitness_type - symbolic constant to specify fitness minimization type .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGASetFitnessMinType(ctx, fitness_type) PGAContext *ctx int fitness_type .fi .SH LOCATION fitness.c .SH EXAMPLE .nf Example: PGAContext *ctx; : PGASetFitnessMinType(ctx, PGA_FITNESSMIN_CMAX); .fi pgapack-1.1.1/man/man1/PGASetRealAllele.10000644000175000017500000000137307034447274015710 0ustar eddedd.TH PGASetRealAllele 1 "05/01/95" " " "PGAPack" .SH NAME PGASetRealAllele \- sets the value of real-valued allele i in string p in population pop .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - string index .PD 0 .TP pop - symbolic constant of the population the string is in .PD 0 .TP i - allele index .PD 0 .TP val - real value to set the allele to .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP side -effect. .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGASetRealAllele(ctx, p, pop, i, value) PGAContext *ctx int p int pop int i double value .fi .SH LOCATION real.c .SH EXAMPLE .nf Sets the value of the ith allele of string p in population PGA_NEWPOP to 1.57 PGAContext *ctx; int i, p; : PGASetRealAllele ( ctx, p, PGA_NEWPOP, i, 1.57) .fi pgapack-1.1.1/man/man1/PGASetEvaluationUpToDateFlag.10000644000175000017500000000202311033025251020163 0ustar eddedd.TH PGASetEvaluationUpToDateFlag 1 "05/01/95" " " "PGAPack" .SH NAME PGASetEvaluationUpToDateFlag \- sets the flag associated with a string to PGA_TRUE or PGA_FLASE to indicate whether the evaluate function value is out-of-date or not. .SH DESCRIPTION Note that this flag is always set to PGA_TRUE when PGASetEvaluation is called. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - string index .PD 0 .TP pop - symbolic constant of the population string p is in .PD 0 .TP status - boolean for whether up-to-date .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGASetEvaluationUpToDateFlag(ctx, p, pop, status) PGAContext *ctx int p int pop int status .fi .SH LOCATION evaluate.c .SH EXAMPLE .nf Example: Set the evaluation function flag for string p in population PGA_NEWPOP to PGA_FALSE (as might happen after, for example, calling a hill-climbing routine that modified this string). PGAContext *ctx; int p; : PGASetEvaluationUpToDateFlag(ctx, p, PGA_NEWPOP, PGA_FALSE); .fi pgapack-1.1.1/man/man1/PGASetFitnessCmaxValue.10000644000175000017500000000112411033025257017104 0ustar eddedd.TH PGASetFitnessCmaxValue 1 "05/01/95" " " "PGAPack" .SH NAME PGASetFitnessCmaxValue \- The value of the multiplier used by PGAFitnessMinCmax so that the worst string has a nonzero fitness. .SH DESCRIPTION The default value is 1.01. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP val - the value of the multiplier .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGASetFitnessCmaxValue(ctx, val) PGAContext *ctx double val .fi .SH LOCATION fitness.c .SH EXAMPLE .nf Example: PGAContext *ctx; : PGASetFitnessCmaxValue(ctx, 1.2); .fi pgapack-1.1.1/man/man1/PGAGetIntegerFromGrayCode.10000644000175000017500000000166407034447274017534 0ustar eddedd.TH PGAGetIntegerFromGrayCode 1 "05/01/95" " " "PGAPack" .SH NAME PGAGetIntegerFromGrayCode \- interpets a binary reflected Gray code sequence as encoding an integer value and returns the integer value it represents. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - string index .PD 0 .TP pop - symbolic constant of the population the string is in .PD 0 .TP start - starting bit position in the binary representation .PD 0 .TP end - ending bit position in the binary representation .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" int PGAGetIntegerFromGrayCode(ctx, p, pop, start, end) PGAContext *ctx int p int pop int start int end .fi .SH LOCATION evaluate.c .SH EXAMPLE .nf Example: Get an integer j from bits 10--29 of string p in population PGA_NEWPOP. The string is encoded in Gray code. PGAContext *ctx; int j, p; : j = PGAGetIntegerFromGrayCode(ctx, p, PGA_NEWPOP, 10, 29); .fi pgapack-1.1.1/man/man1/PGAEvaluate.10000644000175000017500000000246511033025133014757 0ustar eddedd.TH PGAEvaluate 1 "05/01/95" " " "PGAPack" .SH NAME PGAEvaluate \- Calls a user-specified function to return an evaluation of each string in the population. .SH DESCRIPTION The user-specified function is only called if the string has been changed (e.g., by crossover or mutation) or the user has explicitly signaled the string's evaluation is out-of-date by a call to PGASetEvaluationUpToDateFlag(). .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP pop - symbolic constant of the population to be evaluated .PD 0 .TP f - a pointer to a function to evaluate a string. This function will be called once for each string in population pop that requires evaluation. This function must return a double (the evaluation function value) and must fit the prototype double f(PGAContext *c, int p, int pop); .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 PGAEvaluate(ctx, pop, , comm) PGAContext *ctx int pop double (*f)(PGAContext *, int, int) MPI_Comm comm .fi .SH LOCATION parallel.c .SH EXAMPLE .nf Example: Evaluate all strings in population PGA_NEWPOP using the user-defined evaluation function Energy. double Energy(PGAContext *ctx, int p, int pop) { : }; PGAContext *ctx; : PGAEvaluate(ctx, PGA_NEWPOP, Energy, MPI_COMM_WORLD); .fi pgapack-1.1.1/man/man1/PGASetIntegerAllele.10000644000175000017500000000133607034447274016421 0ustar eddedd.TH PGASetIntegerAllele 1 "05/01/95" " " "PGAPack" .SH NAME PGASetIntegerAllele \- sets the value of a (integer) allele. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - string index .PD 0 .TP pop - symbolic constant of the population the string is in .PD 0 .TP i - allele index .PD 0 .TP val - integer value to set the allele to .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGASetIntegerAllele(ctx, p, pop, i, value) PGAContext *ctx int p int pop int i int value .fi .SH LOCATION integer.c .SH EXAMPLE .nf Set the value of the ith allele of string p in population PGA_NEWPOP to 64. PGAContext *ctx; int p, i; : PGASetIntegerAllele (ctx, p, PGA_NEWPOP, i, 64) .fi pgapack-1.1.1/man/man1/PGAGetRealFromBinary.10000644000175000017500000000220707034447274016543 0ustar eddedd.TH PGAGetRealFromBinary 1 "05/01/95" " " "PGAPack" .SH NAME PGAGetRealFromBinary \- Interpets a binary string as encoding a real value and returns the real value it represents. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - string index .PD 0 .TP pop - symbolic constant of the population the string is in .PD 0 .TP start - starting bit position in the binary representation .PD 0 .TP end - ending bit position in the binary representation .PD 0 .TP lower - lower bound of the interval the real number is defined on .PD 0 .TP upper - lower bound of the interval the real number is defined on .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" double PGAGetRealFromBinary(ctx, p, pop, start, end, lower, upper) PGAContext *ctx int p int pop int start int end double lower double upper .fi .SH LOCATION evaluate.c .SH EXAMPLE .nf Example: Decode a real value from the string p in population PGA_NEWPOP. The value to decode lies on the interval [-10,20] and is represented using the 20 bits in bit positions 10--29. double x; : x = PGAGetRealFromBinary(ctx, p, PGA_NEWPOP, 10, 29, -10.0, 20.0); .fi pgapack-1.1.1/man/man1/PGAGetIntegerAllele.10000644000175000017500000000137511033025176016373 0ustar eddedd.TH PGAGetIntegerAllele 1 "05/01/95" " " "PGAPack" .SH NAME PGAGetIntegerAllele \- Returns the value of allele i of member p in population pop. .SH DESCRIPTION Assumes the data type is PGA_DATATYPE_INTEGER. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - string index .PD 0 .TP pop - symbolic constant of the population the string is in .PD 0 .TP i - allele index .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" int PGAGetIntegerAllele(ctx, p, pop, i) PGAContext *ctx int p int pop int i .fi .SH LOCATION integer.c .SH EXAMPLE .nf Returns the value of the ith integer allele of string p in population PGA_NEWPOP. PGAContext *ctx; int p, i, k; : k = PGAGetIntegerAllele ( ctx, p, PGA_NEWPOP, i ) .fi pgapack-1.1.1/man/man1/PGASetBinaryAllele.10000644000175000017500000000155407034447274016252 0ustar eddedd.TH PGASetBinaryAllele 1 "05/01/95" " " "PGAPack" .SH NAME PGASetBinaryAllele \- sets a binary allele to the specified value. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - string index .PD 0 .TP pop - symbolic constant of the population the string is in .PD 0 .TP i - allele index .PD 0 .TP val - binary value (either 1 or 0) to set the allele to .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP side -effect. .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" void PGASetBinaryAllele(ctx, p, pop, i, val) PGAContext *ctx int p int pop int i int val .fi .SH LOCATION binary.c .SH EXAMPLE .nf 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)) .fi pgapack-1.1.1/man/man1/PGARank.10000644000175000017500000000211211033025227014075 0ustar eddedd.TH PGARank 1 "05/01/95" " " "PGAPack" .SH NAME PGARank \- returns the rank of a string in a population. .SH DESCRIPTION This is a value between 1,...,N (the population size). The most fit string has rank 1, the least fit string has rank N. .SH INPUT PARAMETERS .PD 0 .TP ctx - context variable .PD 0 .TP p - the index of the string whose rank is desired .PD 0 .TP order - an array containing a unique rank for each string .PD 0 .TP n - the size of the array order .PD 1 .SH OUTPUT PARAMETERS .PD 0 .TP none .PD 1 .SH SYNOPSIS .nf #include "pgapack.h" int PGARank(ctx, p, order, n) PGAContext *ctx int p int *order int n .fi .SH LOCATION fitness.c .SH EXAMPLE .nf Example: Determine the rank of string p. PGAContext *ctx; int i, popsize, rank, *order; double *fitness; popsize = PGAGetPopsize(ctx); order = (int *) malloc(sizeof(int) * popsize); fitness = (double *)malloc(sizeof(double) * popsize); for(i=0;i&1 ; } print_usage() { cat <<. Usage: configure -arch ARCH_TYPE [-cc CC] [-f77 FC] [-debug] [-help] [-cflags CFLAGS] [-fflags FFLAGS] [-mpiinc MPI_INC_DIR -mpilib MPI_LIB] where ARCH_TYPE = the type of machine that PGAPack is to be configured for CC = the name of the ANSI C compiler FC = the name of the FORTRAN 77 compiler CFLAGS = C compiler flags FFLAGS = FORTRAN compiler flags MPI_INC_DIR = the MPI include directory MPI_LIB = the full path to the MPI library Known architectures are: Workstations sun4 (SUN OS 4.x) hpux (HP UX) irix (Silicon Graphics IRIX) alpha (DEC Alpha) rs6000 (AIX for IBM RS6000) next (NeXT 680x0) freebsd (PC clones running FreeBSD) linux (PC clones running LINUX) generic (Generic 32-bit UNIX-like machine) MPP's powerchallenge (Silicon Graphics PowerChallenge) challenge (Silicon Graphics Challenge) t3d (Cray-T3D) sp2 (IBM SP2) paragon (Intel Paragon) exemplar (Convex Exemplar) In the absence of the -f77 or -cc options, configure assumes the name of a FORTRAN 77 or ANSI C compiler based on the architecture type. If the -debug flag is set, then PGAPack will be built for debugging. This enables the extensive debugging options and datatype checks. If both -mpiinc and -mpilib are missing, PGAPack is built using a non-parallel "stub" library for all MPI calls. The -help flag causes this usage guide to be printed. Example 1: ---------- Configure and build for parallel operation on the sun4 architectue. MPI is in /usr/local/mpi; the MPI library is /usr/local/mpi/lib/sun4/ch_p4/libmpi.a. configure -arch sun4 -mpilib /usr/local/mpi/lib/sun4/ch_p4/libmpi.a \ -mpiinc /usr/local/mpi/include make install Example 2: ---------- Configure and build a debug sequential library on the rs6000 architecture. configure -arch rs6000 -debug make install . } ############################################################################### # This section initializes the variables that will be used throughout # the script. ############################################################################### AC_INIT(source/pga.c) ARCH="" # architecture type PARALLEL=0 # parallel libray, or use stub routines? OPTIMIZE=1 # optimized? CPPFLAGS="" # flags to send to the C preprocessor LDFLAGS="" # link flags CFLAGS="" # flags to send to the C compiler FFLAGS="" # flags to send to the FORTRAN compiler PGA_DIR="`pwd`" # the root of the pgapack tree PGA_DIR=`echo $PGA_DIR | sed "s=tmp_mnt/=="` # get rid of 'tmp_mnt/' HEADERS="$PGA_DIR/include/pgapack.h" # headers upon which pgapack depends INCLUDES="-I$PGA_DIR/include" # directories where to search for include files LIB_DIRS="" # directories where to search for libraries LIBS="" # libraries with which to link MPI_INC_DIR="" MPI_LIB="" SHELL="/usr/bin/sh" RM="/bin/rm -f" # command to force removal of files 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' # these are pgapack's object files ############################################################################### # This section parse the command line options. There a two types of options: # those that take arguments and those that don't. Parsing the case where an # option takes an argument is a little tricky. This is how it works. Suppose # that the program comes upon "-cc". Then we know that the next argument # will be the name of the C compiler. Hence, we set the flag next_cc to be # equal to "yes". The next time through the loop, it will be the case that # x$next_cc equal "xyes" because $next_cc expands to "yes". Thus, we know that # this argument is the name of the compiler and we assign it to USR_CC. Then # we set next_cc back to a null string. This way on the next time through # the loop x$next_cc will equal just "x". Since the shell initializes # variables to null strings, we do not have to initialize the "next_" family # of variables by hand. ############################################################################### for arg do if test x$next_arch = xyes then ARCH=$arg next_arch= elif test x$next_mpiinc = xyes then MPI_INC_DIR=$arg next_mpiinc= elif test x$next_mpilib = xyes then MPI_LIB=$arg next_mpilib= elif test x$next_f77 = xyes then USR_FC=$arg next_f77= elif test x$next_cc = xyes then USR_CC=$arg next_cc= elif test x$next_cflags = xyes then CFLAGS="$arg $CFLAGS" next_cflags= elif test x$next_fflags = xyes then FFLAGS="$arg $FFLAGS" next_fflags= else case $arg in -arch) next_arch=yes ;; -f77) next_f77=yes ;; -cc) next_cc=yes ;; -mpiinc) next_mpiinc=yes PARALLEL=1 ;; -mpilib) next_mpilib=yes PARALLEL=1 ;; -debug) OPTIMIZE=0 ;; -cflags) next_cflags=yes ;; -fflags) next_fflags=yes ;; -help) print_usage >& 2 exit 1 ;; *) ;; esac fi done if test "$MPI_LIB" -a "$MPI_INC_DIR" ; then if test ! -d "$MPI_INC_DIR" ; then print_error "MPI_INC_DIR == $MPI_INC_DIR is not a valid directory!" exit 1 fi if test ! -f "$MPI_INC_DIR/mpi.h" ; then print_error "Couldn't find $MPI_INC_DIR/mpi.h!" exit 1 fi if test ! -f "$MPI_LIB" ; then print_error "MPI_LIB == $MPI_LIB is not a file!" exit 1 fi PARALLEL=1 else PARALLEL=0 CPPFLAGS="-DFAKE_MPI $CPPFLAGS" fi if test $OPTIMIZE -eq 1 ; then CPPFLAGS="-DOPTIMIZE $CPPFLAGS" CFLAGS="-O $CFLAGS" FFLAGS="-O $FFLAGS" PGA_LIB="pgaO" else CFLAGS="-g $CFLAGS" FFLAGS="-g $FFLAGS" PGA_LIB="pgag" fi ############################################################################### # This section sets the default values of certain variables based upon the # architecture type specified. If no architecture was specified, the script # issues an error and aborts. ############################################################################### if test -z "$ARCH" then print_error "You must specify the architecture with -arch " print_error "Valid architectures are the following:" print_error " Workstations MPP's" print_error " sun4 powerchallenge" print_error " next challenge" print_error " rs6000 t3d" print_error " freebsd sp2" print_error " irix paragon" print_error " linux exemplar" print_error " hpux" print_error " alpha" print_error " generic" print_error "" print_error "For more information type configure -help." exit 1 fi case $ARCH in sun4) CC=cc FC=f77 CPPFLAGS="-DWL=32 -DFORTRANUNDERSCORE $CPPFLAGS" ;; next) CC=cc FC= CPPFLAGS="-DWL=32 -DFORTRANUNDERSCORE $CPPFLAGS" ;; rs6000) CC=cc FC=f77 CPPFLAGS="-DWL=32 $CPPFLAGS" ;; freebsd) CC=cc FC=f77 FFLAGS="-w" CPPFLAGS="-DWL=32 -DFORTRANUNDERSCORE $CPPFLAGS" ;; irix) CC=cc FC=f77 CPPFLAGS="-DWL=32 -DFORTRANUNDERSCORE $CPPFLAGS" ;; alpha) CC=cc FC=f77 CPPFLAGS="-DWL=64 -DFORTRANUNDERSCORE $CPPFLAGS" ;; hpux) CC=cc FC=f77 CPPFLAGS="-DWL=32 $CPPFLAGS" SHELL=/bin/sh ;; linux) SHELL="/bin/sh" CC=cc FC=f77 FFLAGS="-w" LDFLAGS="-s $LDFLAGS" CPPFLAGS="-DWL=32 -DFORTRANUNDERSCORE $CPPFLAGS" ;; t3d) CC=/mpp/bin/cc FC=/mpp/bin/cf77 CFLAGS="-T cray-t3d" FFLAGS="-C cray-t3d -dp" CPPFLAGS="-DWL=64 -DFORTRANCAP $CPPFLAGS" SHELL=/bin/sh ;; powerchallenge) CC=cc FC=f77 CFLAGS="-mips4 -fullwarn -64" CPPFLAGS="-DWL=64 -DFORTRANUNDERSCORE $CPPFLAGS" ;; challenge) CC=cc FC=f77 CFLAGS="-mips2 -fullwarn -32" CPPFLAGS="-DWL=32 -DFORTRANUNDERSCORE $CPPFLAGS" ;; paragon) CC=cc FC=f77 CFLAGS="-nx $CFLAGS" FFLAGS="-nx $FFLAGS" CPPFLAGS="-DWL=32 -DFORTRANUNDERSCORE $CPPFLAGS" ;; sp2) CC=cc FC=f77 CPPFLAGS="-DWL=32 $CPPFLAGS" ;; exemplar) CC=cc FC=fort77 FFLAGS="-L/usr/lib -lU77 $FFLAGS" CPPFLAGS="-DWL=32 $CPPFLAGS" SHELL=/bin/sh ;; *) CC=cc FC=f77 CPPFLAGS="-DWL=32 $CPPFLAGS" print_error "WARNING: Configuring for untested architecture. Using" print_error " word size of 32 bits, cc and f77 as compilers." print_error " You might have trouble with Fortran programs" print_error " not linking correctly. Check the manual on" print_error " the FORTRANUNDERSCORE #define." ;; esac ############################################################################### # This section sets the variables that do not relate to parallel code. ############################################################################### CPPFLAGS="-D$ARCH $CPPFLAGS" PGA_LIB_DIR="../lib/$ARCH" LIB_DIRS="-L$PGA_DIR/lib/$ARCH $LIB_DIRS" LIBS="-l$PGA_LIB $LIBS" # Set output variable `RANLIB' to `ranlib' if `ranlib' is found, # otherwise to `:' (do nothing). AC_PROG_RANLIB() # "Determine a C compiler to use. If `CC' is not already set in the # environment, check for `gcc', and use `cc' if it's not found. Set # output variable `CC' to the name of the compiler found. # # "If using the GNU C compiler, set shell variable `GCC' to `yes', # empty otherwise. If output variable `CFLAGS' was not already set, # set it to `-g -O' for the GNU C compiler (`-O' on systems where # GCC does not accept `-g'), or `-g' for other compilers." if test -n "$USR_CC" then CC=$USR_CC else AC_PROG_CC() fi # Check for each program in the whitespace-separated list # PROGS-TO-CHECK-FOR exists in `PATH'. If it is found, set VARIABLE # to the name of that program. Otherwise, continue checking the # next program in the list. If none of the programs in the list are # found, set VARIABLE to VALUE-IF-NOT-FOUND; if VALUE-IF-NOT-FOUND # is not specified, the value of VARIABLE is not changed. if test -n "$USR_FC" then FC=$USR_FC else AC_PROGRAMS_CHECK(FC, f77 fortran xlf gf77 mpxlf if77) fi # Originally had # OBJS="$OBJS $(PGA_LIB_DIR)/f2c.o" # However, freebsd bourne shell equates $(var) and `var`. Hence, I had # to break the assignment up into two parts. $FORTWRAP is a Makefile # dependency line defining how to compile f2c.c if test -n "$FC" then TEMP='$(PGA_LIB_DIR)/f2c.o' OBJS="$OBJS $TEMP" FORTWRAP='$(PGA_LIB_DIR)/f2c.o: f2c.c $(HEADERS)\ $(COMPILE.c) f2c.c' fi if test ! -d lib then mkdir lib fi if test ! -d lib/$ARCH then mkdir lib/$ARCH fi # Set up symlinks for pgapackf.h to any directories with Fortran source rm -f ./examples/fortran/pgapackf.h ./examples/mgh/pgapackf.h ./test/pgapackf.h ln -s ../../include/pgapackf.h ./examples/fortran/pgapackf.h ln -s ../../include/pgapackf.h ./examples/mgh/pgapackf.h ln -s ../include/pgapackf.h ./test/pgapackf.h # Use the stub library. if test $PARALLEL -eq 0 then rm -f ./include/mpi.h ./include/mpif.h ./examples/fortran/mpif.h ./examples/mgh/mpif.h ./test/mpif.h ln -s fakempi_h include/mpi.h ln -s fakempif_h include/mpif.h ln -s ../../include/mpif.h ./examples/fortran/mpif.h ln -s ../../include/mpif.h ./examples/mgh/mpif.h ln -s ../include/mpif.h ./test/mpif.h TEMP='$(PGA_LIB_DIR)/mpi_stub.o' OBJS="$OBJS $TEMP" MPICOMP='$(PGA_LIB_DIR)/mpi_stub.o: mpi_stub.c $(HEADERS)\ $(COMPILE.c) mpi_stub.c' # The tab above is IMPORTANT! Needed for make! else rm -f ./include/mpi.h ./include/mpif.h ./examples/fortran/mpif.h ./examples/mgh/mpif.h ./test/mpif.h ln -s $MPI_INC_DIR/mpif.h ./examples/fortran/mpif.h ln -s $MPI_INC_DIR/mpif.h ./examples/mgh/mpif.h ln -s $MPI_INC_DIR/mpif.h ./test/mpif.h LIBS="$LIBS $MPI_LIB" INCLUDES="$INCLUDES -I$MPI_INC_DIR" fi LIBS="$LIBS -lm" CPPFLAGS="$INCLUDES $CPPFLAGS" LDFLAGS="$LDFLAGS $LIB_DIRS $LIBS" ############################################################################### # This section exports the variables that have previously been set. # Configure creates the Makefiles listed on the last line from the # Makefile.in in each directory. It does this by substituting the value # of $VAR for every occurent of @VAR@ in the Makefile.in. For # example, if the characters @CC@ occur any place in a Makefile.in, they # will be replaced with the value that $CC has when ac_subst(CC) is # called. ############################################################################### AC_SUBST(CC) AC_SUBST(CFLAGS) AC_SUBST(FFLAGS) AC_SUBST(CPPFLAGS) AC_SUBST(FC) AC_SUBST(FORTWRAP) AC_SUBST(HEADERS) AC_SUBST(LDFLAGS) AC_SUBST(PARALLEL) AC_SUBST(PGA_LIB_DIR) AC_SUBST(PGA_LIB) AC_SUBST(OBJS) AC_SUBST(MPICOMP) AC_SUBST(RM) AC_SUBST(RANLIB) AC_SUBST(SHELL) AC_OUTPUT(Makefile source/Makefile test/Makefile test/Makefile \ examples/Makefile examples/c/Makefile examples/fortran/Makefile \ examples/mgh/Makefile) if test ! -f ".pgapack" ; then if test $PARALLEL -eq 1 ; then OPERATION="parallel" ECHO_LIBS="$MPI_LIB" else OPERATION="sequential" ECHO_LIBS="stub routines in mpi_stub.c" fi if test $OPTIMIZE -eq 1 ; then OPERATION="optimized $OPERATION" else OPERATION="debug $OPERATION" fi echo " " echo "PGAPack has been configured for $OPERATION operation on" echo "the $ARCH architecture, using $ECHO_LIBS." echo " " echo "Type \"make install\" to install PGAPack." echo " " fi pgapack-1.1.1/README0000644000175000017500000002161411076416643012066 0ustar eddedd [ Updated March 2008: -- the original README, minus two references to the now obsolete website and mailing lists, follows below -- PGAPack has also been built successfully against LAM/MPI and Open MPI. ] This is the top-level README for PGAPack V1.0 Copyright ========= See the file COPYRIGHT for Copyright and disclaimer information. Introduction ============ PGAPack is a general-purpose, data-structure-neutral, parallel genetic algorithm library developed at Argonne National Laboratory. Key features are: * Callable from Fortran or C. * Runs on uniprocessors, parallel computers, and workstation networks. * Binary-, integer-, real-, and character-valued native data types. * Object-oriented data structure neutral design. * Parameterized population replacement. * Multiple choices for selection, crossover, and mutation operators. * Easy integration of hill-climbing heuristics. * Easy-to-use interface for novice and application users. * Fully extensible to support custom operators and new data types. * Extensive debugging facilities. * A large set of example problems. Availability ============ PGAPack is freely available. The complete distribution is available by anonymous ftp from from ftp.mcs.anl.gov in the file pub/pgapack/pgapack.tar.Z. The distribution contains all source code, installation instructions, users guide, and a collection of examples in C and Fortran. Computational Environment ========================= PGAPack is written in ANSI C and uses the MPI message passing interface and should run on most uniprocessors, parallel computers, and workstation networks. PGAPack has been tested on the workstations and parallel computers specified by the ARCH_TYPE variable below. Documentation ============= * The PGAPack users guide is in ./docs/user_guide.ps. * Man pages for PGAPack functions are in the ./man directory. * Installation instructions are in this README file and the users guide. * Example problems are in the ./examples directory. Installation Requirements ========================= To compile you must have an ANSI C compiler that includes a full implementation of the Standard C library and related header files. To build a *parallel* version of PGAPack you must provide an implementation of MPI (Message Passing Interface) for the parallel computer or workstation network you are running on. Most of our testing and development was done using MPICH, a freely available implementation of MPI. MPICH runs on many parallel computers and workstation networks and is publicly available and free. The complete distribution is available by anonymous ftp from ftp.mcs.anl.gov. Take the file mpich.tar.Z from the directory pub/mpi. Additional information about MPICH is avaliable on the World Wide Web at http://www.mcs.anl.gov/mpi. Installation Instructions ========================= When installing PGAPack you make two choices: whether to build a sequential (the default) or parallel version, and whether to build a debug or optimized (the default) version. In broad outline, the installation steps are as follows. 1. Make a directory to install PGAPack in (mkdir /usr/local/pga). 2. Change directories to the directory created in the last step (cd /usr/local/pga). 3. Obtain the compressed tar file pgapack.tar.Z by anonymous ftp in ftp.mcs.anl.gov from the directory pub/pgapack. 4. Uncompress the tar file (uncompress pgapack.tar.Z). 5. Untar the uncompressed tar file (tar xvf ./pgapack.tar). 6. Run configure to configure the makefiles (configure -arch ARCH_TYPE) where ARCH_TYPE is one of sun4 for Sun SparcStations workstations, next for NeXT workstations, rs600 for IBM RS6000 workstations, irix for Silicon Graphics workstations, hpux for Hewlett Packard workstations, alpha for DEC Alpha workstations, linux for machines running Linux, freebsd for machines running FreeBSD, generic for generic 32-bit machines, powerchallenge for the Silicon Graphics Power Challenge Array, challenge for the Silicon Graphics Challenge, t3d for the Cray T3D, sp2 for the IBM SP2, paragon for the Intel Paragon, or exemplar for the Convex Exemplar. The full configure options are configure -arch ARCH_TYPE [-cc CC] [-cflags CFLAGS] [-f77 FC] [-fflags FFLAGS] [-debug] [-mpiinc MPI_INCLUDE_DIRECTORY] [-mpilib MPI_LIBRARY] [-help] where all parameters except -arch are optional and do the following: [-cc]: The name of the ANSI C compiler, cc by default. [-cflags]: Options passed to the C compiler. [-f77]: The name of the Fortran 77 compiler, f77 by default. (The Fortran compiler is used only to compile the Fortran examples in the [./examples/] directory.) [-fflags]: Options passed to the Fortran compiler. [-debug]: If specified, enables the debugging features and compiles the source code with the -g flag. [-mpiinc]: The *directory* where MPI include files are located. [-mpilib]: The *full path* to the MPI library. If the [-mpilib] and [-mpiinc] options are specified, a parallel version of PGAPack will be built. If these flags are not specified a sequential version of PGAPack will be built. 7. Execute the makefile (make install). 8. Add PGAPack's man pages to your man page path. (setenv MANPATH "$MANPATH"":/home/pgapack/man") 9. Execute a simple test problem Sequential version ------------------ C: /usr/local/pga/examples/c/maxbit Fortran: /usr/local/pga/examples/fortran/maxbit Parallel version ------------------ C: mpirun -np 4 /usr/local/pga/examples/c/maxbit Fortran: mpirun -np 4 /usr/local/pga/examples/fortran/maxbit If a parallel version of PGAPack was used, the actual commands to execute a parallel program depend on the particular MPI implementation and parallel computer. If the MPICH implementation was used the "mpirun" command can be used to execute a parallel program on most systems. Example Installation ==================== Assuming you have the compressed tar file, pgapack.tar.Z, containing the distribution in /home/username. To build a sequential version of PGAPack containing debug features for a Sun SparcStation in /usr/local/pga and run a test example, type: uncompress /home/username/pgapack.tar.Z mkdir /usr/local/pga cd /usr/local/pga tar xvf /home/username/pgapack.tar configure -arch sun4 -debug make install /usr/local/pga/examples/c/maxbit To build a parallel version of PGAPack for an IBM SP parallel computer using an MPI implementation with include files in /usr/local/mpi/include and library in /usr/local/mpi/lib, and run a test example, type: uncompress /home/username/pgapack.tar.Z mkdir /usr/local/pga cd /usr/local/pga tar xvf /home/username/pgapack.tar configure -arch rs6000 -mpiinc /usr/local/mpi/include \ -mpilib /usr/local/mpi/lib/libmpi.a make install mpirun -np 4 /usr/local/pga/examples/c/maxbit PGAPack on PCs =================== PGAPack has not been ported to MS-DOS, Windows 3.1, Windows 95, or Apple OS. As mentioned earlier, however, PGAPack is written in ANSI standard C and should compile in these environments. Be aware, however, that PGAPack's random number generator, PGARandom01, assumes certain machine characteristics for ints and floats that may not correspond with what your PC and/or compiler support, resulting in erroneous values. Structure of the Distribution Directory ======================================= CHANGES: Changes new to this release of PGAPack. COPYRIGHT: Copyright and disclaimer information. README: This file. configure.in: The ``source code'' for the configure script. configure: Unix shell script to configure Makefile.in for a specific architecture. Makefile.in: Prototype that is configured into ``Makefile'' by configure. docs: Directory containing documentation. examples: A directory containing C and Fortran examples. include: The PGAPack include directory. lib: The directory the library will be installed in. man: The directory containing the PGAPack man pages. source: The source code for the PGAPack system. test: A directory containing programs to verify the installation. Contributions ============= PGAPack was written to be extensible in two ways: adding new operators that work with existing data types, and defining new data types. Enhancements of either type that you wish to share are welcome for possible inclusion in future versions of PGAPack. Acknowledgment ============== Users of PGAPack are asked to acknowledge its use in any document referencing work based on the program, such as published research. Also, please supply to us a copy of any published research referencing work based on the software. pgapack-1.1.1/lib/0000755000175000017500000000000010765236352011751 5ustar eddeddpgapack-1.1.1/COPYRIGHT0000644000175000017500000000261210760673225012476 0ustar eddeddCOPYRIGHT 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. pgapack-1.1.1/Makefile.in0000644000175000017500000000221407034447274013251 0ustar eddeddRM = @RM@ SHELL = @SHELL@ default: @echo "Choices are:" @echo "make install (install the PGAPack distribution)" @echo "make clean (return to the state just after configure was run)" @echo "make spotless (keep ONLY *.a and include files)" install: @echo "Installing PGAPack . . ." @cd source ; make @echo "Installing Examples . . ." @cd examples ; make @echo "Installing Test program . . ." @cd test ; make @echo "Install successful." @echo " Please \"cd test\" and run the \"instverf\" program" @echo " to verify the correctness of your installation." clean: @echo "Removing superfluous files . . ." @$(RM) lib/*/*.o @cd examples ; make clean @cd test ; make clean spotless: @echo "WARNING: Removing docs, man, examples, and source directories" @echo " in 5 seconds!!" @sleep 1 @echo " .. 4 .." @sleep 1 @echo " .. 3 .." @sleep 1 @echo " .. 2 .." @sleep 1 @echo " .. 1 .." @sleep 1 @echo " .. 0 .." @echo " .. Removing everything except libraries and includes!!" @sleep 1 @$(RM) -rf docs examples man source test util lib/*/*.o distribution: @/home/pgapack/util/make_distribution pgapack-1.1.1/configure0000755000175000017500000006155510736524650013125 0ustar eddedd#!/bin/sh # This file is configure. # # Make all changes to configure.in, if at all possible. After changing, # run "autoconf". If autoconf is not installed, then make changes to # configure. # # Documentation on the autoconf program exists in GNU info file format. # To read this, run emacs and type C-h i. Then press the down arrow # until you come to the line beginning "* Autoconf:". Pressing enter on # this line will bring up the documentaition. # # Type "configure" (i.e., no arguments) or read below for usage information. # print_error() { echo "$*" 2>&1 ; } print_usage() { cat <<. Usage: configure -arch ARCH_TYPE -cc CC -f77 FC -debug -help -cflags CFLAGS -fflags FFLAGS -mpiinc MPI_INC_DIR -mpilib MPI_LIB where ARCH_TYPE = the type of machine that PGAPack is to be configured for CC = the name of the ANSI C compiler FC = the name of the FORTRAN 77 compiler CFLAGS = C compiler flags FFLAGS = FORTRAN compiler flags MPI_INC_DIR = the MPI include directory MPI_LIB = the full path to the MPI library Known architectures are: Workstations sun4 (SUN OS 4.x) hpux (HP UX) irix (Silicon Graphics IRIX) alpha (DEC Alpha) rs6000 (AIX for IBM RS6000) next (NeXT 680x0) freebsd (PC clones running FreeBSD) linux (PC clones running LINUX) generic (Generic 32-bit UNIX-like machine) MPP's powerchallenge (Silicon Graphics PowerChallenge) challenge (Silicon Graphics Challenge) t3d (Cray-T3D) sp2 (IBM SP2) paragon (Intel Paragon) exemplar (Convex Exemplar) In the absence of the -f77 or -cc options, configure assumes the name of a FORTRAN 77 or ANSI C compiler based on the architecture type. If the -debug flag is set, then PGAPack will be built for debugging. This enables the extensive debugging options and datatype checks. If both -mpiinc and -mpilib are missing, PGAPack is built using a non-parallel "stub" library for all MPI calls. The -help flag causes this usage guide to be printed. Example 1: ---------- Configure and build for parallel operation on the sun4 architectue. MPI is in /usr/local/mpi; the MPI library is /usr/local/mpi/lib/sun4/ch_p4/libmpi.a. configure -arch sun4 -mpilib /usr/local/mpi/lib/sun4/ch_p4/libmpi.a \ -mpiinc /usr/local/mpi/include make install Example 2: ---------- Configure and build a debug sequential library on the rs6000 architecture. configure -arch rs6000 -debug make install . } ############################################################################### # This section initializes the variables that will be used throughout # the script. ############################################################################### #!/bin/sh # Guess values for system-dependent variables and create Makefiles. # Generated automatically using autoconf. # Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # Usage: configure [--srcdir=DIR] [--host=HOST] [--gas] [--nfp] # [--prefix=PREFIX] [--exec-prefix=PREFIX] [--with-PACKAGE[=VALUE]] # Ignores all args except --srcdir, --prefix, --exec-prefix, and # --with-PACKAGE[=VALUE] unless this script has special code to handle it. for arg do # Handle --exec-prefix with a space before the argument. if test x$next_exec_prefix = xyes; then exec_prefix=$arg; next_exec_prefix= # Handle --host with a space before the argument. elif test x$next_host = xyes; then next_host= # Handle --prefix with a space before the argument. elif test x$next_prefix = xyes; then prefix=$arg; next_prefix= # Handle --srcdir with a space before the argument. elif test x$next_srcdir = xyes; then srcdir=$arg; next_srcdir= else case $arg in # For backward compatibility, recognize -exec-prefix and --exec_prefix. -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* | --exec=* | --exe=* | --ex=* | --e=*) exec_prefix=`echo $arg | sed 's/[-a-z_]*=//'` ;; -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- | --exec | --exe | --ex | --e) next_exec_prefix=yes ;; -gas | --gas | --ga | --g) ;; -host=* | --host=* | --hos=* | --ho=* | --h=*) ;; -host | --host | --hos | --ho | --h) next_host=yes ;; -nfp | --nfp | --nf) ;; -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) prefix=`echo $arg | sed 's/[-a-z_]*=//'` ;; -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) next_prefix=yes ;; -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=* | --s=*) srcdir=`echo $arg | sed 's/[-a-z_]*=//'` ;; -srcdir | --srcdir | --srcdi | --srcd | --src | --sr | --s) next_srcdir=yes ;; -with-* | --with-*) package=`echo $arg|sed -e 's/-*with-//' -e 's/=.*//'` # Reject names that aren't valid shell variable names. if test -n "`echo $package| sed 's/[-a-zA-Z0-9_]//g'`"; then echo "configure: $package: invalid package name" >&2; exit 1 fi package=`echo $package| sed 's/-/_/g'` case "$arg" in *=*) val="`echo $arg|sed 's/[^=]*=//'`" ;; *) val=1 ;; esac eval "with_$package='$val'" ;; -v | -verbose | --verbose | --verbos | --verbo | --verb | --ver | --ve | --v) verbose=yes ;; *) ;; esac fi done trap 'rm -fr conftest* confdefs* core; exit 1' 1 3 15 trap 'rm -f confdefs*' 0 # NLS nuisances. # These must not be set unconditionally because not all systems understand # e.g. LANG=C (notably SCO). if test "${LC_ALL+set}" = 'set' ; then LC_ALL=C; export LC_ALL; fi if test "${LANG+set}" = 'set' ; then LANG=C; export LANG; fi rm -f conftest* confdefs.h # AIX cpp loses on an empty file, so make sure it contains at least a newline. echo > confdefs.h compile='${CC-cc} $CFLAGS conftest.c -o conftest $LIBS >/dev/null 2>&1' # A filename unique to this package, relative to the directory that # configure is in, which we can look for to find out if srcdir is correct. unique_file=source/pga.c # Find the source files, if location was not specified. if test -z "$srcdir"; then srcdirdefaulted=yes # Try the directory containing this script, then `..'. prog=$0 confdir=`echo $prog|sed 's%/[^/][^/]*$%%'` test "X$confdir" = "X$prog" && confdir=. srcdir=$confdir if test ! -r $srcdir/$unique_file; then srcdir=.. fi fi if test ! -r $srcdir/$unique_file; then if test x$srcdirdefaulted = xyes; then echo "configure: Can not find sources in \`${confdir}' or \`..'." 1>&2 else echo "configure: Can not find sources in \`${srcdir}'." 1>&2 fi exit 1 fi # Preserve a srcdir of `.' to avoid automounter screwups with pwd. # But we can't avoid them for `..', to make subdirectories work. case $srcdir in .|/*|~*) ;; *) srcdir=`cd $srcdir; pwd` ;; # Make relative path absolute. esac # Save the original args to write them into config.status later. configure_args="$*" ARCH="" # architecture type PARALLEL=0 # parallel libray, or use stub routines? OPTIMIZE=1 # optimized? CPPFLAGS="" # flags to send to the C preprocessor LDFLAGS="" # link flags CFLAGS="" # flags to send to the C compiler FFLAGS="" # flags to send to the FORTRAN compiler PGA_DIR="`pwd`" # the root of the pgapack tree PGA_DIR=`echo $PGA_DIR | sed "s=tmp_mnt/=="` # get rid of 'tmp_mnt/' HEADERS="$PGA_DIR/include/pgapack.h" # headers upon which pgapack depends INCLUDES="-I$PGA_DIR/include" # directories where to search for include files LIB_DIRS="" # directories where to search for libraries LIBS="" # libraries with which to link MPI_INC_DIR="" MPI_LIB="" SHELL="/usr/bin/sh" RM="/bin/rm -f" # command to force removal of files 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' # these are pgapack's object files ############################################################################### # This section parse the command line options. There a two types of options: # those that take arguments and those that don't. Parsing the case where an # option takes an argument is a little tricky. This is how it works. Suppose # that the program comes upon "-cc". Then we know that the next argument # will be the name of the C compiler. Hence, we set the flag next_cc to be # equal to "yes". The next time through the loop, it will be the case that # x$next_cc equal "xyes" because $next_cc expands to "yes". Thus, we know that # this argument is the name of the compiler and we assign it to USR_CC. Then # we set next_cc back to a null string. This way on the next time through # the loop x$next_cc will equal just "x". Since the shell initializes # variables to null strings, we do not have to initialize the "next_" family # of variables by hand. ############################################################################### for arg do if test x$next_arch = xyes then ARCH=$arg next_arch= elif test x$next_mpiinc = xyes then MPI_INC_DIR=$arg next_mpiinc= elif test x$next_mpilib = xyes then MPI_LIB=$arg next_mpilib= elif test x$next_f77 = xyes then USR_FC=$arg next_f77= elif test x$next_cc = xyes then USR_CC=$arg next_cc= elif test x$next_cflags = xyes then CFLAGS="$arg $CFLAGS" next_cflags= elif test x$next_fflags = xyes then FFLAGS="$arg $FFLAGS" next_fflags= else case $arg in -arch) next_arch=yes ;; -f77) next_f77=yes ;; -cc) next_cc=yes ;; -mpiinc) next_mpiinc=yes PARALLEL=1 ;; -mpilib) next_mpilib=yes PARALLEL=1 ;; -debug) OPTIMIZE=0 ;; -cflags) next_cflags=yes ;; -fflags) next_fflags=yes ;; -help) print_usage >& 2 exit 1 ;; *) ;; esac fi done if test "$MPI_LIB" -a "$MPI_INC_DIR" ; then if test ! -d "$MPI_INC_DIR" ; then print_error "MPI_INC_DIR == $MPI_INC_DIR is not a valid directory!" exit 1 fi if test ! -f "$MPI_INC_DIR/mpi.h" ; then print_error "Couldn't find $MPI_INC_DIR/mpi.h!" exit 1 fi if test ! -f "$MPI_LIB" ; then print_error "MPI_LIB == $MPI_LIB is not a file!" exit 1 fi PARALLEL=1 else PARALLEL=0 CPPFLAGS="-DFAKE_MPI $CPPFLAGS" fi if test $OPTIMIZE -eq 1 ; then CPPFLAGS="-DOPTIMIZE $CPPFLAGS" CFLAGS="-O $CFLAGS" FFLAGS="-O $FFLAGS" PGA_LIB="pgaO" else CFLAGS="-g $CFLAGS" FFLAGS="-g $FFLAGS" PGA_LIB="pgag" fi ############################################################################### # This section sets the default values of certain variables based upon the # architecture type specified. If no architecture was specified, the script # issues an error and aborts. ############################################################################### if test -z "$ARCH" then print_error "You must specify the architecture with -arch " print_error "Valid architectures are the following:" print_error " Workstations MPP's" print_error " sun4 powerchallenge" print_error " next challenge" print_error " rs6000 t3d" print_error " freebsd sp2" print_error " irix paragon" print_error " linux exemplar" print_error " hpux" print_error " alpha" print_error " generic" print_error "" print_error "For more information type configure -help." exit 1 fi case $ARCH in sun4) CC=cc FC=f77 CPPFLAGS="-DWL=32 -DFORTRANUNDERSCORE $CPPFLAGS" ;; next) CC=cc FC= CPPFLAGS="-DWL=32 -DFORTRANUNDERSCORE $CPPFLAGS" ;; rs6000) CC=cc FC=f77 CPPFLAGS="-DWL=32 $CPPFLAGS" ;; freebsd) CC=cc FC=f77 FFLAGS="-w" CPPFLAGS="-DWL=32 -DFORTRANUNDERSCORE $CPPFLAGS" ;; irix) CC=cc FC=f77 CPPFLAGS="-DWL=32 -DFORTRANUNDERSCORE $CPPFLAGS" ;; alpha) CC=cc FC=f77 CPPFLAGS="-DWL=64 -DFORTRANUNDERSCORE $CPPFLAGS" ;; hpux) CC=cc FC=f77 CPPFLAGS="-DWL=32 $CPPFLAGS" SHELL=/bin/sh ;; linux) SHELL="/bin/sh" CC=cc FC=f77 FFLAGS="-w" LDFLAGS="-s $LDFLAGS" CPPFLAGS="-DWL=32 -DFORTRANUNDERSCORE $CPPFLAGS" ;; t3d) CC=/mpp/bin/cc FC=/mpp/bin/cf77 CFLAGS="-T cray-t3d" FFLAGS="-C cray-t3d -dp" CPPFLAGS="-DWL=64 -DFORTRANCAP $CPPFLAGS" SHELL=/bin/sh ;; powerchallenge) CC=cc FC=f77 CFLAGS="-mips4 -fullwarn -64" CPPFLAGS="-DWL=64 -DFORTRANUNDERSCORE $CPPFLAGS" ;; challenge) CC=cc FC=f77 CFLAGS="-mips2 -fullwarn -32" CPPFLAGS="-DWL=32 -DFORTRANUNDERSCORE $CPPFLAGS" ;; paragon) CC=cc FC=f77 CFLAGS="-nx $CFLAGS" FFLAGS="-nx $FFLAGS" CPPFLAGS="-DWL=32 -DFORTRANUNDERSCORE $CPPFLAGS" ;; sp2) CC=cc FC=f77 CPPFLAGS="-DWL=32 $CPPFLAGS" ;; exemplar) CC=cc FC=fort77 FFLAGS="-L/usr/lib -lU77 $FFLAGS" CPPFLAGS="-DWL=32 $CPPFLAGS" SHELL=/bin/sh ;; *) CC=cc FC=f77 CPPFLAGS="-DWL=32 $CPPFLAGS" print_error "WARNING: Configuring for untested architecture. Using" print_error " word size of 32 bits, cc and f77 as compilers." print_error " You might have trouble with Fortran programs" print_error " not linking correctly. Check the manual on" print_error " the FORTRANUNDERSCORE #define." ;; esac ############################################################################### # This section sets the variables that do not relate to parallel code. ############################################################################### CPPFLAGS="-D$ARCH $CPPFLAGS" PGA_LIB_DIR="../lib/$ARCH" LIB_DIRS="-L$PGA_DIR/lib/$ARCH $LIB_DIRS" LIBS="-l$PGA_LIB $LIBS" # Set output variable `RANLIB' to `ranlib' if `ranlib' is found, # otherwise to `:' (do nothing). if test -z "$RANLIB"; then # Extract the first word of `ranlib', so it can be a program name with args. set dummy ranlib; word=$2 echo checking for $word IFS="${IFS= }"; saveifs="$IFS"; IFS="${IFS}:" for dir in $PATH; do test -z "$dir" && dir=. if test -f $dir/$word; then RANLIB="ranlib" break fi done IFS="$saveifs" fi test -z "$RANLIB" && RANLIB=":" test -n "$RANLIB" && test -n "$verbose" && echo " setting RANLIB to $RANLIB" # "Determine a C compiler to use. If `CC' is not already set in the # environment, check for `gcc', and use `cc' if it's not found. Set # output variable `CC' to the name of the compiler found. # # "If using the GNU C compiler, set shell variable `GCC' to `yes', # empty otherwise. If output variable `CFLAGS' was not already set, # set it to `-g -O' for the GNU C compiler (`-O' on systems where # GCC does not accept `-g'), or `-g' for other compilers." if test -n "$USR_CC" then CC=$USR_CC else if test -z "$CC"; then # Extract the first word of `gcc', so it can be a program name with args. set dummy gcc; word=$2 echo checking for $word IFS="${IFS= }"; saveifs="$IFS"; IFS="${IFS}:" for dir in $PATH; do test -z "$dir" && dir=. if test -f $dir/$word; then CC="gcc" break fi done IFS="$saveifs" fi test -z "$CC" && CC="cc" test -n "$CC" && test -n "$verbose" && echo " setting CC to $CC" # Find out if we are using GNU C, under whatever name. cat > conftest.c < conftest.out 2>&1 if egrep yes conftest.out >/dev/null 2>&1; then GCC=1 # For later tests. fi rm -f conftest* fi # Check for each program in the whitespace-separated list # PROGS-TO-CHECK-FOR exists in `PATH'. If it is found, set VARIABLE # to the name of that program. Otherwise, continue checking the # next program in the list. If none of the programs in the list are # found, set VARIABLE to VALUE-IF-NOT-FOUND; if VALUE-IF-NOT-FOUND # is not specified, the value of VARIABLE is not changed. if test -n "$USR_FC" then FC=$USR_FC else for p in f77 fortran xlf gf77 mpxlf if77 do if test -z "$FC"; then # Extract the first word of `$p', so it can be a program name with args. set dummy $p; word=$2 echo checking for $word IFS="${IFS= }"; saveifs="$IFS"; IFS="${IFS}:" for dir in $PATH; do test -z "$dir" && dir=. if test -f $dir/$word; then FC="$p" break fi done IFS="$saveifs" fi test -n "$FC" && test -n "$verbose" && echo " setting FC to $FC" test -n "$FC" && break done fi # Originally had # OBJS="$OBJS $(PGA_LIB_DIR)/f2c.o" # However, freebsd bourne shell equates $(var) and `var`. Hence, I had # to break the assignment up into two parts. $FORTWRAP is a Makefile # dependency line defining how to compile f2c.c if test -n "$FC" then TEMP='$(PGA_LIB_DIR)/f2c.o' OBJS="$OBJS $TEMP" FORTWRAP='$(PGA_LIB_DIR)/f2c.o: f2c.c $(HEADERS)\ $(COMPILE.c) f2c.c' fi if test ! -d lib then mkdir lib fi if test ! -d lib/$ARCH then mkdir lib/$ARCH fi # Set up symlinks for pgapackf.h to any directories with Fortran source rm -f ./examples/fortran/pgapackf.h ./examples/mgh/pgapackf.h ./test/pgapackf.h ln -s ../../include/pgapackf.h ./examples/fortran/pgapackf.h ln -s ../../include/pgapackf.h ./examples/mgh/pgapackf.h ln -s ../include/pgapackf.h ./test/pgapackf.h # Use the stub library. if test $PARALLEL -eq 0 then rm -f ./include/mpi.h ./include/mpif.h ./examples/fortran/mpif.h ./examples/mgh/mpif.h ./test/mpif.h ln -s fakempi_h include/mpi.h ln -s fakempif_h include/mpif.h ln -s ../../include/mpif.h ./examples/fortran/mpif.h ln -s ../../include/mpif.h ./examples/mgh/mpif.h ln -s ../include/mpif.h ./test/mpif.h TEMP='$(PGA_LIB_DIR)/mpi_stub.o' OBJS="$OBJS $TEMP" MPICOMP='$(PGA_LIB_DIR)/mpi_stub.o: mpi_stub.c $(HEADERS)\ $(COMPILE.c) mpi_stub.c' # The tab above is IMPORTANT! Needed for make! else rm -f ./include/mpi.h ./include/mpif.h ./examples/fortran/mpif.h ./examples/mgh/mpif.h ./test/mpif.h ln -s $MPI_INC_DIR/mpif.h ./examples/fortran/mpif.h ln -s $MPI_INC_DIR/mpif.h ./examples/mgh/mpif.h ln -s $MPI_INC_DIR/mpif.h ./test/mpif.h LIBS="$LIBS $MPI_LIB" INCLUDES="$INCLUDES -I$MPI_INC_DIR" fi LIBS="$LIBS -lm" CPPFLAGS="$INCLUDES $CPPFLAGS" LDFLAGS="$LDFLAGS $LIB_DIRS $LIBS" ############################################################################### # This section exports the variables that have previously been set. # Configure creates the Makefiles listed on the last line from the # Makefile.in in each directory. It does this by substituting the value # of $VAR for every occurent of @VAR@ in the Makefile.in. For # example, if the characters @CC@ occur any place in a Makefile.in, they # will be replaced with the value that $CC has when ac_subst(CC) is # called. ############################################################################### # Set default prefixes. if test -n "$prefix"; then test -z "$exec_prefix" && exec_prefix='${prefix}' prsub="s%^prefix\\([ ]*\\)=\\([ ]*\\).*$%prefix\\1=\\2$prefix%" fi if test -n "$exec_prefix"; then prsub="$prsub s%^exec_prefix\\([ ]*\\)=\\([ ]*\\).*$%exec_prefix\\1=\\2$exec_prefix%" fi # Quote sed substitution magic chars in DEFS. cat >conftest.def < config.status </dev/null | sed 1q`: # # $0 $configure_args for arg do case "\$arg" in -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) echo running \${CONFIG_SHELL-/bin/sh} $0 $configure_args exec \${CONFIG_SHELL-/bin/sh} $0 $configure_args ;; *) echo "Usage: config.status --recheck" 2>&1; exit 1 ;; esac done trap 'rm -f Makefile source/Makefile test/Makefile test/Makefile \ examples/Makefile examples/c/Makefile examples/fortran/Makefile \ examples/mgh/Makefile; exit 1' 1 3 15 RANLIB='$RANLIB' CC='$CC' FC='$FC' CFLAGS='$CFLAGS' FFLAGS='$FFLAGS' CPPFLAGS='$CPPFLAGS' FORTWRAP='$FORTWRAP' HEADERS='$HEADERS' LDFLAGS='$LDFLAGS' PARALLEL='$PARALLEL' PGA_LIB_DIR='$PGA_LIB_DIR' PGA_LIB='$PGA_LIB' OBJS='$OBJS' MPICOMP='$MPICOMP' RM='$RM' SHELL='$SHELL' LIBS='$LIBS' srcdir='$srcdir' DEFS='$DEFS' prefix='$prefix' exec_prefix='$exec_prefix' prsub='$prsub' extrasub='$extrasub' EOF cat >> config.status <<\EOF top_srcdir=$srcdir CONFIG_FILES=${CONFIG_FILES-"Makefile source/Makefile test/Makefile test/Makefile \ examples/Makefile examples/c/Makefile examples/fortran/Makefile \ examples/mgh/Makefile"} for file in .. ${CONFIG_FILES}; do if test "x$file" != x..; then srcdir=$top_srcdir # Remove last slash and all that follows it. Not all systems have dirname. dir=`echo $file|sed 's%/[^/][^/]*$%%'` if test "$dir" != "$file"; then test "$top_srcdir" != . && srcdir=$top_srcdir/$dir test ! -d $dir && mkdir $dir fi echo creating $file rm -f $file echo "# Generated automatically from `echo $file|sed 's|.*/||'`.in by configure." > $file sed -e " $prsub $extrasub s%@RANLIB@%$RANLIB%g s%@CC@%$CC%g s%@FC@%$FC%g s%@CFLAGS@%$CFLAGS%g s%@FFLAGS@%$FFLAGS%g s%@CPPFLAGS@%$CPPFLAGS%g s%@FORTWRAP@%$FORTWRAP%g s%@HEADERS@%$HEADERS%g s%@LDFLAGS@%$LDFLAGS%g s%@PARALLEL@%$PARALLEL%g s%@PGA_LIB_DIR@%$PGA_LIB_DIR%g s%@PGA_LIB@%$PGA_LIB%g s%@OBJS@%$OBJS%g s%@MPICOMP@%$MPICOMP%g s%@RM@%$RM%g s%@SHELL@%$SHELL%g s%@LIBS@%$LIBS%g s%@srcdir@%$srcdir%g s%@DEFS@%$DEFS% " $top_srcdir/${file}.in >> $file fi; done exit 0 EOF chmod +x config.status ${CONFIG_SHELL-/bin/sh} config.status if test ! -f ".pgapack" ; then if test $PARALLEL -eq 1 ; then OPERATION="parallel" ECHO_LIBS="$MPI_LIB" else OPERATION="sequential" ECHO_LIBS="stub routines in mpi_stub.c" fi if test $OPTIMIZE -eq 1 ; then OPERATION="optimized $OPERATION" else OPERATION="debug $OPERATION" fi echo " " echo "PGAPack has been configured for $OPERATION operation on" echo "the $ARCH architecture, using $ECHO_LIBS." echo " " echo "Type \"make install\" to install PGAPack." echo " " fi pgapack-1.1.1/source/0000755000175000017500000000000010765236352012503 5ustar eddeddpgapack-1.1.1/source/utility.c0000644000175000017500000004052710760674200014353 0ustar eddedd/* 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 /*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 && pga.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); } pgapack-1.1.1/source/mpi_stub.c0000644000175000017500000002240010760674057014472 0ustar eddedd/* 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: mpi_stub.c: MPI stubs needed for PGAPack operation without * linking with a real MPI. * * Authors: Brian P. Walenz ******************************************************************************/ #include "pgapack.h" /* * * In the object files created by gcc the names of functions are the same as * in the corresponding source files. fort77 and g77 append an underscore to * each name when creating the object files. To make it possible to call * the functions with the same name in C and fortran, the fortran versions * in pgapack have an additional underscore. * * This works perfectly well when the function name does not contain one or * more underscores. In this case fort77 and g77 append two underscores. * * The following block of defines was added to take care of that. * * Andreas Franzen , 24 Sep 1998 * */ #define mpi_address_ mpi_address__ #define mpi_bcast_ mpi_bcast__ #define mpi_comm_dup_ mpi_comm_dup__ #define mpi_comm_free_ mpi_comm_free__ #define mpi_comm_rank_ mpi_comm_rank__ #define mpi_comm_size_ mpi_comm_size__ #define mpi_finalize_ mpi_finalize__ #define mpi_init_ mpi_init__ #define mpi_initialized_ mpi_initialized__ #define mpi_probe_ mpi_probe__ #define mpi_send_ mpi_send__ #define mpi_recv_ mpi_recv__ #define mpi_sendrecv_ mpi_sendrecv__ #define mpi_type_commit_ mpi_type_commit__ #define mpi_type_free_ mpi_type_free__ #define mpi_type_struct_ mpi_type_struct__ /* #if defined(FORTRANCAP) #define mpi_address_ MPI_ADDRESS #define mpi_bcast_ MPI_BCAST #define mpi_comm_dup_ MPI_COMM_DUP #define mpi_comm_free_ MPI_COMM_FREE #define mpi_comm_rank_ MPI_COMM_RANK #define mpi_comm_size_ MPI_COMM_SIZE #define mpi_finalize_ MPI_FINALIZE #define mpi_init_ MPI_INIT #define mpi_initialized_ MPI_INITIALIZED #define mpi_probe_ MPI_PROBE #define mpi_send_ MPI_SEND #define mpi_recv_ MPI_RECV #define mpi_sendrecv_ MPI_SENDRECV #define mpi_type_commit_ MPI_TYPE_COMMIT #define mpi_type_free_ MPI_TYPE_FREE #define mpi_type_struct_ MPI_TYPE_STRUCT #elif !defined(FORTRANUNDERSCORE) #define mpi_address_ mpi_address #define mpi_bcast_ mpi_bcast #define mpi_comm_dup_ mpi_comm_dup #define mpi_comm_free_ mpi_comm_free #define mpi_comm_rank_ mpi_comm_rank #define mpi_comm_size_ mpi_comm_size #define mpi_finalize_ mpi_finalize #define mpi_init_ mpi_init #define mpi_initialized_ mpi_initialized #define mpi_probe_ mpi_probe #define mpi_send_ mpi_send #define mpi_recv_ mpi_recv #define mpi_sendrecv_ mpi_sendrecv #define mpi_type_commit_ mpi_type_commit #define mpi_type_free_ mpi_type_free #define mpi_type_struct_ mpi_type_struct #endif */ /* Places the address of "location" into "address" * In FORTRAN, does not return anything. */ int MPI_Address(void *location, MPI_Aint *address) { *address = (MPI_Aint)NULL; return(0); } /* Broadcast "buf" to all processes. * FORTRAN adds integer ierror to the end of the parameters. */ int MPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm) { return(0); } /* Duplicates communicator "comm" into "newcomm" * FORTRAN has a third parameter, integer ie, and does not return anything. */ int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm) { return(0); } /* Frees a communicator. */ int MPI_Comm_free(MPI_Comm *comm) { return(0); } /* Returns the rank of the current process in rank. We return * 0 -- we are the master. */ int MPI_Comm_rank(MPI_Comm comm, int *rank) { *rank = 0; return(0); } /* Returns the number of processors that are in communicator comm * in size. Always 1. */ int MPI_Comm_size(MPI_Comm comm, int *size) { *size = 1; return(0); } /* Finalizes MPI. */ int MPI_Finalize(void) { return(0); } /* Initializes MPI. * Ideally, we should parse the command-line and remove MPI arguments. */ int MPI_Init(int *argc, char ***argv) { return(0); } /* Returns 1 in flag if MPI is already running. It is. */ int MPI_Initialized(int *flag) { *flag = 1; return(0); } /* Waits for messages to us with tag "tag". Sets status->MPI_SOURCE to the * source of the message, status->MPI_TAG to the tag, and status->MPI_ERROR * to 0. */ int MPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status *status) { status->MPI_SOURCE = source; status->MPI_TAG = tag; status->MPI_ERROR = 0; return(0); } /* Send a message to a process. */ int MPI_Send(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) { return(0); } /* Receive a message from a source. */ int MPI_Recv(void* buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status) { status->MPI_SOURCE = source; status->MPI_TAG = tag; status->MPI_ERROR = 0; return(0); } int MPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dest, int sendtag, void *recvbuf, int recvcount, MPI_Datatype recvtype, int source, int recvtag, MPI_Comm comm, MPI_Status *status) { status->MPI_SOURCE = source; status->MPI_TAG = recvtag; status->MPI_ERROR = 0; return(0); } int MPI_Type_commit(MPI_Datatype *datatype) { return(0); } int MPI_Type_free(MPI_Datatype *datatype) { return(0); } int MPI_Type_struct(int count, int *array_of_blocklengths, MPI_Aint *array_of_displacements, MPI_Datatype *array_of_types, MPI_Datatype *newtype) { return(0); } /* FORTRAN versions of some of the above functions. * Most of these operate the same as above, we just need to make sure that * they are linked in properly, see f2c.c for details. */ void mpi_address_(void **location, MPI_Aint *address) { *address = (MPI_Aint)NULL; } void mpi_bcast_(void **n, int *com, MPI_Datatype *dt, int *r, MPI_Comm *c, int *ie) { *ie = 0; } void mpi_comm_dup_(MPI_Comm *comm, MPI_Comm **newcomm, int *ie) { *ie = 0; } void mpi_comm_free_(MPI_Comm **comm, int *ie) { *ie = 0; } void mpi_comm_rank_(MPI_Comm *comm, int *rank, int *ie) { *rank = 0; *ie = 0; } void mpi_comm_size_(MPI_Comm *comm, int *size, int *ie) { *size = 1; *ie = 0; } void mpi_finalize_(int *ie) { *ie = 0; } void mpi_init_(int *ie) { *ie = 0; } void mpi_initialized_(int *flag, int *ie) { *flag = 1; *ie = 0; } void mpi_probe_(int *source, int *tag, MPI_Comm *comm, MPI_Status *status, int *ie) { status->MPI_SOURCE = *source; status->MPI_TAG = *tag; status->MPI_ERROR = 0; *ie = 0; } void mpi_send_(void *buf, int *count, MPI_Datatype *datatype, int *dest, int *tag, MPI_Comm *comm, int *ie) { *ie = 0; } void mpi_recv_(void *buf, int *count, MPI_Datatype *datatype, int *source, int *tag, MPI_Comm *comm, MPI_Status *status, int *ie) { status->MPI_SOURCE = *source; status->MPI_TAG = *tag; status->MPI_ERROR = 0; *ie = 0; } void mpi_sendrecv_(void *sendbuf, int *sendcount, MPI_Datatype *sendtype, int *dest, int *sendtag, void *recvbuf, int *recvcount, MPI_Datatype *recvtype, int *source, int *recvtag, MPI_Comm *comm, MPI_Status *status, int *ie) { status->MPI_SOURCE = *source; status->MPI_TAG = *recvtag; status->MPI_ERROR = 0; *ie = 0; } void mpi_type_commit_(MPI_Datatype **datatype, int *ie) { *ie = 0; } void mpi_type_free_(MPI_Datatype **datatype, int *ie) { *ie = 0; } void mpi_type_struct_(int *count, int **array_of_blocklengths, MPI_Aint **array_of_displacements, MPI_Datatype **array_of_types, MPI_Datatype **newtype, int *ie) { *ie = 0; } pgapack-1.1.1/source/restart.c0000644000175000017500000002204310760674155014336 0ustar eddedd/* 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); } pgapack-1.1.1/source/evaluate.c0000644000175000017500000007426010760673773014475 0ustar eddedd/* 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: evaluate.c: This file contains routines specific to the evaluation * of the strings. * * Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle, * Brian P. Walenz *****************************************************************************/ #include "pgapack.h" /*U**************************************************************************** PGASetEvaluation - Set the evaluation function value for a string to a specified value. Also sets the evaulation up to date flag to PGA_TRUE. Category: Fitness & Evaluation Inputs: ctx - context variable p - string index pop - symbolic constant of the population string p is in val - the (user) evaluation value to assign to string p Outputs: Sets the evaluation function value of string p and the EvalUpToDate flag (to PGA_TRUE) via side effect Example: Set the evaluation function value of string p in population PGA_NEWPOP to 123.456. PGAContext *ctx; int p; : PGASetEvaluation(ctx, p, PGA_NEWPOP, 123.456); ****************************************************************************U*/ void PGASetEvaluation ( PGAContext *ctx, int p, int pop, double val ) { PGAIndividual *ind; PGADebugEntered("PGASetEvaluation"); PGADebugPrint( ctx, PGA_DEBUG_PRINTVAR,"PGASetEvaluation", "p = ", PGA_INT, (void *) &p ); PGADebugPrint( ctx, PGA_DEBUG_PRINTVAR,"PGASetEvaluation", "pop = ", PGA_INT, (void *) &pop ); PGADebugPrint( ctx, PGA_DEBUG_PRINTVAR,"PGASetEvaluation", "val = ", PGA_DOUBLE, (void *) &val ); ind = PGAGetIndividual ( ctx, p, pop ); ind->evalfunc = val; ind->evaluptodate = PGA_TRUE; PGADebugExited("PGASetEvaluation"); } /*U*************************************************************************** PGAGetEvaluation - returns the evaluation function value for string p in population pop Category: Fitness & Evaluation Inputs: ctx - context variable p - string index pop - symbolic constant of the population the string is in Outputs: The evaluation function value for string p in population pop Example: PGAContext *ctx; int p; double eval; : eval = PGAGetEvaluation(ctx, p, PGA_NEWPOP); ***************************************************************************U*/ double PGAGetEvaluation ( PGAContext *ctx, int p, int pop ) { PGAIndividual *ind; PGADebugEntered("PGAGetEvaluation"); PGADebugPrint( ctx, PGA_DEBUG_PRINTVAR,"PGAGetEvaluation", "p = ", PGA_INT, (void *) &p ); PGADebugPrint( ctx, PGA_DEBUG_PRINTVAR,"PGAGetEvaluation", "pop = ", PGA_INT, (void *) &pop ); ind = PGAGetIndividual ( ctx, p, pop ); #ifndef OPTIMIZE if (ind->evaluptodate != PGA_TRUE) PGAError(ctx, "Evaluation not up to date. Returning old evaluation.", PGA_WARNING, PGA_VOID, NULL); #endif PGADebugExited("PGAGetEvaluation"); return(ind->evalfunc); } /*U**************************************************************************** PGASetEvaluationUpToDateFlag - sets the flag associated with a string to PGA_TRUE or PGA_FLASE to indicate whether the evaluate function value is out-of-date or not. Note that this flag is always set to PGA_TRUE when PGASetEvaluation is called. Category: Fitness & Evaluation Inputs: ctx - context variable p - string index pop - symbolic constant of the population string p is in status - boolean for whether up-to-date Outputs: Sets the EvalUpToDate associated with the evaluation function value of string p via side effect Example: Set the evaluation function flag for string p in population PGA_NEWPOP to PGA_FALSE (as might happen after, for example, calling a hill-climbing routine that modified this string). PGAContext *ctx; int p; : PGASetEvaluationUpToDateFlag(ctx, p, PGA_NEWPOP, PGA_FALSE); ****************************************************************************U*/ void PGASetEvaluationUpToDateFlag ( PGAContext *ctx, int p, int pop, int status ) { PGAIndividual *ind; PGADebugEntered("PGASetEvaluationUpToDateFlag"); PGADebugPrint( ctx, PGA_DEBUG_PRINTVAR,"PGASetEvaluationUpToDateFlag", "p = ", PGA_INT, (void *) &p ); PGADebugPrint( ctx, PGA_DEBUG_PRINTVAR,"PGASetEvaluationUpToDateFlag", "pop = ", PGA_INT, (void *) &pop ); ind = PGAGetIndividual ( ctx, p, pop ); switch(status) { case PGA_TRUE: case PGA_FALSE: ind->evaluptodate = status; break; default: PGAError(ctx, "PGASetEvaluationUpToDateFlag: Invalid value of status:", PGA_FATAL, PGA_INT, (void *) &status); break; } PGADebugExited("PGASetEvaluationUpToDateFlag"); } /*U*************************************************************************** PGAGetEvaluationUpToDateFlag - returns true/false to indicate whether the evaluate function value is up to date Category: Fitness & Evaluation Inputs: ctx - context variable p - string index pop - symbolic constant of the population the string is in Outputs: Returns PGA_TRUE if the evaluate function value is up to date. Otherwise, returns PGA_FALSE Example: PGAContext *ctx; int uptodate; : uptodate = PGAGetEvaluationUpToDateFlag(ctx); switch (uptodate) { case PGA_TRUE: printf("Evaluation function value current\n"); break; case PGA_FALSE: printf("Evaluation function value out-of-date\n"); break; } ***************************************************************************U*/ int PGAGetEvaluationUpToDateFlag ( PGAContext *ctx, int p, int pop ) { PGAIndividual *ind; PGADebugEntered("PGAGetEvaluationUpToDateFlag"); PGADebugPrint( ctx, PGA_DEBUG_PRINTVAR,"PGAGetEvaluationUpToDateFlag", "p = ", PGA_INT, (void *) &p ); PGADebugPrint( ctx, PGA_DEBUG_PRINTVAR,"PGAGetEvaluationUpToDateFlag", "p = ", PGA_INT, (void *) &pop ); ind = PGAGetIndividual ( ctx, p, pop ); PGADebugExited("PGAGetEvaluationUpToDateFlag"); return(ind->evaluptodate); } /*U**************************************************************************** PGAGetRealFromBinary - Interpets a binary string as encoding a real value and returns the real value it represents. Category: Fitness & Evaluation Inputs: ctx - context variable p - string index pop - symbolic constant of the population the string is in start - starting bit position in the binary representation end - ending bit position in the binary representation lower - lower bound of the interval the real number is defined on upper - lower bound of the interval the real number is defined on Outputs: The real value encoded by the binary string Example: Decode a real value from the string p in population PGA_NEWPOP. The value to decode lies on the interval [-10,20] and is represented using the 20 bits in bit positions 10--29. double x; : x = PGAGetRealFromBinary(ctx, p, PGA_NEWPOP, 10, 29, -10.0, 20.0); ****************************************************************************U*/ double PGAGetRealFromBinary(PGAContext *ctx, int p, int pop, int start, int end, double lower, double upper) { int length, sum; double value; PGADebugEntered("PGAGetRealFromBinary"); PGACheckDataType("PGAGetRealFromBinary", PGA_DATATYPE_BINARY); length = end - start + 1; if (start < 0) PGAError(ctx, "PGAGetRealFromBinary: start less than 0:", PGA_FATAL, PGA_INT, (void *) &start); if (end >= PGAGetStringLength(ctx)) PGAError(ctx, "PGAGetRealFromBinary: end greater than string " "length:", PGA_FATAL, PGA_INT, (void *) &end); if (start >= end) PGAError(ctx, "PGAGetRealFromBinary: start exceeds end:", PGA_FATAL, PGA_INT, (void *) &start); if (lower >= upper) PGAError(ctx, "PGAGetRealFromBinary: lower exceeds upper:", PGA_FATAL, PGA_DOUBLE, (void *) &lower); sum = PGAGetIntegerFromBinary(ctx, p, pop, start, end); value = PGAMapIntegerToReal(ctx, sum, 0, (length == sizeof(unsigned) * 8 - 1) ? INT_MAX : (1u << length) - 1, lower, upper); PGADebugExited("PGAGetRealFromBinary"); return(value); } /*U**************************************************************************** PGAGetRealFromGrayCode - interpets a binary reflected Gray code sequence in a binary string as encoding a real value and returns the real value it represents. Category: Fitness & Evaluation Inputs: ctx - context variable p - string index pop - symbolic constant of the population the string is in start - starting bit position in the binary representation end - ending bit position in the binary representation lower - lower bound of the interval the real number is defined on upper - lower bound of the interval the real number is defined on Outputs: The real value encoded by the binary reflected Gray code sequence Example: Decode a real value from the string p in population PGA_NEWPOP. The value to decode lies on the interval [-10,20] and is represented using the 20 bits in bit positions 10--29. double x; : x = PGAGetRealFromGrayCode(ctx, p, PGA_NEWPOP, 10, 29, -10.0, 20.0); ****************************************************************************U*/ double PGAGetRealFromGrayCode(PGAContext *ctx, int p, int pop, int start, int end, double lower, double upper) { int length, sum; double value; PGADebugEntered("PGAGetRealFromGrayCode"); PGACheckDataType("PGAGetRealFromGrayCode", PGA_DATATYPE_BINARY); length = end - start + 1; if (start < 0) PGAError(ctx, "PGAGetRealFromGrayCode: start less than 0:", PGA_FATAL, PGA_INT, (void *) &start); if (end >= PGAGetStringLength(ctx)) PGAError(ctx, "PGAGetRealFromGrayCode: end greater than string " "length:", PGA_FATAL, PGA_INT, (void *) &end); if (start >= end) PGAError(ctx, "PGAGetRealFromGrayCode: start exceeds end:", PGA_FATAL, PGA_INT, (void *) &start); if (lower >= upper) PGAError(ctx, "PGAGetRealFromGrayCode: lower exceeds upper:", PGA_FATAL, PGA_DOUBLE, (void *) &lower); sum = PGAGetIntegerFromGrayCode(ctx, p, pop, start, end); value = PGAMapIntegerToReal(ctx, sum, 0, (length == sizeof(unsigned) * 8 - 1) ? INT_MAX : (1u << length) - 1, lower, upper); PGADebugExited("PGAGetRealFromGrayCode"); return(value); } /*U**************************************************************************** PGAEncodeRealAsBinary - encodes a real value as a binary string Category: Fitness & Evaluation Inputs: ctx - context variable p - string index pop - symbolic constant of the population the string is in start - starting bit position in p to encode val in end - ending bit position in p to encode val in low - lower bound of the interval the val is defined on high - lower bound of the interval the val is defined on val - the real number to be represented as a binary string Outputs: The string is modified by side-effect. Example: Encode 3.14 from the interval [0,10] in 30 bits in bit positions 0--29 in string p in population PGA_NEWPOP. PGAContext *ctx; int p; : PGAEncodeRealAsBinary(ctx, p, PGA_NEWPOP, 0, 29, 0.0, 10.0, 3.14); ****************************************************************************U*/ void PGAEncodeRealAsBinary(PGAContext *ctx, int p, int pop, int start, int end, double low, double high, double val) { int length, d; PGADebugEntered("PGAEncodeRealAsBinary"); PGACheckDataType("PGAEncodeRealAsBinary", PGA_DATATYPE_BINARY); length = end - start + 1; if (start < 0) PGAError(ctx, "PGAEncodeRealAsBinary: start less than 0:", PGA_FATAL, PGA_INT, (void *) &start); if (end >= PGAGetStringLength(ctx)) PGAError(ctx, "PGAEncodeRealAsBinary: end greater than string " "length:", PGA_FATAL, PGA_INT, (void *) &end); if (start >= end) PGAError(ctx, "PGAEncodeRealAsBinary: start exceeds end:", PGA_FATAL, PGA_INT, (void *) &start); if (low >= high) PGAError(ctx, "PGAEncodeRealAsBinary: low exceeds high:", PGA_FATAL, PGA_DOUBLE, (void *) &low); if (val < low || val > high) PGAError(ctx, "PGAEncodeRealAsBinary: val outside of bounds:", PGA_FATAL, PGA_DOUBLE, (void *) &val); d = PGAMapRealToInteger(ctx, val, low, high, 0, (length == sizeof(unsigned) * 8 - 1) ? INT_MAX : (1u << length) - 1); PGAEncodeIntegerAsBinary(ctx, p, pop, start, end, d); PGADebugExited("PGAEncodeRealAsBinary"); } /*U**************************************************************************** PGAEncodeRealAsGrayCode - encodes a real value as a binary reflected Gray code sequence Category: Fitness & Evaluation Inputs: ctx - context variable p - string index pop - symbolic constant of the population the string is in start - starting bit position in p to encode val in end - ending bit position in p to encode val in low - lower bound of the interval the val is defined on high - lower bound of the interval the val is defined on val - the real number to be represented as a binary string Outputs: The string is modified by side-effect. Example: Encode 3.14 from the interval [0,10] in 30 bits in bit positions 0--29 in string p in population PGA_NEWPOP as a binary reflected Gray code sequence. PGAContext *ctx; int p; : PGAEncodeRealAsGrayCode(ctx, p, PGA_NEWPOP, 0, 29, 0.0, 10.0, 3.14); ****************************************************************************U*/ void PGAEncodeRealAsGrayCode(PGAContext *ctx, int p, int pop, int start, int end, double low, double high, double val) { int length, d; PGADebugEntered("PGAEncodeRealAsGrayCode"); PGACheckDataType("PGAEncodeRealAsGrayCode", PGA_DATATYPE_BINARY); length = end - start + 1; if (start < 0) PGAError(ctx, "PGAEncodeRealAsGrayCode: start less than 0:", PGA_FATAL, PGA_INT, (void *) &start); if (end >= PGAGetStringLength(ctx)) PGAError(ctx, "PGAEncodeRealAsGrayCode: end greater than string " "length:", PGA_FATAL, PGA_INT, (void *) &end); if (start >= end) PGAError(ctx, "PGAEncodeRealAsGrayCode: start exceeds end:", PGA_FATAL, PGA_INT, (void *) &start); if (low >= high) PGAError(ctx, "PGAEncodeRealAsGrayCode: low exceeds high:", PGA_FATAL, PGA_DOUBLE, (void *) &low); if (val < low || val > high) PGAError(ctx, "PGAEncodeRealAsGrayCode: val outside of bounds:", PGA_FATAL, PGA_DOUBLE, (void *) &val); d = PGAMapRealToInteger(ctx, val, low, high, 0, (length == sizeof(unsigned) * 8 - 1) ? INT_MAX : (1u << length) - 1); PGAEncodeIntegerAsGrayCode(ctx, p, pop, start, end, d); PGADebugExited("PGAEncodeRealAsGrayCode"); } /*U**************************************************************************** PGAGetIntegerFromBinary - interpets a binary string as encoding an integer value and returns the integer value it represents. Category: Fitness & Evaluation Inputs: ctx - context variable p - string index pop - symbolic constant of the population the string is in start - starting bit position in the binary representation end - ending bit position in the binary representation Outputs: The integer value encoded by the binary string Example: Get an integer j from bits 10--29 of string p in population PGA_NEWPOP. PGAContext *ctx; int j, p; : j = PGAGetIntegerFromBinary(ctx, p, PGA_NEWPOP, 10, 29); ****************************************************************************U*/ int PGAGetIntegerFromBinary(PGAContext *ctx, int p, int pop, int start, int end) { int length, i, val; unsigned power2; PGADebugEntered("PGAGetIntegerFromBinary"); PGACheckDataType("PGAGetIntegerFromBinary", PGA_DATATYPE_BINARY); length = end - start + 1; if (length > sizeof(int) * 8 - 1) PGAError(ctx, "PGAGetIntegerFromBinary: length of bit string " "exceeds sizeof type int:", PGA_FATAL, PGA_INT, (void *) &length); if (start < 0) PGAError(ctx, "PGAGetIntegerFromBinary: start less than 0:", PGA_FATAL, PGA_INT, (void *) &start); if (end >= PGAGetStringLength(ctx)) PGAError(ctx, "PGAGetIntegerFromBinary: end greater than string " "length:", PGA_FATAL, PGA_INT, (void *) &end); if (start >= end) PGAError(ctx, "PGAGetIntegerFromBinary: start exceeds end:", PGA_FATAL, PGA_INT, (void *) &start); val = 0; power2 = 1u << (length - 1); for (i = start; i <= end; i++) { if (PGAGetBinaryAllele(ctx, p, pop, i)) val += power2; power2 >>= 1; } PGADebugExited("PGAGetIntegerFromBinary"); return(val); } /*U**************************************************************************** PGAGetIntegerFromGrayCode - interpets a binary reflected Gray code sequence as encoding an integer value and returns the integer value it represents. Category: Fitness & Evaluation Inputs: ctx - context variable p - string index pop - symbolic constant of the population the string is in start - starting bit position in the binary representation end - ending bit position in the binary representation Outputs: The integer value encoded by the binary reflected Gray code sequence Example: Get an integer j from bits 10--29 of string p in population PGA_NEWPOP. The string is encoded in Gray code. PGAContext *ctx; int j, p; : j = PGAGetIntegerFromGrayCode(ctx, p, PGA_NEWPOP, 10, 29); ****************************************************************************U*/ int PGAGetIntegerFromGrayCode(PGAContext *ctx, int p, int pop, int start, int end) { int length, *BitString, i, val; unsigned power2; PGADebugEntered("PGAGetIntegerFromGrayCode"); PGACheckDataType("PGAGetIntegerFromGrayCode", PGA_DATATYPE_BINARY); length = end - start + 1; if (length > sizeof(int) * 8 - 1) PGAError(ctx, "PGAGetIntegerFromGrayCode: length of binary string " "exceeds size of type int:", PGA_FATAL, PGA_INT, (void *) &length); if (start < 0) PGAError(ctx, "PGAGetIntegerFromGrayCode: start less than 0:", PGA_FATAL, PGA_INT, (void *) &start); if (end >= PGAGetStringLength(ctx)) PGAError(ctx, "PGAGetIntegerFromGrayCode: end greater than string " "length:", PGA_FATAL, PGA_INT, (void *) &end); if (start >= end) PGAError(ctx, "PGAGetIntegerFromGrayCode: start exceeds end:", PGA_FATAL, PGA_INT, (void *) &start); BitString = (int *) malloc(length * sizeof(int)); if (!BitString) PGAError(ctx, "PGAGetIntegerFromGrayCode: No room for BitString", PGA_FATAL, PGA_VOID, NULL); BitString[0] = PGAGetBinaryAllele(ctx, p, pop, start); for(i = 1; i < length; i++) BitString[i] = BitString[i-1] ^ PGAGetBinaryAllele(ctx, p, pop, start + i); val = 0; power2 = 1u << (length - 1); for (i = 0; i < length; i++) { if (BitString[i]) val += power2; power2 >>= 1; } free(BitString); PGADebugExited("PGAGetIntegerFromGrayCode"); return(val); } /*U**************************************************************************** PGAEncodeIntegerAsBinary - encodes an integer value as a binary string Category: Fitness & Evaluation Inputs: ctx - context variable p - string index pop - symbolic constant of the population the string is in start - starting bit position in p to encode val in end - ending bit position in p to encode val in val - the integer value to be represented as a binary string Outputs: The string is modified by side-effect. Example: Encode an integer v in 20 bits in bit positions 0--19 in string p in population PGA_NEWPOP. PGAContext *ctx; int v, p; : PGAEncodeIntegerAsBinary(ctx, p, PGA_NEWPOP, 0, 19, v); ****************************************************************************U*/ void PGAEncodeIntegerAsBinary(PGAContext *ctx, int p, int pop, int start, int end, int val) { int length, i; unsigned power2; PGADebugEntered("PGAEncodeIntegerAsBinary"); PGACheckDataType("PGAEncodeIntegerAsBinary", PGA_DATATYPE_BINARY); length = end - start + 1; if (length > sizeof(int) * 8 - 1) PGAError(ctx, "PGAEncodeIntegerAsBinary: length of bit string " "exceeds size of type int:", PGA_FATAL, PGA_INT, (void *) &length); if (start < 0) PGAError(ctx, "PGAEncodeIntegerAsBinary: start less than 0:", PGA_FATAL, PGA_INT, (void *) &start); if (end >= PGAGetStringLength(ctx)) PGAError(ctx, "PGAEncodeIntegerAsBinary: end greater than string " "length:", PGA_FATAL, PGA_INT, (void *) &end); if (start >= end) PGAError(ctx, "PGAEncodeIntegerAsBinary: start exceeds end:", PGA_FATAL, PGA_INT, (void *) &start); if ((val > (1u << length) - 1) && (length != sizeof(int) * 8) - 1) PGAError(ctx, "PGAEncodeIntegerAsBinary: Integer too big for string " "length:", PGA_FATAL, PGA_INT, (void *) &val); if (val < 0) PGAError(ctx, "PGAEncodeIntegerAsBinary: Integer less than zero:", PGA_FATAL, PGA_INT, (void *) & val); power2 = 1u << (length - 1); for (i = 0; i < length; i++) { if (val >= power2) { PGASetBinaryAllele(ctx, p, pop, start + i, 1); val -= power2; } else PGASetBinaryAllele(ctx, p, pop, start + i, 0); power2 >>= 1; } PGADebugExited("PGAEncodeIntegerAsBinary"); } /*U**************************************************************************** PGAEncodeIntegerAsGrayCode - encodes a real value as a binary reflected Gray code sequence Category: Fitness & Evaluation Inputs: ctx - context variable p - string index pop - symbolic constant of the population the string is in start - starting bit position in p to encode val in end - ending bit position in p to encode val in val - the integer value to be represented as a binary reflected Gray code sequence Outputs: The string is modified by side-effect. Example: Encode an integer v in 20 bits in bit positions 0--19 in string p in population PGA_NEWPOP using Gray code. PGAContext *ctx; int v, p; : PGAEncodeIntegerAsGrayCode(ctx, p, PGA_NEWPOP, 0, 19, 7); ****************************************************************************U*/ void PGAEncodeIntegerAsGrayCode(PGAContext *ctx, int p, int pop, int start, int end, int val) { int i, *bit, length; unsigned power2; PGADebugEntered("PGAEncodeIntegerAsGrayCode"); PGACheckDataType("PGAEncodeIntegerAsGrayCode", PGA_DATATYPE_BINARY); length = end - start + 1; if (length > sizeof(int) * 8 - 1) PGAError(ctx, "PGAEncodeIntegerAsGrayCode: length of bit string" "exceeds size of type int:", PGA_FATAL, PGA_INT, (void *) &length); if (start < 0) PGAError(ctx, "PGAEncodeIntegerAsGrayCode: start less than 0:", PGA_FATAL, PGA_INT, (void *) &start); if (end >= PGAGetStringLength(ctx)) PGAError(ctx, "PGAEncodeIntegerAsGrayCode: end greater than string " "length:", PGA_FATAL, PGA_INT, (void *) &end); if (start >= end) PGAError(ctx, "PGAEncodeIntegerAsGrayCode: start exceeds end:", PGA_FATAL, PGA_INT, (void *) &start); if ((val > (1u << length) - 1) && (length != sizeof(int) * 8 - 1)) PGAError(ctx, "PGAEncodeIntegerAsGrayCode: Integer too big for " "string length:", PGA_FATAL, PGA_INT, (void *) &val); if (val < 0) PGAError(ctx, "PGAEncodeIntegerAsGrayCode: Integer less than zero:", PGA_FATAL, PGA_INT, (void *) &val); bit = (int *) malloc(length * sizeof(int)); if (bit == NULL) PGAError(ctx, "PGAEncodeIntegerAsGrayCode: No room to allocate bit", PGA_FATAL, PGA_VOID, NULL); power2 = 1u << (length - 1); for (i = 0; i < length; i++) { if (val >= power2) { bit[i] = 1; val -= power2; } else bit[i] = 0; power2 >>= 1; } PGASetBinaryAllele(ctx, p, pop, start, bit[0]); for(i = 1; i < length; i++) PGASetBinaryAllele(ctx, p, pop, start + i, bit[i-1] ^ bit[i]); free(bit); PGADebugExited("PGAEncodeIntegerAsGrayCode"); } /*I**************************************************************************** PGAMapIntegerToReal - Maps the value v defined on [a,b] to r defined on [l,u]. In the context of PGAPack [a,b] is the discrete interval [0,2^nbits-1] (i.e., the number of bits in a binary string) and [l,u] represent the range of possible values of the real number r. Inputs: ctx - context variable v - value from original interval (usually the decoded bit string) a - lower bound of integer interval (usually 0) b - upper bound of integer interval (usually 2^nbits-1) l - lower bound of real interval u - upper bound of real interval Outputs: Scaled value of v defined on [l,u] Example: Map a five bit (that is, an integer with a range of [0, 31]) integer v to a real in the range [0, 3.14]. PGAContext *ctx; double x; int v; : x = PGAMapIntegerToReal(ctx, v, 0, 31, 0.0, 3.14); ****************************************************************************I*/ double PGAMapIntegerToReal (PGAContext *ctx, int v, int a, int b, double l, double u) { PGADebugEntered("PGAMapIntegerToReal"); PGADebugExited("PGAMapIntegerToReal"); return((v-a) * (u-l) / (b-a) + l); } /*I**************************************************************************** PGAMapRealToInteger - Maps the value r defined on [l,u] to v defined on [a,b]. In the context of PGAPack [a,b] is the discrete interval [0,2^nbits-1] (i.e., the number of bits in a binary string) and [l,u] represent the range of possible values of the real number r. Inputs: ctx - context variable r - real value defined on [l,u] l - lower bound of real interval u - upper bound of real interval a - lower bound of integer interval (usually 0) b - upper bound of integer interval (usually 2^nbits-1) Outputs: Scaled value of r defined on [a,b] Example: Map the value r on the interval [0, 3.14] to a five bit integer v. PGAContext *ctx; double r; int v; : v = PGAMapRealToInteger(ctx, r, 0.0, 3.14, 0, 31); ****************************************************************************I*/ int PGAMapRealToInteger(PGAContext *ctx, double r, double l, double u, int a, int b) { PGADebugEntered("PGAMapRealToInteger"); PGADebugExited("PGAMapRealToInteger"); return PGARound(ctx, (b - a) * (r - l) / (u - l) + a); } pgapack-1.1.1/source/integer.c0000644000175000017500000007051710760674043014314 0ustar eddedd/* 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: integer.c: This file contains the routines specific to the integer * data structure * * Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle, * Brian P. Walenz *****************************************************************************/ #include "pgapack.h" /*U**************************************************************************** PGASetIntegerAllele - sets the value of a (integer) allele. Category: Fitness & Evaluation Inputs: ctx - context variable p - string index pop - symbolic constant of the population the string is in i - allele index val - integer value to set the allele to Outputs: Example: Set the value of the ith allele of string p in population PGA_NEWPOP to 64. PGAContext *ctx; int p, i; : PGASetIntegerAllele (ctx, p, PGA_NEWPOP, i, 64) ****************************************************************************U*/ void PGASetIntegerAllele (PGAContext *ctx, int p, int pop, int i, int value) { PGAIndividual *ind; PGAInteger *chrom; PGADebugEntered("PGASetIntegerAllele"); PGACheckDataType("PGASetIntegerAllele", PGA_DATATYPE_INTEGER); ind = PGAGetIndividual ( ctx, p, pop ); chrom = (PGAInteger *)ind->chrom; chrom[i] = value; PGADebugExited("PGASetIntegerAllele"); } /*U**************************************************************************** PGAGetIntegerAllele - Returns the value of allele i of member p in population pop. Assumes the data type is PGA_DATATYPE_INTEGER. Category: Fitness & Evaluation Inputs: ctx - context variable p - string index pop - symbolic constant of the population the string is in i - allele index Outputs: Example: Returns the value of the ith integer allele of string p in population PGA_NEWPOP. PGAContext *ctx; int p, i, k; : k = PGAGetIntegerAllele ( ctx, p, PGA_NEWPOP, i ) ****************************************************************************U*/ int PGAGetIntegerAllele (PGAContext *ctx, int p, int pop, int i) { PGAIndividual *ind; PGAInteger *chrom; PGADebugEntered("PGAGetIntegerAllele"); PGACheckDataType("PGAGetIntegerAllele", PGA_DATATYPE_INTEGER); ind = PGAGetIndividual ( ctx, p, pop ); chrom = (PGAInteger *)ind->chrom; PGADebugExited("PGAGetIntegerAllele"); return( (int) chrom[i] ); } /*U**************************************************************************** PGASetIntegerInitPermute - sets a flag to tell the initialization routines to set each integer-valued gene to a random permutation of the values given by an upper and lower bound. The length of the interval must be the same as the string length. This is the default strategy for initializing integer-valued strings. The default interval is [0,L-1] where L is the string length. No string initialization is done by this call. Category: Initialization Inputs: ctx - context variable min - the lower bound of numbers used in the permutation max - the upper bound of numbers used in the permutation Outputs: Example: Set the initialization routines to set each gene to a random and unique value from the interval $[500,599]$. PGAContext *ctx; : PGASetIntegerInitPermute(ctx, 500, 599)} ****************************************************************************U*/ void PGASetIntegerInitPermute ( PGAContext *ctx, int min, int max) { int i, range; PGADebugEntered("PGASetIntegerInitPermute"); PGAFailIfSetUp("PGASetIntegerInitPermute"); PGACheckDataType("PGASetIntegerInitPermute", PGA_DATATYPE_INTEGER); range = max - min + 1; if (max <= min) PGAError(ctx, "PGASetIntegerInitPermute: max does not exceed min:", PGA_FATAL, PGA_INT, (void *) &max); else if (range != ctx->ga.StringLen) { PGAError(ctx, "PGASetIntegerInitPermute: range of:", PGA_FATAL, PGA_INT, (void *) &range); PGAError(ctx, "PGASetIntegerInitPermute: does not equal " "string length:", PGA_FATAL, PGA_INT, (void *) &(ctx->ga.StringLen)); } else { ctx->init.IntegerType = PGA_IINIT_PERMUTE; for (i = 0; i < ctx->ga.StringLen; i++) { ctx->init.IntegerMin[i] = min; ctx->init.IntegerMax[i] = max; } } PGADebugExited("PGASetIntegerInitPermute"); } /*U**************************************************************************** PGASetIntegerInitRange - sets a flag to tell the initialization routines to set each integer-valued gene to a value chosen randomly from the interval given by an upper and lower bound. No string initialization is done by this call. Category: Initialization Inputs: ctx - context variable min - array of lower bounds that define the interval the gene is initialized from max - array of upper bounds that define the interval the gene is initialized from Outputs: Example: Set the initialization routines to select a value for gene i uniformly randomly from the interval [0,i]. Assumes all strings are of the same length. PGAContext *ctx; int *low, *high, stringlen, i; : stringlen = PGAGetStringLength(ctx); low = (int *) malloc(stringlen*sizeof(int)); high = (int *) malloc(stringlen*sizeof(int)); for(i=0;iga.StringLen; i++) { if (max[i] < min[i]) PGAError(ctx, "PGASetIntegerInitRange: Lower bound exceeds upper " "bound for allele #", PGA_FATAL, PGA_INT, (void *) &i); else { ctx->init.IntegerMin[i] = min[i]; ctx->init.IntegerMax[i] = max[i]; } } ctx->init.IntegerType = PGA_IINIT_RANGE; PGADebugExited("PGASetIntegerInitRange"); } /*U*************************************************************************** PGAGetIntegerInitType - returns the type of scheme used to randomly initialize strings of data type PGA_DATATYPE_INTEGER. Category: Initialization Inputs: ctx - context variable Outputs: Returns the integer corresponding to the symbolic constant used to specify the scheme used to initialize integer strings Example: PGAContext *ctx; int inittype; : inittype = PGAGetIntegerInitType(ctx); switch (inittype) { case PGA_IINIT_PERMUTE: printf("Data Type = PGA_IINIT_PERMUTE\n"); break; case PGA_IINIT_RANGE: printf("Data Type = PGA_IINIT_RANGE\n"); break; } ***************************************************************************U*/ int PGAGetIntegerInitType (PGAContext *ctx) { PGADebugEntered("PGAGetIntegerInitType"); PGAFailIfNotSetUp("PGAGetIntegerInitType"); PGACheckDataType("PGAGetIntegerInitType", PGA_DATATYPE_INTEGER); PGADebugExited("PGAGetIntegerInitType"); return(ctx->init.IntegerType); } /*U*************************************************************************** PGAGetMinIntegerInitValue - returns the minimum of the range of integers used to randomly initialize integer strings. Category: Initialization Inputs: ctx - context variable Outputs: The minimum of the range of integers used to randomly initialize integer strings Example: PGAContext *ctx; int min; : min = PGAGetMinIntegerInitValue(ctx); ***************************************************************************U*/ int PGAGetMinIntegerInitValue (PGAContext *ctx, int i) { PGADebugEntered("PGAGetMinIntegerInitValue"); PGAFailIfNotSetUp("PGAGetMinIntegerInitValue"); PGACheckDataType("PGASetIntegerAllele", PGA_DATATYPE_INTEGER); if (i < 0 || i >= ctx->ga.StringLen) PGAError(ctx, "PGAGetMinIntegerInitValue: Index out of range:", PGA_FATAL, PGA_INT, (int *) &i); PGADebugExited("PGAGetMinIntegerInitValue"); return(ctx->init.IntegerMin[i]); } /*U*************************************************************************** PGAGetMaxIntegerInitValue - returns the maximum of the range of integers used to randomly initialize integer strings. Category: Initialization Inputs: ctx - context variable Outputs: The maximum of the range of integers used to randomly initialize integer strings. Example: PGAContext *ctx; int max; : max = PGAGetMaxIntegerInitValue(ctx); ***************************************************************************U*/ int PGAGetMaxIntegerInitValue (PGAContext *ctx, int i) { PGADebugEntered("PGAGetMaxIntegerInitValue"); PGAFailIfNotSetUp("PGAGetMaxIntegerInitValue"); PGACheckDataType("PGAGetMaxIntegerInitValue", PGA_DATATYPE_INTEGER); if (i < 0 || i >= ctx->ga.StringLen) PGAError(ctx, "PGAGetMaxIntegerInitValue: Index out of range:", PGA_FATAL, PGA_INT, (int *) &i); PGADebugExited("PGAGetMaxIntegerInitValue"); return(ctx->init.IntegerMax[i]); } /*I**************************************************************************** PGAIntegerCreateString - Allocate memory for a string of type PGAInteger, and initializes or clears the string according to initflag. 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: new - a pointer set to the address of the allocated memory Example: Allocates and clears memory and assigns the address of the allocated memory to the string field (ind->chrom) of the individual. PGAContext *ctx; PGAIndividual *ind; : PGAIntegerCreateString( ctx, ind, PGA_FALSE ); ****************************************************************************I*/ void PGAIntegerCreateString (PGAContext *ctx, int p, int pop, int InitFlag) { int i, fp; PGAInteger *c; PGAIndividual *new = PGAGetIndividual(ctx, p, pop); PGADebugEntered("PGAIntegerCreateString"); new->chrom = (void *)malloc(ctx->ga.StringLen * sizeof(PGAInteger)); if (new->chrom == NULL) PGAError(ctx, "PGAIntegerCreateString: No room to allocate " "new->chrom", PGA_FATAL, PGA_VOID, NULL); c = (PGAInteger *)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; iga.StringLen; i++) c[i] = 0; PGADebugExited("PGAIntegerCreateString"); } /*I**************************************************************************** PGAIntegerMutation - randomly mutates an integer-valued gene with a specified probability. This routine is called from PGAMutation and must cast the void string pointer it is passed as the second argument. Inputs: ctx - context variable p - string index pop - symbolic constant of the population string p is in mr - probability of mutating an integer-valued gene Outputs: Returns the number of mutations Example: ****************************************************************************I*/ int PGAIntegerMutation( PGAContext *ctx, int p, int pop, double mr ) { PGAInteger *c; int i, j, temp; int count = 0; PGADebugEntered("PGAIntegerMutation"); c = (PGAInteger *)PGAGetIndividual(ctx, p, pop)->chrom; for(i=0; iga.StringLen; i++) { /* randomly choose an allele */ if ( PGARandomFlip(ctx, mr) ) { /* apply appropriate mutation operator */ switch (ctx->ga.MutationType) { case PGA_MUTATION_CONSTANT: /* add or subtract from allele */ if ( PGARandomFlip(ctx, .5) ) c[i] += ctx->ga.MutateIntegerValue; else c[i] -= ctx->ga.MutateIntegerValue; break; case PGA_MUTATION_PERMUTE: /* could check for j == i if we were noble */ /* edd: 16 Jun 2007 applying patch from Debian bug report #333381 correcting an 'off-by-one' here bu reducing StringLen by 1 */ j = PGARandomInterval(ctx, 0, ctx->ga.StringLen - 1); temp = c[i]; c[i] = c[j]; c[j] = temp; break; case PGA_MUTATION_RANGE: c[i] = PGARandomInterval(ctx, ctx->init.IntegerMin[i], ctx->init.IntegerMax[i]); break; default: PGAError(ctx, "PGAIntegerMutation: Invalid value of " "ga.MutationType:", PGA_FATAL, PGA_INT, (void *) &(ctx->ga.MutationType)); break; } /* reset to min/max if bounded flag true and outside range */ if( ctx->ga.MutateBoundedFlag == PGA_TRUE ) { if( c[i] < ctx->init.IntegerMin[i]) c[i] = ctx->init.IntegerMin[i]; if( c[i] > ctx->init.IntegerMax[i]) c[i] = ctx->init.IntegerMax[i]; } count++; } } PGADebugExited("PGAIntegerMutation"); return(count); } /*I**************************************************************************** PGAIntegerOneptCrossover - 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; : PGAIntegerOneptCrossover(ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP); ****************************************************************************I*/ void PGAIntegerOneptCrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1, int c2, int pop2) { PGAInteger *parent1 = (PGAInteger *)PGAGetIndividual(ctx, p1, pop1)->chrom; PGAInteger *parent2 = (PGAInteger *)PGAGetIndividual(ctx, p2, pop1)->chrom; PGAInteger *child1 = (PGAInteger *)PGAGetIndividual(ctx, c1, pop2)->chrom; PGAInteger *child2 = (PGAInteger *)PGAGetIndividual(ctx, c2, pop2)->chrom; int i, xsite; PGADebugEntered("PGAIntegerOneptCrossover"); xsite = PGARandomInterval(ctx, 1,ctx->ga.StringLen-1); for(i=0;iga.StringLen;i++) { child1[i] = parent2[i]; child2[i] = parent1[i]; } PGADebugExited("PGAIntegerOneptCrossover"); } /*I**************************************************************************** PGAIntegerTwoptCrossover - 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; : PGAIntegerTwoptCrossover(ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP); ****************************************************************************I*/ void PGAIntegerTwoptCrossover( PGAContext *ctx, int p1, int p2, int pop1, int c1, int c2, int pop2) { PGAInteger *parent1 = (PGAInteger *)PGAGetIndividual(ctx, p1, pop1)->chrom; PGAInteger *parent2 = (PGAInteger *)PGAGetIndividual(ctx, p2, pop1)->chrom; PGAInteger *child1 = (PGAInteger *)PGAGetIndividual(ctx, c1, pop2)->chrom; PGAInteger *child2 = (PGAInteger *)PGAGetIndividual(ctx, c2, pop2)->chrom; int i, temp, xsite1, xsite2; PGADebugEntered("PGAIntegerTwoptCrossover"); /* 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;iga.StringLen;i++) { child1[i] = parent1[i]; child2[i] = parent2[i]; } PGADebugExited("PGAIntegerTwoptCrossover"); } /*I**************************************************************************** PGAIntegerUniformCrossover - 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; : PGAIntegerUniformCrossover( ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP); ****************************************************************************I*/ void PGAIntegerUniformCrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1, int c2, int pop2) { PGAInteger *parent1 = (PGAInteger *)PGAGetIndividual(ctx, p1, pop1)->chrom; PGAInteger *parent2 = (PGAInteger *)PGAGetIndividual(ctx, p2, pop1)->chrom; PGAInteger *child1 = (PGAInteger *)PGAGetIndividual(ctx, c1, pop2)->chrom; PGAInteger *child2 = (PGAInteger *)PGAGetIndividual(ctx, c2, pop2)->chrom; int i; PGADebugEntered("PGAIntegerUniformCrossover"); for(i=0;iga.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("PGAIntegerUniformCrossover"); } /*I**************************************************************************** PGAIntegerPrintString - writes an integer-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 member p in population PGA_NEWPOP to stdout. PGAContext *ctx; int p; : PGAIntegerPrintString(ctx, stdout, p, PGA_NEWPOP); ****************************************************************************I*/ void PGAIntegerPrintString ( PGAContext *ctx, FILE *fp, int p, int pop) { PGAInteger *c = (PGAInteger *)PGAGetIndividual(ctx, p, pop)->chrom; int i; PGADebugEntered("PGAIntegerPrintString"); for(i = 0; i < ctx->ga.StringLen; i++) { switch ( i % 6 ) { case 0: fprintf ( fp, "#%5d: [%8ld]",i,c[i]); break; case 1: case 2: case 3: case 4: fprintf ( fp, ", [%8ld]",c[i]); break; case 5: fprintf ( fp, ", [%8ld]",c[i]); if (i+1 < ctx->ga.StringLen) fprintf ( fp, "\n"); break; } } fprintf ( fp, "\n" ); PGADebugExited("PGAIntegerPrintString"); } /*I**************************************************************************** PGAIntegerCopyString - Copy one integer-valued 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: Example: ****************************************************************************I*/ void PGAIntegerCopyString (PGAContext *ctx, int p1, int pop1, int p2, int pop2) { PGAInteger *source = (PGAInteger *)PGAGetIndividual(ctx, p1, pop1)->chrom; PGAInteger *dest = (PGAInteger *)PGAGetIndividual(ctx, p2, pop2)->chrom; int i; PGADebugEntered("PGAIntegerCopyString"); for (i = 0; i < ctx->ga.StringLen; i++) dest[i] = source[i]; PGADebugExited("PGAIntegerCopyString"); } /*I**************************************************************************** PGAIntegerDuplicate - Returns true if string a is a duplicate of 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: ****************************************************************************I*/ int PGAIntegerDuplicate( PGAContext *ctx, int p1, int pop1, int p2, int pop2) { PGAInteger *a = (PGAInteger *)PGAGetIndividual(ctx, p1, pop1)->chrom; PGAInteger *b = (PGAInteger *)PGAGetIndividual(ctx, p2, pop2)->chrom; int i; PGADebugEntered("PGAIntegerDuplicate"); i = ctx->ga.StringLen-1; if (a[0] == b[0]) for(; (i>0) && (a[i] == b[i]); i--); PGADebugExited("PGAIntegerDuplicate"); return((i==0) ? PGA_TRUE : PGA_FALSE); } /*I**************************************************************************** PGAIntegerInitString - randomly initialize a string of type PGAInteger Inputs: ctx - context variable p - index of string to randomly initialize pop - symbolic constant of the population string p is in Outputs: Example: ****************************************************************************I*/ void PGAIntegerInitString(PGAContext *ctx, int p, int pop) { int *list; int len, i, j; PGAInteger *c = (PGAInteger *)PGAGetIndividual(ctx, p, pop)->chrom; PGADebugEntered("PGAIntegerInitString"); len = ctx->ga.StringLen; switch (ctx->init.IntegerType) { case PGA_IINIT_PERMUTE: list = (int *)malloc(sizeof(int) * len); if (list == NULL) PGAError(ctx, "PGAIntegerInitString: No room to allocate list", PGA_FATAL, PGA_VOID, NULL); j = ctx->init.IntegerMin[0]; for (i = 0; i < len; i++) list[i] = j++; for (i = 0; i < len; i++) { j = PGARandomInterval ( ctx, 0, len - i - 1 ); c[i] = list[j]; list[j] = list[len - i - 1]; } free(list); break; case PGA_IINIT_RANGE: for (i = 0; i < len; i++) c[i] = PGARandomInterval(ctx, ctx->init.IntegerMin[i], ctx->init.IntegerMax[i]); break; } PGADebugExited("PGAIntegerInitString"); } /*I**************************************************************************** PGAIntegerBuildDatatype - Build an MPI datatype for a string of type PGA_DATATYPE_INTEGER. Inputs: ctx - context variable p - index of string to randomly initialize pop - symbolic constant of the population string p is in Outputs: Example: ****************************************************************************I*/ MPI_Datatype PGAIntegerBuildDatatype(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("PGAIntegerBuildDatatype"); 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_LONG; MPI_Type_struct(4, counts, displs, types, &individualtype); MPI_Type_commit(&individualtype); PGADebugExited("PGAIntegerBuildDatatype"); return (individualtype); } pgapack-1.1.1/source/hamming.c0000644000175000017500000001131610760674023014265 0ustar eddedd/* 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: hamming.c: This file contains the routines that have to do with * Hamming distances. * * Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle *****************************************************************************/ #include "pgapack.h" /*U**************************************************************************** PGAHammingDistance - Calculates the mean Hamming distance for a population of binary strings. For all other data types returns a value of 0.0 and prints a warning message. Category: Utility Inputs: ctx - context variable popindex - symbolic constant of the population for which the Hamming distance is to be calculated Output: The mean Hamming distance in the population Example: PGAContext *ctx; double hd; : hd = PGAHammingDistance(ctx, PGA_NEWPOP); ****************************************************************************U*/ double PGAHammingDistance( PGAContext *ctx, int popindex) { int i, j, hd, count=0; double avg_hd = 0.; PGAIndividual *pop; /* pointer to appropriate population */ PGADebugEntered("PGAHammingDistance"); switch (popindex) { case PGA_OLDPOP: pop = ctx->ga.oldpop; break; case PGA_NEWPOP: pop = ctx->ga.newpop; break; default: PGAError( ctx, "PGAHammingDistance: Invalid value of popindex:", PGA_FATAL, PGA_INT, (void *) &popindex ); break; } switch (ctx->ga.datatype) { case PGA_DATATYPE_BINARY: for(i=0; iga.PopSize-1; ++i) for ( j = i+1; jga.PopSize; ++j ) { count++; hd = PGABinaryHammingDistance( ctx, (pop+i)->chrom, (pop+j)->chrom ); avg_hd += (double) hd; } avg_hd /= (double) count; break; case PGA_DATATYPE_INTEGER: avg_hd = 0.0; PGAError( ctx, "PGAHammingDistance: No Hamming Distance for PGA_DATATYPE_INTEGER ", PGA_WARNING, PGA_DOUBLE, (void *) &avg_hd ); break; case PGA_DATATYPE_REAL: avg_hd = 0; PGAError( ctx, "PGAHammingDistance: No Hamming Distance for PGA_DATATYPE_REAL ", PGA_WARNING, PGA_DOUBLE, (void *) &avg_hd ); break; case PGA_DATATYPE_CHARACTER: avg_hd = 0; PGAError( ctx, "PGAHammingDistance: No Hamming Distance for PGA_DATATYPE_CHARACTER ", PGA_WARNING, PGA_DOUBLE, (void *) &avg_hd ); break; case PGA_DATATYPE_USER: avg_hd = 0; PGAError( ctx, "PGAHammingDistance: No Hamming Distance for PGA_DATATYPE_USER ", PGA_WARNING, PGA_DOUBLE, (void *) &avg_hd ); break; default: PGAError( ctx, "PGAHammingDistance: Invalid value of datatype:", PGA_FATAL, PGA_INT, (void *) &(ctx->ga.datatype) ); break; } PGADebugExited("PGAHammingDistance"); return(avg_hd); } pgapack-1.1.1/source/fitness.c0000644000175000017500000005425010760674014014324 0ustar eddedd/* 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: fitness.c: This file contains the routines that have to do with * fitness calculations. * * Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle, * Brian P. Walenz *****************************************************************************/ #include "pgapack.h" /*U**************************************************************************** PGAFitness - Maps the user's evaluation function value to a fitness value. First, the user's evaluation function value is translated to all positive values if any are negative. Next, this positive sequence is translated to a maximization problem if the user's optimization direction was minimization. This positive sequence is then mapped to a fitness value using linear ranking, linear normalization fitness, or the identity (i.e., the evaluation function value). This routine is usually used after PGAEvaluate is called. Category: Fitness & Evaluation Inputs: ctx - context variable pop - symbolic constant of the population to calculate fitness for Outputs: Calculates the fitness for each string in the population via side effect Example: Calculate the fitness of all strings in population PGA_NEWPOP after calling PGAEvaluate to calculate the strings evaluation value. double energy(PGAContext *ctx, int p, int pop); PGAContext *ctx; : PGAEvaluate(ctx, PGA_NEWPOP, energy); PGAFitness (ctx, PGA_NEWPOP); ****************************************************************************U*/ void PGAFitness ( PGAContext *ctx, int popindex ) { int i; double mineval; PGAIndividual *pop; PGADebugEntered("PGAFitness"); /* set pointer to appropriate population */ switch (popindex) { case PGA_OLDPOP: pop = ctx->ga.oldpop; break; case PGA_NEWPOP: pop = ctx->ga.newpop; break; default: PGAError( ctx, "PGAFitness: Invalid value of popindex:", PGA_FATAL, PGA_INT, (void *) &popindex ); break; } /* make sure all evaluation function values are up-to-date */ for( i=0; iga.PopSize; i++ ) { /*printf("i = %d, evaluptodate = %d\n",i,(pop+i)->evaluptodate);*/ if ( (pop+i)->evaluptodate != PGA_TRUE ) PGAError( ctx, "PGAFitness: evaluptodate not PGA_TRUE for:", PGA_FATAL, PGA_INT, (void *) &i ); } /* put raw fitness into fitness field */ for( i=0; iga.PopSize; i++ ) (pop+i)->fitness = (pop+i)->evalfunc; /* translate to all positive sequence (if necessary) */ mineval = ctx->sys.PGAMaxDouble; for( i=0; iga.PopSize; i++ ) if ( (pop+i)->fitness < mineval ) mineval =(pop+i)->fitness; if ( mineval < 0.0 ) { mineval = (-1.01) * mineval; for( i=0; iga.PopSize; i++ ) (pop+i)->fitness = (pop+i)->fitness + mineval; } /* translate to maximization problem (if necessary) */ if ( ctx->ga.optdir == PGA_MINIMIZE ) { switch (ctx->ga.FitnessMinType) { case PGA_FITNESSMIN_RECIPROCAL: PGAFitnessMinReciprocal( ctx, pop ); break; case PGA_FITNESSMIN_CMAX: PGAFitnessMinCmax ( ctx, pop ); break; default: PGAError( ctx, "PGAFitness: Invalid FitnessMinType:", PGA_FATAL, PGA_INT, (void *) &(ctx->ga.FitnessMinType) ); break; } } /* last step in fitness calculation */ switch (ctx->ga.FitnessType) { case PGA_FITNESS_RAW: break; case PGA_FITNESS_NORMAL: PGAFitnessLinearNormal ( ctx, pop ); break; case PGA_FITNESS_RANKING: PGAFitnessLinearRank ( ctx, pop ); break; default: PGAError( ctx, "PGAFitness: Invalid FitnessType:", PGA_FATAL, PGA_INT, (void *) &(ctx->ga.FitnessType) ); break; } PGADebugExited("PGAFitness"); } /*U**************************************************************************** PGARank - returns the rank of a string in a population. This is a value between 1,...,N (the population size). The most fit string has rank 1, the least fit string has rank N. Category: Fitness & Evaluation Inputs: ctx - context variable p - the index of the string whose rank is desired order - an array containing a unique rank for each string n - the size of the array order Outputs: The rank of string p Example: Determine the rank of string p. PGAContext *ctx; int i, popsize, rank, *order; double *fitness; popsize = PGAGetPopsize(ctx); order = (int *) malloc(sizeof(int) * popsize); fitness = (double *)malloc(sizeof(double) * popsize); for(i=0;i PGAGetPopSize(ctx))) PGAError(ctx, "PGARank: Not a valid population member, p = ", PGA_FATAL, PGA_INT, (void *)&p); /* Search through all the orderings until we find the one that * matches the given string. Return the index number. If we do not * find one, something is _very_ bad; terminate with a fatal error. */ for(i=0; ievalfunc); } /*U*************************************************************************** PGAGetFitnessType - Returns the type of fitness transformation used. Category: Fitness & Evaluation Inputs: ctx - context variable Outputs: Returns the integer corresponding to the symbolic constant used to specify the type of fitness transformation used Example: PGAContext *ctx; int fittype; : fittype = PGAGetFitnessType(ctx); switch (fittype) { case PGA_FITNESS_RAW: printf("Fitness Type = PGA_FITNESS_RAW\n"); break; case PGA_FITNESS_NORMAL: printf("Fitness Type = PGA_FITNESS_NORMAL\n"); break; case PGA_FITNESS_RANKING: printf("Fitness Type = PGA_FITNESS_RANKING\n"); break; } ***************************************************************************U*/ int PGAGetFitnessType (PGAContext *ctx) { PGADebugEntered("PGAGetFitnessType"); PGAFailIfNotSetUp("PGAGetFitnessType"); PGADebugExited("PGAGetFitnessType"); return(ctx->ga.FitnessType); } /*U*************************************************************************** PGAGetFitnessMinType - Returns the type of fitness transformation used for minimization problems. Category: Fitness & Evaluation Inputs: ctx - context variable Outputs: Returns the integer corresponding to the symbolic constant used to specify the type of fitness transformation used for minimization problems Example: PGAContext *ctx; int fitmintype; : fitmintype = PGAGetFitnessMinType(ctx); switch (fitmintype) { case PGA_FITNESSMIN_RECIPROCAL: printf("Fitness Minimization Type = PGA_FITNESSMIN_RECIPROCAL\n"); break; case PGA_FITNESSMIN_CMAX: printf("Fitness Minimization Type = PGA_FITNESSMIN_CMAX\n"); break; } ***************************************************************************U*/ int PGAGetFitnessMinType (PGAContext *ctx) { PGADebugEntered("PGAGetFitnessMinType"); PGAFailIfNotSetUp("PGAGetFitnessType"); PGADebugExited("PGAGetFitnessMinType"); return(ctx->ga.FitnessMinType); } /*U*************************************************************************** PGAGetMaxFitnessRank - returns the maximum value used in rank-based fitness. Category: Fitness & Evaluation Inputs: ctx - context variable Outputs: The value of MAX used in rank-based fitness Example: PGAContext *ctx; double max; : max = PGAGetMaxFitnessRank(ctx); ***************************************************************************U*/ double PGAGetMaxFitnessRank (PGAContext *ctx) { PGADebugEntered("PGAGetMaxFitnessRank"); PGAFailIfNotSetUp("PGAGetFitnessType"); PGADebugExited("PGAGetMaxFitnessRank"); return(ctx->ga.FitnessRankMax); } /*U**************************************************************************** PGASetFitnessType - Set the type of fitness algorithm to use. Valid choices are PGA_FITNESS_RAW, PGA_FITNESS_NORMAL, or PGA_FITNESS_RANKING for raw fitness (the evaluation function value), linear normalization, or linear ranking, respectively. The default is PGA_FITNESS_RAW. Category: Fitness & Evaluation Inputs: ctx - context variable fitness_type - symbolic constant to specify fitness type Outputs: None Example: PGAContext *ctx; : PGASetFitnessType(ctx, PGA_FITNESS_RANKING); ****************************************************************************U*/ void PGASetFitnessType( PGAContext *ctx, int fitness_type) { PGADebugEntered("PGASetFitnessType"); switch (fitness_type) { case PGA_FITNESS_RAW: case PGA_FITNESS_NORMAL: case PGA_FITNESS_RANKING: ctx->ga.FitnessType = fitness_type; break; default: PGAError(ctx, "PGASetFitnessType: Invalid value of fitness_type:", PGA_FATAL, PGA_INT, (void *) &fitness_type); break; } PGADebugExited("PGASetFitnessType"); } /*U**************************************************************************** PGASetFitnessMinType - sets the type of algorithm used if a minimization problem is specified to determine how values are remapped for maximization. Valid choices are PGA_FITNESSMIN_RECIPROCAL and PGA_FITNESSMIN_CMAX to do the mapping using the reciprocal of the evaluation function, or by subtracting the worst evaluation function value from each evaluation function value, respectively. The default is PGA_FITNESSMIN_CMAX Category: Fitness & Evaluation Inputs: ctx - context variable fitness_type - symbolic constant to specify fitness minimization type Outputs: None Example: PGAContext *ctx; : PGASetFitnessMinType(ctx, PGA_FITNESSMIN_CMAX); ****************************************************************************U*/ void PGASetFitnessMinType( PGAContext *ctx, int fitness_type) { PGADebugEntered("PGASetFitnessMinType"); switch (fitness_type) { case PGA_FITNESSMIN_RECIPROCAL: case PGA_FITNESSMIN_CMAX: ctx->ga.FitnessMinType = fitness_type; break; default: PGAError ( ctx, "PGASetFitnessMinType: Invalid value of fitness_type:", PGA_FATAL, PGA_INT, (void *) &fitness_type); break; } PGADebugExited("PGASetFitnessMinType"); } /*U**************************************************************************** PGASetMaxFitnessRank - The value of the parameter Max when using linear ranking for fitness determination. The default value is 1.2. The value must be from the interval [1.0, 2.0]. The fitness type must have been set to PGA_FITNESS_RANKING with PGASetFitnessType for this function call to have any effect. Category: Fitness & Evaluation Inputs: ctx - context variable max - the value of the parameter Max when using linear ranking Outputs: None Example: PGAContext *ctx; : PGASetMaxFitnessRank(ctx, 1.1); ****************************************************************************U*/ void PGASetMaxFitnessRank( PGAContext *ctx, double fitness_rank_max) { PGADebugEntered("PGASetMaxFitnessRank"); if ((fitness_rank_max < 1.0) || (fitness_rank_max > 2.0)) PGAError ( ctx, "PGASetMaxFitnessRank: Invalid value of fitness_rank_max:", PGA_FATAL, PGA_DOUBLE, (void *) &fitness_rank_max); else ctx->ga.FitnessRankMax = fitness_rank_max; PGADebugExited("PGASetMaxFitnessRank"); } /*I**************************************************************************** PGAFitnessLinearNormal - Calculates fitness using a ranking method and linear' ordering. The fitness function is of the form u(x) = K - ( rank * sigma ) with the constant K equal to the mean of the evaluation functions, and the decrement sigma equal to the standard deviation of the same. Ref: L. Davis, Handbook of Genetic Algorithms, pg. 33 Inputs: ctx - context variable pop - population pointer to calculate fitness for Outputs: Calculates the fitness for each string in the population via side effect Example: ****************************************************************************I*/ void PGAFitnessLinearNormal ( PGAContext *ctx, PGAIndividual *pop ) { int i; double K, sigma, mean; PGADebugEntered("PGAFitnessLinearNormal"); /* fill arrays for sorting */ for(i=0;iga.PopSize;i++) { ctx->scratch.dblscratch[i] = (pop+i)->fitness; ctx->scratch.intscratch[i] = i; } /* calculate parameters for linear normalization */ mean = PGAMean ( ctx, ctx->scratch.dblscratch, ctx->ga.PopSize ); sigma = PGAStddev ( ctx, ctx->scratch.dblscratch, ctx->ga.PopSize, mean ); if (sigma == 0) sigma = 1; K = sigma * (double) ctx->ga.PopSize; PGADblHeapSort ( ctx, ctx->scratch.dblscratch, ctx->scratch.intscratch, ctx->ga.PopSize); for( i=0; iga.PopSize; i++ ) (pop+i)->fitness = K - ( sigma * (double) PGARank(ctx,i,ctx->scratch.intscratch,ctx->ga.PopSize) ); PGADebugExited("PGAFitnessLinearNormal"); } /*I**************************************************************************** PGAFitnessLinearRank - Calculates fitness using linear ranking. The fitness function is of the form 1/N * ( max - (max-min) * ( (i-1)/(N-1) ) ) where min = 2-max and 1 <= max <= 2. Ref: J. Baker: Adaptive selection methods for GAs Ref: J. Baker: Extended selection mechanism in GAs Ref: J. Grefenstte: A critical look at implicit parallelism Ref: D. Whitley's linear() function on pp. 121 of ICGA Inputs: ctx - context variable pop - population pointer to calculate fitness for Outputs: Calculates the fitness for each string in the population via side effect Example: ****************************************************************************I*/ void PGAFitnessLinearRank ( PGAContext *ctx, PGAIndividual *pop ) { double max, min, popsize, rpopsize; int i; PGADebugEntered("PGAFitnessLinearRank"); max = ctx->ga.FitnessRankMax; min = 2. - max; popsize = (double) ctx->ga.PopSize; rpopsize = 1.0/popsize; for(i=0;iga.PopSize;i++) { ctx->scratch.dblscratch[i] = (pop+i)->fitness; ctx->scratch.intscratch[i] = i; } PGADblHeapSort ( ctx, ctx->scratch.dblscratch, ctx->scratch.intscratch, ctx->ga.PopSize); for(i=0;iga.PopSize;i++) { (pop+i)->fitness = rpopsize * ( max - ( (max - min) * ( ( (double) PGARank(ctx,i,ctx->scratch.intscratch,ctx->ga.PopSize) - 1. ) / ( popsize - 1. ) ) ) ); } PGADebugExited("PGAFitnessLinearRank"); } /*I**************************************************************************** PGAFitnessMinReciprocal - Calculates fitness in the case of a minimization problem using the reciprocal of the evaluation function. This is a power law u(x) = ( a f(x) + b )^k with a=1, b=0, k=-1 Inputs: ctx - context variable pop - population pointer to calculate fitness for Outputs: Calculates the fitness for each string in the population via side effect Example: ****************************************************************************I*/ void PGAFitnessMinReciprocal ( PGAContext *ctx, PGAIndividual *pop ) { int i; PGADebugEntered("PGAFitnessMinReciprocal"); for( i=0; iga.PopSize; i++ ) { if ( (pop+i)->fitness != 0. ) (pop+i)->fitness = 1. / (pop+i)->fitness; else PGAError( ctx, "PGAFitnessReciprocal: Value 0.0 for fitness member:", PGA_FATAL, PGA_INT, (void *) &i ); } PGADebugExited("PGAFitnessMinReciprocal"); } /*I**************************************************************************** PGAFitnessMinCmax - Calculates fitness in the case of a minimization problem by subtracting the worst evaluation function value from each evaluation function. This is a dynamic linear fitness function u(x) = a f(x) + b(t) with a=-1, b(t) = 1.1 * max f(x) Inputs: ctx - context variable pop - population pointer to calculate fitness for Outputs: Calculates the fitness for each string in the population via side effect Example: ****************************************************************************I*/ void PGAFitnessMinCmax ( PGAContext *ctx, PGAIndividual *pop ) { int i; double cmax; PGADebugEntered("PGAFitnessMinCmax"); cmax = 0.; for(i=0; iga.PopSize; i++) if ( (pop+i)->evalfunc > cmax ) cmax = (pop+i)->evalfunc; cmax *= ctx->ga.FitnessCmaxValue; /* so worst string has nonzero fitness */ for(i=0;iga.PopSize;i++) (pop+i)->fitness = cmax - (pop+i)->evalfunc; PGADebugExited("PGAFitnessMinCmax"); } /*U**************************************************************************** PGASetFitnessCmaxValue - The value of the multiplier used by PGAFitnessMinCmax so that the worst string has a nonzero fitness. The default value is 1.01. Category: Fitness & Evaluation Inputs: ctx - context variable val - the value of the multiplier Outputs: None Example: PGAContext *ctx; : PGASetFitnessCmaxValue(ctx, 1.2); ****************************************************************************U*/ void PGASetFitnessCmaxValue( PGAContext *ctx, double val) { PGADebugEntered("PGASetFitnessCmaxValue"); ctx->ga.FitnessCmaxValue = val; PGADebugExited("PGASetFitnessCmaxValue"); } /*U*************************************************************************** PGAGetFitnessCmaxValue - returns the value of the multiplier used by PGAFitnessMinCmax. Category: Fitness & Evaluation Inputs: ctx - context variable Outputs: The value of Cmax used in Example: PGAContext *ctx; double cmax; : cmax = PGAGetFitnessCmaxValue(ctx); ***************************************************************************U*/ double PGAGetFitnessCmaxValue (PGAContext *ctx) { PGADebugEntered("PGAGetFitnessCmaxValue"); PGAFailIfNotSetUp("PGAGetFitnessType"); PGADebugExited("PGAGetFitnessCmaxValue"); return(ctx->ga.FitnessCmaxValue); } pgapack-1.1.1/source/report.c0000644000175000017500000011630610760674152014170 0ustar eddedd/* COPYRIGHT The following is a notice of limited availability of the code, and disclaimer which must be included in the prologue of the code and in all source listings of the code. (C) COPYRIGHT 2008 University of Chicago Permission is hereby granted to use, reproduce, prepare derivative works, and to redistribute to others. This software was authored by: D. Levine Mathematics and Computer Science Division Argonne National Laboratory Group with programming assistance of participants in Argonne National Laboratory's SERS program. GOVERNMENT LICENSE Portions of this material resulted from work developed under a U.S. Government Contract and are subject to the following license: the Government is granted for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide license in this computer software to reproduce, prepare derivative works, and perform publicly and display publicly. DISCLAIMER This computer code material was prepared, in part, as an account of work sponsored by an agency of the United States Government. Neither the United States, nor the University of Chicago, nor any of their employees, makes any warranty express or implied, or assumes any legal liability or responsibility for the accuracy, completeness, or usefulness of any information, apparatus, product, or process disclosed, or represents that its use would not infringe privately owned rights. */ /****************************************************************************** * FILE: report.c: This file contains functions for reporting on GA * parameters, and execution. * * Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle * Brian P. Walenz ******************************************************************************/ #include "pgapack.h" /*U**************************************************************************** PGAPrintReport - prints genetic algorithm statistics. The statistics that are printed are determined by PGASetPrintOptions(). Category: Reporting Inputs: ctx - context variable fp - file pointer to print the output to pop - symbolic constant of the population whose statistics are printed Outputs: genetic algorithm statistics are printed to fp Example: PGAContext *ctx; int p; : PGAPrintReport(ctx, stdout, PGA_NEWPOP); ****************************************************************************U*/ void PGAPrintReport(PGAContext *ctx, FILE *fp, int pop) { int p, best_p; double e, best_e; PGADebugEntered("PGAPrintReport"); /* * edd 07 Feb 2007 this prints unconditionally, so let's change it * WAS: if (ctx->ga.iter == 1) */ if ((ctx->rep.PrintFreq >=0) && !(ctx->ga.iter % ctx->rep.PrintFreq)) /* fprintf (fp, "Iter # Field Value Time\n"); */ fprintf (fp, "Iter # Field Value\n"); best_p = PGAGetBestIndex(ctx, pop); best_e = PGAGetEvaluation(ctx, best_p, pop); /* * edd 07 Feb 2007 this prints unconditionally, so let's change it * WAS: (!(ctx->ga.iter % ctx->rep.PrintFreq) || ctx->ga.iter == 1) */ if ((ctx->rep.PrintFreq >=0) && !(ctx->ga.iter % ctx->rep.PrintFreq)) { fprintf(fp, "%-11dBest %e\n", PGAGetGAIterValue(ctx), best_e); /* fprintf(fp, " %ld\n", time(NULL) - ctx->rep.starttime); */ if ((ctx->rep.PrintOptions & PGA_REPORT_WORST) == PGA_REPORT_WORST) { p = PGAGetWorstIndex(ctx, pop); e = PGAGetEvaluation(ctx, p, pop); fprintf(fp, " Worst %e\n", e); } if ((ctx->rep.PrintOptions & PGA_REPORT_AVERAGE) == PGA_REPORT_AVERAGE) fprintf(fp, " Average %e\n", ctx->rep.Average); if ((ctx->rep.PrintOptions & PGA_REPORT_OFFLINE) == PGA_REPORT_OFFLINE) fprintf(fp, " Offline %e\n", ctx->rep.Offline); if ((ctx->rep.PrintOptions & PGA_REPORT_ONLINE) == PGA_REPORT_ONLINE) fprintf(fp, " Online %e\n", ctx->rep.Online); if((ctx->rep.PrintOptions & PGA_REPORT_HAMMING) == PGA_REPORT_HAMMING) fprintf(fp, " Hamming %e\n", PGAHammingDistance(ctx, pop)); if ((ctx->rep.PrintOptions & PGA_REPORT_STRING) == PGA_REPORT_STRING) PGAPrintString(ctx, fp, best_p, pop); } fflush(fp); PGADebugExited("PGAPrintReport"); } /*U**************************************************************************** PGASetPrintOptions - set flags to indicate what GA statistics should be printed whenever output is printed. May be called more than once to specify different report options. Valid choices are PGA_REPORT_AVERAGE, PGA_REPORT_OFFLINE, PGA_REPORT_ONLINE, PGA_REPORT_WORST, PGA_REPORT_HAMMING, and PGA_REPORT_STRING to specify offline analysis, online analysis, the worst string in the population, the Hamming distance of the population, and the actual allele values of the best string. The best string is always printed. Category: Reporting Inputs: ctx - context variable option - symbolic constant to specify a print option Outputs: None Example: PGAContext *ctx; : PGASetPrintOptions(ctx, PGA_REPORT_WORST); ****************************************************************************U*/ void PGASetPrintOptions (PGAContext *ctx, int option) { PGADebugEntered("PGASetPrintOptions"); switch (option) { case PGA_REPORT_AVERAGE: case PGA_REPORT_OFFLINE: case PGA_REPORT_ONLINE: case PGA_REPORT_WORST: case PGA_REPORT_HAMMING: case PGA_REPORT_STRING: ctx->rep.PrintOptions |= option; break; default: PGAError (ctx, "PGASetPrintOption: Invalid value of option:", PGA_FATAL, PGA_INT, (void *) &option); break; } PGADebugExited("PGASetPrintOptions"); } /*U**************************************************************************** PGASetPrintFrequencyValue - Specifies the frequency with which genetic algorithm statistics are reported. The default is every 10 GA iterations. Used only if PGARun() is used to run the GA. Category: Reporting Inputs: ctx - context variable print_freq - the genetic algorithm population size to use Outputs: None Example: PGAContext *ctx; : PGASetPrintFrequencyValue(ctx,1); ****************************************************************************U*/ void PGASetPrintFrequencyValue( PGAContext *ctx, int print_freq) { PGADebugEntered("PGASetPrintFrequencyValue"); if (print_freq < 0) PGAError ( ctx, "PGASetPrintFrequencyValue: Invalid value of print_freq:", PGA_FATAL, PGA_INT, (void *) &print_freq); else ctx->rep.PrintFreq = print_freq; PGADebugExited("PGASetPrintFrequencyValue"); } /*U*************************************************************************** PGAGetPrintFrequencyValue - returns how often to print statistics reports Category: Reporting Inputs: ctx - context variable Outputs: The frequency of printing output Example: PGAContext *ctx; int freq; : freq = PGAGetPrintFrequencyValue(ctx); ***************************************************************************U*/ int PGAGetPrintFrequencyValue (PGAContext *ctx) { PGADebugEntered("PGAGetPrintFrequencyValue"); PGAFailIfNotSetUp("PGAGetPrintFrequencyValue"); PGADebugExited("PGAGetPrintFrequencyValue"); return(ctx->rep.PrintFreq); } /*U**************************************************************************** PGAPrintPopulation - Calls PGAPrintIndividual to print each member of a population Category: Reporting Inputs: ctx - context variable fp - file pointer to print the output to pop - symbolic constant of the population to be printed Outputs: The strings and associated fields that make up a population member are printed to fp. Example: PGAContext *ctx; : PGAPrintPopulation(ctx, stdout, PGA_NEWPOP); ****************************************************************************U*/ void PGAPrintPopulation ( PGAContext *ctx, FILE *fp, int pop ) { int i; PGADebugEntered("PGAPrintPopulation"); for ( i=0; i < ctx->ga.PopSize; i++ ) PGAPrintIndividual ( ctx, fp, i, pop ); fprintf(fp,"\n"); PGADebugExited("PGAPrintPopulation"); } /*U**************************************************************************** PGAPrintIndividual - prints the allele values of a string and associated fields (evaluation, fitness, etc.) of a string Category: Reporting Inputs: ctx - context variable fp - file pointer to print the output to p - string index pop - symbolic constant of the population string p is in Outputs: The allele values of string p and associated fields are printed to fp Example: PGAContext *ctx; int p; : PGAPrintIndividual(ctx, stdout, p, PGA_NEWPOP); ****************************************************************************U*/ void PGAPrintIndividual ( PGAContext *ctx, FILE *fp, int p, int pop ) { PGAIndividual *ind; PGADebugEntered("PGAPrintIndividual"); ind = PGAGetIndividual ( ctx, p, pop ); fprintf( fp,"%d %e %e ", p, ind->evalfunc, ind->fitness); if ( ind->evaluptodate ) fprintf( fp, "T\n" ); else fprintf( fp, "F\n" ); PGAPrintString ( ctx, fp, p, pop ); PGADebugExited("PGAPrintIndividual"); } /*U**************************************************************************** PGAPrintString - write the allele values in a string to a file Category: Reporting Inputs: ctx - context variable fp - pointer to file to write the string to p - index of the string to write out pop - symbolic constant of the population string p is in Outputs: None Example: PGAContext *ctx; int p; : PGAPrintString(ctx, stdout, p, PGA_OLDPOP); ****************************************************************************U*/ void PGAPrintString ( PGAContext *ctx, FILE *file, int p, int pop ) { int fp; PGADebugEntered("PGAPrintString"); PGADebugPrint( ctx, PGA_DEBUG_PRINTVAR,"PGAPrintString", "p = ", PGA_INT, (void *) &p ); PGADebugPrint( ctx, PGA_DEBUG_PRINTVAR,"PGAPrintString", "pop = ", PGA_INT, (void *) &pop ); if (ctx->fops.PrintString) { fp = ((p == PGA_TEMP1) || (p == PGA_TEMP2)) ? p : p+1; (*ctx->fops.PrintString)(&ctx, NULL, &fp, &pop); } else { (*ctx->cops.PrintString)(ctx, file, p, pop); } fprintf(file,"\n"); PGADebugExited("PGAPrintString"); } /*U**************************************************************************** PGAPrintContextVariable - prints the value of all the fields in the context variable. Category: Reporting Inputs: ctx - context variable fp - file pointer to print the output to Outputs: The value of all the fields in the context variable are printed to fp. Example: PGAContext *ctx; : PGAPrintContextVariable(ctx, stdout); ****************************************************************************U*/ void PGAPrintContextVariable ( PGAContext *ctx, FILE *fp ) { PGADebugEntered("PGAPrintContextVariable"); fprintf( fp,"Algorithm Parameters (Static)\n"); fprintf( fp," Data type : "); switch(ctx->ga.datatype) { case PGA_DATATYPE_BINARY: fprintf( fp,"Binary\n"); /*fprintf( fp," Bit Type Total Words : "); switch(ctx->ga.tw) { case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"%d\n",ctx->ga.tw); break; }; fprintf( fp," Bit Type Full Words : "); switch(ctx->ga.fw) { case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"%d\n",ctx->ga.fw); break; }; fprintf( fp," Bit Type Extra Bits : "); switch(ctx->ga.eb) { case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"%d\n",ctx->ga.eb); break; };*/ break; case PGA_DATATYPE_INTEGER: fprintf( fp,"Integer\n"); break; case PGA_DATATYPE_REAL: fprintf( fp,"Real\n"); break; case PGA_DATATYPE_CHARACTER: fprintf( fp,"Character\n"); break; case PGA_DATATYPE_USER: fprintf( fp,"User Defined\n"); break; case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"!ERROR! =(%d)?\n", ctx->ga.datatype); break; }; fprintf( fp," Optimization Direction : "); switch(ctx->ga.optdir) { case PGA_MAXIMIZE: fprintf( fp,"Maximize\n"); break; case PGA_MINIMIZE: fprintf( fp,"Minimize\n"); break; case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"!ERROR! =(%d)?\n", ctx->ga.optdir); break; }; fprintf( fp," Population Size : "); switch(ctx->ga.PopSize) { case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"%d\n",ctx->ga.PopSize); break; }; fprintf( fp," String Length : "); switch(ctx->ga.StringLen) { case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"%d\n",ctx->ga.StringLen); break; }; fprintf( fp," Copy to Next Population : "); switch(ctx->ga.PopReplace) { case PGA_POPREPL_BEST: fprintf( fp,"Best\n"); break; case PGA_POPREPL_RANDOM_NOREP: fprintf( fp,"Random without replacement\n"); break; case PGA_POPREPL_RANDOM_REP: fprintf( fp,"Random with replacement\n"); break; case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"!ERROR! =(%d)?\n", ctx->ga.PopReplace); break; }; /*fprintf( fp," Stopping Rule (s) :\n"); if ((ctx->ga.StoppingRule & PGA_STOP_MAXITER) == PGA_STOP_MAXITER) fprintf(fp, "%50s", "Maximum iterations\n"); if ((ctx->ga.StoppingRule & PGA_STOP_NOCHANGE) == PGA_STOP_NOCHANGE) fprintf(fp, "%49s", "No change in best\n"); if ((ctx->ga.StoppingRule & PGA_STOP_TOOSIMILAR) == PGA_STOP_TOOSIMILAR) fprintf(fp, "%54s", "Population Homogeneity\n"); if (ctx->ga.StoppingRule == PGA_UNINITIALIZED_INT) fprintf(fp, "%47s", "*UNINITIALIZED*\n");*/ fprintf( fp," Stop: Maximum Iterations : "); if ((ctx->ga.StoppingRule & PGA_STOP_MAXITER) == PGA_STOP_MAXITER) fprintf( fp,"On\n"); else fprintf( fp,"Off\n"); fprintf( fp," Maximum Iterations : "); switch(ctx->ga.MaxIter) { case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"%d\n",ctx->ga.MaxIter); break; }; fprintf( fp," Stop: No Change : "); if ((ctx->ga.StoppingRule & PGA_STOP_NOCHANGE) == PGA_STOP_NOCHANGE) fprintf( fp,"On\n"); else fprintf( fp,"Off\n"); fprintf(fp, " Max No Change Iterations : "); switch(ctx->ga.MaxNoChange) { case PGA_UNINITIALIZED_INT: fprintf(fp, "*UNINITIALIZED*\n"); break; default: fprintf(fp, "%d\n", ctx->ga.MaxNoChange); break; } fprintf( fp," Stop: Too Similar : "); if ((ctx->ga.StoppingRule & PGA_STOP_TOOSIMILAR) == PGA_STOP_TOOSIMILAR) fprintf( fp,"On\n"); else fprintf( fp,"Off\n"); fprintf(fp, " Percent Similarity : "); switch(ctx->ga.MaxSimilarity) { case PGA_UNINITIALIZED_INT: fprintf(fp, "*UNINITIALIZED*\n"); break; default: fprintf(fp, "%d\n", ctx->ga.MaxSimilarity); break; } fprintf( fp," No. Strings Replaced per Iter : "); switch(ctx->ga.NumReplace) { case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"%d\n",ctx->ga.NumReplace); break; }; fprintf( fp," Mutate [And,Or] Crossover : "); switch(ctx->ga.MutateOnlyNoCross) { case PGA_TRUE: fprintf( fp,"Or\n"); break; case PGA_FALSE: fprintf( fp,"And\n"); break; case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"!ERROR! =(%d)?\n", ctx->ga.MutateOnlyNoCross); break; }; fprintf( fp," Crossover Type : "); switch(ctx->ga.CrossoverType) { case PGA_CROSSOVER_ONEPT: fprintf( fp,"One Point\n"); break; case PGA_CROSSOVER_TWOPT: fprintf( fp,"Two Point\n"); break; case PGA_CROSSOVER_UNIFORM: fprintf( fp,"Uniform\n"); break; case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"!ERROR! =(%d)?\n", ctx->ga.CrossoverType); break; }; fprintf( fp," Crossover Probability : "); if (ctx->ga.CrossoverProb == PGA_UNINITIALIZED_DOUBLE) fprintf( fp,"*UNINITIALIZED*\n"); else fprintf( fp,"%f\n",ctx->ga.CrossoverProb); fprintf( fp," Uniform Crossover Prob. : "); if (ctx->ga.UniformCrossProb == PGA_UNINITIALIZED_DOUBLE) fprintf( fp,"*UNINITIALIZED*\n"); else fprintf( fp,"%f\n",ctx->ga.UniformCrossProb); fprintf( fp," Mutation Type : "); switch(ctx->ga.datatype) { case PGA_DATATYPE_BINARY: fprintf( fp,"Binary\n"); break; case PGA_DATATYPE_CHARACTER: fprintf( fp,"Character\n"); break; case PGA_DATATYPE_REAL: case PGA_DATATYPE_INTEGER: switch(ctx->ga.MutationType) { case PGA_MUTATION_CONSTANT: fprintf( fp,"Constant\n"); break; case PGA_MUTATION_RANGE: fprintf( fp,"Range\n"); break; case PGA_MUTATION_UNIFORM: fprintf( fp,"Uniform\n"); break; case PGA_MUTATION_GAUSSIAN: fprintf( fp,"Gaussian\n"); break; case PGA_MUTATION_PERMUTE: fprintf( fp,"Permutation\n"); break; case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"!ERROR! =(%d)?\n", ctx->ga.MutationType); break; }; default: break; }; fprintf( fp," Mutation Probability : "); if (ctx->ga.MutationProb == PGA_UNINITIALIZED_DOUBLE) fprintf( fp,"*UNINITIALIZED*\n"); else fprintf( fp,"%f\n",ctx->ga.MutationProb); fprintf( fp," Real Mutation Constant : "); if (ctx->ga.MutationProb == PGA_UNINITIALIZED_DOUBLE) fprintf( fp,"*UNINITIALIZED*\n"); else fprintf( fp,"%f\n",ctx->ga.MutateRealValue); fprintf(fp, " Integer Mutation Constant : "); switch(ctx->ga.MutateIntegerValue) { case PGA_UNINITIALIZED_INT: fprintf(fp, "*UNINITIALIZED*\n"); break; default: fprintf(fp, "%d\n", ctx->ga.MutateIntegerValue); break; } fprintf( fp," Mutation Range Bounded : "); switch(ctx->ga.MutateBoundedFlag) { case PGA_TRUE: fprintf( fp,"On\n"); break; case PGA_FALSE: fprintf( fp,"Off\n"); break; case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"!ERROR! =(%d)?\n", ctx->ga.MutateBoundedFlag); break; }; fprintf( fp," Selection Type : "); switch(ctx->ga.SelectType) { case PGA_SELECT_PROPORTIONAL: fprintf( fp,"Proportional\n"); break; case PGA_SELECT_SUS: fprintf( fp,"Stochastic Universal\n"); break; case PGA_SELECT_TOURNAMENT: fprintf( fp,"Binary Tournament\n"); break; case PGA_SELECT_PTOURNAMENT: fprintf( fp,"Probabilistic Binary Tournament\n"); break; case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"!ERROR! =(%d)?\n", ctx->ga.SelectType); break; }; fprintf( fp," Tournament Selection Param : "); if (ctx->ga.PTournamentProb == PGA_UNINITIALIZED_DOUBLE) fprintf( fp,"*UNINITIALIZED*\n"); else fprintf( fp,"%f\n",ctx->ga.PTournamentProb); fprintf( fp," Restart Operator : "); switch(ctx->ga.restart) { case PGA_TRUE: fprintf( fp,"On\n"); break; case PGA_FALSE: fprintf( fp,"Off\n"); break; case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"!ERROR! =(%d)?\n", ctx->ga.restart); break; }; fprintf( fp," Restart Frequency : "); switch(ctx->ga.restartFreq) { case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"%d\n",ctx->ga.restartFreq); break; }; fprintf( fp," Restart Allele Change Prob : "); if (ctx->ga.restartAlleleProb == PGA_UNINITIALIZED_DOUBLE) fprintf( fp,"*UNINITIALIZED*\n"); else fprintf( fp,"%f\n",ctx->ga.restartAlleleProb); fprintf( fp," Allow Duplicates : "); switch(ctx->ga.NoDuplicates) { case PGA_TRUE: fprintf( fp,"No\n"); break; case PGA_FALSE: fprintf( fp,"Yes\n"); break; case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"!ERROR! =(%d)?\n", ctx->ga.NoDuplicates); break; }; fprintf( fp," Fitness Type : "); switch(ctx->ga.FitnessType) { case PGA_FITNESS_RAW: fprintf( fp,"Raw\n"); break; case PGA_FITNESS_NORMAL: fprintf( fp,"Linear Normalization\n"); break; case PGA_FITNESS_RANKING: fprintf( fp,"Linear Ranking\n"); break; case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"!ERROR! =(%d)?\n", ctx->ga.FitnessType); break; }; if ( ctx->ga.optdir == PGA_MINIMIZE ) { fprintf( fp," Fitness Type(Minimization) : "); switch(ctx->ga.FitnessMinType) { case PGA_FITNESSMIN_RECIPROCAL: fprintf( fp,"Reciprocal\n"); break; case PGA_FITNESSMIN_CMAX: fprintf( fp,"CMax\n"); break; case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"!ERROR! =(%d)?\n", ctx->ga.FitnessMinType); break; }; } fprintf( fp," Fitness Ranking Parameter : "); if (ctx->ga.FitnessRankMax == PGA_UNINITIALIZED_DOUBLE) fprintf( fp,"*UNINITIALIZED*\n"); else fprintf( fp,"%f\n",ctx->ga.FitnessRankMax); fprintf( fp," Fitness CMAX Parameter : "); if (ctx->ga.FitnessCmaxValue == PGA_UNINITIALIZED_DOUBLE) fprintf( fp,"*UNINITIALIZED*\n"); else fprintf( fp,"%f\n",ctx->ga.FitnessCmaxValue); fprintf( fp,"Algorithm Parameters (Dynamic)\n"); fprintf( fp," Current Generation : "); switch(ctx->ga.iter) { case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"%d\n",ctx->ga.iter); break; }; fprintf(fp, " Num Iters With No Change : "); switch(ctx->ga.ItersOfSame) { case PGA_UNINITIALIZED_INT: fprintf(fp, "*UNINITIALIZED*\n"); break; default: fprintf(fp, "%d\n", ctx->ga.ItersOfSame); break; } fprintf(fp, " Percent Similarity In Pop : "); switch(ctx->ga.PercentSame) { case PGA_UNINITIALIZED_INT: fprintf(fp, "?UNINITIALZED?\n"); break; default: fprintf(fp, "%d\n", ctx->ga.PercentSame); break; } fprintf( fp," Selection Index : "); switch(ctx->ga.SelectIndex) { case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"%d\n",ctx->ga.SelectIndex); break; }; /* initialization */ fprintf( fp,"Initialization\n"); fprintf( fp," Random Initialization : "); switch(ctx->init.RandomInit) { case PGA_TRUE: fprintf( fp,"On\n"); break; case PGA_FALSE: fprintf( fp,"Off\n"); break; case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"!ERROR! =(%d)?\n", ctx->init.RandomInit); break; }; fprintf( fp," Initialization Binary Prob : "); if (ctx->init.BinaryProbability == PGA_UNINITIALIZED_DOUBLE) fprintf( fp,"*UNINITIALIZED*\n"); else fprintf( fp,"%f\n",ctx->init.BinaryProbability); fprintf( fp," Initialization Real : "); switch(ctx->init.RealType) { case PGA_RINIT_RANGE: fprintf( fp,"Range\n"); break; case PGA_RINIT_PERCENT: fprintf( fp,"Percent Offset\n"); break; case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"!ERROR! =(%d)?\n", ctx->init.RealType); break; }; fprintf( fp," Initialization Integer : "); switch(ctx->init.IntegerType) { case PGA_IINIT_RANGE: fprintf( fp,"Range\n"); break; case PGA_IINIT_PERMUTE: fprintf( fp,"Permutation\n"); break; case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"!ERROR! =(%d)?\n", ctx->init.IntegerType); break; }; fprintf( fp," Initialization Character : "); switch(ctx->init.CharacterType) { case PGA_CINIT_LOWER: fprintf( fp,"Lower Case\n"); break; case PGA_CINIT_UPPER: fprintf( fp,"Upper Case\n"); break; case PGA_CINIT_MIXED: fprintf( fp,"Mixed Case\n"); break; case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"!ERROR! =(%d)?\n", ctx->init.CharacterType); break; }; fprintf( fp," Random Number Seed : "); switch(ctx->init.RandomSeed) { case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"%d\n", ctx->init.RandomSeed); break; }; PGADebugExited("PGAPrintContextVariable"); /* par */ fprintf( fp,"Parallel\n"); fprintf( fp," MPI Library Used : "); switch(ctx->par.MPIStubLibrary) { case PGA_TRUE: fprintf( fp,"Sequential\n"); break; case PGA_FALSE: fprintf( fp,"Parallel\n"); break; default: fprintf( fp,"!ERROR! =(%d)?\n", ctx->par.MPIStubLibrary); break; }; fprintf( fp," MPI Initialized by PGAPack : "); switch(ctx->par.MPIAlreadyInit) { case PGA_TRUE: fprintf( fp,"Yes\n"); break; case PGA_FALSE: fprintf( fp,"No\n"); break; case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"!ERROR! =(%d)?\n", ctx->par.MPIAlreadyInit); break; }; /*fprintf(fp, " Number Islands : "); switch(ctx->par.NumIslands) { case PGA_UNINITIALIZED_INT: fprintf(fp, "*UNINITIALIZED*\n"); break; default: fprintf(fp, "%d\n", ctx->par.NumIslands); break; } fprintf(fp, " Number Demes : "); switch(ctx->par.NumDemes) { case PGA_UNINITIALIZED_INT: fprintf(fp, "*UNINITIALIZED*\n"); break; default: fprintf(fp, "%d\n", ctx->par.NumDemes); break; }*/ fprintf(fp, " Default Communicator : "); if (ctx->par.DefaultComm == NULL) fprintf(fp, "NULL\n"); else if (ctx->par.DefaultComm == MPI_COMM_WORLD) fprintf(fp, "MPI_COMM_WORLD\n"); else fprintf(fp, "User Defined\n"); /* report */ fprintf( fp,"Report\n"); fprintf( fp," Print Frequency : "); switch(ctx->rep.PrintFreq) { case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"%d\n",ctx->rep.PrintFreq); break; }; fprintf( fp," Print Worst Evaluation : "); if ((ctx->rep.PrintOptions & PGA_REPORT_WORST) == PGA_REPORT_WORST) fprintf( fp,"On\n"); else fprintf( fp,"Off\n"); fprintf( fp," Print Average Evaluation : "); if ((ctx->rep.PrintOptions & PGA_REPORT_AVERAGE) == PGA_REPORT_AVERAGE) fprintf( fp,"On\n"); else fprintf( fp,"Off\n"); fprintf( fp," Print Offline Statistics : "); if ((ctx->rep.PrintOptions & PGA_REPORT_OFFLINE) == PGA_REPORT_OFFLINE) fprintf( fp,"On\n"); else fprintf( fp,"Off\n"); fprintf( fp," Print Online Statistics : "); if ((ctx->rep.PrintOptions & PGA_REPORT_ONLINE) == PGA_REPORT_ONLINE) fprintf( fp,"On\n"); else fprintf( fp,"Off\n"); fprintf( fp," Print Hamming Distance : "); if ((ctx->rep.PrintOptions & PGA_REPORT_HAMMING) == PGA_REPORT_HAMMING) fprintf( fp,"On\n"); else fprintf( fp,"Off\n"); /* system */ fprintf( fp,"System\n"); fprintf( fp," Maximum Integer : "); switch(ctx->sys.PGAMaxInt) { case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"%d\n",ctx->sys.PGAMaxInt); break; }; fprintf( fp," Minimum Integer : "); switch(ctx->sys.PGAMinInt) { case PGA_UNINITIALIZED_INT: fprintf( fp,"*UNINITIALIZED*\n"); break; default: fprintf( fp,"%d\n",ctx->sys.PGAMinInt); break; }; fprintf( fp," Maximum Double : "); if (ctx->sys.PGAMaxDouble == PGA_UNINITIALIZED_DOUBLE) fprintf( fp,"*UNINITIALIZED*\n"); else fprintf( fp,"%e\n",ctx->sys.PGAMaxDouble); fprintf( fp," Minimum Double : "); if (ctx->sys.PGAMinDouble == PGA_UNINITIALIZED_DOUBLE) fprintf( fp,"*UNINITIALIZED*\n"); else fprintf( fp,"%e\n",ctx->sys.PGAMinDouble); /* ops */ fprintf( fp,"Operations\n"); fprintf( fp," CreateString function : "); if (ctx->cops.CreateString == NULL) fprintf( fp,"NULL\n"); else if (ctx->cops.CreateString == PGABinaryCreateString) fprintf( fp,"PGABinaryCreateString\n"); else if (ctx->cops.CreateString == PGAIntegerCreateString) fprintf( fp,"PGAIntegerCreateString\n"); else if (ctx->cops.CreateString == PGARealCreateString) fprintf( fp,"PGARealCreateString\n"); else if (ctx->cops.CreateString == PGACharacterCreateString) fprintf( fp,"PGACharacterCreateString\n"); else fprintf( fp,"C User Defined: %p\n",ctx->cops.CreateString); fprintf( fp," InitString function : "); if (ctx->cops.InitString) { if (ctx->cops.InitString == PGABinaryInitString) fprintf( fp,"PGABinaryInitString\n"); else if (ctx->cops.InitString == PGAIntegerInitString) fprintf( fp,"PGAIntegerInitString\n"); else if (ctx->cops.InitString == PGARealInitString) fprintf( fp,"PGARealInitString\n"); else if (ctx->cops.InitString == PGACharacterInitString) fprintf( fp,"PGACharacterInitString\n"); else fprintf( fp,"C User Defined: %p\n",ctx->cops.InitString); } else { if (ctx->fops.InitString) fprintf( fp,"Fortran User Defined: %p\n",ctx->fops.InitString); else fprintf( fp,"NULL\n"); } fprintf( fp," BuildDatatype function : "); if (ctx->cops.BuildDatatype == NULL) fprintf( fp,"NULL\n"); else if (ctx->cops.BuildDatatype == PGABinaryBuildDatatype) fprintf( fp,"PGABinaryBuildDatatype\n"); else if (ctx->cops.BuildDatatype == PGAIntegerBuildDatatype) fprintf( fp,"PGAIntegerBuildDatatype\n"); else if (ctx->cops.BuildDatatype == PGARealBuildDatatype) fprintf( fp,"PGARealBuildDatatype\n"); else if (ctx->cops.BuildDatatype == PGACharacterBuildDatatype) fprintf( fp,"PGACharacterBuildDatatype\n"); else fprintf( fp,"C User Defined: %p\n",ctx->cops.BuildDatatype); fprintf( fp," Mutation function : "); if (ctx->cops.Mutation) { if (ctx->cops.Mutation == PGABinaryMutation) fprintf( fp,"PGABinaryMutation\n"); else if (ctx->cops.Mutation == PGAIntegerMutation) fprintf( fp,"PGAIntegerMutation\n"); else if (ctx->cops.Mutation == PGARealMutation) fprintf( fp,"PGARealMutation\n"); else if (ctx->cops.Mutation == PGACharacterMutation) fprintf( fp,"PGACharacterMutation\n"); else fprintf( fp,"C User Defined: %p\n",ctx->cops.Mutation); } else { if (ctx->fops.Mutation) fprintf( fp,"Fortran User Defined: %p\n",ctx->fops.Mutation); else fprintf( fp,"NULL\n"); } fprintf( fp," Crossover function : "); if (ctx->cops.Crossover) { if (ctx->cops.Crossover == PGABinaryOneptCrossover) fprintf( fp,"PGABinaryOneptCrossover\n"); else if (ctx->cops.Crossover == PGAIntegerOneptCrossover) fprintf( fp,"PGAIntegerOneptCrossover\n"); else if (ctx->cops.Crossover == PGARealOneptCrossover) fprintf( fp,"PGARealOneptCrossover\n"); else if (ctx->cops.Crossover == PGACharacterOneptCrossover) fprintf( fp,"PGACharacterOneptCrossover\n"); else if (ctx->cops.Crossover == PGABinaryTwoptCrossover) fprintf( fp,"PGABinaryTwoptCrossover\n"); else if (ctx->cops.Crossover == PGAIntegerTwoptCrossover) fprintf( fp,"PGAIntegerTwoptCrossover\n"); else if (ctx->cops.Crossover == PGARealTwoptCrossover) fprintf( fp,"PGARealTwoptCrossover\n"); else if (ctx->cops.Crossover == PGACharacterTwoptCrossover) fprintf( fp,"PGACharacterTwoptCrossover\n"); else if (ctx->cops.Crossover == PGABinaryUniformCrossover) fprintf( fp,"PGABinarytUniformCrossover\n"); else if (ctx->cops.Crossover == PGAIntegerUniformCrossover) fprintf( fp,"PGAIntegerUniformCrossover\n"); else if (ctx->cops.Crossover == PGARealUniformCrossover) fprintf( fp,"PGARealUniformCrossover\n"); else if (ctx->cops.Crossover == PGACharacterUniformCrossover) fprintf( fp,"PGACharacterUniformCrossover\n"); else fprintf( fp,"C User Defined: %p\n",ctx->cops.Crossover); } else { if (ctx->fops.Crossover) fprintf( fp,"Fortran User Defined: %p\n",ctx->fops.Crossover); else fprintf( fp,"NULL\n"); } fprintf( fp," PrintString function : "); if (ctx->cops.PrintString) { if (ctx->cops.PrintString == PGABinaryPrintString) fprintf( fp,"PGABinaryPrintString\n"); else if (ctx->cops.PrintString == PGAIntegerPrintString) fprintf( fp,"PGAIntegerPrintString\n"); else if (ctx->cops.PrintString == PGARealPrintString) fprintf( fp,"PGARealPrintString\n"); else if (ctx->cops.PrintString == PGACharacterPrintString) fprintf( fp,"PGACharacterPrintString\n"); else fprintf( fp,"C User Defined: %p\n",ctx->cops.PrintString); } else { if (ctx->fops.PrintString) fprintf( fp,"Fortran User Defined: %p\n",ctx->fops.PrintString); else fprintf( fp,"NULL\n"); } fprintf( fp," CopyString function : "); if (ctx->cops.CopyString) { if (ctx->cops.CopyString == PGABinaryCopyString) fprintf( fp,"PGABinaryCopyString\n"); else if (ctx->cops.CopyString == PGAIntegerCopyString) fprintf( fp,"PGAIntegerCopyString\n"); else if (ctx->cops.CopyString == PGARealCopyString) fprintf( fp,"PGARealCopyString\n"); else if (ctx->cops.CopyString == PGACharacterCopyString) fprintf( fp,"PGACharacterCopyString\n"); else fprintf( fp,"C User Defined: %p\n",ctx->cops.CopyString); } else { if (ctx->cops.CopyString) fprintf( fp,"Fortran User Defined: %p\n",ctx->fops.CopyString); else fprintf( fp,"NULL\n"); } fprintf( fp," Duplicate function : "); if (ctx->cops.Duplicate) { if (ctx->cops.Duplicate == PGABinaryDuplicate) fprintf( fp,"PGABinaryDuplicate\n"); else if (ctx->cops.Duplicate == PGAIntegerDuplicate) fprintf( fp,"PGAIntegerDuplicate\n"); else if (ctx->cops.Duplicate == PGARealDuplicate) fprintf( fp,"PGARealDuplicate\n"); else if (ctx->cops.Duplicate == PGACharacterDuplicate) fprintf( fp,"PGACharacterDuplicate\n"); else fprintf( fp,"C User Defined: %p\n",ctx->cops.Duplicate); } else { if (ctx->fops.Duplicate) fprintf( fp,"Fortran User Defined: %p\n",ctx->fops.Duplicate); else fprintf( fp,"NULL\n"); } fprintf( fp," Stopping function : "); if (ctx->cops.StopCond) fprintf( fp,"C User Defined: %p\n",ctx->cops.StopCond); else if (ctx->fops.StopCond) fprintf( fp,"Fortran User Defined: %p\n",ctx->fops.StopCond); else fprintf( fp,"PGACheckStoppingConditions\n"); fprintf( fp," End of Generation function : "); if (ctx->cops.EndOfGen) fprintf( fp,"C User Defined: %p\n",ctx->cops.EndOfGen); else if (ctx->cops.EndOfGen) fprintf( fp,"Fortran User Defined: %p\n",ctx->fops.EndOfGen); else fprintf( fp,"NULL\n"); } pgapack-1.1.1/source/create.c0000644000175000017500000010145610760673731014122 0ustar eddedd/* 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: create.c: This file contains functions to create and initialize * data structures and populations. * * Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle, * Brian P. Walenz *****************************************************************************/ #include "pgapack.h" /*U**************************************************************************** PGACreate - creates an uninitialized context variable. The Fortran version of this function call contains only the last three arguments Category: Generation Inputs: argc - address of the count of the number of command line arguments. argv - array of command line arguments. datatype - the data type used for the strings. Must be one of PGA_DATATYPE_BINARY, PGA_DATATYPE_CHARACTER, PGA_DATATYPE_INTEGER, PGA_DATATYPE_REAL, or PGA_DATATYPE_USER to specify binary-valued, character-valued, integer-valued, real-valued, or a user-defined datatype, respectively. len - the string length (number of genes). maxormin - the direction of optimization. Must be one of PGA_MAXIMIZE or PGA_MINIMIZE for maximization or minimization, respectively. Outputs: A pointer to the context variable. Example: In C: void main(int argc, char **argv) { PGAContext *ctx; : ctx = PGACreate(&argc, argv, PGA_DATATYPE_BINARY, 100, PGA_MAXIMIZE); : // Set options here : PGASetUp(ctx); : // Run the GA here : PGADestroy(ctx); } In FORTRAN: integer ctx : ctx = PGACreate(PGA_DATATYPE_BINARY, 100, PGA_MAXIMIZE) : c Set options here : call PGASetUp(ctx) : c Run the GA here : call PGADestroy(ctx) stop end ****************************************************************************U*/ PGAContext *PGACreate ( int *argc, char **argv, int datatype, int len, int maxormin ) { int i; PGAContext *ctx; ctx = (PGAContext *) malloc ( sizeof(PGAContext) ); /* We cannot make PGA calls until we sort the FuncNameIndex below, * so we just manually print the (rather severe) error message. */ if( ctx == NULL ) { fprintf(stderr, "PGACreate: No room to allocate ctx\n"); exit(-1); } /* We use this (indirectly) in PGAReadCmdLine -- in processing * -pgahelp and -pgahelp debug. */ MPI_Initialized (&ctx->par.MPIAlreadyInit); /* Initialize MPI, only if it isn't already running (fortran) */ if (!ctx->par.MPIAlreadyInit) MPI_Init (argc, &argv); #if OPTIMIZE==0 /* Sort the FuncNameIndex. This allows us to use a binary search * for finding the function names. */ PGASortFuncNameIndex(ctx); #endif /* Initialize debug flags, then parse command line arguments. */ for (i=0; idebug.PGADebugFlags[i] = PGA_FALSE; PGAReadCmdLine( ctx, argc, argv ); /* The context variable is now initialized enough to allow this * call to complete successfully. */ PGADebugEntered("PGACreate"); /* required parameter 1: abstract data type */ switch (datatype) { case PGA_DATATYPE_BINARY: case PGA_DATATYPE_INTEGER: case PGA_DATATYPE_REAL: case PGA_DATATYPE_CHARACTER: case PGA_DATATYPE_USER: ctx->ga.datatype = datatype; break; default: PGAError( ctx, "PGACreate: Invalid value of datatype:", PGA_FATAL, PGA_INT, (void *) &datatype ); }; /* required parameter 2: string string length */ if (len <= 1) PGAError( ctx, "PGACreate: Invalid value of len:", PGA_FATAL, PGA_INT, (void *) &len ); else ctx->ga.StringLen = len; /* required parameter 3: optimization direction */ switch (maxormin) { case PGA_MAXIMIZE: case PGA_MINIMIZE: ctx->ga.optdir = maxormin; break; default: PGAError( ctx, "PGACreate: Invalid value of optdir:", PGA_FATAL, PGA_INT, (void *) &maxormin ); }; /* For datatype == PGA_DATATYPE_BINARY, set how many full words * are used in the packed representation, and how many extra bits * this leaves us with. Finally, set how many total words are used; * if there are no extra bits, this is just the number of full words, * else, there is one more word used than the number of full words. */ switch (datatype) { case PGA_DATATYPE_BINARY: ctx->ga.fw = ctx->ga.StringLen/WL; ctx->ga.eb = ctx->ga.StringLen%WL; if ( ctx->ga.eb == 0 ) ctx->ga.tw = ctx->ga.fw; else ctx->ga.tw = ctx->ga.fw+1; break; default: ctx->ga.fw = PGA_UNINITIALIZED_INT; ctx->ga.eb = PGA_UNINITIALIZED_INT; ctx->ga.tw = PGA_UNINITIALIZED_INT; break; } /* Clear all the setting. Later on, PGASetUp() will be called, and then * it will notice which setting are uninitialized, and set them to the * default value. */ ctx->ga.PopSize = PGA_UNINITIALIZED_INT; ctx->ga.StoppingRule = PGA_STOP_MAXITER; ctx->ga.MaxIter = PGA_UNINITIALIZED_INT; ctx->ga.MaxNoChange = PGA_UNINITIALIZED_INT; ctx->ga.MaxSimilarity = PGA_UNINITIALIZED_INT; ctx->ga.NumReplace = PGA_UNINITIALIZED_INT; ctx->ga.CrossoverType = PGA_UNINITIALIZED_INT; ctx->ga.SelectType = PGA_UNINITIALIZED_INT; ctx->ga.FitnessType = PGA_UNINITIALIZED_INT; ctx->ga.FitnessMinType = PGA_UNINITIALIZED_INT; ctx->ga.MutationType = PGA_UNINITIALIZED_INT; ctx->ga.MutateOnlyNoCross = PGA_UNINITIALIZED_INT; ctx->ga.MutateRealValue = PGA_UNINITIALIZED_DOUBLE; ctx->ga.MutateIntegerValue = PGA_UNINITIALIZED_INT; ctx->ga.MutateBoundedFlag = PGA_UNINITIALIZED_INT; ctx->ga.NoDuplicates = PGA_UNINITIALIZED_INT; ctx->ga.MutationProb = PGA_UNINITIALIZED_DOUBLE; ctx->ga.CrossoverProb = PGA_UNINITIALIZED_DOUBLE; ctx->ga.UniformCrossProb = PGA_UNINITIALIZED_DOUBLE; ctx->ga.PTournamentProb = PGA_UNINITIALIZED_DOUBLE; ctx->ga.FitnessRankMax = PGA_UNINITIALIZED_DOUBLE; ctx->ga.FitnessCmaxValue = PGA_UNINITIALIZED_DOUBLE; ctx->ga.PopReplace = PGA_UNINITIALIZED_INT; ctx->ga.iter = 0; ctx->ga.ItersOfSame = 0; ctx->ga.PercentSame = 0; ctx->ga.selected = NULL; ctx->ga.SelectIndex = 0; ctx->ga.restart = PGA_UNINITIALIZED_INT; ctx->ga.restartFreq = PGA_UNINITIALIZED_INT; ctx->ga.restartAlleleProb = PGA_UNINITIALIZED_DOUBLE; /* Operations */ ctx->cops.CreateString = NULL; ctx->cops.Mutation = NULL; ctx->cops.Crossover = NULL; ctx->cops.PrintString = NULL; ctx->cops.CopyString = NULL; ctx->cops.Duplicate = NULL; ctx->cops.InitString = NULL; ctx->cops.BuildDatatype = NULL; ctx->cops.StopCond = NULL; ctx->cops.EndOfGen = NULL; ctx->fops.Mutation = NULL; ctx->fops.Crossover = NULL; ctx->fops.PrintString = NULL; ctx->fops.CopyString = NULL; ctx->fops.Duplicate = NULL; ctx->fops.InitString = NULL; ctx->fops.StopCond = NULL; ctx->fops.EndOfGen = NULL; /* Parallel */ ctx->par.NumIslands = PGA_UNINITIALIZED_INT; ctx->par.NumDemes = PGA_UNINITIALIZED_INT; ctx->par.DefaultComm = NULL; #ifdef FAKE_MPI ctx->par.MPIStubLibrary = PGA_TRUE; #else ctx->par.MPIStubLibrary = PGA_FALSE; #endif /* Reporting */ ctx->rep.PrintFreq = PGA_UNINITIALIZED_INT; ctx->rep.PrintOptions = 0; ctx->rep.Online = 0; ctx->rep.Offline = 0; ctx->rep.Best = PGA_UNINITIALIZED_DOUBLE; ctx->rep.starttime = PGA_UNINITIALIZED_INT; /* System * * If ctx->sys.UserFortran is not set to PGA_TRUE in pgacreate_ (the * fortran stub to PGACreate), the user program is in C. */ if (ctx->sys.UserFortran != PGA_TRUE) ctx->sys.UserFortran = PGA_FALSE; ctx->sys.SetUpCalled = PGA_FALSE; ctx->sys.PGAMaxInt = INT_MAX; ctx->sys.PGAMinInt = INT_MIN; ctx->sys.PGAMaxDouble = DBL_MAX; ctx->sys.PGAMinDouble = DBL_MIN; /* Debug */ /* Set above before parsing command line arguments */ /* Initialization */ ctx->init.RandomInit = PGA_UNINITIALIZED_INT; ctx->init.BinaryProbability = PGA_UNINITIALIZED_DOUBLE; ctx->init.RealType = PGA_UNINITIALIZED_INT; ctx->init.IntegerType = PGA_UNINITIALIZED_INT; ctx->init.CharacterType = PGA_UNINITIALIZED_INT; ctx->init.RandomSeed = PGA_UNINITIALIZED_INT; /* Allocate and clear arrays to define the minimum and maximum values * allowed by integer and real datatypes. */ switch (datatype) { case PGA_DATATYPE_INTEGER: ctx->init.IntegerMax = (int *) malloc(len * sizeof(PGAInteger)); if (!ctx->init.IntegerMax) PGAError(ctx, "PGACreate: No room to allocate:", PGA_FATAL, PGA_CHAR, (void *) "ctx->init.IntegerMax"); ctx->init.IntegerMin = (int *) malloc(len * sizeof(PGAInteger)); if (!ctx->init.IntegerMin) PGAError(ctx, "PGACreate: No room to allocate:", PGA_FATAL, PGA_CHAR, (void *) "ctx->init.IntegerMin"); ctx->init.RealMax = NULL; ctx->init.RealMin = NULL; for (i = 0; i < len; i++) { ctx->init.IntegerMin[i] = PGA_UNINITIALIZED_INT; ctx->init.IntegerMax[i] = PGA_UNINITIALIZED_INT; } break; case PGA_DATATYPE_REAL: ctx->init.RealMax = (PGAReal *) malloc(len * sizeof(PGAReal)); if (!ctx->init.RealMax) PGAError(ctx, "PGACreate: No room to allocate:", PGA_FATAL, PGA_CHAR, (void *) "ctx->init.RealMax"); ctx->init.RealMin = (PGAReal *) malloc(len * sizeof(PGAReal)); if (!ctx->init.RealMin) PGAError(ctx, "PGACreate: No room to allocate:", PGA_FATAL, PGA_CHAR, (void *) "ctx->init.RealMin"); ctx->init.IntegerMax = NULL; ctx->init.IntegerMin = NULL; for (i = 0; i < len; i++) { ctx->init.RealMin[i] = PGA_UNINITIALIZED_DOUBLE; ctx->init.RealMax[i] = PGA_UNINITIALIZED_DOUBLE; } break; default: ctx->init.RealMax = NULL; ctx->init.RealMin = NULL; ctx->init.IntegerMax = NULL; ctx->init.IntegerMin = NULL; break; } PGADebugExited("PGACreate"); return(ctx); } /*U**************************************************************************** PGASetUp - set all uninitialized variables to default values and initialize some internal arrays. Must be called after PGACreate() and before the GA is started. Category: Generation Inputs: ctx - context variable Outputs: Uninitialized values in the context variable are set to defaults, and set values are checked for legality. Example: PGAContext *ctx; : PGACreate(ctx, ...); : // Set options here : PGASetUp(ctx); ****************************************************************************U*/ void PGASetUp ( PGAContext *ctx ) { /* These are for temporary storage of datatype specific functions. * They allow some (understatement of the yesr!!) cleaning of the * code below. */ void (*CreateString)(PGAContext *, int, int, int); int (*Mutation)(PGAContext *, int, int, double); void (*Crossover)(PGAContext *, int, int, int, int, int, int); void (*PrintString)(PGAContext *, FILE *, int, int); void (*CopyString)(PGAContext *, int, int, int, int); int (*Duplicate)(PGAContext *, int, int, int, int); void (*InitString)(PGAContext *, int, int); MPI_Datatype (*BuildDatatype)(PGAContext *, int, int); int err=0, i; PGADebugEntered("PGASetUp"); PGAFailIfSetUp("PGASetUp"); ctx->sys.SetUpCalled = PGA_TRUE; if ( ctx->ga.datatype == PGA_DATATYPE_BINARY && ctx->ga.tw == PGA_UNINITIALIZED_INT ) PGAError( ctx, "PGASetUp: Binary: Total Words (ctx->ga.tw) == UNINITIALIZED?", PGA_FATAL, PGA_INT, (void *) &ctx->ga.tw ); if ( ctx->ga.datatype == PGA_DATATYPE_BINARY && ctx->ga.fw == PGA_UNINITIALIZED_INT ) PGAError( ctx, "PGASetUp: Binary: Full Words (ctx->ga.fw) == UNINITIALIZED?", PGA_FATAL, PGA_INT, (void *) &ctx->ga.fw ); if ( ctx->ga.datatype == PGA_DATATYPE_BINARY && ctx->ga.eb == PGA_UNINITIALIZED_INT ) PGAError( ctx, "PGASetUp: Binary: Empty Bits (ctx->ga.eb) == UNINITIALIZED?", PGA_FATAL, PGA_INT, (void *) &ctx->ga.eb ); if ( ctx->ga.PopSize == PGA_UNINITIALIZED_INT) ctx->ga.PopSize = 100; if ( ctx->ga.MaxIter == PGA_UNINITIALIZED_INT) ctx->ga.MaxIter = 1000; if ( ctx->ga.MaxNoChange == PGA_UNINITIALIZED_INT) ctx->ga.MaxNoChange = 100; if ( ctx->ga.MaxSimilarity == PGA_UNINITIALIZED_INT) ctx->ga.MaxSimilarity = 95; if ( ctx->ga.NumReplace == PGA_UNINITIALIZED_INT) ctx->ga.NumReplace = (int) ceil(ctx->ga.PopSize * 0.1); if ( ctx->ga.NumReplace > ctx->ga.PopSize) PGAError(ctx, "PGASetUp: NumReplace > PopSize", PGA_FATAL, PGA_VOID, NULL); if ( ctx->ga.CrossoverType == PGA_UNINITIALIZED_INT) ctx->ga.CrossoverType = PGA_CROSSOVER_TWOPT; if (ctx->ga.CrossoverType == PGA_CROSSOVER_TWOPT && ctx->ga.StringLen == 2) PGAError(ctx, "PGASetUp: Invalid Crossover type for string of length " "2", PGA_FATAL, PGA_INT, (void *) &ctx->ga.CrossoverType); if ( ctx->ga.SelectType == PGA_UNINITIALIZED_INT) ctx->ga.SelectType = PGA_SELECT_TOURNAMENT; if ( ctx->ga.FitnessType == PGA_UNINITIALIZED_INT) ctx->ga.FitnessType = PGA_FITNESS_RAW; if ( ctx->ga.FitnessMinType == PGA_UNINITIALIZED_INT) ctx->ga.FitnessMinType = PGA_FITNESSMIN_CMAX; if ( ctx->ga.MutateOnlyNoCross == PGA_UNINITIALIZED_INT) ctx->ga.MutateOnlyNoCross = PGA_TRUE; if ( ctx->ga.MutationProb == PGA_UNINITIALIZED_DOUBLE) ctx->ga.MutationProb = 1. / ctx->ga.StringLen; if ( ctx->ga.MutationType == PGA_UNINITIALIZED_INT) { switch (ctx->ga.datatype) { case PGA_DATATYPE_BINARY: case PGA_DATATYPE_CHARACTER: case PGA_DATATYPE_USER: /* leave PGA_UNINITIALIZED_INT for these data types */ break; case PGA_DATATYPE_REAL: ctx->ga.MutationType = PGA_MUTATION_GAUSSIAN; break; case PGA_DATATYPE_INTEGER: switch (ctx->init.IntegerType) { case PGA_UNINITIALIZED_INT: case PGA_IINIT_PERMUTE: ctx->ga.MutationType = PGA_MUTATION_PERMUTE; break; case PGA_IINIT_RANGE: ctx->ga.MutationType = PGA_MUTATION_RANGE; break; } break; default: PGAError( ctx, "PGASetup: Invalid value of ctx->ga.datatype:", PGA_FATAL, PGA_INT, (void *) &(ctx->ga.datatype) ); } } if (ctx->ga.MutateRealValue == PGA_UNINITIALIZED_DOUBLE) { switch (ctx->ga.MutationType) { case PGA_MUTATION_GAUSSIAN: ctx->ga.MutateRealValue = 0.1; break; case PGA_MUTATION_UNIFORM: ctx->ga.MutateRealValue = 0.1; break; case PGA_MUTATION_CONSTANT: ctx->ga.MutateRealValue = 0.01; break; case PGA_MUTATION_RANGE: default: ctx->ga.MutateRealValue = 0.0; } } if ( ctx->ga.MutateIntegerValue == PGA_UNINITIALIZED_INT) ctx->ga.MutateIntegerValue = 1; if ( ctx->ga.MutateBoundedFlag == PGA_UNINITIALIZED_INT) ctx->ga.MutateBoundedFlag = PGA_FALSE; if ( ctx->ga.NoDuplicates == PGA_UNINITIALIZED_INT) ctx->ga.NoDuplicates = PGA_FALSE; if ( ctx->ga.NoDuplicates && ((ctx->ga.StoppingRule & PGA_STOP_TOOSIMILAR) == PGA_STOP_TOOSIMILAR)) PGAError(ctx, "PGASetUp: No Duplicates inconsistent with Stopping " "Rule:", PGA_FATAL, PGA_INT, (void *) &ctx->ga.StoppingRule); if ( ctx->ga.CrossoverProb == PGA_UNINITIALIZED_DOUBLE) ctx->ga.CrossoverProb = 0.85; if ( ctx->ga.UniformCrossProb == PGA_UNINITIALIZED_DOUBLE) ctx->ga.UniformCrossProb = 0.6; if ( ctx->ga.PTournamentProb == PGA_UNINITIALIZED_DOUBLE) ctx->ga.PTournamentProb = 0.6; if ( ctx->ga.FitnessRankMax == PGA_UNINITIALIZED_DOUBLE) ctx->ga.FitnessRankMax = 1.2; if ( ctx->ga.FitnessCmaxValue == PGA_UNINITIALIZED_DOUBLE) ctx->ga.FitnessCmaxValue = 1.01; if ( ctx->ga.PopReplace == PGA_UNINITIALIZED_INT) ctx->ga.PopReplace = PGA_POPREPL_BEST; if ( ctx->ga.restart == PGA_UNINITIALIZED_INT) ctx->ga.restart = PGA_FALSE; if ( ctx->ga.restartFreq == PGA_UNINITIALIZED_INT) ctx->ga.restartFreq = 50; if ( ctx->ga.restartAlleleProb == PGA_UNINITIALIZED_DOUBLE) ctx->ga.restartAlleleProb = 0.5; /* ops */ /* If no user supplied "done" function, use the built in one. * No need to check EndOfGen; they only get called if they * are defined. */ if (((void *)ctx->cops.StopCond == (void *)PGADone) || ((void *)ctx->fops.StopCond == (void *)PGADone)) PGAError( ctx, "PGASetUp: Using PGADone as the user stopping condition will" " result in an infinite loop!", PGA_FATAL, PGA_VOID, NULL); switch (ctx->ga.datatype) { case PGA_DATATYPE_BINARY: CreateString = PGABinaryCreateString; BuildDatatype = PGABinaryBuildDatatype; Mutation = PGABinaryMutation; switch (ctx->ga.CrossoverType) { case PGA_CROSSOVER_ONEPT: Crossover = PGABinaryOneptCrossover; break; case PGA_CROSSOVER_TWOPT: Crossover = PGABinaryTwoptCrossover; break; case PGA_CROSSOVER_UNIFORM: Crossover = PGABinaryUniformCrossover; break; } PrintString = PGABinaryPrintString; CopyString = PGABinaryCopyString; Duplicate = PGABinaryDuplicate; InitString = PGABinaryInitString; break; case PGA_DATATYPE_INTEGER: CreateString = PGAIntegerCreateString; BuildDatatype = PGAIntegerBuildDatatype; Mutation = PGAIntegerMutation; switch (ctx->ga.CrossoverType) { case PGA_CROSSOVER_ONEPT: Crossover = PGAIntegerOneptCrossover; break; case PGA_CROSSOVER_TWOPT: Crossover = PGAIntegerTwoptCrossover; break; case PGA_CROSSOVER_UNIFORM: Crossover = PGAIntegerUniformCrossover; break; } PrintString = PGAIntegerPrintString; CopyString = PGAIntegerCopyString; Duplicate = PGAIntegerDuplicate; InitString = PGAIntegerInitString; break; case PGA_DATATYPE_REAL: CreateString = PGARealCreateString; BuildDatatype = PGARealBuildDatatype; Mutation = PGARealMutation; switch (ctx->ga.CrossoverType) { case PGA_CROSSOVER_ONEPT: Crossover = PGARealOneptCrossover; break; case PGA_CROSSOVER_TWOPT: Crossover = PGARealTwoptCrossover; break; case PGA_CROSSOVER_UNIFORM: Crossover = PGARealUniformCrossover; break; } PrintString = PGARealPrintString; CopyString = PGARealCopyString; Duplicate = PGARealDuplicate; InitString = PGARealInitString; break; case PGA_DATATYPE_CHARACTER: CreateString = PGACharacterCreateString; BuildDatatype = PGACharacterBuildDatatype; Mutation = PGACharacterMutation; switch (ctx->ga.CrossoverType) { case PGA_CROSSOVER_ONEPT: Crossover = PGACharacterOneptCrossover; break; case PGA_CROSSOVER_TWOPT: Crossover = PGACharacterTwoptCrossover; break; case PGA_CROSSOVER_UNIFORM: Crossover = PGACharacterUniformCrossover; break; } PrintString = PGACharacterPrintString; CopyString = PGACharacterCopyString; Duplicate = PGACharacterDuplicate; InitString = PGACharacterInitString; break; case PGA_DATATYPE_USER: if (ctx->cops.CreateString == NULL) PGAError( ctx, "PGASetUp: User datatype needs CreateString function:", PGA_WARNING, PGA_INT, (void *) &err ); if (ctx->cops.Mutation == NULL) PGAError( ctx, "PGASetUp: User datatype needs Mutation function:", PGA_WARNING, PGA_INT, (void *) &err ); if (ctx->cops.Crossover == NULL) PGAError( ctx, "PGASetUp: User datatype needs Crossover function:", PGA_WARNING, PGA_INT, (void *) &err ); if (ctx->cops.PrintString == NULL) PGAError( ctx, "PGASetUp: User datatype needs PrintString function:", PGA_WARNING, PGA_INT, (void *) &err ); if (ctx->cops.Duplicate == NULL) PGAError( ctx, "PGASetUp: User datatype needs Duplicate function:", PGA_WARNING, PGA_INT, (void *) &err ); if (ctx->cops.CopyString == NULL) PGAError( ctx, "PGASetUp: User datatype needs CopyString function:", PGA_WARNING, PGA_INT, (void *) &err ); if (ctx->cops.BuildDatatype == NULL) PGAError(ctx, "PGASetUp: User datatype needs BuildDatatype " "function:", PGA_FATAL, PGA_INT, (void *) &err ); break; } if ((ctx->cops.Mutation == NULL) && (ctx->fops.Mutation == NULL)) ctx->cops.Mutation = Mutation; if ((ctx->cops.Crossover == NULL) && (ctx->fops.Crossover == NULL)) ctx->cops.Crossover = Crossover; if ((ctx->cops.PrintString == NULL) && (ctx->fops.PrintString == NULL)) ctx->cops.PrintString = PrintString; if ((ctx->cops.Duplicate == NULL) && (ctx->fops.Duplicate == NULL)) ctx->cops.Duplicate = Duplicate; if ((ctx->cops.InitString == NULL) && (ctx->fops.InitString == NULL)) ctx->cops.InitString = InitString; if (ctx->cops.CreateString == NULL) ctx->cops.CreateString = CreateString; if (ctx->cops.CopyString == NULL) ctx->cops.CopyString = CopyString; if (ctx->cops.BuildDatatype == NULL) ctx->cops.BuildDatatype = BuildDatatype; /* par */ if ( ctx->par.NumIslands == PGA_UNINITIALIZED_INT) ctx->par.NumIslands = 1; if ( ctx->par.NumDemes == PGA_UNINITIALIZED_INT) ctx->par.NumDemes = 1; if ( ctx->par.DefaultComm == NULL ) ctx->par.DefaultComm = MPI_COMM_WORLD; /* rep */ if ( ctx->rep.PrintFreq == PGA_UNINITIALIZED_INT) ctx->rep.PrintFreq = 10; /* sys */ /* no more sets necessary here. */ /* debug */ /* init */ if ( ctx->init.RandomInit == PGA_UNINITIALIZED_INT) ctx->init.RandomInit = PGA_TRUE; if ( ctx->init.BinaryProbability == PGA_UNINITIALIZED_DOUBLE) ctx->init.BinaryProbability = 0.5; if ( ctx->init.RealType == PGA_UNINITIALIZED_INT) ctx->init.RealType = PGA_RINIT_RANGE; if ( ctx->init.IntegerType == PGA_UNINITIALIZED_INT) ctx->init.IntegerType = PGA_IINIT_PERMUTE; if ( ctx->init.CharacterType == PGA_UNINITIALIZED_INT) ctx->init.CharacterType = PGA_CINIT_LOWER; switch (ctx->ga.datatype) { case PGA_DATATYPE_INTEGER: for (i = 0; i < ctx->ga.StringLen; i++) { if (ctx->init.IntegerMin[i] == PGA_UNINITIALIZED_INT) ctx->init.IntegerMin[i] = 0; if (ctx->init.IntegerMax[i] == PGA_UNINITIALIZED_INT) ctx->init.IntegerMax[i] = ctx->ga.StringLen - 1; } break; case PGA_DATATYPE_REAL: for (i = 0; i < ctx->ga.StringLen; i++) { if (ctx->init.RealMin[i] == PGA_UNINITIALIZED_DOUBLE) ctx->init.RealMin[i] = 0.; if (ctx->init.RealMax[i] == PGA_UNINITIALIZED_DOUBLE) ctx->init.RealMax[i] = 1.; } break; } /* If a seed was not specified, get one from a time of day call */ if ( ctx->init.RandomSeed == PGA_UNINITIALIZED_INT) ctx->init.RandomSeed = (int)time(NULL); /* seed random number generator with this process' unique seed */ ctx->init.RandomSeed += PGAGetRank(ctx, MPI_COMM_WORLD); PGARandom01( ctx, ctx->init.RandomSeed ); ctx->ga.selected = (int *)malloc( sizeof(int) * ctx->ga.PopSize ); if (ctx->ga.selected == NULL) PGAError(ctx, "PGASetUp: No room to allocate ctx->ga.selected", PGA_FATAL, PGA_VOID, NULL); ctx->ga.sorted = (int *)malloc( sizeof(int) * ctx->ga.PopSize ); if (ctx->ga.sorted == NULL) PGAError(ctx, "PGASetUp: No room to allocate ctx->ga.sorted", PGA_FATAL, PGA_VOID, NULL); ctx->scratch.intscratch = (int *)malloc( sizeof(int) * ctx->ga.PopSize ); if (ctx->scratch.intscratch == NULL) PGAError(ctx, "PGASetUp: No room to allocate ctx->scratch.intscratch", PGA_FATAL, PGA_VOID, NULL); ctx->scratch.dblscratch = (double *)malloc(sizeof(double) * ctx->ga.PopSize); if (ctx->scratch.dblscratch == NULL) PGAError(ctx, "PGASetUp: No room to allocate ctx->scratch.dblscratch", PGA_FATAL, PGA_VOID, NULL); PGACreatePop ( ctx , PGA_OLDPOP ); PGACreatePop ( ctx , PGA_NEWPOP ); ctx->rep.starttime = time(NULL); PGADebugExited("PGASetUp"); } /*U**************************************************************************** PGASetRandomInitFlag - A boolean flag to indicate whether to randomly initialize alleles. Legal values are PGA_TRUE and PGA_FALSE. Default is PGA_TRUE -- randomly initialize alleles. Category: Initialization Inputs: ctx - context variable flag - either PGA_TRUE or PGA_FALSE Outputs: None Example: Set the initialization routine to initialize all alleles to zero PGAContext *ctx; : PGASetRandomInitFlag(ctx,PGA_FALSE); ****************************************************************************U*/ void PGASetRandomInitFlag(PGAContext *ctx, int RandomBoolean) { PGADebugEntered("PGASetRandomInitFlag"); PGAFailIfSetUp("PGASetRandomInitFlag"); switch (RandomBoolean) { case PGA_TRUE: case PGA_FALSE: ctx->init.RandomInit = RandomBoolean; break; default: PGAError(ctx, "PGASetRandomInitFlag: Invalid value of RandomBoolean:", PGA_FATAL, PGA_INT, (void *) &RandomBoolean); break; } PGADebugExited("PGASetRandomInitFlag"); } /*U*************************************************************************** PGAGetRandomInitFlag - returns true/false to indicate whether or not alleles are randomly initialized. Category: Initialization Inputs: ctx - context variable Outputs: Returns PGA_TRUE if alleles are randomly initialized. Otherwise, returns PGA_FALSE Example: PGAContext *ctx; int raninit; : raninit = PGAGetRandomInitFlag(ctx); switch (raninit) { case PGA_TRUE: printf("Population is randomly initialized\n"); break; case PGA_FALSE: printf("Population initialized to zero\n"); break; } ***************************************************************************U*/ int PGAGetRandomInitFlag (PGAContext *ctx) { PGADebugEntered("PGAGetRandomInitFlag"); PGAFailIfNotSetUp("PGAGetRandomInitFlag"); PGADebugExited("PGAGetRandomInitFlag"); return(ctx->init.RandomInit); } /*I**************************************************************************** PGACreatePop - allocates a population of individuals and calls PGACreateIndividual to set up each one Inputs: ctx - context variable pop - symbolic constant of the population to create Outputs: None Example: PGAContext *ctx; : PGACreatePop(ctx, PGA_NEWPOP); ****************************************************************************I*/ void PGACreatePop (PGAContext *ctx, int pop) { int p, flag; PGADebugEntered("PGACreatePop"); switch (pop) { case PGA_OLDPOP: ctx->ga.oldpop = (PGAIndividual *)malloc(sizeof(PGAIndividual) * (ctx->ga.PopSize + 2)); if (ctx->ga.oldpop == NULL) PGAError(ctx, "PGACreatePop: No room to allocate " "ctx->ga.oldpop", PGA_FATAL, PGA_VOID, NULL); flag = ctx->init.RandomInit; break; case PGA_NEWPOP: ctx->ga.newpop = (PGAIndividual *)malloc(sizeof(PGAIndividual) * (ctx->ga.PopSize + 2)); if (ctx->ga.newpop == NULL) PGAError(ctx, "PGACreatePop: No room to allocate " "ctx->ga.newpop", PGA_FATAL, PGA_VOID, NULL); flag = PGA_FALSE; break; default: PGAError(ctx, "PGACreatePop: Invalid value of pop:", PGA_FATAL, PGA_INT, (void *) &pop ); break; }; for (p = 0; p < ctx->ga.PopSize; p++) PGACreateIndividual (ctx, p, pop, flag); PGACreateIndividual (ctx, PGA_TEMP1, pop, PGA_FALSE); PGACreateIndividual (ctx, PGA_TEMP2, pop, PGA_FALSE); PGADebugExited("PGACreatePop"); } /*I**************************************************************************** PGACreateIndividual - initialize to zero various data structures of an individual and call the appropriate function to create and initialize the string for the specific data type Inputs: ctx - context variable p - string index pop - symbolic constant of the population string p is in initflag - if the value is PGA_TRUE, the string is randomly initialized. Otherwise it is set to zero. Outputs: None Example: PGAContext *ctx; int p; : PGACreateIndividual(ctx, p, PGA_NEWPOP, PGA_TRUE); ****************************************************************************I*/ void PGACreateIndividual (PGAContext *ctx, int p, int pop, int initflag) { PGAIndividual *ind = PGAGetIndividual(ctx, p, pop); PGADebugEntered("PGACreateIndividual"); ind->evalfunc = 0.0; ind->fitness = 0.0; ind->evaluptodate = PGA_FALSE; (*ctx->cops.CreateString)(ctx, p, pop, initflag); PGADebugExited("PGACreateIndividual"); } pgapack-1.1.1/source/char.c0000644000175000017500000005276710760673707013611 0ustar eddedd/* 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 /*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; iga.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; iga.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;iga.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;iga.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;iga.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); } pgapack-1.1.1/source/f2c.c0000644000175000017500000020440110760674004013315 0ustar eddedd/* 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: f2c_interface.c * * This file contains routines that are called by the Fortran version of * the PGAPack calls. They just make the call to the appropriate C * routine. Issues are: * * Fortran's always passing by reference, * * Using Fortran integers for holding C pointer values * * Fortran's 1,...,n indexing vs. C's 0,...,n-1 * (this comes up in population member and allele indices) * * Pointers to functions * * File pointers * * Characters strings * * Variable length argument lists * * We assume the Fortran compiler generates one of three symbol names for * the external PGAPack routine, e.g., pgasetpopsize, pgasetpopsize_, or * PGASETPOPSIZE. We use #ifdef's based on the appropriate routine to * convert the canonical pgasetpopsize_ to the other two. Since the real * C routine is always mixed case we will never have a conflict. * * Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle, * Brian P. Walenz *****************************************************************************/ #include "pgapack.h" #if defined(FORTRANCAP) #define pgasetbinaryallele_ PGASETBINARYALLELE #define pgagetbinaryallele_ PGAGETBINARYALLELE #define pgasetbinaryinitprob_ PGASETBINARYINITPROB #define pgagetbinaryinitprob_ PGAGETBINARYINITPROB #define pgasetcharacterallele_ PGASETCHARACTERALLELE #define pgagetcharacterallele_ PGAGETCHARACTERALLELE #define pgasetcharacterinittype_ PGASETCHARACTERINITTYPE #define pgacreate_ PGACREATE #define pgasetup_ PGASETUP #define pgasetrandominitflag_ PGASETRANDOMINITFLAG #define pgagetrandominitflag_ PGAGETRANDOMINITFLAG #define pgacrossover_ PGACROSSOVER #define pgagetcrossovertype_ PGAGETCROSSOVERTYPE #define pgagetcrossoverprob_ PGAGETCROSSOVERPROB #define pgagetuniformcrossoverprob_ PGAGETUNIFORMCROSSOVERPROB #define pgasetcrossovertype_ PGASETCROSSOVERTYPE #define pgasetcrossoverprob_ PGASETCROSSOVERPROB #define pgasetuniformcrossoverprob_ PGASETUNIFORMCROSSOVERPROB #define pgadebugprint_ PGADEBUGPRINT #define pgasetdebuglevel_ PGASETDEBUGLEVEL #define pgacleardebuglevel_ PGACLEARDEBUGLEVEL #define pgasetdebuglevelbyname_ PGASETDEBUGLEVELBYNAME #define pgacleardebuglevelbyname_ PGACLEARDEBUGLEVELBYNAME #define pgaduplicate_ PGADUPLICATE #define pgachange_ PGACHANGE #define pgasetnoduplicatesflag_ PGASETNODUPLICATESFLAG #define pgagetnoduplicatesflag_ PGAGETNODUPLICATESFLAG #define pgasetevaluation_ PGASETEVALUATION #define pgagetevaluation_ PGAGETEVALUATION #define pgasetevaluationuptodateflag_ PGASETEVALUATIONUPTODATEFLAG #define pgagetevaluationuptodateflag_ PGAGETEVALUATIONUPTODATEFLAG #define pgagetrealfrombinary_ PGAGETREALFROMBINARY #define pgagetrealfromgraycode_ PGAGETREALFROMGRAYCODE #define pgaencoderealasbinary_ PGAENCODEREALASBINARY #define pgaencoderealasgraycode_ PGAENCODEREALASGRAYCODE #define pgagetintegerfrombinary_ PGAGETINTEGERFROMBINARY #define pgagetintegerfromgraycode_ PGAGETINTEGERFROMGRAYCODE #define pgaencodeintegerasbinary_ PGAENCODEINTEGERASBINARY #define pgaencodeintegerasgraycode_ PGAENCODEINTEGERASGRAYCODE #define pgafitness_ PGAFITNESS #define pgarank_ PGARANK #define pgagetfitness_ PGAGETFITNESS #define pgagetfitnesstype_ PGAGETFITNESSTYPE #define pgagetfitnessmintype_ PGAGETFITNESSMINTYPE #define pgagetmaxfitnessrank_ PGAGETMAXFITNESSRANK #define pgasetfitnesstype_ PGASETFITNESSTYPE #define pgasetfitnessmintype_ PGASETFITNESSMINTYPE #define pgasetmaxfitnessrank_ PGASETMAXFITNESSRANK #define pgasetfitnesscmaxvalue_ PGASETFITNESSCMAXVALUE #define pgagetfitnesscmaxvalue_ PGAGETFITNESSCMAXVALUE #define pgahammingdistance_ PGAHAMMINGDISTANCE #define pgasetintegerallele_ PGASETINTEGERALLELE #define pgagetintegerallele_ PGAGETINTEGERALLELE #define pgasetintegerinitpermute_ PGASETINTEGERINITPERMUTE #define pgasetintegerinitrange_ PGASETINTEGERINITRANGE #define pgagetintegerinittype_ PGAGETINTEGERINITTYPE #define pgagetminintegerinitvalue_ PGAGETMININTEGERINITVALUE #define pgagetmaxintegerinitvalue_ PGAGETMAXINTEGERINITVALUE #define pgamutate_ PGAMUTATE #define pgasetmutationtype_ PGASETMUTATIONTYPE #define pgagetmutationtype_ PGAGETMUTATIONTYPE #define pgasetmutationrealvalue_ PGASETMUTATIONREALVALUE #define pgagetmutationrealvalue_ PGAGETMUTATIONREALVALUE #define pgasetmutationintegervalue_ PGASETMUTATIONINTEGERVALUE #define pgagetmutationintegervalue_ PGAGETMUTATIONINTEGERVALUE #define pgasetmutationboundedflag_ PGASETMUTATIONBOUNDEDFLAG #define pgagetmutationboundedflag_ PGAGETMUTATIONBOUNDEDFLAG #define pgasetmutationprob_ PGASETMUTATIONPROB #define pgagetmutationprob_ PGAGETMUTATIONPROB #define pgarungm_ PGARUNGM #define pgaevaluate_ PGAEVALUATE #define pgabuilddatatype_ PGABUILDDATATYPE #define pgasendindividual_ PGASENDINDIVIDUAL #define pgareceiveindividual_ PGARECEIVEINDIVIDUAL #define pgasendreceiveindividual_ PGASENDRECEIVEINDIVIDUAL #define pgagetrank_ PGAGETRANK #define pgagetnumprocs_ PGAGETNUMPROCS #define pgasetcommunicator_ PGASETCOMMUNICATOR #define pgagetcommunicator_ PGAGETCOMMUNICATOR #define pgarun_ PGARUN #define pgarunmutationandcrossover_ PGARUNMUTATIONANDCROSSOVER #define pgarunmutationorcrossover_ PGARUNMUTATIONORCROSSOVER #define pgaupdategeneration_ PGAUPDATEGENERATION #define pgagetdatatype_ PGAGETDATATYPE #define pgagetoptdirflag_ PGAGETOPTDIRFLAG #define pgagetstringlength_ PGAGETSTRINGLENGTH #define pgagetgaitervalue_ PGAGETGAITERVALUE #define pgasetmutationorcrossoverflag_ PGASETMUTATIONORCROSSOVERFLAG #define pgasetmutationandcrossoverflag_ PGASETMUTATIONANDCROSSOVERFLAG #define pgagetmutationorcrossoverflag_ PGAGETMUTATIONORCROSSOVERFLAG #define pgagetmutationandcrossoverflag_ PGAGETMUTATIONANDCROSSOVERFLAG #define pgasortpop_ PGASORTPOP #define pgagetpopsize_ PGAGETPOPSIZE #define pgagetnumreplacevalue_ PGAGETNUMREPLACEVALUE #define pgagetpopreplacetype_ PGAGETPOPREPLACETYPE #define pgagetsortedpopindex_ PGAGETSORTEDPOPINDEX #define pgasetpopsize_ PGASETPOPSIZE #define pgasetnumreplacevalue_ PGASETNUMREPLACEVALUE #define pgasetpopreplacetype_ PGASETPOPREPLACETYPE #define pgarandomflip_ PGARANDOMFLIP #define pgarandominterval_ PGARANDOMINTERVAL #define pgarandom01_ PGARANDOM01 #define pgarandomuniform_ PGARANDOMUNIFORM #define pgarandomgaussian_ PGARANDOMGAUSSIAN #define pgagetrandomseed_ PGAGETRANDOMSEED #define pgasetrandomseed_ PGASETRANDOMSEED #define pgasetrealallele_ PGASETREALALLELE #define pgagetrealallele_ PGAGETREALALLELE #define pgasetrealinitpercent_ PGASETREALINITPERCENT #define pgasetrealinitrange_ PGASETREALINITRANGE #define pgagetminrealinitvalue_ PGAGETMINREALINITVALUE #define pgagetmaxrealinitvalue_ PGAGETMAXREALINITVALUE #define pgagetrealinittype_ PGAGETREALINITTYPE #define pgaprintreport_ PGAPRINTREPORT #define pgasetprintoptions_ PGASETPRINTOPTIONS #define pgasetprintfrequencyvalue_ PGASETPRINTFREQUENCYVALUE #define pgagetprintfrequencyvalue_ PGAGETPRINTFREQUENCYVALUE #define pgaprintpopulation_ PGAPRINTPOPULATION #define pgaprintindividual_ PGAPRINTINDIVIDUAL #define pgaprintstring_ PGAPRINTSTRING #define pgaprintcontextvariable_ PGAPRINTCONTEXTVARIABLE #define pgarestart_ PGARESTART #define pgasetrestartflag_ PGASETRESTARTFLAG #define pgagetrestartflag_ PGAGETRESTARTFLAG #define pgasetrestartfrequencyvalue_ PGASETRESTARTFREQUENCYVALUE #define pgagetrestartfrequencyvalue_ PGAGETRESTARTFREQUENCYVALUE #define pgasetrestartallelechangeprob_ PGASETRESTARTALLELECHANGEPROB #define pgagetrestartallelechangeprob_ PGAGETRESTARTALLELECHANGEPROB #define pgaselect_ PGASELECT #define pgaselectnextindex_ PGASELECTNEXTINDEX #define pgasetselecttype_ PGASETSELECTTYPE #define pgagetselecttype_ PGAGETSELECTTYPE #define pgasetptournamentprob_ PGASETPTOURNAMENTPROB #define pgagetptournamentprob_ PGAGETPTOURNAMENTPROB #define pgadone_ PGADONE #define pgacheckstoppingconditions_ PGACHECKSTOPPINGCONDITIONS #define pgasetstoppingruletype_ PGASETSTOPPINGRULETYPE #define pgagetstoppingruletype_ PGAGETSTOPPINGRULETYPE #define pgasetmaxgaitervalue_ PGASETMAXGAITERVALUE #define pgagetmaxgaitervalue_ PGAGETMAXGAITERVALUE #define pgasetmaxnochangevalue_ PGASETMAXNOCHANGEVALUE #define pgasetmaxsimilarityvalue_ PGASETMAXSIMILARITYVALUE #define pgaerror_ PGAERROR #define pgadestroy_ PGADESTROY #define pgagetmaxmachineintvalue_ PGAGETMAXMACHINEINTVALUE #define pgagetminmachineintvalue_ PGAGETMINMACHINEINTVALUE #define pgagetmaxmachinedoublevalue_ PGAGETMAXMACHINEDOUBLEVALUE #define pgagetminmachinedoublevalue_ PGAGETMINMACHINEDOUBLEVALUE #define pgausage_ PGAUSAGE #define pgaprintversionnumber_ PGAPRINTVERSIONNUMBER #define pgasetuserfunction_ PGASETUSERFUNCTION #define pgamean_ PGAMEAN #define pgastddev_ PGASTDDEV #define pgaround_ PGAROUND #define pgacopyindividual_ PGACOPYINDIVIDUAL #define pgachecksum_ PGACHECKSUM #define pgagetworstindex_ PGAGETWORSTINDEX #define pgagetbestindex_ PGAGETBESTINDEX #elif defined(FORTRANTWOUNDERSCORE) #define pgasetbinaryallele_ _pgasetbinaryallele_ #define pgagetbinaryallele_ _pgagetbinaryallele_ #define pgasetbinaryinitprob_ _pgasetbinaryinitprob_ #define pgagetbinaryinitprob_ _pgagetbinaryinitprob_ #define pgasetcharacterallele_ _pgasetcharacterallele_ #define pgagetcharacterallele_ _pgagetcharacterallele_ #define pgasetcharacterinittype_ _pgasetcharacterinittype_ #define pgacreate_ _pgacreate_ #define pgasetup_ _pgasetup_ #define pgasetrandominitflag_ _pgasetrandominitflag_ #define pgagetrandominitflag_ _pgagetrandominitflag_ #define pgacrossover_ _pgacrossover_ #define pgagetcrossovertype_ _pgagetcrossovertype_ #define pgagetcrossoverprob_ _pgagetcrossoverprob_ #define pgagetuniformcrossoverprob_ _pgagetuniformcrossoverprob_ #define pgasetcrossovertype_ _pgasetcrossovertype_ #define pgasetcrossoverprob_ _pgasetcrossoverprob_ #define pgasetuniformcrossoverprob_ _pgasetuniformcrossoverprob_ #define pgadebugprint_ _pgadebugprint_ #define pgasetdebuglevel_ _pgasetdebuglevel_ #define pgacleardebuglevel_ _pgacleardebuglevel_ #define pgasetdebuglevelbyname_ _pgasetdebuglevelbyname_ #define pgacleardebuglevelbyname_ _pgacleardebuglevelbyname_ #define pgaduplicate_ _pgaduplicate_ #define pgachange_ _pgachange_ #define pgasetnoduplicatesflag_ _pgasetnoduplicatesflag_ #define pgagetnoduplicatesflag_ _pgagetnoduplicatesflag_ #define pgasetevaluation_ _pgasetevaluation_ #define pgagetevaluation_ _pgagetevaluation_ #define pgasetevaluationuptodateflag_ _pgasetevaluationuptodateflag_ #define pgagetevaluationuptodateflag_ _pgagetevaluationuptodateflag_ #define pgagetrealfrombinary_ _pgagetrealfrombinary_ #define pgagetrealfromgraycode_ _pgagetrealfromgraycode_ #define pgaencoderealasbinary_ _pgaencoderealasbinary_ #define pgaencoderealasgraycode_ _pgaencoderealasgraycode_ #define pgagetintegerfrombinary_ _pgagetintegerfrombinary_ #define pgagetintegerfromgraycode_ _pgagetintegerfromgraycode_ #define pgaencodeintegerasbinary_ _pgaencodeintegerasbinary_ #define pgaencodeintegerasgraycode_ _pgaencodeintegerasgraycode_ #define pgafitness_ _pgafitness_ #define pgarank_ _pgarank_ #define pgagetfitness_ _pgagetfitness_ #define pgagetfitnesstype_ _pgagetfitnesstype_ #define pgagetfitnessmintype_ _pgagetfitnessmintype_ #define pgagetmaxfitnessrank_ _pgagetmaxfitnessrank_ #define pgasetfitnesstype_ _pgasetfitnesstype_ #define pgasetfitnessmintype_ _pgasetfitnessmintype_ #define pgasetmaxfitnessrank_ _pgasetmaxfitnessrank_ #define pgasetfitnesscmaxvalue_ _pgasetfitnesscmaxvalue_ #define pgagetfitnesscmaxvalue_ _pgagetfitnesscmaxvalue_ #define pgahammingdistance_ _pgahammingdistance_ #define pgasetintegerallele_ _pgasetintegerallele_ #define pgagetintegerallele_ _pgagetintegerallele_ #define pgasetintegerinitpermute_ _pgasetintegerinitpermute_ #define pgasetintegerinitrange_ _pgasetintegerinitrange_ #define pgagetintegerinittype_ _pgagetintegerinittype_ #define pgagetminintegerinitvalue_ _pgagetminintegerinitvalue_ #define pgagetmaxintegerinitvalue_ _pgagetmaxintegerinitvalue_ #define pgamutate_ _pgamutate_ #define pgasetmutationtype_ _pgasetmutationtype_ #define pgagetmutationtype_ _pgagetmutationtype_ #define pgasetmutationrealvalue_ _pgasetmutationrealvalue_ #define pgagetmutationrealvalue_ _pgagetmutationrealvalue_ #define pgasetmutationintegervalue_ _pgasetmutationintegervalue_ #define pgagetmutationintegervalue_ _pgagetmutationintegervalue_ #define pgasetmutationboundedflag_ _pgasetmutationboundedflag_ #define pgagetmutationboundedflag_ _pgagetmutationboundedflag_ #define pgasetmutationprob_ _pgasetmutationprob_ #define pgagetmutationprob_ _pgagetmutationprob_ #define pgarungm_ _pgarungm_ #define pgaevaluate_ _pgaevaluate_ #define pgabuilddatatype_ _pgabuilddatatype_ #define pgasendindividual_ _pgasendindividual_ #define pgareceiveindividual_ _pgareceiveindividual_ #define pgasendreceiveindividual_ _pgasendreceiveindividual_ #define pgagetrank_ _pgagetrank_ #define pgagetnumprocs_ _pgagetnumprocs_ #define pgasetcommunicator_ _pgasetcommunicator_ #define pgagetcommunicator_ _pgagetcommunicator_ #define pgarun_ _pgarun_ #define pgarunmutationandcrossover_ _pgarunmutationandcrossover_ #define pgarunmutationorcrossover_ _pgarunmutationorcrossover_ #define pgaupdategeneration_ _pgaupdategeneration_ #define pgagetdatatype_ _pgagetdatatype_ #define pgagetoptdirflag_ _pgagetoptdirflag_ #define pgagetstringlength_ _pgagetstringlength_ #define pgagetgaitervalue_ _pgagetgaitervalue_ #define pgasetmutationorcrossoverflag_ _pgasetmutationorcrossoverflag_ #define pgasetmutationandcrossoverflag_ _pgasetmutationandcrossoverflag_ #define pgagetmutationorcrossoverflag_ _pgagetmutationorcrossoverflag_ #define pgagetmutationandcrossoverflag_ _pgagetmutationandcrossoverflag_ #define pgasortpop_ _pgasortpop_ #define pgagetpopsize_ _pgagetpopsize_ #define pgagetnumreplacevalue_ _pgagetnumreplacevalue_ #define pgagetpopreplacetype_ _pgagetpopreplacetype_ #define pgagetsortedpopindex_ _pgagetsortedpopindex_ #define pgasetpopsize_ _pgasetpopsize_ #define pgasetnumreplacevalue_ _pgasetnumreplacevalue_ #define pgasetpopreplacetype_ _pgasetpopreplacetype_ #define pgarandomflip_ _pgarandomflip_ #define pgarandominterval_ _pgarandominterval_ #define pgarandom01_ _pgarandom01_ #define pgarandomuniform_ _pgarandomuniform_ #define pgarandomgaussian_ _pgarandomgaussian_ #define pgagetrandomseed_ _pgagetrandomseed_ #define pgasetrandomseed_ _pgasetrandomseed_ #define pgasetrealallele_ _pgasetrealallele_ #define pgagetrealallele_ _pgagetrealallele_ #define pgasetrealinitpercent_ _pgasetrealinitpercent_ #define pgasetrealinitrange_ _pgasetrealinitrange_ #define pgagetminrealinitvalue_ _pgagetminrealinitvalue_ #define pgagetmaxrealinitvalue_ _pgagetmaxrealinitvalue_ #define pgagetrealinittype_ _pgagetrealinittype_ #define pgaprintreport_ _pgaprintreport_ #define pgasetprintoptions_ _pgasetprintoptions_ #define pgasetprintfrequencyvalue_ _pgasetprintfrequencyvalue_ #define pgagetprintfrequencyvalue_ _pgagetprintfrequencyvalue_ #define pgaprintpopulation_ _pgaprintpopulation_ #define pgaprintindividual_ _pgaprintindividual_ #define pgaprintstring_ _pgaprintstring_ #define pgaprintcontextvariable_ _pgaprintcontextvariable_ #define pgarestart_ _pgarestart_ #define pgasetrestartflag_ _pgasetrestartflag_ #define pgagetrestartflag_ _pgagetrestartflag_ #define pgasetrestartfrequencyvalue_ _pgasetrestartfrequencyvalue_ #define pgagetrestartfrequencyvalue_ _pgagetrestartfrequencyvalue_ #define pgasetrestartallelechangeprob_ _pgasetrestartallelechangeprob_ #define pgagetrestartallelechangeprob_ _pgagetrestartallelechangeprob_ #define pgaselect_ _pgaselect_ #define pgaselectnextindex_ _pgaselectnextindex_ #define pgasetselecttype_ _pgasetselecttype_ #define pgagetselecttype_ _pgagetselecttype_ #define pgasetptournamentprob_ _pgasetptournamentprob_ #define pgagetptournamentprob_ _pgagetptournamentprob_ #define pgadone_ _pgadone_ #define pgacheckstoppingconditions_ _pgacheckstoppingconditions_ #define pgasetstoppingruletype_ _pgasetstoppingruletype_ #define pgagetstoppingruletype_ _pgagetstoppingruletype_ #define pgasetmaxgaitervalue_ _pgasetmaxgaitervalue_ #define pgagetmaxgaitervalue_ _pgagetmaxgaitervalue_ #define pgasetmaxnochangevalue_ _pgasetmaxnochangevalue_ #define pgasetmaxsimilarityvalue_ _pgasetmaxsimilarityvalue_ #define pgaerror_ _pgaerror_ #define pgadestroy_ _pgadestroy_ #define pgagetmaxmachineintvalue_ _pgagetmaxmachineintvalue_ #define pgagetminmachineintvalue_ _pgagetminmachineintvalue_ #define pgagetmaxmachinedoublevalue_ _pgagetmaxmachinedoublevalue_ #define pgagetminmachinedoublevalue_ _pgagetminmachinedoublevalue_ #define pgausage_ _pgausage_ #define pgaprintversionnumber_ _pgaprintversionnumber_ #define pgasetuserfunction_ _pgasetuserfunction_ #define pgamean_ _pgamean_ #define pgastddev_ _pgastddev_ #define pgaround_ _pgaround_ #define pgacopyindividual_ _pgacopyindividual_ #define pgachecksum_ _pgachecksum_ #define pgagetworstindex_ _pgagetworstindex_ #define pgagetbestindex_ _pgagetbestindex_ #elif !defined(FORTRANUNDERSCORE) #define pgasetbinaryallele_ pgasetbinaryallele #define pgagetbinaryallele_ pgagetbinaryallele #define pgasetbinaryinitprob_ pgasetbinaryinitprob #define pgagetbinaryinitprob_ pgagetbinaryinitprob #define pgasetcharacterallele_ pgasetcharacterallele #define pgagetcharacterallele_ pgagetcharacterallele #define pgasetcharacterinittype_ pgasetcharacterinittype #define pgacreate_ pgacreate #define pgasetup_ pgasetup #define pgasetrandominitflag_ pgasetrandominitflag #define pgagetrandominitflag_ pgagetrandominitflag #define pgacrossover_ pgacrossover #define pgagetcrossovertype_ pgagetcrossovertype #define pgagetcrossoverprob_ pgagetcrossoverprob #define pgagetuniformcrossoverprob_ pgagetuniformcrossoverprob #define pgasetcrossovertype_ pgasetcrossovertype #define pgasetcrossoverprob_ pgasetcrossoverprob #define pgasetuniformcrossoverprob_ pgasetuniformcrossoverprob #define pgadebugprint_ pgadebugprint #define pgasetdebuglevel_ pgasetdebuglevel #define pgacleardebuglevel_ pgacleardebuglevel #define pgasetdebuglevelbyname_ pgasetdebuglevelbyname #define pgacleardebuglevelbyname_ pgacleardebuglevelbyname #define pgaduplicate_ pgaduplicate #define pgachange_ pgachange #define pgasetnoduplicatesflag_ pgasetnoduplicatesflag #define pgagetnoduplicatesflag_ pgagetnoduplicatesflag #define pgasetevaluation_ pgasetevaluation #define pgagetevaluation_ pgagetevaluation #define pgasetevaluationuptodateflag_ pgasetevaluationuptodateflag #define pgagetevaluationuptodateflag_ pgagetevaluationuptodateflag #define pgagetrealfrombinary_ pgagetrealfrombinary #define pgagetrealfromgraycode_ pgagetrealfromgraycode #define pgaencoderealasbinary_ pgaencoderealasbinary #define pgaencoderealasgraycode_ pgaencoderealasgraycode #define pgagetintegerfrombinary_ pgagetintegerfrombinary #define pgagetintegerfromgraycode_ pgagetintegerfromgraycode #define pgaencodeintegerasbinary_ pgaencodeintegerasbinary #define pgaencodeintegerasgraycode_ pgaencodeintegerasgraycode #define pgafitness_ pgafitness #define pgarank_ pgarank #define pgagetfitness_ pgagetfitness #define pgagetfitnesstype_ pgagetfitnesstype #define pgagetfitnessmintype_ pgagetfitnessmintype #define pgagetmaxfitnessrank_ pgagetmaxfitnessrank #define pgasetfitnesstype_ pgasetfitnesstype #define pgasetfitnessmintype_ pgasetfitnessmintype #define pgasetmaxfitnessrank_ pgasetmaxfitnessrank #define pgasetfitnesscmaxvalue_ pgasetfitnesscmaxvalue #define pgagetfitnesscmaxvalue_ pgagetfitnesscmaxvalue #define pgahammingdistance_ pgahammingdistance #define pgasetintegerallele_ pgasetintegerallele #define pgagetintegerallele_ pgagetintegerallele #define pgasetintegerinitpermute_ pgasetintegerinitpermute #define pgasetintegerinitrange_ pgasetintegerinitrange #define pgagetintegerinittype_ pgagetintegerinittype #define pgagetminintegerinitvalue_ pgagetminintegerinitvalue #define pgagetmaxintegerinitvalue_ pgagetmaxintegerinitvalue #define pgamutate_ pgamutate #define pgasetmutationtype_ pgasetmutationtype #define pgagetmutationtype_ pgagetmutationtype #define pgasetmutationrealvalue_ pgasetmutationrealvalue #define pgagetmutationrealvalue_ pgagetmutationrealvalue #define pgasetmutationintegervalue_ pgasetmutationintegervalue #define pgagetmutationintegervalue_ pgagetmutationintegervalue #define pgasetmutationboundedflag_ pgasetmutationboundedflag #define pgagetmutationboundedflag_ pgagetmutationboundedflag #define pgasetmutationprob_ pgasetmutationprob #define pgagetmutationprob_ pgagetmutationprob #define pgarungm_ pgarungm #define pgaevaluate_ pgaevaluate #define pgabuilddatatype_ pgabuilddatatype #define pgasendindividual_ pgasendindividual #define pgareceiveindividual_ pgareceiveindividual #define pgasendreceiveindividual_ pgasendreceiveindividual #define pgagetrank_ pgagetrank #define pgagetnumprocs_ pgagetnumprocs #define pgasetcommunicator_ pgasetcommunicator #define pgagetcommunicator_ pgagetcommunicator #define pgarun_ pgarun #define pgarunmutationandcrossover_ pgarunmutationandcrossover #define pgarunmutationorcrossover_ pgarunmutationorcrossover #define pgaupdategeneration_ pgaupdategeneration #define pgagetdatatype_ pgagetdatatype #define pgagetoptdirflag_ pgagetoptdirflag #define pgagetstringlength_ pgagetstringlength #define pgagetgaitervalue_ pgagetgaitervalue #define pgasetmutationorcrossoverflag_ pgasetmutationorcrossoverflag #define pgasetmutationandcrossoverflag_ pgasetmutationandcrossoverflag #define pgagetmutationorcrossoverflag_ pgagetmutationorcrossoverflag #define pgagetmutationandcrossoverflag_ pgagetmutationandcrossoverflag #define pgasortpop_ pgasortpop #define pgagetpopsize_ pgagetpopsize #define pgagetnumreplacevalue_ pgagetnumreplacevalue #define pgagetpopreplacetype_ pgagetpopreplacetype #define pgagetsortedpopindex_ pgagetsortedpopindex #define pgasetpopsize_ pgasetpopsize #define pgasetnumreplacevalue_ pgasetnumreplacevalue #define pgasetpopreplacetype_ pgasetpopreplacetype #define pgarandomflip_ pgarandomflip #define pgarandominterval_ pgarandominterval #define pgarandom01_ pgarandom01 #define pgarandomuniform_ pgarandomuniform #define pgarandomgaussian_ pgarandomgaussian #define pgagetrandomseed_ pgagetrandomseed #define pgasetrandomseed_ pgasetrandomseed #define pgasetrealallele_ pgasetrealallele #define pgagetrealallele_ pgagetrealallele #define pgasetrealinitpercent_ pgasetrealinitpercent #define pgasetrealinitrange_ pgasetrealinitrange #define pgagetminrealinitvalue_ pgagetminrealinitvalue #define pgagetmaxrealinitvalue_ pgagetmaxrealinitvalue #define pgagetrealinittype_ pgagetrealinittype #define pgaprintreport_ pgaprintreport #define pgasetprintoptions_ pgasetprintoptions #define pgasetprintfrequencyvalue_ pgasetprintfrequencyvalue #define pgagetprintfrequencyvalue_ pgagetprintfrequencyvalue #define pgaprintpopulation_ pgaprintpopulation #define pgaprintindividual_ pgaprintindividual #define pgaprintstring_ pgaprintstring #define pgaprintcontextvariable_ pgaprintcontextvariable #define pgarestart_ pgarestart #define pgasetrestartflag_ pgasetrestartflag #define pgagetrestartflag_ pgagetrestartflag #define pgasetrestartfrequencyvalue_ pgasetrestartfrequencyvalue #define pgagetrestartfrequencyvalue_ pgagetrestartfrequencyvalue #define pgasetrestartallelechangeprob_ pgasetrestartallelechangeprob #define pgagetrestartallelechangeprob_ pgagetrestartallelechangeprob #define pgaselect_ pgaselect #define pgaselectnextindex_ pgaselectnextindex #define pgasetselecttype_ pgasetselecttype #define pgagetselecttype_ pgagetselecttype #define pgasetptournamentprob_ pgasetptournamentprob #define pgagetptournamentprob_ pgagetptournamentprob #define pgadone_ pgadone #define pgacheckstoppingconditions_ pgacheckstoppingconditions #define pgasetstoppingruletype_ pgasetstoppingruletype #define pgagetstoppingruletype_ pgagetstoppingruletype #define pgasetmaxgaitervalue_ pgasetmaxgaitervalue #define pgagetmaxgaitervalue_ pgagetmaxgaitervalue #define pgasetmaxnochangevalue_ pgasetmaxnochangevalue #define pgasetmaxsimilarityvalue_ pgasetmaxsimilarityvalue #define pgaerror_ pgaerror #define pgadestroy_ pgadestroy #define pgagetmaxmachineintvalue_ pgagetmaxmachineintvalue #define pgagetminmachineintvalue_ pgagetminmachineintvalue #define pgagetmaxmachinedoublevalue_ pgagetmaxmachinedoublevalue #define pgagetminmachinedoublevalue_ pgagetminmachinedoublevalue #define pgausage_ pgausage #define pgaprintversionnumber_ pgaprintversionnumber #define pgasetuserfunction_ pgasetuserfunction #define pgamean_ pgamean #define pgastddev_ pgastddev #define pgaround_ pgaround #define pgacopyindividual_ pgacopyindividual #define pgachecksum_ pgachecksum #define pgagetworstindex_ pgagetworstindex #define pgagetbestindex_ pgagetbestindex #endif void pgasetbinaryallele_(PGAContext **ftx, int *p, int *pop, int *i, int *val); int pgagetbinaryallele_(PGAContext **ftx, int *p, int *pop, int *i); void pgasetbinaryinitprob_(PGAContext **ftx, double *probability); double pgagetbinaryinitprob_(PGAContext **ftx); void pgasetcharacterallele_(PGAContext **ftx, int *p, int *pop, int *i, char *val); void pgagetcharacterallele_(char *retval_ptr, int retval_len, PGAContext **ftx, int *p, int *pop, int *i); void pgasetcharacterinittype_(PGAContext **ftx, int *value); unsigned long pgacreate_(int *datatype, int *len, int *maxormin); void pgasetup_(PGAContext **ftx); void pgasetrandominitflag_(PGAContext **ftx, int *RandomBoolean); int pgagetrandominitflag_(PGAContext **ftx); void pgacrossover_(PGAContext **ftx, int *m1, int *m2, int *oldpop, int *t1, int *t2, int *newpop); int pgagetcrossovertype_(PGAContext **ftx); double pgagetcrossoverprob_(PGAContext **ftx); double pgagetuniformcrossoverprob_(PGAContext **ftx); void pgasetcrossovertype_(PGAContext **ftx, int *crossover_type); void pgasetcrossoverprob_(PGAContext **ftx, double *crossover_prob); void pgasetuniformcrossoverprob_(PGAContext **ftx, double *uniform_cross_prob); void pgadebugprint_(PGAContext **ftx, int *level, char *funcname, char *msg, int *datatype, void *data, int len1, int len2); void pgasetdebuglevel_(PGAContext **ftx, int *level); void pgacleardebuglevel_(PGAContext **ftx, int *level); void pgasetdebuglevelbyname_(PGAContext **ftx, char *name, int len); void pgacleardebuglevelbyname_(PGAContext **ftx, char *name, int len); int pgaduplicate_(PGAContext **ftx, int *j, int *pop1, int *pop2, int *n); void pgachange_(PGAContext **ftx, int *j, int *popindex); void pgasetnoduplicatesflag_(PGAContext **ftx, int *no_dup); int pgagetnoduplicatesflag_(PGAContext **ftx); void pgasetevaluation_( PGAContext **ftx, int *p, int *pop, double *val ); double pgagetevaluation_(PGAContext **ftx, int *p, int *pop); void pgasetevaluationuptodateflag_(PGAContext **ftx, int *p, int *pop, int *status); int pgagetevaluationuptodateflag_(PGAContext **ftx, int *p, int *pop); double pgagetrealfrombinary_(PGAContext **ftx, int *p, int *pop, int *start, int *end, double *lower, double *upper); double pgagetrealfromgraycode_(PGAContext **ftx, int *p, int *pop, int *start, int *end, double *lower, double *upper); void pgaencoderealasbinary_(PGAContext **ftx, int *p, int *pop, int *start, int *end, double *lower, double *upper, double *value); void pgaencoderealasgraycode_(PGAContext **ftx, int *p, int *pop, int *start, int *end, double *lower, double *upper, double *value); int pgagetintegerfrombinary_(PGAContext **ftx, int *p, int *pop, int *start, int *end); int pgagetintegerfromgraycode_(PGAContext **ftx, int *p, int *pop, int *start, int *end); void pgaencodeintegerasbinary_(PGAContext **ftx, int *p, int *pop, int*start, int *end, int *value); void pgaencodeintegerasgraycode_(PGAContext **ftx, int *p, int *pop, int*start, int *end, int *value); void pgafitness_(PGAContext **ftx, int *popindex); int pgarank_(PGAContext **ftx, int *p, int *order, int *n); double pgagetfitness_(PGAContext **ftx, int *p, int *pop); int pgagetfitnesstype_(PGAContext **ftx); int pgagetfitnessmintype_(PGAContext **ftx); double pgagetmaxfitnessrank_(PGAContext **ftx); void pgasetfitnesstype_(PGAContext **ftx, int *fitness_type); void pgasetfitnessmintype_(PGAContext **ftx, int *fitness_type); void pgasetmaxfitnessrank_(PGAContext **ftx, double *fitness_rank_max); void pgasetfitnesscmaxvalue_(PGAContext **ftx, double *val); double pgagetfitnesscmaxvalue_(PGAContext **ftx); double pgahammingdistance_(PGAContext **ftx, int *popindex); void pgasetintegerallele_(PGAContext **ftx, int *p, int *pop, int *i, int *val); int pgagetintegerallele_(PGAContext **ftx, int *p, int *pop, int *i); void pgasetintegerinitpermute_(PGAContext **ftx, int *min, int *max); void pgasetintegerinitrange_ (PGAContext **ftx, int *min, int *max); int pgagetintegerinittype_(PGAContext **ftx); int pgagetminintegerinitvalue_ (PGAContext **ftx, int *i); int pgagetmaxintegerinitvalue_ (PGAContext **ftx, int *i); void pgamutate_(PGAContext **ftx, int *p, int *pop); void pgasetmutationtype_(PGAContext **ftx, int *mutation_type); int pgagetmutationtype_(PGAContext **ftx); void pgasetmutationrealvalue_(PGAContext **ftx, double *val); double pgagetmutationrealvalue_(PGAContext **ftx); void pgasetmutationintegervalue_(PGAContext **ftx, int *val); int pgagetmutationintegervalue_(PGAContext **ftx); void pgasetmutationboundedflag_(PGAContext **ftx, int *val); int pgagetmutationboundedflag_(PGAContext **ftx); void pgasetmutationprob_(PGAContext **ftx, double *mutation_prob); double pgagetmutationprob_(PGAContext **ftx); void pgarungm_(PGAContext **ftx, double (*f)(PGAContext *, int, int), MPI_Comm *comm); void pgaevaluate_(PGAContext **ftx, int *pop, double (*f)(PGAContext *, int, int), MPI_Comm *comm); unsigned long pgabuilddatatype_(PGAContext **ftx, int *p, int *pop); void pgasendindividual_(PGAContext **ftx, int *p, int *pop, int *dest, int *tag, MPI_Comm *comm); void pgareceiveindividual_(PGAContext **ftx, int *p, int *pop, int *source, int *tag, MPI_Comm *comm, MPI_Status *status); void pgasendreceiveindividual_(PGAContext **ftx, int *send_p, int *send_pop, int *dest, int *send_tag, int *recv_p, int *recv_pop, int *source, int *recv_tag, MPI_Comm *comm, MPI_Status *status); int pgagetrank_(PGAContext **ftx, MPI_Comm *comm); int pgagetnumprocs_(PGAContext **ftx, MPI_Comm *comm); void pgasetcommunicator_(PGAContext **ftx, MPI_Comm *comm); MPI_Comm pgagetcommunicator_(PGAContext **ftx); void pgarun_(PGAContext **ftx, double (*evaluate)(PGAContext *c, int p, int pop)); void pgarunmutationandcrossover_(PGAContext **ftx, int *oldpop, int *newpop); void pgarunmutationorcrossover_(PGAContext **ftx, int *oldpop, int *newpop); void pgaupdategeneration_(PGAContext **ftx, MPI_Comm *comm); int pgagetdatatype_(PGAContext **ftx); int pgagetoptdirflag_(PGAContext **ftx); int pgagetstringlength_(PGAContext **ftx); int pgagetgaitervalue_(PGAContext **ftx); void pgasetmutationorcrossoverflag_(PGAContext **ftx, int *flag); void pgasetmutationandcrossoverflag_(PGAContext **ftx, int *flag); int pgagetmutationorcrossoverflag_(PGAContext **ftx); int pgagetmutationandcrossoverflag_(PGAContext **ftx); void pgasortpop_(PGAContext **ftx, int *pop); int pgagetpopsize_(PGAContext **ftx); int pgagetnumreplacevalue_(PGAContext **ftx); int pgagetpopreplacetype_(PGAContext **ftx); int pgagetsortedpopindex_(PGAContext **ftx, int *n); void pgasetpopsize_(PGAContext **ftx, int *popsize); void pgasetnumreplacevalue_(PGAContext **ftx, int *pop_replace); void pgasetpopreplacetype_(PGAContext **ftx, int *pop_replace); int pgarandomflip_(PGAContext **ftx, double *p); int pgarandominterval_(PGAContext **ftx, int *start, int *end); double pgarandom01_(PGAContext **ftx, int *newseed); double pgarandomuniform_(PGAContext **ftx, double *start, double *end); double pgarandomgaussian_(PGAContext **ftx, double *mean, double *sigma); int pgagetrandomseed_(PGAContext **ftx); void pgasetrandomseed_(PGAContext **ftx, int *seed); void pgasetrealallele_(PGAContext **ftx, int *p, int *pop, int *i, double *val); double pgagetrealallele_(PGAContext **ftx, int *p, int *pop, int *i); void pgasetrealinitpercent_(PGAContext **ftx, double *median, double *percent); void pgasetrealinitrange_ (PGAContext **ftx, double *min, double *max); double pgagetminrealinitvalue_(PGAContext **ftx, int *i); double pgagetmaxrealinitvalue_(PGAContext **ftx, int *i); int pgagetrealinittype_(PGAContext **ftx); void pgaprintreport_(PGAContext **ftx, char *name, int *pop, int len); void pgasetprintoptions_(PGAContext **ftx, int *option); void pgasetprintfrequencyvalue_(PGAContext **ftx, int *print_freq); int pgagetprintfrequencyvalue_(PGAContext **ftx); void pgaprintpopulation_(PGAContext **ftx, char *name, int *pop, int len); void pgaprintindividual_ (PGAContext **ftx, char *name, int *p, int *pop, int len); void pgaprintstring_ (PGAContext **ftx, char *name, int *p, int *pop, int len); void pgaprintcontextvariable_(PGAContext **ftx, char *name, int len); void pgarestart_(PGAContext **ftx, int *source_pop, int *dest_pop); void pgasetrestartflag_(PGAContext **ftx, int *val); int pgagetrestartflag_(PGAContext **ftx); void pgasetrestartfrequencyvalue_(PGAContext **ftx, int *numiter); int pgagetrestartfrequencyvalue_(PGAContext **ftx); void pgasetrestartallelechangeprob_(PGAContext **ftx, double *prob); double pgagetrestartallelechangeprob_(PGAContext **ftx); void pgaselect_(PGAContext **ftx, int *popix); int pgaselectnextindex_(PGAContext **ftx); void pgasetselecttype_(PGAContext **ftx, int *select_type); int pgagetselecttype_(PGAContext **ftx); void pgasetptournamentprob_(PGAContext **ftx, double *ptournament_prob); double pgagetptournamentprob_(PGAContext **ftx); int pgadone_(PGAContext **ftx, MPI_Comm *comm); int pgacheckstoppingconditions_(PGAContext **ftx); void pgasetstoppingruletype_(PGAContext **ftx, int *stoprule); int pgagetstoppingruletype_(PGAContext **ftx); void pgasetmaxgaitervalue_(PGAContext **ftx, int *maxiter); int pgagetmaxgaitervalue_(PGAContext **ftx); void pgasetmaxnochangevalue_(PGAContext **ftx, int *max_no_change); void pgasetmaxsimilarityvalue_(PGAContext **ftx, int *max_similarity); void pgaerror_(PGAContext **ftx, char *msg, int *level, int *datatype, void **data, int len); void pgadestroy_(PGAContext **ftx); int pgagetmaxmachineintvalue_(PGAContext **ftx); int pgagetminmachineintvalue_(PGAContext **ftx); double pgagetmaxmachinedoublevalue_(PGAContext **ftx); double pgagetminmachinedoublevalue_(PGAContext **ftx); void pgausage_(PGAContext **ftx); void pgaprintversionnumber_(PGAContext **ftx); void pgasetuserfunction_(PGAContext **ftx, int *constant, void *f); double pgamean_(PGAContext **ftx, double *a, int *n); double pgastddev_(PGAContext **ftx, double *a, int *n, double *m); int pgaround_(PGAContext **ftx, double *x); void pgacopyindividual_(PGAContext **ftx, int *i, int *p1, int *j, int *p2); int pgachecksum_(PGAContext **ftx, int *p, int *pop); int pgagetworstindex_(PGAContext **ftx, int *pop); int pgagetbestindex_(PGAContext **ftx, int *pop); void pgasetbinaryallele_(PGAContext **ftx, int *p, int *pop, int *i, int *val) { PGASetBinaryAllele(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop, *i-1, *val); } int pgagetbinaryallele_(PGAContext **ftx, int *p, int *pop, int *i) { return PGAGetBinaryAllele(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop, *i-1); } void pgasetbinaryinitprob_(PGAContext **ftx, double *probability) { PGASetBinaryInitProb (*ftx, *probability); } double pgagetbinaryinitprob_(PGAContext **ftx) { return PGAGetBinaryInitProb (*ftx); } void pgasetcharacterallele_(PGAContext **ftx, int *p, int *pop, int *i, char *val) { PGASetCharacterAllele(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop, *i-1, *val); } void pgagetcharacterallele_(char *retval_ptr, int retval_len, PGAContext **ftx, int *p, int *pop, int *i) { *retval_ptr = PGAGetCharacterAllele(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop, *i-1); } void pgasetcharacterinittype_(PGAContext **ftx, int *value) { PGASetCharacterInitType (*ftx, *value); } unsigned long pgacreate_(int *datatype, int *len, int *maxormin) { int argc; char *argv[1]; PGAContext *ctx; argv[0] = "pgapack"; argc = 1; ctx = PGACreate(&argc, argv, *datatype, *len, *maxormin); ctx->sys.UserFortran = PGA_TRUE; return (unsigned long)ctx; } void pgasetup_(PGAContext **ftx) { PGASetUp (*ftx); } void pgasetrandominitflag_(PGAContext **ftx, int *RandomBoolean) { PGASetRandomInitFlag (*ftx, *RandomBoolean); } int pgagetrandominitflag_(PGAContext **ftx) { return PGAGetRandomInitFlag (*ftx); } void pgacrossover_(PGAContext **ftx, int *m1, int *m2, int *oldpop, int *t1, int *t2, int *newpop) { PGACrossover (*ftx, *m1 == PGA_TEMP1 || *m1 == PGA_TEMP2 ? *m1 : *m1-1, *m2 == PGA_TEMP1 || *m2 == PGA_TEMP2 ? *m2 : *m2-1, *oldpop, *t1 == PGA_TEMP1 || *t1 == PGA_TEMP2 ? *t1 : *t1-1, *t2 == PGA_TEMP1 || *t2 == PGA_TEMP2 ? *t2 : *t2-1, *newpop); } int pgagetcrossovertype_(PGAContext **ftx) { return PGAGetCrossoverType (*ftx); } double pgagetcrossoverprob_(PGAContext **ftx) { return PGAGetCrossoverProb (*ftx); } double pgagetuniformcrossoverprob_(PGAContext **ftx) { return PGAGetUniformCrossoverProb (*ftx); } void pgasetcrossovertype_(PGAContext **ftx, int *crossover_type) { PGASetCrossoverType (*ftx, *crossover_type); } void pgasetcrossoverprob_(PGAContext **ftx, double *crossover_prob) { PGASetCrossoverProb (*ftx, *crossover_prob); } void pgasetuniformcrossoverprob_(PGAContext **ftx, double *uniform_cross_prob) { PGASetUniformCrossoverProb (*ftx, *uniform_cross_prob); } #if OPTIMIZE==0 void pgadebugprint_(PGAContext **ftx, int *level, char *funcname, char *msg, int *datatype, void *data, int len1, int len2) /* FORTRAN implicitly passes the lengths of funcname and msg into len1 and len2, respectively */ { if (funcname[len1] != 0 || msg[len2] != 0) funcname[len1] = msg[len2] = 0; PGADebugPrint(*ftx, *level, funcname, msg, *datatype, data ); } #else void pgadebugprint_(PGAContext **ftx, int *level, char *funcname, char *msg, int *datatype, void *data, int len1, int len2) { printf("PGADebugPrint is not supported in the optimized version of PGAPack.\n"); } #endif #if OPTIMIZE==0 void pgasetdebuglevel_(PGAContext **ftx, int *level) { PGASetDebugLevel(*ftx, *level); } #else void pgasetdebuglevel_(PGAContext **ftx, int *level) { printf("PGASetDebugLevel is not supported in the optimized version of PGAPack.\n"); } #endif #if OPTIMIZE==0 void pgacleardebuglevel_(PGAContext **ftx, int *level) { PGAClearDebugLevel(*ftx, *level); } #else void pgacleardebuglevel_(PGAContext **ftx, int *level) { printf("PGAClearDebugLevel is not supported in the optimized version of PGAPack.\n"); } #endif #if OPTIMIZE==0 void pgasetdebuglevelbyname_(PGAContext **ftx, char *name, int len) { if (name[len] != 0) name[len] = 0; PGASetDebugLevelByName(*ftx, name); } #else void pgasetdebuglevelbyname_(PGAContext **ftx, char *name, int len) { printf("PGASetDebugLevelByName is not supported in the optimized version of PGAPack.\n"); } #endif #if OPTIMIZE==0 void pgacleardebuglevelbyname_(PGAContext **ftx, char *name, int len) { if (name[len] != 0) name[len] = 0; PGAClearDebugLevelByName(*ftx, name); } #else void pgacleardebuglevelbyname_(PGAContext **ftx, char *name, int len) { printf("PGAClearDebugLevelByName is not supported in the optimized version of PGAPack.\n"); } #endif int pgaduplicate_(PGAContext **ftx, int *j, int *pop1, int *pop2, int *n) { return PGADuplicate(*ftx, *j == PGA_TEMP1 || *j == PGA_TEMP2 ? *j : *j-1, *pop1, *pop2, *n); } void pgachange_(PGAContext **ftx, int *j, int *popindex) { PGAChange(*ftx, *j == PGA_TEMP1 || *j == PGA_TEMP2 ? *j : *j-1, *popindex); } void pgasetnoduplicatesflag_(PGAContext **ftx, int *no_dup) { PGASetNoDuplicatesFlag (*ftx, *no_dup); } int pgagetnoduplicatesflag_(PGAContext **ftx) { return PGAGetNoDuplicatesFlag (*ftx); } void pgasetevaluation_( PGAContext **ftx, int *p, int *pop, double *val ) { PGASetEvaluation(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p-1, *pop, *val ); } double pgagetevaluation_(PGAContext **ftx, int *p, int *pop) { return PGAGetEvaluation(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p-1, *pop); } void pgasetevaluationuptodateflag_(PGAContext **ftx, int *p, int *pop, int *status) { PGASetEvaluationUpToDateFlag(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p-1, *pop, *status); } int pgagetevaluationuptodateflag_(PGAContext **ftx, int *p, int *pop) { return PGAGetEvaluationUpToDateFlag(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p-1, *pop); } double pgagetrealfrombinary_(PGAContext **ftx, int *p, int *pop, int *start, int *end, double *lower, double *upper) { return PGAGetRealFromBinary(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop, *start-1, *end-1, *lower, *upper); } double pgagetrealfromgraycode_(PGAContext **ftx, int *p, int *pop, int *start, int *end, double *lower, double *upper) { return PGAGetRealFromGrayCode(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop, *start-1, *end-1, *lower, *upper); } void pgaencoderealasbinary_(PGAContext **ftx, int *p, int *pop, int *start, int *end, double *lower, double *upper, double *value) { PGAEncodeRealAsBinary(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop, *start-1, *end-1, *lower, *upper, *value); } void pgaencoderealasgraycode_(PGAContext **ftx, int *p, int *pop, int *start, int *end, double *lower, double *upper, double *value) { PGAEncodeRealAsGrayCode(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop, *start-1, *end-1, *lower, *upper, *value); } int pgagetintegerfrombinary_(PGAContext **ftx, int *p, int *pop, int *start, int *end) { return PGAGetIntegerFromBinary(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop, *start-1, *end-1); } int pgagetintegerfromgraycode_(PGAContext **ftx, int *p, int *pop, int *start, int *end) { return PGAGetIntegerFromGrayCode(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop, *start-1, *end-1); } void pgaencodeintegerasbinary_(PGAContext **ftx, int *p, int *pop, int*start, int *end, int *value) { PGAEncodeIntegerAsBinary(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop, *start-1, *end-1, *value); } void pgaencodeintegerasgraycode_(PGAContext **ftx, int *p, int *pop, int*start, int *end, int *value) { PGAEncodeIntegerAsGrayCode(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop, *start-1, *end-1, *value); } void pgafitness_(PGAContext **ftx, int *popindex) { PGAFitness (*ftx, *popindex); } int pgarank_(PGAContext **ftx, int *p, int *order, int *n) { return PGARank(*ftx, *p-1, order, *n); } double pgagetfitness_(PGAContext **ftx, int *p, int *pop) { return PGAGetFitness(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p-1, *pop); } int pgagetfitnesstype_(PGAContext **ftx) { return PGAGetFitnessType (*ftx); } int pgagetfitnessmintype_(PGAContext **ftx) { return PGAGetFitnessMinType (*ftx); } double pgagetmaxfitnessrank_(PGAContext **ftx) { return PGAGetMaxFitnessRank (*ftx); } void pgasetfitnesstype_(PGAContext **ftx, int *fitness_type) { PGASetFitnessType (*ftx, *fitness_type); } void pgasetfitnessmintype_(PGAContext **ftx, int *fitness_type) { PGASetFitnessMinType (*ftx, *fitness_type); } void pgasetmaxfitnessrank_(PGAContext **ftx, double *fitness_rank_max) { PGASetMaxFitnessRank (*ftx, *fitness_rank_max); } void pgasetfitnesscmaxvalue_(PGAContext **ftx, double *val) { PGASetFitnessCmaxValue (*ftx, *val); } double pgagetfitnesscmaxvalue_(PGAContext **ftx) { return PGAGetFitnessCmaxValue (*ftx); } double pgahammingdistance_(PGAContext **ftx, int *popindex) { return PGAHammingDistance (*ftx, *popindex); } void pgasetintegerallele_(PGAContext **ftx, int *p, int *pop, int *i, int *val) { PGASetIntegerAllele(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop, *i-1, *val); } int pgagetintegerallele_(PGAContext **ftx, int *p, int *pop, int *i) { return PGAGetIntegerAllele(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop, *i-1); } void pgasetintegerinitpermute_(PGAContext **ftx, int *min, int *max) { PGASetIntegerInitPermute (*ftx, *min, *max); } void pgasetintegerinitrange_ (PGAContext **ftx, int *min, int *max) { PGASetIntegerInitRange(*ftx, min, max); } int pgagetintegerinittype_(PGAContext **ftx) { return PGAGetIntegerInitType (*ftx); } int pgagetminintegerinitvalue_ (PGAContext **ftx, int *i) { return PGAGetMinIntegerInitValue(*ftx, *i-1); } int pgagetmaxintegerinitvalue_ (PGAContext **ftx, int *i) { return PGAGetMaxIntegerInitValue(*ftx, *i-1); } void pgamutate_(PGAContext **ftx, int *p, int *pop) { PGAMutate(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p-1, *pop); } void pgasetmutationtype_(PGAContext **ftx, int *mutation_type) { PGASetMutationType (*ftx, *mutation_type); } int pgagetmutationtype_(PGAContext **ftx) { return PGAGetMutationType (*ftx); } void pgasetmutationrealvalue_(PGAContext **ftx, double *val) { PGASetMutationRealValue (*ftx, *val); } double pgagetmutationrealvalue_(PGAContext **ftx) { return PGAGetMutationRealValue (*ftx); } void pgasetmutationintegervalue_(PGAContext **ftx, int *val) { PGASetMutationIntegerValue (*ftx, *val); } int pgagetmutationintegervalue_(PGAContext **ftx) { return PGAGetMutationIntegerValue (*ftx); } void pgasetmutationboundedflag_(PGAContext **ftx, int *val) { PGASetMutationBoundedFlag (*ftx, *val); } int pgagetmutationboundedflag_(PGAContext **ftx) { return PGAGetMutationBoundedFlag (*ftx); } void pgasetmutationprob_(PGAContext **ftx, double *mutation_prob) { PGASetMutationProb (*ftx, *mutation_prob); } double pgagetmutationprob_(PGAContext **ftx) { return PGAGetMutationProb (*ftx); } void pgarungm_(PGAContext **ftx, double (*f)(PGAContext *, int, int), MPI_Comm *comm) { PGARunGM (*ftx, (*f), *comm); } void pgaevaluate_(PGAContext **ftx, int *pop, double (*f)(PGAContext *, int, int), MPI_Comm *comm) { PGAEvaluate (*ftx, *pop, (*f), *comm); } unsigned long pgabuilddatatype_(PGAContext **ftx, int *p, int *pop) { return((unsigned long)PGABuildDatatype(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop)); } void pgasendindividual_(PGAContext **ftx, int *p, int *pop, int *dest, int *tag, MPI_Comm *comm) { PGASendIndividual(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop, *dest, *tag, *comm); } void pgareceiveindividual_(PGAContext **ftx, int *p, int *pop, int *source, int *tag, MPI_Comm *comm, MPI_Status *status) { PGAReceiveIndividual(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p-1, *pop, *source, *tag, *comm, status); } void pgasendreceiveindividual_(PGAContext **ftx, int *send_p, int *send_pop, int *dest, int *send_tag, int *recv_p, int *recv_pop, int *source, int *recv_tag, MPI_Comm *comm, MPI_Status *status) { PGASendReceiveIndividual(*ftx, *send_p == PGA_TEMP1 || *send_p == PGA_TEMP2 ? *send_p : *send_p - 1, *send_pop, *dest, *send_tag, *recv_p == PGA_TEMP1 || *recv_p == PGA_TEMP2 ? *recv_p : *recv_p - 1, *recv_pop, *source, *recv_tag, *comm, status); } int pgagetrank_(PGAContext **ftx, MPI_Comm *comm) { return PGAGetRank (*ftx, *comm); } int pgagetnumprocs_(PGAContext **ftx, MPI_Comm *comm) { return PGAGetNumProcs (*ftx, *comm); } void pgasetcommunicator_(PGAContext **ftx, MPI_Comm *comm) { PGASetCommunicator (*ftx, *comm); } MPI_Comm pgagetcommunicator_(PGAContext **ftx) { return PGAGetCommunicator (*ftx); } void pgarun_(PGAContext **ftx, double (*evaluate)(PGAContext *c, int p, int pop)) { PGARun (*ftx, (*evaluate)); } void pgarunmutationandcrossover_(PGAContext **ftx, int *oldpop, int *newpop) { PGARunMutationAndCrossover (*ftx, *oldpop, *newpop); } void pgarunmutationorcrossover_(PGAContext **ftx, int *oldpop, int *newpop) { PGARunMutationOrCrossover (*ftx, *oldpop, *newpop); } void pgaupdategeneration_(PGAContext **ftx, MPI_Comm *comm) { PGAUpdateGeneration (*ftx, *comm); } int pgagetdatatype_(PGAContext **ftx) { return PGAGetDataType (*ftx); } int pgagetoptdirflag_(PGAContext **ftx) { return PGAGetOptDirFlag (*ftx); } int pgagetstringlength_(PGAContext **ftx) { return PGAGetStringLength (*ftx); } int pgagetgaitervalue_(PGAContext **ftx) { return PGAGetGAIterValue (*ftx); } void pgasetmutationorcrossoverflag_(PGAContext **ftx, int *flag) { PGASetMutationOrCrossoverFlag (*ftx, *flag); } void pgasetmutationandcrossoverflag_(PGAContext **ftx, int *flag) { PGASetMutationAndCrossoverFlag (*ftx, *flag); } int pgagetmutationorcrossoverflag_(PGAContext **ftx) { return PGAGetMutationOrCrossoverFlag (*ftx); } int pgagetmutationandcrossoverflag_(PGAContext **ftx) { return PGAGetMutationAndCrossoverFlag (*ftx); } void pgasortpop_(PGAContext **ftx, int *pop) { PGASortPop (*ftx, *pop); } int pgagetpopsize_(PGAContext **ftx) { return PGAGetPopSize (*ftx); } int pgagetnumreplacevalue_(PGAContext **ftx) { return PGAGetNumReplaceValue (*ftx); } int pgagetpopreplacetype_(PGAContext **ftx) { return PGAGetPopReplaceType (*ftx); } int pgagetsortedpopindex_(PGAContext **ftx, int *n) { return PGAGetSortedPopIndex(*ftx, *n-1); } void pgasetpopsize_(PGAContext **ftx, int *popsize) { PGASetPopSize (*ftx, *popsize); } void pgasetnumreplacevalue_(PGAContext **ftx, int *pop_replace) { PGASetNumReplaceValue (*ftx, *pop_replace); } void pgasetpopreplacetype_(PGAContext **ftx, int *pop_replace) { PGASetPopReplaceType (*ftx, *pop_replace); } int pgarandomflip_(PGAContext **ftx, double *p) { return PGARandomFlip (*ftx, *p); } int pgarandominterval_(PGAContext **ftx, int *start, int *end) { return PGARandomInterval (*ftx, *start, *end); } double pgarandom01_(PGAContext **ftx, int *newseed) { return PGARandom01 (*ftx, *newseed); } double pgarandomuniform_(PGAContext **ftx, double *start, double *end) { return PGARandomUniform (*ftx, *start, *end); } double pgarandomgaussian_(PGAContext **ftx, double *mean, double *sigma) { return PGARandomGaussian (*ftx, *mean, *sigma); } int pgagetrandomseed_(PGAContext **ftx) { return PGAGetRandomSeed (*ftx); } void pgasetrandomseed_(PGAContext **ftx, int *seed) { PGASetRandomSeed (*ftx, *seed); } void pgasetrealallele_(PGAContext **ftx, int *p, int *pop, int *i, double *val) { PGASetRealAllele(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop, *i-1, *val); } double pgagetrealallele_(PGAContext **ftx, int *p, int *pop, int *i) { return PGAGetRealAllele(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop, *i-1); } void pgasetrealinitpercent_(PGAContext **ftx, double *median, double *percent) { PGASetRealInitPercent(*ftx, median, percent); } void pgasetrealinitrange_ (PGAContext **ftx, double *min, double *max) { PGASetRealInitRange(*ftx, min, max); } double pgagetminrealinitvalue_(PGAContext **ftx, int *i) { return PGAGetMinRealInitValue(*ftx, *i-1); } double pgagetmaxrealinitvalue_(PGAContext **ftx, int *i) { return PGAGetMaxRealInitValue(*ftx, *i-1); } int pgagetrealinittype_(PGAContext **ftx) { return PGAGetRealInitType (*ftx); } void pgaprintreport_(PGAContext **ftx, char *name, int *pop, int len) /* FORTRAN implicitly passes the length of name into len. */ { FILE *fp; if (name[len] != 0) name[len] = 0; if (!strcmp(name, "STDOUT") || !strcmp(name, "stdout")) { fp = stdout; PGAPrintReport(*ftx, fp, *pop); } else if (!strcmp(name, "STDERR") || !strcmp(name, "stderr")) { fp = stderr; PGAPrintReport(*ftx, fp, *pop); } else { fp = fopen(name, "a"); if (!fp) PGAError(*ftx, "PGAPrintReport: Could not open file:", PGA_FATAL, PGA_CHAR, (void *) name); else { PGAPrintReport(*ftx, fp, *pop); fclose(fp); } } } void pgasetprintoptions_(PGAContext **ftx, int *option) { PGASetPrintOptions (*ftx, *option); } void pgasetprintfrequencyvalue_(PGAContext **ftx, int *print_freq) { PGASetPrintFrequencyValue (*ftx, *print_freq); } int pgagetprintfrequencyvalue_(PGAContext **ftx) { return PGAGetPrintFrequencyValue (*ftx); } void pgaprintpopulation_(PGAContext **ftx, char *name, int *pop, int len) /* FORTRAN implicitly passes the length of name into len. */ { FILE *fp; if (name[len] != 0) name[len] = 0; if (!strcmp(name, "STDOUT") || !strcmp(name, "stdout")) { fp = stdout; PGAPrintPopulation(*ftx, fp, *pop); } else if (!strcmp(name, "STDERR") || !strcmp(name, "stderr")) { fp = stderr; PGAPrintPopulation(*ftx, fp, *pop); } else { fp = fopen(name, "a"); if (!fp) PGAError(*ftx, "PGAPrintPopulation: Could not open file:", PGA_FATAL, PGA_CHAR, (void *) name); else { PGAPrintPopulation(*ftx, fp, *pop); fclose(fp); } } } void pgaprintindividual_ (PGAContext **ftx, char *name, int *p, int *pop, int len) /* FORTRAN implicitly passes the length of name into len. */ { FILE *fp; if (name[len] != 0) name[len] = 0; if (!strcmp(name, "STDOUT") || !strcmp(name, "stdout")) { fp = stdout; PGAPrintIndividual(*ftx, fp, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop); } else if (!strcmp(name, "STDERR") || !strcmp(name, "stderr")) { fp = stderr; PGAPrintIndividual(*ftx, fp, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop); } else { fp = fopen(name, "a"); if (!fp) PGAError(*ftx, "PGAPrintIndividual: Could not open file:", PGA_FATAL, PGA_CHAR, (void *) name); else { PGAPrintIndividual(*ftx, fp, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop); fclose(fp); } } } void pgaprintstring_ (PGAContext **ftx, char *name, int *p, int *pop, int len) /* FORTRAN implicitly passes the length of name into len. */ { FILE *fp; if (name[len] != 0) name[len] = 0; if (!strcmp(name, "STDOUT") || !strcmp(name, "stdout")) { fp = stdout; PGAPrintString(*ftx, fp, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop); } else if (!strcmp(name, "STDERR") || !strcmp(name, "stderr")) { fp = stderr; PGAPrintString(*ftx, fp, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop); } else { fp = fopen(name, "a"); if (!fp) PGAError(*ftx, "PGAPrintString: Could not open file:", PGA_FATAL, PGA_CHAR, (void *) name); else { PGAPrintString(*ftx, fp, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p - 1, *pop); fclose(fp); } } } void pgaprintcontextvariable_(PGAContext **ftx, char *name, int len) /* FORTRAN implicitly passes the length of name into len. */ { FILE *fp; if (name[len] != 0) name[len] = 0; if (!strcmp(name, "STDOUT") || !strcmp(name, "stdout")) { fp = stdout; PGAPrintContextVariable(*ftx, fp); } else if (!strcmp(name, "STDERR") || !strcmp(name, "stderr")) { fp = stderr; PGAPrintContextVariable(*ftx, fp); } else { fp = fopen(name, "a"); if (!fp) PGAError(*ftx, "PGAPrintContextVariable: Could not open file:", PGA_FATAL, PGA_CHAR, (void *) name); else { PGAPrintContextVariable(*ftx, fp); fclose(fp); } } } void pgarestart_(PGAContext **ftx, int *source_pop, int *dest_pop) { PGARestart (*ftx, *source_pop, *dest_pop); } void pgasetrestartflag_(PGAContext **ftx, int *val) { PGASetRestartFlag (*ftx, *val); } int pgagetrestartflag_(PGAContext **ftx) { return PGAGetRestartFlag (*ftx); } void pgasetrestartfrequencyvalue_(PGAContext **ftx, int *numiter) { PGASetRestartFrequencyValue (*ftx, *numiter); } int pgagetrestartfrequencyvalue_(PGAContext **ftx) { return PGAGetRestartFrequencyValue (*ftx); } void pgasetrestartallelechangeprob_(PGAContext **ftx, double *prob) { PGASetRestartAlleleChangeProb (*ftx, *prob); } double pgagetrestartallelechangeprob_(PGAContext **ftx) { return PGAGetRestartAlleleChangeProb (*ftx); } void pgaselect_(PGAContext **ftx, int *popix) { PGASelect (*ftx, *popix); } int pgaselectnextindex_(PGAContext **ftx) { return PGASelectNextIndex (*ftx); } void pgasetselecttype_(PGAContext **ftx, int *select_type) { PGASetSelectType (*ftx, *select_type); } int pgagetselecttype_(PGAContext **ftx) { return PGAGetSelectType (*ftx); } void pgasetptournamentprob_(PGAContext **ftx, double *ptournament_prob) { PGASetPTournamentProb (*ftx, *ptournament_prob); } double pgagetptournamentprob_(PGAContext **ftx) { return PGAGetPTournamentProb (*ftx); } int pgadone_(PGAContext **ftx, MPI_Comm *comm) { return PGADone (*ftx, *comm); } int pgacheckstoppingconditions_(PGAContext **ftx) { return PGACheckStoppingConditions (*ftx); } void pgasetstoppingruletype_(PGAContext **ftx, int *stoprule) { PGASetStoppingRuleType (*ftx, *stoprule); } int pgagetstoppingruletype_(PGAContext **ftx) { return PGAGetStoppingRuleType (*ftx); } void pgasetmaxgaitervalue_(PGAContext **ftx, int *maxiter) { PGASetMaxGAIterValue (*ftx, *maxiter); } int pgagetmaxgaitervalue_(PGAContext **ftx) { return PGAGetMaxGAIterValue (*ftx); } void pgasetmaxnochangevalue_(PGAContext **ftx, int *max_no_change) { PGASetMaxNoChangeValue (*ftx, *max_no_change); } void pgasetmaxsimilarityvalue_(PGAContext **ftx, int *max_similarity) { PGASetMaxSimilarityValue (*ftx, *max_similarity); } void pgaerror_(PGAContext **ftx, char *msg, int *level, int *datatype, void **data, int len) /* FORTRAN implicitly passes the length of msg into len. */ { if (msg[len] != 0) msg[len] = 0; PGAError (*ftx, msg, *level, *datatype, *data); } void pgadestroy_(PGAContext **ftx) { PGADestroy (*ftx); } int pgagetmaxmachineintvalue_(PGAContext **ftx) { return PGAGetMaxMachineIntValue (*ftx); } int pgagetminmachineintvalue_(PGAContext **ftx) { return PGAGetMinMachineIntValue (*ftx); } double pgagetmaxmachinedoublevalue_(PGAContext **ftx) { return PGAGetMaxMachineDoubleValue (*ftx); } double pgagetminmachinedoublevalue_(PGAContext **ftx) { return PGAGetMinMachineDoubleValue (*ftx); } void pgausage_(PGAContext **ftx) { PGAUsage (*ftx); } void pgaprintversionnumber_(PGAContext **ftx) { PGAPrintVersionNumber (*ftx); } void pgasetuserfunction_(PGAContext **ftx, int *constant, void *f) { PGASetUserFunction(*ftx, *constant, f); } double pgamean_(PGAContext **ftx, double *a, int *n) { return PGAMean(*ftx, a, *n); } double pgastddev_(PGAContext **ftx, double *a, int *n, double *m) { return PGAStddev(*ftx, a, *n, *m); } int pgaround_(PGAContext **ftx, double *x) { return PGARound (*ftx, *x); } void pgacopyindividual_(PGAContext **ftx, int *i, int *p1, int *j, int *p2) { PGACopyIndividual(*ftx, *i == PGA_TEMP1 || *i == PGA_TEMP2 ? *i : *i-1, *p1, *j == PGA_TEMP1 || *j == PGA_TEMP2 ? *j : *j-1, *p2); } int pgachecksum_(PGAContext **ftx, int *p, int *pop) { return PGACheckSum(*ftx, *p == PGA_TEMP1 || *p == PGA_TEMP2 ? *p : *p-1, *pop); } int pgagetworstindex_(PGAContext **ftx, int *pop) { return PGAGetWorstIndex(*ftx, *pop) + 1; } int pgagetbestindex_(PGAContext **ftx, int *pop) { return PGAGetBestIndex(*ftx, *pop) + 1; } pgapack-1.1.1/source/Makefile.in0000644000175000017500000000472507034447274014562 0ustar eddeddCC = @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 pgapack-1.1.1/source/heap.c0000644000175000017500000001624210760674032013565 0ustar eddedd/* 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: heap.c: This file contains routines for sorting individuals for * selection * * Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle, * Brian P. Walenz *****************************************************************************/ #include /****************************************************************************** PGAAdjustHeap - Auxiliary routine called by PGA*HeapSort Category: Sorting Inputs: ctx - context variable a - array of values to be sorted idx - array of integer indices corresponding to the array a being sorted i - point of combination -- combine the node at a[i] with the two heaps at a[2i+1] and a[2i+2] to form a single heap. 0 <= i <= n-1. n - size of the arrays a and idx j - temporary variable, integer item - temporary variable, type must be same as a item_idx - temporary variable, integer Output: Example: ******************************************************************************/ #define PGAAdjustHeap(ctx, a, idx, i, n, j, item, item_idx) { \ item = a[i]; \ item_idx = idx[i]; \ j = 2*i+1; /* let j be the left child */ \ while (j < n) { \ if (j a[j+1]) \ j = j + 1; /* j is the larger child */ \ if (item <= a[j]) /* a position for item has been found */ \ break; \ a[(j-1)/2] = a[j]; /* move the larger child up a level */ \ idx[(j-1)/2] = idx[j]; \ j = j*2+1; \ } \ a[(j-1)/2] = item; \ idx[(j-1)/2] = item_idx; \ } \ /*I**************************************************************************** PGADblHeapSort - Uses a heapsort algorithm to sort from largest to smallest element. An integer array, intialized with the original indices of the elements of array a is sorted also so that the original locations are known Category: Sorting Inputs: ctx - context variable a - array of (double) values to be sorted idx - array of integer indices corresponding to the array a being sorted n - size of the arrays a and idx Output: The sorted arrays a and idx Example: The following code sorts the population by fitness PGAContext *ctx; int i,j,n,idx[LARGE] double a[LARGE]; : n = PGAGetPopsize(ctx); for(i=0;i=0; i--) PGAAdjustHeap(ctx, a, idx, i, n, j, item, item_idx); for ( i=n-1; i>=1; i--) /* interchange the new maximum with the */ { /* element at the end of the tree */ temp_a = a[i]; temp_idx = idx[i]; a[i] = a[0]; idx[i] = idx[0]; a[0] = temp_a; idx[0] = temp_idx; PGAAdjustHeap(ctx, a, idx, 0, i, j, item, item_idx); } PGADebugExited("PGADblHeapSort"); } /*I**************************************************************************** PGAIntHeapSort - Uses a heapsort algorithm to sort from largest to smallest element. An integer array, intialized with the original indices of the elements of array a is sorted also so that the original locations are known Category: Sorting Inputs: ctx - context variable a - array of (int) values to be sorted idx - array of integer indices corresponding to the array a being sorted n - size of the arrays a and idx Output: The sorted arrays a and idx Example: The following code sorts the population by fitness PGAContext *ctx; int i,j,n,idx[LARGE],a[LARGE]; : n = PGAGetPopsize(ctx); for(i=0;i=0; i--) PGAAdjustHeap(ctx, a, idx, i, n, j, item, item_idx); for ( i=n-1; i>=1; i--) /* interchange the new maximum with the */ { /* element at the end of the tree */ temp_a = a[i]; temp_idx = idx[i]; a[i] = a[0]; idx[i] = idx[0]; a[0] = temp_a; idx[0] = temp_idx; PGAAdjustHeap(ctx, a, idx, 0, i, j, item, item_idx); } PGADebugExited("PGAIntHeapSort"); } pgapack-1.1.1/source/binary.c0000644000175000017500000006632110760673665014152 0ustar eddedd/* 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; iga.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; wiga.fw; wi++) for(i=0; i 0 */ if (ctx->ga.eb > 0 ) for(i=0;iga.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> bix; child1[windex] = (~mask & parent1[windex])|(mask & parent2[windex]); child2[windex] = (~mask & parent2[windex])|(mask & parent1[windex]); for(i=windex+1;iga.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> bix2; mask = mask1 | mask2; child1[windex1] = (mask & parent1[windex1])|(~mask & parent2[windex1]); child2[windex1] = (mask & parent2[windex1])|(~mask & parent1[windex1]); for(i=windex1+1;iga.tw;i++) { child1[i] = parent1[i]; child2[i] = parent2[i]; } } else { /* cross sites in different words */ for(i=0;i> bix1; child1[windex1] = (~mask & parent1[windex1])|(mask & parent2[windex1]); child2[windex1] = (~mask & parent2[windex1])|(mask & parent1[windex1]); for(i=windex1+1; i> bix2; child1[windex2] = (mask & parent1[windex2])|(~mask & parent2[windex2]); child2[windex2] = (mask & parent2[windex2])|(~mask & parent1[windex2]); for(i=windex2+1; iga.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;wiga.tw;wi++) { if ( parent1[wi] == parent2[wi] ) { child1[wi] = parent1[wi]; child2[wi] = parent2[wi]; } else { mask = 0; for (j=0;jga.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; iga.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; wiga.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>=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"); } pgapack-1.1.1/source/user.c0000644000175000017500000001441310760674173013632 0ustar eddedd/* 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"); } pgapack-1.1.1/source/pop.c0000644000175000017500000003105410760674131013444 0ustar eddedd/* 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: pop.c: This file contains systme routines that act on entire * populations. * * Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle, * Brian P. Walenz *****************************************************************************/ #include "pgapack.h" /*U**************************************************************************** PGASortPop - Creates an (internal) array of indices according to one of three criteria. 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. Category: Generation Inputs: ctx - context variable popindex - symbolic constant of the population from which to create the srted array. Output: An inteneral array of indices sorted according to one of three criteria is created. 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); : ****************************************************************************U*/ void PGASortPop ( PGAContext *ctx, int pop ) { int i,j; PGADebugEntered("PGASortPop"); switch (ctx->ga.PopReplace) { case PGA_POPREPL_BEST: switch ( pop ) { case PGA_OLDPOP: for (i = 0 ; i < ctx->ga.PopSize ; i++ ) { ctx->ga.sorted[i] = i; ctx->scratch.dblscratch[i] = ctx->ga.oldpop[i].fitness; }; break; case PGA_NEWPOP: for (i = 0 ; i < ctx->ga.PopSize ; i++ ) { ctx->ga.sorted[i] = i; ctx->scratch.dblscratch[i] = ctx->ga.newpop[i].fitness; }; break; default: PGAError( ctx, "PGASort: Invalid value of pop:", PGA_FATAL, PGA_INT, (void *) &pop ); break; }; PGADblHeapSort ( ctx, ctx->scratch.dblscratch, ctx->ga.sorted, ctx->ga.PopSize ); break; case PGA_POPREPL_RANDOM_REP: if ((pop != PGA_OLDPOP) && (pop != PGA_NEWPOP)) PGAError( ctx, "PGASort: Invalid value of pop:", PGA_FATAL, PGA_INT, (void *) &pop ); for (i = 0; i < ctx->ga.PopSize; i++) { ctx->scratch.intscratch[i] = i; }; for (i = 0; i < ctx->ga.PopSize; i++) { j = PGARandomInterval ( ctx, 0, ctx->ga.PopSize-1 ); ctx->ga.sorted[i] = ctx->scratch.intscratch[j]; }; break; case PGA_POPREPL_RANDOM_NOREP: if ((pop != PGA_OLDPOP) && (pop != PGA_NEWPOP)) PGAError( ctx, "PGASort: Invalid value of pop:", PGA_FATAL, PGA_INT, (void *) &pop ); for (i = 0; i < ctx->ga.PopSize; i++) { ctx->scratch.intscratch[i] = i; }; for (i = 0; i < ctx->ga.PopSize; i++) { j = PGARandomInterval ( ctx, 0, ctx->ga.PopSize-i-1 ); ctx->ga.sorted[i] = ctx->scratch.intscratch[j]; ctx->scratch.intscratch[j] = ctx->scratch.intscratch[ctx->ga.PopSize-i-1]; }; break; } PGADebugExited("PGASortPop"); } /*U*************************************************************************** PGAGetPopSize - Returns the population size Category: Generation Inputs: ctx - context variable Outputs: The population size Example: PGAContext *ctx; int popsize; : popsize = PGAGetPopSize(ctx); ***************************************************************************U*/ int PGAGetPopSize (PGAContext *ctx) { PGADebugEntered("PGAGetPopSize"); PGAFailIfNotSetUp("PGAGetPopSize"); PGADebugExited("PGAGetPopSize"); return(ctx->ga.PopSize); } /*U*************************************************************************** PGAGetNumReplaceValue - Returns the maximum number of strings to replace each generation. Category: Generation Inputs: ctx - context variable Outputs: The maximum number number of strings to replace each generation Example: PGAContext *ctx; int numreplace; : numreplace = PGAGetNumReplaceValue(ctx); ***************************************************************************U*/ int PGAGetNumReplaceValue (PGAContext *ctx) { PGADebugEntered("PGAGetNumReplaceValue"); PGAFailIfNotSetUp("PGAGetNumReplaceValue"); PGADebugExited("PGAGetNumReplaceValue"); return(ctx->ga.NumReplace); } /*U*************************************************************************** PGAGetPopReplaceType - returns the symbolic constant used to determine which strings to copy from the old population to the new population. Category: Generation Inputs: ctx - context variable Outputs: The symbolic constant of the replacement strategy. Example: PGAContext *ctx; int popreplace; : popreplace = PGAGetPopReplaceType(ctx); switch (popreplace) { case PGA_POPREPL_BEST: printf("Replacement Strategy = PGA_POPREPL_BEST\n"); break; case PGA_POPREPL_RANDOM_REP: printf("Replacement Strategy = PGA_POPREPL_RANDOM_REP\n"); break; case PGA_POPREPL_RANDOM_NOREP: printf("Replacement Strategy = PGA_POPREPL_RANDOM_NOREP\n"); break; } ****************************************************************************U*/ int PGAGetPopReplaceType (PGAContext *ctx) { PGADebugEntered("PGAGetPopReplaceType"); PGAFailIfNotSetUp("PGAGetPopRelaceType"); PGADebugExited("PGAGetPopReplaceType"); return(ctx->ga.PopReplace); } /*U**************************************************************************** PGAGetSortedPopIndex - returns a population string index from the array created by PGASortPop(). Category: Generation Inputs: ctx - context variable n - specified which index element is to be returned. Output: A population string index from the array created by PGASortPop 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); : ****************************************************************************U*/ int PGAGetSortedPopIndex ( PGAContext *ctx, int n ) { int temp; PGADebugEntered("PGAGetSortedPopIndex"); if (n >= 0 && n < ctx->ga.PopSize ) temp = ctx->ga.sorted[n]; else PGAError( ctx, "PGAGetSorted: Invalid value of n:", PGA_FATAL, PGA_INT, (void *) &n ); PGADebugExited("PGAGetSortedPopIndex"); return (temp); } /*U**************************************************************************** PGASetPopSize - Specifies the size of the genetic algorithm population. The default population size is 100. Category: Generation Inputs: ctx - context variable popsize - the genetic algorithm population size to use Outputs: None Example: PGAContext *ctx; : PGASetPopSize(ctx, 200); ****************************************************************************U*/ void PGASetPopSize (PGAContext *ctx, int popsize) { PGADebugEntered("PGASetPopSize"); PGAFailIfSetUp("PGASetPopSize"); if (popsize < 1 || popsize % 2) PGAError( ctx, "PGASetPopSize: Invalid value of popsize:", PGA_FATAL, PGA_INT, (void *) &popsize ); else ctx->ga.PopSize = popsize; PGADebugExited("PGASetPopSize"); } /*U**************************************************************************** PGASetNumReplaceValue - specifies the number of new strings to create each generation. The default is ten percent of the population size Category: Generation Inputs: ctx - context variable pop_replace - the genetic algorithm population size to use Outputs: None Example: PGAContext *ctx; : PGASetNumReplaceValue(ctx, 35); ****************************************************************************U*/ void PGASetNumReplaceValue( PGAContext *ctx, int pop_replace) { PGADebugEntered("PGASetNumReplaceValue"); if (pop_replace < 0) PGAError( ctx, "PGASetNumReplaceValue: Invalid value of pop_replace:", PGA_FATAL, PGA_INT, (void *) &pop_replace ); else ctx->ga.NumReplace = pop_replace; PGADebugExited("PGASetNumReplaceValue"); } /*U**************************************************************************** PGASetPopReplaceType - Choose method of sorting strings to copy from old population to new population. 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. Category: Generation Inputs: ctx - context variable pop_replace - symbolic constant to specify the population replacement strategy Outputs: None Example: PGAContext *ctx; : PGASetPopReplaceType(ctx, PGA_POPREPL_RANDOM_NOREP); ****************************************************************************U*/ void PGASetPopReplaceType( PGAContext *ctx, int pop_replace) { PGADebugEntered("PGASetPopReplaceType"); switch (pop_replace) { case PGA_POPREPL_BEST: case PGA_POPREPL_RANDOM_NOREP: case PGA_POPREPL_RANDOM_REP: ctx->ga.PopReplace = pop_replace; break; default: PGAError ( ctx, "PGASetPopReplaceType: Invalid value of pop_replace:", PGA_FATAL, PGA_INT, (void *) &pop_replace); break; } PGADebugExited("PGASetPopReplaceType"); } pgapack-1.1.1/source/system.c0000644000175000017500000002320110760674170014170 0ustar eddedd/* 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