# pengguansheng09/toptw architecture

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

- Interactive diagram: https://gitdiagram.com/pengguansheng09/toptw
- Repository: https://github.com/pengguansheng09/toptw

## Overview

This repository implements an exact Branch-Price-Cuts solver for the Team Orienteering Problem with Time Windows (TOPTW). The user-facing workflow is a console run selecting an instance, loading and preprocessing its vertices and arcs, and solving it to produce routes and result files. Internally, the documented algorithm combines branch-and-bound, a restricted master problem, column generation with exact and heuristic pricing, and cuts; a primal heuristic can seek integer solutions. The excerpts show instance loading, labeling-based pricing, branching, and heuristic behavior. Some solver-to-subsystem links are dashed because the relevant call sites were not excerpted.

Main entry points: [`BranchNBound.cs`](https://github.com/pengguansheng09/toptw/blob/main/BranchNBound.cs) (Branch and bound), [`ColumnGeneration.cs`](https://github.com/pengguansheng09/toptw/blob/main/ColumnGeneration.cs) (Column generation), [`GlobalVar.cs`](https://github.com/pengguansheng09/toptw/blob/main/GlobalVar.cs) (Solver state), [`OPTW.cs`](https://github.com/pengguansheng09/toptw/blob/main/OPTW.cs) (OPTW solver)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Run and input"]
  node_runner["Console runner<br/>[Program.cs]"]
  node_loader["Instance loader<br/>[LoadData.cs]"]
  node_instance["TOPTW instances"]
  node_result["Solution results"]
end

subgraph group_search["Exact search"]
  node_optw["OPTW solver<br/>[OPTW.cs]"]
  node_branch["Branch and bound<br/>[BranchNBound.cs]"]
  node_branching["Branch rules<br/>[BranchScheme.cs]"]
  node_primal["Primal heuristic<br/>[PrimalHeuristic.cs]"]
  node_stack["Search stack<br/>[Stack.cs]"]
end

subgraph group_optimization["Column optimization"]
  node_cg["Column generation"]
  node_master["Master problem<br/>[MasterProblem.cs]"]
  node_pricing["Exact pricing<br/>[Pricing.cs]"]
  node_heurpricing["Heuristic pricing"]
  node_cuts["SRI cuts<br/>[SRIcuts.cs]"]
  node_algorithm["Algorithm model<br/>[ClassAlgorithm.cs]"]
  node_problem["Problem model<br/>[ClassProblem.cs]"]
end

subgraph group_support["Shared solver state"]
  node_globals["Solver state<br/>[GlobalVar.cs]"]
  node_queue["Label queue<br/>[Queue.cs]"]
  node_priority["Priority queue<br/>[PriorityQueue.cs]"]
end

node_user(("Solver user"))

node_user -->|"starts"| node_runner
node_runner -->|"loads instances"| node_loader
node_loader -->|"reads"| node_instance
node_runner -->|"starts solve"| node_optw
node_optw -.->|"writes output"| node_result
node_runner -->|"writes results"| node_result
node_optw -->|"uses state"| node_globals
node_optw -.->|"uses queue"| node_queue
node_optw -.->|"runs exact search"| node_branch
node_branch -->|"stores nodes"| node_stack
node_branch -->|"seeks incumbent"| node_primal
node_branch -.->|"creates children"| node_branching
node_branch -.->|"solves node LP"| node_cg
node_cg -.->|"optimizes relaxation"| node_master
node_cg -.->|"prices routes"| node_pricing
node_cg -.->|"prices heuristically"| node_heurpricing
node_cg -.->|"separates cuts"| node_cuts
node_pricing -->|"extends labels"| node_queue
node_pricing -->|"uses state"| node_globals
node_heurpricing -->|"uses state"| node_globals
node_primal -->|"uses state"| node_globals
node_branch -->|"uses state"| node_globals
node_cg -->|"uses state"| node_globals
node_algorithm -->|"uses parameters"| node_globals

click node_runner "https://github.com/pengguansheng09/toptw/blob/main/Program.cs"
click node_loader "https://github.com/pengguansheng09/toptw/blob/main/LoadData.cs"
click node_instance "https://github.com/pengguansheng09/toptw/tree/main/Data"
click node_result "https://github.com/pengguansheng09/toptw/tree/main/Results"
click node_optw "https://github.com/pengguansheng09/toptw/blob/main/OPTW.cs"
click node_branch "https://github.com/pengguansheng09/toptw/blob/main/BranchNBound.cs"
click node_branching "https://github.com/pengguansheng09/toptw/blob/main/BranchScheme.cs"
click node_primal "https://github.com/pengguansheng09/toptw/blob/main/PrimalHeuristic.cs"
click node_stack "https://github.com/pengguansheng09/toptw/blob/main/Stack.cs"
click node_cg "https://github.com/pengguansheng09/toptw/blob/main/ColumnGeneration.cs"
click node_master "https://github.com/pengguansheng09/toptw/blob/main/MasterProblem.cs"
click node_pricing "https://github.com/pengguansheng09/toptw/blob/main/Pricing.cs"
click node_heurpricing "https://github.com/pengguansheng09/toptw/blob/main/HeuristicPricing.cs"
click node_cuts "https://github.com/pengguansheng09/toptw/blob/main/SRIcuts.cs"
click node_algorithm "https://github.com/pengguansheng09/toptw/blob/main/ClassAlgorithm.cs"
click node_problem "https://github.com/pengguansheng09/toptw/blob/main/ClassProblem.cs"
click node_globals "https://github.com/pengguansheng09/toptw/blob/main/GlobalVar.cs"
click node_queue "https://github.com/pengguansheng09/toptw/blob/main/Queue.cs"
click node_priority "https://github.com/pengguansheng09/toptw/blob/main/PriorityQueue.cs"

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_runner,node_loader,node_instance,node_result,node_user toneBlue
class node_optw,node_branch,node_branching,node_primal,node_stack toneAmber
class node_cg,node_master,node_pricing,node_heurpricing,node_cuts,node_algorithm,node_problem toneMint
class node_globals,node_queue,node_priority toneRose
```

## Components

### Run and input

- [Console runner](https://github.com/pengguansheng09/toptw/blob/main/Program.cs): `Program.cs`
- [Instance loader](https://github.com/pengguansheng09/toptw/blob/main/LoadData.cs): `LoadData.cs`
- [TOPTW instances](https://github.com/pengguansheng09/toptw/tree/main/Data): `Data`
- [Solution results](https://github.com/pengguansheng09/toptw/tree/main/Results): `Results`

### Exact search

- [OPTW solver](https://github.com/pengguansheng09/toptw/blob/main/OPTW.cs): `OPTW.cs`
- [Branch and bound](https://github.com/pengguansheng09/toptw/blob/main/BranchNBound.cs): `BranchNBound.cs`
- [Branch rules](https://github.com/pengguansheng09/toptw/blob/main/BranchScheme.cs): `BranchScheme.cs`
- [Primal heuristic](https://github.com/pengguansheng09/toptw/blob/main/PrimalHeuristic.cs): `PrimalHeuristic.cs`
- [Search stack](https://github.com/pengguansheng09/toptw/blob/main/Stack.cs): `Stack.cs`

### Column optimization

- [Column generation](https://github.com/pengguansheng09/toptw/blob/main/ColumnGeneration.cs): `ColumnGeneration.cs`
- [Master problem](https://github.com/pengguansheng09/toptw/blob/main/MasterProblem.cs): `MasterProblem.cs`
- [Exact pricing](https://github.com/pengguansheng09/toptw/blob/main/Pricing.cs): `Pricing.cs`
- [Heuristic pricing](https://github.com/pengguansheng09/toptw/blob/main/HeuristicPricing.cs): `HeuristicPricing.cs`
- [SRI cuts](https://github.com/pengguansheng09/toptw/blob/main/SRIcuts.cs): `SRIcuts.cs`
- [Algorithm model](https://github.com/pengguansheng09/toptw/blob/main/ClassAlgorithm.cs): `ClassAlgorithm.cs`
- [Problem model](https://github.com/pengguansheng09/toptw/blob/main/ClassProblem.cs): `ClassProblem.cs`

### Shared solver state

- [Solver state](https://github.com/pengguansheng09/toptw/blob/main/GlobalVar.cs): `GlobalVar.cs`
- [Label queue](https://github.com/pengguansheng09/toptw/blob/main/Queue.cs): `Queue.cs`
- [Priority queue](https://github.com/pengguansheng09/toptw/blob/main/PriorityQueue.cs): `PriorityQueue.cs`

### Other components

- **Solver user**

## Connections

- Solver user → Console runner: starts (evidence: `README.md`)
- Console runner → Instance loader: loads instances (evidence: `Program.cs`)
- Instance loader → TOPTW instances: reads (evidence: `LoadData.cs`)
- Console runner → OPTW solver: starts solve (evidence: `Program.cs`)
- OPTW solver → Solution results: writes output
- Console runner → Solution results: writes results (evidence: `Program.cs`)
- OPTW solver → Solver state: uses state (evidence: `OPTW.cs`)
- OPTW solver → Label queue: uses queue (evidence: `OPTW.cs`)
- OPTW solver → Branch and bound: runs exact search
- Branch and bound → Search stack: stores nodes (evidence: `BranchNBound.cs`)
- Branch and bound → Primal heuristic: seeks incumbent (evidence: `BranchNBound.cs`)
- Branch and bound → Branch rules: creates children
- Branch and bound → Column generation: solves node LP
- Column generation → Master problem: optimizes relaxation
- Column generation → Exact pricing: prices routes
- Column generation → Heuristic pricing: prices heuristically
- Column generation → SRI cuts: separates cuts
- Exact pricing → Label queue: extends labels (evidence: `Pricing.cs`)
- Exact pricing → Solver state: uses state (evidence: `Pricing.cs`)
- Heuristic pricing → Solver state: uses state (evidence: `HeuristicPricing.cs`)
- Primal heuristic → Solver state: uses state (evidence: `PrimalHeuristic.cs`)
- Branch and bound → Solver state: uses state (evidence: `BranchNBound.cs`)
- Column generation → Solver state: uses state (evidence: `ColumnGeneration.cs`)
- Algorithm model → Solver state: uses parameters (evidence: `ClassAlgorithm.cs`)
