﻿ Chapter 4 - GeneHunter Tutorial for the Excel Interface > Camping Trip Example > Tutorial Step 7

# Tutorial Step 7

Navigation:  Chapter 4 - GeneHunter Tutorial for the Excel Interface > Camping Trip Example >

# Tutorial Step 7

 Constraints as Subgoals   GeneHunter considers constraints as subgoals when searching for a solution.  The Camping Trip example does this by comparing cells D8:D13 (Actual Percent of Diet) with cells C8:C13 (Recommended Percent of Diet).  The comparison is listed as a constraint in the list of constraints as follows:  \$D\$8:\$D\$13=\$C\$8:\$C\$13.  If the sum of Actual Percent of Diet differs from the sum of Recommended Percent of Diet in a particular solution, GeneHunter attempts to find solutions where the sums are closer to each other.  It may take a number of generations before solutions evolve in which the sums are actually close.  The same is true for any soft constraint: early solutions may not meet the constraint very well.  In fact, for some problems, a soft constraint may never be attained exactly.   In order that the user can have a single measurement of how good the Diet Quality is, we have included a Diet Quality percentage in cell G16.  This has nothing to do with the functioning of the GA or the problem; it is just for information only.  The Diet Quality percentage is calculated using the least squares method from statistics.  The difference between the actual servings minus the recommended servings is computed and then squared for each food group.  Squaring the error serves two purposes:  it magnifies the larger errors and it offsets the cases where the differences are negative values (the square of a negative number is a positive number).   The Diet Quality percentage is computed by the following formula: =1-SQRT(SUM(H8:H13))   Taking the square root of values that were previously squared brings the error value back into the range of the original values.  This value is subtracted from 1 in order to show the Diet Quality rather than a small diet error value.   You may want to experiment by varying the constraint on the minimum or maximum number of servings or by varying the Recommended Percent of Diet for each food group.  Another experiment you can try is to use the Diet Quality percentage as the fitness function, which you will maximize.  In this case, there will be no soft constraint, and we are assuming that cost is not a consideration.