1 /****************************************************************************** 2 * FILE: pgapack.h: This file contains all constant and structure 3 * definitions definitions for PGAPack as well as all 4 * function declarations. 5 * Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle, 6 * Brian P. Walenz 7 ******************************************************************************/ 8 #include <stdio.h> 9 #include <stdlib.h> 10 #include <math.h> 11 #include <time.h> 12 #include <limits.h> 13 #include <float.h> 14 #include <string.h> 15 #include <ctype.h> 16 #include <mpi.h> 17 18 19 /* If OPTIMIZED, remove various sanity checks, and debug output. 20 * 21 * PGADebugEntered(a) - Print a debug message about entering "a" 22 * PGADebugExited(a) - Print a debug message about exiting "a" 23 * PGAFailIfNotSetup(a) - Fail fatally if PGASetUp has not been called 24 * PGAFailIfSetup(a) - Fail fatally if PGASetUp has been called 25 * PGACheckDataType(a, D) - Fail fatally if the datatype is not D 26 */ 27 #ifndef OPTIMIZE 28 #define OPTIMIZE 0 29 #define PGADebugEntered(a) \ 30 PGADebugPrint(ctx, PGA_DEBUG_ENTERED, a, "Entered", PGA_VOID, NULL) 31 #define PGADebugExited(a) \ 32 PGADebugPrint(ctx, PGA_DEBUG_EXIT, a, "Exited", PGA_VOID, NULL) 33 #define PGAFailIfNotSetUp(Name) \ 34 if (ctx->sys.SetUpCalled == PGA_FALSE) \ 35 PGAError(ctx, "PGASetUp must be called before " Name, \ 36 PGA_FATAL, PGA_VOID, NULL) 37 #define PGAFailIfSetUp(Name) \ 38 if (ctx->sys.SetUpCalled == PGA_TRUE) \ 39 PGAError(ctx, Name " must be called before PGASetUp", PGA_FATAL, \ 40 PGA_VOID, NULL) 41 #define PGACheckDataType(Name, DataType) \ 42 if (ctx->ga.datatype != DataType) \ 43 PGAError(ctx, "DataType is incorrect for " Name,PGA_FATAL,PGA_VOID,NULL) 44 #else 45 #undef OPTIMIZE 46 #define OPTIMIZE 1 47 #define PGADebugPrint(a,b,c,x,y,z) ; 48 #define PGADebugEntered(a) ; 49 #define PGADebugExited(a) ; 50 #define PGAFailIfNotSetUp(Name) ; 51 #define PGAFailIfSetUp(Name) ; 52 #define PGACheckDataType(Name, DataType) ; 53 #endif 54 55 /***************************************** 56 * BINARY MACROS * 57 *****************************************/ 58 #ifndef WL 59 #error WL must be defined on the command line! 60 #endif 61 62 #define ONEL ((PGABinary)1) 63 #define BIT(x,y) (y&(ONEL<<((WL-1)-(x)))) /* true if bit is 1, */ 64 #define SET(x,y) (y|=(ONEL<<((WL-1)-(x)))) /* set a bit to 1 */ 65 #define UNSET(x,y) (y&=(~(ONEL<<((WL-1)-(x)))))/* set a bit to 0, clear */ 66 #define TOGGLE(x,y) (y^=(ONEL<<((WL-1)-(x)))) /* complement a bits value */ 67 #define INDEX(ix,bx,bit,WL) ix=bit/WL;bx=bit%WL /* map global column (bit) */ 68 /* to word (ix) and bit (bx) */ 69 70 /***************************************** 71 * ABSTRACT DATA TYPES * 72 *****************************************/ 73 #define PGA_DATATYPE_BINARY 1 /* Array of unsigned ints */ 74 /* parsed into bits : binary.c */ 75 #define PGA_DATATYPE_INTEGER 2 /* Array of ints : integer.c */ 76 #define PGA_DATATYPE_REAL 3 /* Array of doubles : real.c */ 77 #define PGA_DATATYPE_CHARACTER 4 /* Array of characters : character.c */ 78 #define PGA_DATATYPE_USER 5 /* --user defined-- */ 79 80 #define PGABinary unsigned long 81 #define PGAInteger signed long int 82 #define PGAReal double 83 #define PGACharacter signed char 84 85 #define PGA_INT 1 86 #define PGA_DOUBLE 2 87 #define PGA_CHAR 3 88 #define PGA_VOID 4 89 90 91 /***************************************** 92 * BOOLEANS * 93 *****************************************/ 94 #define PGA_TRUE 1 95 #define PGA_FALSE 0 96 97 /***************************************** 98 * FLAGS * 99 *****************************************/ 100 #define PGA_FATAL 1 101 #define PGA_WARNING 2 102 103 /***************************************** 104 * MISC CONSTANT * 105 *****************************************/ 106 #define PGA_TEMP1 -1138 107 #define PGA_TEMP2 -4239 108 109 #define PGA_OLDPOP -6728 110 #define PGA_NEWPOP -8376 111 112 #define PGA_UNINITIALIZED_INT -3827 113 #define PGA_UNINITIALIZED_DOUBLE -968.3827 114 115 /***************************************** 116 * DEBUG LEVELS * 117 *****************************************/ 118 #define PGA_DEBUG_ENTERED 12 119 #define PGA_DEBUG_EXIT 13 120 #define PGA_DEBUG_MALLOC 80 121 #define PGA_DEBUG_PRINTVAR 82 122 #define PGA_DEBUG_SEND 22 123 #define PGA_DEBUG_RECV 23 124 #define PGA_DEBUG_MAXPGAPACKFUNCTIONS 300 125 #define PGA_DEBUG_MAXFLAGS 1000 126 127 /***************************************** 128 * DIRECTION * 129 *****************************************/ 130 #define PGA_MAXIMIZE 1 /* specify direction for fitness calc */ 131 #define PGA_MINIMIZE 2 /* specify direction for fitness calc */ 132 133 /***************************************** 134 * STOPPING CRITERIA * 135 *****************************************/ 136 #define PGA_STOP_MAXITER 1 /* Stop: for maximum iterations */ 137 #define PGA_STOP_NOCHANGE 2 /* Stop: no change in best string */ 138 #define PGA_STOP_TOOSIMILAR 4 /* Stop: homogeneous population */ 139 140 /***************************************** 141 * CROSSOVER * 142 *****************************************/ 143 #define PGA_CROSSOVER_ONEPT 1 /* One point crossover */ 144 #define PGA_CROSSOVER_TWOPT 2 /* Two point crossover */ 145 #define PGA_CROSSOVER_UNIFORM 3 /* Uniform crossover */ 146 147 /***************************************** 148 * SELECTION * 149 *****************************************/ 150 #define PGA_SELECT_PROPORTIONAL 1 /* proportional selection */ 151 #define PGA_SELECT_SUS 2 /* stochastic universal selection */ 152 #define PGA_SELECT_TOURNAMENT 3 /* tournament selection */ 153 #define PGA_SELECT_PTOURNAMENT 4 /* probabilistic tournament selection */ 154 155 /***************************************** 156 * FITNESS * 157 *****************************************/ 158 #define PGA_FITNESS_RAW 1 /* use raw fitness (evaluation) */ 159 #define PGA_FITNESS_NORMAL 2 /* linear normalization fitness */ 160 #define PGA_FITNESS_RANKING 3 /* linear ranking fitness */ 161 162 /***************************************** 163 * FITNESS (MINIMIZATION) * 164 *****************************************/ 165 #define PGA_FITNESSMIN_RECIPROCAL 1 /* reciprocal fitness */ 166 #define PGA_FITNESSMIN_CMAX 2 /* cmax fitness */ 167 168 /***************************************** 169 * MUTATION * 170 *****************************************/ 171 #define PGA_MUTATION_CONSTANT 1 /* Real/Integer: Fixed value */ 172 #define PGA_MUTATION_RANGE 2 /* Real/Integer: Uniform range */ 173 #define PGA_MUTATION_UNIFORM 3 /* Real: +- Uniform random no. */ 174 #define PGA_MUTATION_GAUSSIAN 4 /* Real: +- Gaussian random no. */ 175 #define PGA_MUTATION_PERMUTE 5 /* Integer: Permutation (swap) */ 176 177 /***************************************** 178 * POPULATION REPLACEMENT * 179 *****************************************/ 180 #define PGA_POPREPL_BEST 1 /* Select best string */ 181 #define PGA_POPREPL_RANDOM_NOREP 2 /* Select random string w/o replacement*/ 182 #define PGA_POPREPL_RANDOM_REP 3 /* Select random string w/ replacement*/ 183 184 /**************************************** 185 * REPORT OPTIONS * 186 ****************************************/ 187 #define PGA_REPORT_ONLINE 1 /* Print the online analysis */ 188 #define PGA_REPORT_OFFLINE 2 /* Print the offline analysis */ 189 #define PGA_REPORT_HAMMING 4 /* Print the Hamming distance */ 190 #define PGA_REPORT_STRING 8 /* Print the string */ 191 #define PGA_REPORT_WORST 16 /* Print the worst individual */ 192 #define PGA_REPORT_AVERAGE 32 /* Print the average of the population */ 193 194 /***************************************** 195 * RANDOMIZER * 196 *****************************************/ 197 #define PGA_RINIT_PERCENT 1 /* real percent offset */ 198 #define PGA_RINIT_RANGE 2 /* real range */ 199 #define PGA_IINIT_PERMUTE 1 /* integer permutation */ 200 #define PGA_IINIT_RANGE 2 /* integer range (nonunique) */ 201 #define PGA_CINIT_LOWER 1 /* all lowercase letters */ 202 #define PGA_CINIT_UPPER 2 /* all uppercase letters */ 203 #define PGA_CINIT_MIXED 3 /* both upper and lower case letters */ 204 205 /***************************************** 206 * SET USER FUNCTION * 207 *****************************************/ 208 #define PGA_USERFUNCTION_CREATESTRING 1 209 #define PGA_USERFUNCTION_MUTATION 2 210 #define PGA_USERFUNCTION_CROSSOVER 3 211 #define PGA_USERFUNCTION_PRINTSTRING 4 212 #define PGA_USERFUNCTION_COPYSTRING 5 213 #define PGA_USERFUNCTION_DUPLICATE 6 214 #define PGA_USERFUNCTION_INITSTRING 7 215 #define PGA_USERFUNCTION_BUILDDATATYPE 8 216 #define PGA_USERFUNCTION_STOPCOND 9 217 #define PGA_USERFUNCTION_ENDOFGEN 10 218 #define PGA_NUM_USERFUNCTIONS 10 219 220 /***************************************** 221 * MPI SEND/RECV TAGS * 222 *****************************************/ 223 #define PGA_COMM_STRINGTOEVAL 1 /* MPI tag for sending string */ 224 #define PGA_COMM_EVALOFSTRING 2 /* MPI tag for returning evaluation */ 225 #define PGA_COMM_DONEWITHEVALS 3 /* MPI tag for ending parallel eval */ 226 227 228 229 230 /***************************************** 231 * INDIVIDUAL STRUTURE * 232 *****************************************/ 233 234 typedef struct { /* primary population data structure */ 235 double evalfunc; /* evaluation function value */ 236 double fitness; /* fitness function value */ 237 int evaluptodate; /* flag whether evalfunc is current */ 238 void *chrom; /* pointer to the GA string */ 239 } PGAIndividual; 240 241 242 /***************************************** 243 * GA ALGORITHM STRUCTURE * 244 *****************************************/ 245 typedef struct { 246 int datatype; /* data type: binary, integer, or real */ 247 int optdir; /* direction of optimization */ 248 int tw; /* total number of words, full + partial */ 249 int fw; /* number of full (WL length) words */ 250 int eb; /* number of extra bits in last NOT full word*/ 251 int PopSize; /* Number of strings to use */ 252 int StringLen; /* string lengths */ 253 int StoppingRule; /* Termination Criteria */ 254 int MaxIter; /* Maximum number of iterations to run */ 255 int MaxNoChange; /* # of iters with no change before stopping */ 256 int MaxSimilarity; /* % of pop the same before stopping */ 257 int NumReplace; /* Number of string to replace each gen */ 258 int PopReplace; /* Method of choosing ind.s to copy to newpop*/ 259 int iter; /* iteration (generation) counter */ 260 int ItersOfSame; /* # iters with no change in best */ 261 int PercentSame; /* % of pop that is homogeneous */ 262 int NoDuplicates; /* Don't allow duplicate strings */ 263 int CrossoverType; /* Type of crossover for genetic algorithm */ 264 int SelectType; /* Type of selection for genetic algorithm */ 265 int SelectIndex; /* index of Select for next two individuals */ 266 int FitnessType; /* Type of fitness transformation used */ 267 int FitnessMinType; /* Transformation for minimization problems */ 268 int MutateOnlyNoCross; /* Mutate only strings not from crossover */ 269 int MutationType; /* Type of mutation used */ 270 int MutateIntegerValue; /* Multiplier to mutate Integer strings with */ 271 int MutateBoundedFlag; /* Confine integer alleles to given range */ 272 double MutateRealValue; /* Multiplier to mutate Real strings with */ 273 double MutationProb; /* Starting mutation probability */ 274 double CrossoverProb; /* Crossover probability */ 275 double UniformCrossProb; /* Prob of bit select in uniform crossover */ 276 double PTournamentProb; /* Prob of selection in Prob. Tournament */ 277 double FitnessRankMax; /* MAX value for use in ranking */ 278 double FitnessCmaxValue; /* Cmax value used to convert minimizations */ 279 double restartAlleleProb;/* prob of changing an allele in a restart */ 280 int restart; /* whether to use the restart operator */ 281 int restartFreq; /* frequency with which to restart */ 282 int *selected; /* array of indices for selection */ 283 int *sorted; /* array of sorted individual indices */ 284 PGAIndividual *oldpop; /* pointer to population (old) */ 285 PGAIndividual *newpop; /* pointer to population (new) */ 286 } PGAAlgorithm; 287 288 289 290 /***************************************** 291 * OPERATIONS STRUCTURES * 292 *****************************************/ 293 typedef struct PGAContext PGAContext; 294 typedef struct { 295 void (*CreateString)(PGAContext *, int, int, int); 296 int (*Mutation)(PGAContext *, int, int, double); 297 void (*Crossover)(PGAContext *, int, int, int, int, int, int); 298 void (*PrintString)(PGAContext *, FILE *, int, int); 299 void (*CopyString)(PGAContext *, int, int, int, int); 300 int (*Duplicate)(PGAContext *, int, int, int, int); 301 void (*InitString)(PGAContext *, int, int); 302 MPI_Datatype (*BuildDatatype)(PGAContext *, int, int); 303 int (*StopCond)(PGAContext *); 304 void (*EndOfGen)(PGAContext *); 305 } PGACOperations; 306 307 typedef struct { 308 int (*Mutation)(void *, void *, void *, void *); 309 void (*Crossover)(void *, void *, void *, void *, void *, void *, void *); 310 void (*PrintString)(void *, void *, void *, void *); 311 void (*CopyString)(void *, void *, void *, void *, void *); 312 int (*Duplicate)(void *, void *, void *, void *, void *); 313 void (*InitString)(void *, void *, void *); 314 int (*StopCond)(void *); 315 void (*EndOfGen)(void *); 316 } PGAFortranOperations; 317 318 /***************************************** 319 * PARALLEL STRUCTURE * 320 *****************************************/ 321 typedef struct { 322 int MPIAlreadyInit; /* Flag whether MPI was previously initialized*/ 323 int NumIslands; /* Number of islands in island model */ 324 int NumDemes; /* Number of demes in neighborhood model */ 325 MPI_Comm DefaultComm; /* Default communicator for PGARun */ 326 int MPIStubLibrary; /* Boolean: real or stub version of MPI */ 327 } PGAParallel; 328 329 /***************************************** 330 * REPORT STRUCTURE * 331 *****************************************/ 332 typedef struct { 333 int PrintFreq; /* How often to print statistics reports*/ 334 int PrintOptions; 335 double Offline; 336 double Online; 337 double Average; 338 double Best; 339 time_t starttime; 340 } PGAReport; 341 342 343 /***************************************** 344 * SYSTEM STRUCTURE * 345 *****************************************/ 346 typedef struct { 347 int UserFortran; /* user routines in Fortran or C? */ 348 int SetUpCalled; /* has PGASetUp been called? */ 349 int PGAMaxInt; /* largest int of machine */ 350 int PGAMinInt; /* smallest int of machine */ 351 double PGAMaxDouble; /* largest double of machine */ 352 double PGAMinDouble; /* smallest double of machine */ 353 } PGASystem; 354 355 356 /***************************************** 357 * DEBUG STRUCTURE * 358 *****************************************/ 359 typedef struct { 360 int PGADebugFlags[PGA_DEBUG_MAXFLAGS]; 361 } PGADebug; 362 363 /***************************************** 364 * INITIALIZATION STRUCTURE * 365 *****************************************/ 366 typedef struct { 367 int RandomInit; /* flag whether to randomize strings */ 368 double BinaryProbability; /* probability that a Bit will be 1 */ 369 int RealType; /* type of real initialization */ 370 int IntegerType; /* type of integer initialization */ 371 int CharacterType; /* type of character initialization */ 372 int *IntegerMin; /* minimum of range of integers */ 373 int *IntegerMax; /* maximum of range of integers */ 374 double *RealMin; /* minimum of range of reals */ 375 double *RealMax; /* maximum of range of reals */ 376 int RandomSeed; /* integer to seed random numbers with */ 377 } PGAInitialize; 378 379 /***************************************** 380 * SCRATCH DATA STRUCTURES * 381 *****************************************/ 382 typedef struct { 383 int *intscratch; /* integer-scratch space */ 384 double *dblscratch; /* double- scratch space */ 385 } PGAScratch; 386 387 /***************************************** 388 * CONTEXT STRUCTURE * 389 *****************************************/ 390 struct PGAContext { 391 PGAAlgorithm ga; 392 PGACOperations cops; 393 PGAFortranOperations fops; 394 PGAParallel par; 395 PGAReport rep; 396 PGASystem sys; 397 PGADebug debug; 398 PGAInitialize init; 399 PGAScratch scratch; 400 }; 401 402 /***************************************** 403 * binary.c 404 *****************************************/ 405 406 void PGASetBinaryAllele ( PGAContext *ctx, int p, int pop, int i, int val ); 407 int PGAGetBinaryAllele ( PGAContext *ctx, int p, int pop, int i ); 408 void PGASetBinaryInitProb ( PGAContext *ctx, double probability ); 409 double PGAGetBinaryInitProb (PGAContext *ctx); 410 void PGABinaryCreateString(PGAContext *ctx, int p, int pop, int initflag); 411 int PGABinaryMutation( PGAContext *ctx, int p, int pop, double mr ); 412 void PGABinaryOneptCrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1, 413 int c2, int pop2); 414 void PGABinaryTwoptCrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1, 415 int c2, int pop2); 416 void PGABinaryUniformCrossover(PGAContext *ctx, int p1, int p2, int pop1, 417 int c1, int c2, int pop2); 418 void PGABinaryPrintString( PGAContext *ctx, FILE *fp, int p, int pop ); 419 void PGABinaryCopyString (PGAContext *ctx, int p1, int pop1, int p2, int pop2); 420 int PGABinaryDuplicate( PGAContext *ctx, int p1, int pop1, int p2, int pop2); 421 void PGABinaryInitString(PGAContext *ctx, int p, int pop); 422 MPI_Datatype PGABinaryBuildDatatype(PGAContext *ctx, int p, int pop); 423 int PGABinaryHammingDistance ( PGAContext *ctx, PGABinary *s1, PGABinary *s2 ); 424 void PGABinaryPrint( PGAContext *ctx, FILE *fp, PGABinary *chrom, int nb ); 425 426 /***************************************** 427 * char.c 428 *****************************************/ 429 430 void PGASetCharacterAllele (PGAContext *ctx, int p, int pop, int i, char value); 431 char PGAGetCharacterAllele (PGAContext *ctx, int p, int pop, int i); 432 void PGASetCharacterInitType(PGAContext *ctx, int value); 433 void PGACharacterCreateString (PGAContext *ctx, int p, int pop, int InitFlag); 434 int PGACharacterMutation( PGAContext *ctx, int p, int pop, double mr ); 435 void PGACharacterOneptCrossover(PGAContext *ctx, int p1, int p2, int pop1, 436 int c1, int c2, int pop2); 437 void PGACharacterTwoptCrossover( PGAContext *ctx, int p1, int p2, int pop1, 438 int c1, int c2, int pop2); 439 void PGACharacterUniformCrossover(PGAContext *ctx, int p1, int p2, int pop1, 440 int c1, int c2, int pop2); 441 void PGACharacterPrintString ( PGAContext *ctx, FILE *fp, int p, int pop); 442 void PGACharacterCopyString (PGAContext *ctx, int p1, int pop1, int p2, 443 int pop2); 444 int PGACharacterDuplicate( PGAContext *ctx, int p1, int pop1, int p2, int pop2); 445 void PGACharacterInitString(PGAContext *ctx, int p, int pop); 446 MPI_Datatype PGACharacterBuildDatatype(PGAContext *ctx, int p, int pop); 447 448 /***************************************** 449 * cmdline.c 450 *****************************************/ 451 452 void PGAReadCmdLine( PGAContext *ctx, int *argc, char **argv ); 453 void PGAParseDebugArg(PGAContext *ctx, char *st); 454 void PGAStripArgs(char **argv, int *argc, int *c, int num); 455 456 /***************************************** 457 * create.c 458 *****************************************/ 459 460 PGAContext *PGACreate ( int *argc, char **argv, 461 int datatype, int len, int maxormin ); 462 void PGASetUp ( PGAContext *ctx ); 463 void PGASetRandomInitFlag(PGAContext *ctx, int RandomBoolean); 464 int PGAGetRandomInitFlag (PGAContext *ctx); 465 void PGACreatePop (PGAContext *ctx, int pop); 466 void PGACreateIndividual (PGAContext *ctx, int p, int pop, int initflag); 467 468 /***************************************** 469 * cross.c 470 *****************************************/ 471 472 void PGACrossover ( PGAContext *ctx, int p1, int p2, int pop1, 473 int c1, int c2, int pop2 ); 474 int PGAGetCrossoverType (PGAContext *ctx); 475 double PGAGetCrossoverProb (PGAContext *ctx); 476 double PGAGetUniformCrossoverProb (PGAContext *ctx); 477 void PGASetCrossoverType (PGAContext *ctx, int crossover_type); 478 void PGASetCrossoverProb( PGAContext *ctx, double crossover_prob); 479 void PGASetUniformCrossoverProb( PGAContext *ctx, double uniform_cross_prob); 480 481 /***************************************** 482 * debug.c 483 *****************************************/ 484 485 void PGASortFuncNameIndex(PGAContext *ctx); 486 #if OPTIMIZE==0 487 void PGADebugPrint( PGAContext *ctx, int level, char *funcname, 488 char *msg, int datatype, void *data ); 489 #endif 490 void PGASetDebugLevel(PGAContext *ctx, int level); 491 void PGAClearDebugLevel(PGAContext *ctx, int level); 492 void PGASetDebugLevelByName(PGAContext *ctx, char *funcname); 493 void PGAClearDebugLevelByName(PGAContext *ctx, char *funcname); 494 int PGAGetDebugLevelOfName(PGAContext *ctx, char *funcname); 495 int PGAGetDebugFlag(PGAContext *ctx, char *funcname); 496 void PGASetDebugFlag11(PGAContext *ctx, int Flag); 497 void PGASetDebugFlag20(PGAContext *ctx, int Flag); 498 void PGASetDebugFlag21(PGAContext *ctx, int Flag); 499 void PGASetDebugFlag30(PGAContext *ctx, int Flag); 500 void PGASetDebugFlag32(PGAContext *ctx, int Flag); 501 void PGASetDebugFlag34(PGAContext *ctx, int Flag); 502 void PGASetDebugFlag36(PGAContext *ctx, int Flag); 503 void PGASetDebugFlag40(PGAContext *ctx, int Flag); 504 void PGASetDebugFlag42(PGAContext *ctx, int Flag); 505 void PGASetDebugFlag44(PGAContext *ctx, int Flag); 506 void PGASetDebugFlag46(PGAContext *ctx, int Flag); 507 void PGASetDebugFlag48(PGAContext *ctx, int Flag); 508 void PGASetDebugFlag50(PGAContext *ctx, int Flag); 509 void PGASetDebugFlag52(PGAContext *ctx, int Flag); 510 void PGASetDebugFlag54(PGAContext *ctx, int Flag); 511 void PGASetDebugFlag56(PGAContext *ctx, int Flag); 512 void PGASetDebugFlag58(PGAContext *ctx, int Flag); 513 void PGASetDebugFlag60(PGAContext *ctx, int Flag); 514 void PGASetDebugFlag62(PGAContext *ctx, int Flag); 515 void PGASetDebugFlag64(PGAContext *ctx, int Flag); 516 void PGASetDebugFlag66(PGAContext *ctx, int Flag); 517 void PGAPrintDebugOptions(PGAContext *ctx); 518 519 /***************************************** 520 * duplcate.c 521 *****************************************/ 522 523 int PGADuplicate(PGAContext *ctx, int p, int pop1, int pop2, int n); 524 void PGAChange( PGAContext *ctx, int p, int pop ); 525 void PGASetNoDuplicatesFlag( PGAContext *ctx, int no_dup); 526 int PGAGetNoDuplicatesFlag (PGAContext *ctx); 527 528 /***************************************** 529 * evaluate.c 530 *****************************************/ 531 532 void PGASetEvaluation ( PGAContext *ctx, int p, int pop, double val ); 533 double PGAGetEvaluation ( PGAContext *ctx, int p, int pop ); 534 void PGASetEvaluationUpToDateFlag ( PGAContext *ctx, int p, int pop, 535 int status ); 536 int PGAGetEvaluationUpToDateFlag ( PGAContext *ctx, int p, int pop ); 537 double PGAGetRealFromBinary(PGAContext *ctx, int p, int pop, int start, 538 int end, double lower, double upper); 539 double PGAGetRealFromGrayCode(PGAContext *ctx, int p, int pop, int start, 540 int end, double lower, double upper); 541 void PGAEncodeRealAsBinary(PGAContext *ctx, int p, int pop, int start, 542 int end, double low, double high, double val); 543 void PGAEncodeRealAsGrayCode(PGAContext *ctx, int p, int pop, int start, 544 int end, double low, double high, double val); 545 int PGAGetIntegerFromBinary(PGAContext *ctx, int p, int pop, int start, 546 int end); 547 int PGAGetIntegerFromGrayCode(PGAContext *ctx, int p, int pop, int start, 548 int end); 549 void PGAEncodeIntegerAsBinary(PGAContext *ctx, int p, int pop, int start, 550 int end, int val); 551 void PGAEncodeIntegerAsGrayCode(PGAContext *ctx, int p, int pop, int start, 552 int end, int val); 553 double PGAMapIntegerToReal (PGAContext *ctx, int v, int a, int b, double l, 554 double u); 555 int PGAMapRealToInteger(PGAContext *ctx, double r, double l, double u, int a, 556 int b); 557 558 /***************************************** 559 * fitness.c 560 *****************************************/ 561 562 void PGAFitness ( PGAContext *ctx, int popindex ); 563 int PGARank( PGAContext *ctx, int p, int *order, int n ); 564 double PGAGetFitness ( PGAContext *ctx, int p, int pop ); 565 int PGAGetFitnessType (PGAContext *ctx); 566 int PGAGetFitnessMinType (PGAContext *ctx); 567 double PGAGetMaxFitnessRank (PGAContext *ctx); 568 void PGASetFitnessType( PGAContext *ctx, int fitness_type); 569 void PGASetFitnessMinType( PGAContext *ctx, int fitness_type); 570 void PGASetMaxFitnessRank( PGAContext *ctx, double fitness_rank_max); 571 void PGAFitnessLinearNormal ( PGAContext *ctx, PGAIndividual *pop ); 572 void PGAFitnessLinearRank ( PGAContext *ctx, PGAIndividual *pop ); 573 void PGAFitnessMinReciprocal ( PGAContext *ctx, PGAIndividual *pop ); 574 void PGAFitnessMinCmax ( PGAContext *ctx, PGAIndividual *pop ); 575 void PGASetFitnessCmaxValue( PGAContext *ctx, double val); 576 double PGAGetFitnessCmaxValue (PGAContext *ctx); 577 578 /***************************************** 579 * hamming.c 580 *****************************************/ 581 582 double PGAHammingDistance( PGAContext *ctx, int popindex); 583 584 /***************************************** 585 * heap.c 586 *****************************************/ 587 588 void PGADblHeapSort ( PGAContext *ctx, double *a, int *idx, int n ); 589 void PGAIntHeapSort ( PGAContext *ctx, int *a, int *idx, int n ); 590 591 /***************************************** 592 * integer.c 593 *****************************************/ 594 595 void PGASetIntegerAllele (PGAContext *ctx, int p, int pop, int i, int value); 596 int PGAGetIntegerAllele (PGAContext *ctx, int p, int pop, int i); 597 void PGASetIntegerInitPermute ( PGAContext *ctx, int min, int max); 598 void PGASetIntegerInitRange (PGAContext *ctx, int *min, int *max); 599 int PGAGetIntegerInitType (PGAContext *ctx); 600 int PGAGetMinIntegerInitValue (PGAContext *ctx, int i); 601 int PGAGetMaxIntegerInitValue (PGAContext *ctx, int i); 602 void PGAIntegerCreateString (PGAContext *ctx, int p, int pop, int InitFlag); 603 int PGAIntegerMutation( PGAContext *ctx, int p, int pop, double mr ); 604 void PGAIntegerOneptCrossover(PGAContext *ctx, int p1, int p2, int pop1, 605 int c1, int c2, int pop2); 606 void PGAIntegerTwoptCrossover( PGAContext *ctx, int p1, int p2, int pop1, 607 int c1, int c2, int pop2); 608 void PGAIntegerUniformCrossover(PGAContext *ctx, int p1, int p2, int pop1, 609 int c1, int c2, int pop2); 610 void PGAIntegerPrintString ( PGAContext *ctx, FILE *fp, int p, int pop); 611 void PGAIntegerCopyString (PGAContext *ctx, int p1, int pop1, int p2, int pop2); 612 int PGAIntegerDuplicate( PGAContext *ctx, int p1, int pop1, int p2, int pop2); 613 void PGAIntegerInitString(PGAContext *ctx, int p, int pop); 614 MPI_Datatype PGAIntegerBuildDatatype(PGAContext *ctx, int p, int pop); 615 616 /***************************************** 617 * mpi_stub.c 618 *****************************************/ 619 620 621 /***************************************** 622 * mutation.c 623 *****************************************/ 624 625 int PGAMutate(PGAContext *ctx, int p, int pop); 626 void PGASetMutationType( PGAContext *ctx, int mutation_type); 627 int PGAGetMutationType (PGAContext *ctx); 628 void PGASetMutationRealValue( PGAContext *ctx, double val); 629 double PGAGetMutationRealValue (PGAContext *ctx); 630 void PGASetMutationIntegerValue( PGAContext *ctx, int val); 631 int PGAGetMutationIntegerValue (PGAContext *ctx); 632 void PGASetMutationBoundedFlag(PGAContext *ctx, int val); 633 int PGAGetMutationBoundedFlag(PGAContext *ctx); 634 void PGASetMutationProb(PGAContext *ctx, double mutation_prob); 635 double PGAGetMutationProb (PGAContext *ctx); 636 637 /***************************************** 638 * parallel.c 639 *****************************************/ 640 641 void PGARunGM(PGAContext *ctx, double (*f)(PGAContext *, int, int), 642 MPI_Comm comm); 643 void PGAEvaluateSeq(PGAContext *ctx, int pop, 644 double (*f)(PGAContext *, int, int)); 645 void PGAEvaluateCoop(PGAContext *ctx, int pop, 646 double (*f)(PGAContext *, int, int), MPI_Comm comm); 647 void PGAEvaluateMS(PGAContext *ctx, int pop, 648 double (*f)(PGAContext *c, int p, int pop), MPI_Comm comm); 649 void PGAEvaluateSlave(PGAContext *ctx, int pop, 650 double (*f)(PGAContext *, int, int), MPI_Comm comm); 651 void PGAEvaluate(PGAContext *ctx, int pop, 652 double (*f)(PGAContext *, int, int), MPI_Comm comm); 653 MPI_Datatype PGABuildDatatype(PGAContext *ctx, int p, int pop); 654 void PGASendIndividual(PGAContext *ctx, int p, int pop, int dest, int tag, 655 MPI_Comm comm); 656 void PGAReceiveIndividual(PGAContext *ctx, int p, int pop, int source, int tag, 657 MPI_Comm comm, MPI_Status *status); 658 void PGASendReceiveIndividual(PGAContext *ctx, int send_p, int send_pop, 659 int dest, int send_tag, int recv_p, int recv_pop, 660 int source, int recv_tag, MPI_Comm comm, 661 MPI_Status *status); 662 void PGARunIM(PGAContext *ctx, double (*f)(PGAContext *c, int p, int pop), 663 MPI_Comm tcomm); 664 void PGARunNM(PGAContext *ctx, double (*f)(PGAContext *c, int p, int pop), 665 MPI_Comm tcomm); 666 int PGAGetRank (PGAContext *ctx, MPI_Comm comm); 667 int PGAGetNumProcs (PGAContext *ctx, MPI_Comm comm); 668 void PGASetNumIslands( PGAContext *ctx, int n); 669 int PGAGetNumIslands (PGAContext *ctx); 670 void PGASetNumDemes( PGAContext *ctx, int numdemes); 671 int PGAGetNumDemes (PGAContext *ctx); 672 void PGASetCommunicator( PGAContext *ctx, MPI_Comm comm); 673 MPI_Comm PGAGetCommunicator( PGAContext *ctx); 674 675 /***************************************** 676 * pga.c 677 *****************************************/ 678 679 void PGARun(PGAContext *ctx, double (*evaluate)(PGAContext *c, int p, int pop)); 680 void PGARunMutationAndCrossover (PGAContext *ctx, int oldpop, int newpop); 681 void PGARunMutationOrCrossover ( PGAContext *ctx, int oldpop, int newpop ); 682 void PGAUpdateGeneration(PGAContext *ctx, MPI_Comm comm); 683 int PGAGetDataType (PGAContext *ctx); 684 int PGAGetOptDirFlag (PGAContext *ctx); 685 int PGAGetStringLength (PGAContext *ctx); 686 int PGAGetVariableStringLength (PGAContext *ctx, int p, int pop); 687 int PGAGetGAIterValue (PGAContext *ctx); 688 void PGASetMutationOrCrossoverFlag( PGAContext *ctx, int flag); 689 void PGASetMutationAndCrossoverFlag( PGAContext *ctx, int flag); 690 int PGAGetMutationOrCrossoverFlag (PGAContext *ctx); 691 int PGAGetMutationAndCrossoverFlag (PGAContext *ctx); 692 693 /***************************************** 694 * pop.c 695 *****************************************/ 696 697 void PGASortPop ( PGAContext *ctx, int pop ); 698 int PGAGetPopSize (PGAContext *ctx); 699 int PGAGetNumReplaceValue (PGAContext *ctx); 700 int PGAGetPopReplaceType (PGAContext *ctx); 701 int PGAGetSortedPopIndex ( PGAContext *ctx, int n ); 702 void PGASetPopSize (PGAContext *ctx, int popsize); 703 void PGASetNumReplaceValue( PGAContext *ctx, int pop_replace); 704 void PGASetPopReplaceType( PGAContext *ctx, int pop_replace); 705 706 /***************************************** 707 * random.c 708 *****************************************/ 709 710 int PGARandomFlip ( PGAContext *ctx, double p ); 711 int PGARandomInterval( PGAContext *ctx, int start, int end); 712 double PGARandom01( PGAContext *ctx, int newseed ); 713 double PGARandomUniform( PGAContext *ctx, double start, double end); 714 double PGARandomGaussian( PGAContext *ctx, double mean, double sigma); 715 int PGAGetRandomSeed(PGAContext *ctx); 716 void PGASetRandomSeed(PGAContext *ctx, int seed); 717 718 /***************************************** 719 * real.c 720 *****************************************/ 721 722 void PGASetRealAllele (PGAContext *ctx, int p, int pop, int i, double value); 723 double PGAGetRealAllele (PGAContext *ctx, int p, int pop, int i); 724 void PGASetRealInitPercent ( PGAContext *ctx, double *median, double *percent); 725 void PGASetRealInitRange (PGAContext *ctx, double *min, double *max); 726 double PGAGetMinRealInitValue (PGAContext *ctx, int i); 727 double PGAGetMaxRealInitValue (PGAContext *ctx, int i); 728 int PGAGetRealInitType (PGAContext *ctx); 729 void PGARealCreateString (PGAContext *ctx, int p, int pop, int initflag); 730 int PGARealMutation( PGAContext *ctx, int p, int pop, double mr ); 731 void PGARealOneptCrossover( PGAContext *ctx, int p1, int p2, int pop1, 732 int c1, int c2, int pop2); 733 void PGARealTwoptCrossover( PGAContext *ctx, int p1, int p2, int pop1, 734 int c1, int c2, int pop2); 735 void PGARealUniformCrossover( PGAContext *ctx, int p1, int p2, int pop1, 736 int c1, int c2, int pop2); 737 void PGARealPrintString (PGAContext *ctx, FILE *fp, int p, int pop); 738 void PGARealCopyString ( PGAContext *ctx, int p1, int pop1, int p2, int pop2); 739 int PGARealDuplicate( PGAContext *ctx, int p1, int pop1, int p2, int pop2); 740 void PGARealInitString ( PGAContext *ctx, int p, int pop); 741 MPI_Datatype PGARealBuildDatatype(PGAContext *ctx, int p, int pop); 742 743 /***************************************** 744 * report.c 745 *****************************************/ 746 747 void PGAPrintReport(PGAContext *ctx, FILE *fp, int pop); 748 void PGASetPrintOptions (PGAContext *ctx, int option); 749 void PGASetPrintFrequencyValue( PGAContext *ctx, int print_freq); 750 int PGAGetPrintFrequencyValue (PGAContext *ctx); 751 void PGAPrintPopulation ( PGAContext *ctx, FILE *fp, int pop ); 752 void PGAPrintIndividual ( PGAContext *ctx, FILE *fp, int p, int pop ); 753 void PGAPrintString ( PGAContext *ctx, FILE *file, int p, int pop ); 754 void PGAPrintContextVariable ( PGAContext *ctx, FILE *fp ); 755 756 /***************************************** 757 * restart.c 758 *****************************************/ 759 760 void PGARestart(PGAContext *ctx, int source_pop, int dest_pop); 761 void PGASetRestartFlag(PGAContext *ctx, int val); 762 int PGAGetRestartFlag(PGAContext *ctx); 763 void PGASetRestartFrequencyValue(PGAContext *ctx, int numiter); 764 int PGAGetRestartFrequencyValue(PGAContext *ctx); 765 void PGASetRestartAlleleChangeProb(PGAContext *ctx, double prob); 766 double PGAGetRestartAlleleChangeProb(PGAContext *ctx); 767 768 /***************************************** 769 * select.c 770 *****************************************/ 771 772 void PGASelect( PGAContext *ctx, int popix ); 773 int PGASelectNextIndex ( PGAContext *ctx ); 774 void PGASetSelectType( PGAContext *ctx, int select_type); 775 int PGAGetSelectType (PGAContext *ctx); 776 void PGASetPTournamentProb(PGAContext *ctx, double ptournament_prob); 777 double PGAGetPTournamentProb(PGAContext *ctx); 778 int PGASelectProportional(PGAContext *ctx, PGAIndividual *pop); 779 void PGASelectSUS( PGAContext *ctx, PGAIndividual *pop ); 780 int PGASelectTournament( PGAContext *ctx, PGAIndividual *pop ); 781 int PGASelectPTournament( PGAContext *ctx, PGAIndividual *pop ); 782 783 /***************************************** 784 * stop.c 785 *****************************************/ 786 787 int PGADone(PGAContext *ctx, MPI_Comm comm); 788 int PGACheckStoppingConditions( PGAContext *ctx); 789 void PGASetStoppingRuleType (PGAContext *ctx, int stoprule); 790 int PGAGetStoppingRuleType (PGAContext *ctx); 791 void PGASetMaxGAIterValue(PGAContext *ctx, int maxiter); 792 int PGAGetMaxGAIterValue (PGAContext *ctx); 793 void PGASetMaxNoChangeValue(PGAContext *ctx, int max_no_change); 794 void PGASetMaxSimilarityValue(PGAContext *ctx, int max_similarity); 795 796 /***************************************** 797 * system.c 798 *****************************************/ 799 800 void PGAError( PGAContext *ctx, char *msg, 801 int level, int datatype, void *data ); 802 void PGADestroy (PGAContext *ctx); 803 int PGAGetMaxMachineIntValue (PGAContext *ctx); 804 int PGAGetMinMachineIntValue (PGAContext *ctx); 805 double PGAGetMaxMachineDoubleValue (PGAContext *ctx); 806 double PGAGetMinMachineDoubleValue (PGAContext *ctx); 807 void PGAUsage( PGAContext *ctx ); 808 void PGAPrintVersionNumber( PGAContext *ctx ); 809 810 /***************************************** 811 * user.c 812 *****************************************/ 813 814 void PGASetUserFunction(PGAContext *ctx, int constant, void *f); 815 816 /***************************************** 817 * utility.c 818 *****************************************/ 819 820 double PGAMean ( PGAContext *ctx, double *a, int n); 821 double PGAStddev ( PGAContext *ctx, double *a, int n, double mean); 822 int PGARound(PGAContext *ctx, double x); 823 void PGACopyIndividual( PGAContext *ctx, int p1, int pop1, int p2, int pop2); 824 int PGACheckSum(PGAContext *ctx, int p, int pop); 825 int PGAGetWorstIndex(PGAContext *ctx, int pop); 826 int PGAGetBestIndex(PGAContext *ctx, int pop); 827 PGAIndividual *PGAGetIndividual ( PGAContext *ctx, int p, int pop); 828 void PGAUpdateAverage(PGAContext *ctx, int pop); 829 void PGAUpdateOnline(PGAContext *ctx, int pop); 830 void PGAUpdateOffline(PGAContext *ctx, int pop); 831 int PGAComputeSimilarity(PGAContext *ctx, PGAIndividual *pop); 832