{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Parallel Machine sample" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We start by importing the module corresponding to the problem we want to tackle" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2022-07-21T15:05:02.377758Z", "start_time": "2022-07-21T15:05:01.824449Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The autoreload extension is already loaded. To reload it, use:\n", " %reload_ext autoreload\n" ] } ], "source": [ "%load_ext autoreload\n", "%autoreload 2\n", "import pyscheduling.PMSP.RmSijkCmax as pmsp_sijk" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We have 2 options to generate an instance:\n", "1. By importing it from a text file.\n", "2. By randomly generating it." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**random generation** : 2 arguments are mandatory to pass to the function :\n", "- Number of jobs\n", "- Number of machines\n", "\n", "\n", "We can customize the random generation by passing multiple other parameters such as :\n", "- Minimal and/or maximal processing time\n", "- Minimal and/or maximal setup time\n", "- Release time factor\n", "- Setup time factor\n", "- Generation protocol, by default we use VALLADA\n", "- Generation probabilistic law, by default we use the uniform law" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2022-07-21T15:05:03.342572Z", "start_time": "2022-07-21T15:05:02.379513Z" } }, "outputs": [], "source": [ "instance = pmsp_sijk.RmSijkCmax_Instance.generate_random(20,4)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are 2 methods to use to solve a given instance :\n", "- **Heuristics** : Usually greedy algorithms used to find an inital solution to the problem. They are found in the **Heuristics** class of the imported module.\n", "\n", "- **Metaheuristics** : More complicated algorithm designed to find very good solutions if given enough time. They are found in the **Metaheuristics** class of the imported module" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Heuristics**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Heuristics of the concerned problem are found in the **Heuristics** class of the imported module.\n", "\n", "As being static methods of the mentioned class, we can call heuristics as follows :" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Search stopped with status : FEASIBLE\n", " Solution is : \n", " Objective : 678\n", "Machine_ID | Job_schedule (job_id , start_time , completion_time) | Completion_time\n", "1 | (13, 0, 35) : (11, 35, 172) : (19, 172, 313) : (0, 313, 458) : (6, 458, 622) | 622\n", "2 | (14, 0, 37) : (18, 37, 184) : (2, 184, 335) : (15, 335, 487) : (17, 487, 640) | 640\n", "3 | (4, 0, 35) : (7, 35, 175) : (12, 175, 323) : (3, 323, 474) : (1, 474, 636) | 636\n", "4 | (9, 0, 35) : (16, 35, 171) : (10, 171, 310) : (5, 310, 475) : (8, 475, 678) | 678 \n", "Runtime is : 0.000600200000917539s \n", "time to best is : -1s \n", "\n" ] } ], "source": [ "solve_result = pmsp_sijk.Heuristics.constructive(instance)\n", "print(solve_result)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Metaheuristics**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Metaheuristics of the concerned problem are found in the **Metaheuristics** class of the imported module.\n", "\n", "As being static methods of the mentioned class, we can call metaheuristics as follows :" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Search stopped with status : FEASIBLE\n", " Solution is : \n", " Objective : 674\n", "Machine_ID | Job_schedule (job_id , start_time , completion_time) | Completion_time\n", "1 | (19, 0, 37) : (8, 37, 197) : (11, 197, 338) : (0, 338, 485) : (7, 485, 650) | 650\n", "2 | (14, 0, 37) : (18, 37, 184) : (4, 184, 328) : (17, 328, 477) : (12, 477, 642) | 642\n", "3 | (15, 0, 50) : (2, 50, 210) : (3, 210, 364) : (13, 364, 514) : (10, 514, 665) | 665\n", "4 | (6, 0, 44) : (16, 44, 187) : (9, 187, 323) : (5, 323, 482) : (1, 482, 674) | 674 \n", "Runtime is : 8.8761697000009s \n", "time to best is : -1s \n", "\n" ] } ], "source": [ "solve_result = pmsp_sijk.Metaheuristics.antColony(instance)\n", "print(solve_result)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can pass any eventual arguments compatible to the metaheuristic used in order to customize the solving process.\n", "\n", "In the following, we specify the number of iterations of the metaheuristic to limit its execution time :" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Search stopped with status : FEASIBLE\n", " Solution is : \n", " Objective : 635\n", "Machine_ID | Job_schedule (job_id , start_time , completion_time) | Completion_time\n", "1 | (8, 0, 47) : (19, 47, 193) : (11, 193, 333) : (13, 333, 470) : (6, 470, 624) | 624\n", "2 | (15, 0, 39) : (14, 39, 183) : (18, 183, 330) : (2, 330, 481) : (17, 481, 635) | 635\n", "3 | (3, 0, 39) : (7, 39, 187) : (12, 187, 335) : (4, 335, 472) : (1, 472, 624) | 624\n", "4 | (5, 0, 46) : (9, 46, 197) : (10, 197, 334) : (16, 334, 472) : (0, 472, 616) | 616 \n", "Runtime is : 0.013670499989530072s \n", "time to best is : 0.0046264999837148935s \n", "\n" ] } ], "source": [ "solve_result = pmsp_sijk.Metaheuristics.lahc(instance,n_iterations=10)\n", "print(solve_result)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**General solver**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There is a more general way to use the heuristics and metaheuristics without distinction by using the **Solver** class.\n", "\n", "We pass the wanted method as a parameter to create a Solver instance which works with this given method. Then, to use the solver, we call its solve() method which takes an instance of the problem as a parameter and any eventual arguments compatible to the method used in order to customize the solving process\n", "\n", "\n", "\n", "The above code can transform into the following :" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Search stopped with status : FEASIBLE\n", " Solution is : \n", " Objective : 678\n", "Machine_ID | Job_schedule (job_id , start_time , completion_time) | Completion_time\n", "1 | (13, 0, 35) : (11, 35, 172) : (19, 172, 313) : (0, 313, 458) : (6, 458, 622) | 622\n", "2 | (14, 0, 37) : (18, 37, 184) : (2, 184, 335) : (15, 335, 487) : (17, 487, 640) | 640\n", "3 | (4, 0, 35) : (7, 35, 175) : (12, 175, 323) : (3, 323, 474) : (1, 474, 636) | 636\n", "4 | (9, 0, 35) : (16, 35, 171) : (10, 171, 310) : (5, 310, 475) : (8, 475, 678) | 678 \n", "Runtime is : 0.00028119998751208186s \n", "time to best is : -1s \n", "\n" ] } ], "source": [ "solver = pmsp_sijk.Solver(pmsp_sijk.Heuristics.constructive)\n", "solve_result = solver.solve(instance)\n", "print(solve_result)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Search stopped with status : FEASIBLE\n", " Solution is : \n", " Objective : 635\n", "Machine_ID | Job_schedule (job_id , start_time , completion_time) | Completion_time\n", "1 | (8, 0, 47) : (11, 47, 188) : (19, 188, 329) : (13, 329, 470) : (6, 470, 624) | 624\n", "2 | (2, 0, 39) : (15, 39, 191) : (14, 191, 335) : (18, 335, 482) : (17, 482, 635) | 635\n", "3 | (10, 0, 41) : (3, 41, 195) : (12, 195, 345) : (4, 345, 482) : (1, 482, 634) | 634\n", "4 | (7, 0, 37) : (9, 37, 174) : (16, 174, 310) : (0, 310, 454) : (5, 454, 624) | 624 \n", "Runtime is : 0.012436999997589737s \n", "time to best is : 0.004275000013876706s \n", "\n" ] } ], "source": [ "solver = pmsp_sijk.Solver(pmsp_sijk.Metaheuristics.lahc)\n", "solve_result = solver.solve(instance,n_iterations=10)\n", "print(solve_result)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.12 ('pyscheduling')", "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.9.12" }, "vscode": { "interpreter": { "hash": "fa7cdbb78ab82d427a6b02c171e3c48e0658c2b720f18feff16576a8f3200f32" } } }, "nbformat": 4, "nbformat_minor": 4 }