bBASoptim: Implementation of the binary BAS(bBAS) algorithm for...

Description Usage Arguments Value References Examples

Description

bBAS is designed to solve the binary-integer-programming. It can also be employed on general optimization problems.

Usage

1
2
3
4
bBASoptim(fn, init = NULL, lower = c(-6, 0), upper = c(-1, 2),
  d0 = 1e-30, d1 = 3, eta_d = 0.99, w = 0.2, c = 0.5, n = 800,
  vmax = 4, seed = NULL, trace = 20, resolution = rep(1,
  length(lower)))

Arguments

fn

objective function; function need to be optimized

init

default = NULL, it will generate randomly; Of course, you can specify it. It should be noted that you'd better specify an integer vector as init when dealing with 0-1 problem. If you don't mind the the init vector is integer or double(numerical), just leave it alone.

lower

lower of parameters to be estimated; Default = c(-6,0) because of the test on Michalewicz function of which thelower is c(-6,0);

upper

upper of parameters; Default = c(-1,2).

d0

a constant to gurantee that sensing length of antennae d doesn't equal to zero. More specifically,

d^t = η_d * d^{t-1} + d_0

where attenuation coefficient η_d belongs to [0,1]

d1

initial value of antenae length. You can specify it according to your problem scale

eta_d

attenuation coefficient of sensing length of antennae

w

the inertia term

c

a constant belongs to (0,1).

V_i=wV_i \pm c*rand

n

iterations times

vmax

maximum speed of beetle

seed

random seed; default = NULL ; The results of BAS depend on random init value and random directions. Therefore, if you set a random seed, for example,seed = 1, the results will remain the same no matter how many times you repeat your experiments.

trace

default = 20; it means the process is printed to the console every 10 iterations.

resolution

If there are non-integer parameters in the optimization problem, resolution should be taken into consideration. You can use resolution parms to reduce the error generated in the process of translating the double(decimal) to binary. More specifically, you can set resolution as c(1,1,1,1,1) when you deal with lot-sizing problem. But you should make the resolution large enough when dealing with Michalewicz function. If the parameter belongs to [-2.048,2.048], bBAS will search binary number in [0, 4096] and translate it into decimal when you set resolution as 1000. The examples below can be referenced.

Value

A list including best beetle position (parameters) and corresponding objective function value.

References

The algorithm is developed by Miss Ruan Yue. The documents or paper about bBAS will come soon.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#======== examples start =======================
# BAS application on Michalewicz function
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)
}
fit <- bBASoptim(fn = mich,
                 init = c(-3,1),
                 resolution = rep(100,2),
                 trace = 20,
                 c = 0.6,
                 seed = 3)
fit$par;fit$value

#==============lot-sizing problem==============#
lot_size2 <- function(x){
  R = c(100,60,40,50,80)
  A = 100
  c = 1
  x1 = 1 - x

  I = rep(0,5)

  for(m in 1:4){
    t = 0
    for (p in (m+1):5){
      if(x1[p] == 1){
        t = t + R[p]
      }
      else{break}
    }
    I[m] = t
  }
  if(x[1]!=1){
    pen = 1e5
  }else{
    pen = 0
  }
  cost = sum(A*x) + sum(c*I) + pen

  return(cost)
}
fit <- bBASoptim(fn = lot_size2,
                 init = rep(1,5),
                 lower = rep(0,5),
                 upper = rep(1,5),
                 resolution = rep(1,5),
                 n = 200)
fit$par;fit$value
#======== examples end =======================

jywang2016/rBAS documentation built on May 21, 2019, 1:43 a.m.