Every factory, hospital, print shop and cloud data centre faces the same question many times a day: which job should be done next, and where? Good answers finish work sooner and keep promises to customers; poor answers create queues and missed deadlines. This tutorial introduces job shop scheduling from scratch, then shows what changes when jobs keep arriving in real time: dynamic job shop scheduling. No background is needed. Every idea comes with a demo, and the main demos have a Show Python code button with a complete program you can copy and run.

~30 minreading and playing time
6interactive demos
Pythoncode for the main demos, ready to copy and run
Beginnerno maths beyond adding up times

1. What Is Job Shop Scheduling?

Picture a small car repair workshop with three stations: a diagnosis bay, a repair bay and a paint booth. Each car needs some of these stations, in its own order, for different lengths of time. One car needs diagnosis, then repair, then paint; another needs diagnosis, paint touch-up, then repair. Each station can work on only one car at a time. In what order should each station work on the cars?

That is a job shop. The same structure appears in machining workshops, semiconductor fabs, hospitals (patients visiting scans, labs and wards) and computing clusters. The vocabulary:

Job

A piece of work to be done, such as a car or a customer order. We write J1, J2, …

Machine

A resource that processes jobs, one job at a time. We write M1, M2, …

Operation and route

Each job is a sequence of operations, each on a given machine. The order is the job's route, and it differs between jobs.

Processing time

How long an operation takes on its machine. Once started, it runs to the end (no interruptions).

Here is the small example used in the next demos: 3 jobs on 3 machines. Each row is a job's route, read left to right. Each block is one operation: its colour shows the job, its fill pattern shows the machine, and its length is the processing time.

A schedule fixes when each operation starts. It is feasible if it obeys three rules:

  1. Route order: a job's operations happen in the order of its route, one after another. J2 cannot go to M3 until it has finished on M1.
  2. One job per machine: a machine never works on two operations at the same time.
  3. No interruptions: an operation, once started, runs for its full processing time.

2. Building a Schedule: Gantt Charts

Schedules are drawn as Gantt charts: one row per machine, time running left to right, and one bar per operation. A simple way to build a schedule is to repeatedly pick a job and place its next operation as early as possible: it starts when both the job is free (its previous operation has finished) and the machine is free.

Demo 1 · Build your own schedule

Possible actions: click a job to schedule its next operation. Try to finish all three jobs as early as possible.

Actions so far (the small numbers under the bars are the start times):

    Try this:
    • Click One job at a time: finishing J1 completely, then J2, then J3 leaves machines idle and takes 20 time units.
    • Now interleave the jobs so that the machines work in parallel. The best possible finishing time for this example is 11.
    • Switch to Job view to follow each job through its route instead of each machine.

    3. What Makes a Schedule Good?

    "Good" depends on what you care about. Three common objectives, where the completion time C of a job is when its last operation ends:

    Makespan

    When does the last job finish? max C. Short makespan means the whole batch is done early and the machines are used efficiently.

    Flowtime

    How long does each job spend in the shop, from arrival to completion? We add it up (total) or average it. Short flowtime means less work in progress and faster service.

    Tardiness

    Each job has a due date d. Its tardiness is how late it is: max(0, C − d). Early jobs have tardiness 0. Low tardiness means promises are kept.

    Different objectives can prefer different schedules. Let us give the jobs due dates: J1 is due at 12, J2 at 7 and J3 at 9. The two schedules below are both the best possible, but for different objectives (both found by checking all 1,680 possible ways to build a schedule for this example).

    Demo 2 · One problem, two "best" schedules

    Gantt charts in machine view: one row per machine, bars labelled by job, start times under the bars. The table shows when each job finishes compared with its due date.

    Schedule A finishes everything sooner, but J2 and J3 miss their due dates. Schedule B takes one time unit longer overall, yet only J2 is late, and only by one unit. Which is better depends on the objective, so the objective must be chosen to match what the business actually needs.

    4. Why Is It Hard?

    For 3 jobs we could check every option. But the number of ways to order n jobs on one machine is n! (n factorial: 3! = 6, 10! = 3,628,800), and each of the m machines has its own order, giving up to (n!)m combinations. This number explodes:

    Demo 3 · How many schedules are there?
    Presets:

    The famous FT10 instance, with just 10 jobs and 10 machines, was published in 1963, and its optimal schedule was only proven in 1989, 26 years later. Job shop scheduling is NP-hard: no known method finds optimal schedules quickly for large instances. In practice we use heuristics: fast methods that find good, though not always optimal, schedules.

    5. Dispatching Rules: Simple, Fast Decisions

    The most widely used heuristics in real factories are dispatching rules. Instead of planning the whole schedule, they build it one small decision at a time, using a candidate pool:

    1. The pool holds every operation that is waiting at an idle machine, across all idle machines.
    2. The rule gives every candidate a priority value. The candidate with the best (smallest) value starts on its machine.
    3. The pool is updated: that machine is now busy, so its other waiting operations leave the pool (they stay in its queue). Repeat while the pool is not empty.
    4. When the pool is empty, the clock jumps to the next time an operation finishes. That machine becomes idle, so its queue joins the pool, and the job that just finished an operation joins the queue of its next machine.
    RulePicks the job with…Priority (smaller = first)Idea
    FIFOthe earliest arrival in the queuetime it joined the queueFirst come, first served: fair and simple.
    SPTthe shortest processing timePTQuick jobs first: many jobs leave the queue fast.
    LPTthe longest processing time−PTBig jobs first (usually a poor idea, as you will see).
    EDDthe earliest due datedue dateMost urgent job first.
    MWKRthe most work remaining−(work remaining)Jobs with a long way to go start early.
    PT+WINQshort time here and a quiet next machinePT + WINQLook ahead: WINQ is the work already waiting in the queue of the job's next machine.

    Watch the rules at work on a small problem: 4 jobs and 3 machines, each job visiting every machine in its own order. Use Next Decision Point to move to the next moment a decision is needed and see the candidate pool, then Make Decision to let the rule choose and see how the pool and the shop change.

    Demo 4 · Dispatching rules, decision by decision

    Compare all six rules on this problem (best value in each column in green):

    Candidate pool at this decision

    Machines and queues (highlighted chips are in the pool):

    Try this: look at the comparison table. MWKR gives the shortest makespan (18): starting the jobs with the most work left first means no job is left far behind. SPT gives the lowest total flowtime but the longest makespan (24), and EDD gives the least tardiness. No rule is best for every objective, and a rule that wins on one problem may lose on another.

    6. Dynamic Job Shop Scheduling

    So far every job was known at time 0. Real shops are not like that: new jobs keep arriving, and we do not know what they will be or when. Other things go wrong too: machines break down, urgent orders jump in, processing takes longer than planned. This is dynamic job shop scheduling (DJSS).

    A perfect plan made in the morning is out of date by lunchtime. Re-optimising the whole schedule after every event is too slow when decisions are needed in seconds. This is where dispatching rules shine: they need only the current state of the shop, and they decide instantly, every time a machine becomes free.

    Because the future is uncertain, we judge a rule by its long-run average performance over many jobs, measured by simulation, rather than by one schedule.

    In this simulation: 5 machines. Each new job visits 2 to 5 different machines in a random order, with processing times from 1 to 9. Jobs arrive at random times, at a rate that keeps the machines busy for the chosen share of time (the utilisation). Each job is due at its arrival time plus 3 × its total processing time.
    Demo 5 · A live dynamic job shop

    Jobs in the shop over time

    The last 60 time units (hatched = machine broken down):

    Candidate pool

    Recently arrived jobs (newest first; faded = done, outlined = current operation)

    Latest decisions (newest first):

      Try this:
      • Push utilisation to 0.95 with FIFO: queues grow long and jobs wait. Switch to SPT while it runs and watch the queues shrink.
      • Pause, then alternate Next Decision Point and Make Decision. The candidate pool fills when a machine becomes idle or a job arrives at an idle machine, and empties as the rule starts operations.
      • Click Break a machine: jobs pile up in front of it, its queue stays out of the pool until it is repaired, and the effect spreads to other machines afterwards.
      • Add a rush job under EDD, then under SPT. Which one gets it out on time?

      7. Which Rule Is Best?

      To compare rules fairly, we simulate each one on exactly the same stream of random jobs, many times over, and average the results. The first 500 jobs are ignored as a warm-up, because the shop starts empty, and the next 2,000 jobs are measured.

      Demo 6 · Compare rules by simulation
      Scenarios:

      Three lessons stand out:

      • The objective matters. SPT and PT+WINQ give short average flowtime, but their maximum flowtime is the worst: long jobs can be overtaken again and again and wait a very long time. FIFO and EDD treat long jobs more fairly.
      • The situation matters. In a quiet shop with relaxed due dates, EDD gives the lowest average tardiness. In a busy shop, PT+WINQ does, and EDD falls well behind.
      • Combining information helps. PT+WINQ, which adds a look at the next machine to SPT, beats each simple rule on average flowtime.

      So which rule should a factory use? Designing a good rule for each shop and objective by hand takes experts a lot of trial and error. This is exactly where genetic programming helps: it can evolve new priority formulas, built from features such as PT, WINQ and due dates, and test them by simulation, as in Demo 6. Evolved rules often outperform the best manual rules. Learn how GP works in my interactive GP tutorial, and see my research on Genetic Programming for Real-time Optimisation and Decision-Making.

      8. Check Your Understanding

      1. What makes a job shop different from a production line where every product visits the machines in the same order?

      2. In Demo 1, an operation starts at max(time the job is free, time the machine is free). Why the maximum?

      3. A schedule finishes all jobs early (small makespan) but several jobs miss their due dates. Is it a good schedule?

      4. Why are dispatching rules popular for dynamic job shops?

      5. SPT gives a short average flowtime. What is its main weakness?

      Where to Go Next

      • Learn genetic programming: my interactive GP tutorial shows how evolution can design programs, including scheduling rules.
      • Make the rules explainable: the Explainable AI by Genetic Programming tutorial shows how GP keeps evolved rules small, simple and readable.
      • Explore my code: GPJSS is a Java framework for evolving dispatching rules for dynamic job shop scheduling with GP. See all my resources.
      • Go deeper: our book Genetic Programming for Production Scheduling (Springer, 2021) covers dynamic job shop scheduling and learning scheduling heuristics in depth.
      • Classic reading: Scheduling: Theory, Algorithms, and Systems by Michael Pinedo, the standard textbook on scheduling.