## A.3 Scaling Method

If the normal selection ruler is used during the GA computation
(*pselect***i***
= fi/f* ) in later generations, when the
population average fitness gets close to the population best
fitness, the above-average members are overwhelmed by average members and
under-average ones. The computation becomes more a random walk. In
this case fitness scaling can help. The linear scaling looks like this :

`f' = af + b.`

__Problems: __

`TFit` is intended to be a number from the interval <0,1>
- The linearity must be preseved.

As a solution the following alternative was chosen.

All genes under `f`_{avg}
are degraded by the `Deg` value. The `Deg` is a multiplicator between
<0,1> specified by user.

__The possible implementation:__

`
void CalculateScaling (TPopulation &pop, double deg, double &avg,
double &a, double &b)
{
double total=0;
for (uint i=0; i<pop.GetSize(); i++)
total+=pop[i].GetFit();
if (pop.GetSize()) avg = total / pop.getSize();
else avg = 0;
if (avg<1) a = (deg*avg - 1) / (avg - 1);
else a=1;
b = 1 - a;
return;
}`

`TFit ScaleFit (TFit from, double deg, double avg, double a, double b)
{
if (from <= avg) return (deg*from);
return (a*from)+b;`

}