Learn
Lesson · Scheduling · More than one machine

Two Machines in Series and Johnson's Rule

Two machines in series, every job visiting them in the same order. The first machine never stops, so the makespan is the work on the second machine plus the idle time in between — and the work does not depend on the order, so minimising the makespan is minimising idle time on the second machine. Johnson's rule does it exactly: jobs quicker on the first machine go to the front, shortest first, and the rest go to the back, longest on the second machine first.

two machines in series, every job M1 then M2, no preemption, all ready at 0 C2(k) = max(C1(k), C2(k−1)) + p2(k) the second machine waits or works makespan = (work on M2) + (idle on M2); the work is order-independent Johnson: p1 < p2 to the FRONT by p1 ascending; the rest to the BACK by p2 descending A 5:2, B 1:6, C 9:7, D 3:8, E 10:4: Johnson B D C E A, makespan 30 typed order A B C D E: 34, and M2 idles 7 where Johnson idles 3
One recursion, one rule, and the gap it is closing

Core ideas

What this lesson establishes

Three ideas: what the second machine is waiting for, why that turns the makespan into an idle-time problem, and what the rule's two halves are each doing.

1

The first machine never stops; the second one waits

Machine one runs the jobs back to back from time zero, so its timeline has no gaps and its finish times do not depend on anything but the order. Machine two can only start a job once machine one has released it and machine two is free, so its timeline has gaps in it. Every interesting quantity here is about those gaps.

2

Minimising the makespan is minimising idle time on the second machine

The project ends when machine two finishes its last job, and machine two's timeline is made of exactly two things: the processing it does, which is sum p2 whatever the order, and the time it spends waiting. So makespan = sum p2 + idle, the first term is a constant, and the whole of the optimisation is the second. On the lab's five jobs the work is 27 in every order and the idle time is 3 under the rule and 7 in the typed order — which is the whole of the difference between 30 and 34.

3

The rule has two halves and they do different jobs

A job quicker on machine one is a job that gets machine two started early, so those jobs go to the front, shortest on machine one first, to start machine two as soon as possible. A job quicker on machine two leaves machine one free early, so those go to the back, longest on machine two first, so that the longest tail is not the thing left at the end. Both halves are minimising idle time, at the two ends where idle time happens.

The material

Two machines, one recursion, and the rule that empties the gaps

The model, the recursion that builds the schedule, the rule in two halves, and it measured against every one of the 120 orders.

Definition · The two-machine flow shop

n jobs; job j needs p1_j on machine one and then p2_j on machine two, in that order. Both machines run one job at a time, nothing is interrupted, everything is available at time zero, and every job visits the machines in the same order — which is what makes it a flow shop.

The same order is used on both machines. A schedule that resequenced between the machines could in principle do better on more than two machines; on two it cannot, which is why one permutation is the whole decision here.

Write the order as k = 1, 2, …, n. Machine one finishes job k at C1(k) = C1(k−1) + p1(k), with C1(0) = 0, so it is the running total. Machine two cannot start job k until both that job has left machine one and machine two has finished job k−1:

C1(k) = C1(k−1) + p1(k) C2(k) = max( C1(k), C2(k−1) ) + p2(k) makespan = C2(n) idle on machine 2 = C2(n) − sum p2 and sum p2 does not move

The max is where the whole problem lives. When C1(k) wins, machine two was idle waiting for the job; when C2(k−1) wins, machine two was busy and the job waited instead. Waiting jobs cost nothing in this objective; a waiting machine costs the makespan.

Definition · Johnson's rule

Split the jobs. Those with p1 < p2 form the front group and are ordered by p1 ascending. The rest, with p1 ≥ p2, form the back group and are ordered by p2 descending. The schedule is the front group followed by the back group, and it minimises the makespan.

Five jobs, and where the four hours went

jobs A 5:2 B 1:6 C 9:7 D 3:8 E 10:4 p1:p2 quicker on machine 1: B (1 < 6) and D (3 < 8) → front, by p1 up: B, D the rest: A, C, E → back, by p2 down: C (7), E (4), A (2) JOHNSON B D C E A M1 B[0,1] D[1,4] C[4,13] E[13,23] A[23,28] M2 B[1,7] D[7,15] C[15,22] E[23,27] A[28,30] makespan 30 idle on M2 = 1 + 1 + 1 = 3 work on M2 = 27 TYPED A B C D E M1 A[0,5] B[5,6] C[6,15] D[15,18] E[18,28] M2 A[5,7] B[7,13] C[15,22] D[22,30] E[30,34] makespan 34 idle on M2 = 5 + 2 = 7 work on M2 = 27 best of all 120 orders 30, attained by 2 of them — Johnson's is one

The two schedules do the same 27 hours of work on machine two and differ only in how long that machine spent waiting. In the typed order it waits five hours at the start, because A occupies machine one for five hours before anything can be handed over. Johnson puts B first, which occupies machine one for one hour, and machine two starts at 1 instead of at 5.

Example · The starved second machine, on purpose

The lab has a preset built to make this visible: four jobs where the typed order begins with an eight-hour job on machine one that needs one hour on machine two. Machine two stands idle for the whole eight hours, and the typed order finishes at 35 with 18 hours of idle time against 17 hours of work.

Johnson's rule turns it round completely: D C B A, finishing at 24 with 7 hours of idle. Same jobs, same work, eleven hours saved, and the enumeration confirms that 24 is the best any of the twenty-four orders can do.

Checking the picture before believing the number

A recursion that produces a number is easy to get subtly wrong, so the lab reads the drawing back. It checks that machine one runs with no gaps, that machine two never overlaps itself, that no job reaches machine two before it has left machine one, and that the makespan taken off the last bar is the makespan the recursion reported. Then it checks work + idle = makespan exactly, which is the identity the rule is built on.

It also runs every one of the n! orders through the same two-machine clock and reports the best, the count and how many orders tie for it. On the lab's instance two orders attain 30, and Johnson's is one of them. Reporting the tie count matters: naming a single order and implying it is the unique optimum is a claim nobody made.

Where this stops

Three machines in series is a different problem and this rule does not extend to it. There is a special case — when the middle machine is dominated by one of the others — in which a two-machine reduction works, and the general case is hard in the sense “Algorithms and Complexity” gave the word. The lab offers two machines and says so rather than offering a third with a rule that is not a theorem.

The tie case is worth one line. When p1 = p2 for every job, as in the lab's third preset, the front group is empty and the rule sorts everything into the back group by p2 descending. That order attains the optimum, and so does every other order: all twenty-four tie at 21. The rule is not doing any work there, and the panel's tie count says so.

Interactive

Two machines in series: Johnson's rule

Machine 2's idle time is the whole of the difference between one order and another

Two machines in series: Johnson's rulethe makespan is the second machine's finishing time, and idle time on it is the whole cost
machine 1machine 2Johnson's orderthe order you typed

Method

Sequencing a two-machine flow shop

Four steps, and the second is the one that decides which half a job belongs to.

1

Write each job as its two times, in machine order

p1:p2, machine one first. Getting the two columns the wrong way round produces a valid schedule for a problem you do not have, and nothing in the output looks wrong — the makespan will simply be larger than it should be.

2

Split the jobs on p1 < p2

Strictly quicker on machine one goes to the front group; everything else, including the ties, goes to the back group. The split is the decision; the two sorts that follow are bookkeeping.

3

Sort the front by p1 ascending and the back by p2 descending

Two different keys for the two groups, and they are not the same sort run twice. The front wants the smallest first-machine time first, to start machine two as early as possible; the back wants the largest second-machine time first, so the tail at the end is short.

4

Build both timelines and check the identity

Run the recursion, then add up the second machine's processing and its idle time and check that they come to the makespan. If they do not, the recursion has a gap in it that the drawing will show at once, and the lab refuses the schedule rather than printing the number.

Idle time, the split, and what the rule is minimising

Score 0 / 0

Five jobs through two machines, and four hours of waiting removed

The lab's opening preset, with both timelines written out. Every figure is what the panel reports when the comparison order is left as typed.

jobs A 5:2 B 1:6 C 9:7 D 3:8 E 10:4 work on machine 2 = 2 + 6 + 7 + 8 + 4 = 27, in every order THE SPLIT p1 < p2: B (1 < 6), D (3 < 8) front, by p1 ascending: B, D p1 ≥ p2: A (5 ≥ 2), C (9 ≥ 7), E (10 ≥ 4) back, by p2 descending: C 7, E 4, A 2 Johnson’s order B D C E A JOHNSON’S SCHEDULE machine 1 B 0–1 D 1–4 C 4–13 E 13–23 A 23–28 machine 2 B 1–7 D 7–15 C 15–22 E 23–27 A 28–30 idle on machine 2: 0–1, 22–23, 27–28 three hours 27 + 3 = 30 = makespan THE TYPED ORDER machine 1 A 0–5 B 5–6 C 6–15 D 15–18 E 18–28 machine 2 A 5–7 B 7–13 C 15–22 D 22–30 E 30–34 idle on machine 2: 0–5, 13–15 seven hours 27 + 7 = 34 = makespan the best of all 120 orders is 30, and 2 of them attain it

The two idle blocks in the typed order are the whole of the four-hour gap, and they have different causes. The five hours at the start are machine two waiting for the first job to exist; the two hours in the middle are machine two having finished B at 13 while C is still on machine one until 15. Johnson's split attacks the first with the front group and the second with the back group.

Machine one is worth checking too. In both schedules it runs from 0 to 28 without a break and finishes before machine two does. That is always true here, and it is why no amount of cleverness about machine one helps: its timeline is fixed up to the order and it is never the thing that ends the schedule.

For a rehearsal, use the preset where every job takes the same time on both machines. The supplied first move is that no job satisfies p1 < p2, so the front group is empty. Predict what the rule returns and what the enumeration says about how many orders tie for the best makespan, before the panel tells you. The answer is that all twenty-four tie, which means the rule is choosing arbitrarily and the tie count is the only honest way to say so.

Common mistakes

1
Sorting the whole list by one keyThe rule is a split and then two different sorts: p1 ascending in the front group, p2 descending in the back. Sorting everything by p1 ascending gives B D A C E on the lab's instance, which is not Johnson's order and does not attain 30.
2
Trying to improve machine oneIt runs from zero to the end of its work with no gaps in every order, and it always finishes before machine two. Effort spent smoothing it is effort spent on a timeline that is not deciding anything; the gaps that matter are all on the second machine.
3
Carrying the makespan intuition over from one machineOn one machine the makespan is a constant and there is nothing to optimise. On two it ranges from 30 to well above 34 on the lab's five jobs, and it is the only objective in this lesson. The constant was a consequence of one machine never idling, and a second machine breaks it.

Check your understanding

✓
Finish when you can build both timelines by hand and account for the makespan as work plus idle.

You should be able to run the two-machine recursion with its max, split the jobs on p1 < p2, sort the two groups on their own keys, draw both machines' timelines, list the idle intervals on machine two, check that the idle time plus sum p2 equals the makespan, and compare the rule against a typed order on the same jobs.

Note: The rule worked because the two machines are visited in the same order by every job, which made one permutation the whole decision. Let two jobs visit the machines in opposite orders and there is no permutation to choose: each shared machine has its own sequencing question, and the questions interact. “The Job Shop and Disjunctive Orientations” is what is left when the exchange argument runs out — but first, the same jobs on machines that run in parallel rather than in series, where a rule survives and arrives with a guarantee rather than a proof of optimality.

Kept in this browser only, for you. Nothing is sent anywhere and nothing checks it. Carry it to another device.

Feedback and recommendations

Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.

No recommendations yet for this lesson.