File: pga.c

package info (click to toggle)
pgapack 1.1-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,344 kB
  • ctags: 1,786
  • sloc: ansic: 10,331; fortran: 2,985; sh: 486; makefile: 462; perl: 105
file content (717 lines) | stat: -rw-r--r-- 22,498 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
/*
COPYRIGHT

The following is a notice of limited availability of the code, and disclaimer
which must be included in the prologue of the code and in all source listings
of the code.

(C) COPYRIGHT 2008 University of Chicago

Permission is hereby granted to use, reproduce, prepare derivative works, and
to redistribute to others. This software was authored by:

D. Levine
Mathematics and Computer Science Division 
Argonne National Laboratory Group

with programming assistance of participants in Argonne National 
Laboratory's SERS program.

GOVERNMENT LICENSE

Portions of this material resulted from work developed under a
U.S. Government Contract and are subject to the following license: the
Government is granted for itself and others acting on its behalf a paid-up,
nonexclusive, irrevocable worldwide license in this computer software to
reproduce, prepare derivative works, and perform publicly and display
publicly.

DISCLAIMER

This computer code material was prepared, in part, as an account of work
sponsored by an agency of the United States Government. Neither the United
States, nor the University of Chicago, nor any of their employees, makes any
warranty express or implied, or assumes any legal liability or responsibility
for the accuracy, completeness, or usefulness of any information, apparatus,
product, or process disclosed, or represents that its use would not infringe
privately owned rights.
*/

/*****************************************************************************
*     FILE: pga.c: This file contains all the routines that are data structure
*                  neutral
*
*     Authors: David M. Levine, Philip L. Hallstrom, and David M. Noelle,
*              Brian P. Walenz
*****************************************************************************/

#include "pgapack.h"

/*U****************************************************************************
  PGARun - Highest level routine to execute the genetic algorithm.  It
  is called after PGACreate and PGASetup have been called.

  Category: Generation

  Inputs:
    ctx      - context variable
    evaluate - a pointer to the user's evaluation function, which must
               have the calling sequence shown in the example.

  Outputs:
    none

  Example:
    PGAContext *ctx,
    double f(PGAContext *ctx, int p, int pop);
    :
    ctx = PGACreate(&argc, argv, PGA_DATATYPE_BINARY, 100, PGA_MAXIMIZE);
    PGASetUp(ctx);
    PGARun(ctx, f);
    PGADestroy(ctx);

****************************************************************************U*/
void PGARun(PGAContext *ctx, double (*evaluate)(PGAContext *c, int p, int pop))
{
     MPI_Comm comm;                  /* value of default communicator */
     int nprocs;                     /* number of processes in above  */
     int npops;                      /* number of populations         */
     int ndemes;                     /* number of demes               */
     

     PGADebugEntered("PGARun");
     PGAFailIfNotSetUp("PGARun");

     comm   = PGAGetCommunicator(ctx);
     nprocs = PGAGetNumProcs    (ctx, comm);
     npops  = PGAGetNumIslands  (ctx);
     ndemes = PGAGetNumDemes    (ctx);

     /**********************************************************************/
     /*              Global model, one island, one deme                    */
     /**********************************************************************/
     if     ( (npops == 1) && (ndemes == 1) ) {

	 PGARunGM(ctx, evaluate, comm);
     }
     
     /**********************************************************************/
     /*              Island model, > one island, one deme                  */
     /**********************************************************************/
     else if( (npops > 1) && (ndemes == 1) ) {
         if ( nprocs == 1 )
             PGAError (ctx, "PGARun: island model with one process",
                       PGA_FATAL, PGA_VOID, (void *) &nprocs);
         if ( nprocs != npops) {
             PGAError (ctx, "PGARun: island model no. processes != no. pops",
                       PGA_FATAL, PGA_VOID, (void *) &nprocs);
         }
         PGARunIM(ctx,evaluate,comm);
     }
             
     /**********************************************************************/
     /*              Neighborhood model, one island, > one deme            */
     /**********************************************************************/
     else if( (npops == 1) && (ndemes > 1) ) {
         if ( nprocs == 1 )
             PGAError (ctx, "PGARun: neighborhood model with one process",
                       PGA_FATAL, PGA_VOID, (void *) &nprocs);
         if ( nprocs != ndemes)
             PGAError (ctx, "PGARun: neighborhood model no. processes "
                       "!= no. demes", PGA_FATAL, PGA_VOID, (void *) &nprocs);
         PGARunNM(ctx,evaluate,comm);
     }
             
     /**********************************************************************/
     /*              Mixed model, > one island, > one deme                 */
     /**********************************************************************/
     else if( (npops > 1) && (ndemes > 1) ) {
         PGAError (ctx, "PGARun: Cannot execute mixed models",
                   PGA_FATAL, PGA_VOID, (void *) &nprocs);
     }

     /**********************************************************************/
     /*                        E R R O R                                   */
     /**********************************************************************/
     else {
         PGAError (ctx, "PGARun: Invalid combination of numislands,"
                   "ndemes, and nprocs.",
                   PGA_FATAL, PGA_VOID, (void *) &nprocs);
     }

     /**********************************************************************/
     /*                         E X I T                                    */
     /**********************************************************************/
     PGADebugExited("PGARun");
     return;
 }


/*U****************************************************************************
  PGARunMutationAndCrossover - Performs crossover and mutation from one
  population to create the next.  Assumes PGASelect has been called.

  Category: Generation

  Inputs:
    ctx - context variable
    oldpop - symbolic constant of old population
    newpop - symbolic constant of new population

  Outputs:
    newpop is modified by side-effect.

  Example:
     PGAContext *ctx,
    :
    PGARunMutationAndCrossover(ctx, PGA_OLDPOP, PGA_NEWPOP);

****************************************************************************U*/
void PGARunMutationAndCrossover (PGAContext *ctx, int oldpop, int newpop)
{
    int i, j, n, m1, m2;
    int popsize, numreplace;
    double pc;

    PGADebugEntered("PGARunMutationAndCrossover");

    popsize = PGAGetPopSize(ctx);
    numreplace = PGAGetNumReplaceValue(ctx);
    /*** first, copy n best strings (sorted by fitness) to new pop ***/
    PGASortPop( ctx, oldpop );
    n = popsize - numreplace;
    for ( i=0; i < n; i++ ) {
        j = PGAGetSortedPopIndex( ctx, i );
        PGACopyIndividual ( ctx, j, oldpop, i, newpop );
    }
    pc = PGAGetCrossoverProb(ctx);
    /*** reproduce to create the rest of the new population ***/
    while ( n < popsize) {
        m1 = PGASelectNextIndex( ctx );
        m2 = PGASelectNextIndex( ctx );
        if ( PGARandomFlip(ctx, pc) ) {
             PGACrossover ( ctx, m1, m2, oldpop, PGA_TEMP1,
                            PGA_TEMP2, newpop);

              /*** mutate and copy first string to new population ***/
              PGAMutate ( ctx, PGA_TEMP1, newpop);
              while (PGADuplicate( ctx, PGA_TEMP1, newpop, newpop, n))
                   PGAChange ( ctx, PGA_TEMP1, newpop );
              PGACopyIndividual ( ctx, PGA_TEMP1, newpop, n, newpop);
              n++;

              if ( n < popsize ) {
              /*** mutate and copy second string to new population ***/
              PGAMutate ( ctx, PGA_TEMP2, newpop);
              while ( PGADuplicate( ctx, PGA_TEMP2, newpop, newpop, n))
                   PGAChange ( ctx, PGA_TEMP2, newpop );
              PGACopyIndividual ( ctx, PGA_TEMP2, newpop, n, newpop);
              n++;
              }
         }
         else {
            PGACopyIndividual ( ctx, m1, oldpop, n, newpop );
            n++;
            if ( n < ctx->ga.PopSize ) {
                PGACopyIndividual ( ctx, m2, oldpop, n, newpop );
                n++;
            }
       }
    }

    PGADebugExited("PGARunMutationAndCrossover");
}


/*U****************************************************************************
  PGARunMutationOrCrossover - Performs crossover or mutation (but not both)
  from one populationto create the next.  Assumes PGASelect has been called.

  Category: Generation

  Inputs:
    ctx - context variable
    oldpop - symbolic constant of old population
    newpop - symbolic constant of new population

  Outputs:
    newpop is modified by side-effect.

  Example:
    PGAContext *ctx,
    :
    PGARunMutationOrCrossover(ctx, PGA_OLDPOP, PGA_NEWPOP);

****************************************************************************U*/
void PGARunMutationOrCrossover ( PGAContext *ctx, int oldpop, int newpop )
{
    int i, j, n, m1, m2;
    int popsize, numreplace;
    double pc;

    PGADebugEntered("PGARunMutationOrCrossover");

    popsize = PGAGetPopSize(ctx);
    numreplace = PGAGetNumReplaceValue(ctx);
    /*** first, copy n best strings (sorted by fitness) to new pop ***/
    PGASortPop( ctx, oldpop );
    n = popsize - numreplace;
    for ( i=0; i < n; i++ ) {
        j = PGAGetSortedPopIndex( ctx, i );
        PGACopyIndividual ( ctx, j, oldpop, i, newpop );
    }
    pc = PGAGetCrossoverProb(ctx);
    /*** reproduce to create the rest of the new population ***/
    while ( n < popsize ) {
        m1 = PGASelectNextIndex( ctx );
        m2 = PGASelectNextIndex( ctx );
        if ( PGARandomFlip(ctx, pc) ) {
            PGACrossover ( ctx, m1, m2, oldpop, PGA_TEMP1,
                                        PGA_TEMP2, newpop);

            /*** copy first string to new population ***/
            while (PGADuplicate(ctx, PGA_TEMP1, newpop,  newpop, n))
                PGAChange ( ctx, PGA_TEMP1, newpop );
            PGACopyIndividual ( ctx, PGA_TEMP1, newpop, n, newpop);
            n++;

            if ( n < popsize )
            {
                 /*** copy second string to new population ***/
                 while (PGADuplicate(ctx, PGA_TEMP2, newpop,  newpop, n))
                      PGAChange ( ctx, PGA_TEMP2, newpop );
                 PGACopyIndividual ( ctx, PGA_TEMP2, newpop, n, newpop);
                 n++;
            }
        }
        else
        {
             PGACopyIndividual(ctx, m1, oldpop, PGA_TEMP1, newpop);
             PGAMutate ( ctx, PGA_TEMP1, newpop );
             while (PGADuplicate(ctx, PGA_TEMP1, newpop, newpop, n ))
                  PGAChange ( ctx, PGA_TEMP1, newpop );
             PGACopyIndividual ( ctx, PGA_TEMP1, newpop, n, newpop);
             n++;

             if ( n < popsize ) {
                  PGACopyIndividual(ctx, m2, oldpop, PGA_TEMP2, newpop);
                  PGAMutate ( ctx, PGA_TEMP2, newpop );
                  while (PGADuplicate(ctx, PGA_TEMP2, newpop, newpop, n ))
                       PGAChange ( ctx, PGA_TEMP2, newpop );
                  PGACopyIndividual ( ctx, PGA_TEMP2, newpop, n, newpop);
                  n++;
             }
        }
    }

    PGADebugExited("PGARunMutationOrCrossover");
}


/*U****************************************************************************
  PGAUpdateGeneration - updates internal data structures for the next
  genetic algorithm iteration, and checks if the termination conditions, both
  user and PGAPack, have been met.  This routine must be called by both
  master and slave processes at the end of each GA generation.

  Category: Generation

  Inputs:
     ctx  - context variable
     comm - an MPI communicator

  Outputs:
     PGA_TRUE if the genetic algorithm has terminated, otherwise PGA_FALSE.

  Example:
    PGAContext *ctx;
    :
    PGAUpdateGeneration(ctx, MPI_COMM_WORLD);

****************************************************************************U*/
void PGAUpdateGeneration(PGAContext *ctx, MPI_Comm comm)
{
    PGAIndividual *temp;
    int i, rank;

    PGADebugEntered("PGAUpdateGeneration");
    PGADebugPrint( ctx, PGA_DEBUG_PRINTVAR,"PGAUpdateGeneration",
                  "ga.iter = ", PGA_INT, (void *) &(ctx->ga.iter) );

    rank = PGAGetRank(ctx, comm);

    ctx->ga.iter++;

    if (rank == 0) {
	if (ctx->rep.PrintOptions & PGA_REPORT_AVERAGE)
	    PGAUpdateAverage(ctx, PGA_NEWPOP);

	if (ctx->rep.PrintOptions & PGA_REPORT_ONLINE)
	    PGAUpdateOnline(ctx, PGA_NEWPOP);

	if (ctx->rep.PrintOptions & PGA_REPORT_OFFLINE)
	    PGAUpdateOffline(ctx, PGA_NEWPOP);

	if ((ctx->ga.StoppingRule & PGA_STOP_NOCHANGE) || ctx->ga.restart) {
	    i = PGAGetBestIndex(ctx, PGA_NEWPOP);
	    if (ctx->rep.Best == PGAGetEvaluation(ctx, i, PGA_NEWPOP))
		ctx->ga.ItersOfSame++;
	    else {
		ctx->rep.Best = PGAGetEvaluation(ctx, i, PGA_NEWPOP);
		ctx->ga.ItersOfSame = 1;
	    }
	}

	if (ctx->ga.StoppingRule & PGA_STOP_TOOSIMILAR)
	    ctx->ga.PercentSame = PGAComputeSimilarity(ctx, ctx->ga.newpop);

	/*  Clear this twice in case the user EOG calls PGASelect.  */
	ctx->ga.SelectIndex = 0;

	if (ctx->fops.EndOfGen)
	    (*ctx->fops.EndOfGen)(&ctx);
	if (ctx->cops.EndOfGen)
	    (*ctx->cops.EndOfGen)(ctx);

	ctx->ga.SelectIndex = 0;
	temp           = ctx->ga.oldpop;
	ctx->ga.oldpop = ctx->ga.newpop;
	ctx->ga.newpop = temp;
    }

    PGADebugExited("PGAUpdateGeneration");
}


/*U***************************************************************************
   PGAGetDataType - Returns the data type used by the given context.

   Category: Generation

   Inputs:
      ctx - context variable

   Outputs:
      Returns the integer corresponding to the symbolic constant
      used to specify the data type.

   Example:
      PGAContext *ctx;
      int datatype;
      :
      datatype = PGAGetDataType(ctx);
      switch (datatype) {
      case PGA_DATATYPE_BINARY:
          printf("Data Type = PGA_DATATYPE_BINARY\n");
          break;
      case PGA_DATATYPE_CHARACTER:
          printf("Data Type = PGA_DATATYPE_CHARACTER\n");
          break;
      case PGA_DATATYPE_INTEGER:
          printf("Data Type = PGA_DATATYPE_INTEGER\n");
          break;
      case PGA_DATATYPE_REAL:
          printf("Data Type = PGA_DATATYPE_REAL\n");
          break;
      case PGA_DATATYPE_USER:
          printf("Data Type = PGA_DATATYPE_USER\n");
          break;
      }

***************************************************************************U*/
int PGAGetDataType (PGAContext *ctx)
{
    PGADebugEntered("PGAGetDataType");

    PGADebugExited("PGAGetDataType");

    return(ctx->ga.datatype);
}

/*U***************************************************************************
   PGAGetOptDirFlag - Returns a symbolic constant that represents the
   direction of optimization

   Category: Generation

   Inputs:
      ctx - context variable

   Outputs:
      Returns the integer corresponding to the symbolic constant
      used to specify the  direction of optimization

   Example:
      PGAContext *ctx;
      int optdir;
      :
      optdir = PGAGetOptDirFlag(ctx);
      switch (optdir) {
      case PGA_MAXIMIZE:
          printf("Optimization direction = PGA_MAXIMIZE\n");
          break;
      case PGA_MINIMIZE:
          printf("Optimization direction = PGA_MINIMIZE\n");
          break;
      }

***************************************************************************U*/
int PGAGetOptDirFlag (PGAContext *ctx)
{
    PGADebugEntered("PGAGetOptDirFlag");

    PGADebugExited("PGAGetOptDirFlag");

    return(ctx->ga.optdir);
}

/*U***************************************************************************
   PGAGetStringLength - Returns the string length

   Category: Generation

   Inputs:
      ctx - context variable

   Outputs:
      The string length

   Example:
      PGAContext *ctx;
      int stringlen;
      :
      stringlen = PGAGetStringLength(ctx);

***************************************************************************U*/
int PGAGetStringLength (PGAContext *ctx)
{
    PGADebugEntered("PGAGetStringLength");

    PGADebugExited("PGAGetStringLength");

    return(ctx->ga.StringLen);
}

/*I***************************************************************************
   PGAGetVariableStringLength - Returns the length of a variable length
   string.

   Category: Generation

   Inputs:
      ctx - context variable
      p   - index into the population
      pop - symbolic constant for the population

   Outputs:
      The string length

   Example:
      PGAContext *ctx;
      int stringlen;
      :
      stringlen = PGAGetVariableStringLength(ctx, 0, PGA_NEWPOP);

***************************************************************************I*/
int PGAGetVariableStringLength (PGAContext *ctx, int p, int pop)
{
    PGADebugEntered("PGAGetVariableStringLength");

    PGADebugExited("PGAGetVariableStringLength");

    PGAError(ctx, "PGAGetVariableStringLength:  Variable length strings not "
	     "currently supported.", PGA_FATAL, PGA_VOID, NULL);
#if 0
    ind = PGAGetIndividual(ctx, p, pop);
    return(ind->StringLength);
#endif
    /*  Make the compilers be quiet.  */
    return(0);
}

/*U***************************************************************************
  PGAGetGAIterValue - returns the number of the current genetic
  algorithm generation

   Category: Generation

   Inputs:
      ctx - context variable

   Outputs:
      The genetic algorithm generation number

   Example:
      PGAContext *ctx;
      int g;
      :
      g = PGAGetGAIterValue(ctx);

***************************************************************************U*/
int PGAGetGAIterValue (PGAContext *ctx)
{
    PGADebugEntered("PGAGetGAIterValue");
    PGAFailIfNotSetUp("PGAGetGAIterValue");

    PGADebugExited("PGAGetGAIterValue");

    return(ctx->ga.iter);
}

/*U****************************************************************************
  PGASetMutationOrCrossoverFlag - A boolean flag to indicate if recombination
  uses exactly one of crossover or mutation on selected strings.

   Category: Generation

   Inputs:
      ctx  - context variable
      flag - PGA_TRUE (default) or PGA_FALSE

   Outputs:
      None

   Example:
      Set the genetic algorithm to use mutation only when crossover is
      not used.

      PGAContext *ctx;
      :
      PGASetMutationOrCrossoverFlag(ctx,PGA_FALSE);

****************************************************************************U*/
void PGASetMutationOrCrossoverFlag( PGAContext *ctx, int flag)
{
    PGADebugEntered("PGASetMutationOrCrossoverFlag");

     switch (flag)
     {
     case PGA_TRUE:
     case PGA_FALSE:
          ctx->ga.MutateOnlyNoCross = flag;
          break;
     default:
          PGAError (ctx, "PGASetMutationOrCrossoverFlag: Invalid value of "
                    "flag:", PGA_FATAL, PGA_INT, (void *) &flag);
          break;
     }

    PGADebugExited("PGASetMutationOrCrossoverFlag");
}

/*U****************************************************************************
  PGASetMutationAndCrossoverFlag - A boolean flag to indicate if
  recombination uses both crossover and mutation on selected strings

   Category: Generation

   Inputs:
      ctx  - context variable
      flag - PGA_TRUE (default) or PGA_FALSE

   Outputs:
      None

   Example:
      Set the genetic algorithm to use both crossover and mutation when
      reproducing strings.

      PGAContext *ctx;
      :
      PGASetMutationAndCrossoverFlag(ctx,PGA_FALSE);

****************************************************************************U*/
void PGASetMutationAndCrossoverFlag( PGAContext *ctx, int flag)
{
    PGADebugEntered("PGASetMutationAndCrossoverFlag");

     switch (flag)
     {
     case PGA_TRUE:
     case PGA_FALSE:
          ctx->ga.MutateOnlyNoCross = !flag;
          break;
     default:
          PGAError (ctx, "PGASetMutationAndCrossoverFlag: Invalid value of "
                    "flag:", PGA_FATAL, PGA_INT, (void *) &flag);
          break;
     }

    PGADebugExited("PGASetMutationAndCrossoverFlag");
}
/*U***************************************************************************
   PGAGetMutationOrCrossoverFlag - Returns true if mutation only occurs when
   crossover does not.

   Category: Generation

   Inputs:
      ctx - context variable

   Outputs:
      Returns PGA_TRUE if mutation only occurs when crossover does not,
      otherwise, returns PGA_FALSE.

   Example:
      PGAContext *ctx;
      int mutatetype;
      :
      mutatetype = PGAGetMutationOrCrossoverFlag(ctx);
      switch (mutatetype) {
      case PGA_TRUE:
          printf("Only mutating strings not undergoing crossover\n");
          break;
      case PGA_FALSE:
          printf("Mutating strings only after crossover\n");
          break;
      }

***************************************************************************U*/
int PGAGetMutationOrCrossoverFlag (PGAContext *ctx)
{
    PGADebugEntered("PGAGetMutationOrCrossoverFlag");
    PGAFailIfNotSetUp("PGAGetMutationOrCrossoverFlag");

    PGADebugExited("PGAGetMutationOrCrossoverFlag");

    return(ctx->ga.MutateOnlyNoCross);
}

/*U***************************************************************************
   PGAGetMutationAndCrossoverFlag - Returns true if mutation occurs only
   when crossover does.

   Category: Generation

   Inputs:
      ctx - context variable

   Outputs:
      Returns PGA_TRUE if mutation is applied to crossed-over strings.
      Otherwise, returns PGA_FALSE

   Example:
      PGAContext *ctx;
      int mutatetype;
      :
      mutatetype = PGAGetMutationAndCrossoverFlag(ctx);
      switch (mutatetype) {
      case PGA_TRUE:
          printf("Mutating strings only after crossover\n");
          break;
      case PGA_FALSE:
          printf("Only mutating strings not undergoing crossover\n");
          break;
      }

***************************************************************************U*/
int PGAGetMutationAndCrossoverFlag (PGAContext *ctx)
{
    PGADebugEntered("PGAGetMutationAndCrossoverFlag");
    PGAFailIfNotSetUp("PGAGetMutationAndCrossoverFlag");

    PGADebugExited("PGAGetMutationAndCrossoverFlag");

    return(!ctx->ga.MutateOnlyNoCross);
}