# d-krupke/cpsat-primer architecture

> Architecture diagram of the GitHub repository d-krupke/cpsat-primer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/d-krupke/cpsat-primer
- Repository: https://github.com/d-krupke/cpsat-primer

## Overview

This checkout contains evaluation code for facility location, rectangle packing, and travelling-salesperson problems—not the primer’s chapter sources. Its practical workflow is to load or define problem instances, run solver variants, and analyze benchmark results. The README describes broader CP-SAT teaching topics, but their implementation is not present in this file tree, so they are not represented as code components. Relationships below are limited to calls shown in excerpts and documented module references; unsampled wiring is omitted.

Main entry points: [`evaluations/packing/01_run_benchmark.py`](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/packing/01_run_benchmark.py) (Packing benchmark), [`evaluations/tsp/2023-11-18_tsplib/_conf.py`](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_tsplib/_conf.py) (Solver configuration), [`evaluations/packing/solver/_instance.py`](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/packing/solver/_instance.py) (Packing data types), [`evaluations/flp/01_run_benchmark.py`](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/flp/01_run_benchmark.py) (FLP benchmark)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_flp["Facility location"]
  node_flp_runner["FLP benchmark"]
  node_flp_schema["FLP instances<br/>[instance_schema.py]"]
  node_flp_solvers["FLP solvers<br/>[solve.py]"]
end

subgraph group_packing["Rectangle packing"]
  node_packing_runner["Packing benchmark"]
  node_packing_types["Packing data types<br/>[_instance.py]"]
  node_pack_plain["Packing no rotation"]
  node_pack_rot["Packing with rotation"]
  node_knapsack_plain["Knapsack no rotation"]
  node_knapsack_rot["Knapsack with rotation"]
  node_squeeze["Smallest box"]
  node_packing_plot["Packing plots<br/>[_plotting.py]"]
end

subgraph group_tsp["TSP evaluation"]
  node_tsp_generator["Instance generation"]
  node_tsp_tsplib_runner["TSPLIB benchmark"]
  node_tsp_random_runner["Euclidean benchmark"]
  node_tsp_config["Solver configuration<br/>[_conf.py]"]
  node_tsp_db[("Graph instance store<br/>[graph_db.py]")]
  node_tsp_cpsat1["CP-SAT v1<br/>[cpsat_v1.py]"]
  node_tsp_cpsat2["CP-SAT v2<br/>[cpsat_v2.py]"]
  node_tsp_cpsat3["CP-SAT v3<br/>[cpsat_v3.py]"]
  node_tsp_mip["MIP solver<br/>[mip.py]"]
  node_tsp_extract["Result extraction<br/>[03_extract_data.py]"]
end

subgraph group_analysis["Benchmark analysis"]
  node_flp_profile["FLP profiles"]
  node_flp_scatter["FLP scatter plots"]
  node_tsp_profile["TSP profiles"]
  node_tsp_scatter["TSP scatter plots"]
  node_random_profile["Euclidean profiles"]
  node_random_scatter["Euclidean scatter plots"]
end

node_user(("Benchmark user"))

node_user -->|"runs benchmark"| node_flp_runner
node_flp_runner -->|"loads instances"| node_flp_schema
node_flp_runner -->|"invokes solvers"| node_flp_solvers
node_flp_solvers -->|"uses instance"| node_flp_schema
node_user -->|"runs benchmark"| node_packing_runner
node_packing_runner -->|"validates input"| node_packing_types
node_packing_runner -->|"solves packing"| node_pack_plain
node_packing_runner -->|"solves packing"| node_pack_rot
node_packing_runner -->|"solves knapsack"| node_knapsack_rot
node_packing_runner -->|"solves knapsack"| node_knapsack_plain
node_packing_runner -->|"solves sizing"| node_squeeze
node_pack_plain -->|"uses data types"| node_packing_types
node_pack_rot -->|"uses data types"| node_packing_types
node_knapsack_plain -->|"uses data types"| node_packing_types
node_knapsack_rot -->|"uses data types"| node_packing_types
node_squeeze -->|"uses data types"| node_packing_types
node_user -->|"generates instances"| node_tsp_generator
node_user -->|"runs benchmark"| node_tsp_tsplib_runner
node_user -->|"runs benchmark"| node_tsp_random_runner
node_tsp_config -->|"selects strategy"| node_tsp_cpsat1
node_tsp_config -->|"selects strategy"| node_tsp_cpsat2
node_tsp_config -->|"selects strategy"| node_tsp_cpsat3
node_tsp_config -->|"selects strategy"| node_tsp_mip
node_tsp_tsplib_runner -->|"uses configuration"| node_tsp_config
node_tsp_random_runner -->|"uses configuration"| node_tsp_config
node_tsp_tsplib_runner -.->|"uses instance store"| node_tsp_db
node_tsp_generator -.->|"stores instances"| node_tsp_db
node_user -->|"extracts results"| node_tsp_extract

click node_flp_runner "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/flp/01_run_benchmark.py"
click node_flp_schema "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/flp/instance_schema.py"
click node_flp_solvers "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/flp/solve.py"
click node_flp_profile "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/flp/performance_profile.py"
click node_flp_scatter "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/flp/scatter_with_performance_zones.py"
click node_packing_runner "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/packing/01_run_benchmark.py"
click node_packing_types "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/packing/solver/_instance.py"
click node_pack_plain "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/packing/solver/packing_wo_rotations.py"
click node_pack_rot "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/packing/solver/packing_with_rotations.py"
click node_knapsack_plain "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/packing/solver/knapsack_wo_rotations.py"
click node_knapsack_rot "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/packing/solver/knapsack_with_rotations.py"
click node_squeeze "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/packing/solver/smallestbox_wo_rotations.py"
click node_packing_plot "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/packing/solver/_plotting.py"
click node_tsp_generator "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_random_euclidean/00_generate_instances.py"
click node_tsp_tsplib_runner "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_tsplib/01_run_benchmark.py"
click node_tsp_random_runner "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_random_euclidean/01_run_benchmark.py"
click node_tsp_config "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_tsplib/_conf.py"
click node_tsp_db "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_tsplib/_utils/graph_db.py"
click node_tsp_cpsat1 "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_tsplib/solver/cpsat_v1.py"
click node_tsp_cpsat2 "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_tsplib/solver/cpsat_v2.py"
click node_tsp_cpsat3 "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_tsplib/solver/cpsat_v3.py"
click node_tsp_mip "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_tsplib/solver/mip.py"
click node_tsp_extract "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_tsplib/03_extract_data.py"
click node_tsp_profile "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_tsplib/performance_profile.py"
click node_tsp_scatter "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_tsplib/scatter_with_performance_zones.py"
click node_random_profile "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_random_euclidean/performance_profile.py"
click node_random_scatter "https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_random_euclidean/scatter_with_performance_zones.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_flp_runner,node_flp_schema,node_flp_solvers,node_user toneBlue
class node_packing_runner,node_packing_types,node_pack_plain,node_pack_rot,node_knapsack_plain,node_knapsack_rot,node_squeeze,node_packing_plot toneAmber
class node_tsp_generator,node_tsp_tsplib_runner,node_tsp_random_runner,node_tsp_config,node_tsp_db,node_tsp_cpsat1,node_tsp_cpsat2,node_tsp_cpsat3,node_tsp_mip,node_tsp_extract toneMint
class node_flp_profile,node_flp_scatter,node_tsp_profile,node_tsp_scatter,node_random_profile,node_random_scatter toneRose
```

## Components

### Facility location

- [FLP benchmark](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/flp/01_run_benchmark.py): `evaluations/flp/01_run_benchmark.py`
- [FLP instances](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/flp/instance_schema.py): `evaluations/flp/instance_schema.py`
- [FLP solvers](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/flp/solve.py): `evaluations/flp/solve.py`

### Rectangle packing

- [Packing benchmark](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/packing/01_run_benchmark.py): `evaluations/packing/01_run_benchmark.py`
- [Packing data types](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/packing/solver/_instance.py): `evaluations/packing/solver/_instance.py`
- [Packing no rotation](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/packing/solver/packing_wo_rotations.py): `evaluations/packing/solver/packing_wo_rotations.py`
- [Packing with rotation](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/packing/solver/packing_with_rotations.py): `evaluations/packing/solver/packing_with_rotations.py`
- [Knapsack no rotation](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/packing/solver/knapsack_wo_rotations.py): `evaluations/packing/solver/knapsack_wo_rotations.py`
- [Knapsack with rotation](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/packing/solver/knapsack_with_rotations.py): `evaluations/packing/solver/knapsack_with_rotations.py`
- [Smallest box](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/packing/solver/smallestbox_wo_rotations.py): `evaluations/packing/solver/smallestbox_wo_rotations.py`
- [Packing plots](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/packing/solver/_plotting.py): `evaluations/packing/solver/_plotting.py`

### TSP evaluation

- [Instance generation](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_random_euclidean/00_generate_instances.py): `evaluations/tsp/2023-11-18_random_euclidean/00_generate_instances.py`
- [TSPLIB benchmark](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_tsplib/01_run_benchmark.py): `evaluations/tsp/2023-11-18_tsplib/01_run_benchmark.py`
- [Euclidean benchmark](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_random_euclidean/01_run_benchmark.py): `evaluations/tsp/2023-11-18_random_euclidean/01_run_benchmark.py`
- [Solver configuration](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_tsplib/_conf.py): `evaluations/tsp/2023-11-18_tsplib/_conf.py`
- [Graph instance store](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_tsplib/_utils/graph_db.py): `evaluations/tsp/2023-11-18_tsplib/_utils/graph_db.py`
- [CP-SAT v1](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_tsplib/solver/cpsat_v1.py): `evaluations/tsp/2023-11-18_tsplib/solver/cpsat_v1.py`
- [CP-SAT v2](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_tsplib/solver/cpsat_v2.py): `evaluations/tsp/2023-11-18_tsplib/solver/cpsat_v2.py`
- [CP-SAT v3](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_tsplib/solver/cpsat_v3.py): `evaluations/tsp/2023-11-18_tsplib/solver/cpsat_v3.py`
- [MIP solver](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_tsplib/solver/mip.py): `evaluations/tsp/2023-11-18_tsplib/solver/mip.py`
- [Result extraction](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_tsplib/03_extract_data.py): `evaluations/tsp/2023-11-18_tsplib/03_extract_data.py`

### Benchmark analysis

- [FLP profiles](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/flp/performance_profile.py): `evaluations/flp/performance_profile.py`
- [FLP scatter plots](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/flp/scatter_with_performance_zones.py): `evaluations/flp/scatter_with_performance_zones.py`
- [TSP profiles](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_tsplib/performance_profile.py): `evaluations/tsp/2023-11-18_tsplib/performance_profile.py`
- [TSP scatter plots](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_tsplib/scatter_with_performance_zones.py): `evaluations/tsp/2023-11-18_tsplib/scatter_with_performance_zones.py`
- [Euclidean profiles](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_random_euclidean/performance_profile.py): `evaluations/tsp/2023-11-18_random_euclidean/performance_profile.py`
- [Euclidean scatter plots](https://github.com/d-krupke/cpsat-primer/blob/main/evaluations/tsp/2023-11-18_random_euclidean/scatter_with_performance_zones.py): `evaluations/tsp/2023-11-18_random_euclidean/scatter_with_performance_zones.py`

### Other components

- **Benchmark user**

## Connections

- Benchmark user → FLP benchmark: runs benchmark (evidence: `evaluations/flp/01_run_benchmark.py`)
- FLP benchmark → FLP instances: loads instances (evidence: `evaluations/flp/01_run_benchmark.py`)
- FLP benchmark → FLP solvers: invokes solvers (evidence: `evaluations/flp/01_run_benchmark.py`)
- FLP solvers → FLP instances: uses instance (evidence: `evaluations/flp/solve.py`)
- Benchmark user → Packing benchmark: runs benchmark (evidence: `evaluations/packing/01_run_benchmark.py`)
- Packing benchmark → Packing data types: validates input (evidence: `evaluations/packing/01_run_benchmark.py`)
- Packing benchmark → Packing no rotation: solves packing (evidence: `evaluations/packing/01_run_benchmark.py`)
- Packing benchmark → Packing with rotation: solves packing (evidence: `evaluations/packing/01_run_benchmark.py`)
- Packing benchmark → Knapsack with rotation: solves knapsack (evidence: `evaluations/packing/01_run_benchmark.py`)
- Packing benchmark → Knapsack no rotation: solves knapsack (evidence: `evaluations/packing/01_run_benchmark.py`)
- Packing benchmark → Smallest box: solves sizing (evidence: `evaluations/packing/01_run_benchmark.py`)
- Packing no rotation → Packing data types: uses data types (evidence: `evaluations/packing/solver/packing_wo_rotations.py`)
- Packing with rotation → Packing data types: uses data types (evidence: `evaluations/packing/solver/packing_with_rotations.py`)
- Knapsack no rotation → Packing data types: uses data types (evidence: `evaluations/packing/solver/knapsack_wo_rotations.py`)
- Knapsack with rotation → Packing data types: uses data types (evidence: `evaluations/packing/solver/knapsack_with_rotations.py`)
- Smallest box → Packing data types: uses data types (evidence: `evaluations/packing/solver/smallestbox_wo_rotations.py`)
- Benchmark user → Instance generation: generates instances (evidence: `evaluations/tsp/2023-11-18_random_euclidean/00_generate_instances.py`)
- Benchmark user → TSPLIB benchmark: runs benchmark (evidence: `evaluations/tsp/2023-11-18_tsplib/01_run_benchmark.py`)
- Benchmark user → Euclidean benchmark: runs benchmark (evidence: `evaluations/tsp/2023-11-18_random_euclidean/01_run_benchmark.py`)
- Solver configuration → CP-SAT v1: selects strategy (evidence: `evaluations/tsp/2023-11-18_tsplib/_conf.py`)
- Solver configuration → CP-SAT v2: selects strategy (evidence: `evaluations/tsp/2023-11-18_tsplib/_conf.py`)
- Solver configuration → CP-SAT v3: selects strategy (evidence: `evaluations/tsp/2023-11-18_tsplib/_conf.py`)
- Solver configuration → MIP solver: selects strategy (evidence: `evaluations/tsp/2023-11-18_tsplib/_conf.py`)
- TSPLIB benchmark → Solver configuration: uses configuration (evidence: `evaluations/tsp/2023-11-18_tsplib/01_run_benchmark.py`)
- Euclidean benchmark → Solver configuration: uses configuration (evidence: `evaluations/tsp/2023-11-18_random_euclidean/01_run_benchmark.py`)
- TSPLIB benchmark → Graph instance store: uses instance store
- Instance generation → Graph instance store: stores instances
- Benchmark user → Result extraction: extracts results (evidence: `evaluations/tsp/2023-11-18_tsplib/03_extract_data.py`)
