Exemple #1
0
/*U****************************************************************************
   PGAError - reports error messages.  Prints out the message supplied, and
   the value of a piece of data.  Terminates if PGA_FATAL.

   Category: System

   Inputs:
      ctx      - context variable
      msg      - the error message to print
      level    - PGA_WARNING or PGA_FATAL to indicate the error's severity
      datatype - the data type of the following argument
      data     - the address of the data to be written out, cast as a void
                 pointer

   Outputs:
      None

   Example:
      PGAContext *ctx;
      int         val;
      :
      PGAError(ctx, "Some Non Fatal Error: val = ", PGA_WARNING, PGA_INT,
               (void *) &val);
      :
      PGAError(ctx, "A Fatal Error!", PGA_FATAL, PGA_VOID, NULL);

****************************************************************************U*/
void PGAError( PGAContext *ctx, char *msg,
               int level, int datatype, void *data )
{

    PGADebugEntered("PGAError");

    switch (datatype) {
      case PGA_INT:
	fprintf(stderr, "%s %d\n", msg, *(int *)    data);
	break;
      case PGA_DOUBLE:
	fprintf(stderr, "%s %f\n", msg, *(double *) data);
	break;
      case PGA_CHAR:
	fprintf(stderr, "%s %s\n", msg,  (char *)   data);
	break;
      case PGA_VOID:
	fprintf(stderr, "%s\n", msg);
	break;
    }
    if ( level == PGA_FATAL ) {
	fprintf(stderr, "PGAError: Fatal\n");
	PGADestroy(ctx);
	exit(-1);
    }
    PGADebugExited("PGAError");
}
Exemple #2
0
/*U****************************************************************************
   PGAUsage - print list of available parameters and quit

   Inputs:
      ctx - context variable

   Outputs:
     list of available parametersNone

   Example:
      PGAContext ctx;
      :
      PGAUsage(ctx);

****************************************************************************U*/
void PGAUsage( PGAContext *ctx )
{
    /*  Print the usage info out if MPI isn't running (thus, only one process
     *  is probably running), or if we actually are the master.
     */
    if (!ctx->par.MPIAlreadyInit || (PGAGetRank(ctx, MPI_COMM_WORLD) == 0)) {
	PGAPrintVersionNumber( ctx );
	printf("PGAPack usage: %s [pga options]\n", PGAProgram);
	printf("Valid PGAPack options:\n");
	printf("\t-pgahelp          \tget this message\n");
	printf("\t-pgahelp debug    \tlist of debug options\n");
	printf("\t-pgadbg <option>  \tset debug option\n");
	printf("\t-pgadebug <option>\tset debug option\n");
	printf("\t-pgaversion       \tprint current PGAPack version number\n");
	printf("\n");
    }
    PGADestroy(ctx);
    exit(-1);
}
Exemple #3
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);
}
Exemple #4
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();
}