Engineering SHEET: /blog/当结构设计遇到遗传算法于是它学会了自己进化/ REV: 2026-05-20

When structural design encounters genetic algorithms, it learns to evolve on its own!

Zhou Wenqi (Venchy) 38 min read

When structural design encounters genetic algorithms, it learns to evolve on its own!

Official Account: Non-Deconstructive · Author: Zhou Wenqi (Venchy)

A long, long time ago, the editor only heard about genetic algorithms in legends, but I had no idea what this thing was. I just felt in my heart that this should be a very awesome existence. What was going on and what was its use? I couldn’t figure it out.。。 Until one day, when the editor was reading ABAQUS-related literature, I found an article “Optimization Design of Prestressed Concrete Wind Turbine Tower Based on Abaqus and Genetic Algorithm” and learned that this algorithm is a tool for solving optimization problems. Through genetic algorithms, the optimal solution of a certain problem can be obtained under the influence of multiple variables.But faced with such a bunch of complicated formulas, I have lost the courage to study genetic algorithms in depth. Another day, the editor was reading the book “Grasshopper Parametric Modeling Technology” and discovered that grasshopper comes with galapagos. Oh, isn’t this a genetic algorithm again?

Image

Following the example, the editor tried to do a simple genetic algorithm optimization in grasshopper:

Image

How cool, the genetic algorithm drives the changes in the input variables and finds the optimal solution in the changes, eh~~~eh~~~ In this case, can I combine it with finite element software to solve optimization problems? Let’s take a look at this simple example:

Image

The entire genetic algorithm optimization problem can be divided into three parts: (1) Input variables (2) Operation function (3) Genetic algorithm driven Let’s think about it again. If we define the variables as geometric parameters of the structure, replace the calculation function with the interface of grasshopper and sap2000, and then connect the genetic algorithm driver, can we solve the optimization problem of the building structure?

Image

So, I wrote this battery pack that combines genetic algorithm with sap2000.Simply solve for the minimum displacement of a single-joint single-span frame under the action of lateral force.

Image

After connecting this set of batteries, open the genetic algorithm module and make relevant settings, let them run.

Image

Although the editor has successfully used galapagos in grasshopper combined with sap2000 to do related optimization analysis, it seems that limitations still exist: (1) galapagos is a genetic algorithm solver for single-objective optimization, that is, it can only set one goal. For multi-objective optimization problems, such as our structural design, we must not only meet the minimum inter-story displacement angle requirements, but also meet the minimum mass requirements, this module seems a bit powerless. (2) The constraints of the target cannot be set.For example, when the calculated inter-layer displacement angle exceeds the specification, the corresponding genome needs to be discarded, and galapagos cannot meet our requirements here. (3) Using galapagos requires the help of the grasshopper platform and cannot solve optimization problems that cannot be expressed through grasshopper. The editor still wants to use a multi-objective optimization algorithm to optimize structural design problems.Think about it, if we let GA run by itself when adjusting the model, we should drink tea, play games, and sleep. It doesn’t feel too good to think about it. But, what the hell is a genetic algorithm? For the editor who has been studying CAD and PKPM and learning YJK, this algorithm thing is out of his reach~~~ So, does the editor just give up like this?!!Give up?!Give up?! Struggle, struggle or do some research.

What is a genetic algorithm?

Genetic algorithm, as you can tell from its name, is inspired by Darwin’s theory of evolution of “survival of the fittest, survival of the fittest”.The most basic common sense in biology is that biological inheritance is realized through genes, and these many genes together form chromosomes. We assume that a collection of multiple chromosomes together form a population.These constitute the most basic elements of the genetic algorithm.

So, what is its specific calculation process? Let us use a simple example to explain the calculation process of the simple genetic algorithm (SGA).

Step 1: Generate initial population Here, we need to determine several variables: (1) Coding rules The traditional optimization method uses the value of the variable itself as the optimization object, such as variables x1=5, x2=4, and directly inputs the value of the variable into the function that needs to be optimized, while the genetic algorithm uses the encoding of the decision variable as the operation object.Borrowing concepts from biology, these variables need to be converted into genes. Encoding rules generally include binary encoding, Gray code encoding, and floating point encoding.Here we use binary coding to encode the variables just now, x1=101, x2=100, x1 and x2 are two genes in the chromosome respectively, so they are combined to form one chromosome, that is, the common chromosome of x1 and x2 is 101100. (2) Population size In the genetic algorithm, defining multiple population sizes is the basis for the next chromosome crossover operation. The more chromosomes are defined, the greater the calculation amount, but the greater the discreteness of the chromosomes, and the results obtained meet the requirements. Here, we assume that a population with four chromosomes is initialized.

Image

Step Two: Individual Evaluation This is an operation that calculates the genetic probability of a chromosome. Here you need to combine the optimized function f(x), assuming f(x)=x1^2+x2^2, to calculate the function value corresponding to each chromosome.

Image

After completing the above fitness evaluation, the selection operation is performed based on the cumulative sum value of each chromosome. Step Three: Select Chromosomes In the process of biological evolution, species with a high degree of adaptability to the environment are more likely to evolve to the next generation, and the step of selecting chromosomes here is to select the chromosomes that will enter the next generation through fitness.The calculation of fitness has been completed through previous individual evaluations.To put it simply, the fitness of chromosome 1 is 34, and the sum of the fitness of all chromosomes is 143. Then 34/143=0.24 is the probability that this chromosome can be passed to the next generation. Here, we use the roulette selection mechanism to select the operator, that is, randomly generate a number between 0 and 1. If this number is within the probability interval of a certain chromosome, then we will select this chromosome to enter the next generation.For example, if 0.46 is randomly generated, then in this example 0.24<0.46<0.48, then the second chromosome will be selected to be inherited in the next generation.

Image

Step 4: Cross chromosomes In the process of biological evolution, two homologous chromosomes recombine through mating to form new chromosomes.In genetic algorithms, related mechanisms are also introduced.Crossover chromosomes refer to the genetic exchange of two paired chromosomes in a certain way to form two new individuals. In the crossover process, the first thing to do is to pair, that is, to group chromosomes into pairs.The general pairing strategy is random, that is, two chromosomes are randomly selected for pairing. The next step is to perform the crossover operation.Crossover can be divided into single-point crossover, double-point crossover, multi-point crossover, etc.For most crossover methods, the location of the crossover point is chosen randomly.

Image

Through the selection operation, we can trace the source. The red part is the component of chromosome 1 after selection, the green part is the component of chromosome 2 after selection, the blue part is the component of chromosome 3 after selection, and the orange part is the component of chromosome 4 after selection.Their intersection points are all random. Step 5: Mutation In the process of biological evolution, due to the action of some accidental factors, certain gene changes will occur, resulting in the emergence of new chromosomes.The mutation operation in the genetic algorithm refers to replacing certain genes in the coding string of individual chromosomes according to their equivalent genes.In short, in binary coding, some 0 components in the gene are replaced with 1 or some 1 components are replaced with 0.This operation is mainly to maintain the diversity of genes and improve the local search ability of the genetic algorithm.

Image

In the above example, the red part is the mutation point produced by the gene.After the mutation is completed, the operation operation of the genetic algorithm generation is completed.The mutated chromosomes are then decoded to obtain the variable values ​​in decimal notation, which are then submitted to the fitness calculation step for calculation. Repeatedly, the evolution of the multi-generation genetic algorithm can be formed to achieve the solution of the optimization problem. Based on the aforementioned solution process, the following genetic algorithm flow chart is obtained.What needs special emphasis is that randomness is a particularly important concept in genetic algorithms. It is a process that guides a set of random processes to the optimal result through a certain mechanism.Among them, the generation of the initial population, the operations of the selection operator, crossover operator, and mutation operator all require random processes.For civil dogs who are not used to using random operations, it is indeed difficult to understand.

Image

After learning all this, the editor is still only at the stage of talking on paper.Can you code a genetic algorithm yourself?!Tangled, hesitant, confused~~~The editor fell into struggle, struggle, struggle again.。。However, thinking about the days when I could drink tea, play games, and sleep while working, the editor’s curiosity for knowledge was aroused again. Of course, the gap between coding and theory is still a bit big.The processing of details is still very complicated. The editor randomly constructed a function to solve:

Image

Four variables x1, x2, x3, and x4 are defined to solve the problem of the maximum value of the function.

Image

Image

It can be seen from the above cases that although there were large fluctuations in the optimization process, after 20-30 generations of operation, the optimization results tended to be stable and corresponding optimization results were obtained. So, can it be combined with finite element software next?!

Image

The editor established a three-bay, three-span, three-story frame. The cross-section size of beams and columns on each floor under the action of lateral force was used as the optimization condition. The minimum inter-story displacement on the first floor was set as the optimization goal, and the optimization operation of the genetic algorithm was performed. Look, look, the genetic algorithm is running happily.。。The editor can go drink tea, sleep and play games.。。。

Image

Image

Image

Image

After a cup of tea, I checked the calculation results. The model became stable around the 30th to 40th generation, with the minimum displacement around 0.33. Although the calculation results after the 40th generation also jumped a bit, they were still relatively stable.The calculation results show that the combination of genetic algorithm and finite element calculation of sap2000 can achieve the expected optimization goal. This is just the simplest genetic algorithm case. For the multi-objective optimization problems, classification problems, etc. that the editor first talked about, there are other genetic algorithm models that can be solved. The editor will introduce AGGA, NSGA-II and other optimization algorithms in the future, so stay tuned.

postscript: When I read an online article before, I was particularly impressed by a sentence: “Skip the cause and effect and find the answer directly from the relationship of the data.“Among the many nonlinear problems, traditional mathematical optimization seems to be a bit limited for problems that cannot be expressed in purely mathematical ways. However, through the analysis of optimization problems through evolutionary algorithms such as genetic algorithms and simulated annealing algorithms, although it cannot obtain an exact solution, it can provide you with a form that is close to the optimal solution.At a time when many parties are bringing optimization companies to fasten steel bars every day, the significance of structural optimization analysis using algorithms based on the concept of parametrics is self-evident for structural design.

In order to facilitate everyone to exchange technology and exchange industry information, please add our “Da Feier” WeChat and join the relevant discussion and exchange group.The Shanghai Structural Design Circle is limited to friends who are engaged in structural design in Shanghai.

Image

Image

Highlights from the past The structure is not only the CAD in front of you, but also python and hair! Use the kangaroo to make the Rhinoceros jump!

Python crawler practice - automatically download seismic wave time history from the Pacific Earthquake Engineering Research Center database

The wind is Xiaoxi - the implementation of single-point pulsating wind AR model

Make your first grasshopper battery

Discussing the form-finding of free-form surface structures in space - taking the British Museum and the Netherlands Maritime Museum as examples

When an architect throws me a rhino model (2)

Parametric analysis of steel structure support end gusset plate based on secondary development of ABAQUS

Image


This document is automatically collected and organized by AI from non-deconstructed public accounts and is for learning reference only.

#wechat

Original Source: http://mp.weixin.qq.com/s?__biz=MzU0Nzc5MDQxNw==&mid=2247487594&idx=1&sn=ff54fbe6eab0050f660f8805968865e0&chksm=fb485b54cc3fd242e8c1ca29acdabc39629458f09955a013cfa28df612ea725f2f65799539c4#rd

§

评论

COMMENT / REVIEW REQUIRED

LOADING…