The fitness function simply defined is a function that takes a candidate solution to the problem as input and produces as output how “fit” our how “good” the solution is with respect to the problem in consideration.
Calculation of fitness value is done repeatedly in a GA and therefore it should be sufficiently fast. A slow computation of the fitness value can adversely affect a GA and make it exceptionally slow.
In most of the cases, the fitness function and the objective function are the same as the objective is to either maximize or minimize the given objective function. For the complex problems having multiple objectives and constraints, an Algorithm Designer might choose to have a different fitness function.
A fitness function should have the following characteristics −
In some cases, calculating the fitness function directly might not be possible due to the inherent complexities of the problem at hand. In such cases, we do fitness approximation to suit our needs.
You can refer the following link for the calculation of fitness function:https://towardsdatascience.com/how-to-define-a-fitness-function-in-a-genetic-algorithm-be572b9ea3b4
Fitness functions are used in genetic programming and genetic algorithms to guide simulations towards optimal design solutions so if you wish to learn about Genetic Programming then visit this Artificial Intelligence Course.