/*****************************************************************************
*     FILE: mutation.c: This file contains the data structure neutral mutation
*                       routines
*
*     Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle
*****************************************************************************/

#include "pgapack.h"

/*U****************************************************************************
  PGAMutate - This routine performs mutation on a string.  The type of mutation
  depends on the data type.  Refer to the user guide for data-specific
  examples.

  Category: Mutation

  Inputs:
      ctx  - context variable
      p   - index of string to mutate
      pop - symbolic constant of the population containing p
      
  Output:
      The mutated string created via side effect
  
  Example:
      This example mutates string p in the new population.
      
      PGAContext *ctx;
      int p;
      :
      PGAMutate( ctx, p, PGA_NEWPOP);

****************************************************************************U*/
int PGAMutate(PGAContext *ctx, int p, int pop)
{
    double mr;
    int count=0;     /* number of mutations.  unused right now */

    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAMutate", "Entered", 
                   PGA_VOID, NULL );

    mr    = ctx->ga.MutationProb;      
    count = (*ctx->ops.Mutation)( ctx, p, pop, mr );

    if ( count > 0 )
	 PGASetEvalUpToDate(ctx, p, pop, PGAFALSE);

    PGADebugPrint( ctx, PGADEBUG_EXIT, "PGAMutate", "Exit", 
                   PGA_VOID, NULL );
    return(count);
}
