# Setting the user home directory as working directory
setwd("~")
# Number of dimensions to be optimised
nparam <- 4
# Setting the seed
set.seed(100)
# Runing PSO with the 'sphere' test function, writting the results to text files
hydroPSO(
fn= "sphere", lower=rep(-100, nparam), upper=rep(100, nparam),
control=list(MinMax="min", npart=2*nparam, maxit=100, topology="gbest",
write2disk=TRUE, plot=TRUE)
)
# Reading the best parameter set and its corresponsing gof found by hydroPSO
setwd("PSO.out")
read_best()
Run the code above in your browser using DataLab