# AI Driven Engineering Optimization of a Trebuchet, Part #1

Genetic Algorithms (GAs) are one of our favorite tools at Resolved Analytics. I can’t help but think that they are an under-appreciated and under-utilized resource for engineers. If you take a look at the Wikipedia page on genetic algorithms you’ll quickly understand why we hear so little about their use. The material is dry, difficult to follow for those not familiar with mathematical operations research, and lacking real world context. Jargon such as “metaheuristics”, “arrays of bits”, and “chromosome representation” make GAs inaccessible to potential learners. Hopefully this series of posts can demystify GAs and encourage their use by starting with a simple, easy to follow use case and building from there.

### Trebuchets!

Everyone knows what a trebuchet is, right? In case you don’t, you should know that it’s a compound machine capable of hurling heavy stones, dead horses, flaming sacks of manure or even pianos at your enemy’s castle using only the force of gravity.

“The key is not the thing you fling, but the fling itself.” Chris Stevens – Northern Exposure

We will start with a simple design optimization problem and build from there. Our initial design is for a see-saw type trebuchet with the counterweight rigidly attached to the lever arm and not utilizing any sling mechanism. The counterweight is raised and then dropped, accelerating the projectile located at the opposite end of the arm and launching it upon impact of the counter weight with the Earth. The initial objective is to achieve the maximum flight distance while obeying all design constraints. This distance we will call the **objective function**. The independent parameters of our solution space include the counter weight and projectile arm lengths and initial angles, as well as the pivot elevation, as shown in the following figure.

### Genetic Algorithms!

Genetic algorithms have a tremendous range of potential uses and are widely being used in fields such as computational biology, financing, logistics, and power electronics. They are one instance of an evolutionary algorithm inspired by biological evolution for iteratively searching for optimal solutions to all types of mathematical problems. A genetic algorithm works by iteratively transforming a collection of possible solutions (sets) to the optimization problem by analogies with evolutionary functions such as reproduction, mutation and selection. A picture speaks a thousand volumes.

An initial collection of sets of gene traits is evaluated and sorted for "fitness", i.e., how well the set of traits solves the problem, and then transformed into a 2nd generation by the following mechanisms:

- A setpoint number of elites survive
- A setpoint number of parents breed children in random fashion
- A setpoint number of children survive without mutation
- A setpoint number of children experience mutation according to a setpoint number of mutations per set

The process of evaluation, sorting and evolution is then repeated for 3rd and future generations. While you chew on this initial description of the optimization problem and genetic algorithms, we’ll be preparing our later installments including:

- Part #2: Detailed equations and GA implementation, with results
- Part #3: Comparison of results with other optimization algorithms
- Part #4: Extension of the model to include additional physics and multiple objectives
- Part #5: Extension of the model to include sling dynamics and Matlab implementation

In the meantime, make sure to keep those flaming projectiles a safe distance from thatched roof historical buildings! Stay tuned and thanks for reading.

In this section, we’re discussing software packages that strive to be comprehensive, multi-physics tools but, in our opinion, fall just a little short in some respect. There are many available CFD software packages that could be described as semi-comprehensive, and we couldn’t possible review them all and still get any real work done. So here, we are focusing on three software packages in this category based on their large user base and/or their potential to become comprehensive: COMSOL Multiphysics, CONVERGE CFD, and Numeca OMNIS.