?? userdefinables.cpp
字號(hào):
exit(1); } if ((pToken = strtok(NULL, BLANK_STR)) == NULL) { printf("Using default scaling of 1 for fitness sharing\n"); ((double*)(globalSetup->nichingParameters))[1] = 1.0; } else ((double*)(globalSetup->nichingParameters))[1] = atof(pToken); } break; case RTS: { globalSetup->nichingParameters = new int[1]; if ((pToken = strtok(NULL, BLANK_STR)) == NULL) { printf("Setting the window size for RTS using default rule: w = min(ell, n/20)\n"); if(globalSetup->noOfDecisionVariables < (globalSetup->populationSize/20)) ((int*)(globalSetup->nichingParameters))[0] = globalSetup->noOfDecisionVariables; else ((int*)(globalSetup->nichingParameters))[0] = (globalSetup->populationSize)/20; //Adjust for small problem sizes: w = n/20; if(globalSetup->noOfDecisionVariables < 20) ((int*)(globalSetup->nichingParameters))[0] = (globalSetup->populationSize)/20; //Check if the window size is greater than the population size if(((int*)globalSetup->nichingParameters)[0] > globalSetup->populationSize) ((int*)(globalSetup->nichingParameters))[0] = globalSetup->populationSize; printf("The window size used for RTR is: %d\n", ((int*)globalSetup->nichingParameters)[0]); } else ((int*)(globalSetup->nichingParameters))[0] = atoi(pToken); // the window size should be in (0, populationSize] if ((((int*)globalSetup->nichingParameters)[0] <= 0) || (((int*)globalSetup->nichingParameters)[0] > globalSetup->populationSize)) { fclose(fInput); printf("Error! window size for RTR should be > 0 and less than the population size\n"); exit(1); } } break; default: { fclose(fInput); printf("Error! valid choices for niching type are: NoNiching, Sharing, RTS, and DeterministicCrowding\n"); exit(1); } break; } // selection if ((pToken = readOneLine(caBuf, ciBufSize, fInput)) == NULL) { fclose(fInput); printf("Error in the input file, please refer to the documentation\n"); exit(1); } if(strcmp("default", pToken) == 0) { printf("Using tournament selection w/o replacement as a default selection method\n"); globalSetup->selectionType = TournamentWOR; } // selection type else if (strcmp("TournamentWOR", pToken) == 0) { globalSetup->selectionType = TournamentWOR; } else if (strcmp("SUS", pToken) == 0) { globalSetup->selectionType = SUS; } else if (strcmp("Truncation", pToken) == 0) { globalSetup->selectionType = Truncation; } else if (strcmp("RouletteWheel", pToken) == 0) { globalSetup->selectionType = RouletteWheel; } else if (strcmp("TournamentWR", pToken) == 0) { globalSetup->selectionType = TournamentWR; } else { fclose(fInput); printf("Error! valid selection methods are: RouletteWheel, SUS, TournamentWOR, TournamentWR, and Truncation\n"); exit(1); } // check selection type if ((globalSetup->gaType == NSGA) && ((globalSetup->selectionType == SUS) || (globalSetup->selectionType == RouletteWheel))) { fclose(fInput); printf("Error! with NSGA, valid selection methods are: TournamentWOR, TournamentWR, and Truncation\n"); exit(1); } // read selection parameters switch(globalSetup->selectionType) { case TournamentWOR: case Truncation: case TournamentWR: { globalSetup->selectionParameters = new int[1]; if ((pToken = strtok(NULL, BLANK_STR)) == NULL) { printf("Using default tournament size of 2\n"); ((int*)globalSetup->selectionParameters)[0] = 2; } else ((int*)globalSetup->selectionParameters)[0] = atoi(pToken); } break; case SUS: case RouletteWheel: // no extra parameters break; default: { fclose(fInput); printf("Error! invalid selection parameter\n"); exit(1); } break; } // Crossover // crossover probability if ((pToken = readOneLine(caBuf, ciBufSize, fInput)) == NULL) { fclose(fInput); printf("Error in the input file, please refer to the documentation\n"); exit(1); } if(strcmp("default", pToken) == 0) { printf("Using a default crossover probability of 0.9\n"); globalSetup->xOverProbability = 0.9; } // the number should be [0.0, 1.0] else if (((globalSetup->xOverProbability = atof(pToken)) < 0.0) || (globalSetup->xOverProbability > 1.0)) { fclose(fInput); printf("Error! crossover probability must be >= 0.0 and <= 1.0\n"); exit(1); } // crossover type if ((pToken = readOneLine(caBuf, ciBufSize, fInput)) == NULL) { fclose(fInput); printf("Error in the input file, please refer to the documentation\n"); exit(1); } if(strcmp("default", pToken) == 0) { printf("Using SBX as the default crossover method. Note that this might be an inappropriate choice if your variables are binary\n"); globalSetup->xOverType = SBX; } else if (strcmp("OnePoint", pToken) == 0) { globalSetup->xOverType = OnePoint; } else if (strcmp("TwoPoint", pToken) == 0) { globalSetup->xOverType = TwoPoint; } else if (strcmp("Uniform", pToken) == 0) { globalSetup->xOverType = Uniform; } else if (strcmp("SBX", pToken) == 0) { globalSetup->xOverType = SBX; } else { fclose(fInput); printf("Error! valid crossover types are: OnePoint, TwoPoint, Uniform, and SBX\n"); exit(1); } // read crossover parameters switch(globalSetup->xOverType) { case OnePoint: case TwoPoint: //no extra parameters break; case Uniform: { globalSetup->xOverParameters = new double[1]; if ((pToken = strtok(NULL, BLANK_STR)) == NULL) { printf("Using default genewise swap probability of 0.5\n"); ((double*)globalSetup->xOverParameters)[0] = 0.5; } else ((double*)globalSetup->xOverParameters)[0] = atof(pToken); if((((double*)globalSetup->xOverParameters)[0] <= 0.0)||(((double*)globalSetup->xOverParameters)[0] >= 1.0)) { fclose(fInput); printf("Genewise probability must be > 0.0 and < 1.0\n"); exit(1); } } case SBX: { globalSetup->xOverParameters = new double[2]; if ((pToken = strtok(NULL, BLANK_STR)) == NULL) { printf("Using default genewise swap probability of 0.5\n"); ((double*)globalSetup->xOverParameters)[0] = 0.5; } else ((double*)globalSetup->xOverParameters)[0] = atof(pToken); if((((double*)globalSetup->xOverParameters)[0] <= 0.0)||(((double*)globalSetup->xOverParameters)[0] >= 1.0)) { fclose(fInput); printf("Error! genewise probability must be > 0.0 and < 1.0\n"); exit(1); } if ((pToken = strtok(NULL, BLANK_STR)) == NULL) { printf("Using default polynomial order for SBX: 10\n"); ((double*)globalSetup->xOverParameters)[1] = 10; } else ((double*)globalSetup->xOverParameters)[1] = atof(pToken); if(((double*)globalSetup->xOverParameters)[1] < 0.0) { fclose(fInput); printf("Error! genewise probability must be >= 0.0\n"); exit(1); } } break; default: { fclose(fInput); printf("Error! invalid crossover parameter\n"); exit(1); } break; } // mutation if ((pToken = readOneLine(caBuf, ciBufSize, fInput)) == NULL) { fclose(fInput); printf("Error in the input file, please refer to the documentation\n"); exit(1); } if(strcmp("default", pToken) == 0) { printf("Using a default mutation probability of 0.1\n"); globalSetup->mutationProbability = 0.1; } // mutation probability // the number should be [0.0, 1.0] else if (((globalSetup->mutationProbability = atof(pToken)) < 0.0) || (globalSetup->mutationProbability > 1.0)) { fclose(fInput); printf("Error! mutation probability must be >= 0.0 and <= 1.0.\n"); exit(1); } // mutation type if ((pToken = readOneLine(caBuf, ciBufSize, fInput)) == NULL) { fclose(fInput); printf("Error in the input file, please refer to the documentation\n"); exit(1); } if(strcmp("default", pToken) == 0) { printf("Using Polynomial as the default mutation method. Note that this might be an inappropriate choice if your variables are binary\n"); globalSetup->mutationType = Polynomial; } else if (strcmp("Selective", pToken) == 0) { globalSetup->mutationType = Selective; } else if (strcmp("Genewise", pToken) == 0) { globalSetup->mutationType = Genewise; } else if (strcmp("Polynomial", pToken) == 0) { globalSetup->mutationType = Polynomial; } else { fclose(fInput); printf("Error! valid mutation types are: Selective, Genewise, and Polynomial\n"); exit(1); } // read mutation parameters switch(globalSetup->mutationType) { case Selective: // no extra parameters break; case Polynomial: { globalSetup->mutationParameters = new int[1]; if ((pToken = strtok(NULL, BLANK_STR)) == NULL) { printf("Using a default value for the polynomial probability: 20\n"); ((int*)globalSetup->mutationParameters)[0] = 20; } else ((int*)globalSetup->mutationParameters)[0] = atoi(pToken); if(((int*)globalSetup->mutationParameters)[0] < 0) { fclose(fInput); printf("Error! polynomial order for polynomial mutation must be > 0\n"); exit(1); } } break; case Genewise: { globalSetup->mutationParameters = new double[globalSetup->noOfDecisionVariables]; for (ii = 0 ; ii < globalSetup->noOfDecisionVariables ; ii++) { if ((pToken = strtok(NULL, BLANK_STR)) == NULL) { printf("Using default std. deviation of 10% of the variable range\n"); ((double*)globalSetup->mutationParameters)[ii] = 0.1*(globalSetup->variableRanges[ii][1] - globalSetup->variableRanges[ii][0]); } else ((double*)globalSetup->mutationParameters)[ii] = atof(pToken); if(((double*)globalSetup->mutationParameters)[ii] <= 0.0) { fclose(fInput); printf("Error! standard deviation for gene %d for genewise mutation must be > 0\n", ii); exit(1); } } } break; default: { fclose(fInput); printf("Error! invalid mutation parameter\n"); exit(1); } break; } // scaling method if ((pToken = readOneLine(caBuf, ciBufSize, fInput)) == NULL) { fclose(fInput); printf("Error in the input file, please refer to the documentation\n"); exit(1); } if(strcmp("default", pToken) == 0) { printf("Scaling is not used by default\n"); globalSetup->scalingMethod = NoScaling; } // scaling method else if (strcmp("NoScaling", pToken) == 0) { globalSetup->scalingMethod = NoScaling; } else if (strcmp("Ranking", pToken) == 0) { globalSetup->scalingMethod = Ranking; } else if (strcmp("SigmaScaling", pToken) == 0) { globalSetup->scalingMethod = SigmaScaling; } else { fclose(fInput); printf("Error! valid scaling methods are: NoScaling, Ranking, and SigmaScaling\n"); exit(1); } // read scaling parameters switch(globalSetup->scalingMethod) { case NoScaling: case Ranking: // no extra parameters break; case SigmaScaling: { globalSetup->scalingParameters = new double[1]; if ((pToken = strtok(NULL, BLANK_STR)) == NULL) { ((double*)globalSetup->scalingParameters)[0] = 1.0; } else ((double*)globalSetup->scalingParameters)[0] = atof(pToken); if(((double*)globalSetup->scalingParameters)[0] <= 0.0) { fclose(fInput); printf("Error! scaling parameter for SigmaScaling must be > 0\n"); exit(1); } } break; default: { fclose(fInput); printf("Error! invalid scaling parameter\n"); exit(1); } break; } // constraint method if ((pToken = readOneLine(caBuf, ciBufSize, fInput)) == NULL) { fclose(fInput); printf("Error in the input file, please refer to the documentation\n"); exit(1); } if(strcmp("default", pToken) == 0) { if(globalSetup->finalNoOfConstraints == 0) { printf("Using no constraint handling method by default\n"); globalSetup->constraintMethod = NoConstraints; } else { printf("Using tournament selection as the default constraint handling method\n"); globalSetup->constraintMethod = Tournament; } } // constraint method else if (strcmp("NoConstraints", pToken) == 0) { globalSetup->constraintMethod = NoConstraints; } else if (strcmp("Penalty", pToken) == 0) { globalSetup->constraintMethod = Penalty; } else if (strcmp("Tournament", pToken) == 0) { globalSetup->constraintMethod = Tournament; } else { fclose(fInput); printf("Error! valid constraint handling methods are: NoConstraint, Penalty, and Tournament\n"); exit(1); } // check constraint method if ((globalSetup->gaType == NSGA) && (globalSetup->constraintMethod == Penalty)) { fclose(fInput); printf("Error! penalty based constraint handling method cannot be used with NSGA\n"); exit(1); } if ((globalSetup->finalNoOfConstraints == 0) && (globalSetup->constraintMethod != NoConstraints)) { fclose(fInput); printf("Error! valid constraint-handling method when there are no constraints is NoConstraints\n"); exit(1); } // read penalty function switch(globalSetup->constraintMethod) {
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -