OptimisationProblem/GeneticAlgorithm.h

35 lines
868 B
C
Raw Normal View History

2023-07-17 00:19:10 +02:00
#pragma once
#include "Solution.h"
typedef std::vector<Solution*> Solutions;
typedef std::vector<float> Scores;
typedef float (*FitnessFn)(Solution*);
typedef Solution* (*SelectionFn)(Solutions*, Scores*);
typedef void (*CrossoverFn)(float rCross, Solution*, Solution*, Solution**, Solution**);
typedef void (*MutatorFn)(Solution*, float);
class GeneticAlgorithm
{
private:
int generations;
float rCross;
float rMut;
Solutions* population;
// GA Functions
FitnessFn fitness;
SelectionFn selection;
CrossoverFn crossover;
MutatorFn mutate;
public:
GeneticAlgorithm(int nGen, float rCross, float rMut, Solutions* population, FitnessFn ff, SelectionFn sf, CrossoverFn cf, MutatorFn mf): //
generations(nGen), rCross(rCross), rMut(rMut), population(population), fitness(ff), selection(sf), crossover(cf), mutate(mf) //
{};
Solution* algorithm();
};