source: trunk/packages/optimizer/src/pgapack/gekco/pgapack/examples/mgh/pgapackf.h @ 5673

Last change on this file since 5673 was 5673, checked in by ldelgass, 9 years ago

Fix line endings, set eol-style to native on all C/C++ sources.

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