Genetic Algorithm for Industrial Process Optimization
Determining optimal control settings for a multi-stage industrial process (with code)
Determining optimal control settings for an industrial process can be challenging. For example, when there are interactions between the effects of the controls, adjusting one setting can require readjusting other settings. A previous article addressed this challenge using deep reinforcement learning to determine the settings for a multi-zoned reflow oven used for soldering electronic components to a circuit board (Figures 1 & 2). This article addresses the same problem using genetic optimization.
The problem
The oven comprises a moving belt that transports the circuit board (product) through eight heating zones (Figure 3), each with a control for setting the temperature of the zone’s heater. An additional control determines the speed of the belt.
The reflow process heats the product according to a target temperature-time profile (Figure 4) required to ensure reliable solder connections. The temperature of the product at each point along the path is determined by the heat transferred to the product from the heaters. Sensors report the temperature of the product as it travels through the oven.
Before making a production run of circuit boards, an operator typically takes the following steps to determine the proper oven settings to produce the target profile:
- run one pass of the product through the oven
- observe the temperature-time profile from the sensor readings
- adjust the heater settings and belt speed to improve the profile
- wait for the oven to stabilize to the new settings
- repeat these steps until the profile from the sensor readings is acceptably close to the target profile
Genetic optimization
The genetic optimization solution described in this post follows a similar procedure. The algorithm models the oven’s controls as a chromosome that comprises nine genes representing the eight heater controls and the belt speed (Figure 5). The genes hold the heaters’ temperature settings and the belt speed.
The algorithm begins by generating a population of oven chromosomes, each with randomly generated gene values. For each member of the population, the oven is programmed with the gene values from that member’s chromosome, and the product is then passed through the oven. The resulting sensor temperature readings are compared to the target temperature-time profile to determine the fitness of that chromosome. The closer the match, the greater the fitness value.
Note: Since considerable time is required to stabilize an oven’s temperature after changing the heater settings (up to 40 minutes) and passing the product through the oven (5 minutes), an oven simulator is used to speed up the genetic learning process. The simulator emulates a single pass of the product through the oven in a few seconds compared to the minutes required by a physical oven. A detailed description of the simulator is available here.
For the next step, the algorithm starts a new generation by creating a new population based on the fitness values of the previous generation and the operations of elitism, cross-over, and mutation. Elitism adds the highest fitness-valued chromosome from the last generation to the new population. Cross-over creates new chromosomes by mixing the genes from high-fitness parent chromosomes from the previous generation. Figure 6 shows two possible child chromosomes formed from two parent chromosomes.
Mutation randomly changes gene values in the new population (Figure 7).
Once the generation is fully populated, the chromosome fitness values are determined, and the process repeats with the next generation. As the algorithm evolves through the generations, the fitness of the best member in each generation increases.
Implementation
The complete Python code for this project is available on Github. The genetic algorithm is implemented with PyGAD, an extensive Python library for building genetic optimization applications.
Results
The results were produced with the following oven, target profile, and product parameters:
PyGAD was instantiated with the parameters from Table 1.
Figure 8 shows the progression of the genetic algorithm from the initial population through generation 170. The best member in each successive generation brings the product temperature (red trace) in closer alignment with the target profile (blue trace). The red trace is the product temperature resulting from each generation’s chromosome settings for the heaters and belt speed.
Figure 9 shows the generation that first achieved the highest fitness value (with subsequent generations maintaining the same value). Even though the algorithm stabilizes at a high fitness value, it does not achieve perfect alignment between the actual product temperature and the target profile. This is partially a result of the physical constraints of the oven since there is no belt speed that can exactly match the timing of the heater zones with the target profile zones. Another constraint is that the relationship between temperature change vs. time is non-linear. Given these constraints, the chromosome settings of this generation represent the best alignment possible with the target profile. The resulting profile is acceptable for producing reliable solder connections.
Figure 10 is the chromosome of the best generation with gene values representing the optimal settings for the heaters and belt speed.
Figure 11 plots the improvement in fitness as the algorithm progresses through the generations.
Conclusion
This article presented a genetic algorithm to determine the optimal settings for a multi-stage reflow oven. The algorithm successfully determined the process settings necessary to produce a product temperature-time profile that is acceptably close to the desired target profile.
A pdf of this article is available on Github.
All images, unless otherwise noted, are by the author.