Пример #1
0
/*******************************************************************
*                   user main program                              *
*******************************************************************/
int main( int argc, char **argv ) {
    PGAContext *ctx;
    int seed;
    
    srandom(time(NULL));
    seed = random() % 1000;
    
    ctx = PGACreate(&argc, argv, PGA_DATATYPE_BINARY, 101, PGA_MAXIMIZE);
    //PGASetRandomSeed(ctx, seed);
    
    PGASetPopSize(ctx, 500);
    PGASetFitnessType(ctx, PGA_FITNESS_RANKING);
    PGASetCrossoverType(ctx, PGA_CROSSOVER_UNIFORM );
    PGASetStoppingRuleType(ctx, PGA_STOP_NOCHANGE);
    PGASetUp(ctx);
    PGARun(ctx, solution_score);
    PGADestroy(ctx);
    
    return(0);
}
Пример #2
0
void main(int argc, char **argv) {
    PGAContext *ctx;

    MPI_Init(&argc, &argv);

    /*  Rather than deal with standard io and strings, we'll just set
     *  this explicitly.
     */
    strcpy(Name, "David M. Levine, Philip L. Hallstrom, David M. Noelle, "
                 "Brian P. Walenz");

    ctx = PGACreate(&argc, argv, PGA_DATATYPE_CHARACTER, strlen(Name),
		    PGA_MAXIMIZE);
    
    PGASetRandomSeed(ctx, 42);
    
    PGASetUserFunction(ctx, PGA_USERFUNCTION_INITSTRING, (void *)N_InitString);
    PGASetUserFunction(ctx, PGA_USERFUNCTION_MUTATION,   (void *)N_Mutation);
    PGASetUserFunction(ctx, PGA_USERFUNCTION_CROSSOVER,  (void *)N_Crossover);
    PGASetUserFunction(ctx, PGA_USERFUNCTION_DUPLICATE,  (void *)N_Duplicate);
    PGASetUserFunction(ctx, PGA_USERFUNCTION_STOPCOND,   (void *)N_StopCond);
    PGASetUserFunction(ctx, PGA_USERFUNCTION_PRINTSTRING,(void *)N_PrintString);
    PGASetUserFunction(ctx, PGA_USERFUNCTION_ENDOFGEN,   (void *)N_EndOfGen);

    /*  We don't want to report anything.  */
    PGASetPrintFrequencyValue(ctx, 10000);
    PGASetPopSize(ctx, 100);
    PGASetNumReplaceValue(ctx, 90);
    PGASetPopReplaceType(ctx, PGA_POPREPL_BEST);
    PGASetNoDuplicatesFlag(ctx, PGA_TRUE);
    PGASetMaxGAIterValue(ctx, 100);
    
    PGASetUp(ctx);
    PGARun(ctx, EvalName);
    PGADestroy(ctx);

    MPI_Finalize();
}