{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Gannt Chart Creation: How to Save GIFs and Videos" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "\n", "from job_shop_lib import JobShopInstance, Operation\n", "\n", "from job_shop_lib.dispatching import (\n", " ReadyOperationsFilterType,\n", " create_composite_operation_filter,\n", ")\n", "from job_shop_lib.dispatching.rules import (\n", " DispatchingRuleSolver,\n", " DispatchingRuleType,\n", ")\n", "\n", "from job_shop_lib.visualization import (\n", " create_gif,\n", " plot_gantt_chart_wrapper,\n", " create_gantt_chart_video,\n", ")\n", "from job_shop_lib.benchmarking import load_benchmark_instance\n", "\n", "plt.style.use(\"ggplot\")" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "CPU = 0\n", "GPU = 1\n", "DATA_CENTER = 2\n", "\n", "job_1 = [Operation(CPU, 1), Operation(GPU, 1), Operation(DATA_CENTER, 7)]\n", "job_2 = [Operation(GPU, 5), Operation(DATA_CENTER, 1), Operation(CPU, 1)]\n", "job_3 = [Operation(DATA_CENTER, 1), Operation(CPU, 3), Operation(GPU, 2)]\n", "\n", "jobs = [job_1, job_2, job_3]\n", "\n", "instance = JobShopInstance(jobs, name=\"Example\")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "solver = DispatchingRuleSolver(DispatchingRuleType.MOST_WORK_REMAINING)\n", "non_optimized_solver = DispatchingRuleSolver(\n", " DispatchingRuleType.MOST_WORK_REMAINING, ready_operations_filter=None\n", ")\n", "plot_function_with_operations = plot_gantt_chart_wrapper(\n", " title=\"Solution with Most Work Remaining Rule\",\n", " show_available_operations=True,\n", ")\n", "plot_function = plot_gantt_chart_wrapper(\n", " title=\"Solution with Most Work Remaining Rule\"\n", ")\n", "\n", "\n", "create_gif(\n", " gif_path=\"output/example.gif\",\n", " instance=instance,\n", " solver=non_optimized_solver,\n", " plot_function=plot_function_with_operations,\n", " remove_frames=False,\n", ")\n", "\n", "create_gif(\n", " gif_path=\"output/example_optimized.gif\",\n", " instance=instance,\n", " solver=solver,\n", " plot_function=plot_function_with_operations,\n", " remove_frames=False,\n", ")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "create_gantt_chart_video(\n", " video_path=\"output/example_optimized.mp4\",\n", " instance=instance,\n", " solver=solver,\n", " plot_function=plot_function_with_operations,\n", " remove_frames=False,\n", " fps=3,\n", ")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "ft06 = load_benchmark_instance(\"ft06\")\n", "\n", "create_gif(\n", " \"output/ft06.gif\",\n", " ft06,\n", " non_optimized_solver,\n", " plot_function=plot_function,\n", " remove_frames=False,\n", " fps=4,\n", ")\n", "\n", "create_gif(\n", " \"output/ft06_optimized.gif\",\n", " ft06,\n", " solver,\n", " plot_function=plot_function,\n", " remove_frames=False,\n", " fps=4,\n", ")" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "create_gantt_chart_video(\n", " ft06,\n", " \"output/ft06_optimized.mp4\",\n", " solver,\n", " plot_function=plot_function,\n", " remove_frames=False,\n", " fps=4,\n", ")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'optimum': 55,\n", " 'upper_bound': 55,\n", " 'lower_bound': 55,\n", " 'reference': \"J.F. Muth, G.L. Thompson. 'Industrial scheduling.', Englewood Cliffs, NJ, Prentice-Hall, 1963.\"}" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ft06.metadata" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "pruning_function = create_composite_operation_filter(\n", " [\n", " ReadyOperationsFilterType.DOMINATED_OPERATIONS,\n", " ReadyOperationsFilterType.NON_IMMEDIATE_MACHINES,\n", " ]\n", ")\n", "solver_optimized_v2 = DispatchingRuleSolver(\n", " DispatchingRuleType.MOST_WORK_REMAINING,\n", " ready_operations_filter=pruning_function,\n", ")\n", "create_gif(\n", " \"output/ft06_optimized_v2.gif\",\n", " ft06,\n", " solver_optimized_v2,\n", " plot_function=plot_function,\n", " remove_frames=False,\n", " fps=4,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "job-shop-lib-gOF0HMZJ-py3.11", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.8" } }, "nbformat": 4, "nbformat_minor": 2 }