Fitness is a numerical score for the quality of a candidate solution. In an evolutionary algorithm, a fitness function scores each individual in a population; higher scores indicate better solutions. Those scores help determine which candidates reproduce or survive as the population evolves. section 7.2.3 section 7.3
Choosing a ticket price
Suppose each candidate is a ticket price and its fitness is the resulting profit. Five candidate prices produce scores of 8,820, 84,420, 90,000, 128,500, and 18,000. The price scoring 128,500 ranks first in this small population—not necessarily across every possible price. In the Python implementation, the best reported price is $155, with profit of $130,500. section 7.3.3 section 7.4
Fitness matters at several points in a genetic algorithm:
- Evaluate the initial population and score new offspring after crossover and mutation. section 7.3
- Select parents: fitness-proportionate selection divides each score by the population’s total fitness to obtain a selection probability. In the ticket-price population, 128,500 ÷ 329,740 gives the leading candidate about a 0.39 chance on each roulette-wheel draw. section 7.3.3
- Select survivors: elitism retains top-scoring individuals, while other methods can leave more room for diversity. section 7.3.5
Match the score’s direction to the search. A genetic algorithm framed around higher fitness can minimize an objective by negating it: maximizing −O(x) selects the same solution as minimizing O(x). Other transformations are possible, but their suitability depends on the objective’s values; a reciprocal transformation, for example, requires a non-negative objective and cannot divide by zero. Fitness also need not dictate every parent choice: random selection gives candidates equal chances, whereas roulette-wheel selection favors higher scores. section 7.3.1 section 7.4
def fitness_score(population):
fitness_values = []
num = []
for i in range(len(population)):
num.append(int("".join(str(x) for x in population[i]), base=2)) #1
fitness_values.append(profit(num[i])) #2
tuples = zip(*sorted(zip(fitness_values, population),reverse=True)) #3
fitness_values, population = [list(t) for t in tuples] #4
return fitness_values, population #5
The Python fitness_score function decodes binary chromosomes into ticket prices, calculates profit for each, and returns scores paired with candidates in descending order. section 7.4
When adapting the method, decide what each candidate represents, define a score that reflects the desired outcome, and check how selection uses that score. For constrained problems, offspring may also need a feasibility check and repair; a high score alone does not replace those steps. section 7.2.3 section 7.3





