Console / terminal sample for multi-objective job-shop scheduling with NSGA-II, supporting Windows 11 and Ubuntu Linux 24.04. Two objectives are minimized at once: the TWET (total weighted earliness and tardiness, where each job has a priority and a due date) and the makespan. Instead of a single best schedule, NSGA-II keeps a Pareto front of non-dominated trade-off solutions through non-dominated sorting and crowding-distance selection. The example dataset is a 10×10 instance with per-job priorities and due dates. There are no training or model files, because the algorithm searches from scratch on every run.

[Folder Structure]

  • CLAUDE.md / AGENT.md: program specification, the two files are kept identical.
  • CHANGELOG.md: change log.
  • copyright.txt: copyright notice.
  • data/job_shop/JSP_dataset.xlsx: three sheets. Processing Time and Machines Sequence are both num_jobs × num_machines, and Priority and Due date is num_jobs × 2.
  • model/job_shop/: run outputs, namely result.txt (the Pareto front), pareto.png (TWET vs makespan scatter) and gantt.html (the first Pareto solution).
  • tool/tools.py: shared helpers, project_root and delete_ipynb_checkpoints.
  • src/: source code, launcher scripts and this document.
  • venv/: Python virtual environment, created by step 01.

[Instructions]

Every step exists as a Windows batch file (.bat) and a Linux shell script (.sh) with identical behavior. All launchers switch to the project root first, so they can be run from any directory.

 

1. 01_venv_create.bat / 01_venv_create.sh

Delete the old venv/, create a fresh one, and install src/requirements.txt. Aborts loudly if pip fails.

 

2. 02_venv_activate.bat / 02_venv_activate.sh

Activate the venv. On Linux, source it: source src/02_venv_activate.sh.

 

3. 03_run.bat / 03_run.sh

Run the NSGA-II job-shop scheduler. Extra arguments are forwarded to genetic_algorithm.py.

 

4. 99_venv_clear.bat / 99_venv_clear.sh

Delete the venv/ folder.

 

[Python Entry Point]

src/genetic_algorithm.py

Arguments and defaults:

  • --dataset job_shop: the dataset folder name
  • --population-size 20: the size of the population
  • --crossover-rate 0.8: mating rate
  • --mutation-rate 0.3: mutation rate
  • --mutation-selection-rate 0.4: mutation selection rate
  • --iterations 1000: number of iterations
  • --seed {n}: optional, makes a run reproducible

The script prints every Pareto solution (TWET, makespan) and writes result.txt (objectives plus operation sequences as 1-based job ids), pareto.png and gantt.html to model/{dataset}/.

[Quick Start]

Windows 11

src\01_venv_create.bat

src\03_run.bat

 

Ubuntu 24.04

bash src/01_venv_create.sh

bash src/03_run.sh

 

A default run (population 20, 1000 generations, 10×10 instance) takes a few seconds. Because the GA is stochastic, results differ between runs, so pass --seed {n} for a reproducible result, or raise --iterations / --population-size for a denser front. Open model/job_shop/gantt.html in a browser to inspect the first Pareto schedule; pareto.png shows the whole front.

[Dataset Format]

  • data/{dataset}/JSP_dataset.xlsx with three sheets, all with a leading index column.
  • Processing Time: pt[j][k], the processing time of job j's k-th operation.
  • Machines Sequence: ms[j][k], the machine (1-based) of job j's k-th operation.
  • Priority and Due date: the per-job priority and due date.
  • To schedule your own problem, keep the same sheet names and layout in data/{name}/JSP_dataset.xlsx and pass --dataset {name}. Job and machine counts are read from the sheet shape.

[Algorithm (NSGA-II, per generation)]

  1. Two-point crossover: every parent pair swaps the segment between two random cut points, followed by a repair step that restores the "every job appears once per machine" invariant.
  2. Mutation: a random set of gene positions rotates its values by one place. The original notebook and upstream code trigger this when mutation_rate ≤ rand(), that is with probability 1 − mutation_rate, and it is kept as-is for fidelity.
  3. Objectives: TWET = Σ (1/priority) · earliness + priority · tardiness, and makespan. Both are minimized.
  4. Non-dominated sorting ranks parents plus offspring into Pareto fronts; selection fills the next population front-by-front, breaking ties with the crowding distance to preserve diversity.
  5. The running best set is merged and re-sorted each generation, so the reported front is the best ever seen.

[References]

Jupyter-Data-Genetic-Algorithm-Job-Shop-NSGA-II-inference.png

 

This SDK is built in AppForAI - AI Dev Tools.

 

Purchase license separately: USD 600, permanent authorization, single APP authorization, single machine authorization, one-year activation, one-year download, one-year update, one-year email technical support.