job_shop_lib.visualization¶
Package for visualization.
- plot_gantt_chart(schedule, title=None, cmap_name='viridis', xlim=None, number_of_x_ticks=15)[source]¶
Plots a Gantt chart for the schedule.
- 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.
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.
- 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 GIF of the schedule being built by the given solver.
- 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 (Callable[[Schedule, int | None, list[Operation] | None, int | None], Figure] | None) -- 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. 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, 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_gif(gif_path, instance, 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 by the given solver.
Deprecated since version 0.6.0: Use create_gif_or_video instead.
- Parameters:
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. It will be made an optional argument in version 1.0.0.
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 (Callable[[Schedule, int | None, list[Operation] | None, int | None], Figure] | None) -- 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. 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 (Callable[[Schedule, int | None, list[Operation] | None, int | None], Figure]) -- 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
- plot_gantt_chart_wrapper(title=None, cmap='viridis', show_available_operations=False)[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.
- 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:
Callable[[Schedule, int | None, list[Operation] | None, int | None], Figure]
- 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
- plot_disjunctive_graph(job_shop, figsize=(6, 4), node_size=1600, title=None, layout=None, edge_width=2, font_size=10, arrow_size=35, alpha=0.95, node_font_color='white', color_map='Dark2_r', draw_disjunctive_edges=True)[source]¶
Returns a plot of the disjunctive graph of the instance.
- Parameters:
job_shop (JobShopGraph | JobShopInstance)
figsize (tuple[float, float])
node_size (int)
title (str | None)
layout (Callable[[Graph], dict[str, tuple[float, float]]] | None)
edge_width (int)
font_size (int)
arrow_size (int)
node_font_color (str)
color_map (str)
draw_disjunctive_edges (bool)
- Return type:
Figure
- plot_agent_task_graph(job_shop_graph, title=None, figsize=(10, 10), layout=None, color_map_name='tab10', node_size=1000, alpha=0.95, add_legend=False)[source]¶
Returns a plot of the agent-task graph of the instance.
Machine and job nodes are represented by squares, and the operation nodes are represented by circles.
- Parameters:
job_shop_graph (JobShopGraph) -- The job shop graph instance. It should be already initialized with the instance with a valid agent-task graph representation.
title (str | None)
figsize (tuple[int, int])
layout (dict[Node, tuple[float, float]] | None)
color_map_name (str)
node_size (int)
alpha (float)
add_legend (bool)
- Returns:
The figure of the plot. This figure can be used to save the plot to a file or to show it in a Jupyter notebook.
- Return type:
Figure
- three_columns_layout(job_shop_graph, *, leftmost_position=0.1, rightmost_position=0.9, topmost_position=1.0, bottommost_position=0.0)[source]¶
Returns the layout of the agent-task graph.
The layout is organized in a grid manner. For example, for a JobShopGraph representing a job shop instance with 2 machines and 3 jobs, the layout would be:
0: - O_11 - 1: - O_12 J1 2: - O_13 - 3: M1 O_21 - 4: - O_22 J2 5: - O_23 - 6: M2 O_31 - 7: - O_32 J3 8: - O_33 - 9: - - - 10: - G - Where M1 and M2 are the machine nodes, J1, J2, and J3 are the job nodes, O_ij are the operation nodes, and G is the global node.
- Parameters:
job_shop_graph (JobShopGraph) -- The job shop graph instance. It should be already initialized with the instance with a valid agent-task graph representation.
leftmost_position (float) -- The center position of the leftmost column of the layout. It should be a float between 0 and 1. The default is 0.1.
rightmost_position (float) -- The center position of the rightmost column of the layout. It should be a float between 0 and 1. The default is 0.9.
topmost_position (float) -- The center position of the topmost node of the layout. It should be a float between 0 and 1. The default is 0.9.
bottommost_position (float) -- The center position of the bottommost node of the layout. It should be a float between 0 and 1. The default is 0.1.
- Returns:
A dictionary with the position of each node in the graph. The keys are the node ids, and the values are tuples with the x and y coordinates.
- Return type:
dict[Node, tuple[float, float]]
- class GanttChartCreator(dispatcher, gantt_chart_wrapper_config=None, gif_config=None, video_config=None)[source]¶
Bases:
object
Facade class that centralizes the creation of Gantt charts, videos and GIFs.
It leverages a HistoryObserver to 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 that shows the evolution of the schedule over time.
It adds a new HistoryObserver to the dispatcher if it does not have one already. Otherwise, it uses the observer already present.
- Parameters:
dispatcher (Dispatcher)
gantt_chart_wrapper_config (GanttChartWrapperConfig | None)
gif_config (GifConfig | None)
video_config (VideoConfig | None)
- 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 plot_gantt_chart_wrapper function.
- __init__(dispatcher, gantt_chart_wrapper_config=None, gif_config=None, video_config=None)[source]¶
Initializes the GanttChartCreator with the given configurations and history observer.
This class adds a new HistoryObserver to the dispatcher if it does not have one already. Otherwise, it uses the observer already present.
- Parameters:
dispatcher (Dispatcher) -- The Dispatcher class that will be tracked using a HistoryObserver.
gantt_chart_wrapper_config (GanttChartWrapperConfig | None) --
Configuration for the Gantt chart wrapper function. 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 title or cmap are not provided here and infer_gantt_chart_config is set to True, the values from gantt_chart_config will 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 and axes of the plotted Gantt chart.
- Return type:
tuple[plt.Figure, plt.Axes]
- 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 HistoryTracker to 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_config attribute.
- Return type:
None
- class GanttChartWrapperConfig[source]¶
Bases:
TypedDict
Configuration for creating the plot function with the plot_gantt_chart_wrapper function.
- title: str | None¶
- cmap: str¶
- show_available_operations: bool¶