Parallel Machine Scheduling using Simulated Annealing
Schedule jobs on unrelated parallel machines in MATLAB with simulated annealing, sequence-dependent setup times, and makespan minimization.

On this page
This package implements Parallel Machine Scheduling in MATLAB and solves it with Simulated Annealing (SA). The goal is to assign jobs to machines and order them so that the makespan (Cmax, the completion time of the last machine) is as small as possible.
Parallel machine scheduling is a classic problem in production planning. Several machines work at the same time, and each job needs one machine. The version in this code is one of the harder ones: the machines are unrelated (the processing time of a job depends on the machine), and the setup time between two jobs depends on their order. Even the simplest version with two identical machines is NP-hard, so metaheuristics such as SA are a common choice.
The problem
There are jobs and machines. The data are:
- : the processing time of job on machine .
- : the setup time on machine when job follows job .
A schedule assigns each job to exactly one machine and gives the order of the jobs on each machine. A machine does one job at a time, without breaks. If job follows job on machine , it starts when job finishes plus the setup time:
The first job on a machine starts at time 0 with no setup. If is the finish time of the last job on machine , the objective is the makespan:
In the standard three field notation, this is the problem .
The sample model in CreateModel.m has 20 jobs and 4 machines. The processing times are between 10 and 60, and the setup times are between 2 and 8.
How a solution is encoded
A solution is a permutation of the numbers 1 to (23 numbers in the sample). The numbers 1 to are jobs, and the numbers above are separators. Reading from left to right, the jobs before the first separator go to machine 1 in that order, the jobs between the first and second separators go to machine 2, and so on. A machine may get no jobs.
ParseSolution.m decodes the permutation this way and then simulates the schedule with the formulas above. It returns the start and finish time of every job, the completion time of each machine and the makespan. MyCost.m returns the makespan as the cost.
How Simulated Annealing searches
SA keeps one current solution. At each temperature it tries MaxIt2 neighbors. CreateNeighbor.m makes a neighbor with one of three moves, chosen with equal probability:
- Swap: exchange two entries. This can move two jobs between machines or change their order.
- Reversion: reverse the order of a part of the permutation.
- Insertion: take one entry and put it in another position.
Because separators are also entries, each move can change the assignment of jobs to machines as well as the order on a machine.
A better or equal neighbor is always accepted. A worse one is accepted with probability , where is the increase in makespan and is the temperature. After each outer iteration the temperature is multiplied by alpha. For a full explanation of the method, see the Simulated Annealing post.
What is in the package
CreateModel.mdefines a sample problem with 20 jobs and 4 machines. It holds a matrix of processing times and a set of setup times for each machine.CreateRandomSolution.mcreates a random initial solution.CreateNeighbor.mcreates a neighbor of a solution by swap, reversion or insertion.ParseSolution.mconverts a solution into job sequences for the machines and simulates the schedule to find the makespan.MyCost.mis the cost function. It returns the makespan.PlotSolution.mplots a solution.sa.mis the main script. It sets the SA parameters (500 iterations, 25 inner iterations, initial temperature 10, damping rate 0.97) and runs the algorithm.
How to use
Open sa.m in MATLAB and run it. To solve your own problem, replace the data in CreateModel.m.
The program prints the best makespan in every iteration. PlotSolution.m draws the best schedule as a Gantt chart, with one row per machine, one colored bar per job and a red line at . At the end, a second figure shows the best cost against the iteration. CreateNeighbor.m calls randsample, so the code probably needs the Statistics and Machine Learning Toolbox.
Parameters in the code
| Parameter | Meaning | Value |
|---|---|---|
MaxIt |
Number of outer iterations (temperature levels) | 500 |
MaxIt2 |
Inner iterations at each temperature | 25 |
T0 |
Initial temperature | 10 |
alpha |
Temperature damping rate | 0.97 |
Check the result
Verify that every job appears once, machine processing times come from the correct column, and each setup time uses the correct ordered pair of jobs. Recompute the makespan from the decoded finish times. The example omits release dates, due dates, breakdowns, and other operational constraints, so those need explicit model changes if they matter to your schedule. Compare repeated runs on the same data rather than treating a single Gantt chart as evidence of optimality.
Applications
Problems of this type appear in many workshops and service systems:
- Production lines with several machines that can do the same operations at different speeds.
- Printing, painting and chemical plants, where cleaning or changeover time depends on the previous job.
- Assigning tasks to processors in computing.
- Scheduling operating rooms or service counters.
Related posts
- Simulated Annealing in MATLAB
- Capacitated Vehicle Routing Problem using Simulated Annealing, which uses the same separator encoding and the same neighbor moves.
- Bin Packing Problem using GA, PSO, FA and IWO
Downloads
How to cite
If you use this code or tutorial in your work, articles or publications, please cite it.
Mostapha Kalami Heris, Parallel Machine Scheduling using Simulated Annealing (YPAP107), Yarpiz, 2015. https://yarpiz.com/parallel-machine-scheduling-ypap107@misc{yarpiz-ypap107,
author = {{Mostapha Kalami Heris}},
title = {{Parallel Machine Scheduling using Simulated Annealing}},
howpublished = {Yarpiz},
year = {2015},
note = {Code YPAP107},
url = {https://yarpiz.com/parallel-machine-scheduling-ypap107}
}Published Updated
Comments