/*U**************************************************************************** PGAPrintString - write the allele values in a string to a file Category: Reporting Inputs: ctx - context variable fp - pointer to file to write the string to p - index of the string to write out pop - symbolic constant of the population string p is in Outputs: None Example: PGAContext *ctx; int p; : PGAPrintString(ctx, stdout, p, PGA_OLDPOP); ****************************************************************************U*/ void PGAPrintString ( PGAContext *ctx, FILE *file, int p, int pop ) { int fp; PGADebugEntered("PGAPrintString"); PGADebugPrint( ctx, PGA_DEBUG_PRINTVAR,"PGAPrintString", "p = ", PGA_INT, (void *) &p ); PGADebugPrint( ctx, PGA_DEBUG_PRINTVAR,"PGAPrintString", "pop = ", PGA_INT, (void *) &pop ); if (ctx->fops.PrintString) { fp = ((p == PGA_TEMP1) || (p == PGA_TEMP2)) ? p : p+1; (*ctx->fops.PrintString)(&ctx, NULL, &fp, &pop); } else { (*ctx->cops.PrintString)(ctx, file, p, pop); } fprintf(file,"\n"); PGADebugExited("PGAPrintString"); }
/*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"); }