/*U**************************************************************************** PGASetRealAllele - sets the value of real-valued allele i in string p in population pop Category: Fitness & Evaluation Inputs: ctx - context variable p - string index pop - symbolic constant of the population the string is in i - allele index val - real value to set the allele to Outputs: The specified allele in p is modified by side-effect. Example: Sets the value of the ith allele of string p in population PGA_NEWPOP to 1.57 PGAContext *ctx; int i, p; : PGASetRealAllele ( ctx, p, PGA_NEWPOP, i, 1.57) ****************************************************************************U*/ void PGASetRealAllele (PGAContext *ctx, int p, int pop, int i, double value) { PGAIndividual *ind; PGAReal *chrom; PGADebugEntered("PGASetRealAllele"); PGACheckDataType("PGASetRealAllele", PGA_DATATYPE_REAL); ind = PGAGetIndividual ( ctx, p, pop ); chrom = (PGAReal *)ind->chrom; chrom[i] = value; PGADebugExited("PGASetRealAllele"); }
/*U**************************************************************************** PGAGetRealAllele - returns the value of real-valued allele i in string p in population pop Category: Fitness & Evaluation Inputs: ctx - context variable p - string index pop - symbolic constant of the population the string is in i - allele index Outputs: The value of allele i Example: Returns the value of the ith real-valued allele of string p in population PGA_NEWPOP PGAContext *ctx; int p, i, r; r = PGAGetRealAllele (ctx, p, PGA_NEWPOP, i) ****************************************************************************U*/ double PGAGetRealAllele (PGAContext *ctx, int p, int pop, int i) { PGAIndividual *ind; PGAReal *chrom; PGADebugEntered("PGAGetRealAllele"); PGACheckDataType("PGAGetRealAllele", PGA_DATATYPE_REAL); ind = PGAGetIndividual ( ctx, p, pop ); chrom = (PGAReal *)ind->chrom; PGADebugExited("PGAGetRealAllele"); return( (double) chrom[i] ); }
/*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**************************************************************************** PGAPrintIndividual - prints the allele values of a string and associated fields (evaluation, fitness, etc.) of a string Category: Reporting Inputs: ctx - context variable fp - file pointer to print the output to p - string index pop - symbolic constant of the population string p is in Outputs: The allele values of string p and associated fields are printed to fp Example: PGAContext *ctx; int p; : PGAPrintIndividual(ctx, stdout, p, PGA_NEWPOP); ****************************************************************************U*/ void PGAPrintIndividual ( PGAContext *ctx, FILE *fp, int p, int pop ) { PGAIndividual *ind; PGADebugEntered("PGAPrintIndividual"); ind = PGAGetIndividual ( ctx, p, pop ); fprintf( fp,"%d %e %e ", p, ind->evalfunc, ind->fitness); if ( ind->evaluptodate ) fprintf( fp, "T\n" ); else fprintf( fp, "F\n" ); PGAPrintString ( ctx, fp, p, pop ); PGADebugExited("PGAPrintIndividual"); }