Here are links to see the main code and the header code. The header code defines five classes: Strand, GenePool, Opti, Mini, Maxi.
Strand is analogous to a DNA strand. It has an array of genes associated with it, an integer length and a variable cost of type double. These genes are of type double and are values of the independant variables given to the optimizer. Thus, each strand has one value for all of the independant variables and offers a possible "solution" to the figure of merit function. The length is the number of genes in the array. The cost is the calculated figure of merit for the strand. The class has several constructors, a destructor, a getter function for the cost, operator overloads for = and (), and several Init functions to randomize the gene values in different ways.
GenePool has an array of strands, an integer population (the number of strands), and an integer length (the length of the strands). The class has several constructors, a destructor, getter functions for length and population, a setter function for length, and several Init functions which will cycle through the strands calling the appropriate Strand Init function for each.
Opti is a class that is inherited from GenePool. Therefore, it contains everything GenePool has but also adds: an integer number of generations, a new Strand called trial to test against existing strands in the GenePool, a figure of merit function called f which will be used to calculate the Strand costs, a function Setf to assign the function f, a constructor, and a function Best to return the index of the best strand in the GenePool. There is also an overloaded pure virtual function, Better, which is defined in classes inherited from Opti. These pure virtual functions prevent instances of Opti from being created directly. (Instances must be created from an inherited class of Opti which has the two Better functions defined.) Lastly, there is the virtual function Optimize which is defined in the main code and will be described below.
Mini and Maxi are two classes inherited from Opti. They simply choose whether you are trying to minimize or maximize the figure of merit function, and they define the two Better functions accordingly. One Better function sees whether the trial Strand is better the a strand in the GenePool, and the other Better function compares two Strands in the GenePool.
In BMADZ, we create an instance of the Mini class, where the length of the Strands is the number of independant variables we are using, the number of generations is the number of cycles assigned in the constraint file, the population is chosen to be 5 times the number of independant variables, and the figure of merit function is demerit which is defined in bmad_opt.f90.
more coming...