Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int GeneticFitnessFunction(node state) {
- return MAX_COST - CalculateAttackingQueens(state);
- }
- node GeneticFindBestState(vector<node>& population) {
- node best = population[0];
- int bestScore = GeneticFitnessFunction(best);
- for (unsigned i = 1; i < population.size(); i++)
- {
- int score = GeneticFitnessFunction(population[i]);
- if (score > bestScore) {
- best = population[i];
- bestScore = score;
- }
- }
- return best;
- }
- void GeneticCreatePopulation(vector<node>& population) {
- // TODO Implement this (InClass #7)
- }
- node GeneticSelect(vector<node>& population) {
- float probability = 1.f;
- int score = 0;
- int i = rand() % sizeof(population);
- for (; true; i = rand() % sizeof(population)) {
- score = GeneticFitnessFunction(population[i]);
- probability = (float)(score / GENETIC_MAX);
- if (probability >= (float)((rand() % 101) / 100.f)) {
- }
- }
- return population[i];
- }
- node GeneticReproduce(node x, node y) {
- node child = x;
- for (int i = rand() % (sizeof(x) / sizeof(node)); i < (sizeof(x) / sizeof(node)); i++) {
- child.queens[i] = y.queens[i];
- }
- return child;
- }
- node GeneticMutate(node child) {
- // TODO Implement this (InClass #7)
- return child;
- }
- // TODO (InClass #7 - Implement genetic algorithm)
- node GeneticAlgorithm() {
- node test = {0, 1, 2, 3, 4, 5, 6, 7};
- return test;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement