Differntial Evolution
by Kenneth Price and Rainer Storn

Listing One
while (count < gen_max)         /* Halt after gen_max generations. */
{ 
   for (i=0; i<NP; i++)         /* Start loop through population. */
   {
                             /********** Mutate/recombine **********/
      do a=rnd_uni()*NP; while (a==i); /* Randomly pick 3 vectors, */ 
      do b=rnd_uni()*NP; while (b==i || b==a);    /* all different */
      do c=rnd_uni()*NP; while (c==i || c==a || c==b);  /* from i. */
      j=rnd_uni()*D;         /* Randomly pick the first parameter. */
      for (k=1; k<=D; k++)      /* Load D parameters into trial[]. */
      {                            /* Perform D-1 binomial trials. */
         if (rnd_uni() < CR || k==D)     /* Source for trial[j] is */
         {           /* a random vector plus weighted differential */
            trial[j]=x1[c][j]+F*(x1[a][j]-x1[b][j]);      /* or... */
         }          /* trial parameter comes from x1[i][j] itself. */
         else trial[j]=x1[i][j];
         j=(j+1)%D;               /* get next parameter, modulo D. */
      }    /* Last parameter (k=D) comes from noisy random vector. */
                              /********** Evaluate/select **********/
      score=evaluate(trial); /* Evaluate trial with your function. */ 
      if (score<=cost[i])       /* If trial[] improves on x1[i][], */
      {                         /* move trial[] to secondary array */
         for (j=0; j<D; j++) x2[i][j]=trial[j];
         cost[i]=score;                 /* and store improved cost */
      }             /* otherwise, move x1[i][] to secondary array. */ 
      else for (j=0; j<D; j++) x2[i][j]=x1[i][j];
   }                /* Mutate/recombine next primary array vector. */

          /********** End of population loop; swap arrays **********/
   for (i=0; i<NP; i++)                 /*  After each generation, */
   {                   /* move secondary array into primary array. */
      for (j=0; j<D; j++) x1[i][j]=x2[i][j];
   }                      /* ...or just swap pointers (not shown). */
   count++;              /* End of generation...increment counter. */
                            /********** End of generation **********/
}                                               /* End of program. */



1


