How wrqccc/fjsp-drl works
Purpose and entry points
This is a Python/PyTorch research implementation of dual-attention deep reinforcement learning for Flexible Job Shop Scheduling (FJSP), optimizing scheduling decisions/makespan. Primary executables are train.py (training), test_trained_model.py (policy evaluation), test_heuristic.py (dispatch-rule baselines), and ortools_solver.py (OR-Tools reference solutions). Parameters are centralized in params.py.
Instance data and dataset boundary
FJSP instances are file-based .fjs inputs. Testing covers standard benchmarks and synthetic sets: data/BenchData/Brandimarte/BrandimarteMk1.fjs, data/SD1/10x5/3128_10j_5m.fjs, and data/SD2/10x5+mix/10x5+mix_001.fjs. Training/validation inputs are separated under data/data_train_vali/SD1/10x5/10j_5m_001.fjs and data/data_train_vali/SD2/10x5+mix/10x5+mix_001.fjs. data_utils.py owns generation, reading, and format conversion, forming the boundary between disk instances and environment-ready tensors/arrays.
Scheduling environments
Two environment implementations represent the sequential decision process and enforce job-operation precedence, machine selection, and state transitions:
• Fixed operation counts: fjsp_env_same_op_nums.py
• Variable operation counts: fjsp_env_various_op_nums.py
Training and inference repeatedly obtain an environment state, select a feasible operation-machine action, apply it, and continue until all operations are scheduled. Environment selection is a key compatibility boundary: model batching and input shape must match whether operation counts are uniform.
Neural policy and PPO optimization
The learned agent consists of a dual-attention network and a PPO training wrapper:
• model/main_model.py defines the main policy/value model.
• model/attention_layer.py and model/sub_layers.py provide attention and supporting neural layers.
• model/PPO.py implements policy rollout storage and PPO updates.
Control flow is train.py → data/environment construction → model action distribution and value estimate → environment rollout/reward → PPO update. Torch 1.11 CUDA builds are the material acceleration runtime; training may run on GPU where available.
Baselines, reference solutions, and evaluation
common_utils.py contains priority dispatching rules used by test_heuristic.py; results are persisted under test_results/, e.g. test_results/SD1/10x5/Result_FIFO_10x5.npy. Google OR-Tools is used locally through ortools_solver.py, with generated reference schedules in or_solution/, e.g. or_solution/BenchData/solution_Brandimarte.npy. These are offline artifacts, not a network service.
test_trained_model.py loads a trained checkpoint, runs greedy or sampled action selection, and writes comparable result arrays. print_test_result.py aggregates saved results into Excel-oriented output.
Persisted experiment artifacts
Model checkpoints are organized by data source and training size, e.g. trained_network/SD1/10x5.pth and trained_network/SD2/10x5+mix.pth. Reward and validation-quality histories are recorded separately in train_log/SD1/reward_10x5.txt and train_log/SD2/valiquality_10x5+mix.txt. The experiment contract is therefore file-system based: instance family and size determine the compatible environment, checkpoint, evaluation set, and result location.
Main entry points: train.py Training entry point · main_model.py Dual-attention policy/value model · data_utils.py Instance data utility · fjsp_env_same_op_nums.py Uniform-operation environment
Components 19
Instances & Data
File-based FJSP inputs are converted for compatible scheduling environments.
- Instance data utility · Generates, reads, and converts FJSP instances into environment-ready data.
data_utils.py - Training/validation instances · Separate SD1 and mixed-size training inputs.
data/data_train_vali/SD1/10x5/10j_5m_001.fjs - Benchmark instances · Standard and synthetic evaluation inputs.
data/BenchData/Brandimarte/BrandimarteMk1.fjs
Learning Runtime
Dual-attention policy training with PPO.
- Training entry point
train.py - Parameters · Centralized experiment parameters.
params.py - Uniform-operation environment · Sequential scheduling environment for fixed operation counts.
fjsp_env_same_op_nums.py - Variable-operation environment · Sequential scheduling environment for variable operation counts.
fjsp_env_various_op_nums.py - Dual-attention policy/value model · Produces feasible action distributions and value estimates.
model/main_model.py - Attention layers
model/attention_layer.py - PPO optimizer · Stores rollouts and updates the policy/value model.
model/PPO.py
Evaluation & References
Learned, heuristic, and OR-Tools scheduling results are persisted locally.
- Learned-policy evaluation · Loads a checkpoint and evaluates greedy or sampled actions.
test_trained_model.py - Dispatch-rule baselines
test_heuristic.py - Priority dispatch rules
common_utils.py - OR-Tools solver · Generates offline reference schedules.
ortools_solver.py - Result reporting · Aggregates saved results into Excel-oriented output.
print_test_result.py
Experiment Artifacts
Checkpoints, logs, schedules, and result arrays form the experiment contract.
- Trained checkpoint · Checkpoint selected by instance family and size.
trained_network/SD1/10x5.pth - Training histories · Reward and validation-quality histories.
train_log/SD1/reward_10x5.txt - Reference schedule
or_solution/BenchData/solution_Brandimarte.npy - Evaluation results · Comparable learned and heuristic makespan results.
test_results/SD1/10x5/Result_FIFO_10x5.npy
Connections 25
- Training entry point → Parameters: reads
- Training entry point → Instance data utility: loads instances
- Training entry point → Uniform-operation environment: uses when uniform
- Training entry point → Variable-operation environment: uses when variable
- Instance data utility → Training/validation instances: reads
- Instance data utility → Uniform-operation environment: builds inputs
- Instance data utility → Variable-operation environment: builds inputs
- Training entry point → Dual-attention policy/value model: trains
- Attention layers → Dual-attention policy/value model: implements attention
- Dual-attention policy/value model → Uniform-operation environment: selects actions
- Dual-attention policy/value model → Variable-operation environment: selects actions
- Uniform-operation environment → PPO optimizer: rollouts and rewards
- Variable-operation environment → PPO optimizer: rollouts and rewards
- PPO optimizer → Dual-attention policy/value model: updates
- Training entry point → Trained checkpoint: writes
- Training entry point → Training histories: writes
- Learned-policy evaluation → Trained checkpoint: loads
- Learned-policy evaluation → Benchmark instances: evaluates on
- Learned-policy evaluation → Evaluation results: writes
- Dispatch-rule baselines → Priority dispatch rules: uses
- Dispatch-rule baselines → Benchmark instances: evaluates on
- Dispatch-rule baselines → Evaluation results: writes
- OR-Tools solver → Benchmark instances: solves
- OR-Tools solver → Reference schedule: writes
- Result reporting → Evaluation results: aggregates