Minimum Spanning Tree Solver is a C++ project that solves the MST problem using a linear programming formulation via IBM CPLEX and visualizes results using CDT (Conforming Delaunay Triangulation).
This project implements an exact solver for the Minimum Spanning Tree (MST) problem using integer programming (IP). IBM CPLEX is used as the solver backend. Results are visualized with CDT in SVG format, overlaying the MST on a Delaunay triangulation.
We want to find a tree spanning all n nodes with minimal total edge cost.
Let x_ij = 1 if edge (i, j) is part of the MST, and 0 otherwise.
Objective: Minimize total cost:
minimize ∑(i,j)∈E c_ij * x_ij
Constraints:
-
Tree contains exactly
n - 1edges:∑(i,j)∈E x_ij = n - 1 -
No cycles — subtour elimination:
∑(i,j)∈E, i∈S, j∈S x_ij ≤ |S| - 1 ∀S ⊂ V, |S| ≥ 3 -
Binary variables:
x_ij ∈ {0, 1}
This is an exponential-size IP, but its LP relaxation has integral extreme points, allowing it to be solved efficiently for MST.
- Language: C++20
- Vertices generation: Uniform distribution in 2D space
- Solver: IBM CPLEX
- LP Library: CPLEX Concert Technology
- Visualization: CDT
- Testing: GoogleTest
- Documentation: Doxygen
To apply the subtour elimination constraint, the solver enumerates all subsets of vertices with size ≥ 3 and < n. For each subset, a constraint is added that limits internal edges to at most |S| - 1.
Make sure to clone the repository with submodules:
git clone --recursive https://github.com/milosz275/minimum-spanning-tree.gitIf you've already cloned the repository without --recursive, run:
git submodule update --init --recursiveThis ensures the CDT library is properly initialized.
CPLEX is automatically located if installed in a standard path.
Simply open the folder in VSCode with the CMake extension, choose x64-release preset and run.
Run the following commands to configure and build the project:
cmake --preset x64-release -DCPLEX_ROOT="C:/Program Files/IBM/ILOG/CPLEX_Studio2212"
cmake --build --preset x64-release
.\out\build\x64-release\minimum-spanning-tree\minimum-spanning-tree.exeUse Developer PowerShell to ensure
cl.exeandCPLEXare in the environment.
Tests are located under minimum-spanning-tree/tests and cover:
- Subset generation
- Euclidean distance calculations
- Solver output consistency (planned)
To run tests via CLI:
ctest --preset x64-releaseOr run test_subsets.exe, test_common.exe directly from the build folder.
The solution is visualized using SVG:
- Gray edges: Delaunay triangulation
- Red edges: Final MST
- Blue dots: Input points (vertices)
Total MST cost: 116.491
SVG visualization written to mst_visualization.svg
Documentation is auto-generated from docstring via Doxygen and hosted via GitHub Pages:
To generate locally:
doxygenThis project is licensed under the MIT License.
