Skip to content
Snippets Groups Projects
Commit 4c597c40 authored by Mauricio Zambrano-Bigiarini's avatar Mauricio Zambrano-Bigiarini
Browse files

hydroPSO.R: improved performance of 'UpdateLocalBest'

parent 560178f7
No related branches found
No related tags found
No related merge requests found
......@@ -1006,23 +1006,21 @@ UpdateLocalBest <- function(pbest.fit, localBest.pos, localBest.fit, x.neighbour
# index of all the particles that are "neighbours" to the particle 'i'
neighs.index <- x.neighbours[i,]
# if one or more of the "neighbours" have a better fitness than the current Local Best
if(MinMax == "max") {
better.index <- which( pbest.fit[neighs.index] > localBest.fit[i] )
} else better.index <- which( pbest.fit[neighs.index] < localBest.fit[i] )
if (length(better.index) > 0) {
if(MinMax == "max") {
localBest.pos[i] <- neighs.index[which.max( pbest.fit[neighs.index] )]
best.neigh.index <- which.max( pbest.fit[neighs.index] )
if (pbest.fit[best.neigh.index] > localBest.fit[i] ) {
localBest.pos[i] <- neighs.index[best.neigh.index ]
localBest.fit[i] <- pbest.fit[localBest.pos[i]]
} # IF end
} else {
best.neigh.index <- which.min( pbest.fit[neighs.index] )
if ( pbest.fit[neighs.index][best.neigh.index] < localBest.fit[i] ) {
localBest.pos[i] <- neighs.index[best.neigh.index]
localBest.fit[i] <- pbest.fit[localBest.pos[i]]
} else {
localBest.pos[i] <- neighs.index[which.min( pbest.fit[neighs.index] )]
localBest.fit[i] <- pbest.fit[localBest.pos[i]]
} # ELSE end
} # |IF end
} # IF end
} # ELSE end
} # FOR end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment