Gannt Chart Creation: How to Save GIFs and VideosΒΆ
[1]:
import matplotlib.pyplot as plt
from job_shop_lib import JobShopInstance, Operation
from job_shop_lib.dispatching import (
ReadyOperationsFilterType,
create_composite_operation_filter,
)
from job_shop_lib.dispatching.rules import (
DispatchingRuleSolver,
DispatchingRuleType,
)
from job_shop_lib.visualization import (
create_gif,
plot_gantt_chart_wrapper,
create_gantt_chart_video,
)
from job_shop_lib.benchmarking import load_benchmark_instance
plt.style.use("ggplot")
[2]:
CPU = 0
GPU = 1
DATA_CENTER = 2
job_1 = [Operation(CPU, 1), Operation(GPU, 1), Operation(DATA_CENTER, 7)]
job_2 = [Operation(GPU, 5), Operation(DATA_CENTER, 1), Operation(CPU, 1)]
job_3 = [Operation(DATA_CENTER, 1), Operation(CPU, 3), Operation(GPU, 2)]
jobs = [job_1, job_2, job_3]
instance = JobShopInstance(jobs, name="Example")
[3]:
solver = DispatchingRuleSolver(DispatchingRuleType.MOST_WORK_REMAINING)
non_optimized_solver = DispatchingRuleSolver(
DispatchingRuleType.MOST_WORK_REMAINING, ready_operations_filter=None
)
plot_function_with_operations = plot_gantt_chart_wrapper(
title="Solution with Most Work Remaining Rule",
show_available_operations=True,
)
plot_function = plot_gantt_chart_wrapper(
title="Solution with Most Work Remaining Rule"
)
create_gif(
gif_path="output/example.gif",
instance=instance,
solver=non_optimized_solver,
plot_function=plot_function_with_operations,
remove_frames=False,
)
create_gif(
gif_path="output/example_optimized.gif",
instance=instance,
solver=solver,
plot_function=plot_function_with_operations,
remove_frames=False,
)
[4]:
create_gantt_chart_video(
video_path="output/example_optimized.mp4",
instance=instance,
solver=solver,
plot_function=plot_function_with_operations,
remove_frames=False,
fps=3,
)
[5]:
ft06 = load_benchmark_instance("ft06")
create_gif(
"output/ft06.gif",
ft06,
non_optimized_solver,
plot_function=plot_function,
remove_frames=False,
fps=4,
)
create_gif(
"output/ft06_optimized.gif",
ft06,
solver,
plot_function=plot_function,
remove_frames=False,
fps=4,
)
[6]:
create_gantt_chart_video(
ft06,
"output/ft06_optimized.mp4",
solver,
plot_function=plot_function,
remove_frames=False,
fps=4,
)
[7]:
ft06.metadata
[7]:
{'optimum': 55,
'upper_bound': 55,
'lower_bound': 55,
'reference': "J.F. Muth, G.L. Thompson. 'Industrial scheduling.', Englewood Cliffs, NJ, Prentice-Hall, 1963."}
[8]:
pruning_function = create_composite_operation_filter(
[
ReadyOperationsFilterType.DOMINATED_OPERATIONS,
ReadyOperationsFilterType.NON_IMMEDIATE_MACHINES,
]
)
solver_optimized_v2 = DispatchingRuleSolver(
DispatchingRuleType.MOST_WORK_REMAINING,
ready_operations_filter=pruning_function,
)
create_gif(
"output/ft06_optimized_v2.gif",
ft06,
solver_optimized_v2,
plot_function=plot_function,
remove_frames=False,
fps=4,
)
[ ]: