use normal distribution on initial random individual creation
initial default range tweaked way down rename "POP" template parameter to "POPSIZE" added RunOneGeneration() method - generations can now be run one at a time added SetRange(i,min,max) method added a decent amount of comments through main algorithm and class declaration
This commit is contained in:
1 parent
c194ae5fc5
commit
6f03c0b106
5 files changed
+267
-113
No files matched your search
@@ -8,9 +8,8 @@
|
||||
|
||||
namespace DE
|
||||
{
|
||||
|
||||
|
||||
template <unsigned int DIM, unsigned int POP=(DIM*10)>
|
||||
template <unsigned int DIM, unsigned int POPSIZE=(DIM*10)>
|
||||
class Engine
|
||||
{
|
||||
public:
|
||||
@@ -18,58 +17,69 @@ namespace DE
|
||||
Engine();
|
||||
virtual ~Engine();
|
||||
|
||||
void Reset();
|
||||
|
||||
const double* GetBest() const;
|
||||
|
||||
void SetRange(double minimum, double maximum);
|
||||
void SetRange(unsigned int i, double minimum, double maximum);
|
||||
void SetRange(const Vector<DIM>& minimum, const Vector<DIM>& maximum);
|
||||
|
||||
virtual double CalculateError(const double testcase[DIM], bool& stop) = 0;
|
||||
|
||||
void Reset();
|
||||
bool Solve(unsigned int maxgenerations = 1000000000);
|
||||
bool RunOneGeneration();
|
||||
|
||||
private:
|
||||
|
||||
void Select(unsigned int candidate, unsigned int *r1 = 0, unsigned int *r2 = 0, unsigned int *r3 = 0, unsigned int *r4 = 0, unsigned int *r5 = 0);
|
||||
// randomly select unique individuals
|
||||
void Select(
|
||||
unsigned int candidate,
|
||||
unsigned int *r1 = 0,
|
||||
unsigned int *r2 = 0,
|
||||
unsigned int *r3 = 0,
|
||||
unsigned int *r4 = 0,
|
||||
unsigned int *r5 = 0
|
||||
);
|
||||
|
||||
// print a single individual to stdout
|
||||
void Dump(const double& fitness, Vector<DIM>& individual) const;
|
||||
|
||||
void MakeTrial_best1exp(unsigned int candidate, Vector<DIM>& trial);
|
||||
void MakeTrial_rand1exp(unsigned int candidate, Vector<DIM>& trial);
|
||||
void MakeTrial_randtobest1exp(unsigned int candidate, Vector<DIM>& trial);
|
||||
void MakeTrial_best2exp(unsigned int candidate, Vector<DIM>& trial);
|
||||
void MakeTrial_rand2exp(unsigned int candidate, Vector<DIM>& trial);
|
||||
void MakeTrial_best1bin(unsigned int candidate, Vector<DIM>& trial);
|
||||
void MakeTrial_rand1bin(unsigned int candidate, Vector<DIM>& trial);
|
||||
void MakeTrial_randtobest1bin(unsigned int candidate, Vector<DIM>& trial);
|
||||
void MakeTrial_best2bin(unsigned int candidate, Vector<DIM>& trial);
|
||||
void MakeTrial_rand2bin(unsigned int candidate, Vector<DIM>& trial);
|
||||
|
||||
private:
|
||||
// DE algorithm
|
||||
void MakeTrial_best1exp (unsigned int candidate, Vector<DIM>& trial);
|
||||
void MakeTrial_rand1exp (unsigned int candidate, Vector<DIM>& trial);
|
||||
void MakeTrial_randtobest1exp (unsigned int candidate, Vector<DIM>& trial);
|
||||
void MakeTrial_best2exp (unsigned int candidate, Vector<DIM>& trial);
|
||||
void MakeTrial_rand2exp (unsigned int candidate, Vector<DIM>& trial);
|
||||
void MakeTrial_best1bin (unsigned int candidate, Vector<DIM>& trial);
|
||||
void MakeTrial_rand1bin (unsigned int candidate, Vector<DIM>& trial);
|
||||
void MakeTrial_randtobest1bin (unsigned int candidate, Vector<DIM>& trial);
|
||||
void MakeTrial_best2bin (unsigned int candidate, Vector<DIM>& trial);
|
||||
void MakeTrial_rand2bin (unsigned int candidate, Vector<DIM>& trial);
|
||||
|
||||
// constants, parameters
|
||||
static const double DEFAULTSCALE;
|
||||
static const double DEFAULTCROSSOVER;
|
||||
static const double DEFAULTRANGE;
|
||||
static const double BIGDOUBLE;
|
||||
double scale;
|
||||
double crossover;
|
||||
|
||||
// entropy source
|
||||
Random prng;
|
||||
|
||||
private:
|
||||
|
||||
Random prng;
|
||||
|
||||
// population
|
||||
Vector<DIM> best;
|
||||
Vector<DIM> minimum;
|
||||
Vector<DIM> maximum;
|
||||
Vector<DIM> population[POP];
|
||||
double fitness[POP];
|
||||
|
||||
double scale;
|
||||
double crossover;
|
||||
Vector<DIM> mean;
|
||||
Vector<DIM> variance;
|
||||
Vector<DIM> population[POPSIZE];
|
||||
double fitness[POPSIZE];
|
||||
double bestfitness;
|
||||
|
||||
};
|
||||
// algorithm state
|
||||
bool success;
|
||||
unsigned int generation;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user