www.pudn.com > dgpc.rar > pentstub.c


/*======================================================================+
| PGPC: Parallel Genetic Programming in C                               |
| (c) 1995 Genetic Algorithm Technology Corp. all rights reserved       |
|   written by David Andre                                              |
+======================================================================*/
/*======================================================================+
| FILE: pentstub.c                                                      |
| DESCRIPTION: Handles the i/o code and startup code for the            |
|              for the uniprocessor stub version.                       |
|                                                                       |
| REVISIONS:                                                            |
| Jan 24, 1995:  Works as of today, no known bugs.                      |
| Jan 25, 95, 1207am:  Added Random seed garnering capability           |
| Jan 26, 1995, 2:21pm:    Putatively done with seed garnering...       |
+======================================================================*/


#include 
#include 
#include 
#include 
#include 
#include 
#ifdef __BORLANDC__
#include 
#include 
#include 
#else
#ifdef _ICC
#include 
#include 
#include 
#include 
#endif
#endif


#include "gp.h"
#include "gpshared.h"
#include "pentstub.h"
#include "proto.h"
#include "gpi_stub.h"

FitCaseInfo out_sample_fitness_cases[_dmax(1,NUM_OUT_SAMPLE_FIT_CASES)];


extern Population gpop;

int main()
{
    int perpetual_number;
    struct tm *now;
    time_t clck;
    char out_put_file_name[40];

    DoWelcomeMessage();
    printf("Sizes:\n");
    printf("sizeof Individual %d, sizeof comp_ind %d,\nPopGlobals %d, StartupInfo %d\n",
            sizeof(Individual), sizeof(CompInd),sizeof(PopGlobals), sizeof(StartupInfo));
    printf("sizeof eog %d, EurekaInfo %d\n",sizeof(EndGenInfo),
            sizeof(EurekaInfo));
    printf("sizeof Population %d\n**************\n", sizeof(Population));
    fflush(stdout);
    setbuf(stdout, (char *) NULL);   /*Is this needed?*/
    time(&clck);
    now = localtime (&clck);
    GetPerpetualNumber(&perpetual_number);
    ReadInputFile(_PRB_IN,&gpop);
    DoRandoms(&gpop,perpetual_number);
    WriteToArchive(&gpop,perpetual_number,asctime(now));
    MakeFunctionTable(&gpop);
    CreateRandomConstants(&gpop);
    ReadPrimedIndividuals(&gpop);
    WriteInfoToOutputFile(&gpop,out_put_file_name,perpetual_number,asctime(now));

	 MainGPLoop(&gpop,&gpop.pop_startup_info,clck);
    return(-1);
}

void MainGPLoop(Population * popptr, StartupInfo * paramptr,time_t start_time)/*;*/ /*MainGPLoop- funcdef - */
{
int gen;

    gen=0;
    gpi_PopCreation(popptr);
    #if (INIT_POP_CHECK)
       init_pop_check(popptr);
       exit(1);
    #endif					
    for (gen=0; !(gpentTerminationQuery(gen)); gen++) {
        gpi_EvaluateGeneration(gen,popptr);
        if (!gpentTerminationQuery(gen))
        {
            gpi_DoEndOfGenMessage(gen,popptr);
            gpi_ReproducePopulation(gen);
        }
    } /* End of main counter loop */	
    gpi_DoEurekaMessage(gen, popptr,start_time);
}

int gpentTerminationQuery(int gen)/*;*/ /*funcdef*/
{
#ifdef USE_USER_TERMINATION
#if (USE_USER_TERMINATION ==1)
		if (UserTermination(gen, gpop.best_fitness,&gpop))
			return(1);
		else
			return(0);
#endif
#endif	
if ((gen < ((int)((float) (gpop.pop_startup_info.num_generations)))) &&
				(gpop.best_fitness > RUN_END_CRITERION))
	 return(0);
else
	 return(1);
}

			
void PreparePrimedInd(Individual * ind,Population *pop)/*;*/ /*funcdef*/
{
    int i,j;

        ind->s_fitness = (float) UNDEFINED;
	ind->hits		 = 0;
	ind->beauty		 = 0;
	
	ind->current_number_of_adfs = NUM_INITIAL_ADFS;
	for (i=0;iadf_arity[i]=MIN_NUM_ADF_ARGS;
        for (j=0;jrpbs[j].function_vector[i] =  (*pop).function_assignment[j][i];	
	}
	for (j=0;jadfs[j].function_vector[i] =  (*pop).function_assignment[NUM_RPBS+j][i];	
	}
#if (DO_POOR_WHITE_TRASH_AUDIT)
        ind->num_ops_done=0;
#endif
}


void ReadPrimedIndividuals(Population *pop)/*;*/ /*funcdef*/
{
FILE *ifp;
FILE *fp;
int counter,front,back;
char ch;
    CreateIndividual(&(pop->pop_startup_info.primed_individual));
    PreparePrimedInd(&(pop->pop_startup_info.primed_individual),pop);
    if (((*pop).pop_startup_info.num_primed_individuals) > 0)
    	{
            counter=0;front=0;back=0;
            /*
   	    fp = fopen("foo","rt");
            while ((ch = getc(fp)) != EOF)
            {
                counter++;
                printf("%c",ch);
                if (ch == '(')
                    front++;
                if (ch == ')')
                    back++;
                if (front + back > 0 && front == back)
                    break;
             }

            printf("front %d, back %d,BUFSIZE %d,counter %d\n",front,back,BUFSIZ,counter);
            rewind(fp);
            fclose(fp);
            counter=0;front=0;back=0;
   	    fp = fopen("foo","rt");
            while ((ch = getc(fp)) != EOF)
            {
                counter++;
                printf("%c",ch);
                if (ch == '(')
                    front++;
                if (ch == ')')
                    back++;
                if (front + back > 0 && front == back)
                    break;
             }

            printf("front %d, back %d,BUFSIZE %d,counter %d\n",front,back,BUFSIZ,counter);
            rewind(fp);
            fclose(fp);
            */

            /*rewind(ifp);*/
            pop->primed_constants = TOTAL_NUMBER_OF_FUNCTIONS - 1;
            /*fflush(pop->out_file);*//**********************/
            fflush(stdout);
/*            ifp = fopen("foo","rt");            */
            ReadIndividual(ifp,&(pop->pop_startup_info.primed_individual));
/*            fclose(ifp); */
            PrintIndividual(&(pop->pop_startup_info.primed_individual),stdout);

  	}
}

void CreateRandomConstants(Population *pop)/*;*/ /*funcdef*/
{
int i;

    (*pop).num_constants =TOTAL_NUMBER_OF_FUNCTIONS-1;
    for (i=(*pop).num_constants;i0)
       {
            fprintf((*pop).out_file,"\nSeed created using as_if_number of %d\n",((*pop).pop_startup_info.as_if_number));
            fprintf(stderr,"\nSeed created using as_if_number of %d\n",((*pop).pop_startup_info.as_if_number));
       }

/*        printf("sizeof Snode is %d\n",sizeof(Snode));
        printf("Sizeof Individual is %d\n",sizeof(Individual));
        printf("sizeof branch is %d\n", sizeof(Branch));
        printf("sizeof int %d, float %d, double %d, char %d, unsigned char %d\n",
            sizeof(int), sizeof(float), sizeof(double), sizeof(char), sizeof(unsigned char));
*/
        fprintf((*pop).out_file," Sizeof Individual is %d, sizeof CompInd %d\n",sizeof(Individual),sizeof(CompInd));

        fprintf((*pop).out_file,"\nnum_primed_individuals = %d  \ncrossover_fraction_for_leaves = %f",
             ((*pop).pop_startup_info.num_primed_individuals),
             ((*pop).pop_startup_info.crossover_fraction_for_leaves));
        fprintf((*pop).out_file,"\ncrossover_fraction_for_node = %f   \nmutation_fraction = %f",
             ((*pop).pop_startup_info.crossover_fraction_for_node),
             ((*pop).pop_startup_info.mutation_fraction));
        fprintf((*pop).out_file,"\ncopy_fraction =%f, \nbranch_creation_fraction = %f",
                            ((*pop).pop_startup_info.copy_fraction),
              ((*pop).pop_startup_info.branch_creation_fraction));
        fprintf((*pop).out_file,"\nbranch_duplication_fraction =%f, \nbranch_deletion_fraction = %f",
                        ((*pop).pop_startup_info.branch_duplication_fraction),
                        ((*pop).pop_startup_info.branch_deletion_fraction));
        fprintf((*pop).out_file,"\narg__duplication_fraction =%f, \narg_deletion_fraction = %f",
                        ((*pop).pop_startup_info.arg_duplication_fraction),
                        ((*pop).pop_startup_info.arg_deletion_fraction));
        fprintf((*pop).out_file,"\nearly_cross_fract_leaves=%f  \nearly_cross_fract_node = %f\n early_mutation_fraction = %f",
             ((*pop).pop_startup_info.early_crossover_fraction_for_leaves),
             ((*pop).pop_startup_info.early_crossover_fraction_for_node),
             ((*pop).pop_startup_info.early_mutation_fraction));
        fprintf((*pop).out_file,"\nearly_copy_fraction =%f, \nearly_branch_creation_fraction = %f",
            ((*pop).pop_startup_info.early_copy_fraction),
            ((*pop).pop_startup_info.early_branch_creation_fraction));
        fprintf((*pop).out_file,"\nearly_branch_duplication_fraction =%f, \nearly_branch_deletion_fraction = %f",
                        ((*pop).pop_startup_info.early_branch_duplication_fraction),
                        ((*pop).pop_startup_info.early_branch_deletion_fraction));
        fprintf((*pop).out_file,"\nearly_arg__duplication_fraction =%f, \nearly_arg_deletion_fraction = %f",
                        ((*pop).pop_startup_info.early_arg_duplication_fraction),
                        ((*pop).pop_startup_info.early_arg_deletion_fraction));
        fprintf((*pop).out_file,"\ngrowth_method = %d\n",
             ((*pop).pop_startup_info.growth_method));
        #if (FUNCREPORT)
                    PrintFunctionTable(gpop.out_file,&gpop);
        #endif
        fflush(stdout);
        fflush(stderr);
        fflush((*pop).out_file);
        fprintf((*pop).out_file,"\n\n----------------- VARIOUS #defs for this problem and the default.in file!-------------\n\n");
        fclose((*pop).out_file);
        sprintf(str,"findstr define *.c >> %s",out_put_file_name);
        system(str);
        sprintf(str,"findstr define *.h >> %s",out_put_file_name);
        system(str);
/*        sprintf(str,"type default.in >> %s",out_put_file_name);
        system(str);
*/
	(*pop).out_file = fopen(out_put_file_name,"a");
        fprintf((*pop).out_file,"\n\n------------------End of #defs----------------------------\n");
        fprintf((*pop).out_file,"\n------------------RESULTS OF THIS RUN----------------------------\n");
        fflush((*pop).out_file);

        sprintf(def_file,"%s/%s.def",((*pop).problem),
                                      ((*pop).problem));

        fp = fopen(def_file,"w");
        fprintf(fp,PROBLEM);
        fprintf(fp,ENVIRON);
        fprintf(fp,FUNK);
        fprintf(fp,"MACHINE \t intel\n");
        fprintf(fp,"M =     \t %d\n",((*pop).pop_startup_info.num_individuals));
        fprintf(fp,"Q =     \t %d\n",((*pop).pop_startup_info.num_individuals));
        fprintf(fp,"D =     \t 1\n");
        fprintf(fp,"B =     \t 0%%\n");
        fprintf(fp,ZVALUE);
        fclose(fp);



}


void ReadInputFile(char * filename,Population * gpop)/*;*/  /*funcdef - startup - ReadInputFile*/
{
FILE * fp;
StartupInfo * popsi;

popsi = &((*gpop).pop_startup_info);

    fp = fopen(filename, "r");
    fscanf(fp,"%s %*s %d %*s %d %*s %d %*s %d %*s",
           &((*gpop).problem),
            &(popsi->num_individuals), &(popsi->num_generations),
            &(popsi->num_primed_individuals),&(popsi->as_if_number));

    printf("problem is %s\n",(*gpop).problem);

    popsi->max_new_tree_depth =                 MAX_NEW_TREE_DEPTH;
    popsi->max_depth_for_mutation =             MAX_DEPTH_FOR_MUTATION;
    popsi->crossover_fraction_for_leaves =      CROSSOVER_FRACTION_FOR_LEAVES;
    popsi->crossover_fraction_for_node   =      CROSSOVER_FRACTION_FOR_NODE;
    popsi->mutation_fraction             =      MUTATION_FRACTION;
    popsi->copy_fraction=                       COPY_FRACTION;
    popsi->branch_creation_fraction        =    BRANCH_CREATION_FRACTION;
    popsi->branch_duplication_fraction  =       BRANCH_DUPLICATION_FRACTION;
    popsi->branch_deletion_fraction =           BRANCH_DELETION_FRACTION;
    popsi->arg_duplication_fraction =           ARG_DUPLICATION_FRACTION;
    popsi->arg_deletion_fraction =              ARG_DELETION_FRACTION;
    popsi->early_crossover_fraction_for_leaves= EARLY_CROSSOVER_FRACTION_FOR_LEAVES;
    popsi->early_crossover_fraction_for_node  = EARLY_CROSSOVER_FRACTION_FOR_NODE;
    popsi->early_mutation_fraction            = EARLY_MUTATION_FRACTION;
    popsi->early_copy_fraction=                 EARLY_COPY_FRACTION;
    popsi->early_branch_creation_fraction     = EARLY_BRANCH_CREATION_FRACTION;
    popsi->early_branch_duplication_fraction  = EARLY_BRANCH_DUPLICATION_FRACTION;
    popsi->early_branch_deletion_fraction =     EARLY_BRANCH_DELETION_FRACTION;
    popsi->early_arg_duplication_fraction =     EARLY_ARG_DUPLICATION_FRACTION;
    popsi->early_arg_deletion_fraction =        EARLY_ARG_DELETION_FRACTION;
    #if (USE_IPBCO || USE_ITERATION_GROUP_CREATION)
        popsi->early_ipbco_fraction =           EARLY_IPBCO_FRACTION;
        popsi->ipbco_fraction       =           IPBCO_FRACTION;
    #endif
    popsi->growth_method    =                   GROWTH_METHOD;

    fclose(fp);
}

void WriteToArchive(Population *pop,int perpetual_number, char * str)/*;*/ /*funcdef - startup - WriteToArchive*/
{
FILE *archive;

        archive = fopen("archive.out", "a");
        fprintf(archive,"\n%s Run =P%6.6d   \nStarting = %s",
             ((*pop).problem), perpetual_number,  str);
        fprintf(archive,"Seed = %ld  num_individuals = %d  num_generations = %d",
             ((*pop).pop_startup_info.seed), ((*pop).pop_startup_info.num_individuals),
             ((*pop).pop_startup_info.num_generations));
        if (((*pop).pop_startup_info.as_if_number) >0)
            fprintf(archive,"\nSeed created using as_if_number of %d\n",
                ((*pop).pop_startup_info.as_if_number));
        fprintf(archive,"\n");
        fflush(archive);
 	fclose(archive);
}

void	ReportToFile(int counter,    /*funcdef - startup - ReportToFile*/
                       int run_num,     /*funcdef - startup -ReportToFile*/
                       FILE * ofp)/*;*/      /*funcdef - startup -ReportToFile*/
{
	struct tm *now;
	time_t clck;
        time(&clck);
        now = localtime (&clck);
	fprintf(gpop.out_file, "%s %d G:%d  BF:%.5f H:%d Ind %d",(gpop.problem),  run_num,
                counter, gpop.best_fitness,gpop.best_so_far.hits,gpop.best_dude_index);
		  if (gpop.best_fitness <= RUN_END_CRITERION)
            fprintf(gpop.out_file,"!!!");
	fprintf(gpop.out_file,"%s",asctime(now));
        PrintIndividual(&(gpop.best_so_far), ofp);
	fprintf(gpop.out_file, "\n");
        fflush(gpop.out_file);
}

void	ReportToScreen(int counter,int run_num)/*;*/   /*funcdef - startup - ReportToScreen*/
{
	struct tm *now;
	time_t clck;
        time(&clck);
        now = localtime (&clck);
        fprintf(stderr, "%s %d G:%d  BF:%.5f H:%d ", (gpop.problem),
                     run_num, counter, gpop.best_fitness,gpop.best_so_far.hits);
        if (gpop.best_fitness <= 0.00001)
            fprintf(stderr,"!!!");
	fprintf(stderr,"%s",asctime(now));
        fflush(stderr);
}

/*Cant be used on the breeder!*/
void PrintIndividual(Individual * ind, FILE * ofp)/*;*/ /*funcdef - dgpc - PrintIndividual*/
{
        int     i,j;
        int zero =0;

        fprintf(ofp,"\nNum RPBS %d ",NUM_RPBS);
        fprintf(ofp,"Num ADFS %d ", ind->current_number_of_adfs);
        fprintf(ofp,"ARITY ");
        for (i=0;i< ind->current_number_of_adfs;i++)
		fprintf(ofp," %d",ind->rpbs[0].function_vector[i]);
	fprintf(ofp,"\n");
        fflush(ofp);
        for (i=0;i< NUM_RPBS; i++)
	{
		fprintf(ofp,"RPB_Num %d: with %d points\n", i,ind->rpbs[i].tree[0].jump);
		PrintTree(&(ind->rpbs[i]), 0, 0, ofp,&zero);
                fprintf(ofp,"\n");
                #if  (PRINTFVECTOR)
                    fprintf(ofp,"func_vector rpb#%d\n",i);
                    for (j=0;jrpbs[i].function_vector[j]));
                    fprintf(ofp,"\n");
                #endif
                #if  (PTREE)
                fprintf(ofp,"Tree:");
                for (j=0;j<50;j++)
                {
                   fprintf(ofp," op %d",ind->rpbs[i].tree[j].opcode);
                   fprintf(ofp," jump %d\n",ind->rpbs[i].tree[j].jump);
                }
                fprintf(ofp,"\n");
                #endif


	}
	for (i=0;i< ind->current_number_of_adfs; i++)
	{
		fprintf(ofp,"ADF_Num %d: with %d points\n", i,ind->adfs[i].tree[0].jump);
                #if (USE_MULTI_TYPED_ADFS)
                    fprintf(ofp,"adf of type");
                    if (ind->adf_type[i] == ADF_TYPE_ADF)
                        fprintf(ofp," ADF\n");
                    else
                        fprintf(ofp," IPB\n");
                #endif
		PrintTree(&(ind->adfs[i]), 0, 0,ofp,&zero);
                fprintf(ofp,"\n");
                #if (PRINTFVECTOR)
                    fprintf(ofp,"func_vector adf#%d\n",i);
                    for (j=0;jadfs[i].function_vector[j]));
                    fprintf(ofp,"\n");
                #endif
                #if (PTREE)
                fprintf(ofp,"Tree:");
                for (j=0;j<25;j++)
                {
                   fprintf(ofp," op %d",ind->adfs[i].tree[j].opcode);
                   fprintf(ofp," jump %d\n",ind->rpbs[i].tree[j].jump);
                }
                fprintf(ofp,"\n");
                #endif
	}
#if (DO_POOR_WHITE_TRASH_AUDIT)
        fprintf(ofp,"num_ops_done %d\ncy_num_of_ops: ",ind->num_ops_done);
        for (i=0;inum_ops_done;i++)
        {
            fprintf(ofp,"%d:%d ",i,ind->cy_num_of_ops[i]);
        }
        fprintf(ofp,"\nop_list: ");
        for (i=0;inum_ops_done;i++)
            fprintf(ofp,"%d:%d ",ind->cy_num_of_ops[i],ind->op_list[i]);
        fprintf(ofp,"\nfit_at_op: ");
        for (i=0;inum_ops_done;i++)
            fprintf(ofp,"%d:%d ",ind->cy_num_of_ops[i],ind->fit_at_op[i]);
        fprintf(ofp,"\n");
#endif
    fprintf(ofp,"\n");
    fflush(ofp);
}

/*Goes to the next occurence in file f of the char c, returns EOF if none*/
/*found, 0 otherwise.  The function also pushes the char back into the file*/
int GoToCharInFile(FILE * fp, char ch)
{
int ibuf;

    while((ibuf = getc(fp)) != EOF)
    {
        if ((char)ibuf == ch)
        {
            ungetc(ch,fp);
            return(0);
        }
    }
    return((int)EOF);
}


void ReadIndividual(FILE * ofp, Individual * ind)/*;*/ /*funcdef - dgpc - ReadIndividual */
{
int i,j;
int temp;
char string[20];

ofp = fopen("foo","r");

if (ofp == NULL)
{
    fprintf(stderr,"ERROR -- no foo file!\n");
    exit(1);
}

#if (DEBUG_READ_DUDE)
    printf("In ReadIndividual\n");
#endif
    i = GoToInFile(ofp,"RPBS");
    if (!i)
        printf("couldn't find first individual\n");
    fscanf(ofp,"%d",&j);
    i = GoToInFile(ofp,"ADFS");
    if (!i)
        printf("couldn't find number of adfs\n");
    fscanf(ofp,"%d ", &(ind->current_number_of_adfs));
    fscanf(ofp,"ARITY");
    for (i=0;icurrent_number_of_adfs;i++)
        fscanf(ofp,"%d",&(ind->adf_arity[i]));
/*    fscanf(ofp,"\n");*/

#if (DEBUG_READ_DUDE)
    printf("Num Rpbs, %d, Num ADFS %d, \n ARITY:",j,ind->current_number_of_adfs);
    for (i=0;icurrent_number_of_adfs;i++)
        printf("%d ",ind->adf_arity[i]);
    printf("\n");
#endif
    for (i=0;icurrent_number_of_adfs)
                ind->rpbs[i].function_vector[j] =  ind->adf_arity[j];
           else
                ind->rpbs[i].function_vector[j] =  -1;
        }
        for (j=MAX_NUM_ADFS;j< (MAX_NUM_ADFS + MAX_NUM_ADF_ARGS);j++)
           ind->rpbs[i].function_vector[j] =  -1;
    }
    for (i=0;icurrent_number_of_adfs;i++)
    {
        for (j=0;jadfs[i].function_vector[j] =  ind->adf_arity[j];
            else
                ind->adfs[i].function_vector[j] =   -1;
        }
        for (j=MAX_NUM_ADFS;j< (MAX_NUM_ADFS + MAX_NUM_ADF_ARGS);j++)
        {
            if ((j-MAX_NUM_ADFS) <= (ind->adf_arity[i] ))
                ind->adfs[i].function_vector[j] =   0;
            else
                ind->adfs[i].function_vector[j] =   -1;
        }
    }
    for (i=0;irpbs[i]),ofp); */
        ReadBranch(&(ind->rpbs[i]),ofp,0);
    }
   for (i=0;icurrent_number_of_adfs;i++)
   {
       temp = GoToInFile(ofp,"ADF_Num");
        fscanf(ofp,"%*d");
#if (USE_MULTI_TYPED_ADFS)
       temp = GoToInFile(ofp,"type");
    fscanf(ofp,"%s",string);
    if (!strcmp(string,"ADF"))
        ind->adf_type[i] = ADF_TYPE_ADF;
    else
        ind->adf_type[i] = ADF_TYPE_IPB;
#endif

        GoToCharInFile(ofp,'(');
       if (temp != 1)
           fprintf(stderr,"Having trouble having finding:  ADF_Num %d\n",i);
/*       NewReadBranch(&(ind->adfs[i]),ofp); */
       ReadBranch(&(ind->adfs[i]),ofp,0);
   }

fclose(ofp);
}


int GoToInFile(FILE * ofp, char * str)/*;*/   /*funcdef - dgpc - GoToInFile*/
{
    char test[100];
    int temp;

    while ((temp = fscanf(ofp,"%s",test)) != EOF)
    {
        if (!strcmp(test,str))
            return(1);
        else
            if (temp == 0)
                temp = fscanf(ofp,"\n");
    }
    return(0);
}

void blanks(FILE *f, int n)/*;*/  /*funcdef - dgpc - blanks*/
{
int i;
	for (i=0;itree[index].opcode = LookupFunctionName(buf);
		passindex = index+1;
                #if (DEBUG_READ_DUDE)
                    printf(" a!%d ",_function_arity(br->tree[index].opcode));
                #endif
    		for (i=0; i < _function_arity(br->tree[index].opcode); i++)
    		{
     			passindex =  ReadBranch(br,f, passindex);
     			if (passindex ==0) return(0);
     		}
                endp=0;done=0;
                GotoEndBracket(f);


  }
  else
  {
    		ungetc(buf[0], f);
    		GetNextToken(buf, f);
#if (DEBUG_READ_DUDE)
    		printf("token was %s \n",buf);		
#endif
     		sscanf(buf, GFORMAT, &temp);
    		br->tree[index].opcode = FindConstantInTables(temp, &constant_num);
                if (br->tree[index].opcode ==  -1)
                {
                    fprintf(stderr,"Error, constant %s not found in tables\n",buf);
                    fprintf(gpop.out_file,"Error, constant %s not found in tables\n",buf);
                    exit(1);
                }
/*    		br->tree[index+1].opcode = constant_num; */
    		passindex = index+1;
  }

return(passindex);
}


int FindConstantInTables(GTYPE temp, int *constant_num)/*;*/ /*funcdef - dgpc - FindConstantInTable*/
{
/*Returns the number of the constant array that the constant was found in,
and places the index in constant_num.  It returns -1 on failure*/

    int i;
    int j;

    temp=temp;
        for (j=TOTAL_NUMBER_OF_FUNCTIONS-1;j gpop.num_constants)
            printf("TERRIBLE Error!!! -- too many constants in read individual\n");
#if (DEBUG_READ_DUDE)
        printf("NumConstants Read in %d\n",gpop.primed_constants);
#endif
        gpop.pop_startup_info.random_constant_table[*constant_num] = temp;
    return(*constant_num);
}




/*-----------------------------------------------------------------------------*/

int PrintTree(Branch * br, int index, int depth,  FILE *f, int *counter)/*;*/ /*funcdef - dgpc - PrintTree*/
{
	int passkey;
	int i;

	#if (SQUISH_PRINT)
    	   if ((*counter) % 10 == 0) fprintf(f,"\n");
	#else
		blanks(f,depth);
	#endif
  	if ((_function_is_constant(br->tree[index].opcode)))
  	{
    		fprintf(f," %f " ,(float) gpop.pop_startup_info.random_constant_table[br->tree[index].opcode]);
    		passkey = index+1;
    	}
    	else
    	{
    		fprintf(f,"(%s ",_function_printname(br->tree[index].opcode) );
  		if (_function_arity(br->tree[index].opcode) == 0)
  		{
     			fprintf(f,")");     	
		passkey = index+1;
     		}
     		else
		{
        		#if (!(SQUISH_PRINT))
    			fprintf(f,"\n");
    			#endif
    			passkey = index+1;
    			for (i=0; i<_function_arity(br->tree[index].opcode); i++)
    			{
                            (*counter)++;
         			passkey = PrintTree(br, passkey, depth+1, f, counter);
         			#if (SQUISH_PRINT)
/*							if ((*counter) % 10 == 0) fprintf(f,"\n");*/
					#endif
         			 if (i == (_function_arity(br->tree[index].opcode))-1)
						fprintf(f,")");
					#if (!(SQUISH_PRINT))
					else
    					fprintf(f,"\n");
    				#endif
    			}
		}
	}
#if (SQUISH_PRINT)
  	if (!depth) fprintf(f,"\n");
#endif
        fflush(f);
  	return(passkey);
}


void WriteBranch(Branch * br, FILE *f)/*;*/  /*funcdef - dgpc - WriteBranch*/

{
int i=0;
PrintTree(br, 0, 0, f,&i);
fprintf(f,"\n");
fflush(f);
}

void PrintFunctionTable(FILE * ofp,Population * pop)/*;*/ /*funcdef - dgpc -Pr intFunctionTable*/
{
int i,j;

    fprintf(ofp,"\n**************Function Table Information****************\n");
    fprintf(ofp,"\n There are %d functions in the function table\n", (*pop).num_general_functions);
    fprintf(ofp," Of these, %d are ADFs, %d are dummy-variables, and %d are general\n",
                  MAX_NUM_ADFS, MAX_NUM_ADF_ARGS, (((*pop).num_general_functions)- (MAX_NUM_ADFS+MAX_NUM_ADF_ARGS)));

    for (i=0;i