source: trunk/optimizer/src/pgapack/pgapack/source/pga.c @ 986

Last change on this file since 986 was 986, checked in by gah, 15 years ago

added global pgapack_abort flag to plugin and abort operation to optimizer

File size: 23.4 KB
Line 
1/*
2 * 
3 *  *********************************************************************
4 *  (C) COPYRIGHT 1995 UNIVERSITY OF CHICAGO
5 *  *********************************************************************
6 * 
7 *  This software was authored by
8 * 
9 *  D. Levine
10 *  Mathematics and Computer Science Division Argonne National Laboratory
11 *  Argonne IL 60439
12 *  levine@mcs.anl.gov
13 *  (708) 252-6735
14 *  (708) 252-5986 (FAX)
15 * 
16 *  with programming assistance of participants in Argonne National
17 *  Laboratory's SERS program.
18 * 
19 *  This program contains material protectable under copyright laws of the
20 *  United States.  Permission is hereby granted to use it, reproduce it,
21 *  to translate it into another language, and to redistribute it to
22 *  others at no charge except a fee for transferring a copy, provided
23 *  that you conspicuously and appropriately publish on each copy the
24 *  University of Chicago's copyright notice, and the disclaimer of
25 *  warranty and Government license included below.  Further, permission
26 *  is hereby granted, subject to the same provisions, to modify a copy or
27 *  copies or any portion of it, and to distribute to others at no charge
28 *  materials containing or derived from the material.
29 * 
30 *  The developers of the software ask that you acknowledge its use in any
31 *  document referencing work based on the  program, such as published
32 *  research.  Also, they ask that you supply to Argonne National
33 *  Laboratory a copy of any published research referencing work based on
34 *  the software.
35 * 
36 *  Any entity desiring permission for further use must contact:
37 * 
38 *  J. Gleeson
39 *  Industrial Technology Development Center Argonne National Laboratory
40 *  Argonne IL 60439
41 *  gleesonj@smtplink.eid.anl.gov
42 *  (708) 252-6055
43 * 
44 *  ********************************************************************
45 *  DISCLAIMER
46 * 
47 *  THIS PROGRAM WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY
48 *  OF THE UNITED STATES GOVERNMENT.  NEITHER THE UNIVERSITY OF CHICAGO,
49 *  THE UNITED STATES GOVERNMENT NOR ANY OF THEIR EMPLOYEES MAKE ANY
50 *  WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR
51 *  RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, OR USEFULNESS OF ANY
52 *  INFORMATION OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT
53 *  INFRINGE PRIVATELY OWNED RIGHTS.
54 * 
55 *  **********************************************************************
56 *  GOVERNMENT LICENSE
57 * 
58 *  The Government is granted for itself and others acting on its behalf a
59 *  paid-up, non-exclusive, irrevocable worldwide license in this computer
60 *  software to reproduce, prepare derivative works, and perform publicly
61 *  and display publicly.
62 */
63
64/*****************************************************************************
65*     FILE: pga.c: This file contains all the routines that are data structure
66*                  neutral
67*
68*     Authors: David M. Levine, Philip L. Hallstrom, and David M. Noelle,
69*              Brian P. Walenz
70*****************************************************************************/
71
72#include "pgapack.h"
73#include <setjmp.h>
74
75jmp_buf pgapack_jmpbuf;
76
77/*U****************************************************************************
78  PGARun - Highest level routine to execute the genetic algorithm.  It
79  is called after PGACreate and PGASetup have been called.
80
81  Category: Generation
82
83  Inputs:
84    ctx      - context variable
85    evaluate - a pointer to the user's evaluation function, which must
86               have the calling sequence shown in the example.
87
88  Outputs:
89    none
90
91  Example:
92    PGAContext *ctx,
93    double f(PGAContext *ctx, int p, int pop);
94    :
95    ctx = PGACreate(&argc, argv, PGA_DATATYPE_BINARY, 100, PGA_MAXIMIZE);
96    PGASetUp(ctx);
97    PGARun(ctx, f);
98    PGADestroy(ctx);
99
100****************************************************************************U*/
101void PGARun(PGAContext *ctx, double (*evaluate)(PGAContext *c, int p, int pop))
102{
103     MPI_Comm comm;                  /* value of default communicator */
104     int nprocs;                     /* number of processes in above  */
105     int npops;                      /* number of populations         */
106     int ndemes;                     /* number of demes               */
107     
108
109     PGADebugEntered("PGARun");
110     PGAFailIfNotSetUp("PGARun");
111
112     comm   = PGAGetCommunicator(ctx);
113     nprocs = PGAGetNumProcs    (ctx, comm);
114     npops  = PGAGetNumIslands  (ctx);
115     ndemes = PGAGetNumDemes    (ctx);
116
117    if (setjmp(pgapack_jmpbuf)) {
118        return;                 /* PGA pack was aborted. */
119    }
120     /**********************************************************************/
121     /*              Global model, one island, one deme                    */
122     /**********************************************************************/
123     if ( (npops == 1) && (ndemes == 1) ) {
124         PGARunGM(ctx, evaluate, comm);
125     }
126     
127     /**********************************************************************/
128     /*              Island model, > one island, one deme                  */
129     /**********************************************************************/
130     else if( (npops > 1) && (ndemes == 1) ) {
131         if ( nprocs == 1 )
132             PGAError (ctx, "PGARun: island model with one process",
133                       PGA_FATAL, PGA_VOID, (void *) &nprocs);
134         if ( nprocs != npops) {
135             PGAError (ctx, "PGARun: island model no. processes != no. pops",
136                       PGA_FATAL, PGA_VOID, (void *) &nprocs);
137         }
138         PGARunIM(ctx,evaluate,comm);
139     }
140             
141     /**********************************************************************/
142     /*              Neighborhood model, one island, > one deme            */
143     /**********************************************************************/
144     else if( (npops == 1) && (ndemes > 1) ) {
145         if ( nprocs == 1 )
146             PGAError (ctx, "PGARun: neighborhood model with one process",
147                       PGA_FATAL, PGA_VOID, (void *) &nprocs);
148         if ( nprocs != ndemes)
149             PGAError (ctx, "PGARun: neighborhood model no. processes "
150                       "!= no. demes", PGA_FATAL, PGA_VOID, (void *) &nprocs);
151         PGARunNM(ctx,evaluate,comm);
152     }
153             
154     /**********************************************************************/
155     /*              Mixed model, > one island, > one deme                 */
156     /**********************************************************************/
157     else if( (npops > 1) && (ndemes > 1) ) {
158         PGAError (ctx, "PGARun: Cannot execute mixed models",
159                   PGA_FATAL, PGA_VOID, (void *) &nprocs);
160     }
161
162     /**********************************************************************/
163     /*                        E R R O R                                   */
164     /**********************************************************************/
165     else {
166         PGAError (ctx, "PGARun: Invalid combination of numislands,"
167                   "ndemes, and nprocs.",
168                   PGA_FATAL, PGA_VOID, (void *) &nprocs);
169     }
170
171     /**********************************************************************/
172     /*                         E X I T                                    */
173     /**********************************************************************/
174     PGADebugExited("PGARun");
175     return;
176 }
177
178
179/*U****************************************************************************
180  PGARunMutationAndCrossover - Performs crossover and mutation from one
181  population to create the next.  Assumes PGASelect has been called.
182
183  Category: Generation
184
185  Inputs:
186    ctx - context variable
187    oldpop - symbolic constant of old population
188    newpop - symbolic constant of new population
189
190  Outputs:
191    newpop is modified by side-effect.
192
193  Example:
194     PGAContext *ctx,
195    :
196    PGARunMutationAndCrossover(ctx, PGA_OLDPOP, PGA_NEWPOP);
197
198****************************************************************************U*/
199void PGARunMutationAndCrossover (PGAContext *ctx, int oldpop, int newpop)
200{
201    int i, j, n, m1, m2;
202    int popsize, numreplace;
203    double pc;
204
205    PGADebugEntered("PGARunMutationAndCrossover");
206
207    popsize = PGAGetPopSize(ctx);
208    numreplace = PGAGetNumReplaceValue(ctx);
209    /*** first, copy n best strings (sorted by fitness) to new pop ***/
210    PGASortPop( ctx, oldpop );
211    n = popsize - numreplace;
212    for ( i=0; i < n; i++ ) {
213        j = PGAGetSortedPopIndex( ctx, i );
214        PGACopyIndividual ( ctx, j, oldpop, i, newpop );
215    }
216    pc = PGAGetCrossoverProb(ctx);
217    /*** reproduce to create the rest of the new population ***/
218    while ( n < popsize) {
219        m1 = PGASelectNextIndex( ctx );
220        m2 = PGASelectNextIndex( ctx );
221        if ( PGARandomFlip(ctx, pc) ) {
222             PGACrossover ( ctx, m1, m2, oldpop, PGA_TEMP1,
223                            PGA_TEMP2, newpop);
224
225              /*** mutate and copy first string to new population ***/
226              PGAMutate ( ctx, PGA_TEMP1, newpop);
227              while (PGADuplicate( ctx, PGA_TEMP1, newpop, newpop, n))
228                   PGAChange ( ctx, PGA_TEMP1, newpop );
229              PGACopyIndividual ( ctx, PGA_TEMP1, newpop, n, newpop);
230              n++;
231
232              if ( n < popsize ) {
233              /*** mutate and copy second string to new population ***/
234              PGAMutate ( ctx, PGA_TEMP2, newpop);
235              while ( PGADuplicate( ctx, PGA_TEMP2, newpop, newpop, n))
236                   PGAChange ( ctx, PGA_TEMP2, newpop );
237              PGACopyIndividual ( ctx, PGA_TEMP2, newpop, n, newpop);
238              n++;
239              }
240         }
241         else {
242            PGACopyIndividual ( ctx, m1, oldpop, n, newpop );
243            n++;
244            if ( n < ctx->ga.PopSize ) {
245                PGACopyIndividual ( ctx, m2, oldpop, n, newpop );
246                n++;
247            }
248       }
249    }
250
251    PGADebugExited("PGARunMutationAndCrossover");
252}
253
254
255/*U****************************************************************************
256  PGARunMutationOrCrossover - Performs crossover or mutation (but not both)
257  from one populationto create the next.  Assumes PGASelect has been called.
258
259  Category: Generation
260
261  Inputs:
262    ctx - context variable
263    oldpop - symbolic constant of old population
264    newpop - symbolic constant of new population
265
266  Outputs:
267    newpop is modified by side-effect.
268
269  Example:
270    PGAContext *ctx,
271    :
272    PGARunMutationOrCrossover(ctx, PGA_OLDPOP, PGA_NEWPOP);
273
274****************************************************************************U*/
275void PGARunMutationOrCrossover ( PGAContext *ctx, int oldpop, int newpop )
276{
277    int i, j, n, m1, m2;
278    int popsize, numreplace;
279    double pc;
280
281    PGADebugEntered("PGARunMutationOrCrossover");
282
283    popsize = PGAGetPopSize(ctx);
284    numreplace = PGAGetNumReplaceValue(ctx);
285    /*** first, copy n best strings (sorted by fitness) to new pop ***/
286    PGASortPop( ctx, oldpop );
287    n = popsize - numreplace;
288    for ( i=0; i < n; i++ ) {
289        j = PGAGetSortedPopIndex( ctx, i );
290        PGACopyIndividual ( ctx, j, oldpop, i, newpop );
291    }
292    pc = PGAGetCrossoverProb(ctx);
293    /*** reproduce to create the rest of the new population ***/
294    while ( n < popsize ) {
295        m1 = PGASelectNextIndex( ctx );
296        m2 = PGASelectNextIndex( ctx );
297        if ( PGARandomFlip(ctx, pc) ) {
298            PGACrossover ( ctx, m1, m2, oldpop, PGA_TEMP1,
299                                        PGA_TEMP2, newpop);
300
301            /*** copy first string to new population ***/
302            while (PGADuplicate(ctx, PGA_TEMP1, newpop,  newpop, n))
303                PGAChange ( ctx, PGA_TEMP1, newpop );
304            PGACopyIndividual ( ctx, PGA_TEMP1, newpop, n, newpop);
305            n++;
306
307            if ( n < popsize )
308            {
309                 /*** copy second string to new population ***/
310                 while (PGADuplicate(ctx, PGA_TEMP2, newpop,  newpop, n))
311                      PGAChange ( ctx, PGA_TEMP2, newpop );
312                 PGACopyIndividual ( ctx, PGA_TEMP2, newpop, n, newpop);
313                 n++;
314            }
315        }
316        else
317        {
318             PGACopyIndividual(ctx, m1, oldpop, PGA_TEMP1, newpop);
319             PGAMutate ( ctx, PGA_TEMP1, newpop );
320             while (PGADuplicate(ctx, PGA_TEMP1, newpop, newpop, n ))
321                  PGAChange ( ctx, PGA_TEMP1, newpop );
322             PGACopyIndividual ( ctx, PGA_TEMP1, newpop, n, newpop);
323             n++;
324
325             if ( n < popsize ) {
326                  PGACopyIndividual(ctx, m2, oldpop, PGA_TEMP2, newpop);
327                  PGAMutate ( ctx, PGA_TEMP2, newpop );
328                  while (PGADuplicate(ctx, PGA_TEMP2, newpop, newpop, n ))
329                       PGAChange ( ctx, PGA_TEMP2, newpop );
330                  PGACopyIndividual ( ctx, PGA_TEMP2, newpop, n, newpop);
331                  n++;
332             }
333        }
334    }
335
336    PGADebugExited("PGARunMutationOrCrossover");
337}
338
339
340/*U****************************************************************************
341  PGAUpdateGeneration - updates internal data structures for the next
342  genetic algorithm iteration, and checks if the termination conditions, both
343  user and PGAPack, have been met.  This routine must be called by both
344  master and slave processes at the end of each GA generation.
345
346  Category: Generation
347
348  Inputs:
349     ctx  - context variable
350     comm - an MPI communicator
351
352  Outputs:
353     PGA_TRUE if the genetic algorithm has terminated, otherwise PGA_FALSE.
354
355  Example:
356    PGAContext *ctx;
357    :
358    PGAUpdateGeneration(ctx, MPI_COMM_WORLD);
359
360****************************************************************************U*/
361void PGAUpdateGeneration(PGAContext *ctx, MPI_Comm comm)
362{
363    PGAIndividual *temp;
364    int i, rank;
365
366    PGADebugEntered("PGAUpdateGeneration");
367    PGADebugPrint( ctx, PGA_DEBUG_PRINTVAR,"PGAUpdateGeneration",
368                  "ga.iter = ", PGA_INT, (void *) &(ctx->ga.iter) );
369
370    rank = PGAGetRank(ctx, comm);
371
372    ctx->ga.iter++;
373
374    if (rank == 0) {
375        if (ctx->rep.PrintOptions & PGA_REPORT_AVERAGE)
376            PGAUpdateAverage(ctx, PGA_NEWPOP);
377
378        if (ctx->rep.PrintOptions & PGA_REPORT_ONLINE)
379            PGAUpdateOnline(ctx, PGA_NEWPOP);
380
381        if (ctx->rep.PrintOptions & PGA_REPORT_OFFLINE)
382            PGAUpdateOffline(ctx, PGA_NEWPOP);
383
384        if ((ctx->ga.StoppingRule & PGA_STOP_NOCHANGE) || ctx->ga.restart) {
385            i = PGAGetBestIndex(ctx, PGA_NEWPOP);
386            if (ctx->rep.Best == PGAGetEvaluation(ctx, i, PGA_NEWPOP))
387                ctx->ga.ItersOfSame++;
388            else {
389                ctx->rep.Best = PGAGetEvaluation(ctx, i, PGA_NEWPOP);
390                ctx->ga.ItersOfSame = 1;
391            }
392        }
393
394        if (ctx->ga.StoppingRule & PGA_STOP_TOOSIMILAR)
395            ctx->ga.PercentSame = PGAComputeSimilarity(ctx, ctx->ga.newpop);
396
397        /*  Clear this twice in case the user EOG calls PGASelect.  */
398        ctx->ga.SelectIndex = 0;
399
400        if (ctx->fops.EndOfGen)
401            (*ctx->fops.EndOfGen)(&ctx);
402        if (ctx->cops.EndOfGen)
403            (*ctx->cops.EndOfGen)(ctx);
404
405        ctx->ga.SelectIndex = 0;
406        temp           = ctx->ga.oldpop;
407        ctx->ga.oldpop = ctx->ga.newpop;
408        ctx->ga.newpop = temp;
409    }
410
411    PGADebugExited("PGAUpdateGeneration");
412}
413
414
415/*U***************************************************************************
416   PGAGetDataType - Returns the data type used by the given context.
417
418   Category: Generation
419
420   Inputs:
421      ctx - context variable
422
423   Outputs:
424      Returns the integer corresponding to the symbolic constant
425      used to specify the data type.
426
427   Example:
428      PGAContext *ctx;
429      int datatype;
430      :
431      datatype = PGAGetDataType(ctx);
432      switch (datatype) {
433      case PGA_DATATYPE_BINARY:
434          printf("Data Type = PGA_DATATYPE_BINARY\n");
435          break;
436      case PGA_DATATYPE_CHARACTER:
437          printf("Data Type = PGA_DATATYPE_CHARACTER\n");
438          break;
439      case PGA_DATATYPE_INTEGER:
440          printf("Data Type = PGA_DATATYPE_INTEGER\n");
441          break;
442      case PGA_DATATYPE_REAL:
443          printf("Data Type = PGA_DATATYPE_REAL\n");
444          break;
445      case PGA_DATATYPE_USER:
446          printf("Data Type = PGA_DATATYPE_USER\n");
447          break;
448      }
449
450***************************************************************************U*/
451int PGAGetDataType (PGAContext *ctx)
452{
453    PGADebugEntered("PGAGetDataType");
454
455    PGADebugExited("PGAGetDataType");
456
457    return(ctx->ga.datatype);
458}
459
460/*U***************************************************************************
461   PGAGetOptDirFlag - Returns a symbolic constant that represents the
462   direction of optimization
463
464   Category: Generation
465
466   Inputs:
467      ctx - context variable
468
469   Outputs:
470      Returns the integer corresponding to the symbolic constant
471      used to specify the  direction of optimization
472
473   Example:
474      PGAContext *ctx;
475      int optdir;
476      :
477      optdir = PGAGetOptDirFlag(ctx);
478      switch (optdir) {
479      case PGA_MAXIMIZE:
480          printf("Optimization direction = PGA_MAXIMIZE\n");
481          break;
482      case PGA_MINIMIZE:
483          printf("Optimization direction = PGA_MINIMIZE\n");
484          break;
485      }
486
487***************************************************************************U*/
488int PGAGetOptDirFlag (PGAContext *ctx)
489{
490    PGADebugEntered("PGAGetOptDirFlag");
491
492    PGADebugExited("PGAGetOptDirFlag");
493
494    return(ctx->ga.optdir);
495}
496
497/*U***************************************************************************
498   PGAGetStringLength - Returns the string length
499
500   Category: Generation
501
502   Inputs:
503      ctx - context variable
504
505   Outputs:
506      The string length
507
508   Example:
509      PGAContext *ctx;
510      int stringlen;
511      :
512      stringlen = PGAGetStringLength(ctx);
513
514***************************************************************************U*/
515int PGAGetStringLength (PGAContext *ctx)
516{
517    PGADebugEntered("PGAGetStringLength");
518
519    PGADebugExited("PGAGetStringLength");
520
521    return(ctx->ga.StringLen);
522}
523
524/*I***************************************************************************
525   PGAGetVariableStringLength - Returns the length of a variable length
526   string.
527
528   Category: Generation
529
530   Inputs:
531      ctx - context variable
532      p   - index into the population
533      pop - symbolic constant for the population
534
535   Outputs:
536      The string length
537
538   Example:
539      PGAContext *ctx;
540      int stringlen;
541      :
542      stringlen = PGAGetVariableStringLength(ctx, 0, PGA_NEWPOP);
543
544***************************************************************************I*/
545int PGAGetVariableStringLength (PGAContext *ctx, int p, int pop)
546{
547    PGADebugEntered("PGAGetVariableStringLength");
548
549    PGADebugExited("PGAGetVariableStringLength");
550
551    PGAError(ctx, "PGAGetVariableStringLength:  Variable length strings not "
552             "currently supported.", PGA_FATAL, PGA_VOID, NULL);
553#if 0
554    ind = PGAGetIndividual(ctx, p, pop);
555    return(ind->StringLength);
556#endif
557    /*  Make the compilers be quiet.  */
558    return(0);
559}
560
561/*U***************************************************************************
562  PGAGetGAIterValue - returns the number of the current genetic
563  algorithm generation
564
565   Category: Generation
566
567   Inputs:
568      ctx - context variable
569
570   Outputs:
571      The genetic algorithm generation number
572
573   Example:
574      PGAContext *ctx;
575      int g;
576      :
577      g = PGAGetGAIterValue(ctx);
578
579***************************************************************************U*/
580int PGAGetGAIterValue (PGAContext *ctx)
581{
582    PGADebugEntered("PGAGetGAIterValue");
583    PGAFailIfNotSetUp("PGAGetGAIterValue");
584
585    PGADebugExited("PGAGetGAIterValue");
586
587    return(ctx->ga.iter);
588}
589
590/*U****************************************************************************
591  PGASetMutationOrCrossoverFlag - A boolean flag to indicate if recombination
592  uses exactly one of crossover or mutation on selected strings.
593
594   Category: Generation
595
596   Inputs:
597      ctx  - context variable
598      flag - PGA_TRUE (default) or PGA_FALSE
599
600   Outputs:
601      None
602
603   Example:
604      Set the genetic algorithm to use mutation only when crossover is
605      not used.
606
607      PGAContext *ctx;
608      :
609      PGASetMutationOrCrossoverFlag(ctx,PGA_FALSE);
610
611****************************************************************************U*/
612void PGASetMutationOrCrossoverFlag( PGAContext *ctx, int flag)
613{
614    PGADebugEntered("PGASetMutationOrCrossoverFlag");
615
616     switch (flag)
617     {
618     case PGA_TRUE:
619     case PGA_FALSE:
620          ctx->ga.MutateOnlyNoCross = flag;
621          break;
622     default:
623          PGAError (ctx, "PGASetMutationOrCrossoverFlag: Invalid value of "
624                    "flag:", PGA_FATAL, PGA_INT, (void *) &flag);
625          break;
626     }
627
628    PGADebugExited("PGASetMutationOrCrossoverFlag");
629}
630
631/*U****************************************************************************
632  PGASetMutationAndCrossoverFlag - A boolean flag to indicate if
633  recombination uses both crossover and mutation on selected strings
634
635   Category: Generation
636
637   Inputs:
638      ctx  - context variable
639      flag - PGA_TRUE (default) or PGA_FALSE
640
641   Outputs:
642      None
643
644   Example:
645      Set the genetic algorithm to use both crossover and mutation when
646      reproducing strings.
647
648      PGAContext *ctx;
649      :
650      PGASetMutationAndCrossoverFlag(ctx,PGA_FALSE);
651
652****************************************************************************U*/
653void PGASetMutationAndCrossoverFlag( PGAContext *ctx, int flag)
654{
655    PGADebugEntered("PGASetMutationAndCrossoverFlag");
656
657     switch (flag)
658     {
659     case PGA_TRUE:
660     case PGA_FALSE:
661          ctx->ga.MutateOnlyNoCross = !flag;
662          break;
663     default:
664          PGAError (ctx, "PGASetMutationAndCrossoverFlag: Invalid value of "
665                    "flag:", PGA_FATAL, PGA_INT, (void *) &flag);
666          break;
667     }
668
669    PGADebugExited("PGASetMutationAndCrossoverFlag");
670}
671/*U***************************************************************************
672   PGAGetMutationOrCrossoverFlag - Returns true if mutation only occurs when
673   crossover does not.
674
675   Category: Generation
676
677   Inputs:
678      ctx - context variable
679
680   Outputs:
681      Returns PGA_TRUE if mutation only occurs when crossover does not,
682      otherwise, returns PGA_FALSE.
683
684   Example:
685      PGAContext *ctx;
686      int mutatetype;
687      :
688      mutatetype = PGAGetMutationOrCrossoverFlag(ctx);
689      switch (mutatetype) {
690      case PGA_TRUE:
691          printf("Only mutating strings not undergoing crossover\n");
692          break;
693      case PGA_FALSE:
694          printf("Mutating strings only after crossover\n");
695          break;
696      }
697
698***************************************************************************U*/
699int PGAGetMutationOrCrossoverFlag (PGAContext *ctx)
700{
701    PGADebugEntered("PGAGetMutationOrCrossoverFlag");
702    PGAFailIfNotSetUp("PGAGetMutationOrCrossoverFlag");
703
704    PGADebugExited("PGAGetMutationOrCrossoverFlag");
705
706    return(ctx->ga.MutateOnlyNoCross);
707}
708
709/*U***************************************************************************
710   PGAGetMutationAndCrossoverFlag - Returns true if mutation occurs only
711   when crossover does.
712
713   Category: Generation
714
715   Inputs:
716      ctx - context variable
717
718   Outputs:
719      Returns PGA_TRUE if mutation is applied to crossed-over strings.
720      Otherwise, returns PGA_FALSE
721
722   Example:
723      PGAContext *ctx;
724      int mutatetype;
725      :
726      mutatetype = PGAGetMutationAndCrossoverFlag(ctx);
727      switch (mutatetype) {
728      case PGA_TRUE:
729          printf("Mutating strings only after crossover\n");
730          break;
731      case PGA_FALSE:
732          printf("Only mutating strings not undergoing crossover\n");
733          break;
734      }
735
736***************************************************************************U*/
737int PGAGetMutationAndCrossoverFlag (PGAContext *ctx)
738{
739    PGADebugEntered("PGAGetMutationAndCrossoverFlag");
740    PGAFailIfNotSetUp("PGAGetMutationAndCrossoverFlag");
741
742    PGADebugExited("PGAGetMutationAndCrossoverFlag");
743
744    return(!ctx->ga.MutateOnlyNoCross);
745}
746
Note: See TracBrowser for help on using the repository browser.