Skip to content
Tactiverge

School/○ Innovator/Week 9

Project: measure the cost, plot it honestly

Your planner works on a 10 × 10 map. Will it still answer in time on a 200 × 200 warehouse? Don't guess: measure, model and plot.

About 50 min · 3 goals · Checked by automated tests

1.Why should I care?

The second half of the term project turns your planner into evidence. You'll run a fair experiment, fit what you see against what big-O predicts, and present it the way an engineering team would: plots that don't mislead, numbers with units, and limits stated plainly.

  • ◇ Measure runtime and cells expanded for two planners on at least four map sizes.
  • ◇ Compare measured growth with the expected big-O and explain any difference.
  • ◇ Present results in two honest, labelled plots and a one-page interpretation.

2.Predict

On open square maps, BFS from corner to corner expands every cell. If the side doubles from 50 to 100, roughly how do cells expanded change?

Guess first. Being wrong here is how the surprise works.

3.Understand

Design the experiment

Question: how do runtime and cells expanded grow with map size for BFS and Dijkstra? Change only the size; fix the obstacle density, the start and goal positions, the random seed and the machine. Repeat each run and record the best or median time.

Choose honest axes

Plot against the number of cells V (not just side length) so linear growth looks linear. A log–log plot turns power laws into straight lines whose slope you can read. Label units, mark each measured point, and never join points you didn't measure with a smooth curve that implies more data.

Interpret, don't decorate

State the expected big-O, the measured exponent and the gap. Dijkstra's heap adds a log V factor and larger constants; Python overheads can dominate small maps. Finish with limits: one machine, one obstacle pattern, simplified robot (no size, turning cost or uncertainty).

Explain it another way

You're the scientist now: your planner is the thing being tested, and the plots are your lab notebook.

Worked example 1

Count cells expanded by BFS on open maps and estimate the growth exponent against the cell count.

import math
from collections import deque


def bfs_expanded(side):
    start, goal = (0, 0), (side - 1, side - 1)
    queue, seen, expanded = deque([start]), {start}, 0
    while queue:
        r, c = queue.popleft()
        expanded += 1
        if (r, c) == goal:
            return expanded
        for n in [(r - 1, c), (r, c + 1), (r + 1, c), (r, c - 1)]:
            if 0 <= n[0] < side and 0 <= n[1] < side and n not in seen:
                seen.add(n)
                queue.append(n)
    return expanded


sides = [25, 50, 100, 200]
counts = [bfs_expanded(s) for s in sides]
print(counts)                                   # [625, 2500, 10000, 40000]
for (s1, e1), (s2, e2) in zip(zip(sides, counts), zip(sides[1:], counts[1:])):
    p = math.log(e2 / e1) / math.log((s2 * s2) / (s1 * s1))
    print(s1, "->", s2, "exponent vs cells:", round(p, 2))   # 1.0 each time

Common mix-ups

  • Bigger numbers on the y-axis are more impressive, so zoom in.
    ✓ Choose axes that show the growth truthfully. Readers should judge the result, not the styling.
  • If the measured exponent isn't exactly 1 or 2, something is broken.
    ✓ Constants, log factors and noise shift it. Explain the gap rather than forcing a round number.

4.Discover

In the Code Lab, run your planners on open and obstacle maps with sides 25, 50, 100 and 200. For each, record cells expanded and the best of five times. Compute the time ratio for each doubling of the side. Which planner's growth is closer to what you predicted, and why might Dijkstra's be a little steeper?

Can't use the interactive? Read a description instead

The Code Lab experiment can be followed from the worked numbers: on open maps with sides 25, 50, 100 and 200, BFS corner to corner expands 625, 2,500, 10,000 and 40,000 cells, an exponent of 1.0 against the number of cells. Times are measured as the best of five runs; plots use cells on the x-axis so linear growth appears straight.

5.Checkpoint: guided practice

Check what you just discovered before going on. Hints appear after a wrong answer.

Practice 1

BFS expands all 3,600 cells of a 60 × 60 open map. How many cells would it expand on a 120 × 120 open map, corner to corner?

cells

6.Practice on your own

Practice, not a test. Wrong answers get a hint and another try.

Practice 2 · a fresh version every time

Timing tests show a collision checker grows like n and takes 5 ms for n = 4096. Assuming that growth holds, predict its time for n = 8192, in ms.

ms

Practice 3 · a fresh version every time

A program is scanning a sensor log. Its step count is measured with: count = sum(1 for i in range(36) for j in range(i)). What value does count hold?

steps

Practice 4

You plot time against map side length and see a curve bending upwards for BFS. What is the clearest honest fix?

Practice 5

Which is the best 'limitations' sentence for your report?

7.Apply it

Term project, part 2 (deliverables). (1) Timing and cells-expanded measurements for BFS and Dijkstra on at least four map sizes. (2) Two plots: time against cells, and path cost (BFS vs Dijkstra) on obstacle maps; labelled, with units, all measured points shown. (3) A one-page interpretation: expected big-O, measured exponents, the gap, and the limits of your model.

8.Reflect

Concepts: Algorithms, searching and complexity · Honest data visualisation · Reproducibility and documentation