Skip to content

Commit d088235

Browse files
committed
Add engineering-based module
1 parent 16c2983 commit d088235

File tree

5 files changed

+1335
-0
lines changed

5 files changed

+1335
-0
lines changed

opfunu/engineering_based/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env python
2+
# Created by "Thieu" at 17:43, 30/07/2022 ----------%
3+
# Email: [email protected] %
4+
# Github: https://github.com/thieu1995 %
5+
# --------------------------------------------------%

opfunu/engineering_based/pdo_2022.py

Lines changed: 381 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,381 @@
1+
#!/usr/bin/env python
2+
# Created by "Thieu" at 15:00, 29/07/2022 ----------%
3+
# Email: [email protected] %
4+
# Github: https://github.com/thieu1995 %
5+
# --------------------------------------------------%
6+
7+
# Source: Prairie Dog Optimization Algorithm (PDO-2022)
8+
9+
import numpy as np
10+
11+
12+
WBD_lb = [0.1, 0.1, 0.1, 0.1]
13+
WBD_ub = [2., 10., 10., 2.]
14+
15+
PVD_lb = [0., 0., 10., 10.]
16+
PVD_ub = [99., 99., 200., 200.]
17+
18+
CSD_lb = [0.05, 0.25, 2.0]
19+
CSD_ub = [2.0, 1.3, 15.0]
20+
21+
SRD_lb = [2.6, 0.7, 17., 7.3, 7.3, 2.9, 5.0]
22+
SRD_ub = [3.6, 0.8, 28., 8.3, 8.3, 3.9, 5.5]
23+
24+
TBTD_lb = [0., 0.]
25+
TBTD_ub = [1., 1.]
26+
27+
GTD_lb = [12, 12, 12, 12]
28+
GTD_ub = [60, 60, 60, 60]
29+
30+
CBD_lb = (0.01 * np.ones(5)).tolist()
31+
CBD_ub = (100 * np.ones(5)).tolist()
32+
33+
IBD_lb = [10., 10., 0.9, 0.9]
34+
IBD_ub = [50., 80., 5., 5.]
35+
36+
TCD_lb = [2., 0.2]
37+
TCD_ub = [14., 0.8]
38+
39+
PLD_lb = [0.05, 0.05, 0.05, 0.05]
40+
PLD_ub = [500., 500., 120., 500.]
41+
42+
CBHD_lb = np.zeros(4).tolist()
43+
CBHD_ub = [100., 100., 100., 5.]
44+
45+
RCB_lb = [0., 28., 5.]
46+
RCB_ub = [9.99, 40., 10.]
47+
48+
49+
def welded_beam_design(x):
50+
"""
51+
WBD is subjected to 4 design constraints: shear, beam blending stress, bar buckling load beam, and deflection
52+
variables: h=x1, l=x2, t=x3, b=x4
53+
l: length, h: height, t: thickness, b: weld thickness of the bar
54+
55+
https://sci-hub.se/10.1016/s0166-3615(99)00046-9
56+
57+
Parameters
58+
----------
59+
x :
60+
61+
Returns
62+
-------
63+
64+
"""
65+
xichma_max = 30000
66+
P = 6000
67+
L = 14
68+
delta_max = 0.25
69+
E = 30*10**6
70+
theta_max=13600
71+
G = 12*10**6
72+
73+
fx = x[0] ** 2 * x[1] * 1.10471 + 0.04811 * x[2] * x[3] * (14.0 + x[1])
74+
75+
Pc_X = 4.013*E*np.sqrt(x[2]**2 * x[3]**6 / 36) / L**2 * (1. - x[2]*np.sqrt(E/(4*G)) / (2*L))
76+
J = 2*(np.sqrt(2)*x[0]*x[1]* (x[1]**2/4 + (x[0] + x[2]/2)**2))
77+
M = P*(L + x[1]/2)
78+
R = np.sqrt(x[1]**2/4 + (x[0]+x[2])**2/4)
79+
t2 = M*R/J
80+
t1 = P/(np.sqrt(2)*x[0]*x[1])
81+
t_X = np.sqrt(t1**2 + 2*t1*t2*x[1]/(2*R) + t2**2)
82+
xichma_X = 6*P*L / (x[3]*x[2]**2)
83+
delta_X = 4*P*L**3 / (E * x[2]**3 * x[3])
84+
85+
g1 = t_X - theta_max
86+
g2 = xichma_X - xichma_max
87+
g3 = x[0] - x[3]
88+
g4 = 0.10471 * x[0]**2 + 0.04811*x[2]*x[3]*(14.0 + x[1]) - 5.0
89+
g5 = 0.125 - x[0]
90+
g6 = delta_X - delta_max
91+
g7 = P - Pc_X
92+
gx = [g1, g2, g3, g4, g5, g6, g7]
93+
94+
return fx, gx
95+
96+
97+
def pressure_vessel_design(x):
98+
"""
99+
Variables: the inner radius (R=x3), the thickness of the head (Th=x2),
100+
the length of the cylindrical section of the vessel (L=x4), and the thickness of the shell (Ts=x1)
101+
102+
https://sci-hub.se/10.1115/1.2912596
103+
104+
Parameters
105+
----------
106+
x :
107+
108+
Returns
109+
-------
110+
111+
"""
112+
fx = 0.6224*x[2]*x[0]*x[3] + 1.7781*x[2]**2*x[1] + 3.1611*x[0]**2*x[3] + 19.8621*x[2]*x[0]**2
113+
g1 = -x[0] + 0.0193*x[2]
114+
g2 = -x[2] + 0.00954*x[2]
115+
g3 = -np.pi*x[1]**2*x[3] - 4./3*np.pi*x[2]**3 + 750*1728
116+
g4 = -240 + x[3]
117+
gx = [g1, g2, g3, g4]
118+
119+
return fx, gx
120+
121+
122+
def compression_srping_design(x):
123+
"""
124+
CSD aims to minimize the weight of a tension/compression spring given the values of 3 parameters:
125+
the wire diameter (d=x1), number of active coils (P=x3), and mean coil diameter (D=x2).
126+
127+
https://sci-hub.se/10.1016/s0166-3615(99)00046-9
128+
129+
Parameters
130+
----------
131+
x :
132+
133+
Returns
134+
-------
135+
136+
"""
137+
fx = (x[2] + 2)*x[1]*x[0]**2
138+
g1 = 1 - x[1]**3*x[2]/(71785*x[0]**4)
139+
g2 = (4*x[1]**2 - x[0]*x[1]) / (12566* (x[2]*x[0]**3 - x[0]**4)) + 1./(5108*x[0]**2) - 1
140+
g3 = 1 - 140.45*x[0] / (x[1]**2 * x[2])
141+
g4 = (x[0] + x[1]) / 1.5 - 1
142+
gx = [g1, g2, g3, g4]
143+
144+
return fx, gx
145+
146+
147+
def speed_reducer_design(x):
148+
"""
149+
Depicts a gearbox that sits between the propeller and engine of an aeroplane
150+
[x1, x2, x3, x4, x5, x6, x7] = [b, m, z, l1, l2, d1, d2]
151+
152+
Parameters
153+
----------
154+
x :
155+
156+
Returns
157+
-------
158+
159+
"""
160+
fx = 0.7854*x[0]*x[1]**2*(3.3333*x[2]**2 + 14.9334*x[2] - 43.0934) - 1.508*x[0]*(x[5]**2 + x[6]**2) +\
161+
7.4777*(x[5]**3 + x[6]**3) + 0.7854*(x[3]*x[5]**2 + x[4]*x[6]**2)
162+
163+
g1 = 27./(x[0]*x[1]**2*x[2]) - 1
164+
g2 = 397.5 / (x[0]*x[1]**2*x[2]**2) - 1
165+
g3 = 1.93*x[3]**2/(x[1]*x[5]**4*x[2]) - 1
166+
g4 = 1.93*x[4]**2/(x[1]*x[6]**4*x[2]) - 1
167+
g5 = np.sqrt((745*x[3]/(x[1]*x[2]))**2 + 16*10**6) / (110 * x[5]**3) - 1
168+
g6 = np.sqrt((745*x[4]/(x[1]*x[2]))**2 + 157.5*10**6) / (85*x[6]**3) - 1
169+
g7 = x[1]*x[2] / 40 - 1
170+
g8 = 5*x[1] / x[0] - 1
171+
g9 = x[0] / (12. * x[1]) - 1
172+
g10 = (1.5*x[5] + 1.9) / x[3] - 1
173+
g11 = (1.1*x[6] + 1.9) / x[4] - 1
174+
gx = [g1, g2, g3, g4, g5, g6, g7, g8, g9, g10, g11]
175+
176+
return fx, gx
177+
178+
179+
def three_bar_truss_design(x):
180+
"""
181+
Minimize three-bar structure weight subject to supporting a total load P acting vertically downwards
182+
183+
Parameters
184+
----------
185+
x :
186+
187+
Returns
188+
-------
189+
190+
"""
191+
L = 100
192+
P = 2
193+
xichma = 2
194+
195+
fx = (2*np.sqrt(2)*x[0] + x[1]) * L
196+
g1 = (np.sqrt(2)*x[0] + x[1]) / (np.sqrt(2)*x[0]**2 + 2*x[0]*x[1])*P - xichma
197+
g2 = x[1] * P / (np.sqrt(x[0]**2 + 2*x[0]*x[1])) - xichma
198+
g3 = P / (np.sqrt(2)*x[1] + x[0]) - xichma
199+
gx = [g1, g2, g3]
200+
201+
return fx, gx
202+
203+
204+
def gear_train_design(x):
205+
"""
206+
Unconstrained discrete design optimization problem
207+
[x1, x2, x3, x4] = [n_A, n_B, n_C, n_D]
208+
209+
Parameters
210+
----------
211+
x :
212+
213+
Returns
214+
-------
215+
216+
"""
217+
x = np.asarray(x, int)
218+
fx = (1. / 6.931 - x[2]*x[1] / (x[0] * x[3]))**2
219+
return fx, 0
220+
221+
222+
def cantilevel_beam_design(x):
223+
"""
224+
Minimize a cantilevel beam's weight.
225+
226+
Parameters
227+
----------
228+
x :
229+
230+
Returns
231+
-------
232+
233+
"""
234+
fx = 0.0624 * np.sum(x)
235+
gx = 61./x[0]**3 + 37./x[1]**3 + 19./x[2]**3 + 7./x[3]**3 + 1./x[4]**3 - 1
236+
237+
return fx, gx
238+
239+
240+
def i_beam_design(x):
241+
"""
242+
Minimizes the vertical deflection of a beam
243+
[x1, x2, x3, x4] = [b, h, t_w, t_f]
244+
Parameters
245+
----------
246+
x :
247+
248+
Returns
249+
-------
250+
251+
"""
252+
fx = 500. / ( (x[2]*(x[1]-2*x[3])**3)/12 + (x[0]*x[3]**3/6) + 2*x[0]*x[3]*(x[1] - x[3])**2 )
253+
g1 = 2*x[0]*x[2] + x[2]*(x[1] - 2*x[3]) - 300
254+
g2 = (18*x[1] * 10**4) / (x[2]*(x[1] - 2*x[3])**3 + 2*x[0]*x[2]*(4*x[3]**2 + 3*x[1]*(x[1] - 2*x[3]))) +\
255+
15*x[0] * 10**3 / ((x[1] - 2*x[3]) * x[2]**2 +2*x[2]*x[0]**3) - 56
256+
gx = [g1, g2]
257+
258+
return fx, gx
259+
260+
261+
def tubular_column_design(x):
262+
"""
263+
[x1, x2] = [d, t]
264+
265+
https://apmonitor.com/me575/index.php/Main/TubularColumn
266+
267+
Parameters
268+
----------
269+
x :
270+
271+
Returns
272+
-------
273+
274+
"""
275+
xichma_y = 450
276+
E = 0.65*10**6
277+
P = 2300
278+
pro = 0.002
279+
L = 300
280+
281+
fx = 9.8*x[0]*x[1] + 2*x[0]
282+
g1 = P / (np.pi*x[0]*x[1]*xichma_y) - 1
283+
g2 = (8*P*L**2) / (np.pi**3 * E *x[0]*x[1] * (x[0]**2 + x[1]**2)) - 1
284+
g3 = 2. / x[0] - 1
285+
g4 = x[0] / 14 - 1
286+
g5 = 0.2 / x[1] - 1
287+
g6 = x[1] / 8 - 1
288+
gx = [g1, g2, g3, g4, g5, g6]
289+
290+
return fx, gx
291+
292+
293+
def piston_lever_design(x):
294+
"""
295+
[x1, x2, x3, x4] = [H, B, D, X]
296+
297+
Parameters
298+
----------
299+
x :
300+
301+
Returns
302+
-------
303+
304+
"""
305+
L = 240
306+
M_max = 1.8*10**6
307+
P = 1500
308+
Q = 10000
309+
theta = np.pi/4
310+
L1 = np.sqrt((x[3] - x[1])**2 + x[0]**2)
311+
L2 = np.sqrt((x[3]*np.sin(theta) + x[0])**2 + (x[1] - x[3]*np.cos(theta))**2)
312+
R = np.abs(-x[3]*(x[3]*np.sin(theta) + x[0]) + x[0]*(x[1] - x[3]*np.cos(theta))) / np.sqrt((x[3] - x[1])**2 + x[0]**2)
313+
F = np.pi*P*x[2]**2 / 4
314+
315+
fx = 0.25*np.pi*x[2]**2 * (L2 - L1)
316+
g1 = Q*L*np.cos(theta) - R*F
317+
g2 = Q*(L - x[3]) - M_max
318+
g3 = 1.2*(L2 - L1) - L1
319+
g4 = x[2]/2 - x[1]
320+
gx = [g1, g2, g3, g4]
321+
322+
return fx, gx
323+
324+
325+
def corrugated_bulkhead_design(x):
326+
"""
327+
[x1, x2, x3, x4] = [width, depth, length, thickness]
328+
Parameters
329+
----------
330+
x :
331+
332+
Returns
333+
-------
334+
335+
"""
336+
fx = 5.885*x[3]*(x[0] + x[2]) / (x[0] + np.sqrt(np.abs(x[2]**2 - x[1]**2)))
337+
g1 = -x[3]*x[2]*(0.4*x[0] + x[2]/6) + 8.94*(x[0] + np.sqrt(np.abs(x[2]**2 - x[1]**2)))
338+
g2 = -x[3]*x[1]**2*(0.2*x[0] + x[2]/12) + 2.2*(8.94*(x[0] + np.sqrt(np.abs(x[2]**2 - x[1]**2))))**(4./3)
339+
g3 = -x[3] + 0.0156 * x[0] + 0.15
340+
g4 = -x[3] + 0.0156 * x[2] + 0.15
341+
g5 = -x[3] + 1.05
342+
g6 = -x[2] + x[1]
343+
gx = [g1, g2, g3, g4, g5, g6]
344+
345+
return fx, gx
346+
347+
348+
def reinforced_concrete_beam_design(x):
349+
"""
350+
351+
Parameters
352+
----------
353+
x :
354+
355+
Returns
356+
-------
357+
358+
"""
359+
x1_list = [6.0, 6.16, 6.32, 6.6, 7.0, 7.11, 7.2, 7.8, 7.9, 8.0, 8.4]
360+
x1, x2, x3 = x1_list[int(x[0])], x[1], x[2]
361+
362+
fx = 2.9*x1 + 0.6*x2*x3
363+
g1 = x2/x3 -4
364+
g2 = 180 + 7.375*x1**2/x3 - x1*x2
365+
gx = [g1, g2]
366+
367+
return fx, gx
368+
369+
370+
WBD = welded_beam_design
371+
PVD = pressure_vessel_design
372+
CSD = compression_srping_design
373+
SRD = speed_reducer_design
374+
TBTD = three_bar_truss_design
375+
GTD = gear_train_design
376+
CBD = cantilevel_beam_design
377+
IBD = i_beam_design
378+
TCD = tubular_column_design
379+
PLD = piston_lever_design
380+
CBHD = corrugated_bulkhead_design
381+
RCB = reinforced_concrete_beam_design

0 commit comments

Comments
 (0)