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

#include "pgapack.h"

/*U****************************************************************************
   PGACrossover - performs crossover on two parent strings to create two
   child strings (via side-effect).  The type of crossover performed is
   either the default or that specified by PGASetCrossoverType

   Category: Crossover

   Inputs:
      ctx  - context variable
      p1   - the first parent string
      p2   - the second parent string
      pop1 - symbolic constant of the population containing string p1 and p2
      pop2 - symbolic constant of the population to contain string c1 and c2
      
   Outputs:
      c1   - the first child string
      c2   - the second child string

   Example:
      To perform crossover on the two parent strings mom and dad in population
      PGA_OLDPOP, and insert the child strings, child1 and child1, in
      population PGA_NEWPOP use
      
      PGAContext *ctx;
      int mom, dad, child1, child2;
      PGACrossover(ctx, mom, dad, PGA_OLDPOP, child1, child2, PGA_NEWPOP);

****************************************************************************U*/
void PGACrossover ( PGAContext *ctx, int p1, int p2, int pop1,
                    int c1, int c2, int pop2 )
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGACrossover", "Entered", 
                   PGA_VOID, NULL );
    PGADebugPrint( ctx, PGADEBUG_PRINTVAR, "PGACrossover", " p1 = ", 
                   PGA_INT, (void *) &p1 );
    PGADebugPrint( ctx, PGADEBUG_PRINTVAR, "PGACrossover", " p2 = ", 
                   PGA_INT, (void *) &p2 );
    PGADebugPrint( ctx, PGADEBUG_PRINTVAR, "PGACrossover", " c1 = ", 
                   PGA_INT, (void *) &c1 );
    PGADebugPrint( ctx, PGADEBUG_PRINTVAR, "PGACrossover", " c2 = ", 
                   PGA_INT, (void *) &c2 );
  
    (*ctx->ops.Crossover)(ctx, p1, p2, pop1, c1, c2, pop2);

    PGASetEvalUpToDate(ctx, c1, pop2, PGAFALSE);
    PGASetEvalUpToDate(ctx, c2, pop2, PGAFALSE);
    
    PGADebugPrint( ctx, PGADEBUG_EXIT, "PGACrossover", "Exit", 
                   PGA_VOID, NULL );
    return;
}
