— PROJECT NAME
Coevolution of Soft Robots and Controllers
— Skills and Tools
C++
OpenGL
Machine Learning
Xcode
— DATE
Fall 2021
Evolutionary Computation is a sub field of Machine Learning that is inspired from biological evolution. The whole idea of evolutionary computation is to develop an algorithm that can solve a very difficult problem that is easy to test. Evolutionary Computation starts off with a random population of solutions. Then, the algorithm identifies certain traits or genes within a solution that are defined by the user. From here, the algorithm will breed two solutions and use recombination and crossover to swap genes between the parents to create a new offspring. This process evolves the original population and the best individuals are selected to survive. Evolutionary computation can be used to solve a variety of problems including the traveling salesperson problem, symbolic regression, circuit design, bridge design, wind turbine design, and robotics.
The purpose of this final project is to develop your own Genetic Algorithm that evolves soft robots and their controllers to optimize speed and displacement. The project itself was very open-ended and allowed room for creativity and different approaches.
I wanted to create an algorithm that randomly generated a population of soft robots of different sizes and a population of controllers for those robots and then coevolve the two population to then optimize the best soft robot shape and corresponding controller. Below is my approach
Description
Before I can even evolve soft robots, I needed to create an environment in which to test my evolved population. As a result, I had to create my own physics simulator. To do so, I used single point masses and springs to simulate solid objects, used OpenGL for 3D graphics, and provided different environment options such as damping and friction that could be toggled on or off. Below are the results of my physics simulator. My physics simulator can be found on my github page.
Description
After creating my physics simulator, the next step was to figure out a way to randomly generate a population of robots that are of different size and shape. I created my robots to be a set of individual cubes. Each cube is made of 8 point masses and 28 springs. The challenging part was being able to randomly pick available faces of the robot and fuse cubes together without repeating point masses and springs. To do this, I kept track of the available faces that an additional cube could be fused to given the current robot configuration and also kept track of points and springs that would match up with each other when fused to another cube. Below is a diagram depicting my idea.
Illustration of how my program worked to randomly generate robots
Description
One of the last steps is to figure out how to breed robots. As stated in the very first section of this page, the idea of evolutionary computation is to take the genes of two parent solutions and recombine them to create an offspring. I approached this problem by recombining vectors of We
represented each robot as a vector of cubes. The positions of the cubes and which cubes they are fused to are the genes and these genes lead to a particular phenotype. This representation allows us to easily crossover two parents. To visualize this I provided a scaled down example in which the offspring gains its first 3 cubes from parent 1 and the last two cubes from parent 2. Please see the images below. easily es
Illustration of how I represented the “DNA” of my soft robots and how the “genes” were recombined.
Process of recombining soft robot DNA to create a new offspring
Description
Continued
From the image above, the program then initializes the offspring and takes the first three cubes from Parent 1 and keeps them in the same configuration. Then, it takes cube 4 from Parent 2 and recognizes that it's supposed to be attached to the front of cube 1. However; on the offspring, cube 2 is already fused to the front of cube 1, so the program instead shifts cube 4 up and attaches it to cube 2. Finally, the program takes Cube 5 from Parent 2 and realizes it's supposed to be attached to the top of Cube 3 and does exactly that. Now, we have our new offspring. To maintain diversity in our robotic population, we also implemented deterministic crowding.
Description
The second to last step is to figure how to represent the controllers for the soft robots. Basically, how do we encode the controllers? We can do so by evolving an equation for each cube of a robot given a set of parameters. As I said previously, each cube is made up of 28 springs. each spring has a material coefficient K and a resting length. From here, you could vary the resting length of a particular spring in a cube by applying a sin wave function. If you apply different material coefficients and equations for each cube (the same equation is applied to all the springs in a cube), you can create a controller for your soft robot that makes the robot move. Below is an illustration of how I implemented direct encoding to create a controller.
Description
The final step is to figure out how to coevolve the controller with the soft robots. To do this, I tested out each evolved controller with each evolved soft robot. Whichever controller performed the best with that particular soft robot, that soft robot would be assigned to that controller. A controller could have multiple soft robots assigned to it. The controller and the soft robot would take turns breeding and evolving. For example, for one iteration, the soft robot will breed and the offspring will be tested with each controller to determine its fitness. The next iteration, the controllers would evolve and the offspring of the controllers would be tested with each soft robot. If the new controller offspring performed better for a soft robot than did the original controller, that soft robot would be assigned to the new controller and the fitness of the robot would be updated.
Deterministic Crowding and Hierarchical Fair Competition
Diversity is paramount in the success of a genetic algorithm. Without diversity, a population cannot evolve properly and all of the resulting individuals will become identical. As a result, I had to use two methods to both maintain diversity and generate diversity.
To implement deterministic crowding for the soft robots, every individual was able to reproduce and the second parent was picked randomly from the top 50% of the individuals. I only produced one offspring that inherited part of its DNA from parent 2. From there, Albert assumed the offspring would have a greater similarity to parent 1 than parent 2 and thus only had parent 1 replaced if and only if the single offspring had a better fitness.
For the controllers, I implemented both deterministic crowding and hierarchical fair competition. To implement deterministic crowding, every individual was able to reproduce and the second parent was picked randomly from the top 50% of the individuals. I only produced one offspring that inherited part of its DNA from parent 2. From there, I assumed the offspring would have a greater similarity to parent 1 than parent 2 and thus only had parent 1 replaced if and only if the single offspring had a better fitness. The Hierarchical Fair Competition method was a little tricky to implement and required some arbitrary decisions on certain parameters. As a reminder, the hierarchical fair competition method separates the entire population into different leagues, such that only individuals with certain fitness levels were able to reproduce with one another, similar to sports leagues. After several generations, some individuals were able to move up into a better leagues, and some are eliminated. For the algorithm, I two leagues: the little league and the major league. The little league maintained a population of 100, and the major league started off with a population of 50, but then grew and maintained a population of 75. Initially, we initialize the little league with a population of 100. After 10 generations, we moved the major league and then replaced those 50 with random individuals that was generated from a "replenish population" function. After them first 10 generations, the little league and the major league evolve in parallel.are retired, the top 50 of the little league move up to major league, and the little league population is replenished once again.From here on out, after every 10 generations, the top 25 of the major league are kept, the bottom 25 of the major league are retired, the top 50 of the little league move up to major league, and the little league population is replenished once again.