This code was developed during research on community network design in Sub-Saharan Africa. We assumed average per-node connection costs vary with the number of nodes connected in a community network. For example, a community with clustered households and small businesses may require only 15m of low-voltage (LV) wire per node to connect the concentrated area. When expanding to connect more dispersed households throughout the community, the LV wire requirement can increase to 30m per node or more. This represents the simplest case. More complex and interesting scenarios should exist in real communities.
Given a community with scattered demand node locations (households, businesses, etc.), we decide:
-
A strategic center as the network root - this could be: trading center, generation set location, main productive load facility, health facilities, other community anchor points ...
-
The number k of demand nodes to connect by adjusting the k parameter to analyze different community coverage scenarios and their associated electric wire requirements
And, the model designs the network connecting k nodes with the least length of electric wire requirement.
The optimization results provide valuable proxies and estimations for electrification planning, such as:
- Phased rollout strategies - Determine optimal sequencing for connecting households as budgets become available
- Infrastructure investment planning - Estimate total wire requirements for different coverage scenarios
- Per-household connection costs at various scales (e.g., cost curves showing how unit costs change from 20 to 50 to 100 connected homes). This would be an important metric to consider when doing electrification planning. Also, the marginal cost insights of the network at different scales.
This makes the tool valuable for strategic planning around rural electrification and energy access policy. However, this model is purely mathematical, calculating proxies without incorporating physical infrastructure constraints or local demand variations. It treats every demand node with equal weight and does not consider line capacity limitations. For more detailed network planning, additional physical constraints and localized demand data should be integrated into the model.
A Mixed Integer Linear Programming (MILP) solver for the k-Minimum Spanning Tree (k-MST) problem using Gurobi optimization. This tool finds the optimal subset of k nodes to connect in a network, minimizing the total connection cost while ensuring all selected nodes form a connected tree rooted at a central node.
- Efficient k-MST Solution: Uses directed flow formulation with edge pruning for better performance
- Scalable: Supports up to 1,500 nodes
- Geospatial Output: Exports results as GeoJSON files
Solves the k-MST optimization problem.
Parameters:
coords: List/array of candidate node coordinates (excluding root)c_coords: Root node coordinatesk: Number of nodes to connect (including root)mip_gap: MIP gap tolerance for Gurobi solvertime_limit: Maximum solving time in seconds
Returns:
selected_nodes: List of selected node labelsselected_edges: List of selected edges with weights
numpy
geopandas
gurobipy
shapelypython radical_kmst_network_optimizer.pyThe code includes randomly generated sample demand nodes for illustration purposes. Always replace this section with your own data when adapting the tool for your specific use case.
The solver generates:
nodes.geojson: All nodes with selection statusedges.geojson: Selected network edgessummary.txt: Solution statistics