function [lb,ub,dim,fobj] = Engineering_Problems(type)
% type:问题类型
% 不同数字 对应 不同问题
% 比如,type = 1 : 选择优化 Tension/compression spring design problem
% type = 2 : 选择优化 Pressure vessel design problem
switch type
case 1 % Tension/compression spring design problem
fobj = @spring; % 函数
lb = [0.05 0.25 2]; % 下限
ub = [2 1.3 15]; % 上限
dim = length(lb); % 维度
case 2 % Pressure vessel design problem
fobj = @ pvd;
lb =[0 0 10 10];
ub = [99 99 200 200];
dim = length(lb);
case 3 % Three-bar truss design problem
fobj = @ three_bar;
lb = [0 0];
ub = [1 1];
dim = length(lb);
case 4 % Welded beam design problem
fobj = @ welded_beam;
lb = [0.1 0.1 0.1 0.1];
ub = [2 10 10 2];
dim = length(lb);
case 5 % Speed reducer design problem
fobj = @ speed_reducer;
lb = [2.6 0.7 17 7.3 7.3 2.9 5];
ub = [3.6 0.8 28 8.3 8.3 3.9 5.5];
dim = length(lb);
case 6 % Gear train design problem
fobj = @ gear_train;
lb = [12 12 12 12];
ub= [60 60 60 60];
dim = length(lb);
case 7 % Rolling element bearing design
fobj = @ rolling_element_bearing;
D=160;
d=90;
lb=[0.5*(D+d) 0.15*(D-d) 4 0.515 0.515 0.4 0.6 0.3 0.02 0.6];
ub=[0.6*(D+d) 0.45*(D-d) 50 0.6 0.6 0.5 0.7 0.4 0.1 0.85];
dim=length(lb);
case 8 % Cantilever beam design problem
fobj = @ cantilever_beam;
lb = [0.01,0.01,0.01,0.01,0.01];
ub= [100,100,100,100,100];
dim = length(lb);
case 9 % Multiple disk clutch brake design problem
fobj = @ Multiple_disk;
lb=[60,90,1,600,2];
ub=[80,110,3,1000,9];
dim=length(lb);
case 10 % Step-cone pulley problem
fobj = @ Step_cone_pulley;
lb=[0,0,0,0,0];
ub=[60,60,90,90,90];
dim=length(lb);
case 11 % Planetary Gear Train Design
fobj = @ Planetary_Gear_Train;
lb=[17,14,14,17,14,48,1,1,1];
ub=[96,54,51,46,51,124,6,6,3];
dim=length(lb);
case 12 % Robot Gripper Problem
fobj = @ Robot_Gripper;
lb=[10,10,100,0,10,100,1];
ub=[150,150,200,50,150,300,3.14];
dim=length(lb);
end
end
function fitness = spring(x)
x1 = x(1);
x2 = x(2);
x3 = x(3);
f = (x3+2)*x2*(x1^2);
panaty_factor = 10e100; % 按需修改
%
g1 = 1-((x2^3)*x3)/(71785*(x1^4));
g2 = (4*(x2^2)-x1*x2)/(12566*(x2*(x1^3)-(x1^4))) + 1/(5108*(x1^2))-1;
g3 = 1-(140.45*x1)/((x2^2)*x3);
g4 = ((x1+x2)/1.5)-1;
panaty_1 = panaty_factor*(max(0,g1))^2; % g1的惩罚项
panaty_2 = panaty_factor*(max(0,g2))^2; % g2的惩罚项
panaty_3 = panaty_factor*(max(0,g3))^2; % g3的惩罚项
panaty_4 = panaty_factor*(max(0,g4))^2; % g4的惩罚项
fitness = f + panaty_1+panaty_2+panaty_3+panaty_4;
end
function fitness = pvd(x)
x1= x(1);x2 = x(2);x3 = x(3);x4 = x(4);
f = 0.6224*x1*x3*x4 + 1.7781*x2*x3^2+3.1661*x1^2*x4+19.84*x1^2*x3;
panaty_factor = 10e100; % 按需修改
%
g1 = -x1+0.0193*x3;
panalty_1 = panaty_factor*(max(0,g1))^2;
g2 = -x2+0.00954*x3;
panalty_2 = panaty_factor*(max(0,g2))^2;
g3 = -pi*x3^2*x4 - (4/3)*pi*x3^3 + 1296000;
panalty_3 = panaty_factor*(max(0,g3))^2;
g4 = x4 - 240;
panalty_4 = panaty_factor*(max(0,g4))^2;
fitness = f + panalty_1 + panalty_2 + panalty_3 + panalty_4;
end
function fitness = three_bar(x)
l = 100; P = 2; q = 2;
x1= x(1);
x2 = x(2);
f = l*(2*sqrt(2)*x1+x2);
panaty_factor = 10e100; % 按需修改
%
g1 = P*(sqrt(2)*x1+x2)/(sqrt(2)*x1^2+2*x1*x2)-q;
penalty_g1 = panaty_factor*(max(0,g1))^2;
g2 = P*(x2)/(sqrt(2)*x1^2+2*x1*x2)-q;
penalty_g2 = panaty_factor*(max(0,g2))^2;
g3 = P/(sqrt(2)*x2+x1)-q;
penalty_g3 = panaty_factor*(max(0,g3))^2;
fitness = f+penalty_g1+penalty_g2+penalty_g3;
end
function fitness = welded_beam(x)
P = 6000;
L=14;
E=30e6;
G = 12e6;
tmax=13600;
sigma_max=30000;
deta_max=0.25;
x1= x(1);
x2 = x(2);
x3 = x(3);
x4 = x(4);
% M
M=P*(L+0.5*x2);
% R
r1 = (x2^2)/4;
r2 = ((x1+x3)/2)^2;
R = (r1+r2)^0.5;
% J
j1=sqrt(2)*x1*x2;
j2 = (x2^2)/12;
j3 = ((x1+x3)/2)^2;
J=2*(j1*(j2+j3));
%
sigma_x=6*P*L/(x4*x3^2);
deta_x = 4*P*L^3/((E*x4)*(x3^3));
% Pc
p1 = (4.013*E*((x3^2)*(x4^6)/36)^0.5)/(L^2);
p2 = (x3/(2*L))*(E/(4*G))^0.5;
Pc = p1*(1-p2);
%
t_1 = P/(sqrt(2*x1*x2));
t_2 = M*R/J;
t=((t_1)^2 + 2*t_1*t_2*(x2/(2*R))+(t_2)^2)^0.5;
% 目标函数
f = 1.10471*(x1^2)*x2+0.04811*x3*x4*(14+x2);
panaty_factor = 10e100; % 按需修改
% g1
g1 = t-tmax;
penalty_g1 = panaty_factor*(max(0,g1))^2;
% g2
g2 = sigma_x-sigma_max;
penalty_g2 = panaty_factor*(max(0,g2))^2;
% g3
g3 = deta_x - deta_max;
penalty_g3 = panaty_factor*(max(0,g3))^2;
% g4
g4 = x1-x4;
penalty_g4 = panaty_factor*(max(0,g4))^2;
% g5
g5 = P - Pc;
penalty_g5 = panaty_factor*(max(0,g5))^2;
% g6
g6 = 0.125-x1;
penalty_g6 = panaty_factor*(max(0,g6))^2;
% g7
g7 =1.10471*(x1^2)*x2+0.04811*x3*x4*(14+x2)-5;
penalty_g7 = panaty_factor*(max(0,g7))^2;
%
fitness = f+penalty_g1+penalty_g2+penalty_g3+penalty_g4+penalty_g5 +penalty_g6+penalty_g7;
end
function fitness = speed_reducer(x)
x1= x(1);
x2 = x(2);
x3 = x(3);
x4 = x(4);
x5 = x(5);
x6 = x(6);
x7 = x(7);
% 目标函数
f = 0.7854*x1*x2^2*(3.3333*x3^2 + 14.9334*x3 - 43.0934) -...
1.508*x1*(x6^2 + x7^2) + 7.4777*(x6^3+x7^3) + 0.7854*(x4*x6^2 + x5*x7^2);
panaty_factor = 10e100; % 按需修改
% g1
g1 = (27/(x1*x2^2*x3))-1 ;
penalty_g1 = panaty_factor*(max(0,g1))^2;
% g2
g2 = (397.5/(x1*x2^2*x3^2)) - 1;
penalty_g2 = panaty_factor*(max(0,g2))^2;
% g3
g3 = (1.93*x4^3/(x2*x3*x6^4)) - 1;
penalty_g3 = panaty_factor*(max(0,g3))^2;
% g4
g4 = (1.93*x5^3/(x2*x3*x7^4)) - 1;
penalty_g4 = panaty_factor*(max(0,g4))^2;
% g5
g5 = (1/(110*x6^3))*(((745*x4/(x2*x3))^2 + 16.9*1e6)^0.5)-1;
penalty_g5 = panaty_factor*(max(0,g5))^2;
% g6
g6 = (1/(85*x7^3))*(((745*x5/(x2*x3))^2 + 157.5*1e6)^0.5)-1;
penalty_g6 = panaty_factor*(max(0,g6))^2;
% g7
g7 = (x2*x3/40) - 1;
penalty_g7 = panaty_factor*(max(0,g7))^2;
% g8
g8 = (5*x2/x1) - 1;
penalty_g8 = panaty_factor*(max(0,g8))^2;
% g9
g9 = (x1/(12*x2)) - 1;
penalty_g9 = panaty_factor*(max(0,g9))^2;
% g10
g10 = ((1.5*x6+1.9)/(x4)) - 1;
penalty_g10 = panaty_factor*(max(0,g10))^2;
% g11
g11 = ((1.1*x7+1.9)/(x5)) - 1;
penalty_g11 = panaty_factor*(max(0,g11))^2;
%
fitness = f+penalty_g1 + penalty_g2 + penalty_g3 + penalty_g4 + penalty_g5 + penalty_g6 + penalty_g7 +...
penalty_g8 + penalty_g9 + penalty_g10 + penalty_g11;
end
function fitness = gear_train(x)
x = round(x);
fitness=(1/6.931-(x(2)*x(3)/(x(1)*x(4))))^2;
end
function fitness = rolling_element_bearing(x)
panalty_factor = 10e100; %惩罚因子
D=160;d=90;Bw=30;
Dm=x(1); Db=x(2); Z=x(3); fi=x(4); f0=x(5); KDmin=x(6); KDmax=x(7);
ep = x(8); ee=x(9); xi=x(10);
Z=round(Z);
% ri=11.033; r0=11.033; fi=ri/Db; f0=r0/Db;
T=D-d-2*Db;
phio=2*pi-acos(((((D-d)/2)-3*(T/4))^2+(D/2-T/4-Db)^2-(d/2+T/4)^2)...
/(2*((D-d)/2-3*(T/4))*(D/2-T/4-Db)));
%
g(1)=1+phio/(2*asin(Db/Dm))-Z;
g(2)=-2*Db+KDmin*(D-d);
g(3)= -KDmax*(D-d)+2*Db;
g(4)=xi*Bw-Db;
g(5)=-Dm+0.5*(D+d);
g(6)=-(0.5+ee)*(D+d)+Dm;
g(7)=-0.5*(D-Dm-Db)+ep*Db;
g(8)=0.515-fi;
g(9)=0.515-f0;
% 惩罚项
penalty=panalty_factor*sum(g(g>0).^2);
gama=Db/Dm;
fc=37.91*((1+(1.04*((1-gama/1+gama)^1.72)*((fi*(2*f0-1)/f0*...
(2*fi-1))^0.41))^(10/3))^-0.3)*((gama^0.3*(1-gama)^1.39)/...
(1+gama)^(1/3))*(2*fi/(2*fi-1))^0.41;
if Db<=25.4
f=-fc*Z^(2/3)*Db^1.8;
else
f=-3.647*fc*Z^(2/3)*Db^1.4;
end
fitness=f+penalty;
end
function fitness=cantilever_beam(x)
panalty_factor = 10e100; %惩罚因子
g(1)=61/x(1)^3+37/x(2)^3+19/x(3)^3+7/x(4)^3+1/x(5)^3-1;
% 惩罚项
penalty=panalty_factor*sum(g(g>0).^2);
fitness=0.0624*sum(x)+penalty;
end
function fitness=Multiple_disk(x)
panalty_factor = 10e100; %�