job_shop_lib.visualization.gantt¶
Contains functions and classes for visualizing job shop scheduling problems.
Plots a Gantt chart for the schedule. |
|
Creates a video of the schedule being built. |
|
Creates a GIF of the schedule being built. |
|
Creates frames of the Gantt chart for the schedule being built. |
|
Returns a function that plots a Gantt chart for an unfinished schedule. |
|
Creates a GIF or video from the frames in the given directory. |
|
Creates a GIF or video from the frames in the given directory. |
|
Facade class that centralizes the creation of Gantt charts, videos and GIFs. |
|
A dictionary with the configuration for creating the GIF using the |
|
Configuration for creating the video using the |
|
A protocol for a function that plots an uncompleted Gantt chart for a schedule. |
|
A dictionary with the configuration for creating the |
- plot_gantt_chart(schedule, title=None, cmap_name='viridis', xlim=None, number_of_x_ticks=15, job_labels=None, machine_labels=None, legend_title='', x_label='Time units', y_label='Machines')[source]¶
Plots a Gantt chart for the schedule.
This function generates a Gantt chart that visualizes the schedule of jobs across multiple machines. Each job is represented with a unique color, and operations are plotted as bars on the corresponding machines over time.
The Gantt chart helps to understand the flow of jobs on machines and visualize the makespan of the schedule, i.e., the time it takes to complete all jobs.
The Gantt chart includes:
X-axis: Time units, representing the progression of the schedule.
Y-axis: Machines, which are assigned jobs at various time slots.
Legend: A list of jobs, labeled and color-coded for clarity.
Note
The last tick on the x-axis always represents the makespan for easy identification of the completion time.
- Parameters:
schedule (Schedule) -- The schedule to plot.
title (str | None) -- The title of the plot. If not provided, the title:
f"Gantt Chart for {schedule.instance.name} instance"is used. To remove the title, provide an empty string.cmap_name (str) -- The name of the colormap to use. Default is "viridis".
xlim (int | None) -- The maximum value for the x-axis. If not provided, the makespan of the schedule is used.
number_of_x_ticks (int) -- The number of ticks to use in the x-axis.
job_labels (list[str] | None) -- A list of labels for each job. If
None, the labels are automatically generated as "Job 0", "Job 1", etc.machine_labels (list[str] | None) -- A list of labels for each machine. If
None, the labels are automatically generated as "0", "1", etc.legend_title (str) -- The title of the legend. If not provided, the legend will not have a title.
x_label (str) -- The label for the x-axis. Default is "Time units". To remove the label, provide an empty string.
y_label (str) -- The label for the y-axis. Default is "Machines". To remove the label, provide an empty string.
- Returns:
A
matplotlib.figure.Figureobject.A
matplotlib.axes.Axesobject where the Gantt chart is plotted.
- Return type:
tuple[Figure, Axes]
- create_gantt_chart_video(instance, video_path=None, solver=None, plot_function=None, fps=1, remove_frames=True, frames_dir=None, plot_current_time=True, schedule_history=None)[source]¶
Creates a video of the schedule being built.
- Parameters:
instance (JobShopInstance) -- The instance of the job shop problem to be scheduled.
video_path (str | None) -- The path to save the video file.
solver (DispatchingRuleSolver | None) -- The dispatching rule solver to use. If not provided, the history of scheduled operations should be provided.
plot_function (PartialGanttChartPlotter | None) -- A function that plots a Gantt chart for a schedule. It should take a
Scheduleobject and the makespan of the schedule as input and return aFigureobject. If not provided, a default function is used.fps (int) -- The number of frames per second in the video.
remove_frames (bool) -- Whether to remove the frames after creating the video.
frames_dir (str | None) -- The directory to save the frames in. If not provided,
name_without_the_extension + "_frames"is used.plot_current_time (bool) -- Whether to plot a vertical line at the current time.
schedule_history (Sequence[ScheduledOperation] | None) -- A sequence of scheduled operations. If not provided, the solver will be used to generate the history.
- Return type:
None
- create_gantt_chart_gif(instance, gif_path=None, solver=None, plot_function=None, fps=1, remove_frames=True, frames_dir=None, plot_current_time=True, schedule_history=None)[source]¶
Creates a GIF of the schedule being built.
- Parameters:
instance (JobShopInstance) -- The instance of the job shop problem to be scheduled.
gif_path (str | None) -- The path to save the GIF file. It should end with ".gif". If not provided, the name of the instance is used.
solver (DispatchingRuleSolver | None) -- The dispatching rule solver to use. If not provided, the history of scheduled operations should be provided.
plot_function (PartialGanttChartPlotter | None) -- A
PlotFunctionthat plots a Gantt chart for a schedule. It should take a Schedule object and the makespan of the schedule as input and return a Figure object. If not provided, a default function is used.fps (int) -- The number of frames per second in the GIF.
remove_frames (bool) -- Whether to remove the frames after creating the GIF.
frames_dir (str | None) -- The directory to save the frames in. If not provided,
gif_path.replace(".gif", "") + "_frames"is used.plot_current_time (bool) -- Whether to plot a vertical line at the current time.
schedule_history (Sequence[ScheduledOperation] | None) -- A sequence of scheduled operations. If not provided, the solver will be used to generate the history.
- Return type:
None
- create_gantt_chart_frames(frames_dir, instance, solver, plot_function, plot_current_time=True, schedule_history=None)[source]¶
Creates frames of the Gantt chart for the schedule being built.
- Parameters:
frames_dir (str) -- The directory to save the frames in.
instance (JobShopInstance) -- The instance of the job shop problem to be scheduled.
solver (DispatchingRuleSolver | None) -- The dispatching rule solver to use. If not provided, the history of scheduled operations should be provided.
plot_function (PartialGanttChartPlotter) -- A function that plots a Gantt chart for a schedule. It should take a Schedule object and the makespan of the schedule as input and return a Figure object.
plot_current_time (bool) -- Whether to plot a vertical line at the current time.
scheduled_history -- A sequence of scheduled operations. If not provided, the solver
schedule_history (Sequence[ScheduledOperation] | None)
- Return type:
None
- get_partial_gantt_chart_plotter(title=None, cmap='viridis', show_available_operations=False, **kwargs)[source]¶
Returns a function that plots a Gantt chart for an unfinished schedule.
- Parameters:
title (str | None) -- The title of the Gantt chart.
cmap (str) -- The name of the colormap to use.
show_available_operations (bool) -- Whether to show the available operations in the Gantt chart.
**kwargs (Any) -- Additional keyword arguments to pass to the
plot_gantt_chart()function.
- Returns:
A function that plots a Gantt chart for a schedule. The function takes the following arguments:
schedule: The schedule to plot.
makespan: The makespan of the schedule.
available_operations: A list of available operations. If None, the available operations are not shown.
current_time: The current time in the schedule. If provided, a red vertical line is plotted at this time.
- Return type:
- create_gif_from_frames(frames_dir, gif_path, fps, loop=0)[source]¶
Creates a GIF or video from the frames in the given directory.
- Parameters:
frames_dir (str) -- The directory containing the frames to be used in the GIF.
gif_path (str) -- The path to save the GIF file. It should end with ".gif".
fps (int) -- The number of frames per second in the GIF.
loop (int) -- The number of times the GIF should loop. Default is 0, which means the GIF will loop indefinitely. If set to 1, the GIF will loop once. Added in version 0.6.0.
- Return type:
None
- create_video_from_frames(frames_dir, gif_path, fps, macro_block_size=16)[source]¶
Creates a GIF or video from the frames in the given directory.
- Parameters:
frames_dir (str) -- The directory containing the frames to be used in the video.
gif_path (str) -- The path to save the video.
fps (int) -- The number of frames per second.
macro_block_size (int)
- Return type:
None
- class GanttChartCreator(dispatcher, partial_gantt_chart_plotter_config=None, gif_config=None, video_config=None)[source]¶
Bases:
objectFacade class that centralizes the creation of Gantt charts, videos and GIFs.
It leverages a
HistoryObserverto keep track of the operations being scheduled and provides methods to plot the current state of the schedule as a Gantt chart and to create a GIF or video that shows the evolution of the schedule over time.It adds a new
HistoryObserverto the dispatcher if it does not have one already. Otherwise, it uses the observer already present.- history_observer¶
The history observer observing the dispatcher's state.
- gantt_chart_config¶
Configuration for plotting the Gantt chart.
- gif_config¶
Configuration for creating the GIF.
- gantt_chart_wrapper_config¶
Configuration for the Gantt chart wrapper function.
- video_config¶
Configuration for creating the video.
- plot_function¶
The function used to plot the Gantt chart when creating the GIF or video. Created using the
get_partial_gantt_chart_plotter()function.
- Parameters:
dispatcher (Dispatcher) -- The
Dispatcherclass that will be tracked using aHistoryObserver.partial_gantt_chart_plotter_config (PartialGanttChartPlotterConfig | None) --
Configuration for the Gantt chart wrapper function through the
PartialGanttChartPlotterConfigclass. Defaults toNone. Valid keys are:title: The title of the Gantt chart.
cmap: The name of the colormap to use.
- show_available_operations: Whether to show available
operations in each step.
If
titleorcmapare not provided here andinfer_gantt_chart_configis set toTrue, the values fromgantt_chart_configwill be used if they are present.gif_config (GifConfig | None) --
Configuration for creating the GIF. Defaults to
None. Valid keys are:gif_path: The path to save the GIF.
fps: The frames per second of the GIF.
- remove_frames: Whether to remove the frames after creating
the GIF.
frames_dir: The directory to store the frames.
- plot_current_time: Whether to plot the current time in the
Gantt chart.
video_config (VideoConfig | None) --
Configuration for creating the video. Defaults to
None. Valid keys are:video_path: The path to save the video.
fps: The frames per second of the video.
- remove_frames: Whether to remove the frames after creating
the video.
frames_dir: The directory to store the frames.
- plot_current_time: Whether to plot the current time in the
Gantt chart.
- property instance¶
The instance being scheduled.
- property schedule¶
The current schedule.
- property dispatcher¶
The dispatcher being observed.
- plot_gantt_chart()[source]¶
Plots the current Gantt chart of the schedule.
- Returns:
The figure of the plotted Gantt chart.
- Return type:
Figure
- create_gif()[source]¶
Creates a GIF of the schedule being built using the recorded history.
This method uses the history of scheduled operations recorded by the
HistoryTrackerto create a GIF that shows the progression of the scheduling process.The GIF creation process involves:
- Using the history of scheduled operations to generate frames for
each step of the schedule.
Creating a GIF from these frames.
Optionally, removing the frames after the GIF is created.
The configuration for the GIF creation can be customized through the
gif_configattribute.- Return type:
None
- class GifConfig[source]¶
Bases:
TypedDictA dictionary with the configuration for creating the GIF using the
create_gantt_chart_gif()function.See also
- gif_path: str | None¶
The path to save the GIF. It must end with '.gif'.
- fps: int¶
The frames per second of the GIF. Defaults to 1.
- remove_frames: bool¶
Whether to remove the frames after creating the GIF.
- frames_dir: str | None¶
The directory to store the frames.
- plot_current_time: bool¶
Whether to plot the current time in the Gantt chart.
- class VideoConfig[source]¶
Bases:
TypedDictConfiguration for creating the video using the
create_gantt_chart_video()function.See also
- video_path: str | None¶
The path to save the video. It must end with a valid video extension (e.g., '.mp4').
- fps: int¶
The frames per second of the video. Defaults to 1.
- remove_frames: bool¶
Whether to remove the frames after creating the video.
- frames_dir: str | None¶
The directory to store the frames.
- plot_current_time: bool¶
Whether to plot the current time in the Gantt chart.
- class PartialGanttChartPlotter(*args, **kwargs)[source]¶
Bases:
ProtocolA protocol for a function that plots an uncompleted Gantt chart for a schedule.
This kind of functions are created using the
plot_gantt_chart_wrapper()function.- __call__(schedule, makespan=None, available_operations=None, current_time=None)[source]¶
Plots a Gantt chart for an unfinished schedule.
- Parameters:
schedule (Schedule) -- The schedule to plot.
makespan (int | None) -- The makespan of the schedule if known. Can be used to fix the x-axis limits.
available_operations (list[Operation] | None) -- A list of available operations. If
None, the available operations are not shown.current_time (int | None) -- The current time in the schedule. If provided, a red vertical line is plotted at this time.
- Return type:
Figure
- class PartialGanttChartPlotterConfig[source]¶
Bases:
TypedDictA dictionary with the configuration for creating the
PartialGanttChartPlotterfunction.- title: str | None¶
The title of the Gantt chart.
- cmap: str¶
The colormap to use in the Gantt chart.
- show_available_operations: bool¶
Whether to show available operations in each step.