A Python package for solving Steiner Tree and Steiner Forest Problems using the HiGHS solver and NetworkX graphs.
Install SteinerPy from PyPI:
pip install steinerpyOr using uv:
uv add steinerpy- Python 3.8+
- NetworkX
- HiGHS Solver (via highspy)
import networkx as nx
from steinerpy import SteinerProblem
# Create a graph
G = nx.Graph()
G.add_edge('A', 'B', weight=1)
G.add_edge('B', 'C', weight=2)
G.add_edge('C', 'D', weight=1)
# Define terminal groups
terminal_groups = [['A', 'D']]
# Solve the Steiner problem
problem = SteinerProblem(G, terminal_groups)
solution = problem.get_solution()
print(f"Optimal cost: {solution.objective}")
print(f"Selected edges: {solution.selected_edges}")See the example.ipynb notebook for detailed usage examples.
networkx: For graph representation and manipulationhighspy: For optimization solving
If you use this package in your research, please cite:
@article{markhorst2025future,
title={Future-proof ship pipe routing: Navigating the energy transition},
author={Markhorst, Berend and Berkhout, Joost and Zocca, Alessandro and Pruyn, Jeroen and van der Mei, Rob},
journal={Ocean Engineering},
volume={319},
pages={120113},
year={2025},
publisher={Elsevier}
}