Skip to main content
Artificial Computational Intelligence

Genetic Algorithms, Ant Colony Optimization, and Neural Architecture Search

Published: 2026-08-13
Level: postgraduate
Audience: Postgraduate students in artificial intelligence and machine learning

Prerequisite Knowledge

This lecture builds on the following concepts from earlier lectures. If any feel unfamiliar, review the linked notes before proceeding.

Previously Covered in This Subject

  • Local search and the mindset change — state-as-solution thinking and fitness values versus heuristics — covered in Lecture 5
  • The 4-Queens problem: representation and fitness — the vector representation and conflict counting — covered in Lecture 5
  • Local beam search — K parallel states that cannot collaborate — covered in Lecture 5
  • Population-based methods: genetic algorithms and ant colony optimization — the introduction to both methods — covered in Lecture 5
  • Heuristic design in practice: the N-Queens problem — the same problem domain approached through heuristics — covered in Lecture 4

6.1 Genetic Algorithms: Foundations and Terminology

6.1.1 Where We Left Off: Local Search and Its Two Branches

Hook. What would happen if the candidate answers to a problem could talk to one another — pair up, swap ideas, and raise new answers together? Every technique in this module so far treated states as lonely workers. Genetic algorithms change that, and the change is the whole point of the topic.

This session opens exactly where the previous one ended. The whole module so far has been about local search — techniques where the state itself is an answer, and we try to improve that answer by making local changes and checking whether we get closer to something better. Nothing external scores the states against a far-away goal; every state is already a candidate solution, and the search walks from one candidate to a slightly changed neighbour.

Inside local search there are two broad categories:

  • Single-instance local search works with exactly one state at a time. The techniques studied there were hill climbing and local beam search along with their variations, and the plan was to stop there — no other single-instance methods.
  • Multiple-instance local search keeps several states alive at once. There are many such methods, and the course covers exactly two of them — the two topics of today: genetic algorithms and ant colony optimization.

The last discussion of the previous session was about beam search. In beam search, K random states start working in parallel. The important concluding point was that those K states cannot collaborate with each other — they work side by side, and if one of them finds the answer, it simply tells the others. The most striking feature of genetic algorithms is precisely the opposite: the individuals in a genetic algorithm can collaborate — they mate with each other, exchange genetic material, and produce offspring. That is the difference that makes genetic algorithms a new idea rather than just another beam-search variant.

Intuition. Think of single-instance search as one detective working a case alone. Beam search is several detectives on the same case who never compare notes: each works independently, and if one solves the case, everyone is told and the search ends. A genetic algorithm is different — the detectives literally merge their case files and create new detectives from the combined notes, then those new detectives work the case. The analogy breaks in one place: merging files does not change the files themselves. In a genetic algorithm the offspring is built from parts of both parents, and mutation later changes bits, so the new individual is genuinely new, not just a photocopy of two old ones.

Dimension Single-instance search (hill climbing) Beam search Genetic algorithms
Number of states One at a time K at a time A population at a time
Collaboration between states Not applicable None — states run in parallel and only share the final answer Full — individuals pair up and produce offspring
Where new states come from Small changes to one state Random neighbours of the K states Mixing parents' material plus mutation
Nature metaphor Hiker walking uphill K hikers on K hills, never speaking Couples raising children

The one-line version: if states can mate, the search stops being a collection of parallel attempts and becomes a population that evolves. That is the seed of today's first topic.

6.1.2 What Is a Genetic Algorithm?

A genetic algorithm (GA) is a search technique for optimization problems — the same job that hill climbing and beam search were doing. What changes is the inspiration: genetic algorithms belong to a family called bio-inspired (or nature-inspired) algorithms, and there is a well-known book collecting nature-inspired algorithms — a whole catalog of algorithms copied from nature, from ant colonies to fireflies. Among all those, genetic algorithms are the ones modeled on evolution — specifically human (and more generally animal) evolution.

The high-level flow should feel familiar at first: we pick a population, we calculate a fitness function — so far it is the same bookkeeping as before. The genuinely new part starts after the fitness calculation, and that is the heart of the algorithm. From here on, the algorithm is inspired by human evolution: we perform parent selection, we create children from those parents, and we give the children some traits (through mutation). If we still do not have a solution, we repeat the whole cycle. Those three steps — parent selection, child creation, trait-giving — are unique to genetic algorithms and do not appear in the earlier local-search methods.

A quick check against the earlier analogy: in previous classes, when we said "how good or bad is this state," we called that quality a heuristic value. In genetic algorithms the same idea gets a biological name — fitness — the healthiness of an individual. Same measurement, new vocabulary. From now on, the lecture reserves "heuristic" for the informed-search material and uses "fitness" inside genetic algorithms; the two words point at the same underlying number, but on the exam, "fitness" is the term attached to this topic.

A little history puts the method in place: the idea of a fitness landscape — a surface whose height at every point is how good that candidate is — goes back to Sewall Wright (1931), and genetic algorithms were championed as optimization tools by John Holland in the 1960s and 1970s. The biological model behind them is the one from the theory of evolution: in DNA, an organism is a string over the four-letter alphabet A, C, G, T; in a genetic algorithm, an individual is a string over the alphabet your problem defines — digits, bits, or rows of a board. Variation happens by point changes (mutation) and by combining long sections of two parents (crossover), and better individuals reproduce more often. That is the whole recipe, and the rest of this section just names its ingredients.

6.1.3 The Terminology of Genetic Algorithms

The vocabulary of genetic algorithms is a short list, and each term maps to something you already know:

  • Population — the collection of individuals, or equivalently the collection of states, being evolved at one time. The population is the multiple-instance part of the method: instead of one state, we carry a whole generation of states.
  • Fitness — a measure of how healthy an individual is; the analogue of the heuristic value from the earlier local-search lectures. Bigger fitness means a healthier (better) parent.
  • Selection — choosing the most biological parents for the next generation, the way nature (or a matchmaker) chooses who gets to reproduce.
  • Crossover — from a bunch of parents, creating new children by mixing their genetic material.
  • Mutation — changing some of the children afterwards, to give them unique traits that neither parent had.

These names all become concrete once we solve a complete example, but it is worth knowing the skeleton first. The standard description is a seven-step process. The first three steps are already familiar from every algorithm so far: (1) represent the problem in some state form, (2) generate the initial population, (3) apply the fitness function. The next three steps are peculiar to genetic algorithms: (4) parent selection, (5) successor generation through crossover, (6) mutation. Step 7 is the loop: check the stopping conditions, and either stop or go back to the fitness/selection steps.

As a flow:

(1) represent the problem → (2) generate initial population → (3) compute fitness
                                                                        ↓
    (7) check stopping criteria ← (6) mutation ← (5) crossover ← (4) parent selection
             ↓ yes
           STOP

Steps 1–3 are bookkeeping you already know. Steps 4–6 are where the biology enters, and step 7 is the loop that turns one generation into the next. Keep this skeleton in view for the whole lecture: the four-queens example in sections 6.2–6.5 walks it once, step by step.

6.1.4 The Three Stopping Criteria

A genetic algorithm needs a way to decide when to stop. There are exactly three stopping criteria, and at least one of them always fires eventually:

  1. The threshold fitness is reached. The threshold means the maximum achievable fitness for the problem — for the four queens problem that maximum is 6 (all six queen pairs non-attacking). If any individual reaches it, the problem is over and the algorithm stops.
  2. A predefined number of new states (or generations) is exhausted. We may say, "generate 10 new states and beyond that don't go; whatever you have there is the best — stop." In exams this is normally given to you explicitly.
  3. No change between successive iterations. If an iteration and the next iteration give exactly the same results (iteration N and iteration N+1 identical — or, say, N+3 and N+4 identical), nothing is improving, so stop.

Q: Can you repeat the third stopping criterion? If there are no changes in the iteration, do we stop? A: The third stopping criterion is about no change between iterations. If the parents and the children are the same, and you get the exact same results at the end of two iterations, you can stop. That's it.

Pitfalls.

  • Criterion 3 compares iterations with each other, not parents with children. A child that differs from its parent is normal and expected; what stops the search is two successive iterations producing identical outcome sets.
  • The threshold must be the true maximum fitness of the problem. For four queens, that is 6 because a 4×4 board has queen pairs and the maximum number of non-attacking pairs is all 6. If the maximum is not known in advance, criterion 2 or 3 must do the stopping work instead.
  • Do not invent a fourth criterion: the three listed here are the complete set. At least one of them always ends the algorithm eventually, because the generation count alone is guaranteed to run out.

Exam note: the three stopping criteria are core vocabulary. In exam questions you will normally be told exactly how many iterations to run — for example, "generate one iteration and stop." You rarely need to decide the stopping point yourself; the question fixes it for you.

Recap + bridge. A genetic algorithm is the multiple-instance local search method in which individuals collaborate: pick a population, score it with fitness, select parents, create children by crossover, mutate for unique traits, and loop until a stopping criterion fires. With the vocabulary fixed — population, fitness, selection, crossover, mutation, and the three stopping criteria — the next section runs the whole machine on a concrete problem: the four queens puzzle, where fitness becomes a real number and the loop becomes arithmetic.

Real-world connection. Genetic algorithms are the workhorses of nature-inspired optimization. In industry they appear wherever the search space is structured but too large for exhaustive search: circuit layout, job-shop scheduling, and — closer to this course — automatically evolving the architecture of deep neural networks, which is exactly the neural architecture search topic at the end of this lecture. The catalogue of nature-inspired algorithms that the lecture mentions collects dozens of such methods, from ant colonies to bee colonies, and the genetic algorithm is the evolution-shaped member of that family.

6.2 Genetic Algorithms: The Four Queens Problem — Setup, Fitness, and Probabilities

6.2.1 Setting Up K Random Board Configurations

Hook. The four queens problem has possible boards (each of the 4 columns holds a queen in one of 4 rows), yet only 2 of them are solutions. A genetic algorithm will hunt through this space without ever listing all 256 boards — it starts from a handful of random ones and lets them mate. Can a random handful of boards evolve into a solution?

The running example is the four queens problem: place four queens on a 4×4 board so that no queen threatens another. The first step of the genetic algorithm is to select K random states. In this problem K is given as 4, so we create four different board configurations.

Each configuration is represented as a vector of four numbers, exactly as in the previous session. The meaning of the vector 1 4 2 2: the first number says the queen in column 1 sits in row 1, the second number says the queen in column 2 sits in row 4, the third says the queen in column 3 sits in row 2, and the fourth says the queen in column 4 sits in row 2. In general, position i of the vector is the row of the queen in column i.

The four boards are named B1, B2, B3, B4. From the narration: B1 = 1422, B3 = 1432, B4 = 2141. B2's exact vector is garbled in the audio; what the lecture states cleanly is B2's fitness — 4 non-attacking pairs — so any reconstruction of B2 must be a vector whose six pairs contain exactly two threatening pairs. One consistent choice, for example, is 1324, which places queens at (1,1), (2,3), (3,2), (4,4): the pairs Q1–Q4 and Q2–Q3 attack diagonally, and the other four pairs do not, giving non-attacking pairs. Since every downstream step uses only B2's fitness (4), this ambiguity never changes the rest of the computation.

A key difference from hill climbing: these four boards are random and independent. In hill climbing we took one state and produced neighbors by making small changes to it. Here, when K = 4 is given, the four configurations are generated from scratch and have nothing to do with each other — they are not neighbors of anything.

6.2.2 The Fitness Function and the Threshold

The next step is to compute the fitness value for each board. First we must fix the fitness function. Two natural choices exist for this problem: the number of attacking queen pairs, or the number of non-attacking queen pairs. The example uses the usual choice — the number of non-attacking pairs. Note what this choice does to the direction of the search: bigger fitness means a better board, and the best possible board scores the maximum.

The computation is exactly what we practiced last session: enumerate all pairings of the four queens. With queens Q1, Q2, Q3, Q4 there are six pairs — Q1Q2, Q1Q3, Q1Q4, Q2Q3, Q2Q4, Q3Q4 — and for each pair we check whether it is conflicting (same row, same column, or same diagonal) or non-conflicting. Two queens conflict exactly when they share a row, a column, or a diagonal; with one queen per column, the column check is already satisfied by the representation, so only rows and diagonals remain.

Working one board in full — B1 = 1422. The vector places queens at (1,1), (2,4), (3,2), (4,2). Pairwise:

  • Q1(1,1) and Q2(2,4): different rows, and , would be an attack — but the differences here are 3 and 1, so no attack.
  • Q1 and Q3(3,2): rows 1 and 2 differ, diagonals do not line up — no attack.
  • Q1 and Q4(4,2): rows 1 and 2 — no attack.
  • Q2(2,4) and Q3(3,2): rows 4 and 2, columns 2 and 3 — no attack.
  • Q2 and Q4(4,2): two rows and two columns apart — same diagonal, so they attack.
  • Q3 and Q4 sit in the same row 2, so they attack.

That is 2 attacking pairs, so non-attacking pairs — fitness of B1 is 4.

For B3 = 1432, queens at (1,1), (2,4), (3,3), (4,2): Q1–Q3 attack diagonally, Q2–Q3 attack diagonally, Q2–Q4 attack diagonally, and Q3–Q4 attack diagonally — 4 attacking pairs, so the fitness is . For B4 = 2141, queens at (1,2), (2,1), (3,4), (4,1): Q1–Q2 attack diagonally, Q1–Q3 attack diagonally, and Q2–Q4 share row 1 — 3 attacking pairs, so the fitness is .

The four fitness values are:

  • B1 = 1422 → fitness 4
  • B2 → fitness 4 (vector unreadable in the audio, fitness given)
  • B3 = 1432 → fitness 2
  • B4 = 2141 → fitness 3

The threshold fitness — the maximum attainable value — is 6, which would mean all six pairs are non-attacking. None of the four boards reaches 6, so we do not stop; we proceed into the genetic algorithm proper.

6.2.3 From Fitness to Probability

Before selection, each individual's fitness is converted into a selection probability: each board's probability equals its fitness divided by the total fitness.

where is the fitness of board and the sum runs over all boards in the population. The denominator is just the total fitness of the whole population — one number — and the numerator is that one board's fitness. Because every numerator is a fitness (a count of non-attacking pairs, always ) and the denominator is the sum of all of them, every lands in and the four probabilities add up to 1: this is a genuine probability distribution over the population, which is exactly what the roulette wheel in the next section needs.

The total fitness is . So:

As percentages those are 31%, 31%, 15%, and 23% (for example ). This is why the pie (a ring, really) has two fat 31% slices, a 23% slice, and a thin 15% slice: a larger fitness value means a larger chunk of the pie, and a larger chunk means a larger chance of being selected when the wheel stops. The probability computation needs nothing beyond the fitness values — the 13 is simply the sum of all fitness values, and each numerator is that one board's fitness.

Assumptions and scope. The fitness-proportionate scheme works because fitnesses are counts on the same scale — every board's score is a number between 0 and 6, so a score of 4 really is twice as good as a score of 2, and twice the probability. This proportionality breaks if the fitness function is changed (say, to the number of attacking pairs): then a better board has a smaller fitness, the pie shrinks for good boards, and the selection step would favour the worst individuals. Always confirm the direction of your fitness function before converting to probabilities. The probabilities also assume the population stays fixed during the step: selection happens before crossover, so the four slices are the same for every spin.

Pitfalls.

  • Confusing attacking with non-attacking: the fitness used here is the count of non-attacking pairs, so each threatening pair reduces the score. Counting the other way gives 2, 2, 4, 3 and inverts the ranking.
  • Forgetting the pair count: a 4-queen board always has exactly pairs, so fitness = 6 − (attacking pairs). The threshold 6 is that pair count, not a guessed number.
  • Using B2's unreadable vector to redo the arithmetic: B2's vector was not announced, but its fitness (4) was, and only the fitness enters the probabilities.

So far, only two steps of the genetic algorithm have happened: generate K random states (four independent boards) and compute their fitness values — plus the derived probabilities. All familiar material. From here, the three steps that are unique to genetic algorithms begin.

Recap + bridge. Four independent random boards, each scored by counting non-attacking queen pairs out of six, give fitnesses 4, 4, 2, 3 and selection probabilities 4/13, 4/13, 2/13, 3/13. The threshold 6 was not reached, so the search continues — and now the biology starts: step four of the process turns those probabilities into actual couples on a roulette wheel.

Real-world connection. This fitness-to-probability conversion is the same idea a cricket selector or a hiring committee uses under the hood: the better the score, the more chances to reproduce — but nobody is guaranteed a spot. In industry terms, fitness-proportionate selection is the standard first step of every evolutionary optimization package, from scheduling solvers to automated machine-learning pipelines, and getting the fitness function's direction right is the classic first bug in real genetic-algorithm projects.

6.3 Genetic Algorithms: Parent Selection with the Roulette Wheel

6.3.1 The Roulette Wheel Method

Hook. Four boards, four probabilities — but only two couples get to reproduce. Who pairs up with whom? If we always picked the two best, the search would be a boring contest between the same two candidates. The lecture's answer is the same device casinos use: put the candidates on a spinning wheel and let luck decide, with the better boards getting bigger slices.

Step four of the process is parent selection: from the four board configurations, choose a few individuals who will become parents of the next generation. The biological analogy is matchmaking — in the human world, someone (parents, matchmaking platforms) picks who forms a couple. Here we must decide which boards pair up.

Several parent-selection methods exist — tournament, ranking, and others — but this course always uses the roulette wheel (also called the fitness-proportionate wheel). The description: the population is divided on a wheel according to each individual's percentage of the total fitness, and fixed point(s) are placed on the wheel — you can use two fixed points, but the example uses just one, a blue arrow. The wheel is spun, and the individual at which the fixed point points when the wheel stops is selected. It is exactly the gambling-wheel mechanism you see in casinos and fun arenas.

Method How a parent is chosen Fairness Used in this course
Roulette wheel Slice size = fitness share; spin decides Every individual gets a chance, better ones more often Yes — the exam method
Tournament Pick a random handful, keep the fittest of the handful Favours strong individuals directly No
Ranking Order individuals, choose by rank rather than raw fitness Softens huge fitness gaps No

The wheel is spun multiple times. The first spin gives the first parent; the second spin gives the second parent, and those two form the first couple. If the same individual wins twice, that second result is ignored (we do not eliminate anyone — more on this below) and the wheel is spun again until a different individual comes up, because a couple must contain two distinct parents. Whether a repeated result forces a re-run depends on whether the repeats block the required couples — see the example.

Exam note: for this course, the roulette wheel is the selection method — it will be used in exams and in all problems here. Other methods (tournament, ranking) exist but are not the ones practiced.

6.3.2 Running the Wheel in the Example

The wheel carries the four probabilities computed earlier: 31% for B1, 31% for B2, 15% for B3, 23% for B4. Picture the wheel: a ring cut into four slices — two fat 31% slices side by side for B1 and B2, a 23% slice for B4, and a thin 15% slice for B3 — with a single blue arrow fixed at the top. When the wheel stops, the slice under the arrow names the selected parent. A 31% slice lands under the arrow roughly twice as often as the 15% slice, but every slice can win.

Tracing the four spins. The wheel was spun four times, because the problem asks for two couples, and two couples need four parents. The four runs produced:

  1. Run 1 → B4 — B4 came to the fixed point as the winner
  2. Run 2 → B1
  3. Run 3 → B1 (again)
  4. Run 4 → B3

These results are purely random — pure luck. Any other combination (B4, B2, B1, B3, or B4, B2, B2, B3, or anything else) would have been equally acceptable. From these four runs, the couples are formed in order: (B4, B1) as couple one, and (B1, B3) as couple two. Sense-check: four parents are needed for two couples, the winners include B1 twice (allowed — it appears in two different couples), and B2 misses out purely by luck.

Two validity rules must hold. First, the couples themselves must be distinct — you may not have couple (B4, B1) and couple (B1, B4), which is the same pair of individuals again. Second, within a couple the two parents must be distinct — (B1, B1) is not a couple. In this example both rules held: B1 appears in two different couples, which is fine — B1 got lucky, appearing twice — because each couple is a different pair and, as the joke goes, while the judicial system may not allow it, genetic algorithms allow one individual to pair with multiple partners at different times.

What about run 3 giving B1 again? It was not discarded, because the fourth run then produced B3, so both couples could still be formed. But consider what would have happened if run 4 had again produced B4: then the couples would be (B4, B1) and (B1, B4) — the same couple twice — and that is not allowed, so we would have re-run the wheel. The general rule: if you cannot form the required number of distinct couples with distinct members, you re-run the wheel. This is why the number of runs cannot be fixed in advance — repeated outcomes may force extra spins.

And B2? Sad about B2 — in this example B2 never got a chance to be in a relationship; it was never selected. That is simply how the luck fell.

6.3.3 Student Questions and Answers

Q: When a parent is selected twice, do we eliminate it? And do we need to check the frequency of fitness to calculate the probability here? What happens if the wheel stops at the same individual again — can we fix the number of runs in advance? A: We do not eliminate. If the same individual comes up again, we ignore that run and spin the wheel again. There is no need to check the frequency of fitness when calculating the selection probability — the probability only uses the fitness value: 4/13 for a board whose fitness is 4, with 13 being the sum of all fitness values. And the number of runs cannot be decided in advance, because if the same individual keeps coming up, you cannot form the required distinct couples — so you re-run until you can. Several students asked about repeated outcomes; the rule in every case is the same: ignore the repeat, spin again.

Q: If one parent is selected, can't we redistribute the percentages among the remaining individuals? A: No, we should not do that. If you got married once, that does not mean you are out of the market — you can get a divorce and get remarried. A selected parent stays in the pool, so selection works with replacement: we will not redistribute the wheel percentages after a parent is selected, and we will not drop the selected parent out of the game. In animal evolution too, there is no rule that only one couple may form; individuals can have multiple partners.

Q: Why can't we simply select the two highest probabilities as parents? A: Because in reality, it is not always two smart people who get together. The roulette wheel gives every individual a fair chance — no prejudice toward the 31% slices. They are all in the boat, and based on luck, anyone can be selected. Tournament and ranking are other ways, but the roulette wheel is the fair game, and it is the one we use.

Q: How do we decide the number of parents — is it 50% of the population? A: The number of parents will be told to you in the question. In the real world, you decide yourself, based on how much computation power you have. And yes — in this problem two couples were requested, so four parents were needed, and four runs were made.

Q: Why don't we just take parents randomly? A: That is exactly what we are doing. The wheel is the random selection mechanism — we put the individuals on it with slices proportional to fitness, spin it, and wherever it stops, that is the parent.

Q: B2 never got selected — and is it true that both the couples and the parents inside them must be distinct? A: Yes, in this example B2 never got to be in a relationship; that is just luck. And both conditions must hold: the couple itself should be distinct — it should not be (B4, B1) twice — and within each couple, the two parents must be distinct, so (B1, B1) is not allowed.

Recap + bridge. Parent selection turns the fitness probabilities into real couples: spin a fitness-proportionate wheel, ignore repeated picks, re-run only when distinct couples cannot form, and keep every individual available for multiple pairings. The couples are now fixed — (B4, B1) and (B1, B3) — and the next step of the algorithm decides what those couples produce: crossover.

Real-world connection. Fitness-proportionate selection is the step that keeps diversity alive in evolutionary software: a genuinely new (but currently mediocre) design keeps a real chance of reproducing, which is how these methods escape the traps that greedy selection falls into. Real-world genetic-algorithm libraries implement exactly this wheel — the same arithmetic of slice sizes and random spins — for problems from antenna design to factory scheduling, and the "keep everyone eligible" rule is what the lecture's marriage joke encodes.

6.4 Genetic Algorithms: Crossover — Generating Children

6.4.1 What Crossover Does

Hook. The couples are chosen — (B4, B1) and (B1, B3). Now the search asks the biological question: what do the children look like? A child is a byproduct of its parents, its DNA inheriting traits from both — and in a genetic algorithm, "inheriting" is a precise operation on the digit strings themselves.

Once the parents (the couples) are selected, the next step is successor generation — creating children. In biological terms: children are a byproduct of parents; their DNA inherits traits from both parents. That is what crossover does — it mixes the genetic material of the two parents to form the next generation's individuals.

Two things are fixed by the problem, not by the algorithm: how many couples to form, and how many children each couple produces. There is no limit on children per couple — bio-inspired again: one couple may have one child, another two, and so on, and the question tells you how many children to generate in every iteration. In this example, four children are required in every iteration.

There are three crossover techniques: single-point crossover, multi-point (two-point) crossover, and uniform crossover. They differ only in how the parents' strings get cut and swapped; the number of children each operation produces follows from the technique, as we see next.

6.4.2 Single-Point Crossover

Single-point crossover is the simplest technique. Take the two parents' strings (bits, or in our problem the numbers of a vector — whatever you imagine the DNA to be). Pick any one position in the string and draw a line there. From that point onwards, the two tails are swapped: the first part comes from one parent and the second part from the other.

The in-class illustration used arbitrary strings unrelated to the queens problem — just a DNA-like example. Parent one was read as 4 3 2 1 0 5 7 8 and parent two as 1 2 3 4 5 1 2 3. The line was drawn after the sixth position, and swapping the tails gave:

- child one: 4 3 2 1 0 5 2 3 → 43210523
- child two: 1 2 3 4 5 1 7 8 → 12345178

A quick consistency check justifies the reconstruction: child one's tail (2 3) can only come from parent two's tail, and child two's tail (7 8) can only come from parent one's tail, so the parents are exactly 43210578 and 12345123 — the strings the slide shows. The line could be drawn after the first position, after the fourth, after the seventh — anywhere; wherever it is drawn, the children change accordingly.

One consequence of single-point crossover: one crossover operation always produces two children. If the question asks for four children, apply single-point crossover twice at two different positions and you get four; if you need three, apply it twice and ignore one child.

6.4.3 Two-Point Crossover

Two-point crossover draws two lines, splitting each parent into three segments — call them X, Y, Z (X1 Y1 Z1 for parent one, X2 Y2 Z2 for parent two). The middle segment is swapped: one child is X1 Y2 Z1 and the other is X2 Y1 Z2. In the illustration, X1 and Z1 came from parent one, and the middle Y2 came from parent two — and symmetrically for the second child. The lines can be placed anywhere.

The number of distinct children is fixed by the segment combinations — X1 Y1 Z2, X1 Y2 Z1, X2 Y1 Z2, X2 Y2 Z1, and so on — and you pick as many as the question asks. For multi-point crossover the count is not unbounded; it is this fixed set of combinations. The important limit to notice: two lines create at most a small handful of recombined strings, not an endless supply.

6.4.4 Uniform Crossover

Uniform crossover chooses random subsets of bits and swaps only those. In the illustration, two parents of bits (strings like 1 0 1 0 0 0 1 1 1 0) were shown, with some bits marked (underlined) as "kept as is" — one child kept those bits from parent one and took everything else from parent two, and the second child did the mirror image.

The percentage version is important for exams. When a question says "perform uniform crossover with 50%", it means: out of the bits, change 50%. For an 8-bit string like 1 0 0 1 0 0 1 0, you can take half from one parent and half from the other and merge them — or you can take every alternate bit from each parent, which is also 50%. If a percentage like 25% or 75% is given, that many bits are swapped. Uniform crossover resembles multi-point crossover, but the percentage logic (swap a stated fraction of the bits) is the distinguishing feature.

6.4.5 Crossover in the Four Queens Problem

Back to the queens: the two couples are (B4, B1) and (B1, B3), and the problem asks for four children in every iteration — two from each couple.

Couple one — (B4, B1): single-point crossover after the first position. B4 = 2141 and B1 = 1422. Writing each as a head and a tail:

- B4 = 2 1 4 1
- B1 = 1 4 2 2

Swapping the tails gives child one = 2 | 4 2 2 = 2422 and child two = 1 | 1 4 1 = 1141. Notice the inheritance explicitly: in 2422, the leading 2 came from B4 and the 422 came from B1. Sense-check: every digit of 2422 is a digit of B4 or B1 — nothing new appeared, exactly what crossover is supposed to do.

Couple two — (B1, B3): two-point crossover. B1 = 1422 and B3 = 1432. The narration keeps the outer bits as they are and swaps the inner parts: the kept bits are 1, 2 from one side and 1, 2 from the other, and the swapped pieces are 42 and 43. Writing both parents as three segments: B1 = 1 | 42 | 2 and B3 = 1 | 43 | 2. Swapping the middle segments gives child one = 1 | 43 | 2 = 1432 and child two = 1 | 42 | 2 = 1422 — the children are C3 = 1432 and C4 = 1422. Because the two parents differ only in the middle segment, the two-point swap reproduces the parent strings themselves; that is a special case of the technique, not a mistake — the mutation step next in the algorithm is what finally changes these children.

At this point every child is still just a combination of its parents' genes — C1 = 2422 has nothing that was not in B4 or B1. Even if a child's configuration looks new, the individual bits all come from one parent or the other. In the real world that is not the whole story — both parents may lack a skill the child has — and that extra something arrives in the next step, mutation.

6.4.6 Student Questions and Answers

Q: How do we know in real situations how many children we want? A: In the question it will be given: how many children to generate in each iteration. In real life, that is an internal matter — and, as you know, some governments even put enforcements on it — but in this technique, the number of children per iteration is told to us.

Q: Isn't uniform crossover similar to multi-point crossover? A: Yes, it is similar. But in uniform crossover you can also split the bits into half and swap, or a percentage will be told to you — perform 25% or 75% — and that many bits you swap.

Q: Please repeat one-point crossover once more. A: It is the simplest technique. Take parent one with bits such as 4 3 2 1 0 5 7 8 and parent two with 1 2 3 4 5 1 2 3. Pick any position — after the sixth bit, for example — and draw a line there. Swap the tails: child one is 4 3 2 1 0 5 2 3 and child two is 1 2 3 4 5 1 7 8. Wherever you draw the line, the children change.

Q: Does crossover give offspring which is the goal state? A: No, not the goal state. We are just generating children. Whether the goal is reached is checked later, by the fitness function.

Q: Will there be only an even number of children in a single crossover? A: Correct — one crossover gives two children. But if the question tells you to generate an odd number, you can ignore one of the children.

Q: What is the maximum number of offspring in a multi-point crossover? A: It is fixed by the segment combinations. With segments X1 Y1 Z1 and X2 Y2 Z2, you combine them in a fixed number of ways — X1 Y2 Z1, X2 Y1 Z2, X1 Y1 Z2, X2 Y1 Z1, and so on — and you pick as many children as the question requires.

Q: In the first crossover, how did the 422 come about — can we change the order of the genes? A: The 422 is simply the tail of B1 carried over after the cross point — the order of the genes is not changed; the split point alone decides which tail goes where. Your idea of reordering genes is noted — we discussed it in the break, because with two-point crossover only certain combinations are valid.

Exam note: a past mid-semester question asked for single-point crossover to generate two children from given parents, and a very similar question appeared in a recent webinar session. Practise drawing the line, swapping tails, and writing both children; the technique never changes the order of the genes.

Recap + bridge. Crossover mixes the two parents' strings into children — one line for single-point (two children, tails swapped), two lines for two-point (middle segment swapped, a fixed set of combinations), random subsets for uniform (swap a stated percentage of bits). The four children C1 = 2422, C2 = 1141, C3 = 1432, C4 = 1422 are pure combinations of their parents' genes — and that is precisely why the algorithm needs its sixth step, mutation, to give each child something neither parent had.

Real-world connection. Crossover is the recombination operator that real evolutionary systems — from genetic algorithms scheduling airline crews to genetic programming growing software functions — rely on to combine good building blocks found in different individuals. The lecture's DNA analogy is not decorative: the reason crossover works at all is the same reason sexual reproduction works — if a partial design is useful on its own (like the first three queens in safe positions), combining it with another useful partial design can inherit both advantages, a property that holds only when the string's parts mean something individually.

6.5 Genetic Algorithms: Mutation and the Complete Iteration

6.5.1 What Mutation Does

Hook. Every child so far — 2422, 1141, 1432, 1422 — is a pure mixture of its parents' digits. What if every child in every iteration were a pure mixture? Then the population could never produce anything the initial boards did not already contain. Step six of the process fixes exactly that: mutation, the gene change that gives each child something neither parent had.

Step six is mutation — a gene change. Children produced by crossover are only combinations of their parents: C1 = 2422, for instance, is just B4's 2 glued to B1's 422. We want the children to have unique traits, and mutation provides them. In the real world this is the "both parents lack a skill, but the child has it" phenomenon — the DNA of a child is a combination of the two parents, but not only a combination; some changes happen.

The mechanics are simple and fully random. For each child, pick one bit — any bit, your choice — and change it to any allowed value except the current one. In the queens problem a position can only hold 1, 2, 3, or 4, so if the chosen bit is 2, it may become 1, 3, or 4; if it is 1, it may become 2, 3, or 4; and so on.

How many bits should change? The preference is one bit — or at most two. If you change all four bits, the child becomes completely different from its parents; that also happens in the real world, so it is not a hard-and-fast rule, but usually we change one or two bits so that the child is still recognizably a child of its parents while carrying its own unique qualities. Different authors prefer different conventions, but one-bit mutation is the standard practice.

Pitfalls.

  • Changing every bit: the child becomes unrecognizable as a child of its parents. One bit, at most two, keeps the child both similar and unique.
  • Forgetting the allowed values: in the queens problem the new value must be in {1, 2, 3, 4} and must differ from the old one — changing a 2 to a 2 is not a mutation.
  • Assuming mutation improves the child: it is a random change, so it can just as easily damage a good board. Improvement is hoped for, never guaranteed — the algorithm compares fitness values at the end of the iteration, not during mutation.

6.5.2 Mutation in the Example

The four children after crossover were C1 = 2422, C2 = 1141, C3 = 1432, C4 = 1422. One bit is picked per child — again at random — and changed:

  • C1 = 2422: the chosen bit is a 2. The board already contains 2s and a 4, so to bring in new flavor the 2 is changed to 1 (picking 3 would also have been fine) → C1' = 1422. Since 2422 and 1422 differ in exactly one position — the leading 2 became 1 — the mutated bit is the first position.
  • C2 = 1141: the chosen bit is a 1, so it may become 2, 3, or 4. The chosen value is 3, so a 3 replaces one of the three 1s. The lecture does not announce which position changed; the valid outcomes are 3141, 1341, and 1143, and any of them is a correct mutation. The trace below uses 3141 as one valid instance.
  • C3 = 1432: the chosen bit is the 3, which may become 1, 2, or 4. The chosen value is 2 → C3' = 1422.
  • C4 = 1422: the chosen bit is a 2, which may become 1, 3, or 4. The chosen value is 3 → C4' = 1432.

Mutating the four children. One bit per child, changed at random to an allowed value:

Child After crossover Mutation After mutation
C1 2422 first bit 2 → 1 C1' = 1422
C2 1141 one of the 1s → 3 (e.g. first) C2' = 3141
C3 1432 the 3 → 2 C3' = 1422
C4 1422 one 2 → 3 C4' = 1432

Sense-check: every child differs from its predecessor in exactly one position, and every new value is a legal row number (1–4) different from the old one — the definition of a one-bit mutation.

Whatever we get here is the ultimate child — the individual that moves on. The vectors are then translated back into board configurations using the same rule as before (a 2 means the queen sits in row 2 of that column, and so on), and the first iteration of the genetic algorithm is complete.

6.5.3 Completing One Iteration — and Then the Loop

"First iteration" means: compute the fitness value for each child. The method is the same pair-enumeration as before — six pairs per board, count the non-attacking ones. For C1' = 1422 the computation works out as before: two attacking pairs (Q2–Q4 diagonally, Q3–Q4 in the same row), fitness 4. Two of the other children repeat boards whose fitness we already found in section 6.2.2 — 1422 scored 4 and 1432 scored 2 — so only C2' is genuinely new; its fitness follows from the same six-pair count, and computing it is the practice the lecture gives you. If any child's fitness is 6 — the threshold — that child is the answer and the algorithm stops.

If nobody reaches 6, the loop continues, and this is the most interesting part of the algorithm: every parent was once a child. The children become the parents of the next generation: compute their probabilities, put them on the roulette wheel, select couples, perform crossover, perform mutation, and repeat. At each new iteration you compare generations: if the fitness values of one iteration and the next are exactly the same as a set, nothing has improved and the algorithm stops (stopping criterion 3); if there is a change, continue. If a fixed iteration count was given (say, 5 iterations), stop there even without the optimum.

A side note on versions: in the vanilla (original) version, no states are saved — the algorithm simply stops with the last child. In coding, it is technically possible to retain the final vector and fitness value of every generation, loop through them, and return the maximum — that is a valid implementation choice, but the original algorithm as taught does not do it.

Exam note: exams will typically ask you to generate one iteration of the genetic algorithm and stop — you do not need to iterate to convergence. And the initial boards will not be given to you; you choose them randomly, while the number to start with (here, K = 4) is given.

6.5.4 Student Questions and Answers

Q: Should we change only one bit in mutation? A: It is preferred to change one bit. If you change all four bits, the child becomes completely different from its parents — that also happens in the real world, so it is not a hard rule. But usually we change one bit or two bits, not more, so the child is still a child of its parents yet carries unique qualities.

Q: Do we have any control over the number of iterations? Is there a possibility that the algorithm never stops? A: You keep going until a stopping condition fires. In some cases it will be told: do five iterations, and if you don't get the optimal value, stop there. And no, the algorithm cannot run forever — there is that counter we described: how many generations to generate, or how many new states. That clause will satisfy at some point; even if you don't get an answer — or even if the previous and next generations are not the same — that clause fires, and you stop.

Q: Is the change in a bit during mutation also random? A: Yes, that is also random — whichever bit you pick, and whatever value you put there. In the human world it is the same: you cannot question why the DNA changed only in that position, or how it got changed.

Q: What if the fitness becomes worse in the children? A: It happens. A lot of people believe later generations are more dumb than the previous generations — it is not empirically proven, but in these cases it can happen; the fitness may go worse. So we compare the fitness of parents with the fitness of children.

Q: The roulette wheel is for crossover, and the strategies are for...? A: The roulette wheel is for parent selection. Crossover is where we looked at the strategies — single-point, multi-point, and so on. Gene manipulation is just that bit manipulation: which bit to manipulate is your choice, and you put a value there.

Q: Will the order be considered when change is checked between parents and children? A: No — we will not check parent against child at all. We only check the fitness values: four fitness values from iteration one, four from the next iteration. If the sets are exactly the same, nothing is better, so we stop; if something improved, we continue — because if there is a five in the new set, a promising couple might lead to the global optimum.

Q: Why can't we simply change the bits in mutation and skip selection and crossover? A: Because the algorithm is bio-inspired. Compare it to the human analogy: first parent selection must happen, then crossover — that particular step of mating — then mutation, the gene changes, and then the children are born. You cannot skip the earlier steps.

Q: Don't all these algorithms seem computationally expensive? A: Absolutely right. That is why people across the globe say AI is harmful — we create such complex algorithms and run them, and computationally expensive algorithms are not so sustainable.

Q: Will the initial board be given in the exam, or who selects it? A: In genetic algorithms, you choose only the very first random configuration — it will not be given to you in the question. But how many to start with will be told: in this case, 4 was given, so you chose 4 boards randomly.

Q: Can we manipulate the gene to match it with the parents, so the process stops? A: No — if you match it with the parent, there is no point doing the gene manipulation. Your grandchild and your grandfather would be exactly the same. We want every generation to have its own unique traits; that is why we do this. Don't think from the exam point of view — an exam will only ask one iteration — but in the real world you would be serving no purpose.

Q: Once a child is formed, can't we adjust one bit to create more children? A: No — you will have to again perform the crossover strategy, and then the mutation. Compare it to the real world: when a first child is born for a couple, you don't change that child's trait to create the second child. A new process happens fully again, with new DNA where that one bit was changed.

Q: Is there a scenario where the optimum value is never reached? A: Absolutely possible — you keep generating, and it may go worse, as someone just said. This whole class of algorithms is local search; it never guarantees that it will give you the global optimum. In that iteration, whatever is possible, it will try to give you.

Q: Initial configuration, parent selection, crossover, mutation — all these steps are random. How is this moving us closer to the solution? And what is the final objective if there is no optimum solution? A: It is not moving us closer to the solution — that is not guaranteed, and this is where the misconception lies. Go back to the definition: we are in local search, where every state is a solution. Don't hold the global optimum in your mind as "the solution." Every board configuration, every child, is an answer to this problem. Every iteration, you hope that the successor generation will be the most brilliant — but you might get it or you might not; human evolution continues anyway. Genetic algorithms never promise the global optimum, but every child you generate is a valid solution.

Q: Suppose an iteration got close to the optimal, but due to crossover we lose the optimal configuration — should we retain the close-to-optimal one? A: No, you can't. Again the real-world analogy: one generation was smarter, and the next generations became dumber — you can't do anything about that last generation. We are learning the vanilla version, which does not save all these states. In coding, you could retain the final vector and fitness value of every generation, loop through them, and output the maximum — technically possible — but the original algorithm stops with the last child.

Q: How do we track that all possible configurations are taken into consideration? A: We don't. We do not take all possible mutations or all possible crossovers into account — it is like human evolution: the child is as it is, and you can't go back and keep having children. If you tried to consider everything, you would get the solution in one iteration itself — and then it would not be a local search.

Q: Any real-world example where we can apply this algorithm? Will you be taking the equation solution in class? A: Yes — solving linear equations using genetic algorithms is a real example: that was a mid-semester question a few years back, and some of you have that as your assignment. The steps are the same everywhere: randomly initialize, compute fitness values, compute probabilities, then perform the three steps — parent selection, child generation, mutation. You might not get the answer in the first two iterations; that's okay. And the uploaded answer for the equation will be self-explanatory — it is just the same three steps, selection, crossover, mutation; the solution may need several iterations.

6.5.5 Applications and Exam Notes

Genetic algorithms are used for creative tasks and planning problems, among other things. There is also an online/offline distinction worth knowing: are you doing the computation during runtime (online) or are you precomputing and keeping the results (offline)? Both styles exist; the earlier example in this course was patent databases — precompute and keep, reuse later.

Real-world: the framing here is that genetic algorithms give you a "good enough" answer, not a promise of the best one. A student example that was confirmed in class: a traffic management system cannot afford to wait for the most optimized solution in real time — by the time it is computed, it becomes obsolete; the model has to act, so we look at a good solution, and that is exactly what this class of algorithms provides.

Real-world: the sustainability angle — these algorithms are computationally expensive, and that connects to the global debate about whether AI is harmful, since running such complex algorithms is not sustainable in the long run.

Exam note: solving a linear equation with a genetic algorithm has appeared before as a mid-semester question; the uploaded solution shows that it is the same flow — random initialization, fitness, probabilities, selection, crossover, mutation — just applied to equation variables A, B, C and so on. In the equation setting, the "fitness" of a candidate assignment is how well it satisfies the equation, and the search iterates until one assignment satisfies it or the iteration cap is reached.

Recap + bridge. One complete iteration of the genetic algorithm is: random boards → fitness → probabilities → roulette parent selection → crossover → mutation → fitness of the children → check the stopping criteria (threshold 6, generation cap, or identical successive iterations). If none fires, the children become the next iteration's parents, and the loop repeats. With the whole loop visible — selection, crossover, mutation, and their limits — the lecture now leaves genetics behind and copies a different animal: ants finding food.

Real-world connection. The "good enough in time" property is why genetic algorithms run inside real-time decision systems: route planning for delivery fleets, crew scheduling for airlines, antenna and circuit design, and even game-playing programs. The same loop you just traced — score, select, mix, mutate, repeat — is what those systems do millions of times per second, and the same caveat applies to all of them: no guarantee of the global optimum, only a strong probable answer delivered inside the time budget.

6.6 Ant Colony Optimization: The Biological Motivation

6.6.1 The Setup: Nest, Food, and Two Paths

Hook. How does a colony of ants find the shortest road to food — with no map, no plan, and no one in charge? They drop a scented trail as they walk, and the trail itself becomes the guide. That humble mechanism, scaled up with arithmetic, is the second multiple-instance local search technique of the course: ant colony optimization.

Ant colony optimization (ACO) is the second multiple-instance local search technique of the course. Like genetic algorithms, it is bio-inspired — but where genetic algorithms copy human evolution, ACO copies how ants find their food. The motivation story is simple and beautiful, and the exam-side of it is even simpler: big formulas, all given, substitute and go. The motivation is what you should really absorb.

Imagine a nest with many ants — A1, A2, A3, and so on — and, somewhere away, food. Between the nest and the food there are two possible paths: a short one and a long one. Two ants, A1 and A2, start their journey toward the food. Both move along the same initial segment (only one path existed so far), and both continuously release a hormone as they walk — that hormone is the pheromone. Pheromones are the ants' communication medium: other ants can smell that some ants have visited these places.

The two ants reach a decision point where the path splits. A1 takes the top (short) path; A2 takes the bottom (long) path. Both keep releasing pheromones on their way.

6.6.2 The First Return: How Pheromone Density Decides

The key quantity is the pheromone density — measured, in the narration's own way, in Boolean terms: if one ant has released pheromone on a stretch, the density is 1; if two ants have released, the density is 2.

While A2 is still slowly walking the long path, A1 has already reached the food. Now A1 must come back to the nest, retracing the short path in reverse — and at the decision point it faces the same choice again. The heart of the algorithm is right here: the ant checks the pheromone density on each option. On the top (short) path the density is 1 — A1 itself deposited pheromone going out. On the bottom (long) path, at that moment, the density is 0 — no ant has come back through there yet, because A2 has not even reached the food, let alone returned. A1 reasons, in effect: this path has density 1, that one has 0, so take this route. It continues releasing pheromone and reaches the nest.

Now A2 finishes its long journey, finds the food, and comes back the same way. At the decision point, A2 also checks densities — but by now the numbers have changed. The short path has density 2: A1 went out once and came back once, two traversals. The long path has density 1: only A2 has been there. So A2 also takes the short path, raising its density to 3, then 4, then 5, as more and more ants use the common route.

The density arithmetic in full. Count traversals, not ants. A1 walks out along the short path: short path = 1, long path = 0. A1 walks back along the short path: short path = 2, long path = 0 (A2 has not returned yet). A2 walks back along the long path, then at the decision point reads short = 2 against long = 1 — it chooses the short path, making short = 3. Each later ant adds one: 4, 5, and so on. The long path stays at 1 — only A2 ever used it — and then evaporates toward zero. Sense-check: every ant that walks the short path twice (out and back) adds 2 to its count, which is why the short path's count grows twice as fast as the long path's.

So even though A2 never walked the optimal path itself, the colony as a whole found the shortest route after roughly one iteration — because the first ant back from the food, plus the pheromone arithmetic, made the short path the obvious choice for everyone.

6.6.3 Evaporation, Convergence, and the Glitch

Why does the long path not stay competitive? Because pheromones evaporate. The single unit of pheromone on the long path slowly evaporates away to zero — while on the short path, ants are constantly depositing fresh pheromone, so its density never drops to zero. The path with the higher pheromone density attracts the next ant, which deposits more, which attracts more — the classic positive feedback that converges the colony onto one route.

This is not speculation about ant behavior; real observational studies were done in the 1970s, with real ants. Initially, when no territory is known and there are no pheromone values, ants at a decision point go in different routes. Then, using their pheromones, they start communicating, and eventually they all follow the same path.

The glitch — keep it as a counterexample. This only works if the ant on the shorter path returns first. What if the ant taking the longer path went first — say it is a faster-moving ant, or the ant on the short path got injured? Then the pheromone deposits accumulate on the longer path first, and everybody starts using the longer path. The whole algorithm goes for a toss. This actually happens in real ant colonies too.

Real-world: if you watch a clan of ants at home, they all follow each other, moving in a group — that follow-the-group behavior is the real-world basis of the algorithm.

6.6.4 Student Questions and Answers

Q: How many pheromones are there — can we state the density in Boolean terms? A: Yes. If only one ant has released pheromone, the density is 1; if two ants have released, the density is 2.

Q: How did the pheromone on the second ant's path become zero? A: Evaporation. Initially it is one, but eventually it evaporates, so it becomes zero. The density here also evaporates — this 2 becomes 1. But since other ants are constantly using the common path, it keeps receiving pheromones and never becomes zero; only unused paths decay to nothing.

Q: What if the ant taking the longer path went first? A: Then the whole algorithm goes for a toss — everybody will start using the longer path. If the ant on the shorter path is slow, or the fast ant is on the longer path, it deposits more pheromones and returns first, so everyone follows it. That happens in real ant colonies too.

Q: How do they know where the food is — is the destination a random explanation? A: Initially they explore, and that exploration is random. But once a few ants have found the food, that is good enough: when they return, the pheromone is already deposited, and based on that, all the others will know where the food is.

Q: At the second decision point, isn't the density on both paths two — since both ants have gone out and come back? A: No, it is not two on both. For ant one, since it came here once and went back once, the density of the short path is 2, but the long path's density is only 1, because only ant two has come till there. So ant two picks the short path as well.

Q: Does ACO always give the shortest path — does it give the global optimum? A: No. The global optimum is not guaranteed — you just counter-argued it yourself. This is exactly the type of counter-argument you should be able to give for these algorithms.

Q: Should we follow others in ACO rather than exploring our own path? A: Correct — that is how ants work. In real life, if there is a clan of ants at your home, they all follow each other and move in a group; that is their behavior.

Recap + bridge. ACO copies how ants find food: walk, drop pheromone, and at every decision point choose the route with the higher pheromone density; used routes keep getting reinforced while unused routes evaporate to nothing. The mechanism works only if the good route is discovered early, and it never guarantees the global optimum. The next step turns this story into mathematics: the travelling salesman problem, a transition probability formula, and a pheromone updation formula — the two formulas the ants in the exam will need.

Real-world connection. The same follow-the-scent logic, formalized by Marco Dorigo in the early 1990s, now routes packets in communication networks, plans delivery routes, and schedules vehicles — any problem where many cheap agents sharing a cheap memory can outperform one clever planner. And the glitch matters in practice too: field deployments of ant-based routing have to handle exactly the "first ant was unlucky" scenario, which is why the formulas include an evaporation term to let bad trails die out.

6.7 Ant Colony Optimization: Formal Model and Formulas

6.7.1 The Problem: Travelling Salesman Problem

Hook. The ant story becomes an exam problem with just two formulas and a graph: N cities, costs on every link, and ants that must visit every city exactly once and come home. Everything else — the constants, the pheromones, the starting city — is given in the question. What the question actually tests is whether you can substitute numbers into two formulas without dropping the evaporation term.

The exam-shaped problem for ACO is the Travelling Salesman Problem (TSP). Given N cities arranged as a graph — a complete graph, so no city is disconnected — the goal is to find the shortest path that goes through all the cities, visiting each one exactly once, and returns to the starting city. Every edge has a cost given in the problem data.

The algorithm works as follows: each ant builds its own tour starting from the starting city. At every step, the ant chooses the next city to go to with a probability (the transition probability formula below), while keeping track of the visited list so it never revisits a city. When the tour is complete, the ant lays pheromones on the edges it used, and those pheromones influence the next round. In a typical exam question you are given the graph, the nodes, the costs, and a pile of parameter values, and you must find the path the ants take using the formulas.

Picture the standard figure: N dots spread in a ring, every pair joined by a line, each line labelled with its cost. The ant starts at one dot, and at each dot the outgoing labels are the candidate costs; the formula below turns those labels into probabilities. That figure — a complete weighted graph — is the entire input of the problem.

6.7.2 Parameters and Symbols

All the parameters below are given in the question (for exams) and predefined by you from domain expertise (in real problems):

  • — the total number of ants; must be greater than one.
  • (tau) — the pheromone amount. The initial pheromone values on all edges, , are given in the question.
  • — the amount of pheromone deposited while traversing from node to node .
  • (eta) — a desirability term defined as one over the cost of the link: . If the link to costs 70, then . It is nothing but one-by-the-cost: cheap links get a big eta, expensive links a small one.
  • (alpha) — the importance coefficient of the pheromone density; it appears as a power on .
  • (beta) — the importance coefficient of the route cost; it appears as a power on .
  • (rho) — the evaporation coefficient, a number in that decides how fast unused pheromones decay.
  • — the importance constant that scales how much pheromone a used edge receives.
  • (written in some slides) — the route (tour cost) taken by ant .
  • visited list — the list of nodes the ant has already visited; the ant may only move to nodes not on this list.

A piece of intuition worth keeping about evaporation: if you keep multiplying a big number by a smaller number — the factor — it keeps diminishing and tends toward zero. Technically it will not become exactly zero; it becomes a very small, insignificant number. That is what evaporation does to unused paths.

6.7.3 The Transition Probability

The first formula tells the ant where to go next. Standing at node , the probability of moving to node — the next transition probability — is:

where the sum runs over all nodes the ant can still visit (the unvisited ones; visited nodes are excluded so the ant never returns to a city it has already covered). The numerator is the pheromone term raised to alpha times the eta term raised to beta; the denominator is the sum of those same expressions over every allowed choice, which normalizes the result into a probability. Because is just one-over-cost, the whole formula is "nothing but one-by-the-cost" weighted by pheromones.

Build it step by step. First, the desirability of a single move combines two signals: how much pheromone sits on that edge, , and how cheap the edge is, . Raising the first to and the second to lets the problem designer control which signal dominates: a large makes the ant a scent-follower, a large makes it a cost-hunter. Then the denominator adds the desirability of every alternative move, so the fraction says: "this move's desirability, as a share of all desirability on the table."

Notation note: many textbooks write the exponent terms as exactly as here, and call the result the transition probability for ant ; the lecture keeps it as to match the slides.

Two sanity checks that are worth memorizing along with the formula. First, the probabilities of all allowed moves from add to 1, because every numerator is a slice of the same denominator. Second, the limiting case — no pheromone, no cost — makes every allowed move equally likely with probability , which is exactly the uniform random walk an ant performs before any information exists.

Pitfalls.

  • Forgetting to restrict the sum to unvisited nodes: if the denominator includes cities already visited, the probabilities are still normalized but the ant may "choose" a revisit, which breaks the visit-each-city-once rule.
  • Confusing eta with the cost itself: , so a cost of 70 gives , not 70. The cheaper the link, the bigger the eta and the higher the probability.
  • Dropping the powers: alpha and beta are exponents on tau and eta respectively — swapping them, or forgetting them, changes every probability.

Exam note: the mid-semester is a closed book, so this formula must be memorized. The consolation is that solving a few problems fixes it — it is straightforward.

6.7.4 Pheromone Updation

After the ant moves, a second, very important step follows: pheromone updation — the ants deposit pheromone on the path they just used. The new pheromone value on edge is:

The term is the evaporation part, and it applies to every edge — even unused edges must be updated, or their pheromones would never evaporate. The extra term is present only on the edge the ant actually traversed:

For all other edges the delta is zero — they only lose pheromone through evaporation.

The structure of the updation deserves one careful look, because it is two effects in one equation:

  • Evaporation for everyone: every edge, used or not, multiplies its old pheromone by . With , every edge keeps 90% of its pheromone per iteration. Repeating this shrinks an unused edge geometrically: — it never hits exactly zero, but it becomes insignificant, which is the intuition from the ant story.
  • Deposit for the traveller only: the edge the ant actually used adds . A shorter route (smaller ) earns a bigger deposit — exactly the positive feedback that made the short path attractive in the story. Note that in the lecture's version is the cost of the leg just traversed, so the deposit is divided by that leg's cost; some standard presentations instead use the full tour length of ant — the relationship is the same (shorter tours, bigger deposits), but in this course's problems, use the leg cost as the slides do.

Notation note: the delta is often written in the literature to make explicit that ant 's deposit applies only to its own edges.

Pitfalls.

  • Updating only the used edge: all other edges also change — they evaporate. Skipping their factor keeps stale pheromones alive forever.
  • Using the old pheromone table in a later iteration: after any update, the current table replaces the given one; the next probability calculation must read the updated values (section 6.8 shows the classic mistake).
  • Treating as a percentage to subtract rather than a multiplier on the old value: the formula keeps times the old value, not .

Exam note: if an ACO question comes, it is worth about three to four marks, and the numbers are kept simpler and the node count smaller than this example — the point is not to test how fast you compute.

Recap + bridge. Two formulas run the whole method: the transition probability decides where the ant goes next, and the pheromone updation with on the used edge refreshes the trails. Every step of an ACO problem is those two formulas repeated. The next section applies both to a complete five-city example — the exact question shape the exam uses.

Real-world connection. These two formulas are the entire engine of ant-based routing systems: telecommunications networks use them to route packets around failed links, delivery companies use them to replan routes when a truck is delayed, and the same evaporation term that protects the ant colony from a stale short-cut also lets a routing network forget an old traffic pattern within a few minutes. The design lesson is universal: a small amount of forgetting is what keeps a learning system from being stuck with its first discovery.

6.8 Ant Colony Optimization: Worked Example — Five Cities

6.8.1 The Given Data

Hook. Five cities, five ants, one starting point, and two formulas. Every number is given — the only skill tested is substituting correctly and remembering which pheromone table is current. Here is the exact question shape, solved end to end.

The example: number of ants = number of cities = 5 (this equality is a choice, not a rule — more on that in the Q&A), with the ants starting at city 4. The constants are , , , and . All of this is given in the question.

The graph is translated into a cost adjacency matrix — in data structures terms, a matrix where entry is the cost of the edge from city to city . Because this is a travelling salesman problem, the graph is bidirectional — going from Mumbai to Delhi costs the same as Delhi to Mumbai — so the matrix is symmetric: . The costs announced in the lecture are cost(1,2) = 65, cost(1,3) = 52, cost(4,1) = 69, cost(4,2) = 28, cost(4,3) = 72, cost(2,3) = 39; the slide's full matrix supplies the remaining entries (the costs of the edges touching city 5 and the 1–4 direction's mirror). In an exam, every entry is printed on the graph.

The initial pheromone values are also given: (and the same, since the table is symmetric), , , , — these are the values the narration actually uses, and by symmetry , , , . The remaining initial entries come from the slide.

There are only two steps per move, and the whole problem is just these two steps repeated: step one — where to go next (transition probability), step two — after reaching the destination, update the pheromones. One simplification: if only one unvisited city remains, skip the probability computation entirely and move directly.

6.8.2 Step 1: Transition Probabilities from City 4

From city 4 the ant can go to 1, 2, 3, or 5. So we compute , , , and and move to the largest.

Take in full. With , :

Substituting the given values: , , , and . So the numerator is:

Worked with a calculator: , , so .

The denominator is the sum of the same expression over all four choices, and this is where the reuse trick lives. Compute the other numerators once:

with , , and read from the slide's matrix (the audio does not announce it — but the probability sum must close at 1, which pins it down as discussed below).

Now the payoff: the numerator of — appears identically inside the denominator of . If you do the first probability carefully, you have already computed the terms you need for the others; each subsequent probability is just a new numerator divided by the same denominator:

The slide reports the winner: is the maximum among the four (the audio garbles the smaller decimals, and the remaining probability comes out at about 0.31–0.32 so that the four sum to 1 — the ranking is what matters: P42 wins). The ant moves from 4 to 2.

6.8.3 Pheromone Updation after 4 → 2

Now step two: update the pheromone table with

The updation numbers after 4 → 2. With , for every edge we multiply the old tau by — the evaporation part. For example, had old value 0.54, so .

Only the edge the ant actually used — 4 to 2 — gets the delta on top:

because is the given constant and is the path cost of the leg just traveled, which is cost(4,2) = 28. So . For every other edge the delta is zero — those edges only evaporate, keeping 90% of their pheromone. Sense-check: the used edge's pheromone jumps from 0.39 to about 3.92 — the deposit (100/28 ≈ 3.57) dwarfs the evaporated remainder (0.351) — exactly the positive feedback that makes the used path attractive next round.

Why do we apply the factor to the edges we did not use? That is exactly the evaporation from the ant story: when a path is not used, its pheromones slowly evaporate. If we did not update the unused edges, they would never decay.

6.8.4 The Rest of the Tour

The same two steps repeat:

  • From city 2: the ant cannot go back to 4 (it came from there), so compute , , and with the same formula. The maximum is — the ant moves 2 → 3. Update: only the 2–3 edge gets , since cost(2,3) = 39; all other edges get their current value.
  • A very common student mistake: in this second updation, students go back to the pheromone values from the question. Wrong — the pheromones were already updated after the first leg. The values used here are the first-iteration pheromone values, the ones just computed: for example, the 1–2 edge starts this step at 0.486, not 0.54.
  • From city 3: the ant cannot return to 2, so only 1 and 5 remain — compute and . The reuse trick pays off here: the numerator of equals the numerator computed earlier for the 1–3 direction (the tau and eta values are symmetric: and ), so you can reuse the value already on your page. The maximum is — the ant moves 3 → 5. Update: only the 3–5 edge gets (the slide's value for cost(3,5) is not announced in the audio; the formula is the same with the cost of this leg).
  • From city 5: the only unvisited city left is 1. This is a no-brainer — no probability calculation needed; the ant moves 5 → 1 directly, and the pheromone updation is done for the 5–1 edge alone: , the rest evaporating at .
  • From city 1: the travelling salesman must return to the origin. City 4 is the starting city, so the final move 1 → 4 is forced — again no formula, just the updation: , because cost(1,4) = 69.

6.8.5 Interpreting the Result

The final tour is 4 → 2 → 3 → 5 → 1 → 4. That is the answer: the path the ants took, given the pheromones and the costs.

One thing this answer is not: it is not guaranteed to be the optimal tour. The computation simply reports the probable solution the ant colony produced under the given pheromones — a probable solution to the travelling salesman problem. Whether it is optimal is a separate question; ACO does not guarantee it, as the counter-argument Q&A below established.

Real-world: the travelling salesman problem is a classic computer science problem — a travelling salesman who has to visit different cities to sell and then come back home can use exactly this method to choose a route.

Real-world: this style of question mirrors the route-optimization assignment — where you must also know that ACO may or may not return the optimum, and that a statement of that limitation earns credit in a write-up.

The example is not difficult and not too lengthy if you reuse the intermediate terms — do the hard work once and the rest falls out.

6.8.6 Student Questions and Answers

Q: Why is the number of ants equal to the number of nodes given in the question? A: It could be different also. In this question it is given that the number of ants equals the number of cities equals five. The number of ants can be more or less — that is a choice for the problem.

Q: Do we have to memorize the formula for the exam? A: Yes — the mid-semester is a closed book. But if you solve a few problems, it should stay with you; it is straightforward.

Q: What does the Q value signify here? A: It is a constant given in the question — in the first slide of the example you will see Q. Usually Q is the summation of all the edge costs, but in this example it is given as 100 just for simple calculation. Sometimes it is actually the addition of all those edge values.

Q: Why is it 100 divided by 69 in this step — and why not for the other edges? A: Because 69 is the edge cost of the leg the ant just moved: one to four is sixty-nine, so the delta is 100 by 69 — Q by L_k. Only the edge that the ant used gets this delta; for all others the delta is zero, but the evaporation part of the formula still applies to them.

Q: Why don't we go back to four? And is the problem over after reaching one? A: Four is where we started — it is the endpoint of the tour, and the travelling salesman problem visits every city exactly once and comes back to where it started, so we never revisit four mid-tour. After 5 → 1 the tour is still incomplete: we must move 1 → 4, back to the origin. These forced moves skip the probability calculation — the ant goes directly and only the pheromones are updated.

Q: Why do we multiply the old tau by one minus rho? A: Evaporation — when a path is not used, its pheromones slowly evaporate, so the old value shrinks every iteration. Rho is the evaporation coefficient, and unused edges only lose; only the used edge also gains its delta.

Recap + bridge. Two steps repeated five times produced the tour 4 → 2 → 3 → 5 → 1 → 4: compute the transition probabilities from the current city, move to the maximum (or move directly when only one city remains), then update every edge with and add on the used edge only — always from the current pheromone table. That completes the second multiple-instance local search technique. The module's last topic is a different animal entirely: using genetic algorithms to design neural networks.

Real-world connection. This five-city example is the smallest honest instance of what delivery and logistics software do at city scale: the route-optimization assignment uses the same two formulas on larger graphs, and the lesson to carry into it is that ACO returns a probable solution — stating that limitation explicitly is itself worth credit. The reuse trick matters in the exam and in code: computing each numerator once and dividing by a shared denominator is what lets the algorithm scale from five cities to hundreds without redoing work.

6.9 Neural Architecture Search (NAS)

6.9.1 What Is NAS — The Era of Self-Designing AI

Hook. Every algorithm in this module needed a human designer: someone chose the heuristic, someone chose the fitness function. What if the search could design those things itself — even the neural network that does the searching? That question is the last topic of the module, and the lecture calls the answer the era of self-designing AI.

The module has now covered uninformed search, heuristic functions, and local search. The one remaining piece is neural architecture search (NAS) — a different kind of topic, based on research papers rather than textbook algorithms, and one the course enters slowly.

The motivation answers a question students kept asking: why do we manually design heuristics and manually design fitness functions — can this be automated? Yes, and a seed of the idea already appeared earlier in this course: patent databases, where we pre-compute and keep results so we can reuse them later, instead of recomputing at runtime. Something similar can be done for search itself. And today's topic, genetic algorithms, gives a concrete route: with a genetic algorithm you can perform an automated search that automatically creates a neural network. That is the era of self-designing AI, and NAS is its name.

Two research papers are linked for this session; both are on arXiv and free to download, and both deserve at least a glance even if you do not fully follow them yet — reading research papers is slightly tricky when you are not used to it, but the course will go through the ideas in class.

6.9.2 CoDeepNEAT: Evolving Deep Neural Networks

The main paper is CoDeepNEAT — Co-Evolving Deep Neural Networks by Augmenting Topologies. It is an automated method for designing deep neural network architectures. Traditionally, network architectures rely on human experts who design them manually; CoDeepNEAT replaces that manual design with evolutionary search — and of the two evolutionary algorithms in this course (genetic algorithms and ant colony optimization), the paper uses the genetic one.

The mechanism will be familiar: inspired by natural evolution, architectures are gradually improved through selection, mutation, and recombination — where selection is the parent selection we practiced, recombination is the crossover, and mutation is the gene modification. The goal of the paper's method: automatically evolve a neural network that can accurately classify images such as cat and dog, without any manual design decision.

Why bother? Manually designing neural networks is challenging because the state space of architectures and parameters is enormous, and human experts rely on trial and error and prior knowledge — which limits them to fairly conventional architectures. An evolutionary search can explore that space and occasionally produce novel children — architectures a human would never have tried. The paper combines the genetic algorithm with gradient descent: the genetic level evolves the architecture, and the weights are trained by gradient descent — a hybrid optimization approach.

The lineage of the idea is worth keeping straight, because the paper builds on it: NEAT (NeuroEvolution of Augmenting Topologies) was the earlier method — "augmenting topologies" meaning the architecture grows by adding nodes and connections as evolution proceeds. The paper first extends NEAT into DeepNEAT, which evolves the topology and hyperparameters of deep networks, and then goes further to CoDeepNEAT, which co-evolves two kinds of structures — modules (small reusable network building blocks) and blueprints (how the modules are assembled) — so that repetitive, deep structures can be assembled automatically. The paper's results match the state of the art on the CIFAR-10 image-classification benchmark, evolve LSTM structures for language modeling, and even build a real captioning application for an online magazine. Each method has its own slides in the course material describing what it is, what problem it solves, and how its networks are generated.

6.9.3 Neural Evolution: GA Concepts Mapped to Networks

The central idea is neural evolution — using genetic algorithms to evolve neural networks. Every network is evolved by the same principles just studied:

  1. Create an initial population — many random networks.
  2. Train each network once (a single training run).
  3. Measure performance — that is the fitness.
  4. Select the best performers — that is parent selection.
  5. Generate new networks — first crossover, then mutation.

The vocabulary maps cleanly:

Genetic algorithm term Meaning in neural evolution
Population The set of networks being evolved
Fitness How good a network performs (e.g. classification accuracy)
Generation One cycle of evolution — one round of selection, crossover, and mutation

The loop is the same loop as the four-queens example: score the networks, select the best as parents, combine them with crossover, perturb with mutation, and repeat — each cycle is one generation of the population of networks. The only difference is that the "individual" is now a whole neural network architecture instead of a four-digit board vector, and its fitness comes from actually training it once and measuring performance.

6.9.4 The Plan, the Papers, and Exam Notes

The plan for the next session: walk through the paper step by step — what each step of the method does — and then solve an example. The example is distinctive because the problem looks like a neural network question (an image classification / caption generation type problem) but the solution mechanism is genetic: show the iteration of the phenotype, the fitness value, selection, crossover, and mutation. Mostly the session will solve that one example; the theory parts will be glanced through quickly. After NAS, the module moves to game playing.

Exam note: the NAS theory will not be asked in the exam — you just read it. The example-style question (a genetic algorithm iteration on a neural network flavored problem) is the exam-relevant part.

Practice exercises: every section of the material carries one or two exercises — for example, given parents, use single-point crossover to generate 2 children, a question from a past mid-semester. A very similar question appeared in a recent webinar session. Solving these exercises is the recommended preparation.

Recap + bridge. Neural architecture search automates the design of neural networks with the same genetic machinery as the four-queens problem: a population of networks, fitness from training, parent selection, crossover, mutation, and a loop over generations. CoDeepNEAT is the paper version — NEAT extended to deep networks and then to co-evolved modules and blueprints — and its example iteration is what the next class will solve. With that, the local-search module closes, and the course moves to game playing.

Real-world connection. NAS is the research backbone of automated machine learning: the same recipe — evolution or search over architectures, gradient descent for weights — now designs production networks for image classification, speech recognition, and language models, replacing years of human trial and error. The cat-versus-dog classifier in the paper is the toy scale of what this machinery does at industrial scale, and the hybrid design (evolution for architecture, gradient descent for weights) is the pattern every serious NAS system since has followed.

Exam Guidance Summary

Genetic algorithms:

  • Exam problems will normally ask for one iteration of the algorithm and tell you to stop — you will be told how many iterations or states to generate. You rarely choose stopping points yourself.
  • The initial boards are chosen by you, randomly; the count to start with (K) is given in the question. The boards will not be provided.
  • The three stopping criteria (threshold reached, predefined generation count, no change between iterations) are core vocabulary.
  • The roulette wheel is the parent-selection method used in this course — tournament and ranking exist but are not practiced here.
  • Expect the crossover family: single-point (draw one line, swap tails, always two children), two-point (swap the middle segment), uniform (swap a stated percentage of bits, e.g. 50% or 25%). A past mid-semester question asked for single-point crossover producing two children from given parents; a similar question appeared in the webinar.
  • Mutation: change one bit per child (one or two bits, not more) to any allowed value other than the current one.
  • Solving a linear equation with a genetic algorithm was a past mid-semester question — same flow as the queens example: random initialization, fitness, probabilities, selection, crossover, mutation. An uploaded solution is available.
  • Do not expect GA to guarantee optimality — the entire class is local search; that limitation itself is exam-relevant.

Ant colony optimization:

  • The mid-semester is closed book — the transition probability formula and the pheromone updation formula must be memorized.
  • If an ACO question appears, it is worth roughly three to four marks, with fewer nodes and simpler numbers than the worked example.
  • Reuse intermediate terms: the numerator of one transition probability appears inside the denominators of the others — compute once, save time.
  • Remember that only the used edge gets the delta ; all edges still get the evaporation factor. Use the updated pheromone values from the previous iteration, never the original table.
  • is commonly 0.1 in many problems — slow evaporation.
  • ACO does not guarantee the global optimum — and stating that counter-argument is itself worth credit (about a mark) in an assignment write-up.

Neural architecture search:

  • NAS theory will not be asked; the example-style genetic algorithm iteration (phenotype, fitness, selection, crossover, mutation) is what to practice.
  • Read the two linked papers on arXiv at least once, even a glance.

General: solve the exercises at the end of each section — they recycle past mid-semester questions.

Key Industry Applications

  • Genetic algorithms — creative tasks and planning problems; solving linear equations; route optimization (the assignment); any situation where a good-enough answer must be found fast, such as traffic management systems, where the most optimized solution would become obsolete before it could be used.
  • Genetic algorithms and sustainability — these algorithms are computationally expensive, and that cost is part of the wider debate about AI sustainability.
  • Ant colony optimization — the travelling salesman problem, a classic computer science problem (a salesman visiting cities and returning home); route optimization in the assignment; the real-world ant behavior it copies (ants following each other in groups).
  • Online vs offline computation — the choice of computing during runtime versus precomputing and keeping results; the patent-databases style of reuse was the course's earlier example.
  • Neural architecture search — automated design of deep neural network architectures, e.g. evolving a network that classifies cat versus dog images without manual design; the era of self-designing AI, built on evolutionary search (genetic algorithms) plus gradient descent for the weights.

ACI Lecture 6 Notes · Genetic Algorithms, Ant Colony Optimization, and Neural Architecture Search

Artificial Computational Intelligence· postgraduate· 2026-08-13

Sections Breakdown

16.1 Genetic Algorithms: Foundations and Terminology

Genetic algorithms as the multiple-instance local search method where individuals collaborate: terminology, the seven-step process, and the three stopping criteria.

26.2 Genetic Algorithms: The Four Queens Problem — Setup, Fitness, and Probabilities

Four random board configurations, the non-attacking-pairs fitness function with threshold 6, and conversion of fitness into selection probabilities.

36.3 Genetic Algorithms: Parent Selection with the Roulette Wheel

Fitness-proportionate roulette wheel selection: spins, repeated picks, distinct-couple rules, and the student questions about selection.

46.4 Genetic Algorithms: Crossover — Generating Children

Single-point, two-point, and uniform crossover, applied to the four-queens couples (B4, B1) and (B1, B3).

56.5 Genetic Algorithms: Mutation and the Complete Iteration

One-bit mutation, the completed first iteration, the generation loop, stopping criteria in action, and applications of genetic algorithms.

66.6 Ant Colony Optimization: The Biological Motivation

The ant food-finding story: pheromone density, evaporation, positive feedback, the glitch, and what the colony finds after one iteration.

76.7 Ant Colony Optimization: Formal Model and Formulas

The travelling salesman problem setup, all ACO parameters, the transition probability, and the pheromone updation formulas.

86.8 Ant Colony Optimization: Worked Example — Five Cities

A complete five-city ACO example: transition probabilities from city 4, pheromone updation after each leg, and the final tour 4 → 2 → 3 → 5 → 1 → 4.

96.9 Neural Architecture Search (NAS)

Self-designing AI: the CoDeepNEAT paper, neural evolution vocabulary, and how genetic algorithms automate neural network design.

10Exam Guidance Summary

Consolidated exam strategy: one-iteration GA questions, the roulette wheel, the crossover family, memorized ACO formulas, and NAS exam guidance.

11Key Industry Applications

Real-world applications: good-enough answers in traffic management, route optimization, the travelling salesman problem, and automated network design.

Postgraduate students in artificial intelligence and machine learning

Exam Revision Notes

Below is the distilled, exam-ready core. Every entry comes from the full explanation above. Use this section for rapid review; return to the main notes when a point needs more context.

Genetic Algorithms: Foundations and Terminology

Must-know: A genetic algorithm is a bio-inspired, multiple-instance local search technique: population → fitness → parent selection → crossover → mutation → repeat until a stopping criterion fires. The three stopping criteria are (1) threshold fitness reached, (2) predefined generation count exhausted, (3) no change between successive iterations.

⚠️ Top pitfall: Comparing criterion 3 wrongly: it compares two successive iterations (identical outcome sets), not parents against children — a child different from its parent is normal.

Self-check: Name the three steps that are unique to genetic algorithms and do not appear in hill climbing or beam search.

Connects to: 6.2, 6.5

Genetic Algorithms: The Four Queens Problem — Setup, Fitness, and Probabilities

Must-know: Fitness = number of non-attacking queen pairs (6 total pairs on a 4x4 board; threshold = 6). Selection probability p_i = f_i / (sum of all fitnesses): 4/13, 4/13, 2/13, 3/13 for fitnesses 4, 4, 2, 3.

⚠️ Top pitfall: Counting attacking pairs instead of non-attacking pairs reverses the ranking; fitness is 6 minus the number of attacking pairs.

Self-check: If a fifth board with fitness 5 joined the population, what would its selection probability be?

Connects to: 6.1, 6.3

Genetic Algorithms: Parent Selection with the Roulette Wheel

Must-know: The roulette wheel is the parent-selection method for this course. Wheel slices are fitness shares (31/31/15/23%); spins are random; a repeated pick is ignored and the wheel is spun again; couples and their members must both be distinct; the number of runs cannot be fixed in advance.

⚠️ Top pitfall: Redistributing percentages after a selection, or eliminating a selected parent — selection works with replacement; everyone stays in the pool.

Self-check: After the runs B4, B1, B4: which couples can form and why must the wheel be spun again?

Connects to: 6.2, 6.4

Genetic Algorithms: Crossover — Generating Children

Must-know: Single-point crossover: draw one line at any position and swap the tails — always two children; two-point: swap the middle segment; uniform: swap a stated percentage of bits (e.g. 50%). Children are only combinations of the parents' genes; the goal is checked later by the fitness function.

⚠️ Top pitfall: Thinking crossover produces the goal state — it only generates children; and thinking gene order can be changed — the split point decides which tails go where, order never changes.

Self-check: Cross 2141 with 1422 after the first position: what are the two children?

Connects to: 6.3, 6.5

Genetic Algorithms: Mutation and the Complete Iteration

Must-know: Mutation: pick one bit per child, change it to any allowed value except the current one (one or two bits at most). One iteration = boards → fitness → probabilities → selection → crossover → mutation → fitness check against the threshold (6). The children become the next iteration's parents; random steps never guarantee progress — every state is a solution in local search.

⚠️ Top pitfall: Thinking the random steps move the search closer to the solution, or that crossover/mutation must improve fitness — neither is guaranteed; the vanilla algorithm never saves states and stops with the last child.

Self-check: Mutate 2422 by changing the leading 2 to 1, and state the resulting vector and its fitness.

Connects to: 6.1, 6.2, 6.4

Ant Colony Optimization: The Biological Motivation

Must-know: ACO is bio-inspired: ants choose routes by pheromone density (Boolean: 1 ant = 1, 2 ants = 2). Used paths keep receiving deposits; unused paths evaporate toward zero. ACO does not guarantee the global optimum — that counter-argument is exam-worthy.

⚠️ Top pitfall: Believing both paths have density 2 at A2's decision point: the short path has 2 (A1 out and back), the long path only 1 (only A2 walked it).

Self-check: Why does the long path's pheromone eventually reach zero while the short path's never does?

Connects to: 6.7, 6.8

Ant Colony Optimization: Formal Model and Formulas

Must-know: Transition probability P_ij = (tau_ij^alpha * eta_ij^beta) / (sum over unvisited h of tau_ih^alpha * eta_ih^beta) with eta = 1/cost. Pheromone updation: tau_new = (1-rho)tau_old + delta where delta = Q/L_k on the used edge and 0 elsewhere. Both formulas must be memorized (closed book).

⚠️ Top pitfall: Forgetting the evaporation term on unused edges — every edge updates with (1-rho); only the used edge also adds the delta Q/L_k.

Self-check: If cost(4,2) = 28 and Q = 100, what is the deposit delta on edge 4-2?

Connects to: 6.6, 6.8

Ant Colony Optimization: Worked Example — Five Cities

Must-know: The tour is 4 → 2 → 3 → 5 → 1 → 4. Steps: compute P_ij from the current city, move to the maximum, then update all edges (tau = 0.9*tau_old) and add delta = 100/L_k on the used edge only. Always use the updated pheromone table, never the original one. ACO returns a probable solution, not the guaranteed optimum.

⚠️ Top pitfall: Going back to the original pheromone table for the second updation — the values updated after the first leg must be used; and forgetting the (1-rho) evaporation on unused edges.

Self-check: After the 4 → 2 move, which edge receives the delta 100/28 and what happens to every other edge's pheromone?

Connects to: 6.7, 6.6

Neural Architecture Search (NAS)

Must-know: NAS automates neural network design with genetic algorithms: population of networks, train each once, fitness = performance, parent selection, crossover, mutation, repeat per generation. CoDeepNEAT = NEAT extended to deep networks with co-evolved modules and blueprints. NAS theory is not examinable; the example-style GA iteration is.

⚠️ Top pitfall: Studying the NAS theory deeply for the exam — the theory is not asked; the genetic-algorithm iteration on a neural-network-flavored problem is what to practise.

Self-check: In neural evolution, what is the fitness of a network and how is it obtained?

Connects to: 6.1, 6.5

Exam Guidance Summary

Must-know: GA questions ask for one iteration with the count given; the roulette wheel is the selection method; ACO formulas must be memorized (closed book) and the used edge alone receives Q/L_k while all edges evaporate with (1-rho); NAS theory is not examinable.

⚠️ Top pitfall: Using the original pheromone table after the first updation, and forgetting that every edge evaporates with (1-rho) even when only one edge receives the delta.

Self-check: Which two formulas must be memorized for the closed-book mid-semester, and what mark weight does an ACO question carry?

Connects to: 6.1, 6.5, 6.7, 6.8, 6.9

Key Industry Applications

Must-know: GA: good-enough answers fast (traffic management), creative and planning tasks, linear equations. ACO: TSP and route optimization. NAS: automated neural architecture design. Online = compute at runtime; offline = precompute and reuse (patent databases).

⚠️ Top pitfall: Claiming these algorithms return the best solution — they deliver probable, good-enough answers, and stating the limitation is itself worth credit.

Self-check: Why can a traffic management system not wait for the most optimized solution?

Connects to: 6.5, 6.8, 6.9

Was this lecture useful?

Loading comments…
🤖

BitsNotes AI Assistant

Subject Notes Assistant

Configure AI Chat

Choose how to access the chatbot
Have your own API key?

Switch to "Bring Your Own Key" tab above for unlimited access with any OpenAI-compatible provider.

🔑 Enter API key above to fetch live models from provider, or enter model name manually.
OpenAI-Compatible API Support

Choose any provider preset (Gemini, DeepSeek, Kimi, GLM, MiniMax, Qwen, OpenAI, Groq, Ollama, etc.) or enter a custom endpoint URL.

Security & Privacy First

Your API key is sent directly from your browser to your specified provider. BitsNotes servers never store or see your key.