# sobihansurendran/lgs architecture

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

- Interactive diagram: https://gitdiagram.com/sobihansurendran/lgs
- Repository: https://github.com/sobihansurendran/lgs

## Overview

This repository implements Latent Guided Sampling for TSP and CVRP. The principal workflow is to configure and train a problem-specific latent-space model, or run inference on saved instances using provided pretrained weights; the README describes LGS inference as using MCMC and stochastic approximation. Sampled trainer and environment code establishes some internal calls, while inference wiring and most test-script behavior were not sampled, so those links are omitted or marked unverified.

Main entry points: [`TSP/test.py`](https://github.com/sobihansurendran/lgs/blob/main/TSP/test.py) (TSP inference), [`CVRP/test.py`](https://github.com/sobihansurendran/lgs/blob/main/CVRP/test.py) (CVRP inference), [`TSP/train.py`](https://github.com/sobihansurendran/lgs/blob/main/TSP/train.py) (TSP trainer), [`CVRP/train.py`](https://github.com/sobihansurendran/lgs/blob/main/CVRP/train.py) (CVRP trainer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_tsp["TSP runtime"]
  node_tsp_train_cli["TSP train command<br/>[run_train.py]"]
  node_tsp_trainer["TSP trainer<br/>[train.py]"]
  node_tsp_model["TSP latent model<br/>[model.py]"]
  node_tsp_env["TSP environment<br/>[env.py]"]
  node_tsp_problem["TSP instances<br/>[problem.py]"]
  node_tsp_test_cmd["TSP inference command<br/>[run_test.py]"]
  node_tsp_test["TSP inference<br/>[test.py]"]
end

subgraph group_cvrp["CVRP runtime"]
  node_cvrp_train_cli["CVRP train command<br/>[run_train.py]"]
  node_cvrp_trainer["CVRP trainer<br/>[train.py]"]
  node_cvrp_model["CVRP latent model<br/>[model.py]"]
  node_cvrp_env["CVRP environment<br/>[env.py]"]
  node_cvrp_problem["CVRP instances<br/>[problem.py]"]
  node_cvrp_test_cmd["CVRP inference command<br/>[run_test.py]"]
  node_cvrp_test["CVRP inference<br/>[test.py]"]
end

subgraph group_assets["Problem assets"]
  node_tsp_data[("TSP saved instances")]
  node_tsp_weights["TSP pretrained weights<br/>[TSP_100_LGS_Net.pt]"]
  node_cvrp_data[("CVRP saved instances")]
  node_cvrp_weights["CVRP pretrained weights"]
end

subgraph group_learning["Learning method"]
  node_lgs_inference["LGS sampling"]
  node_mcmc["MCMC"]
  node_stochastic_approx["Stochastic approximation"]
end

node_user(("Engineer"))

node_user -->|"runs training"| node_tsp_train_cli
node_user -->|"runs inference"| node_tsp_test_cmd
node_user -.->|"runs training"| node_cvrp_train_cli
node_user -.->|"runs inference"| node_cvrp_test_cmd
node_tsp_train_cli -->|"calls"| node_tsp_trainer
node_tsp_trainer -->|"creates"| node_tsp_model
node_tsp_trainer -->|"creates"| node_tsp_env
node_tsp_env -->|"generates instances"| node_tsp_problem
node_cvrp_train_cli -->|"calls"| node_cvrp_trainer
node_cvrp_trainer -->|"creates"| node_cvrp_model
node_cvrp_trainer -->|"creates"| node_cvrp_env
node_cvrp_env -->|"generates instances"| node_cvrp_problem
node_tsp_test_cmd -.->|"dispatches"| node_tsp_test
node_cvrp_test_cmd -.->|"dispatches"| node_cvrp_test
node_tsp_test -.->|"uses for inference"| node_tsp_model
node_cvrp_test -.->|"uses for inference"| node_cvrp_model
node_tsp_test -.->|"loads instances"| node_tsp_data
node_cvrp_test -.->|"loads instances"| node_cvrp_data
node_tsp_test -.->|"loads weights"| node_tsp_weights
node_cvrp_test -.->|"loads weights"| node_cvrp_weights
node_tsp_test -.->|"runs sampling"| node_lgs_inference
node_cvrp_test -.->|"runs sampling"| node_lgs_inference
node_lgs_inference -->|"uses"| node_mcmc
node_lgs_inference -->|"uses"| node_stochastic_approx

click node_tsp_train_cli "https://github.com/sobihansurendran/lgs/blob/main/TSP/run_train.py"
click node_tsp_trainer "https://github.com/sobihansurendran/lgs/blob/main/TSP/train.py"
click node_tsp_model "https://github.com/sobihansurendran/lgs/blob/main/TSP/model.py"
click node_tsp_env "https://github.com/sobihansurendran/lgs/blob/main/TSP/env.py"
click node_tsp_problem "https://github.com/sobihansurendran/lgs/blob/main/TSP/problem.py"
click node_tsp_test_cmd "https://github.com/sobihansurendran/lgs/blob/main/TSP/run_test.py"
click node_tsp_test "https://github.com/sobihansurendran/lgs/blob/main/TSP/test.py"
click node_cvrp_train_cli "https://github.com/sobihansurendran/lgs/blob/main/CVRP/run_train.py"
click node_cvrp_trainer "https://github.com/sobihansurendran/lgs/blob/main/CVRP/train.py"
click node_cvrp_model "https://github.com/sobihansurendran/lgs/blob/main/CVRP/model.py"
click node_cvrp_env "https://github.com/sobihansurendran/lgs/blob/main/CVRP/env.py"
click node_cvrp_problem "https://github.com/sobihansurendran/lgs/blob/main/CVRP/problem.py"
click node_cvrp_test_cmd "https://github.com/sobihansurendran/lgs/blob/main/CVRP/run_test.py"
click node_cvrp_test "https://github.com/sobihansurendran/lgs/blob/main/CVRP/test.py"
click node_tsp_data "https://github.com/sobihansurendran/lgs/tree/main/TSP/data"
click node_tsp_weights "https://github.com/sobihansurendran/lgs/blob/main/TSP/model/TSP_100_LGS_Net.pt"
click node_cvrp_data "https://github.com/sobihansurendran/lgs/tree/main/CVRP/data"
click node_cvrp_weights "https://github.com/sobihansurendran/lgs/blob/main/CVRP/model/CVRP_100_LGS_Net.pt"

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_tsp_train_cli,node_tsp_trainer,node_tsp_model,node_tsp_env,node_tsp_problem,node_tsp_test_cmd,node_tsp_test toneBlue
class node_cvrp_train_cli,node_cvrp_trainer,node_cvrp_model,node_cvrp_env,node_cvrp_problem,node_cvrp_test_cmd,node_cvrp_test toneAmber
class node_tsp_data,node_tsp_weights,node_cvrp_data,node_cvrp_weights toneMint
class node_lgs_inference,node_mcmc,node_stochastic_approx toneRose
class node_user toneIndigo
```

## Components

### TSP runtime

- [TSP train command](https://github.com/sobihansurendran/lgs/blob/main/TSP/run_train.py): `TSP/run_train.py`
- [TSP trainer](https://github.com/sobihansurendran/lgs/blob/main/TSP/train.py): `TSP/train.py`
- [TSP latent model](https://github.com/sobihansurendran/lgs/blob/main/TSP/model.py): `TSP/model.py`
- [TSP environment](https://github.com/sobihansurendran/lgs/blob/main/TSP/env.py): `TSP/env.py`
- [TSP instances](https://github.com/sobihansurendran/lgs/blob/main/TSP/problem.py): `TSP/problem.py`
- [TSP inference command](https://github.com/sobihansurendran/lgs/blob/main/TSP/run_test.py): `TSP/run_test.py`
- [TSP inference](https://github.com/sobihansurendran/lgs/blob/main/TSP/test.py): `TSP/test.py`

### CVRP runtime

- [CVRP train command](https://github.com/sobihansurendran/lgs/blob/main/CVRP/run_train.py): `CVRP/run_train.py`
- [CVRP trainer](https://github.com/sobihansurendran/lgs/blob/main/CVRP/train.py): `CVRP/train.py`
- [CVRP latent model](https://github.com/sobihansurendran/lgs/blob/main/CVRP/model.py): `CVRP/model.py`
- [CVRP environment](https://github.com/sobihansurendran/lgs/blob/main/CVRP/env.py): `CVRP/env.py`
- [CVRP instances](https://github.com/sobihansurendran/lgs/blob/main/CVRP/problem.py): `CVRP/problem.py`
- [CVRP inference command](https://github.com/sobihansurendran/lgs/blob/main/CVRP/run_test.py): `CVRP/run_test.py`
- [CVRP inference](https://github.com/sobihansurendran/lgs/blob/main/CVRP/test.py): `CVRP/test.py`

### Problem assets

- [TSP saved instances](https://github.com/sobihansurendran/lgs/tree/main/TSP/data): `TSP/data`
- [TSP pretrained weights](https://github.com/sobihansurendran/lgs/blob/main/TSP/model/TSP_100_LGS_Net.pt): `TSP/model/TSP_100_LGS_Net.pt`
- [CVRP saved instances](https://github.com/sobihansurendran/lgs/tree/main/CVRP/data): `CVRP/data`
- [CVRP pretrained weights](https://github.com/sobihansurendran/lgs/blob/main/CVRP/model/CVRP_100_LGS_Net.pt): `CVRP/model/CVRP_100_LGS_Net.pt`

### Learning method

- **LGS sampling**
- **MCMC**
- **Stochastic approximation**

### Other components

- **Engineer**

## Connections

- Engineer → TSP train command: runs training (evidence: `README.md`)
- Engineer → TSP inference command: runs inference (evidence: `README.md`)
- Engineer → CVRP train command: runs training
- Engineer → CVRP inference command: runs inference
- TSP train command → TSP trainer: calls (evidence: `TSP/run_train.py`)
- TSP trainer → TSP latent model: creates (evidence: `TSP/train.py`)
- TSP trainer → TSP environment: creates (evidence: `TSP/train.py`)
- TSP environment → TSP instances: generates instances (evidence: `TSP/env.py`)
- CVRP train command → CVRP trainer: calls (evidence: `CVRP/run_train.py`)
- CVRP trainer → CVRP latent model: creates (evidence: `CVRP/train.py`)
- CVRP trainer → CVRP environment: creates (evidence: `CVRP/train.py`)
- CVRP environment → CVRP instances: generates instances (evidence: `CVRP/env.py`)
- TSP inference command → TSP inference: dispatches
- CVRP inference command → CVRP inference: dispatches
- TSP inference → TSP latent model: uses for inference
- CVRP inference → CVRP latent model: uses for inference
- TSP inference → TSP saved instances: loads instances
- CVRP inference → CVRP saved instances: loads instances
- TSP inference → TSP pretrained weights: loads weights
- CVRP inference → CVRP pretrained weights: loads weights
- TSP inference → LGS sampling: runs sampling
- CVRP inference → LGS sampling: runs sampling
- LGS sampling → MCMC: uses (evidence: `README.md`)
- LGS sampling → Stochastic approximation: uses (evidence: `README.md`)
