# NOT RUN {
# Setting the user home directory as working directory
setwd("~")
# Number of dimensions to be optimised
D <- 5
# Boundaries of the search space (Ackley test function)
lower <- rep(-32, D)
upper <- rep(32, D)
# Setting the seed
set.seed(100)
# Running PSO with the 'ackley' test function, writing the results to text files
hydroPSO(fn=ackley, lower=lower, upper=upper)
# Reading all the results and storing them in a variable
res <- read_results()
# Plotting all the results with a goodness-of-fit value lower than 5
plot_results(MinMax="min", beh.thr=5)
# }
# NOT RUN {
# }
# NOT RUN {
################################################################################
####################### SPSO-2007 example START ###############################
################################################################################
# Number of dimensions to be optimised
D <- 10
# boundaries for the test function
lower <- rep(-100, D) # sphere
#lower <- rep(-5.12, D) # rastrigin
#lower <- rep(-32, D) # ackley
fn <- sphere
#fn <-rastrigin
#fn <-ackley
#######################################
##### SPSO-2007 parameters ########
npart <- 10+floor(2*sqrt(D))
c1 <- 0.5+log(2)
c2 <- 0.5+log(2)
abstol <- 1e-20
reltol <- 1e-20
maxit <- 1000
use.IW <- TRUE
IW.w <- 1/(2*log(2))
REPORT <- 100
lambda <- 1
boundary.wall <- "absorbing2007"
#######################################
# Setting the user home directory as working directory
setwd("~")
# Running PSO and writing the results to text files
set.seed(100)
hydroPSO(fn= fn, method="spso2007", lower=lower, upper=-lower,
control=list(MinMax="min", maxit=maxit, npart=npart,
c1=c1, c2=c2,
use.IW=use.IW, IW.w=IW.w,
topology="random", lambda=lambda, K=3,
Xini.type="random", Vini.type="random2007",
best.update="sync",
boundary.wall=boundary.wall,
write2disk=TRUE, plot=FALSE, REPORT=REPORT,
abstol=abstol, reltol=reltol
)
)
# Plotting all the results
plot_results(MinMax="min")
################################################################################
####################### SPSO-2007 example END ###############################
################################################################################
################################################################################
############### recommended hydroPSO configuration - START #####################
################################################################################
# Running PSO and writing the results to text files
set.seed(100)
hydroPSO(fn= fn, method="spso2011", lower=lower, upper=-lower,
control=list(MinMax="min", maxit=maxit, npart=40,
c1=2.05, c2=2.05,
use.IW=FALSE, use.CF=TRUE,
topology="random", K=11,
use.TVlambda=TRUE, TVlambda.rng=c(1, 0.5),
Xini.type="lhs", Vini.type="lhs2011",
best.update="sync",
boundary.wall="absorbing2011",
write2disk=FALSE, plot=FALSE, REPORT=REPORT,
abstol=abstol, reltol=reltol
)
)
# compare the final optimum value and the number of function calls with those
# obtained in the SPSO-2007 example
################################################################################
################ recommended hydroPSO configuration - END ######################
################################################################################
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab