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

📄 gpkernel.c

📁 遗传规划工具
💻 C
📖 第 1 页 / 共 5 页
字号:
        if (op_todo->repro_op_type == CROSSOVER_ON_LEAVES ||            op_todo->repro_op_type == CROSSOVER_ON_NODES)        {            UpDateDude(op_todo->parent2,from_list);        }        op_todo->repro_op_type = OP_DONE;         if (gpop.free_list == NULL)         {            gpi_SendError("Error, no free dudes\n");            #ifdef _ICC                __asm{seterr;};            #else                exit(1);            #endif         }         free_dude = gpop.free_list;         gpop.free_list = free_dude->forward;         if (free_dude->forward != NULL)            free_dude->forward->backward = NULL;         free_dude->backward = NULL;         free_dude->forward = NULL;         free_dude->usage = -1;/*         PrintIndividual(&(gpop.tempind),stdout);*/         CompressIndividual(&(gpop.tempind),free_dude);    }    if (gpop.free1->usage == -1)    {/*        gpi_SendTrace("used free1\n");*/         free_dude = gpop.free_list;         if (free_dude == NULL)            gpi_SendTrace("Error, no free guys\n");         gpop.free_list = free_dude->forward;         if (free_dude->forward != NULL)            free_dude->forward->backward = NULL;         free_dude->backward = NULL;         free_dude->forward = NULL;         free_dude->usage = -1;         UnCompressIndividual(gpop.free1,&(gpop.tempind));         CompressIndividual(&(gpop.tempind),free_dude);    }    if (gpop.free2->usage == -1)    {/*        gpi_SendTrace("used free2\n");*/         free_dude = gpop.free_list;         if (free_dude == NULL)            gpi_SendTrace("Error, no free guys\n");         gpop.free_list = free_dude->forward;         if (free_dude->forward != NULL)            free_dude->forward->backward = NULL;         free_dude->backward = NULL;         free_dude->forward = NULL;         free_dude->usage = -1;         UnCompressIndividual(gpop.free2,&(gpop.tempind));         CompressIndividual(&(gpop.tempind),free_dude);    }}void UpDateDude(int parent, int from_list)/*;*/ /*funcdef*/{    if (gpop.members[parent].usage == 1)    {        gpop.one_list = RemoveFromCindList(&(gpop.members[parent]),gpop.one_list);        gpop.free_list = PlaceOnCindList(&(gpop.members[parent]),gpop.free_list);    }    else if (gpop.members[parent].usage == 2)    {        gpop.two_list =RemoveFromCindList(&(gpop.members[parent]),gpop.two_list);        gpop.one_list = PlaceOnCindList(&(gpop.members[parent]),gpop.one_list);    }    else if (gpop.members[parent].usage > 2)    {        gpop.more_list = RemoveFromCindList(&(gpop.members[parent]),gpop.more_list);        if (gpop.members[parent].usage == 3)            gpop.two_list = PlaceOnCindList(&(gpop.members[parent]),gpop.two_list);        else            gpop.more_list = PlaceOnCindList(&(gpop.members[parent]),gpop.more_list);    }    gpop.members[parent].usage--;}void DoReproductiveOp(ReproOpInfo * op_to_do, Individual *child,int child_num)/*;*/ /*funcdef*/{    int temp;    UnCompressIndividual(&(gpop.members[op_to_do->parent1]),&(gpop.parent1));    CopyIndividual( &(gpop.parent1), child);    #if (REPRO_ERROR_CHECKING)    if (ErrorInDude(child))    {        gpi_SendError("ERROR from copying in do repro op \n");        exit(1);    }    #endif    #if GENERATION_VARIED_FITNESS        child->s_fitness = UNDEFINED;    #endif    if (op_to_do->repro_op_type == CROSSOVER_ON_NODES)    {        DoCrossoverOp(1,child,op_to_do,&(gpop.parent1));        child->s_fitness = UNDEFINED;        #if (REPRO_ERROR_CHECKING)        if (ErrorInDude(child))        {            gpi_SendError("ERROR from docrossoverop -- nodes\n");            exit(1);        }        #endif    }    else if (op_to_do->repro_op_type == CROSSOVER_ON_LEAVES)    {        DoCrossoverOp(0,child,op_to_do,&(gpop.parent1));        child->s_fitness = UNDEFINED;       #if (REPRO_ERROR_CHECKING)        if (ErrorInDude(child))        {            gpi_SendError("ERROR from docrossoverop -- leaves\n");            exit(1);        }       #endif    }    else if (op_to_do->repro_op_type == MUTATION)    {        DoMutation(GetRightBranch(&(gpop.parent1),op_to_do->brnum1),                   GetRightBranch(child,op_to_do->brnum1));#if 0    printf("in do op Parent -- MUTATION");    PrintIndividual(&(gpop.parent1),stdout);    printf("in do op Child -- MUTATION");    PrintIndividual(child,stdout);#endif        child->s_fitness = UNDEFINED;      #if (REPRO_ERROR_CHECKING)        if (ErrorInDude(child))        {            gpi_SendError("ERROR from mutation\n");            exit(1);        }      #endif    }    else if (op_to_do->repro_op_type == BRCREATE)    {        temp = DoBranchCreation(child,&(gpop.parent1));        temp=temp;/*to keep compiler from complaining*/      #if (REPRO_ERROR_CHECKING)        if (ErrorInDude(child))        {            gpi_SendError("ERROR from branchcreate\n");            exit(1);        }      #endif    }    #if (USE_IPBCO || USE_ITERATION_GROUP_CREATION)    else if (op_to_do->repro_op_type == IPB_BRC)    {        #if (USE_IPBCO)            temp = DoIterationPerformingBranchCreation(child,&(gpop.parent1));        #else            temp = DoIterationGroupCreation(child,&(gpop.parent1));        #endif        temp=temp;        child->s_fitness = UNDEFINED;      #if (REPRO_ERROR_CHECKING)        if (ErrorInDude(child))        {            gpi_SendError("ERROR from IPBbranchcreate\n");            exit(1);        }       #endif    }    #endif    else if (op_to_do->repro_op_type == BRDUP)    {        temp = 	DoBranchDuplication(child,&(gpop.parent1));      #if (REPRO_ERROR_CHECKING)        if (ErrorInDude(child))        {            gpi_SendError("ERROR from branch duplication\n");            exit(1);        }      #endif    }    else if (op_to_do->repro_op_type == BRDEL)    {        temp = DoBranchDeletion(child,&(gpop.parent1));        child->s_fitness = UNDEFINED;      #if (REPRO_ERROR_CHECKING)        if (ErrorInDude(child))        {            gpi_SendError("ERROR from branch deletion\n");            exit(1);        }      #endif    }    else if (op_to_do->repro_op_type == ARGDUP)    {        temp = DoArgumentDuplication(child,&(gpop.parent1));      #if (REPRO_ERROR_CHECKING)        if (ErrorInDude(child))        {            gpi_SendError("ERROR from do arg duplication\n");            exit(1);        }       #endif    }    else if (op_to_do->repro_op_type == ARGDEL)    {        temp = DoArgumentDeletion(child,&(gpop.parent1));      #if (REPRO_ERROR_CHECKING)        if (ErrorInDude(child))        {            gpi_SendError("ERROR from do arg deletion\n");            exit(1);        }      #endif        child->s_fitness = UNDEFINED;    }}void ChooseOneReproduction(int early, int counter, int ind_num)/*;*/ /*funcdef - dgpc - DoOneReproduction*/{	int parent1;	float fraction;	int bnum1,bnum2,bnum;        int temp;        #if (SEDUCTION == ON)            g_male_selection_method = (counter+ind_num) %2;        #else            g_male_selection_method =0;        #endif	parent1 = FindGoodTree(g_male_selection_method);        counter=counter;        bnum2=bnum2;        UnCompressIndividual(&(gpop.members[parent1]),&(gpop.parent1));        (gpop.members[parent1].usage)++;        gpop.repro_op_list[ind_num].next_for_parent1 = gpop.members[parent1].op_list;        gpop.members[parent1].op_list = &(gpop.repro_op_list[ind_num]);        gpop.repro_op_list[ind_num].parent1 = parent1;        gpop.repro_op_list[ind_num].parent2 = -1;	fraction = (float) RandomFloat((float)1.0);        gpop.repro_op_list[ind_num].repro_op_type = COPY;    if ( (early && (fraction < (        (gpop.pop_startup_info.early_crossover_fraction_for_node)+	(gpop.pop_startup_info.early_crossover_fraction_for_leaves)))) ||	(!early && (fraction <        (gpop.pop_startup_info.crossover_fraction_for_node)+	(gpop.pop_startup_info.crossover_fraction_for_leaves))))    {        #ifdef SIZE_WEIGHTED_CROSSOVER_BRANCH_SELECTION        #   if (SIZE_WEIGHTED_CROSSOVER_BRANCH_SELECTION)        	bnum = ChooseWRandomBranch(&(gpop.parent1));        #   else    	        bnum = (int) RandomInt(gpop.parent1.current_number_of_adfs + NUM_RPBS);	        #   endif        #else    	        bnum = (int) RandomInt(gpop.parent1.current_number_of_adfs + NUM_RPBS);	        #endif        gpop.repro_op_list[ind_num].brnum1 = bnum; 	if ( (early && (fraction <            (gpop.pop_startup_info.early_crossover_fraction_for_node))) ||	   (!early&& (fraction <            (gpop.pop_startup_info.crossover_fraction_for_node))))        {	   DoCrossoverPrep(1, &(gpop.repro_op_list[ind_num]),                             &(gpop.parent1), bnum);           gpop.repro_op_list[ind_num].repro_op_type = CROSSOVER_ON_NODES;        }	else        {    	   DoCrossoverPrep(0, &(gpop.repro_op_list[ind_num]),                              &(gpop.parent1), bnum);           gpop.repro_op_list[ind_num].repro_op_type = CROSSOVER_ON_LEAVES;        }    }    else if ((early && (fraction <            (gpop.pop_startup_info.early_crossover_fraction_for_node) +            (gpop.pop_startup_info.early_crossover_fraction_for_leaves) +	    (gpop.pop_startup_info.early_mutation_fraction))) ||	    (!early && (fraction <            (gpop.pop_startup_info.crossover_fraction_for_node) +	    (gpop.pop_startup_info.crossover_fraction_for_leaves) +	    (gpop.pop_startup_info.mutation_fraction))))    {        gpop.repro_op_list[ind_num].repro_op_type = MUTATION;        #ifdef SIZE_WEIGHTED_CROSSOVER_BRANCH_SELECTION        #   if (SIZE_WEIGHTED_CROSSOVER_BRANCH_SELECTION)        	bnum = ChooseWRandomBranch(&(gpop.parent1));        #   else    	        bnum = (int) RandomInt(gpop.parent1.current_number_of_adfs + NUM_RPBS);	        #   endif        #else    	        bnum = (int) RandomInt(gpop.parent1.current_number_of_adfs + NUM_RPBS);	        #endif        gpop.repro_op_list[ind_num].brnum1 = bnum;    }    else if ((early && (fraction <            (gpop.pop_startup_info.early_crossover_fraction_for_node) +            (gpop.pop_startup_info.early_crossover_fraction_for_leaves) +	    (gpop.pop_startup_info.early_mutation_fraction) +	    (gpop.pop_startup_info.early_branch_creation_fraction))) ||            (!early && (fraction <            (gpop.pop_startup_info.crossover_fraction_for_node) +	    (gpop.pop_startup_info.crossover_fraction_for_leaves) +	    (gpop.pop_startup_info.mutation_fraction) +	    (gpop.pop_startup_info.branch_creation_fraction))))			    {        gpop.repro_op_list[ind_num].repro_op_type = BRCREATE;    }    else if ((early && (fraction <            (gpop.pop_startup_info.early_crossover_fraction_for_node) +	    (gpop.pop_startup_info.early_crossover_fraction_for_leaves) +	    (gpop.pop_startup_info.early_mutation_fraction) +	    (gpop.pop_startup_info.early_branch_creation_fraction) +	    (gpop.pop_startup_info.early_branch_duplication_fraction))) ||	    (!early && (fraction <            (gpop.pop_startup_info.crossover_fraction_for_node) +	    (gpop.pop_startup_info.crossover_fraction_for_leaves) +	    (gpop.pop_startup_info.mutation_fraction) +	    (gpop.pop_startup_info.branch_creation_fraction) +            (gpop.pop_startup_info.branch_duplication_fraction))))			    {        gpop.repro_op_list[ind_num].repro_op_type = BRDUP;    }    else if ((early && (fraction <            (gpop.pop_startup_info.early_crossover_fraction_for_node) +            (gpop.pop_startup_info.early_crossover_fraction_for_leaves) +            (gpop.pop_startup_info.early_mutation_fraction) +            (gpop.pop_startup_info.early_branch_creation_fraction) +            (gpop.pop_startup_info.early_branch_duplication_fraction) +            (gpop.pop_startup_info.early_branch_deletion_fraction))) ||            (!early && (fraction < (gpop.pop_startup_info.crossover_fraction_for_node) +            (gpop.pop_startup_info.crossover_fraction_for_leaves) +            (gpop.pop_startup_info.mutation_fraction) +            (gpop.pop_startup_info.branch_creation_fraction) +            (gpop.pop_startup_info.branch_duplication_fraction) +            (gpop.pop_startup_info.branch_deletion_fraction))))			    {        gpop.repro_op_list[ind_num].repro_op_type = BRDEL;    }    else if ((early && (fraction <            (gpop.pop_startup_info.early_crossover_fraction_for_node) +            (gpop.pop_startup_info.early_crossover_fraction_for_leaves) +            (gpop.pop_startup_info.early_mutation_fraction) +            (gpop.pop_startup_info.early_branch_creation_fraction) +            (gpop.pop_startup_info.early_branch_duplication_fraction) +            (gpop.pop_startup_info.early_branch_deletion_fraction) +            (gpop.pop_startup_info.early_arg_duplication_fraction))) ||    	    (!early && (fraction <            (gpop.pop_startup_info.crossover_fraction_for_node) +            (gpop.pop_startup_info.crossover_fraction_for_leaves) +            (gpop.pop_startup_info.mutation_fraction) +            (gpop.pop_startup_info.branch_creation_fraction) +            (gpop.pop_startup_info.branch_duplication_fraction) +            (gpop.pop_startup_info.branch_deletion_fraction) +            (gpop.pop_startup_info.arg_duplication_fraction))))    {        gpop.repro_op_list[ind_num].repro_op_type = ARGDUP;    }    else if ((early && (fraction <            (gpop.pop_startup_info.early_crossover_fraction_for_node) +            (gpop.pop_startup_info.early_crossover_fraction_for_leaves) +            (gpop.pop_startup_info.early_mutation_fraction) +            (gpop.pop_startup_info.early_branch_creation_fraction) +            (gpop.pop_startup_info.early_branch_duplication_fraction) +            (gpop.pop_startup_info.early_branch_deletion_fraction) +            (gpop.pop_startup_info.early_arg_duplication_fraction) +            (gpop.pop_startup_info.early_arg_deletion_fraction))) ||	    (!early &&            (fraction < (gpop.pop_startup_info.crossover_fraction_for_node) +            (gpop.pop_startup_info.crossover_fraction_for_leaves) +            (gpop.pop_startup_info.mutation_fraction) +            (gpop.pop_startup_info.branch_creation_fraction) +            (gpop.pop_startup_info.branch_duplication_fraction) +            (gpop.pop_startup_info.branch_deletion_fraction) +            (gpop.pop_startup_info.arg_duplication_fraction) +            (gpop.pop_startup_info.arg_deletion_fraction))))    {        gpop.repro_op_list[ind_num].repro_op_type = ARGDEL;    }    #if (USE_IPBCO || USE_ITERATION_GROUP_CREATION)        else if ((early && (fraction <           (gpop.pop_startup_info.early_crossover_fraction_for_node) +           (gpop.pop_startup_info.early_crossover_fraction_for_leaves) +            (gpop.pop_startup_info.early_mutation_fraction) +            (gpop.pop_startup_info.early_branch_creation_fraction) +            (gpop.pop_startup_info.early_branch_duplication_fraction) +            (gpop.pop_startup_info.early_branch_deletion_fraction) +            (gpop.pop_startup_info.early_arg_duplication_fracti

⌨️ 快捷键说明

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