-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGA.h
56 lines (52 loc) · 1.45 KB
/
GA.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// Created by morps on 11/16/16.
//
#include<list>
#include<vector>
#include "Util.h"
#ifndef PROJETOTG_GA_H
#define PROJETOTG_GA_H
class GA{
public:
struct Chromo{
std::vector<bool> bits;
float fitness;
Chromo(): bits( {false}), fitness(0.0f){};
Chromo(std::vector<bool> bts, float ftns): bits(bts), fitness(ftns){}
};
void setPsize(int value);
void setMaxgen(int value);
void setXover(float value);
void setXmen(float value);
void setGlength(int value);
void setClength(int value);
int getPsize();
int getMaxgen();
float getXover();
float getXmen();
int getGlength();
int getClength();
GA(int clength, Util::Vertex* array);
GA::Chromo getRandomChromo(int length);
float assignFitness(std::vector<bool> bits);
std::vector<bool> roulette(float total_fitness, Chromo* Population);
std::vector<bool> elitism(Chromo* Population);
void mutate(std::vector<bool>& bits);
void mutate2(std::vector<bool>& bits);
void crossover(std::vector<bool>& offspring1, std::vector<bool>& offspring2);
void printChromo(std::vector<bool> bits);
bool isClique(std::vector<bool> bits);
float grauAv(std::vector<bool> bits);
int bitSize(std::vector<bool> bits);
int run();
private:
int psize;
int maxgen;
float xover;
float xmen;
int glength;
int clength;
Util::Vertex* graph;
};
//class
#endif //PROJETOTG_GA_H