Skip to content

Commit affc640

Browse files
authored
Update EngineeringRealWorld.py
1 parent 5783ce3 commit affc640

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

desdeo_problem/testproblems/EngineeringRealWorld.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,66 @@
1414
from desdeo_problem.problem import ScalarObjective
1515
from desdeo_problem.problem.Problem import MOProblem, ProblemBase
1616

17+
def re21(var_iv: np.array = np.array([2, 2, 2, 2])) -> MOProblem:
18+
""" Four bar truss design problem.
19+
Two objectives and four variables.
20+
21+
Arguments:
22+
var_iv (np.array): Optional, initial variable values.
23+
Defaults are [2, 2, 2, 2]. x1, x4 ∈ [a, 3a], x2, x3 ∈ [√2 a, 3a]
24+
and a = F / sigma
25+
Returns:
26+
MOProblem: a problem object.
27+
"""
28+
29+
# Parameters
30+
F = 10.0
31+
sigma = 10.0
32+
E = 2.0 * 1e5
33+
L = 200.0
34+
a = F / sigma
35+
36+
# Check the number of variables
37+
if (np.shape(np.atleast_2d(var_iv)[0]) != (4,)):
38+
raise RuntimeError("Number of variables must be four")
39+
40+
# Lower bounds
41+
lb = np.array([a, np.sqrt(2) * a, np.sqrt(2) * a, a])
42+
43+
# Upper bounds
44+
ub = np.array([3 * a, 3 * a, 3 * a, 3 * a])
45+
46+
# Check the variable bounds
47+
if np.any(lb > var_iv) or np.any(ub < var_iv):
48+
raise ValueError("Initial variable values need to be between lower and upper bounds")
49+
50+
def f_1(x: np.ndarray) -> np.ndarray:
51+
x = np.atleast_2d(x)
52+
return L * ((2 * x[:, 0]) + np.sqrt(2.0) * x[:, 1] + np.sqrt(x[:, 2]) + x[:, 3])
53+
54+
def f_2(x: np.ndarray) -> np.ndarray:
55+
x = np.atleast_2d(x)
56+
return ((F * L) / E) * ((2.0 / x[:, 0]) +
57+
(2.0 * np.sqrt(2.0) / x[:, 1]) - (2.0 * np.sqrt(2.0) / x[:, 2]) + (2.0 / x[:, 3]))
58+
59+
objective_1 = ScalarObjective(name="minimize the structural volume", evaluator=f_1, maximize=[False])
60+
objective_2 = ScalarObjective(name="minimize the joint displacement", evaluator=f_2, maximize=[False])
61+
62+
objectives = [objective_1, objective_2]
63+
64+
# The four variables determine the length of four bars
65+
x_1 = Variable("x_1", 2 * a, a, 3 * a)
66+
x_2 = Variable("x_2", 2 * a, (np.sqrt(2.0) * a), 3 * a)
67+
x_3 = Variable("x_3", 2 * a, (np.sqrt(2.0) * a), 3 * a)
68+
x_4 = Variable("x_4", 2 * a, a, 3 * a)
69+
70+
variables = [x_1, x_2, x_3, x_4]
71+
72+
problem = MOProblem(variables=variables, objectives=objectives)
73+
74+
return problem
75+
76+
1777

1878
def re22(var_iv: np.array = np.array([7.2, 10, 20])) -> MOProblem:
1979
""" Reinforced concrete beam design problem.

0 commit comments

Comments
 (0)