Algorithm Search⌘K

Algorithmadvanced

Bidirectional evolutionary structural optimization

Also called BESO, evolutionary structural optimization.

Ranks elements by strain energy density and lowers the volume step by step, removing the weakest solid elements and adding back void ones, so the design stays 0/1 at every iteration.

Time
O(k (s + n log n)) worst
Space
O(n) extra
Where
k = number of iterations; n = number of elements; s = time of one finite element solve
Properties
deterministicnot exactiterative
Origin
Osvaldo M. Querin, Grant P. Steven, Yi Min Xie, Xiaodong Huang, 1998

Bidirectional evolutionary structural optimization (BESO) is a method for topology optimization that keeps every element either solid or void. It starts from the full design domain and lowers the volume by a small ratio at each iteration. After each finite element solve, it gives every element a sensitivity number, the strain energy per unit volume, and keeps the elements with the highest numbers up to the current target volume. Solid elements with low numbers are removed, and void elements with high numbers come back, which is the "bidirectional" part. The older method of Xie and Steven (1993) only removed elements. Querin, Steven and Xie (1998) added the reverse step, and Huang and Xie (2007) added a filter and an average with the previous iteration, which make the results stable on fine meshes. BESO is simple and gives crisp designs, but it has no general proof of convergence or of optimality. This page proves what holds for a network of bars: the sensitivity is the derivative of the compliance, the method is optimal for parallel bars with equal areas, and it is a greedy knapsack rule, worse than the optimum by any factor, when the areas differ.

In plain words

Start with a solid block. Push on it and see which small pieces work hard and which hardly work at all. Remove a few of the lazy pieces, so the block gets a little lighter. Push again. Some pieces that were removed may now be needed, so put the most useful of them back.

Repeat until the block has the target weight and stops changing. What is left is a frame of members that carry the load. At every step each piece is either fully there or fully gone, so the result needs no rounding at the end.

The problem

The design domain is divided into nn elements, and element ee has the volume vev_e and the variable xe∈{xmin⁡,1}x_e \in \{x_{\min}, 1\}. The stiffness of the structure is K(x)=∑exepKeK(x) = \sum_e x_e^p K_e, where KeK_e is the element matrix of the solid material and p≥1p \ge 1. A void element keeps the small stiffness xmin⁡pKex_{\min}^p K_e, which is the soft-kill form, so the solve is always defined. The goal is

min⁡x c(x)=fTusubject toK(x)u=f,∑exeve≤V∗,xe∈{xmin⁡,1}.\min_x\ c(x) = f^{\mathsf T} u \quad\text{subject to}\quad K(x) u = f,\quad \sum_e x_e v_e \le V^*,\quad x_e \in \{x_{\min}, 1\}.

The sensitivity number. As on the SIMP page, ∂c/∂xe=−p xep−1ueTkeue\partial c / \partial x_e = -p\, x_e^{p-1} u_e^{\mathsf T} k_e u_e. BESO uses

αe=12 xep−1 ueTkeueve=−12p ve∂c∂xe.\alpha_e = \frac{1}{2}\, \frac{x_e^{p-1}\, u_e^{\mathsf T} k_e u_e}{v_e} = -\frac{1}{2p\,v_e} \frac{\partial c}{\partial x_e}.

For a solid element this is its strain energy per unit volume. For a void element it is xmin⁡p−1x_{\min}^{p-1} times that of the solid element with the same displacements. With xmin⁡=10−3x_{\min} = 10^{-3} and p=3p = 3 the factor is 10−610^{-6}. A void element ranks high only when its displacements are very large, which is what happens when the remaining solid parts lose their connection.

The algorithm

  1. BESO(mesh, f, V*, ER, p, x_min, AR_max, τ, N)
  2. 1x_e ← 1 for every element; V ← Σ v_e
  3. 2for k = 1 to maxit do
  4. 3solve K(x) u = f; C_k ← fᵀu
  5. 4if V = V* and k > 2N and |Σ_{last N} C − Σ_{previous N} C| ≤ τ Σ_{last N} C then stop
  6. 5α_e ← ½ x_e^(p−1) u_eᵀ k_e u_e / v_e ▷ filtered on a continuum mesh
  7. 6if k > 1 then α_e ← (α_e + α_e^prev) / 2; α^prev ← α
  8. 7V ← max(V*, V (1 − ER))
  9. 8S ← the longest prefix of the elements sorted by decreasing α with Σ_{e∈S} v_e ≤ V
  10. 9if more than AR_max·n elements of S are void then
  11. keep the best AR_max·n of those voids, then fill with solid elements by α up to V
  12. 10x_e ← 1 for e in S and x_min for the other elements
  13. 11return x

Line L7 is the volume schedule: the target falls by the evolutionary ratio ER (often 1% to 2%) per iteration until it reaches V∗V^*. Line L8 is the threshold of Huang and Xie: the solid set is the elements whose sensitivity is above a level, chosen so that the volume meets the target. Line L9 is the admission limit: when too many voids would turn solid at once, only the best of them do, which keeps the design from jumping. Line L6 averages each number with its value from the previous iteration. Huang and Xie (2007) found that this stops the design from oscillating between two states. On a continuum mesh, line L5 also smooths the numbers over a radius rmin⁡r_{\min}, with the cone weights of the sensitivity filter of the SIMP page. The filter also gives void elements a number from their solid neighbors, so material grows next to stressed regions. Line L4 stops when the compliance over the last NN iterations (often 5) differs from the NN before by a relative amount of at most τ\tau.

Example

The test structure is a set of parallel bars between a wall and a rigid plate, with a unit load on the plate and E=1E = 1. Every bar stretches by the same δ=F/∑exepAe/Le\delta = F / \sum_e x_e^p A_e / L_e, so by line L5 a solid bar has αe=δ2/(2Le2)\alpha_e = \delta^2 / (2 L_e^2), whatever its area.

Equal areas. Six bars of area 1 have the lengths 1 to 6, so the total volume is 21. Take V∗=10V^* = 10, ER =1/10= 1/10, p=3p = 3 and xmin⁡=1/1000x_{\min} = 1/1000. The shorter a bar, the higher its number, so line L8 keeps the shortest bars that fit:

iteration target VV solid bars (lengths) volume compliance
0 21 1, 2, 3, 4, 5, 6 21 0.4082
1 18.9 1, 2, 3, 4, 5 15 0.4380
2, 3 17.01, 15.31 1, 2, 3, 4, 5 15 0.4380
4 to 7 13.78 down to 10.04 1, 2, 3, 4 10 0.4800
8 to 13 10 1, 2, 3, 4 10 0.4800

The compliance of the full design is 1/(1+1/2+⋯+1/6)=20/49≈0.40821/(1 + 1/2 + \dots + 1/6) = 20/49 \approx 0.4082, and that of the final design is 1/(1+1/2+1/3+1/4)=12/25=0.481/(1 + 1/2 + 1/3 + 1/4) = 12/25 = 0.48, plus a term of order 10−910^{-9} from the void bars. The run stops after 14 solves, when the compliance has not changed over two windows of 5. The volume falls in jumps, not smoothly, because a bar is either in or out: at iteration 1 the target is 18.9 but the design has volume 15. Brute force over all 262^6 designs confirms that {1,2,3,4}\{1, 2, 3, 4\} is the best design with volume at most 10.

Unequal areas. Two bars: bar 1 with L=1L = 1, A=1A = 1 (stiffness 1, volume 1), and bar 2 with L=1.1L = 1.1, A=10A = 10 (stiffness 100/11≈9.09100/11 \approx 9.09, volume 11). The target is V∗=11V^* = 11 and ER =1/50= 1/50. Bar 1 has the higher number, δ2/2\delta^2/2 against δ2/2.42\delta^2/2.42. At the first target, 11.76, both bars together have volume 12, so line L8 keeps bar 1 alone. Bar 2 is now void, its number is a factor 10−610^{-6} smaller, and it never returns. BESO ends with compliance about 1.0. The best design is bar 2 alone, with compliance 11/100=0.1111/100 = 0.11. BESO is 9.09 times softer than the optimum.

Random networks. On 100 random networks of 4 nodes on a line (the wall at the first node, a unit load at the last, a chain of 3 bars of area 1 and 4 to 7 more bars between random node pairs with areas 1 to 3, seed 3, V∗V^* half the total volume), BESO matched the brute force optimum within 10−610^{-6} on 28 networks and came within 10% on 43. The median ratio was 1.17 and the worst 3.0. These are measurements on small discrete examples, where the jumps of the volume are large, and they say nothing about fine continuum meshes.

Correctness

What is proved for the method as stated: every design after the first meets the current target volume, the targets reach V∗V^* after ⌈ln⁡(V∗/V0)/ln⁡(1−ER)⌉\lceil \ln(V^*/V_0)/\ln(1 - \text{ER}) \rceil iterations, and the loop stops after maxit iterations. The sensitivity is −12pve-\frac{1}{2p v_e} times the derivative of the compliance, by differentiating Ku=fK u = f. So line L8 ranks the elements by the first order gain per unit volume.

For parallel bars with equal areas and distinct lengths, the method is optimal. By induction the solid set is always a prefix of the bars sorted by length, and a removed bar never fits again, because the targets only fall. So BESO ends at the longest prefix that fits in V∗V^*. Any feasible set with ss bars has at least the total length of the ss shortest bars, so ss is at most the length of that prefix, and its stiffness ∑1/Le\sum 1/L_e is at most that of the prefix. With unequal areas the problem is a 0/1 knapsack with value Ae/LeA_e/L_e and weight AeLeA_e L_e, and BESO takes the bars in the order of value per weight. That rule is optimal for the fractional knapsack, not for the 0/1 one, and the two bar example shows a gap that grows without bound as the second area grows.

What is not proved. BESO has no general proof of convergence. The averaging and the stop rule are measured to work well, but the 0/1 iterates can cycle, and nothing bounds the gap to the optimum. Zhou and Rozvany (2001) gave a small example where the element removal of the earlier ESO method gives a highly nonoptimal design. The full proofs of the statements above are in the correctness proof.

What the tests check. The solver against the closed forms for bars in parallel and in series, the sensitivity against an exact central difference of the compliance, the equal area case and random equal area cases against brute force, the knapsack counterexample, and the volume and feasibility on random networks.

Proof: BESO keeps feasible designs and stops, its sensitivity is the scaled derivative of the compliance, and on parallel bars it is optimal for equal areas and a greedy knapsack rule otherwisefull

Setting. A network of nn axial bars with Young's modulus E=1E = 1. Bar ee has the length LeL_e, the area AeA_e, the volume ve=AeLev_e = A_e L_e and the design variable xe∈{xmin⁡,1}x_e \in \{x_{\min}, 1\} with 0<xmin⁡<10 < x_{\min} < 1. Its stiffness matrix is xepkex_e^p k_e with ke=(Ae/Le)(1−1−11)k_e = (A_e/L_e)\begin{pmatrix}1 & -1 \\ -1 & 1\end{pmatrix} and p≥1p \ge 1. The supports make K(x)=∑exepKeK(x) = \sum_e x_e^p K_e positive definite on the free nodes whenever every bar has xe>0x_e > 0 and every node is joined to a support by a path of bars. The compliance is c(x)=fTuc(x) = f^{\mathsf T} u with K(x)u=fK(x) u = f. Let 0<V∗≤V0=∑eve0 < V^* \le V_0 = \sum_e v_e and 0<ER<10 < \text{ER} < 1.

Claim.

  1. Every design after the first has solid volume at most the current target VkV_k, and the targets reach V∗V^* after at most ⌈ln⁡(V∗/V0)/ln⁡(1−ER)⌉\lceil \ln(V^*/V_0) / \ln(1 - \text{ER}) \rceil iterations and then stay there. The method stops after at most maxit iterations.
  2. For every design, αeve=−12p∂c/∂xe\alpha_e v_e = -\frac{1}{2p} \partial c / \partial x_e, so ranking by α\alpha is ranking by the derivative of the compliance per unit volume.
  3. For bars in parallel between a support and a rigid plate with load FF, the displacement is δ=F/∑exepAe/Le\delta = F / \sum_e x_e^p A_e / L_e, the compliance is FδF \delta, and αe=xep−1δ2/(2Le2)\alpha_e = x_e^{p-1} \delta^2 / (2 L_e^2).
  4. If in addition all areas are equal and the lengths are distinct, the final design of BESO is the longest prefix of the bars sorted by increasing length whose volume is at most V∗V^*, and it has the least compliance among all 0/1 designs with volume at most V∗V^*.
  5. With unequal areas, the problem is a 0/1 knapsack problem, BESO ranks the solid bars by value per weight, and its result can be worse than the optimum by any factor.

Proof of 1. Line L7 sets Vk+1=max⁡(V∗,Vk(1−ER))V_{k+1} = \max(V^*, V_k(1 - \text{ER})), so Vk≥V∗V_k \ge V^* for all kk, the sequence does not increase, and Vk=max⁡(V∗,V0(1−ER)k)V_k = \max(V^*, V_0 (1 - \text{ER})^k). The second value is at most V∗V^* once k≥ln⁡(V∗/V0)/ln⁡(1−ER)k \ge \ln(V^*/V_0)/\ln(1 - \text{ER}). Line L8 adds elements in the ranked order only while the volume stays at most Vk+1V_{k+1}. Line L9, when it applies, first takes some voids, at most ⌊ARmax⁡n⌋\lfloor \text{AR}_{\max} n \rfloor of them, all of which were in the set of line L8, and then solid elements while the volume stays at most Vk+1V_{k+1}. In both cases the solid volume is at most Vk+1V_{k+1}. The loop of line L2 runs at most maxit times.

Proof of 2. Differentiate Ku=fK u = f with respect to xex_e: K ∂u=−(∂K)uK\, \partial u = -(\partial K) u, so ∂c/∂xe=fT∂u=−uTK K−1(∂K)u=−uT(∂K/∂xe)u=−p xep−1 ueTkeue\partial c / \partial x_e = f^{\mathsf T} \partial u = -u^{\mathsf T} K\, K^{-1} (\partial K) u = -u^{\mathsf T} (\partial K / \partial x_e) u = -p\, x_e^{p-1}\, u_e^{\mathsf T} k_e u_e, using KT=KK^{\mathsf T} = K and f=Kuf = K u. Line L5 computes αe=12xep−1ueTkeue/ve\alpha_e = \frac{1}{2} x_e^{p-1} u_e^{\mathsf T} k_e u_e / v_e, which is −12p∂c/∂xe-\frac{1}{2p} \partial c / \partial x_e divided by vev_e. For a solid bar it is the strain energy per unit volume. For a void bar it is xmin⁡p−1x_{\min}^{p-1} times the energy density that the bar would have if it were solid with the same displacements.

Proof of 3. All bars join node 0 (fixed) and node 1 (the plate), so KK is the 1×11 \times 1 matrix ∑exepAe/Le\sum_e x_e^p A_e/L_e, and δ=F/∑exepAe/Le\delta = F / \sum_e x_e^p A_e / L_e. Each bar has ueTkeue=(Ae/Le)δ2u_e^{\mathsf T} k_e u_e = (A_e / L_e) \delta^2, so αe=12xep−1(Ae/Le)δ2/(AeLe)=xep−1δ2/(2Le2)\alpha_e = \frac12 x_e^{p-1} (A_e/L_e) \delta^2 / (A_e L_e) = x_e^{p-1} \delta^2 / (2 L_e^2).

Proof of 4. Number the bars by increasing length, L1<⋯<LnL_1 < \dots < L_n, all with area AA. Write Pj={1,…,j}P_j = \{1, \dots, j\}.

BESO keeps a prefix. By induction on the iteration, the solid set is some PjP_j, and every void bar r>jr > j was removed at an iteration where the target was below A(L1+⋯+Lr)A(L_1 + \dots + L_r). At the start the solid set is PnP_n. Assume the solid set is PjP_j. By claim 3, a bar that is solid in this iteration and in the previous one has the averaged αe=(δk2+δk−12)/(4Le2)\alpha_e = (\delta_k^2 + \delta_{k-1}^2)/(4 L_e^2), and every void bar has the factor xmin⁡p−1<1x_{\min}^{p-1} < 1 on at least one of the two terms. So every solid bar has a larger α\alpha than every void bar (all void bars are longer than all solid bars), and among the solid bars α\alpha decreases with the length. Line L8 takes the solid bars in increasing length while they fit in Vk+1V_{k+1}. If it stops inside PjP_j, the new solid set is a prefix Pj′P_{j'} with j′≤jj' \le j. If all of PjP_j fits, the next element is a void bar r>jr > j. Its volume would bring the total to at least A(L1+⋯+Lj+1)A(L_1 + \dots + L_{j+1}), because Lr≥Lj+1L_r \ge L_{j+1}, and when bar j+1j + 1 was removed the target was below this value. The targets do not increase, so rr does not fit, line L8 stops, and no void bar is added. So line L9 does nothing, and the solid set is PjP_j again.

The final prefix is the longest one that fits. Once Vk=V∗V_k = V^*, line L8 keeps the longest prefix of PjP_j with volume at most V∗V^*. Let j∗j^* be the largest jj with A(L1+⋯+Lj)≤V∗A(L_1 + \dots + L_j) \le V^*. While the target is above V∗V^*, the solid set has volume at most the target and all prefixes up to j∗j^* fit in every target, so the solid set always contains Pj∗P_{j^*}. At target V∗V^* the prefix Pj∗+1P_{j^* + 1} does not fit, so the solid set is exactly Pj∗P_{j^*}.

The prefix is optimal. The compliance is F2/(∑exepA/Le)F^2 / (\sum_e x_e^p A/L_e), so the best 0/1 design maximizes ∑e∈S1/Le\sum_{e \in S} 1/L_e plus a term from the void bars that is the same for all sets of the same size only up to the factor xmin⁡px_{\min}^p. Ignore that term first. Let SS be any set with A∑e∈SLe≤V∗A\sum_{e \in S} L_e \le V^* and ∣S∣=s|S| = s. The ss shortest bars have total length at most that of SS, so PsP_s is feasible and s≤j∗s \le j^*. The ss largest values of 1/Le1/L_e are those of PsP_s, so ∑e∈S1/Le≤∑e∈Ps1/Le≤∑e∈Pj∗1/Le\sum_{e \in S} 1/L_e \le \sum_{e \in P_s} 1/L_e \le \sum_{e \in P_{j^*}} 1/L_e. Now include the voids: the stiffness of a design is ∑e∈SA/Le+xmin⁡p∑e∉SA/Le=(1−xmin⁡p)∑e∈SA/Le+xmin⁡p∑eA/Le\sum_{e \in S} A/L_e + x_{\min}^p \sum_{e \notin S} A/L_e = (1 - x_{\min}^p) \sum_{e \in S} A/L_e + x_{\min}^p \sum_e A/L_e. The last term does not depend on SS, and 1−xmin⁡p>01 - x_{\min}^p > 0, so the same set maximizes it. So Pj∗P_{j^*} has the least compliance.

Proof of 5. By the last formula, minimizing the compliance with volume at most V∗V^* is maximizing ∑e∈SAe/Le\sum_{e \in S} A_e / L_e subject to ∑e∈SAeLe≤V∗\sum_{e \in S} A_e L_e \le V^*: a 0/1 knapsack problem with values Ae/LeA_e/L_e and weights AeLeA_e L_e. By claim 3 the solid bars are ranked by 1/Le21/L_e^2, which is value per weight, and line L8 takes a prefix of this order. Two bars with (L,A)=(1,1)(L, A) = (1, 1) and (1.1,10)(1.1, 10) and V∗=11V^* = 11 give the counterexample. The ranking puts the first bar first (its 1/L21/L^2 is larger), the first prefix of volume at most 11.7611.76 is the first bar alone (adding the second gives 12), and the second bar never returns, as in the proof of claim 4. The optimum is the second bar alone, with stiffness 100/11100/11 against 1, so BESO is 100/11≈9.09100/11 \approx 9.09 times softer, up to the xmin⁡px_{\min}^p terms. Scaling the second bar's area and the target makes the factor as large as wanted.

What is not proved. For general structures the history averaging, the filter and the admission limit have no proof of convergence: the 0/1 iterates can cycle, and nothing bounds the gap to the optimum. The stop rule of line L4 measures the change of the compliance over two windows of iterations. It is a test, not a proof that a stationary design was reached.

Complexity

Each iteration does one finite element solve, of time ss, then computes nn sensitivity numbers, filters them in O(nr2)O(n r^2) time on a 2D grid with filter radius rr, and sorts them in O(nlog⁡n)O(n \log n). With a bisection on the threshold instead of a sort, the selection is O(n)O(n) per step of the bisection. So kk iterations take O(k(s+nlog⁡n))O(k(s + n \log n)), and the solve is most of the time on real meshes. The space is O(n)O(n) for the numbers and the design, plus the solver.

The number of iterations is at least ⌈ln⁡(V∗/V0)/ln⁡(1−ER)⌉\lceil \ln(V^*/V_0) / \ln(1 - \text{ER}) \rceil to reach the volume, which is 35 for V∗/V0=1/2V^*/V_0 = 1/2 and ER =2%= 2\%, plus at least 2N2N to pass the stop test. On the random networks above the runs took 36 to 47 solves. No formula bounds the number of iterations after the target is reached; the code stops at maxit.

Properties

  • 0/1 designs. Every iterate is solid or void, so there is no gray material to round at the end.
  • Feasible volume. Every design after the first meets the current target.
  • First order ranking. The sensitivity number is the derivative of the compliance per unit volume, scaled by a positive constant.
  • Heuristic. It has no general proof of convergence and no bound on the gap to the optimum.
  • Volume in jumps. On coarse meshes the volume can fall well below the target in one step.
  • Deterministic. With a fixed tie rule the result depends only on the input and the parameters.

Variants and improvements

  • ESO. The one-way method of Xie and Steven (1993) only removes elements, by a stress or energy criterion. A removed element cannot return, which is the weakness that Zhou and Rozvany (2001) showed.
  • Hard kill. Void elements are deleted from the mesh instead of kept at xmin⁡x_{\min}. The solve is smaller, but a void element has no displacement, so its number must come from the filter.
  • Soft kill with interpolation. Huang and Xie use xmin⁡x_{\min} and the power pp as in SIMP, which gives void elements a defined number and lets the method treat several materials.
  • Other objectives. Natural frequencies, displacement constraints and several load cases change the sensitivity number, not the selection.
  • Filters. The mesh-independency filter is the same as the sensitivity filter of SIMP. See density filtering for the filter on the densities and its properties.

When to use it

Use BESO when a crisp 0/1 design is needed at every iteration, for example when the next step of the work reads the layout directly, or when the analysis code can only switch elements on and off. It is easy to add to an existing finite element code, because it needs only element energies. For problems with several constraints or a need for a certificate of optimality, a gradient method on a relaxed problem, such as SIMP with a general optimizer, is the safer choice.

Pitfalls

  • Claiming convergence. The stop rule says that the compliance stopped changing. It does not prove a local optimum.
  • An admission limit of zero. A limit of AR_max times nn, rounded down, is 0 on a small model, and then no void element can ever return. The code of this page uses at least 1.
  • No averaging. Without line L6 the design often flips between two states on fine meshes.
  • A large ER. Large volume steps remove members that later turn out to be needed, and on coarse meshes the volume jumps far below the target.
  • Disconnected designs. If the solid set loses its path from the load to the supports, the soft-kill solve still works, but the compliance is huge. With hard kill the matrix becomes singular.
  • Reading the volume as the target. The final volume is at most V∗V^* and can be smaller, as the 6 bar example shows at iteration 1.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

beso_method.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/beso-method/. The authors are listed in prov/0GMFJK.jsonl.

"""Bidirectional evolutionary structural optimization (BESO), soft-kill form.

The structure is a network of axial bars on a line. Bar e joins the nodes
i and j, has the length L_e, the area A_e and the Young's modulus 1. Its design
variable x_e is 1 (solid) or xmin (void), and its stiffness is
x_e^p A_e / L_e. The method minimizes the compliance f^T u for a target
volume, after Huang and Xie (2007, 2009). All arithmetic is exact (Fraction).
"""

from fractions import Fraction as F


class Network:
    def __init__(self, nnodes, bars, fixed, loads):
        """bars: list of (i, j, L, A). fixed: node indices. loads: {node: force}."""
        self.nnodes = nnodes
        self.bars = [(i, j, F(L), F(A)) for i, j, L, A in bars]
        self.fixed = set(fixed)
        self.loads = {k: F(v) for k, v in loads.items()}

    def volume(self, e):
        return self.bars[e][2] * self.bars[e][3]


def gauss_solve(a, b):
    """Solve a x = b exactly by Gaussian elimination with row pivoting."""
    n = len(b)
    m = [row[:] + [b[i]] for i, row in enumerate(a)]
    for col in range(n):
        piv = next(r for r in range(col, n) if m[r][col] != 0)
        m[col], m[piv] = m[piv], m[col]
        for r in range(col + 1, n):
            if m[r][col] != 0:
                t = m[r][col] / m[col][col]
                for c in range(col, n + 1):
                    m[r][c] -= t * m[col][c]
    x = [F(0)] * n
    for r in range(n - 1, -1, -1):
        s = m[r][n] - sum(m[r][c] * x[c] for c in range(r + 1, n))
        x[r] = s / m[r][r]
    return x


def solve(net, x, p):
    """Displacements of all nodes and the compliance f^T u."""
    free = [k for k in range(net.nnodes) if k not in net.fixed]
    pos = {k: t for t, k in enumerate(free)}
    n = len(free)
    k = [[F(0)] * n for _ in range(n)]
    for e, (i, j, L, A) in enumerate(net.bars):
        s = x[e] ** p * A / L
        for a, b, sign in ((i, i, 1), (j, j, 1), (i, j, -1), (j, i, -1)):
            if a in pos and b in pos:
                k[pos[a]][pos[b]] += sign * s
    f = [net.loads.get(node, F(0)) for node in free]
    uf = gauss_solve(k, f)
    u = [F(0)] * net.nnodes
    for node, t in pos.items():
        u[node] = uf[t]
    c = sum(net.loads.get(node, F(0)) * u[node] for node in range(net.nnodes))
    return u, c


def sensitivities(net, x, u, p):
    """alpha_e = (1/2) x_e^(p-1) u_e^T k0 u_e / v_e, the strain energy per
    unit volume of the solid bar, scaled by x_e^(p-1) for a void bar."""
    out = []
    for e, (i, j, L, A) in enumerate(net.bars):
        d = u[i] - u[j]
        out.append(x[e] ** (p - 1) * (A / L) * d * d / 2 / (A * L))
    return out


def update(net, x, alpha, target, ar_max, xmin):
    """Lines L8 to L10: a new 0/1 design of volume at most target.

    The elements are ranked by alpha. The solid set is the longest prefix of
    the ranking whose volume is at most the target. If more than ar_max of
    the elements would turn from void to solid, only the best ar_max of them
    are added, and the solid elements fill the rest of the volume.
    """
    n = len(x)
    order = sorted(range(n), key=lambda e: (-alpha[e], e))
    chosen, vol = [], F(0)
    for e in order:  # @line L8
        if vol + net.volume(e) > target:
            break
        chosen.append(e)
        vol += net.volume(e)
    added = [e for e in chosen if x[e] != 1]
    limit = max(1, int(ar_max * n))  # at least one, so small models can add an element
    if len(added) > limit:  # @line L9
        added = added[:limit]
        chosen, vol = list(added), sum((net.volume(e) for e in added), F(0))
        for e in order:
            if x[e] == 1:
                if vol + net.volume(e) > target:
                    break
                chosen.append(e)
                vol += net.volume(e)
    keep = set(chosen)
    return [F(1) if e in keep else xmin for e in range(n)]  # @line L10


def beso(net, target_volume, er=F(1, 50), p=3, xmin=F(1, 1000), ar_max=F(1, 50), tau=F(1, 1000), window=5, maxit=200):
    """Run BESO from the full design. Return (x, history), where history is a
    list of (target volume, volume, compliance) per iteration."""
    n = len(net.bars)
    x = [F(1)] * n  # @line L1
    total = sum(net.volume(e) for e in range(n))
    vt = total
    prev = None
    hist = []
    for it in range(maxit):  # @line L2
        u, c = solve(net, x, p)  # @line L3
        vol = sum(net.volume(e) for e in range(n) if x[e] == 1)
        hist.append((vt, vol, c))
        cs = [h[2] for h in hist]
        if vt == target_volume and len(cs) >= 2 * window:  # @line L4
            a, b = sum(cs[-window:]), sum(cs[-2 * window:-window])
            if abs(a - b) <= tau * a:
                break
        alpha = sensitivities(net, x, u, p)  # @line L5
        if prev is not None:
            alpha = [(a + b) / 2 for a, b in zip(alpha, prev)]  # @line L6
        prev = alpha
        vt = max(F(target_volume), vt * (1 - er))  # @line L7
        x = update(net, x, alpha, vt, ar_max, xmin)
    return x, hist  # @line L11


def parallel_bars(lengths, areas, force=1):
    """Bars between a wall (node 0) and a rigid plate. The plate is modeled by
    giving every bar the same end node 1, which carries the load."""
    bars = [(0, 1, L, A) for L, A in zip(lengths, areas)]
    return Network(2, bars, [0], {1: force})


def series_bars(lengths, areas, force=1):
    """A chain of bars from a wall, loaded at the free end."""
    bars = [(e, e + 1, L, A) for e, (L, A) in enumerate(zip(lengths, areas))]
    return Network(len(bars) + 1, bars, [0], {len(bars): force})


def brute_force(net, target_volume, p=3, xmin=F(1, 1000)):
    """The best 0/1 design with volume at most the target, by enumeration."""
    n = len(net.bars)
    best = None
    for mask in range(1 << n):
        vol = sum(net.volume(e) for e in range(n) if mask >> e & 1)
        if vol > target_volume:
            continue
        x = [F(1) if mask >> e & 1 else xmin for e in range(n)]
        _, c = solve(net, x, p)
        if best is None or c < best[0]:
            best = (c, mask)
    return best
test_beso_method.py 114 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/beso-method/. The authors are listed in prov/0GMFJK.jsonl.

import random
from fractions import Fraction as F

from beso_method import Network, beso, brute_force, parallel_bars, sensitivities, series_bars, solve

XMIN = F(1, 1000)


def test_parallel_bars_closed_form() -> None:
    rng = random.Random(1)
    for _ in range(50):
        n = rng.randint(1, 6)
        lengths = [F(rng.randint(1, 20), rng.randint(1, 4)) for _ in range(n)]
        areas = [F(rng.randint(1, 9), rng.randint(1, 3)) for _ in range(n)]
        u, c = solve(parallel_bars(lengths, areas, 3), [F(1)] * n, 3)
        k = sum(a / L for L, a in zip(lengths, areas))
        assert u[1] == 3 / k  # delta = F / sum(E A_i / L_i)
        assert c == 9 / k  # compliance F^2 / sum(E A_i / L_i)


def test_series_bars_closed_form() -> None:
    rng = random.Random(2)
    for _ in range(50):
        n = rng.randint(1, 6)
        lengths = [F(rng.randint(1, 20), rng.randint(1, 4)) for _ in range(n)]
        areas = [F(rng.randint(1, 9), rng.randint(1, 3)) for _ in range(n)]
        _, c = solve(series_bars(lengths, areas, 2), [F(1)] * n, 3)
        assert c == 4 * sum(L / a for L, a in zip(lengths, areas))  # springs in series


def test_sensitivity_is_minus_one_over_p_times_the_derivative() -> None:
    # alpha_e v_e = -(1/p) dC/dx_e, with dC/dx_e = -p x^(p-1) u_e^T k0 u_e / 2 for C = f^T u / 2.
    # Check against a central difference quotient on a small network, exactly in Fraction.
    net = Network(3, [(0, 1, 2, 1), (1, 2, 1, 2), (0, 2, 3, 1), (0, 1, 1, 1)], [0], {2: 1})
    x = [F(1), F(1, 2), F(3, 4), F(1, 5)]
    p = 3
    u, _ = solve(net, x, p)
    alpha = sensitivities(net, x, u, p)
    h = F(1, 10**6)
    for e in range(4):
        xp, xm = list(x), list(x)
        xp[e] += h
        xm[e] -= h
        dc = (solve(net, xp, p)[1] - solve(net, xm, p)[1]) / (2 * h)  # d(f^T u)/dx_e
        want = -dc / 2 / p  # -(1/p) dC/dx_e with C = f^T u / 2
        assert abs(alpha[e] * net.volume(e) - want) < F(1, 10**8)


def test_equal_areas_keep_the_shortest_bars_which_is_optimal() -> None:
    net = parallel_bars([1, 2, 3, 4, 5, 6], [1] * 6)
    x, hist = beso(net, 10, er=F(1, 10))
    assert [int(v == 1) for v in x] == [1, 1, 1, 1, 0, 0]
    assert hist[-1][1] == 10
    c, mask = brute_force(net, 10)
    assert mask == 0b001111 and hist[-1][2] == c


def test_equal_areas_random_lengths() -> None:
    rng = random.Random(4)
    for _ in range(20):
        lengths = [F(rng.randint(1, 30), 3) for _ in range(rng.randint(2, 7))]
        net = parallel_bars(lengths, [1] * len(lengths))
        target = sum(lengths) * F(rng.randint(2, 8), 10)
        x, hist = beso(net, target)
        c, mask = brute_force(net, target)
        assert hist[-1][2] == c  # the shortest-first prefix is optimal


def test_unequal_areas_are_a_knapsack_where_beso_is_worse() -> None:
    # bar 1: L = 1, A = 1 (stiffness 1, volume 1); bar 2: L = 11/10, A = 10 (stiffness 100/11, volume 11)
    net = parallel_bars([1, F(11, 10)], [1, 10])
    x, hist = beso(net, 11)
    assert [int(v == 1) for v in x] == [1, 0]
    c, mask = brute_force(net, 11)
    assert mask == 0b10
    assert hist[-1][2] > 9 * c  # BESO keeps the bar with the higher energy density, 9 times softer


def random_net(rng):
    pos = [0, 2, 4, 6]
    bars = []
    for _ in range(rng.randint(4, 7)):
        i, j = sorted(rng.sample(range(4), 2))
        bars.append((i, j, pos[j] - pos[i], rng.randint(1, 3)))
    for i in range(3):
        bars.append((i, i + 1, 2, 1))
    return Network(4, bars, [0], {3: 1})


def test_random_networks_feasible_and_not_better_than_brute_force() -> None:
    rng = random.Random(3)
    for _ in range(25):
        net = random_net(rng)
        total = sum(net.volume(e) for e in range(len(net.bars)))
        x, hist = beso(net, total / 2)
        vol = sum(net.volume(e) for e in range(len(net.bars)) if x[e] == 1)
        assert vol <= total / 2
        assert solve(net, x, 3)[1] == hist[-1][2]
        best, _ = brute_force(net, total / 2)
        assert hist[-1][2] >= best
        assert hist[-1][2] <= 4 * best  # measured: at most 3 times worse on this set


def test_volume_schedule() -> None:
    net = parallel_bars([1, 2, 3, 4, 5, 6], [1] * 6)
    _, hist = beso(net, 10, er=F(1, 10))
    targets = [h[0] for h in hist]
    assert targets[:3] == [21, F(189, 10), F(1701, 100)]
    assert all(a >= b for a, b in zip(targets, targets[1:]))
    assert targets[-1] == 10
    assert all(h[1] <= h[0] for h in hist)

History

Xie and Steven (1993) proposed evolutionary structural optimization: remove the least stressed elements, a few at a time, until the design stops changing. Querin, Steven and Xie (1998) made it bidirectional by adding elements near the most stressed regions. Zhou and Rozvany (2001) showed with a small example that the removal rule can give a design far from the optimum, which started a debate on the method. Huang and Xie (2007) gave the form used today: sensitivity numbers from the compliance, a mesh-independency filter, an average with the previous iteration and a stop rule on the compliance. Their 2010 book collects the soft-kill form with material interpolation and many applications.

References

  1. Y. M. Xie and G. P. Steven, A simple evolutionary procedure for structural optimization, Computers and Structures 49(5), 1993, 885 to 896, the removal of the elements with the lowest stress, step by step, until the design reaches a steady state
  2. O. M. Querin, G. P. Steven and Y. M. Xie, Evolutionary structural optimisation (ESO) using a bidirectional algorithm, Engineering Computations 15(8), 1998, 1031 to 1048, adding elements next to the most stressed regions as well as removing the least stressed ones
  3. X. Huang and Y. M. Xie, Convergent and mesh-independent solutions for the bi-directional evolutionary structural optimization method, Finite Elements in Analysis and Design 43(14), 2007, 1039 to 1049, the sensitivity numbers, the mesh-independency filter, the averaging with the previous iteration, the evolutionary volume ratio and the stop rule on the compliance
  4. Xiaodong Huang and Yi Min Xie, Evolutionary Topology Optimization of Continuum Structures, Methods and Applications, Wiley, 2010, the soft-kill BESO with a material interpolation scheme and the admission ratio (general locator)
  5. M. Zhou and G. I. N. Rozvany, On the validity of ESO type methods in topology optimization, Structural and Multidisciplinary Optimization 21(1), 2001, 80 to 83, a small example where the element removal of ESO gives a highly nonoptimal design

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example