To locate a minimum of Himmelblau's function using particle swarm optimization, we've created a Python program called 03-pso-himmelblau.py, which is located at https://github.com/PacktPublishing/Hands-On-Genetic-Algorithms-with-Python/blob/master/Chapter12/03-pso-himmelblau.py.
The following steps describe the main parts of this program:
- We start by setting various constants that will be used throughout the program. First is the dimensionality of the problem at hand – two, in our case – which, in turn, determines the dimensionality of the location and velocity of each particle. Next comes the population size – the total number of particles in the swarm, and the number of generations, or iterations, ...