# wrqccc/fjsp-drl architecture

> Architecture diagram of the GitHub repository wrqccc/fjsp-drl, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wrqccc/fjsp-drl
- Repository: https://github.com/wrqccc/fjsp-drl

## Overview

#### 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`](https://github.com/wrqccc/fjsp-drl/blob/main/train.py) (Training entry point), [`model/main_model.py`](https://github.com/wrqccc/fjsp-drl/blob/main/model/main_model.py) (Dual-attention policy/value model), [`data_utils.py`](https://github.com/wrqccc/fjsp-drl/blob/main/data_utils.py) (Instance data utility), [`fjsp_env_same_op_nums.py`](https://github.com/wrqccc/fjsp-drl/blob/main/fjsp_env_same_op_nums.py) (Uniform-operation environment)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Instances &amp; Data"]
  node_data_utils["Instance data utility<br/>Python module<br/>[data_utils.py]"]
  node_train_instances["Training/validation instances<br/>FJSP files<br/>[10j_5m_001.fjs]"]
  node_benchmark_instances["Benchmark instances<br/>FJSP files<br/>[BrandimarteMk1.fjs]"]
end

subgraph group_learning["Learning Runtime"]
  node_train["Training entry point<br/>Python executable<br/>[train.py]"]
  node_params["Parameters<br/>Python module<br/>[params.py]"]
  node_same_env["Uniform-operation environment<br/>Python environment"]
  node_various_env["Variable-operation environment<br/>Python environment"]
  node_policy["Dual-attention policy/value model<br/>PyTorch model<br/>[main_model.py]"]
  node_attention_layers["Attention layers<br/>PyTorch layers<br/>[attention_layer.py]"]
  node_ppo["PPO optimizer<br/>PyTorch training module<br/>[PPO.py]"]
end

subgraph group_evaluation["Evaluation &amp; References"]
  node_model_test["Learned-policy evaluation<br/>Python executable"]
  node_heuristic_test["Dispatch-rule baselines<br/>Python executable<br/>[test_heuristic.py]"]
  node_dispatch_rules["Priority dispatch rules<br/>Python module<br/>[common_utils.py]"]
  node_ortools["OR-Tools solver<br/>Python executable<br/>[ortools_solver.py]"]
  node_report["Result reporting<br/>Python executable"]
end

subgraph group_artifacts["Experiment Artifacts"]
  node_checkpoint["Trained checkpoint<br/>PyTorch artifact<br/>[10x5.pth]"]
  node_train_log["Training histories<br/>Text artifacts<br/>[reward_10x5.txt]"]
  node_reference_schedule["Reference schedule<br/>NumPy artifact"]
  node_results["Evaluation results<br/>NumPy artifacts"]
end

node_train -->|"reads"| node_params
node_train -->|"loads instances"| node_data_utils
node_train -->|"uses when uniform"| node_same_env
node_train -->|"uses when variable"| node_various_env
node_data_utils -->|"reads"| node_train_instances
node_data_utils -->|"builds inputs"| node_same_env
node_data_utils -->|"builds inputs"| node_various_env
node_train -->|"trains"| node_policy
node_attention_layers -->|"implements attention"| node_policy
node_policy -->|"selects actions"| node_same_env
node_policy -->|"selects actions"| node_various_env
node_same_env -->|"rollouts and rewards"| node_ppo
node_various_env -->|"rollouts and rewards"| node_ppo
node_ppo -->|"updates"| node_policy
node_train -->|"writes"| node_checkpoint
node_train -->|"writes"| node_train_log
node_model_test -->|"loads"| node_checkpoint
node_model_test -->|"evaluates on"| node_benchmark_instances
node_model_test -->|"writes"| node_results
node_heuristic_test -->|"uses"| node_dispatch_rules
node_heuristic_test -->|"evaluates on"| node_benchmark_instances
node_heuristic_test -->|"writes"| node_results
node_ortools -->|"solves"| node_benchmark_instances
node_ortools -->|"writes"| node_reference_schedule
node_report -->|"aggregates"| node_results

click node_train "https://github.com/wrqccc/fjsp-drl/blob/main/train.py"
click node_params "https://github.com/wrqccc/fjsp-drl/blob/main/params.py"
click node_data_utils "https://github.com/wrqccc/fjsp-drl/blob/main/data_utils.py"
click node_train_instances "https://github.com/wrqccc/fjsp-drl/blob/main/data/data_train_vali/SD1/10x5/10j_5m_001.fjs"
click node_benchmark_instances "https://github.com/wrqccc/fjsp-drl/blob/main/data/BenchData/Brandimarte/BrandimarteMk1.fjs"
click node_same_env "https://github.com/wrqccc/fjsp-drl/blob/main/fjsp_env_same_op_nums.py"
click node_various_env "https://github.com/wrqccc/fjsp-drl/blob/main/fjsp_env_various_op_nums.py"
click node_policy "https://github.com/wrqccc/fjsp-drl/blob/main/model/main_model.py"
click node_attention_layers "https://github.com/wrqccc/fjsp-drl/blob/main/model/attention_layer.py"
click node_ppo "https://github.com/wrqccc/fjsp-drl/blob/main/model/PPO.py"
click node_checkpoint "https://github.com/wrqccc/fjsp-drl/blob/main/trained_network/SD1/10x5.pth"
click node_train_log "https://github.com/wrqccc/fjsp-drl/blob/main/train_log/SD1/reward_10x5.txt"
click node_model_test "https://github.com/wrqccc/fjsp-drl/blob/main/test_trained_model.py"
click node_heuristic_test "https://github.com/wrqccc/fjsp-drl/blob/main/test_heuristic.py"
click node_dispatch_rules "https://github.com/wrqccc/fjsp-drl/blob/main/common_utils.py"
click node_ortools "https://github.com/wrqccc/fjsp-drl/blob/main/ortools_solver.py"
click node_reference_schedule "https://github.com/wrqccc/fjsp-drl/blob/main/or_solution/BenchData/solution_Brandimarte.npy"
click node_results "https://github.com/wrqccc/fjsp-drl/blob/main/test_results/SD1/10x5/Result_FIFO_10x5.npy"
click node_report "https://github.com/wrqccc/fjsp-drl/blob/main/print_test_result.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_data_utils,node_train_instances,node_benchmark_instances toneBlue
class node_train,node_params,node_same_env,node_various_env,node_policy,node_attention_layers,node_ppo toneAmber
class node_model_test,node_heuristic_test,node_dispatch_rules,node_ortools,node_report toneMint
class node_checkpoint,node_train_log,node_reference_schedule,node_results toneRose
```

## Components

### Instances & Data

File-based FJSP inputs are converted for compatible scheduling environments.

- [Instance data utility](https://github.com/wrqccc/fjsp-drl/blob/main/data_utils.py): Python module · Generates, reads, and converts FJSP instances into environment-ready data. · `data_utils.py`
- [Training/validation instances](https://github.com/wrqccc/fjsp-drl/blob/main/data/data_train_vali/SD1/10x5/10j_5m_001.fjs): FJSP files · Separate SD1 and mixed-size training inputs. · `data/data_train_vali/SD1/10x5/10j_5m_001.fjs`
- [Benchmark instances](https://github.com/wrqccc/fjsp-drl/blob/main/data/BenchData/Brandimarte/BrandimarteMk1.fjs): FJSP files · Standard and synthetic evaluation inputs. · `data/BenchData/Brandimarte/BrandimarteMk1.fjs`

### Learning Runtime

Dual-attention policy training with PPO.

- [Training entry point](https://github.com/wrqccc/fjsp-drl/blob/main/train.py): Python executable · `train.py`
- [Parameters](https://github.com/wrqccc/fjsp-drl/blob/main/params.py): Python module · Centralized experiment parameters. · `params.py`
- [Uniform-operation environment](https://github.com/wrqccc/fjsp-drl/blob/main/fjsp_env_same_op_nums.py): Python environment · Sequential scheduling environment for fixed operation counts. · `fjsp_env_same_op_nums.py`
- [Variable-operation environment](https://github.com/wrqccc/fjsp-drl/blob/main/fjsp_env_various_op_nums.py): Python environment · Sequential scheduling environment for variable operation counts. · `fjsp_env_various_op_nums.py`
- [Dual-attention policy/value model](https://github.com/wrqccc/fjsp-drl/blob/main/model/main_model.py): PyTorch model · Produces feasible action distributions and value estimates. · `model/main_model.py`
- [Attention layers](https://github.com/wrqccc/fjsp-drl/blob/main/model/attention_layer.py): PyTorch layers · `model/attention_layer.py`
- [PPO optimizer](https://github.com/wrqccc/fjsp-drl/blob/main/model/PPO.py): PyTorch training module · 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](https://github.com/wrqccc/fjsp-drl/blob/main/test_trained_model.py): Python executable · Loads a checkpoint and evaluates greedy or sampled actions. · `test_trained_model.py`
- [Dispatch-rule baselines](https://github.com/wrqccc/fjsp-drl/blob/main/test_heuristic.py): Python executable · `test_heuristic.py`
- [Priority dispatch rules](https://github.com/wrqccc/fjsp-drl/blob/main/common_utils.py): Python module · `common_utils.py`
- [OR-Tools solver](https://github.com/wrqccc/fjsp-drl/blob/main/ortools_solver.py): Python executable · Generates offline reference schedules. · `ortools_solver.py`
- [Result reporting](https://github.com/wrqccc/fjsp-drl/blob/main/print_test_result.py): Python executable · 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](https://github.com/wrqccc/fjsp-drl/blob/main/trained_network/SD1/10x5.pth): PyTorch artifact · Checkpoint selected by instance family and size. · `trained_network/SD1/10x5.pth`
- [Training histories](https://github.com/wrqccc/fjsp-drl/blob/main/train_log/SD1/reward_10x5.txt): Text artifacts · Reward and validation-quality histories. · `train_log/SD1/reward_10x5.txt`
- [Reference schedule](https://github.com/wrqccc/fjsp-drl/blob/main/or_solution/BenchData/solution_Brandimarte.npy): NumPy artifact · `or_solution/BenchData/solution_Brandimarte.npy`
- [Evaluation results](https://github.com/wrqccc/fjsp-drl/blob/main/test_results/SD1/10x5/Result_FIFO_10x5.npy): NumPy artifacts · Comparable learned and heuristic makespan results. · `test_results/SD1/10x5/Result_FIFO_10x5.npy`

## Connections

- 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
