An R module aimed at implementation of Beetle Antennae Search (BAS) Algorithm and its mutations, for example, Beetle Swarm Antenae Search (BSAS) Algorithm.
rBAS
is currently not on CRAN. You can install rBAS
from Github with:
devtools::install_github("jywang2016/rBAS")
Use help()
to see the document pages about functions in rBAS
.
Two typocal test functions are applied to validate the efficacy of BAS/BSAS algorithm
gold <- function(x){
x1 <- x[1]
x2 <- x[2]
y1 <- 1 + (x1 + x2 + 1)^2*(19 - 14*x1+3*x1^2 - 14*x2 + 6*x1*x2 + 3*x2^2)
y2 <- 30 + (2*x1 -3*x2)^2*(18 - 32*x1 + 12*x1^2+48*x2-36*x1*x2 + 27*x2^2)
return(y1*y2)
}
test<-
BASoptim(fn = gold,
lower = c(-2,-2), upper = c(2,2),
seed = NULL, n = 100,trace = F)
test$par
#> [1] 0.001870855 -0.996496153
test$value
#> [1] 3.004756
summary(test$df)
#> Length Class Mode
#> x 174 -none- numeric
#> f 87 -none- numeric
#> xbest 174 -none- numeric
#> fbest 87 -none- numeric
pressure_Vessel <- list(
obj = function(x){
x1 <- floor(x[1])*0.0625
x2 <- floor(x[2])*0.0625
x3 <- x[3]
x4 <- x[4]
result <- 0.6224*x1*x3*x4 + 1.7781*x2*x3^2 +3.1611*x1^2*x4 + 19.84*x1^2*x3
},
con = function(x){
x1 <- floor(x[1])*0.0625
x2 <- floor(x[2])*0.0625
x3 <- x[3]
x4 <- x[4]
c(
0.0193*x3 - x1,
0.00954*x3 - x2,
750.0*1728.0 - pi*x3^2*x4 - 4/3*pi*x3^3
)
}
)
result <- BSASoptim(fn = pressure_Vessel$obj,
k = 10,
lower =c( 1, 1, 10, 10),
upper = c(100, 100, 200, 200),
constr = pressure_Vessel$con,
n = 200,
step = 100,
d1 = 4,
pen = 1e6,
steptol = 1e-6,
n_flag = 2,
seed = 2,trace = FALSE)
result$par
#> [1] 14.077163 7.087842 45.335198 140.284669
result$value
#> [1] 6090.567
In order to save space, the BSAS algorithm code is executed with trace
as FALSE
because of too much trace information. You can set trace
to TRUE
and observe the trace messages.
If you want find more algorithm which is avaliable in rBAS
.You can visit the Reference page. And click the function name. Furthermore, you can also get more examples of those algorithm application by this way. For example, the Pressure-Vessel problem solved by BSO algorithm can be found here.
BTW, in rBAS 0.1.8
, bBAS which is designed for binary-programming is added.
After rBAS 0.1.0
, shiny interface is added into rBAS
. Now, the users only need to define their objective problems in R code. And the rest of paramsters in BASoptim
or BSASoptim
functions can be adjust in the shiny interface.
For example, Michalewicz function
can be imported to shiny with united
theme as follows,
run_BAS_App(func = mich)
The theme
argument is used to provides Bootstrap themes for shiny. More details can be found in shinythemes
. Or you can use help(run_BAS_App)
to check which themes you can choose.
Algorithm:
Application:
UI interface:
You can list your requirements in the issues. Furthermore, if you have a good idea or codes about BAS’s mutations, pull requests and discussions are welcome. Contact me by email: jywang_2016@hust.edu.cn
citation(package = 'rBAS')
#>
#> To cite package 'rBAS' in publications use:
#>
#> Jiangyu Wang, Shuai Li and Xiangyuan Jiang (2018). rBAS:
#> Implementation of the BAS algorithm and its mutation. R package
#> version 0.1.8. https://github.com/jywang2016/rBAS
#>
#> A BibTeX entry for LaTeX users is
#>
#> @Manual{,
#> title = {rBAS: Implementation of the BAS algorithm and its mutation},
#> author = {Jiangyu Wang and Shuai Li and Xiangyuan Jiang},
#> year = {2018},
#> note = {R package version 0.1.8},
#> url = {https://github.com/jywang2016/rBAS},
#> }
J. Y. Wang, and H. X. Chen, “BSAS: Beetle Swarm Antennae Search Algorithm for Optimization Problems,” arXiv:1807.10470v1. Chinese Handbook of rBAS, please click here.