VIEW THIS AS

Auto mode follows the Route Engine until you choose a viewpoint.

YOU ARE HERE

ROUTE CHECK

CONNECTED TO

WHAT NEXT

Use the canonical route for this room, or HELP if you are unsure.

How Artificial Intelligence AI Works | How AI Searches for Better Solutions With Genetic Algorithms

Did you know? Some optimisation problems have so many possible solutions that checking every one would be impractical. Instead of using a single guess and adjusting it step by step, a computer can keep a population of candidate solutions, evaluate them, combine some of them and introduce small random changes.

This is a family of methods called evolutionary computation. A well-known example is the genetic algorithm. The terminology is inspired by ideas from biological evolution, but the method is a deliberately designed mathematical search procedure, not an artificial organism.

Quick answer: represent candidate designs → create an initial population → calculate fitness under stated rules → select candidates → apply crossover and mutation → evaluate a new generation → stop when suitable criteria are met. A strong fitness score is evidence that a candidate performs well on the chosen objective, not proof that it is safe, fair or globally optimal.

Genetic algorithms in 30 seconds

  • Individual: one candidate solution to the defined problem.
  • Chromosome or genome: a numerical or symbolic encoding of an individual.
  • Population: a collection of candidates evaluated together.
  • Fitness function: a numerical score or set of scores representing the design objective.
  • Selection: choosing which candidates influence the next generation.
  • Crossover: combining information from two candidates under a specified operator.
  • Mutation: making a small, potentially random change to a candidate.
  • Generation: one stage of evaluation, selection and variation.

These are terms from optimisation. A “strong” candidate is strong only under the fitness criteria supplied by the designer. The algorithm does not independently decide what society ought to value.

A fictional four-switch puzzle

Imagine a made-up device with four switches, each either off (0) or on (1). Your classroom challenge is to maximise the number of switches that are on.

A candidate can be written as a four-bit sequence such as 1100 or 0011. In this artificial puzzle, its fitness is simply the number of ones.

The candidates 1100 and 0011 both have fitness 2. The candidate 1111 has fitness 4, the best possible score under this deliberately simple objective.

Real design problems are more complex, but this toy example makes the search process easy to follow without software.

Step 1: Write down the real problem first

A genetic algorithm cannot optimise an undefined wish such as “make everything better.” The developer has to describe the decisions being made and the criteria for evaluating them.

For a fictional timetable, the decision variables might specify which timeslots are assigned to activities. The constraints could require no overlapping bookings and enough space for each group.

A timetable that scores well on convenience but violates a room-capacity limit is not an acceptable result. It should not be presented as valid simply because the optimiser likes its score.

Step 2: Represent each candidate correctly

Different problems need different kinds of encodings. A binary chromosome fits the four-switch puzzle, but a route-planning task might use a permutation of stops. A continuous engineering design may use real-valued numbers.

The DEAP evolutionary computation documentation demonstrates different forms of individuals, including vectors and permutations, and explains how fitness can be defined for minimisation or maximisation.

Encoding matters because mutation and crossover operate on that structure. Randomly mixing two routes as though they were ordinary strings may create a route that repeats one destination and omits another.

Step 3: Create an initial population

Instead of beginning with one guess, the algorithm constructs several candidate solutions. Some can be random within permitted constraints, while others may be produced through a suitable heuristic or other defined process.

In our four-switch puzzle, a tiny initial population could be 1000, 1100, 0011 and 0101. Their scores are 1, 2, 2 and 2.

Starting diversity can help a search explore different regions. A population containing twenty identical candidates cannot draw on much variation unless the method introduces it later.

Population size is a design choice. Larger populations involve more evaluations and are not automatically superior.

Step 4: Design an honest fitness function

The fitness function tells the algorithm what to prefer. For the four-switch puzzle, count the ones. This is easy to check and has an unambiguous maximum of four.

For a realistic engineering problem, the score could involve energy use, cost, performance or reliability under suitable constraints. Developers must decide how to measure these quantities consistently.

A dangerous mistake is rewarding the wrong proxy. If a fictional timetable fitness function rewards only the number of sessions packed into a day, the algorithm may produce an impossibly crowded schedule.

A better design includes valid constraints and evaluates consequences separately. Optimising a proxy perfectly does not establish that the underlying practical goal has been achieved.

Step 5: Select candidates without losing all diversity

Selection operators influence which individuals can contribute to the next generation. Some strategies favour candidates with higher fitness; others use tournament-style comparisons or additional diversity controls.

A selection procedure does not always keep only the single best candidate. Doing so can quickly remove variation and prevent exploration.

The DEAP operators tutorial covers selection, crossover, mutation and evaluation as configurable operations rather than one universal recipe.

A candidate with high fitness under one noisy evaluation should not be treated as unquestionably best in every situation. The fitness procedure itself needs reliability checks.

Step 6: See crossover in four bits

Suppose two parent candidates are 1100 and 0011. With a one-point crossover after the second bit, each child keeps the first two bits of one parent and the last two of the other.

One child becomes 1111, while the other becomes 0000. Their fitness scores are 4 and 0 under our toy rule.

This is an unusually simple example in which one child immediately reaches the maximum. It demonstrates the arithmetic of crossover, not a guarantee that crossover improves fitness in general.

In real optimisation, combining two valid designs can produce a worse design or violate constraints. The operator must be appropriate for the representation.

Step 7: Introduce mutation

Mutation modifies a candidate according to a chosen rule. For our binary puzzle, a mutation might flip one bit from 0 to 1 or from 1 to 0.

Starting from 1100, flipping the third bit gives 1110, increasing the toy fitness from 2 to 3. Flipping the first bit instead produces 0100, decreasing the score to 1.

Mutation therefore does not always improve an individual immediately. Its role is to introduce variation that may help the broader search explore solutions not present in the current population.

An excessively high mutation rate can disrupt useful structures; an extremely low rate may leave a population with too little new variation.

Step 8: Build the next generation

After variation, new candidates are evaluated. The algorithm then forms the next population under its chosen replacement rules.

Some strategies replace the old population with newly created offspring. Others select from both parents and offspring. Some deliberately preserve the best known candidate through elitism.

DEAP’s algorithms reference provides examples of these distinct generational strategies, including approaches that select from combined parent and offspring pools.

The general method should be reported clearly. Two programs both called “genetic algorithms” may make different choices about crossover probability, mutation probability, elitism and replacement.

Step 9: Why a generation is not a learning epoch

In neural-network training, an epoch often refers to processing a training dataset through a model. In evolutionary computation, a generation refers to producing and evaluating candidate solutions in a population.

These ideas involve repeated improvement, but their internal operations differ. Genetic algorithms are not simply neural-network gradient descent with biological names.

The representation, objective and computational budget determine which approach is suitable.

Step 10: What happens when a candidate violates a constraint?

Suppose a timetable candidate assigns two classes to the same small room at the same time. Even if its numerical preference score is high, it violates the space constraint.

An optimiser can handle this in several ways: construct only valid candidates, repair certain invalid candidates, apply penalties or use specialised constraint-handling techniques.

No penalty guarantees safe behaviour without an adequate model of the real restrictions. For consequential systems, validity checks should be independent of the optimiser’s preferred score.

A candidate failing a hard safety constraint should not become acceptable merely because it performs well on other objectives.

Step 11: Balancing more than one objective

Many real problems involve trade-offs. A vehicle design might seek lower weight and greater durability. An operations plan might seek lower cost while preserving service quality.

A single weighted fitness score is one approach, but weights encode choices about priorities. Different choices can produce different preferred solutions.

Multi-objective evolutionary algorithms can instead work with sets of trade-offs, including solutions on a Pareto frontier. A candidate is Pareto-dominated when another solution is at least as good in all considered objectives and better in at least one.

The output is not automatically one universally best option. Decision-makers still need to understand the objectives, constraints and consequences.

Step 12: Why diversity matters

Imagine a population of twenty candidates that all have nearly identical designs. Crossover among them may produce only minor variations.

A diverse population may cover more of the search space and have better chances of finding useful alternatives, depending on the problem. Genetic algorithms use mutation and different selection strategies partly to manage this trade-off.

But simply maximising diversity would also be a mistake if it prevented the method from retaining valuable solutions. Effective search balances exploration with selecting good candidates.

The goal is not just to create many variations. It is to discover useful, valid solutions under an honestly defined objective.

Step 13: Can a genetic algorithm guarantee the best solution?

Not generally. Stochastic evolutionary search does not usually prove that its final candidate is the global optimum.

The result may depend on the initial population, random choices, evaluation budget, crossover, mutation and problem structure. For some small, precisely defined problems, exhaustive search or exact mathematical optimisation may be preferable.

A developer should compare the genetic algorithm with sensible baselines and known optimal solutions when those are available. A fancy procedure does not automatically outperform a simple one.

Step 14: When should the algorithm stop?

A search may stop after a fixed number of generations, a maximum number of evaluations, a time or compute budget, or a period without meaningful improvement.

For our four-bit toy puzzle, reaching fitness 4 proves success because the maximum is known. For a complex real-world problem, reaching an apparently strong score may not establish that no better solution exists.

Stopping rules and resource use should be documented. If one method uses a thousand times more evaluations than another, comparing only the final fitness may be unfair.

Step 15: The danger of an unreliable simulator

Evolutionary optimisation often uses a function or simulation to evaluate candidate designs. If the simulator is inaccurate, the algorithm may discover solutions that exploit its weaknesses instead of working well in reality.

Suppose a fictional paper-airplane simulator rewards longer flight time but ignores structural stability. A generated design might perform brilliantly inside the simulator while failing when built.

The correct response is to validate the evaluation process, not to congratulate the algorithm for finding an extreme score. Independent real-world checks are essential when a result will be used physically.

Step 16: Genetic algorithms versus reinforcement learning

Reinforcement learning commonly involves an agent interacting with an environment and improving a decision policy from reward signals over sequences of actions.

Genetic algorithms usually operate on a population of candidate solutions, using evaluation, selection and variation to search the space. They do not necessarily require an agent to learn through step-by-step environmental interactions.

The two ideas can sometimes be combined, but they describe different optimisation workflows. The trial-and-reward guide explains reinforcement learning separately.

Step 17: Genetic algorithms versus gradient descent

Gradient descent uses gradient information about how a differentiable loss changes when parameters change. It can be efficient for neural-network weight optimisation when suitable gradients are available.

A genetic algorithm evaluates candidate solutions and uses variation operators rather than requiring the same form of derivative information. This can be useful in some combinatorial, discontinuous or simulation-based tasks.

But being derivative-free is not automatically an advantage: evaluating many candidate solutions can be computationally expensive. Choose methods by evidence, problem structure and available resources.

In genetic programming, an individual can represent a program, expression tree or other executable structure. Evolutionary operators modify those representations under a chosen fitness objective.

Ordinary genetic algorithms can use strings, vectors or permutations that encode candidate decisions. Genetic programming is a specialised family within the broader evolutionary-computation field.

DEAP supports both kinds of experimentation, but it is not accurate to say that every genetic algorithm automatically writes new software programs.

Step 19: Does evolutionary computation create consciousness?

No such conclusion follows from the mathematics. A candidate is a collection of values or a defined structure, and a fitness function produces an evaluation. Selection and mutation are algorithms, not conscious choice or biological reproduction.

“Survival,” “population” and “mutation” are useful analogies borrowed from biology. They should not be taken as evidence that the software is alive or independently understands the purpose for which it was built.

Scientific care means using those terms to explain the operators without inventing human or biological attributes.

Step 20: Where can evolutionary search be useful?

  • Timetabling research: explore feasible arrangements under explicit capacity and scheduling constraints.
  • Engineering design: study combinations of parameters using suitably validated simulations.
  • Routing and logistics: search candidate orderings under travel and operational constraints.
  • Hyperparameter search: explore settings for a machine-learning model, subject to fair validation.
  • Scientific optimisation: investigate multi-objective trade-offs where evaluation is appropriately defined.

These are possible research and engineering applications, not universal demonstrations of superiority. Results require domain expertise and independent tests.

Step 21: Measure performance honestly

For a small puzzle with a known optimum, record how often the algorithm reaches that optimum across several runs and how many evaluations it needed.

For larger problems, compare a sensible baseline, a random-search procedure and any available specialised solver under a comparable budget. Record variability rather than only the best outcome from one lucky run.

If a solution uses a trained predictive model to estimate fitness, account for uncertainty and the possibility that the optimiser exploits errors in that estimator.

Try it: crossover and mutate paper chromosomes

Draw two four-bit parents: 1100 and 0011. Cut each sequence after its second bit. Exchange the right-hand halves to get children 1111 and 0000.

Count the ones: the new fitness scores are 4 and 0. Now mutate one bit in either child and recalculate its score. Does the score always improve? No.

Repeat with a different cut point or different starting candidates. This exercise illustrates selection and variation, not a guaranteed production-ready optimisation strategy.

Five mistakes worth avoiding

  • “Evolutionary search always finds the global optimum.” A finite stochastic run usually has no such guarantee.
  • “Any high fitness score means a safe solution.” The objective can omit essential constraints.
  • “Every genetic algorithm uses binary strings.” Representations vary by task.
  • “Mutation always improves candidates.” Variation can increase or decrease fitness.
  • “Genetic algorithms and gradient descent are identical.” Their optimisation mechanisms differ.

Frequently asked questions

What is a genetic algorithm in AI?

It is a population-based optimisation method that evaluates candidate solutions and uses selection and variation operators to search for better ones.

What does fitness mean?

Fitness is a numerical assessment under the designer’s defined objective. It is not a universal judgement of real-world goodness.

What is crossover?

An operation that combines parts of two candidate representations to produce offspring, using a rule suited to the representation.

Why is mutation useful?

It introduces variation, which can help the search explore candidates not already present in the population.

Is a genetic algorithm better than a neural network?

They solve different aspects of different problems. Suitability depends on the objective, available gradients, data, evaluation cost and desired result.

Your one-minute takeaway

Genetic algorithms search through populations of candidate solutions, selecting, combining and mutating representations under an explicit fitness function. They can explore difficult optimisation spaces, but they do not guarantee the global optimum or correct a badly specified goal. Sound constraints, comparisons and independent validation are the gold standard.

Trusted reading and connected articles

Discover more from eduKate Singapore

Subscribe now to keep reading and get access to the full archive.

Continue reading