bool FlowShopOpCrossoverQuad::operator()(FlowShop & _flowshop1, FlowShop & _flowshop2) { bool oneAtLeastIsModified; // computation of the 2 random points unsigned int point1, point2; do { point1 = rng.random(std::min(_flowshop1.size(), _flowshop2.size())); point2 = rng.random(std::min(_flowshop1.size(), _flowshop2.size())); } while (fabs((double) point1-point2) <= 2); // computation of the offspring FlowShop offspring1 = generateOffspring(_flowshop1, _flowshop2, point1, point2); FlowShop offspring2 = generateOffspring(_flowshop2, _flowshop1, point1, point2); // does at least one genotype has been modified ? if ((_flowshop1 != offspring1) || (_flowshop2 != offspring2)) { // update _flowshop1.value(offspring1); _flowshop2.value(offspring2); // at least one genotype has been modified oneAtLeastIsModified = true; } else { // no genotype has been modified oneAtLeastIsModified = false; } // return 'true' if at least one genotype has been modified return oneAtLeastIsModified; }
void MainWindow::on_FPS_clicked() { //initial graph graphs gr; gr.setModal(true); int k = 0; while(k < COUNT){ TotalFitness = 0; population.clear(); newpopulation.clear(); generatePopulations(false); //sort by fitness sort(this->population.begin(), this->population.end(), by_fitness()); int j = 0; while(j < COUNT){ calc_prob_ranges(false); //offsprings for(int i=0; i<((COUNT/2)/2); i++){ float val = randomRange(0, 1); temp = generateOffspring(val); offsprint_x1 = temp.x; offsprint_y1 = temp.y; val = randomRange(0, 1); temp = generateOffspring(val); offsprint_x2 = temp.x; offsprint_y2 = temp.y; //mutation process mutation(offsprint_x1, offsprint_y2, offsprint_x2, offsprint_y1, false); } //merge new with old population population.insert(population.end(), newpopulation.begin(), newpopulation.end()); //clear new population newpopulation.clear(); //sort by compute sort(population.begin(), population.end(), by_fitness()); // erase unecessary elements/population: population.erase(population.begin()+COUNT,population.end()); //cout << "population for new iteration" << endl; TotalFitness = 0; for(int i=0; i < population.size(); i++ ){ TotalFitness = TotalFitness + population[i].fitness; //cout << population[i].x << "," << population[i].y << "," << population[i].fitness << endl; } //best of iteration best.push_back(population[0].fitness); //cout << "fps best" << population[0].fitness << endl; //avg of iteration avg.push_back(population[(COUNT/2)-1].fitness); j++; } k++; TotalFitness = 0; pso(); ais(); gr.data.push_back({best, avg, pso_best, ais_best, ais_avg,COUNT}); reverse(pso_best.begin(), pso_best.end()); reverse(ais_best.begin(), ais_best.end()); reverse(ais_avg.begin(), ais_avg.end()); reverse(best.begin(), best.end()); reverse(avg.begin(), avg.end()); best_best.push_back(best[0]); avg_avg.push_back(avg[0]); ais_avg_avg.push_back(ais_avg[0]); pso_bb.push_back(pso_best[0]); pso_best.clear(); ais_bb.push_back(ais_best[0]); ais_best.clear(); ais_avg.clear(); best.clear(); avg.clear(); } gr.data.push_back({best_best,avg_avg, pso_bb, ais_bb, ais_avg_avg,COUNT}); best_best.clear(); avg_avg.clear(); ais_bb.clear(); pso_bb.clear(); ais_avg_avg.clear(); // for(int i=0; i < COUNT; i++ ){ // gr.best.push_back({best[i].fitness}); // gr.avg.push_back({avg[i].fitness}); // } // cout << gr.best.size() << endl; // gr.generation = COUNT; gr.makePlot(0); gr.exec(); }