source: trunk/packages/optimizer/src/pgapack/pgapack/include/pgapack.h @ 1202

Last change on this file since 1202 was 1202, checked in by liveletlive, 14 years ago

Changes made to include the following items:
1) Hard restart
2) SBX
3) Random population replacement proportion
4) Definitions and macros for the above functions in pgapack.h

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