# ai4co/rl4co architecture

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

- Interactive diagram: https://gitdiagram.com/ai4co/rl4co
- Repository: https://github.com/ai4co/rl4co

## Overview

RL4CO is a reinforcement-learning benchmark and toolkit for combinatorial optimization. Its main user workflow is to select or generate problem instances, define an environment and policy/model, then train and evaluate the model. The repository also provides reusable constructive and improvement policies, multiple RL algorithms, decoding and neural-network components, and active-search methods. The README supports the high-level workflow; source excerpts and the SOURCE INDEX establish only selected internal links, so other capability links are omitted rather than inferred.

Main entry points: [`rl4co/models/rl/common/base.py`](https://github.com/ai4co/rl4co/blob/main/rl4co/models/rl/common/base.py) (RL model base), [`rl4co/envs/common/base.py`](https://github.com/ai4co/rl4co/blob/main/rl4co/envs/common/base.py) (CO environments), [`rl4co/tasks/train.py`](https://github.com/ai4co/rl4co/blob/main/rl4co/tasks/train.py) (Training task), [`rl4co/tasks/eval.py`](https://github.com/ai4co/rl4co/blob/main/rl4co/tasks/eval.py) (Policy evaluation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_problems["Problems and data"]
  node_generators["Instance generators<br/>[generator.py]"]
  node_environments["CO environments<br/>[base.py]"]
  node_dataset["Dataset handling<br/>[dataset.py]"]
  node_data_generation["Data generation<br/>[generate_data.py]"]
  node_data_transforms["Data transforms<br/>[transforms.py]"]
end

subgraph group_policies["Policies and algorithms"]
  node_policy_families["Policy families<br/>[base.py]"]
  node_attention_model["Attention Model<br/>[model.py]"]
  node_eas_search["EAS search<br/>[search.py]"]
  node_active_search["Active search<br/>[search.py]"]
  node_rl_algorithms["RL algorithms"]
end

subgraph group_runtime["Training and evaluation"]
  node_training_model["RL model base<br/>[base.py]"]
  node_training_task["Training task<br/>[train.py]"]
  node_evaluation["Policy evaluation<br/>[eval.py]"]
  node_trainer["Trainer<br/>[trainer.py]"]
end

subgraph group_components["Reusable components"]
  node_decoding["Action decoding<br/>[decoding.py]"]
  node_neural_components["Neural components"]
  node_position_encoding["Position encodings<br/>[pe.py]"]
  node_ops["Tensor operations<br/>[ops.py]"]
end

node_user(("Researcher"))

node_user -->|"chooses problem"| node_generators
node_generators -->|"provides instances"| node_environments
node_user -->|"selects policy"| node_attention_model
node_environments -->|"configures model"| node_training_model
node_attention_model -->|"supplies policy"| node_training_model
node_training_model -->|"fits model"| node_trainer
node_training_task -->|"instantiates"| node_environments
node_training_task -->|"instantiates"| node_training_model
node_training_task -->|"runs training"| node_trainer
node_training_model -->|"uses environment"| node_environments
node_training_model -->|"uses generated data"| node_data_generation
node_environments -->|"loads datasets"| node_dataset
node_eas_search -->|"uses decoding"| node_decoding
node_active_search -->|"uses augmentation"| node_data_transforms
node_evaluation -->|"scores actions"| node_environments
node_evaluation -->|"evaluates policy"| node_policy_families

click node_generators "https://github.com/ai4co/rl4co/blob/main/rl4co/envs/routing/tsp/generator.py"
click node_environments "https://github.com/ai4co/rl4co/blob/main/rl4co/envs/common/base.py"
click node_dataset "https://github.com/ai4co/rl4co/blob/main/rl4co/data/dataset.py"
click node_data_generation "https://github.com/ai4co/rl4co/blob/main/rl4co/data/generate_data.py"
click node_data_transforms "https://github.com/ai4co/rl4co/blob/main/rl4co/data/transforms.py"
click node_policy_families "https://github.com/ai4co/rl4co/blob/main/rl4co/models/common/constructive/base.py"
click node_attention_model "https://github.com/ai4co/rl4co/blob/main/rl4co/models/zoo/am/model.py"
click node_eas_search "https://github.com/ai4co/rl4co/blob/main/rl4co/models/zoo/eas/search.py"
click node_active_search "https://github.com/ai4co/rl4co/blob/main/rl4co/models/zoo/active_search/search.py"
click node_rl_algorithms "https://github.com/ai4co/rl4co/tree/main/rl4co/models/rl"
click node_training_model "https://github.com/ai4co/rl4co/blob/main/rl4co/models/rl/common/base.py"
click node_training_task "https://github.com/ai4co/rl4co/blob/main/rl4co/tasks/train.py"
click node_evaluation "https://github.com/ai4co/rl4co/blob/main/rl4co/tasks/eval.py"
click node_decoding "https://github.com/ai4co/rl4co/blob/main/rl4co/utils/decoding.py"
click node_neural_components "https://github.com/ai4co/rl4co/tree/main/rl4co/models/nn"
click node_position_encoding "https://github.com/ai4co/rl4co/blob/main/rl4co/utils/pe.py"
click node_ops "https://github.com/ai4co/rl4co/blob/main/rl4co/utils/ops.py"
click node_trainer "https://github.com/ai4co/rl4co/blob/main/rl4co/utils/trainer.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_generators,node_environments,node_dataset,node_data_generation,node_data_transforms toneBlue
class node_policy_families,node_attention_model,node_eas_search,node_active_search,node_rl_algorithms toneAmber
class node_training_model,node_training_task,node_evaluation,node_trainer toneMint
class node_decoding,node_neural_components,node_position_encoding,node_ops toneRose
class node_user toneIndigo
```

## Components

### Problems and data

- [Instance generators](https://github.com/ai4co/rl4co/blob/main/rl4co/envs/routing/tsp/generator.py): `rl4co/envs/routing/tsp/generator.py`
- [CO environments](https://github.com/ai4co/rl4co/blob/main/rl4co/envs/common/base.py): `rl4co/envs/common/base.py`
- [Dataset handling](https://github.com/ai4co/rl4co/blob/main/rl4co/data/dataset.py): `rl4co/data/dataset.py`
- [Data generation](https://github.com/ai4co/rl4co/blob/main/rl4co/data/generate_data.py): `rl4co/data/generate_data.py`
- [Data transforms](https://github.com/ai4co/rl4co/blob/main/rl4co/data/transforms.py): `rl4co/data/transforms.py`

### Policies and algorithms

- [Policy families](https://github.com/ai4co/rl4co/blob/main/rl4co/models/common/constructive/base.py): `rl4co/models/common/constructive/base.py`
- [Attention Model](https://github.com/ai4co/rl4co/blob/main/rl4co/models/zoo/am/model.py): `rl4co/models/zoo/am/model.py`
- [EAS search](https://github.com/ai4co/rl4co/blob/main/rl4co/models/zoo/eas/search.py): `rl4co/models/zoo/eas/search.py`
- [Active search](https://github.com/ai4co/rl4co/blob/main/rl4co/models/zoo/active_search/search.py): `rl4co/models/zoo/active_search/search.py`
- [RL algorithms](https://github.com/ai4co/rl4co/tree/main/rl4co/models/rl): `rl4co/models/rl`

### Training and evaluation

- [RL model base](https://github.com/ai4co/rl4co/blob/main/rl4co/models/rl/common/base.py): `rl4co/models/rl/common/base.py`
- [Training task](https://github.com/ai4co/rl4co/blob/main/rl4co/tasks/train.py): `rl4co/tasks/train.py`
- [Policy evaluation](https://github.com/ai4co/rl4co/blob/main/rl4co/tasks/eval.py): `rl4co/tasks/eval.py`
- [Trainer](https://github.com/ai4co/rl4co/blob/main/rl4co/utils/trainer.py): `rl4co/utils/trainer.py`

### Reusable components

- [Action decoding](https://github.com/ai4co/rl4co/blob/main/rl4co/utils/decoding.py): `rl4co/utils/decoding.py`
- [Neural components](https://github.com/ai4co/rl4co/tree/main/rl4co/models/nn): `rl4co/models/nn`
- [Position encodings](https://github.com/ai4co/rl4co/blob/main/rl4co/utils/pe.py): `rl4co/utils/pe.py`
- [Tensor operations](https://github.com/ai4co/rl4co/blob/main/rl4co/utils/ops.py): `rl4co/utils/ops.py`

### Other components

- **Researcher**

## Connections

- Researcher → Instance generators: chooses problem (evidence: `README.md`)
- Instance generators → CO environments: provides instances (evidence: `README.md`)
- Researcher → Attention Model: selects policy (evidence: `README.md`)
- CO environments → RL model base: configures model (evidence: `README.md`)
- Attention Model → RL model base: supplies policy (evidence: `README.md`)
- RL model base → Trainer: fits model (evidence: `README.md`)
- Training task → CO environments: instantiates (evidence: `rl4co/tasks/train.py`)
- Training task → RL model base: instantiates (evidence: `rl4co/tasks/train.py`)
- Training task → Trainer: runs training (evidence: `rl4co/tasks/train.py`)
- RL model base → CO environments: uses environment (evidence: `rl4co/models/rl/common/base.py`)
- RL model base → Data generation: uses generated data (evidence: `rl4co/models/rl/common/base.py`)
- CO environments → Dataset handling: loads datasets (evidence: `rl4co/envs/common/base.py`)
- EAS search → Action decoding: uses decoding (evidence: `rl4co/models/zoo/eas/search.py`)
- Active search → Data transforms: uses augmentation (evidence: `rl4co/models/zoo/active_search/search.py`)
- Policy evaluation → CO environments: scores actions (evidence: `rl4co/tasks/eval.py`)
- Policy evaluation → Policy families: evaluates policy (evidence: `rl4co/tasks/eval.py`)
