# NOT RUN {
##################################
## Optimizing the schewefel's problem 1.2 function
# define schewefel's problem 1.2 function as objective function
schewefels1.2 <- function(x){
dim <- length(x)
result <- 0
for(i in 1:dim){
result <- result + sum(x[1:i])^2
}
return(result)
}
## Define parameter
Vmax <- 2
ci <- 1.5
cg <- 1.5
w <- 0.7
numVar <- 5
rangeVar <- matrix(c(-10,10), nrow=2)
## calculate the optimum solution using Particle Swarm Optimization Algorithm
resultPSO <- PSO(schewefels1.2, optimType="MIN", numVar, numPopulation=20,
maxIter=100, rangeVar, Vmax, ci, cg, w)
## calculate the optimum value using schewefel's problem 1.2 function
optimum.value <- schewefels1.2(resultPSO)
# }
Run the code above in your browser using DataLab