Fix distribute clustering with cbc/glpk/ipopt

Assume you have 10 nodes that need to be distributed between 2 countries.
What can happen with some of the open source solvers is that one country
gets assigned to 9.01 (float) nodes, and the other one to 0.99.

Now using .astype(int) would lead to a node distribution of 0 and 9, as
the `astype(int)` function round down by default (0.99 -> 0). This assigned
zero value breaks the code in case open source solvers are used.
Gurobi somehow does deal with it.
This commit is contained in:
Max Parzen 2021-11-24 14:16:24 +01:00
parent 1da908b956
commit f1243c3e0c

View File

@ -218,7 +218,7 @@ def distribute_clusters(n, n_clusters, focus_weights=None, solver_name=None):
results = opt.solve(m)
assert results['Solver'][0]['Status'] == 'ok', f"Solver returned non-optimally: {results}"
return pd.Series(m.n.get_values(), index=L.index).astype(int)
return pd.Series(m.n.get_values(), index=L.index).round().astype(int)
def busmap_for_n_clusters(n, n_clusters, solver_name, focus_weights=None, algorithm="kmeans", **algorithm_kwds):