Community resourceWorksheet
OCR H446 2.2.2 Programming and evaluating heuristics
Part 9 of 14 · H446 2.2.2 · Computational methods
H446 2.2.2 expects a heuristic to be transparent enough to test, so here the scoring rule becomes Python. Students implement job selection for a site-inspection team with a defined tie rule, design tests that isolate each part of the score, and then argue about what a new weighted term would do to the choices made.
Students will:
- translate a written scoring rule into a function that returns a score
- implement a selection that returns the smallest-scoring option and keeps first-in-list order on a tie
- design tests that isolate a single field, a boundary case and the tie rule
- explain why examples chosen to match the code are weak evidence of correctness
- assess the behaviour change, benefit, risk and evaluation of adding a weighted urgency term
Inside: 7 explanation cells, 1 multiple-choice question, 1 fill-in-the-blanks cell, 1 written answer and 2 Python tasks. 18 marks, about 25 to 40 minutes.
Series: H446 2.2.2 · Computational methods, part 9 of 14.
Shared by Coding PathwayVerified teacher
- 12 cells
- About 30 minutes
- CC BY-SA 4.0
- Shared 31 Aug 2026
- Updated 3 Sept 2026
Preview
The whole resource, exactly as a class sees it. Answers and marking are held back.
Programming and evaluating heuristics
Complete the sections in order, beginning with retrieval and method selection before applying the ideas in integrated contexts. No new required knowledge is introduced.
A site-inspection team must choose which job to attempt next. You will implement a transparent scoring heuristic, then evaluate how its weights change behaviour.
By the end, you will be able to
- translate a stated heuristic into code;
- select the candidate with the best score;
- test ties and boundary cases;
- evaluate weights, bias and solution quality.
Reactivate: a function should separate calculation from input/output so the rule can be tested.
Make the policy explicit
Each job is a dictionary with name, distance and delay. Use:
score = distance + 2 × delay
Choose the job with the smallest score. Distance represents travel cost; twice the delay estimate gives expected disruption more influence. This is a heuristic: the selected job is promising under the chosen model, not proven globally best once traffic, urgency and later jobs are considered.
jobs = [
{"name": "A", "distance": 8, "delay": 1},
{"name": "B", "distance": 4, "delay": 4},
{"name": "C", "distance": 6, "delay": 1}
]
def job_score(job):
return job["distance"] + 2 * job["delay"]
for job in jobs:
print(job["name"], job_score(job))Worked selection
Scores are A = 10, B = 12 and C = 8, so C is selected. Although B is closest, its estimated delay raises its score.
A robust implementation starts with the first job as the current best, then replaces it only when a smaller score is found. This gives a deterministic tie rule: if scores are equal, the first job remains selected.
What is the most direct effect of increasing the delay multiplier from 2 to 5?
- ADelay has more influence on the ranking
- BEvery score becomes smaller
- CDistance is no longer used
- DThe selected job is guaranteed optimal
Independent implementation
Complete choose_job. Assume jobs contains at least one valid dictionary. Return the name of the job with the smallest score. Preserve first-in-list order when scores tie.
def choose_job(jobs):
# score = distance + 2 * delay
# Return the name with the smallest score.
passGuided test design
Use tests that isolate the rule:
- one job tests the boundary case;
- a nearer job with a high delay tests both fields;
- equal scores test the tie rule;
- changing only the delay tests its multiplier.
Passing examples chosen to match the code is weak evidence. Predict the expected result from the specification first.
The team considers adding - 3 × urgency to the score, still choosing the smallest. Explain how this changes behaviour, one benefit, one risk and how the weight could be evaluated.
Use a concrete comparison or explain the direction of change.
Students type their answer here.
Closed-book checkpoint
Complete each sentence from memory. There is no answer bank and correctness is held for teacher review.
Review your understanding
Before submitting, check that you can explain the central distinction in your own words, expose the intermediate state that supports your answer and apply the method in an unfamiliar context.