EMOPSO::EMOPSO() { setPopSize(40); setBinarySize(0); setFloatSize(4); setGenerations(625); setNumberOfClusters(3); setSeed(1); for (int i = 0; i != getFloatSize() ; i++) { setFLLimit(-5,i); setFHLimit(5,i); } setMaxArchiveSize(100); setSocialAcc(2.0); setCognitiveAcc(2.0); setInertia(0.4); setFlyTime(5); nclusters= 3; gen=0; archive = new EFILE; }
// FIX - too long (separate into more than one function) // FIX - Make a function that prints out its usage (help function) void initParameters(int argc, char ** argv){ char * arch_filename = DEFAULT_ARCH_FILENAME; char * dfg_filename = DEFAULT_DFG_FILENAME; char * prr_filename = DEFAULT_PRR_FILENAME; int seed = randSeed(); int c; opterr = 0; while((c = getopt(argc, argv, "a:b:c:d:f:g:h:m:n:o:p:r:s:t:Vvw:")) != -1){ switch(c){ case 'a': arch_filename = optarg; break; case 'b': if(strncasecmp("one-point", optarg, strlen(optarg)) == 0 || strncasecmp("one_point", optarg, strlen(optarg)) == 0 || strncasecmp("one point", optarg, strlen(optarg)) == 0 ) crossover_type = 1; else if(strncasecmp("two-point", optarg, strlen(optarg)) != 0 && strncasecmp("two_point", optarg, strlen(optarg)) != 0 && strncasecmp("two point", optarg, strlen(optarg)) != 0 ){ fprintf(stderr, "Unknown crossover option : %s\n", optarg); exit(1); } break; case 'c': setCrossoverRate(atof(optarg)); break; case 'd': dfg_filename = optarg; break; case 'f': setFitnessFunction(optarg); break; case 'g': MAX_NUM_GENERATIONS = atoi(optarg); break; case 'h': setSetupIndex(atoi(optarg)); break; case 'm': setMutationRate(atof(optarg)); break; case 'n': if(strncasecmp("random", optarg, strlen(optarg)) == 0) mutation_type = 2; else if(strncasecmp("rotationally", optarg, strlen(optarg)) != 0){ fprintf(stderr, "Unknown mutation option : %s\n", optarg); exit(1); } break; case 'p': setPopSize(atoi(optarg)); break; case 'r': if(strncasecmp("keep-best", optarg, strlen(optarg)) == 0 || strncasecmp("keep_best", optarg, strlen(optarg)) == 0 || strncasecmp("keep best", optarg, strlen(optarg)) == 0) replacement_type = 2; else if(strncasecmp("all", optarg, strlen(optarg)) != 0){ fprintf(stderr, "Unknown replacement option : %s\n", optarg); exit(1); } break; case 's': if(strncasecmp("random", optarg, strlen(optarg)) == 0) selection_type = 2; else if(strncasecmp("tournament", optarg, strlen(optarg)) != 0){ fprintf(stderr, "Unknown selection option : %s\n", optarg); exit(1); } break; case 't': seed = atoi(optarg); break; case 'V': case 'v': fprintf(stdout, "Offline Scheduler version 2.0 (GA + Napoleon + rcSimulator)\n"); #ifdef DEBUG fprintf(stdout, "Using the DEBUG build\n\n"); #endif #ifdef VERBOSE fprintf(stdout, "Using the VERBOSE build\n\n"); #endif #ifdef STATS fprintf(stdout, "Using the STATS build\n\n"); #endif fprintf(stdout, "Please see https://github.com/Aalwattar/GA for more information\n"); exit(0); case 'w': setRuntimeWeight(atof(optarg)); break; case ':': fprintf(stderr, "Option -%c requires an operand\n", optopt); break; case '?': fprintf(stderr, "Unrecognized option: -%c\n", optopt); default: exit(1); } } if(optind < argc){ printf("Non-option argument %s\n", argv[optind]); exit(1); } // FIX - Check the return value seedRandGenerator(seed); if(initScheduler(arch_filename, dfg_filename, prr_filename) == EXIT_FAILURE) exit(1); if(POP_SIZE == 0){ POP_SIZE = getNumNodes(); } fprintf(stdout, "Parameters:\n"); fprintf(stdout, "\tFitness Function = %s\n\n", getFitnessFunction()); fprintf(stdout, "\tPopulation Size = %d\n", POP_SIZE); fprintf(stdout, "\tNumber of Generations = %d\n\n", MAX_NUM_GENERATIONS); fprintf(stdout, "\tMutation Rate = %.4lf\n", getMutationRate()); fprintf(stdout, "\tCrossover Rate = %.4lf\n", getCrossoverRate()); fprintf(stdout, "\tRuntime Weight = %.4lf\n", getRuntimeWeight()); fprintf(stdout, "\tPower Weight = %.4lf\n\n", 1.0 - getRuntimeWeight()); if(crossover_type == 1) fprintf(stdout, "\tCrossover Algorithm = One point Crossover\n"); else fprintf(stdout, "\tCrossover Algorithm = Two point Crossover\n"); if(mutation_type == 1) fprintf(stdout, "\tMutation Algorithm = Rotational Mutation\n"); else fprintf(stdout, "\tMutation Algorithm = Random Mutation\n"); if(selection_type == 1) fprintf(stdout, "\tSelection Algorithm = Tournament Selection\n"); else fprintf(stdout, "\tSelection Algorithm = Random Selection\n"); if(replacement_type == 1) fprintf(stdout, "\tReplacement Algorithm = Replace All\n\n"); else fprintf(stdout, "\tReplacement Algorithm = Keep Best\n\n"); // FIX - make this dynamic fprintf(stdout, "\tSeed = %d\n", seed); fprintf(stdout, "\tPercent seeding = %.4lf\n", (1.0 - PERCENT_POP_RANDOM)); }