Initial population (InitialPopulationMatrix) specifies an initial population for the genetic algorithm. The default value is [], in which case ga uses the default Creation function to create an initial population. If you enter a nonempty array in the Initial population field, the array must have no more than Population size rows, and exactly Number of variables columns. If you have a partial initial population, meaning fewer than Population size rows, then the genetic algorithm calls a Creation function to generate the remaining individuals.
So the way you should proceed is:
- Make an array of all possible combinations of resistor values, one row each;
- Set the InitialPopulation option to that array;
- Set the Population Size option to the same number of rows that the above array has
- set the OutputFcn option to pick through the values and choose all of the ones with the same optimal value
- run ga() with those options
ga will proceed to evaluate the objective function with the contents of each row of that InitialPopulation, calculating the cost for each. It will then flail around for a while trying to find better values, but will not make any progress because you already gave all possible combinations as initial population, so any selection and random combinations and so on it does will just be redundant. In time it will give up and return back the value corresponding to one of the best entries; in the meantime the OutputFcn will have fired and you would have configured that to save all of the ones that had the same best score.
Now, if I needed to do this, I would not bother with the step of calling ga(): I would just call the objective function on each of the possible combinations, since you had to build them in advance anyhow. ga() is not going to add anything useful to the process.
I suspect this is not the answer you were expecting, and not the answer you were looking for, but it is the answer.
The reason it is is the answer is that ga() is not guaranteed to try any particular population combination unless it is given as an InitialPopulation . ga() proceeds randomly, and will happily try the same combination (say) 39 times while completely missing a different combination. ga() doesn't care.
In any situation in which you need all of something, you should not be using ga(), or fmincon() or fminsearch() or patternsearch() or gamultiobj() or simulated annealing . Not one of them is guaranteed to try all of the possibilities, and typically they will not try all of them. If you need all of a possibility, then you need to generate all of the possibilities and try them all -- though in some cases it is possible to be smart about what to try, such as if you use alpha-beta pruning or dynamic programming.
Best Answer