[Rcpp-commits] r2344 - pkg/RcppDE/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Oct 19 18:47:03 CEST 2010


Author: edd
Date: 2010-10-19 18:47:03 +0200 (Tue, 19 Oct 2010)
New Revision: 2344

Modified:
   pkg/RcppDE/src/de4_0.cpp
Log:
remove another unneeded variable declaration
reorder switch cases to 1,2,3, ...


Modified: pkg/RcppDE/src/de4_0.cpp
===================================================================
--- pkg/RcppDE/src/de4_0.cpp	2010-10-19 14:52:16 UTC (rev 2343)
+++ pkg/RcppDE/src/de4_0.cpp	2010-10-19 16:47:03 UTC (rev 2344)
@@ -133,7 +133,6 @@
     if (i_specinitialpop > 0) {    		// if initial population provided, initialize with values 
 	initialpop = trans(initialpopm);	// transpose as we prefer columns for population members here
     }
-    //l_nfeval = 0;    				// already init'ed in main function
 
     for (i = 0; i < i_NP; i++) {		// ------Initialization-----------------------------
 	if (i_specinitialpop <= 0) { 		// random initial member 
@@ -190,20 +189,20 @@
 	    k = 0;				// loop counter used in all strategies below 
 
 	    // ===Choice of strategy=======================================================
-	    switch (i_strategy) { 		// and putting default value one first
+	    switch (i_strategy) {
 
-	    case 2:				// ---DE/local-to-best/1/bin---------------------------------------------------
+	    case 1:				// ---classical strategy DE/rand/1/bin-----------------------------------------
 		j = static_cast<int>(::unif_rand() * i_D); 	// random parameter 
 		do {				// add fluctuation to random target 
-		    t_tmpP[j] = t_tmpP[j] + f_weight * (t_bestitP[j] - t_tmpP[j]) + f_weight * (ta_oldP.at(j,i_r2) - ta_oldP.at(j,i_r3));
+		    t_tmpP[j] = ta_oldP.at(j,i_r1) + f_weight * (ta_oldP.at(j,i_r2) - ta_oldP.at(j,i_r3));
 		    j = (j + 1) % i_D;
 		} while ((::unif_rand() < f_cross) && (++k < i_D));
 		break;
 
-	    case 1:				// ---classical strategy DE/rand/1/bin-----------------------------------------
+	    case 2:				// ---DE/local-to-best/1/bin---------------------------------------------------
 		j = static_cast<int>(::unif_rand() * i_D); 	// random parameter 
 		do {				// add fluctuation to random target 
-		    t_tmpP[j] = ta_oldP.at(j,i_r1) + f_weight * (ta_oldP.at(j,i_r2) - ta_oldP.at(j,i_r3));
+		    t_tmpP[j] = t_tmpP[j] + f_weight * (t_bestitP[j] - t_tmpP[j]) + f_weight * (ta_oldP.at(j,i_r2) - ta_oldP.at(j,i_r3));
 		    j = (j + 1) % i_D;
 		} while ((::unif_rand() < f_cross) && (++k < i_D));
 		break;



More information about the Rcpp-commits mailing list