#1 Unconstrained problem
ex1 <- function(x){
y<-4*x[1]*x[1]-2.1*x[1]^4+1/3*x[1]^6+x[1]*x[2]-4*x[2]*x[2]+4*x[2]^4;
return(y)
}
#global optimum
#x*=[0.0898, -0.7127];
# or
#x*=[-0.0898, 0.7127];
#
#f(x*)= -1.03163;
#========================= PROBLEM SPECIFICATIONS ===========================
problem<-list(f="ex1",x_L=rep(-1,2),x_U=rep(1,2))
opts<-list(maxeval=500, ndiverse=10, dim_refset=4, local_solver="solnp", local_n2=1)
#========================= END OF PROBLEM SPECIFICATIONS =====================
Results<-essR(problem,opts);
#2 Constrained problem
ex2<-function(x){
F=-x[1]-x[2];
g<-rep(0,2);
g[1]<-x[2]-2*x[1]^4+8*x[1]^3-8*x[1]^2;
g[2]<-x[2]-4*x[1]^4+32*x[1]^3-88*x[1]^2+96*x[1];
return(list(F=F,g=g))
}
# global optimum
#x*=[2.32952, 3.17849];
#f(x*)=-5.50801
#========================= PROBLEM SPECIFICATIONS ===========================
problem<-list(f="ex2",x_L=rep(0,2),x_U=c(3,4), c_L=rep(-Inf,2), c_U=c(2,36))
opts<-list(maxeval=750, local_solver="solnp", local_n2=1)
#========================= END OF PROBLEM SPECIFICATIONS =====================
Results<-essR(problem,opts);
#3 Constrained problem with equality constraints
ex3<-function(x,k1,k2,k3,k4){
f=-x[4];
#Equality constraints
g<-rep(0,5);
g[1]=x[4]-x[3]+x[2]-x[1]+k4*x[4]*x[6];
g[2]=x[1]-1+k1*x[1]*x[5];
g[3]=x[2]-x[1]+k2*x[2]*x[6];
g[4]=x[3]+x[1]-1+k3*x[3]*x[5];
#Inequality constraint
g[5]=x[5]^0.5+x[6]^0.5;
return(list(f=f,g=g));
}
#global optimum
#x*=[0.77152
# 0.516994
# 0.204189
# 0.388811
# 3.0355
# 5.0973];
#
#f(x*)= -0.388811;
#========================= PROBLEM SPECIFICATIONS ===========================
problem<-list(f="ex3",x_L=rep(0,6),x_U=c(rep(1,4),16,16), neq=4, c_L=-Inf, c_U=4)
opts<-list(maxtime=7, local_solver="solnp", local_n2=10)
#========================= END OF PROBLEM SPECIFICATIONS =====================
k1=0.09755988;
k3=0.0391908;
k2=0.99*k1;
k4=0.9*k3;
Results<-essR(problem,opts,k1,k2,k3,k4);
#4 Mixed integer problem
ex4<-function(x){
F = x[2]^2 + x[3]^2 + 2.0*x[1]^2 + x[4]^2 - 5.0*x[2] - 5.0*x[3] - 21.0*x[1] + 7.0*x[4];
g<-rep(0,3);
g[1] = x[2]^2 + x[3]^2 + x[1]^2 + x[4]^2 + x[2] - x[3] + x[1] - x[4];
g[2] = x[2]^2 + 2.0*x[3]^2 + x[1]^2 + 2.0*x[4]^2 - x[2] - x[4];
g[3] = 2.0*x[2]^2 + x[3]^2 + x[1]^2 + 2.0*x[2] - x[3] - x[4];
return(list(F=F, g=g));
}
# global optimum
#x*=[2.23607, 0, 1, 0];
#f(x*)=-40.9575;
#========================= PROBLEM SPECIFICATIONS ===========================
problem<-list(f="ex4", x_L=rep(0,4), x_U=rep(10,4), x_0=c(3,4,5,1),int_var=3, c_L=rep(-Inf,3), c_U=c(8,10,5))
opts<-list(maxtime=2)
#========================= END OF PROBLEM SPECIFICATIONS =====================
Results<-essR(problem,opts);
Run the code above in your browser using DataLab