GeneticAlgorithm.h 803 B

12345678910111213141516171819202122232425
  1. #pragma once
  2. #include "ObjectiveFunction.h"
  3. #include "BinaryHeuristic.h"
  4. #include <ostream>
  5. class GeneticAlgorithm : BinaryHeuristic
  6. {
  7. public:
  8. GeneticAlgorithm(std::ostream& outstream, int iteration, int population, double mutateProbability = 0.01, double swapProbability = 0.5, double tournamentSize = 2.0);
  9. Solution execute(int round, int n, std::function<double(const std::vector<bool>&)> objectiveFunction, ObjectiveFunctionGoal goal) override;
  10. protected:
  11. private:
  12. //params:
  13. int iteration;
  14. int populationSize;
  15. double mutateProbability;
  16. double swapProbability;
  17. double tournamentSize;
  18. //methods:
  19. Solution& selectAParent(std::vector<Solution>& population, std::function<bool(double, double)> op);
  20. void crossover(Solution& childA, Solution& childB);
  21. void mutate(Solution& individual);
  22. };