knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
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
.
library(rBAS) #load package help(BASoptim) help(BSASoptim)
Two typocal test functions are applied to validate the efficacy of BAS/BSAS algorithm
library(rBAS) mich <- function(x){ y1 <- -sin(x[1])*(sin((x[1]^2)/pi))^20 y2 <- -sin(x[2])*(sin((2*x[2]^2)/pi))^20 return(y1+y2) }
test<- BASoptim(fn = mich, lower = c(-6,0), upper = c(-1,2), seed = 1, n = 100,trace = F) test$par test$value summary(test$df)
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 test$value summary(test$df)
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 result$value
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.
test<- BSASoptim(fn = mich, lower = c(-6,0), upper = c(-1,2), seed = 12, n = 100,k=5, trace = F) test$par test$value summary(test$df)
test<- BSASoptim(fn = gold, lower = c(-2,-2), upper = c(2,2), seed = 11, n = 100,k=2, trace = F) test$par test$value summary(test$df)
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:
basic interface
automatic report generation
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
Jiangyu Wang
School of Energy and Power Engineering, Huazhong University of Science and Technology
Shuai Li
personal homepage & Googlescholar
Department of Computing, The Hong Kong Polytechnic University
Xiangyuan Jiang
Department of Computing, The Hong Kong Polytechnic University
citation(package = '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.
The project is released under the terms of the GPL-3.0.
Copyright © 2018 Jiangyu Wang
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.