72 lines
1.9 KiB
C++
72 lines
1.9 KiB
C++
#include "Individ.h"
|
|
#define _USE_MATH_DEFINES
|
|
#include <cmath>
|
|
|
|
float Individ::sigmaX = 1.f;
|
|
float Individ::sigmaE = 0.1f;
|
|
float Individ::sigmaC1 = 1.f;
|
|
float Individ::sigmaC2 = 1.f;
|
|
float Individ::sigmaC3= 1.f;
|
|
float Individ::sigmaC4= 1.f;
|
|
float Individ::sigmaC5= 1.f;
|
|
float Individ::Xopt = 110.f;
|
|
std::vector<float> Individ::c(5);
|
|
|
|
Individ::Individ(float _E) : E(_E) {};
|
|
IndividFeedBack::IndividFeedBack(float _E) : Individ(_E), C2(Individ::c[1]) {}
|
|
//IndividFeedBack(const IndividFeedBack& parent) : Individ(parent.E), C2(parent.C2) {}
|
|
|
|
float Individ::getFitness() const {
|
|
float X = c[0]/c[2] * (E+c[3]);
|
|
float fitness = 1/(sqrt(2*M_PI)) * exp(-0.5*pow((X-Xopt)/sigmaX,2.f));
|
|
return fitness;
|
|
}
|
|
|
|
float IndividFeedBack::getFitness() const {
|
|
//float X = -c[1]/2 + sqrt( c[1]*c[1]/4 + c[4]*c[1]/c[2]*(E+c[3]));
|
|
float X = -C2/2 + sqrt( C2*C2/4 + c[4]*C2/c[2]*(E+c[3]));
|
|
float fitness = 1/(sqrt(2*M_PI)) * exp(-0.5*pow((X-Xopt)/sigmaX,2.f));
|
|
return fitness;
|
|
}
|
|
|
|
void Individ::initConstants(){
|
|
c[0] = 10.f;
|
|
c[1] = 100.f;
|
|
c[2] = 1.f;
|
|
c[3] = 1.f;
|
|
c[4] = 21.f;
|
|
Xopt = 110.f;
|
|
sigmaX = 1.f;
|
|
sigmaE = 0.1f;
|
|
}
|
|
|
|
void Individ::initConstantsFromGUI(float c1, float c2, float c3, float c4, float c5, float Xoptim, float sigX, float sigE, float sigC1, float sigC2,
|
|
float sigC3, float sigC4, float sigC5)
|
|
{
|
|
c[0] = c1;
|
|
c[1] = c2;
|
|
c[2] = c3;
|
|
c[3] = c4;
|
|
c[4] = c5;
|
|
Xopt = Xoptim;
|
|
sigmaX = sigX;
|
|
sigmaE = sigE;
|
|
sigmaC1 = sigC1;
|
|
sigmaC2 = sigC2;
|
|
sigmaC3 = sigC3;
|
|
sigmaC4 = sigC4;
|
|
sigmaC5 = sigC5;
|
|
}
|
|
|
|
float IndividFeedBack::getOptimalE(){
|
|
float a = (Xopt + c[1]/2)*(Xopt + c[1]/2);
|
|
float b = c[1]*c[1]/4;
|
|
|
|
float ans = (a-b)*c[2]/(c[4]*c[1]) - c[3];
|
|
return ans;
|
|
}
|
|
|
|
bool compareOnFitness(const Individ* a, const Individ* b){
|
|
return a->getFitness() < b->getFitness();
|
|
}
|