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

Last change on this file since 1018 was 816, checked in by liveletlive, 16 years ago

Committing the newer version of PGAPack.

File size: 38.4 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
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
234typedef 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*****************************************/
245typedef 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*****************************************/
293typedef struct PGAContext PGAContext;
294typedef 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
307typedef 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*****************************************/
321typedef 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*****************************************/
332typedef 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*****************************************/
346typedef 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*****************************************/
359typedef struct {
360    int PGADebugFlags[PGA_DEBUG_MAXFLAGS];
361} PGADebug;
362
363/*****************************************
364*      INITIALIZATION STRUCTURE          *
365*****************************************/
366typedef 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*****************************************/
382typedef struct {
383    int    *intscratch;            /* integer-scratch space                 */
384    double *dblscratch;            /* double- scratch space                 */
385} PGAScratch;
386
387/*****************************************
388*          CONTEXT STRUCTURE             *
389*****************************************/
390struct 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
406void PGASetBinaryAllele ( PGAContext *ctx, int p, int pop, int i, int val );
407int PGAGetBinaryAllele ( PGAContext *ctx, int p, int pop, int i );
408void PGASetBinaryInitProb ( PGAContext *ctx, double probability );
409double PGAGetBinaryInitProb (PGAContext *ctx);
410void PGABinaryCreateString(PGAContext *ctx, int p, int pop, int initflag);
411int PGABinaryMutation( PGAContext *ctx, int p, int pop, double mr );
412void PGABinaryOneptCrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1,
413                             int c2, int pop2);
414void PGABinaryTwoptCrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1,
415                             int c2, int pop2);
416void PGABinaryUniformCrossover(PGAContext *ctx, int p1, int p2, int pop1,
417                               int c1, int c2, int pop2);
418void PGABinaryPrintString( PGAContext *ctx, FILE *fp, int p, int pop );
419void PGABinaryCopyString (PGAContext *ctx, int p1, int pop1, int p2, int pop2);
420int PGABinaryDuplicate( PGAContext *ctx, int p1, int pop1, int p2, int pop2);
421void PGABinaryInitString(PGAContext *ctx, int p, int pop);
422MPI_Datatype PGABinaryBuildDatatype(PGAContext *ctx, int p, int pop);
423int PGABinaryHammingDistance ( PGAContext *ctx, PGABinary *s1, PGABinary *s2 );
424void PGABinaryPrint( PGAContext *ctx, FILE *fp, PGABinary *chrom, int nb );
425
426/*****************************************
427*          char.c
428*****************************************/
429
430void PGASetCharacterAllele (PGAContext *ctx, int p, int pop, int i, char value);
431char PGAGetCharacterAllele (PGAContext *ctx, int p, int pop, int i);
432void PGASetCharacterInitType(PGAContext *ctx, int value);
433void PGACharacterCreateString (PGAContext *ctx, int p, int pop, int InitFlag);
434int PGACharacterMutation( PGAContext *ctx, int p, int pop, double mr );
435void PGACharacterOneptCrossover(PGAContext *ctx, int p1, int p2, int pop1,
436                                int c1, int c2, int pop2);
437void PGACharacterTwoptCrossover( PGAContext *ctx, int p1, int p2, int pop1,
438                              int c1, int c2, int pop2);
439void PGACharacterUniformCrossover(PGAContext *ctx, int p1, int p2, int pop1,
440                                int c1, int c2, int pop2);
441void PGACharacterPrintString ( PGAContext *ctx, FILE *fp, int p, int pop);
442void PGACharacterCopyString (PGAContext *ctx, int p1, int pop1, int p2,
443                             int pop2);
444int PGACharacterDuplicate( PGAContext *ctx, int p1, int pop1, int p2, int pop2);
445void PGACharacterInitString(PGAContext *ctx, int p, int pop);
446MPI_Datatype PGACharacterBuildDatatype(PGAContext *ctx, int p, int pop);
447
448/*****************************************
449*          cmdline.c
450*****************************************/
451
452void PGAReadCmdLine( PGAContext *ctx, int *argc, char **argv );
453void PGAParseDebugArg(PGAContext *ctx, char *st);
454void PGAStripArgs(char **argv, int *argc, int *c, int num);
455
456/*****************************************
457*          create.c
458*****************************************/
459
460PGAContext *PGACreate ( int *argc, char **argv,
461                        int datatype, int len, int maxormin );
462void PGASetUp ( PGAContext *ctx );
463void PGASetRandomInitFlag(PGAContext *ctx, int RandomBoolean);
464int PGAGetRandomInitFlag (PGAContext *ctx);
465void PGACreatePop (PGAContext *ctx, int pop);
466void PGACreateIndividual (PGAContext *ctx, int p, int pop, int initflag);
467
468/*****************************************
469*          cross.c
470*****************************************/
471
472void PGACrossover ( PGAContext *ctx, int p1, int p2, int pop1,
473                    int c1, int c2, int pop2 );
474int PGAGetCrossoverType (PGAContext *ctx);
475double PGAGetCrossoverProb (PGAContext *ctx);
476double PGAGetUniformCrossoverProb (PGAContext *ctx);
477void PGASetCrossoverType (PGAContext *ctx, int crossover_type);
478void PGASetCrossoverProb( PGAContext *ctx, double crossover_prob);
479void PGASetUniformCrossoverProb( PGAContext *ctx, double uniform_cross_prob);
480
481/*****************************************
482*          debug.c
483*****************************************/
484
485void PGASortFuncNameIndex(PGAContext *ctx);
486#if OPTIMIZE==0
487void PGADebugPrint( PGAContext *ctx, int level, char *funcname,
488                   char *msg, int datatype, void *data );
489#endif
490void PGASetDebugLevel(PGAContext *ctx, int level);
491void PGAClearDebugLevel(PGAContext *ctx, int level);
492void PGASetDebugLevelByName(PGAContext *ctx, char *funcname);
493void PGAClearDebugLevelByName(PGAContext *ctx, char *funcname);
494int PGAGetDebugLevelOfName(PGAContext *ctx, char *funcname);
495int PGAGetDebugFlag(PGAContext *ctx, char *funcname);
496void PGASetDebugFlag11(PGAContext *ctx, int Flag);
497void PGASetDebugFlag20(PGAContext *ctx, int Flag);
498void PGASetDebugFlag21(PGAContext *ctx, int Flag);
499void PGASetDebugFlag30(PGAContext *ctx, int Flag);
500void PGASetDebugFlag32(PGAContext *ctx, int Flag);
501void PGASetDebugFlag34(PGAContext *ctx, int Flag);
502void PGASetDebugFlag36(PGAContext *ctx, int Flag);
503void PGASetDebugFlag40(PGAContext *ctx, int Flag);
504void PGASetDebugFlag42(PGAContext *ctx, int Flag);
505void PGASetDebugFlag44(PGAContext *ctx, int Flag);
506void PGASetDebugFlag46(PGAContext *ctx, int Flag);
507void PGASetDebugFlag48(PGAContext *ctx, int Flag);
508void PGASetDebugFlag50(PGAContext *ctx, int Flag);
509void PGASetDebugFlag52(PGAContext *ctx, int Flag);
510void PGASetDebugFlag54(PGAContext *ctx, int Flag);
511void PGASetDebugFlag56(PGAContext *ctx, int Flag);
512void PGASetDebugFlag58(PGAContext *ctx, int Flag);
513void PGASetDebugFlag60(PGAContext *ctx, int Flag);
514void PGASetDebugFlag62(PGAContext *ctx, int Flag);
515void PGASetDebugFlag64(PGAContext *ctx, int Flag);
516void PGASetDebugFlag66(PGAContext *ctx, int Flag);
517void PGAPrintDebugOptions(PGAContext *ctx);
518
519/*****************************************
520*          duplcate.c
521*****************************************/
522
523int PGADuplicate(PGAContext *ctx, int p, int pop1, int pop2, int n);
524void PGAChange( PGAContext *ctx, int p, int pop );
525void PGASetNoDuplicatesFlag( PGAContext *ctx, int no_dup);
526int PGAGetNoDuplicatesFlag (PGAContext *ctx);
527
528/*****************************************
529*          evaluate.c
530*****************************************/
531
532void PGASetEvaluation ( PGAContext *ctx, int p, int pop, double val );
533double PGAGetEvaluation ( PGAContext *ctx, int p, int pop );
534void PGASetEvaluationUpToDateFlag ( PGAContext *ctx, int p, int pop,
535                                   int status );
536int PGAGetEvaluationUpToDateFlag ( PGAContext *ctx, int p, int pop );
537double PGAGetRealFromBinary(PGAContext *ctx, int p, int pop, int start,
538                            int end, double lower, double upper);
539double PGAGetRealFromGrayCode(PGAContext *ctx, int p, int pop, int start,
540                                  int end, double lower, double upper);
541void PGAEncodeRealAsBinary(PGAContext *ctx, int p, int pop, int start,
542                               int end, double low, double high, double val);
543void PGAEncodeRealAsGrayCode(PGAContext *ctx, int p, int pop, int start,
544                              int end, double low, double high, double val);
545int PGAGetIntegerFromBinary(PGAContext *ctx, int p, int pop, int start,
546                                 int end);
547int PGAGetIntegerFromGrayCode(PGAContext *ctx, int p, int pop, int start,
548                                   int end);
549void PGAEncodeIntegerAsBinary(PGAContext *ctx, int p, int pop, int start,
550                              int end, int val);
551void PGAEncodeIntegerAsGrayCode(PGAContext *ctx, int p, int pop, int start,
552                                int end, int val);
553double PGAMapIntegerToReal (PGAContext *ctx, int v, int a, int b, double l,
554                            double u);
555int PGAMapRealToInteger(PGAContext *ctx, double r, double l, double u, int a,
556                        int b);
557
558/*****************************************
559*          fitness.c
560*****************************************/
561
562void PGAFitness ( PGAContext *ctx, int popindex );
563int PGARank( PGAContext *ctx, int p, int *order, int n );
564double PGAGetFitness ( PGAContext *ctx, int p, int pop );
565int PGAGetFitnessType (PGAContext *ctx);
566int PGAGetFitnessMinType (PGAContext *ctx);
567double PGAGetMaxFitnessRank (PGAContext *ctx);
568void PGASetFitnessType( PGAContext *ctx, int fitness_type);
569void PGASetFitnessMinType( PGAContext *ctx, int fitness_type);
570void PGASetMaxFitnessRank( PGAContext *ctx, double fitness_rank_max);
571void PGAFitnessLinearNormal ( PGAContext *ctx, PGAIndividual *pop );
572void PGAFitnessLinearRank ( PGAContext *ctx, PGAIndividual *pop );
573void PGAFitnessMinReciprocal ( PGAContext *ctx, PGAIndividual *pop );
574void PGAFitnessMinCmax ( PGAContext *ctx, PGAIndividual *pop );
575void PGASetFitnessCmaxValue( PGAContext *ctx, double val);
576double PGAGetFitnessCmaxValue (PGAContext *ctx);
577
578/*****************************************
579*          hamming.c
580*****************************************/
581
582double PGAHammingDistance( PGAContext *ctx, int popindex);
583
584/*****************************************
585*          heap.c
586*****************************************/
587
588void PGADblHeapSort ( PGAContext *ctx, double *a, int *idx, int n );
589void PGAIntHeapSort ( PGAContext *ctx, int *a, int *idx, int n );
590
591/*****************************************
592*          integer.c
593*****************************************/
594
595void PGASetIntegerAllele (PGAContext *ctx, int p, int pop, int i, int value);
596int PGAGetIntegerAllele (PGAContext *ctx, int p, int pop, int i);
597void PGASetIntegerInitPermute ( PGAContext *ctx, int min, int max);
598void PGASetIntegerInitRange (PGAContext *ctx, int *min, int *max);
599int PGAGetIntegerInitType (PGAContext *ctx);
600int PGAGetMinIntegerInitValue (PGAContext *ctx, int i);
601int PGAGetMaxIntegerInitValue (PGAContext *ctx, int i);
602void PGAIntegerCreateString (PGAContext *ctx, int p, int pop, int InitFlag);
603int PGAIntegerMutation( PGAContext *ctx, int p, int pop, double mr );
604void PGAIntegerOneptCrossover(PGAContext *ctx, int p1, int p2, int pop1,
605                              int c1, int c2, int pop2);
606void PGAIntegerTwoptCrossover( PGAContext *ctx, int p1, int p2, int pop1,
607                              int c1, int c2, int pop2);
608void PGAIntegerUniformCrossover(PGAContext *ctx, int p1, int p2, int pop1,
609                                int c1, int c2, int pop2);
610void PGAIntegerPrintString ( PGAContext *ctx, FILE *fp, int p, int pop);
611void PGAIntegerCopyString (PGAContext *ctx, int p1, int pop1, int p2, int pop2);
612int PGAIntegerDuplicate( PGAContext *ctx, int p1, int pop1, int p2, int pop2);
613void PGAIntegerInitString(PGAContext *ctx, int p, int pop);
614MPI_Datatype PGAIntegerBuildDatatype(PGAContext *ctx, int p, int pop);
615
616/*****************************************
617*          mpi_stub.c
618*****************************************/
619
620
621/*****************************************
622*          mutation.c
623*****************************************/
624
625int PGAMutate(PGAContext *ctx, int p, int pop);
626void PGASetMutationType( PGAContext *ctx, int mutation_type);
627int PGAGetMutationType (PGAContext *ctx);
628void PGASetMutationRealValue( PGAContext *ctx, double val);
629double PGAGetMutationRealValue (PGAContext *ctx);
630void PGASetMutationIntegerValue( PGAContext *ctx, int val);
631int PGAGetMutationIntegerValue (PGAContext *ctx);
632void PGASetMutationBoundedFlag(PGAContext *ctx, int val);
633int PGAGetMutationBoundedFlag(PGAContext *ctx);
634void PGASetMutationProb(PGAContext *ctx, double mutation_prob);
635double PGAGetMutationProb (PGAContext *ctx);
636
637/*****************************************
638*          parallel.c
639*****************************************/
640
641void PGARunGM(PGAContext *ctx, double (*f)(PGAContext *, int, int),
642              MPI_Comm comm);
643void PGAEvaluateSeq(PGAContext *ctx, int pop,
644                    double (*f)(PGAContext *, int, int));
645void PGAEvaluateCoop(PGAContext *ctx, int pop,
646                     double (*f)(PGAContext *, int, int), MPI_Comm comm);
647void PGAEvaluateMS(PGAContext *ctx, int pop,
648                   double (*f)(PGAContext *c, int p, int pop), MPI_Comm comm);
649void PGAEvaluateSlave(PGAContext *ctx, int pop,
650                      double (*f)(PGAContext *, int, int), MPI_Comm comm);
651void PGAEvaluate(PGAContext *ctx, int pop,
652                 double (*f)(PGAContext *, int, int), MPI_Comm comm);
653MPI_Datatype PGABuildDatatype(PGAContext *ctx, int p, int pop);
654void PGASendIndividual(PGAContext *ctx, int p, int pop, int dest, int tag,
655                       MPI_Comm comm);
656void PGAReceiveIndividual(PGAContext *ctx, int p, int pop, int source, int tag,
657                          MPI_Comm comm, MPI_Status *status);
658void 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);
662void PGARunIM(PGAContext *ctx, double (*f)(PGAContext *c, int p, int pop),
663              MPI_Comm tcomm);
664void PGARunNM(PGAContext *ctx, double (*f)(PGAContext *c, int p, int pop),
665              MPI_Comm tcomm);
666int PGAGetRank (PGAContext *ctx, MPI_Comm comm);
667int PGAGetNumProcs (PGAContext *ctx, MPI_Comm comm);
668void PGASetNumIslands( PGAContext *ctx, int n);
669int PGAGetNumIslands (PGAContext *ctx);
670void PGASetNumDemes( PGAContext *ctx, int numdemes);
671int PGAGetNumDemes (PGAContext *ctx);
672void PGASetCommunicator( PGAContext *ctx, MPI_Comm comm);
673MPI_Comm PGAGetCommunicator( PGAContext *ctx);
674
675/*****************************************
676*          pga.c
677*****************************************/
678
679void PGARun(PGAContext *ctx, double (*evaluate)(PGAContext *c, int p, int pop));
680void PGARunMutationAndCrossover (PGAContext *ctx, int oldpop, int newpop);
681void PGARunMutationOrCrossover ( PGAContext *ctx, int oldpop, int newpop );
682void PGAUpdateGeneration(PGAContext *ctx, MPI_Comm comm);
683int PGAGetDataType (PGAContext *ctx);
684int PGAGetOptDirFlag (PGAContext *ctx);
685int PGAGetStringLength (PGAContext *ctx);
686int PGAGetVariableStringLength (PGAContext *ctx, int p, int pop);
687int PGAGetGAIterValue (PGAContext *ctx);
688void PGASetMutationOrCrossoverFlag( PGAContext *ctx, int flag);
689void PGASetMutationAndCrossoverFlag( PGAContext *ctx, int flag);
690int PGAGetMutationOrCrossoverFlag (PGAContext *ctx);
691int PGAGetMutationAndCrossoverFlag (PGAContext *ctx);
692
693/*****************************************
694*          pop.c
695*****************************************/
696
697void PGASortPop ( PGAContext *ctx, int pop );
698int PGAGetPopSize (PGAContext *ctx);
699int PGAGetNumReplaceValue (PGAContext *ctx);
700int PGAGetPopReplaceType (PGAContext *ctx);
701int PGAGetSortedPopIndex ( PGAContext *ctx, int n );
702void PGASetPopSize (PGAContext *ctx, int popsize);
703void PGASetNumReplaceValue( PGAContext *ctx, int pop_replace);
704void PGASetPopReplaceType( PGAContext *ctx, int pop_replace);
705
706/*****************************************
707*          random.c
708*****************************************/
709
710int PGARandomFlip ( PGAContext *ctx, double p );
711int PGARandomInterval( PGAContext *ctx, int start, int end);
712double PGARandom01( PGAContext *ctx, int newseed );
713double PGARandomUniform( PGAContext *ctx, double start, double end);
714double PGARandomGaussian( PGAContext *ctx, double mean, double sigma);
715int PGAGetRandomSeed(PGAContext *ctx);
716void PGASetRandomSeed(PGAContext *ctx, int seed);
717
718/*****************************************
719*          real.c
720*****************************************/
721
722void PGASetRealAllele (PGAContext *ctx, int p, int pop, int i, double value);
723double PGAGetRealAllele (PGAContext *ctx, int p, int pop, int i);
724void PGASetRealInitPercent ( PGAContext *ctx, double *median, double *percent);
725void PGASetRealInitRange (PGAContext *ctx, double *min, double *max);
726double PGAGetMinRealInitValue (PGAContext *ctx, int i);
727double PGAGetMaxRealInitValue (PGAContext *ctx, int i);
728int PGAGetRealInitType (PGAContext *ctx);
729void PGARealCreateString (PGAContext *ctx, int p, int pop, int initflag);
730int PGARealMutation( PGAContext *ctx, int p, int pop, double mr );
731void PGARealOneptCrossover( PGAContext *ctx, int p1, int p2, int pop1,
732                           int c1, int c2, int pop2);
733void PGARealTwoptCrossover( PGAContext *ctx, int p1, int p2, int pop1,
734                           int c1, int c2, int pop2);
735void PGARealUniformCrossover( PGAContext *ctx, int p1, int p2, int pop1,
736                             int c1, int c2, int pop2);
737void PGARealPrintString (PGAContext *ctx, FILE *fp, int p, int pop);
738void PGARealCopyString ( PGAContext *ctx, int p1, int pop1, int p2, int pop2);
739int PGARealDuplicate( PGAContext *ctx, int p1, int pop1, int p2, int pop2);
740void PGARealInitString ( PGAContext *ctx, int p, int pop);
741MPI_Datatype PGARealBuildDatatype(PGAContext *ctx, int p, int pop);
742
743/*****************************************
744*          report.c
745*****************************************/
746
747void PGAPrintReport(PGAContext *ctx, FILE *fp, int pop);
748void PGASetPrintOptions (PGAContext *ctx, int option);
749void PGASetPrintFrequencyValue( PGAContext *ctx, int print_freq);
750int PGAGetPrintFrequencyValue (PGAContext *ctx);
751void PGAPrintPopulation ( PGAContext *ctx, FILE *fp, int pop );
752void PGAPrintIndividual ( PGAContext *ctx, FILE *fp, int p, int pop );
753void PGAPrintString ( PGAContext *ctx, FILE *file, int p, int pop );
754void PGAPrintContextVariable ( PGAContext *ctx, FILE *fp );
755
756/*****************************************
757*          restart.c
758*****************************************/
759
760void PGARestart(PGAContext *ctx, int source_pop, int dest_pop);
761void PGASetRestartFlag(PGAContext *ctx, int val);
762int PGAGetRestartFlag(PGAContext *ctx);
763void PGASetRestartFrequencyValue(PGAContext *ctx, int numiter);
764int PGAGetRestartFrequencyValue(PGAContext *ctx);
765void PGASetRestartAlleleChangeProb(PGAContext *ctx, double prob);
766double PGAGetRestartAlleleChangeProb(PGAContext *ctx);
767
768/*****************************************
769*          select.c
770*****************************************/
771
772void PGASelect( PGAContext *ctx, int popix );
773int PGASelectNextIndex ( PGAContext *ctx );
774void PGASetSelectType( PGAContext *ctx, int select_type);
775int PGAGetSelectType (PGAContext *ctx);
776void PGASetPTournamentProb(PGAContext *ctx, double ptournament_prob);
777double PGAGetPTournamentProb(PGAContext *ctx);
778int PGASelectProportional(PGAContext *ctx, PGAIndividual *pop);
779void PGASelectSUS( PGAContext *ctx, PGAIndividual *pop );
780int PGASelectTournament( PGAContext *ctx, PGAIndividual *pop );
781int PGASelectPTournament( PGAContext *ctx, PGAIndividual *pop );
782
783/*****************************************
784*          stop.c
785*****************************************/
786
787int PGADone(PGAContext *ctx, MPI_Comm comm);
788int PGACheckStoppingConditions( PGAContext *ctx);
789void PGASetStoppingRuleType (PGAContext *ctx, int stoprule);
790int PGAGetStoppingRuleType (PGAContext *ctx);
791void PGASetMaxGAIterValue(PGAContext *ctx, int maxiter);
792int PGAGetMaxGAIterValue (PGAContext *ctx);
793void PGASetMaxNoChangeValue(PGAContext *ctx, int max_no_change);
794void PGASetMaxSimilarityValue(PGAContext *ctx, int max_similarity);
795
796/*****************************************
797*          system.c
798*****************************************/
799
800void PGAError( PGAContext *ctx, char *msg,
801               int level, int datatype, void *data );
802void PGADestroy (PGAContext *ctx);
803int PGAGetMaxMachineIntValue (PGAContext *ctx);
804int PGAGetMinMachineIntValue (PGAContext *ctx);
805double PGAGetMaxMachineDoubleValue (PGAContext *ctx);
806double PGAGetMinMachineDoubleValue (PGAContext *ctx);
807void PGAUsage( PGAContext *ctx );
808void PGAPrintVersionNumber( PGAContext *ctx );
809
810/*****************************************
811*          user.c
812*****************************************/
813
814void PGASetUserFunction(PGAContext *ctx, int constant, void *f);
815
816/*****************************************
817*          utility.c
818*****************************************/
819
820double PGAMean ( PGAContext *ctx, double *a, int n);
821double PGAStddev ( PGAContext *ctx, double *a, int n, double mean);
822int PGARound(PGAContext *ctx, double x);
823void PGACopyIndividual( PGAContext *ctx, int p1, int pop1, int p2, int pop2);
824int PGACheckSum(PGAContext *ctx, int p, int pop);
825int PGAGetWorstIndex(PGAContext *ctx, int pop);
826int PGAGetBestIndex(PGAContext *ctx, int pop);
827PGAIndividual *PGAGetIndividual ( PGAContext *ctx, int p, int pop);
828void PGAUpdateAverage(PGAContext *ctx, int pop);
829void PGAUpdateOnline(PGAContext *ctx, int pop);
830void PGAUpdateOffline(PGAContext *ctx, int pop);
831int PGAComputeSimilarity(PGAContext *ctx, PGAIndividual *pop);
Note: See TracBrowser for help on using the repository browser.