When structural design encounters genetic algorithms, it learns to evolve on its own!
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… 直到有一天,小编看ABAQUS相关的文献的时候,发现一篇文章《基于Abaqus和遗传算法的预应力混凝土风机塔架优化设计》,知道了这个算法是求最优化问题的工具,就是通过遗传算法,可以得到某个问题在多个变量影响下的最优解。但面对那么一堆复杂的公式,已然丧失了深究遗传算法的勇气。 再又到一天,小编看《Grasshopper参数化建模技术》这本书,发现grasshopper自带的galapagos,oh,这不又是遗传算法吗?

照着例题,小编试着在grasshopper中做了个简单的遗传算法的优化:

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:

整个遗传算法最优化问题可以分成了三个部分: (1) Input variables (2)运算函数 (3)遗传算法驱动 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?

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.

连接完成这组电池,打开遗传算法模块做好相关设置后,就让他们跑起来吧。

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. 小编还是想做多目标优化算法来优化结构设计问题的。想想要是调模型的时候让GA自己跑起来,我们该喝茶喝茶,该打游戏打游戏,该睡觉睡觉,想想不要太爽。 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? ! 挣扎,挣扎着要么还是去研究一下吧。
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? 我们通过一个简单的例子,来阐述一下简单遗传算法(SGA)的计算过程。
第一步:生成初始种群 Here, we need to determine several variables: (1)编码规则 传统的优化方法是以变量本身的值作为优化对象的,如变量x1=5,x2=4,直接将变量的值输入需要被优化的函数,而对遗传算法是以决策变量的编码作为运算对象的。借鉴生物学的概念,这些变量都需要被转换为基因。 编码规则一般有二进制编码法,格雷码编码法,浮点数编码法。这里我们用二进制编码法来对刚才的变量进行编码,x1=101,x2=100,x1及x2分别是染色体中的两个基因,因此将其合并组成一个染色体,即x1和x2共同的染色体为101100。 (2)种群数量 在遗传算法中,定义多个种群数量是接下来染色体进行交叉操作的基础,定义越多的染色体,计算量越大,但是染色体的离散度也越大,得到的结果符合要求。 Here, we assume that a population with four chromosomes is initialized.

第二步:个体评价 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.

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. 在这里,我们用轮盘赌选择机制来选择算子,即随机生成一个0-1之间的数,如果这个数在某个染色体的概率区间,那么,我们就选择这个染色体进入下一代。譬如随机生成了0.46,那么在这个例子中0.24<0.46<0.48,那么就选择第二条染色体进入下一代遗传。

Step 4: Cross chromosomes 在生物进化过程中,两个同源染色体通过交配而重组,形成新的染色体。在遗传算法中,也引入了相关的机制。交叉染色体,是指对两个相互配对的染色体按某种方式进行基因互换,从而形成两个新的个体。 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. 接下来就是要进行交叉操作。交叉可分为单点交叉,双点交叉多点交叉等。对于大多数的交叉方法,交叉点位置的选取都是随机的。

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 在生物进化过程中,由于一些偶然因素的作用,会产生某些基因的变化,从而出现新的染色体。遗传算法中的变异运算,是指将个体染色体编码串中的某些基因按照其等效基因进行替换。简而言之,在二进制编码中,将基因中的某些0成分替换成1或者将某些1成分替换成0。这个操作主要是要维持基因的多样性,同时改善遗传算法的局部搜索能力。

在以上例子中红色部分即为基因产生的变异点。变异完成后,即完成遗传算法一代的运算操作。再将变异后的染色体进行解码,得到十进制下的变量值,提交到适应度计算步骤进行运算,循环往复,即可形成多代遗传算法的进化,实现最优化问题的求解。 综合前述求解过程,得到以下遗传算法流程图。其中需要特别强调的是,随机是遗传算法中一个特别重要的概念,它是通过一定的机制,将一组随机过程引导至最优化结果的过程。其中,初始种群的生成,选择算子,交叉算子,变异算子的操作,都需要随机过程。对于不习惯用随机运算的土木狗来说,理解起来确实有一定的困难。

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. 小编随机构造了一个函数进行求解:

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


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? !

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… .




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.
为了方便大家交流技术和互通行业资讯,请添加我们“大菲儿”微信,加入相关讨论交流群。上海结构设计圈仅限在上海从事结构设计的朋友们。


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

本文档由AI从非解构公众号自动采集整理,仅供学习参考。
LOADING…