Constraints and Penalties

<< Click to Display Table of Contents >>

Navigation:  Chapter 6 - Programming Your Genetic Algorithms Using the DLL >

Constraints and Penalties

Previous pageReturn to chapter overviewNext page

The GAs that you program using GALIB32.DLL will, of course, require hard constraints (see Chapter 3), which are implemented when you supply the range information to MakeChromosome.  Soft constraints are more difficult.

 

There is no direct method of giving the DLL a soft constraint.  Soft constraints are implemented by adding a “penalty” to the fitness function.  Whenever the chromosomes of a particular individual violate a soft constraint, then you, the programmer, must add or subtract some penalty amount to or from the fitness.  If you are maximizing the fitness, then the penalty is subtracted before you call PutFitness.  If you are minimizing the fitness, then the penalty is added before calling PutFitness.  The net result is that, after some number of generations, the GA will stop generating individuals that violate the constraint, because such individuals are less fit.

 

How large should the penalty be?  This is difficult to answer because it is problem dependent.  You will probably have to experiment with different values.  However, a general rule is that the more the constraint is violated, the higher the penalty should be.  Also, more violated critical constraints should result in larger penalties.  Using some knowledge of the problem at hand, you will most likely be able to build better GAs with GALIB32.DLL than can be built with the Excel interface.