⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pentstub.c

📁 遗传规划工具
💻 C
📖 第 1 页 / 共 3 页
字号:
             ((*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;j<TOTAL_NUMBER_OF_FUNCTIONS;j++)                        fprintf(ofp," %d",((int)ind->rpbs[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;j<TOTAL_NUMBER_OF_FUNCTIONS;j++)                        fprintf(ofp," %d",((int)ind->adfs[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;i<ind->num_ops_done;i++)        {            fprintf(ofp,"%d:%d ",i,ind->cy_num_of_ops[i]);        }        fprintf(ofp,"\nop_list: ");        for (i=0;i<ind->num_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;i<ind->num_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;i<ind->current_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;i<ind->current_number_of_adfs;i++)        printf("%d ",ind->adf_arity[i]);    printf("\n");#endif    for (i=0;i<NUM_RPBS;i++)    {        for (j=0;j<MAX_NUM_ADFS;j++)        {           if (j<ind->current_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;i<ind->current_number_of_adfs;i++)    {        for (j=0;j<MAX_NUM_ADFS;j++)        {            if (j != i)                ind->adfs[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;i<NUM_RPBS;i++)    {        temp = GoToInFile(ofp,"RPB_Num");        fscanf(ofp,"%*d");        GoToCharInFile(ofp,'(');        if (temp != 1)            fprintf(stderr,"Having trouble having finding: RPB_Num %d\n",i);/*        NewReadBranch(&(ind->rpbs[i]),ofp); */        ReadBranch(&(ind->rpbs[i]),ofp,0);    }   for (i=0;i<ind->current_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;i<n;i++)	{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -