void GeneticAlgorithm::run() {


    Population p = createBasePopulation();
    p.process();
    generations.push_back(p);

    double fitness = 0.001;
    int generation = 0;

    while(generation < params.generations){
        //p.printChromos();
        generation++;
        p = p.tournament_selection(generation);
        p.crossover_selection(params.crossoverPercent);
        p.mutation(params.mutationPercent);
        p.process();

        p.calcDiversity();
        //p.printBestCandidate();
       // std::cout << "Min Fitness: " << p.minFitness << std::endl;
       // std::cout << "Max Fitness: " << p.maxFitness << std::endl;

        generations.push_back(p);
     }

    generations.back().printBestCandidate();

    //resultToFile();
    resultAsJson();
}
Example #2
0
Environment::Environment(Point start, Point target, int type, int populationSize, float f, float cr, int movementSteps) {
	this->start.x = start.x;
	this->start.y = start.y;
	this->target.x = target.x;
	this->target.y = target.y;

	this->type = type;
	this->movementSteps = movementSteps;
	this->f = f;
	this->cr = cr;
	startPopulationSize = populationSize;
	createBasePopulation();
}