Study Guide
Modelling the Real World
How to design, use and evaluate a model of something real: deciding what to keep and what to leave out, describing a system by its states and the events that change them, running a simple simulation of a canteen queue, and judging where a model stops being reliable.
Lesson 5.20 Algorithms and Programming
For: Key Stage 3 learners (about ages 12 to 14), and anyone starting to think about how programs represent real systems
Stage: Think
A map that is not a map
A fictional town’s bus map shows each route as a coloured line, with the stops as dots along it. The lines are drawn straight or at gentle angles, the dots are evenly spaced, and there are no streets, no hills and no distances. Yet people find their way round the town with it every day.
Think it through
What does the bus map leave out? Why is it still useful, and for which questions would it be no use at all?
- Hint 1: Think about what a passenger needs to know: where to get on, where to get off, where to change.
- Hint 2: Would it help someone who wants to know how far apart two stops really are?
Show a model answer
It leaves out the real shape of the streets, the real distances between stops and anything that is not a bus route. That is why it is easy to read: the passenger sees only the stops and the connections. It is useful for “which route, and where do I change?” and no use for “how long is the walk between these stops?”, because that detail was left out.
Stage: Discover
What a model keeps, and why
A fictional school canteen could be represented in different ways: a floor plan that shows where the tills and tables are, a price list that shows each item and its cost, or a count of how many pupils arrive and are served each minute.
Think it through
The headteacher asks: “How long will the queue at the canteen get at lunchtime?” Which of the three representations would you use, and what from the other two would you not need?
- Hint 1: Which one has numbers that change minute by minute?
Show a model answer
The count of pupils arriving and being served each minute, because the question is about how the queue grows and shrinks over time. The floor plan (where the tables are) and the price list (what each item costs) are not needed to answer it.
A model is a simplified representation of something real, made to answer particular questions. It is made by abstraction: keeping the details that matter to the question and leaving out the rest. The same canteen has a different model for each question, and no model keeps everything, because a model that kept everything would be as complicated as the canteen.
Check your understanding
Show the answer
Answer: C. Pupils arriving each minute, and how many the till serves.
The question decides what the model keeps. A different question, such as “what will lunch cost?”, would keep different details.
Stage: Predict
A crossing’s lights
A fictional pedestrian crossing has traffic lights for cars and a signal for people. Cars normally have a green light. When a person presses the button, the lights change in a fixed order to stop the cars so that people can cross, and then go back.
Think it through
List the different situations the crossing can be in, such as which lights are showing, and say what makes it change from one situation to the next. Try to find four situations and two things that make the crossing change.
- Hint 1: Start with the normal situation, with cars going.
- Hint 2: What makes the lights move on after someone has pressed the button? Something happens that is not a person.
Show a model answer
The four situations (simplified for this lesson) are: cars have a green light (Cars go); cars have an amber light (Cars slow); cars have a red light and the green man shows (People cross); cars still have red and the green man flashes (People hurry). Two things make the crossing change: a person pressing the button, and a timer running out.
Each situation the system can be in is a state: a complete description of how things are now, which is all the model needs to remember to know what can happen next. Something that happens, such as the button being pressed, is an event. A change from one state to another, caused by an event, is a state transition.
The crossing’s model has four states, Cars go, Cars slow, People cross and People hurry, and two events, button pressed and timer ends. Its rules are:
- When the state is Cars go, pressing the button moves to Cars slow. The timer does nothing.
- Cars slow, People cross and People hurry each move on to the next state when the timer ends, in that order. After People hurry the state goes back to Cars go.
- In every state except Cars go, pressing the button changes nothing.
Check your understanding
Show the answer
Answer: A. The button is pressed.
A state is how things are; an event is something that happens.
Stage: Experiment
Writing the model as a table
A table with a row for each state and event, and the state that follows, describes the whole behaviour without any code. Use the rules above to fill in the next state for each row. The first is given.
| State now | Event | Next state |
|---|---|---|
| Cars go | button pressed | Cars slow |
| Cars go | timer ends | |
| Cars slow | timer ends | |
| Cars slow | button pressed | |
| People cross | timer ends | |
| People cross | button pressed | |
| People hurry | timer ends | |
| People hurry | button pressed |
Show the completed table
| State now | Event | Next state |
|---|---|---|
| Cars go | button pressed | Cars slow |
| Cars go | timer ends | Cars go |
| Cars slow | timer ends | People cross |
| Cars slow | button pressed | Cars slow |
| People cross | timer ends | People hurry |
| People cross | button pressed | People cross |
| People hurry | timer ends | Cars go |
| People hurry | button pressed | People hurry |
Four of the eight rows leave the state unchanged. A model needs a row for an event that does nothing, because someone can still cause it.
Now use the model. The crossing starts in Cars go, and these events happen in order. Work out the state after each event, using the table.
| Step | Event | State after |
|---|---|---|
| 1 | timer ends | Cars go |
| 2 | button pressed | |
| 3 | timer ends | |
| 4 | timer ends | |
| 5 | button pressed | |
| 6 | timer ends | |
| 7 | timer ends |
Show the completed table
| Step | Event | State after |
|---|---|---|
| 1 | timer ends | Cars go |
| 2 | button pressed | Cars slow |
| 3 | timer ends | People cross |
| 4 | timer ends | People hurry |
| 5 | button pressed | People hurry |
| 6 | timer ends | Cars go |
| 7 | timer ends | Cars go |
The model starts in Cars go. The first row is given.
Check your understanding
Show the answer
Answer: D. In this model a press only matters when cars are going, so otherwise it changes nothing.
A model makes decisions, such as “a press is ignored here”. Another designer might choose to remember the press.
Stage: Apply
A game character as states
The same idea models a character in a fictional platform game. The character can be Standing, Running or Jumping. The events are arrow key held, arrow key released, jump key pressed and lands. The model has these rows:
| State now | Event | Next state |
|---|---|---|
| Standing | arrow key held | Running |
| Standing | jump key pressed | Jumping |
| Running | arrow key released | Standing |
| Running | jump key pressed | Jumping |
| Jumping | lands | Standing |
Apply it
Show the answer
Answer: B. Jumping with the event jump key pressed.
Any pair of state and event that can really happen needs a decision, even if the decision is “nothing changes”.
Think it through
Decide what the model should do when the jump key is pressed while Jumping, and write the row you would add. Give a reason, and say how the game would feel to play with your choice.
- Hint 1: The simplest row keeps the state the same. Another design lets the character jump again in mid-air.
Show a model answer
Two reasonable rows are Jumping, jump key pressed, Jumping (the press is ignored, so the character cannot jump twice, which makes the game harder and the jumps more predictable) and a new state such as Double jumping (the character jumps again in mid-air, which makes the game feel freer but needs another state and more rows). Both are right: the model records a design decision, and the designer, not the table, makes it.
Stage: Predict
Running a model over time
Back to the canteen. A fictional model of the lunch queue uses these rules: pupils arrive each minute in the numbers 4, 4, 3, 1, 1, 0 and 0, for seven minutes; one till serves up to 2 pupils every minute; and the queue is empty at the start.
Think it through
Without working it out exactly, guess: does the queue grow at first, and does it ever get shorter? How long do you think the longest queue will be, and in which minute?
- Hint 1: In the first minutes, do more pupils arrive than the till can serve?
Show what happens
At first more pupils arrive each minute (4, 4, 3) than the till serves (2), so the queue grows. Later, when only 1 or 0 arrive, the till serves 2, so the queue shrinks. The exact length of the longest queue needs the table below.
Each minute follows the same rule: the pupils waiting before serving are the queue left from the minute before plus the pupils who arrive; the till then serves the smaller of 2 and the number waiting; the queue left is what remains. Running a model like this, one step at a time, to see what happens is a simulation.
| Minute | Pupils arrive | Waiting before serving | Served | Queue left |
|---|---|---|---|---|
| 1 | 4 | 4 | 2 | 2 |
| 2 | 4 | |||
| 3 | 3 | |||
| 4 | 1 | |||
| 5 | 1 | |||
| 6 | 0 | |||
| 7 | 0 |
Show the completed table
| Minute | Pupils arrive | Waiting before serving | Served | Queue left |
|---|---|---|---|---|
| 1 | 4 | 4 | 2 | 2 |
| 2 | 4 | 6 | 2 | 4 |
| 3 | 3 | 7 | 2 | 5 |
| 4 | 1 | 6 | 2 | 4 |
| 5 | 1 | 5 | 2 | 3 |
| 6 | 0 | 3 | 2 | 1 |
| 7 | 0 | 1 | 1 | 0 |
The first row is given. Minute 7 shows why “served” is the smaller of 2 and the number waiting.
Check your understanding
Show the answer
Answer: A. 5 pupils, at the end of minute 3.
A simulation lets you see how a system changes over time without waiting for it to happen.
Stage: Explain
Asking what if?
The headteacher asks whether opening a second till, so that 4 pupils are served each minute, would fix the long queue. It is cheaper to change the model than to change the canteen.
Think it through
Change the model so that the till or tills serve 4 pupils a minute, keeping the same arrivals (4, 4, 3, 1, 1, 0, 0). Predict what happens to the queue. Then work out the queue left each minute, to see if you were right.
Work this out on paper or the board first. Nothing here is marked: compare yours with the model answer.
- Hint 1: Use the same rule: waiting before serving, then served is the smaller of 4 and that number.
Show a model answer
Minute 1: 4 arrive, 4 are served, 0 left. Minute 2: 4 arrive, 4 served, 0 left. Minute 3: 3 arrive, 3 served, 0 left. Minutes 4 and 5: 1 arrives and 1 is served, 0 left. Minutes 6 and 7: nothing arrives, nothing is waiting. The queue left is 0 in every minute, so with this model the second till would keep the queue from forming at all.
Check your understanding
Show the answer
Answer: C. 2 pupils, at the end of minutes 2 and 3.
Changing a number in the model and running it again is how a simulation answers “what if?” without trying it for real.
Stage: Apply
How far can a model be trusted?
The queue model is simple on purpose. It assumes that pupils arrive in the numbers given and that every pupil takes exactly the same time to serve. It leaves out pupils who join and leave, pupils who choose slowly, a till that stops for a minute, and a bell that brings everyone at once. Each of these could make the real queue different.
A model is not a copy of reality, and a simulation does not prove what will happen. A model shows what happens if its assumptions are true. A good model is right enough for its purpose, and is tested against real observations. Where it is wrong, the assumptions are what to examine.
Apply it
Show the answer
Answer: B. Compare its assumptions with what really happened, then adjust the model.
Evaluating a model means comparing it with real observations and asking which assumptions are responsible when they disagree.
Apply it
Show the answer
Answer: A. It shows what would happen if its assumptions hold, which a real day may not match.
A good model supports a decision; it does not make it.
Stage: Apply
Design a model of your own
A fictional school drinks machine takes a coin, lets the user choose a drink, gives the drink, and returns to waiting. A user can also press a refund button after paying and before choosing.
Think it through
Design a state model for the machine. Give its states and its events, then write the table with a row for every pair of state and event. Say one thing your model leaves out.
Work this out on paper or the board first. Nothing here is marked: compare yours with the model answer.
- Hint 1: Three states may be enough: waiting for a coin, waiting for a choice, and giving a drink.
- Hint 2: Events could be coin inserted, choice made, refund pressed and drink taken.
Show a model answer
One model has three states, Waiting, Paid and Giving drink, and four events, coin inserted, choice made, refund pressed and drink taken.
| State now | Event | Next state |
|---|---|---|
| Waiting | coin inserted | Paid |
| Waiting | choice made | Waiting |
| Waiting | refund pressed | Waiting |
| Waiting | drink taken | Waiting |
| Paid | coin inserted | Paid |
| Paid | choice made | Giving drink |
| Paid | refund pressed | Waiting |
| Paid | drink taken | Paid |
| Giving drink | coin inserted | Giving drink |
| Giving drink | choice made | Giving drink |
| Giving drink | refund pressed | Giving drink |
| Giving drink | drink taken | Waiting |
Every state has a row for every event, with “nothing changes” where an event cannot matter. The model leaves out many details: the price, whether the drink is in stock, how much money was paid, and what happens if the user never takes the drink.
Stage: Consolidate
Show what you know
Think it through
Explain in your own words what a model keeps and leaves out, and what a state, an event and a simulation are. Use a system that is not in this lesson, such as a school bell, a lift or a washing machine.
Show a model answer
A good answer says that a model is a simplified version made to answer a question, which keeps what the question needs and leaves out the rest. For a lift: the states might be “stopped at floor 2” or “moving up”; an event is a button pressed or a floor reached; a transition is the lift moving from one state to the next; a simulation would run a day of button presses through the model to see how long people wait. The model leaves out the lift’s weight limit, its speed and its colour.
Apply it
Show the answer
Answer: D. Buses and passengers arriving at each stop minute by minute, without colours or prices.
The question decides what the model must keep. Everything else can be left out.
Think it through
Which part of this lesson are you least sure about? Write one question you would ask your teacher.
Show a model answer
There is no wrong answer. Two questions worth asking: “how do I decide what to leave out?” (ask what the model is for, and keep what that question needs) and “how do I know a model is good?” (compare it with real observations and examine the assumptions where they differ).
- A model is a simplified representation made to answer a question. Abstraction keeps what matters to the question and leaves out the rest, so different questions need different models of the same thing.
- A state is how a system is now; an event is something that happens; a state transition is the change from one state to another caused by an event. A table of state, event and next state describes the behaviour, and needs a row for events that change nothing.
- A simulation runs a model step by step, such as a queue minute by minute. Changing a number and running it again answers a what-if question without changing the real thing.
- A model shows what happens if its assumptions are true. Evaluate it by comparing it with real observations and examining which assumptions differ.
Sources and scope
- What this lesson is. The twentieth lesson of the Algorithms and Programming module, written for this site. It covers modelling in the Key Stage 3 programme of study without needing a programming language. Its curriculum links are provisional and imply no review or endorsement by any examination board.
- Original material. The bus map, the crossing, the platform game, the canteen and its numbers, the drinks machine and Dev are fictional, written for this lesson. Every table, the simulation and the second-till results were worked out by hand and checked with a short Python program.
- Simplified on purpose. The crossing has four states and two events, and real crossings have more (flashing amber, detectors and timers of different lengths). The queue uses invented numbers and a single rule, with no randomness, and the lesson does not teach how to model chance. Models are built with tables and not in code.
- Left to later lessons. Writing a model as a program, and models that use random numbers.
Keeping only the details that matter to a problem and leaving out the rest, so that the problem is easier to think about.
A sequence of precise steps that solves a problem or completes a task.
A simplified representation of something real, made to answer particular questions, which keeps the details that matter and leaves out the rest.
A high-level programming language written as text, popular for learning and for real work, in which indentation shows which lines belong together.
Running a model step by step to see how a system would behave, often with a number changed to answer a what-if question.
A complete description of how a system is at one moment, which is all a model needs to know to work out what can happen next.
A change from one state to another, caused by an event such as a button being pressed or a timer ending.
Your progress on this lesson
Saved in this browser only. It is not sent anywhere, does not follow you to another device, and is lost if you clear this site’s data.
This browser is not allowing the site to save progress, so it will be forgotten when you leave the page.