Python Implementation with Visualization and Analysis
I’ll create a practical scheduling problem, solve it using $Python$, and visualize the results with graphs.
I’ll include mathematical formulas and provide a clear explanation of the code.
Scheduling Problem: Job Shop Scheduling
Let’s solve a job shop scheduling problem, which is a common scheduling challenge in manufacturing and operations research.
Problem Definition
We have:
- 5 jobs to be processed
- 4 machines
- Each job must go through all machines in a specific order
- Each job has different processing times on each machine
- The goal is to minimize the total completion time (makespan)
Mathematically, we want to minimize:
$$ C_{max} = \max_{j \in \text{Jobs}} C_j $$
Where $C_j$ is the completion time of job $j$.
Solution Using Python
1 | import numpy as np |
Explanation of the Solution
Problem Setup
I’ve created a job shop scheduling problem with 5 jobs and 4 machines. Each job has:
- A specific processing time for each machine
- A required sequence through the machines
The mathematical objective is to minimize the makespan ($C_{max}$), which is the time when all jobs are completed:
$$ C_{max} = \max_{j \in \text{Jobs}} C_j $$
Algorithm Implementation
The solution uses two common scheduling heuristics:
- Shortest Processing Time (SPT): Prioritizes operations with shorter processing times
- Longest Processing Time (LPT): Prioritizes operations with longer processing times
For each scheduling rule, the algorithm:
- Tracks machine availability times
- Tracks job completion status
- Identifies eligible operations (next steps for jobs)
- Selects operations based on the priority rule
- Updates the schedule until all jobs are complete
Visualization
The code creates three visualizations:
- Machine-oriented Gantt chart: Shows when each machine is processing which job
- X-axis: Time
- Y-axis: Machines
- Colors: Different jobs

- Job-oriented Gantt chart: Shows the progress of each job through the machines
- X-axis: Time
- Y-axis: Jobs
- Colors: Different machines

- Comparison chart: Compares the makespan results of SPT vs LPT scheduling rules

Results Analysis
[Output]
Processing Times:
Machine 0 Machine 1 Machine 2 Machine 3
Job 0 7 4 8 5
Job 1 7 3 7 8
Job 2 5 4 8 8
Job 3 3 6 5 2
Job 4 8 6 2 5
Machine Orders:
Job 0: Machine 0 -> Machine 3 -> Machine 2 -> Machine 1
Job 1: Machine 0 -> Machine 1 -> Machine 3 -> Machine 2
Job 2: Machine 2 -> Machine 0 -> Machine 3 -> Machine 1
Job 3: Machine 0 -> Machine 3 -> Machine 1 -> Machine 2
Job 4: Machine 3 -> Machine 2 -> Machine 0 -> Machine 1
Schedule Results:
Makespan: 40
Job Completion Times: [np.int64(29), np.int64(40), np.int64(33), np.int64(17), np.int64(39)]
Comparison of Scheduling Rules:
SPT Makespan: 40
When you run this code, you’ll see:
- The problem data (processing times and machine orders)
- The resulting schedule and makespan for each scheduling rule
- Visualizations that make it easy to understand the schedules
The SPT rule often leads to better overall throughput in many scheduling scenarios, but the LPT rule can sometimes perform better when there are significant differences in processing times.
The comparison chart clearly shows which rule performs better for the specific problem instance.
Key Insights
This implementation demonstrates several important scheduling concepts:
- Priority rule-based scheduling heuristics
- Resource constraints (machines can only process one job at a time)
- Precedence constraints (operations within a job must follow a specific order)
- Visualization techniques for schedule analysis
This type of scheduling problem appears in manufacturing, project management, computing resource allocation, and many other practical domains.



















is the sample mean.

