Skip to content
Home » Fitness function

Fitness function

Genetic Algorithm – Fitness Function

1. What is a Fitness Function?

A Fitness Function is a function used in a Genetic Algorithm to measure how good or suitable a candidate solution is.

It assigns a fitness value to each chromosome. A better solution generally gets a better fitness value.

2. Simple Example

Suppose we want to maximize:\[ f(x)=x^2 \]

For different chromosomes:

Solution \(x\)Fitness \(f(x)\)
24
416
636
864

Here, 8 is the best solution because it has the highest fitness value.


3. Role in Genetic Algorithm

The fitness function is mainly used during selection.

Population
    ↓
Fitness Function
    ↓
Calculate Fitness
    ↓
Select Better Solutions
    ↓
Crossover + Mutation
    ↓
New Generation

Solutions with better fitness usually get a higher probability of being selected for reproduction.


4. Maximization and Minimization

Maximization Problem

Higher value = better solution.

Example:\[ Fitness=f(x) \]

Fitness = 90 → Better
Fitness = 50 → Poorer

Minimization Problem

Lower value = better solution.

For example, if we want to minimize distance:

Distance = 100 km → Poor
Distance = 50 km  → Better
Distance = 20 km  → Best

The objective may need to be converted into a fitness value, for example:\[ Fitness = \frac{1}{1+Cost} \]

So lower cost produces higher fitness.


5. Example in Travelling Salesman Problem

In TSP, the objective is to minimize total distance.

Suppose:

RouteDistanceFitness
A100 km0.0099
B70 km0.0141
C40 km0.0244

Using:\[ Fitness=\frac{1}{1+Distance} \]

Route C has the highest fitness and is therefore the better solution.


6. Important Characteristics

A good fitness function should:

  • Clearly measure the quality of a solution
  • Distinguish good and poor solutions
  • Be reasonably fast to calculate
  • Match the objective of the problem
  • Give meaningful values for selection

Exam Definition

A Fitness Function is a function used in a Genetic Algorithm to evaluate the quality or performance of each candidate solution. It assigns a fitness value to chromosomes and helps the algorithm select better solutions for the next generation.

Memory Line

Fitness Function = “How good is this solution?”