From 6d4805e3d0d28174a82c37b4362f33981e673d5b Mon Sep 17 00:00:00 2001
From: Mauricio Zambrano-Bigiarini <hzambran@users.noreply.github.com>
Date: Thu, 20 Sep 2012 16:38:28 +0000
Subject: [PATCH] 'hydroPSO': SPSO-2011 V[t+1] is now correctly implemented

---
 R/PSO_v2012.R | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/R/PSO_v2012.R b/R/PSO_v2012.R
index eeaaee7..87ad38f 100755
--- a/R/PSO_v2012.R
+++ b/R/PSO_v2012.R
@@ -238,14 +238,18 @@ compute.veloc <- function(x, v, w, c1, c2, CF, Pbest, part.index, gbest,
   r2 <- runif(n, min=0, max=1)
   
   if ( method=="spso2011" ) {
-  
-     # gx = Gi - Xi:
-     ifelse( part.index != localBest.pos,
-             gx <- r1*(c1/3)*(pbest-x) + r2*(c2/3)*(localBest-x),
-             gx <- r1*(c1/2)*(pbest-x)
-           )
+
+       p <- x + r1*c1 * ( pbest - x )
+       l <- x + r2*c2 * ( localBest - x )
+       
+       ifelse( part.index != localBest.pos,
+              Gr <- (1/3)*(x + p + l),
+              Gr <- (1/2)*(x + p)
+             )
      
-     vn <- CF * (w*v + gx + alea.sphere(G=gx + x, radius=enorm(gx) ) )
+      vn <- CF * (w*v + alea.sphere( G=Gr, radius= enorm(Gr-x) ) - x )
+      
+      #vn <- CF * (w*v + gx + alea.sphere(G=gx + x, radius=enorm(gx) ) )
   
   } else if ( method=="spso2007" ) {
   
-- 
GitLab