Examples
Here we show a few useful examples for the Scheduling
package.
Comparing algorithms
In this example, we randomly choose 20 instances of the $\text{P}||\text{C}_\text{max}$ problem and then compare the solutions generated by an exact algorithm, the LPT rule and the approximation algorithm by Hochbaum & Shmoys.
using Random
using Scheduling, Scheduling.Algorithms, Scheduling.Objectives
# We generate 20 instances
for instance_id in 1:20
# Generate the set of machines
M = Machines(rand(2:6))
# Generate the set of 12--20 jobs
J = Jobs(rand(1:50, rand(12:20)))
# Generate an exact solution
S1 = Algorithms.P__Cmax_IP(J, M)
# Generate a heuristic solution
S2 = Algorithms.lpt(J, M)
# Generate an approximation
S3 = Algorithms.P__Cmax_HS(J, M)
# Print the summary
println("Instance $(instance_id):")
println(" Optimal solution: $(float(cmax(S1)))")
println(" Heuristic: $(float(cmax(S2)))")
println(" Heuristic approx. ratio: $(float(cmax(S2)//cmax(S1)))")
println(" H&S: $(float(cmax(S3)))")
println(" H&S approx. ratio: $(float(cmax(S3)//cmax(S1)))")
end
Saving and loading a schedule
using Scheduling
using Scheduling.Algorithms
# Generate a set of jobs with processing times from an array
J = Jobs([27, 19, 19, 4, 48, 38, 29, 21, 9, 22, 11, 27, 36, 34, 21, 7, 7, 28])
# Generate a set of 4 identical machines
M = Machines(4)
# Generate an optimal schedule using IP
S = Algorithms.P__Cmax_IP(J, M)
# Save the schedule into the file
Scheduling.save(S, "my_optimal_schedule.jdl")
# Load the saved schedule to another variable
T = Scheduling.load("my_optimal_schedule.jdl")
# Plot the loaded schedule
Scheduling.plot(T)