The science
C_grid(v) = d_v * c_km + hh_v * c_conn line + household connections
C_mg(v) = hh_v * c_mg panels + battery + wiring
d*(hh) = hh (c_mg - c_conn) / c_km grid wins when d < d*
max sum hh_v x_v s.t. sum C_v x_v <= Budget, x_v in {0,1} (0/1 knapsack)
Each village is priced both ways and takes the cheaper one; then the budget is spent to power as many households as possible. Greedy (cheapest per household first) is fast and intuitive, but it can strand money that a different mix would have used. The optimal plan is found with a dynamic-programming knapsack in $100 units, exact for the stated model. Distance, village size and both unit costs move the crossover, so cheap solar pulls the far villages away from the grid first.
Simplifications. Illustrative numbers, not tariffs or a forecast. Each line runs straight to the substation (real lines follow roads and share trunks, so a cluster of villages is cheaper than separate lines); terrain, transformers, line losses, operating cost, fuel, tariffs and replacement of batteries are ignored; microgrid cost is a flat per-household price; a village is funded entirely or not at all; village layouts are random draws. The 3D scene offsets villages from the substation for legibility, distances in the numbers are exact.
Independent numerical checks compare the DP optimum against brute force over all subsets, test that greedy never beats the optimum and that both sit under the fractional (LP) bound, verify the closed-form crossover distance, budget conservation, and run 40,000 random plans as a Monte Carlo floor.
Not run yet.