//2.1 DE/current to selbest/1 scheme public void d_evolve_rand_selbest_1(DecisionVector v, DecisionVector sbest, DecisionVector v2, DecisionVector v3, double F, double X) { for (int i = 0; i < v.Dimension; i++) { v.TrialVector[i] = v.CurrentVector[i] + X * (sbest.CurrentVector[i] - v.CurrentVector[i]) + F * (v2.CurrentVector[i] - v3.CurrentVector[i]); } }
//3.1 DE/selbest/1 scheme public void d_evolve_selbest_1(DecisionVector v, DecisionVector sbest, DecisionVector v1, DecisionVector v2, double F, double X) { for (int i = 0; i < v.Dimension; i++) { v.TrialVector[i] = sbest.CurrentVector[i] + F * (v1.CurrentVector[i] - v2.CurrentVector[i]); } }
//12. combine linear weight between localbest to rand/1 public void d_evolve_rand1_to_localbest(DecisionVector v, DecisionVector lbest, DecisionVector v1, DecisionVector v2, DecisionVector v3, DecisionVector v4, DecisionVector v5, double F, double X, double W) { for (int i = 0; i < v.Dimension; i++) { v.TrialVector[i] = W * lbest.CurrentVector[i] + (1 - W) * v1.CurrentVector[i] + F * (v1.CurrentVector[i] - v2.CurrentVector[i]); } }
//1. DE/rand/1 scheme public void d_evole_r_1(DecisionVector v, DecisionVector v1, DecisionVector v2, DecisionVector v3, double F) { for (int i = 0; i < v.Dimension; i++) { v.TrialVector[i] = v1.CurrentVector[i] + F * (v2.CurrentVector[i] - v3.CurrentVector[i]); } }
//11. combine linear weight between randtolocalbest to rand/1 public void d_evolve_randtolocalbest_to_rand_1(DecisionVector v, DecisionVector lbest, DecisionVector v1, DecisionVector v2, DecisionVector v3, DecisionVector v4, DecisionVector v5, double F, double X, double W) { for (int i = 0; i < v.Dimension; i++) { v.TrialVector[i] = (1 - W) * (lbest.CurrentVector[i] + X * (lbest.CurrentVector[i] - v.CurrentVector[i]) + F * (v1.CurrentVector[i] - v2.CurrentVector[i])) + W * (v3.CurrentVector[i] + F * (v4.CurrentVector[i] - v5.CurrentVector[i])); } }
//9. combine linear weight between randtolocalBest and randtoBest public void d_evolve_rand_localBest_TO_rand_to_Best(DecisionVector v, DecisionVector lbest, DecisionVector vbest, DecisionVector v1, DecisionVector v2, DecisionVector v3, DecisionVector v4, double X, double F, double W) { for (int i = 0; i < v.Dimension; i++) { v.TrialVector[i] = (1 - W) * (v.CurrentVector[i] + X * (lbest.CurrentVector[i] - v.CurrentVector[i]) + F * (v2.CurrentVector[i] - v3.CurrentVector[i])) + W * (v.CurrentVector[i] + X * (vbest.CurrentVector[i] - v.CurrentVector[i]) + F * (v2.CurrentVector[i] - v3.CurrentVector[i])); } }
//4.DE/best/2 scheme public void d_evolve_best_2(DecisionVector v, DecisionVector vbest, DecisionVector v1, DecisionVector v2, DecisionVector v3, DecisionVector v4, double F) { for (int i = 0; i < v.Dimension; i++) { v.TrialVector[i] = vbest.CurrentVector[i] + F * (v1.CurrentVector[i] + v2.CurrentVector[i] - v3.CurrentVector[i] - v4.CurrentVector[i]); } }
//5.DE/rand/2 scheme public void d_evolve_rand_2(DecisionVector v, DecisionVector v1, DecisionVector v2, DecisionVector v3, DecisionVector v4, DecisionVector v5, double F) { for (int i = 0; i < v.Dimension; i++) { v.TrialVector[i] = v1.CurrentVector[i] + F * (v2.CurrentVector[i] - v3.CurrentVector[i]) + F * (v4.CurrentVector[i] - v5.CurrentVector[i]); } }
public void randomtrialvector(DecisionVector v) // diff way to generate new vector { Random rnd = new Random(); for (int i = 0; i < v.Dimension; i++) { v.TrialVector[i] = rnd.NextDouble(); } }
public void Crossover_1point(DecisionVector v, double coRate, Random rnd) { for (int i = 0; i < v.Dimension; i++) // consider each dimension àŹР{ if (rnd.NextDouble() >= coRate) { v.TrialVector[i] = v.CurrentVector[i]; } } }
public Population(int nVec, int nDim) { // construct a population with nVec vector, // each vector with nDim dimension Member = nVec; Vector = new DecisionVector[Member]; // declare size of Vector (array) lBestVectorIndex = new int[Member]; sBestVectorIndex = new int[Member]; for (int i = 0; i < Member; i++) { //Initialize vectors and each vector has nDim dimension Vector[i] = new DecisionVector(nDim); } }
public void Crossover_2point(DecisionVector v, double coRate, Random rnd) { int start_p = rnd.Next(v.Dimension); int L = 0; do { L++; }while ((rnd.NextDouble() <= coRate) && (start_p + L < v.Dimension)); for (int i = start_p; i < start_p + L; i++) { v.TrialVector[i] = v.CurrentVector[i]; } }
public virtual void LocalSearchVector(DecisionVector p, ref Random rnd) { }
public virtual double Objective(DecisionVector p, int trial) { //empty function to be override in the problem specific definition //to calculate objective function of a particle return(0); }