solve_network: Remove hard-coded solver fallback in busmap_for_n_clusters
Necessary for when `clustering_for_n_clusters` is used from the simplify_network rule. Fixes #12
This commit is contained in:
parent
6f1b387804
commit
9279c7f027
@ -93,7 +93,7 @@ def distribute_clusters(n, n_clusters, solver_name=None):
|
|||||||
|
|
||||||
return pd.Series(m.n.get_values(), index=L.index).astype(int)
|
return pd.Series(m.n.get_values(), index=L.index).astype(int)
|
||||||
|
|
||||||
def busmap_for_n_clusters(n, n_clusters, algorithm="kmeans", **algorithm_kwds):
|
def busmap_for_n_clusters(n, n_clusters, solver_name, algorithm="kmeans", **algorithm_kwds):
|
||||||
if algorithm == "kmeans":
|
if algorithm == "kmeans":
|
||||||
algorithm_kwds.setdefault('n_init', 1000)
|
algorithm_kwds.setdefault('n_init', 1000)
|
||||||
algorithm_kwds.setdefault('max_iter', 30000)
|
algorithm_kwds.setdefault('max_iter', 30000)
|
||||||
@ -101,11 +101,6 @@ def busmap_for_n_clusters(n, n_clusters, algorithm="kmeans", **algorithm_kwds):
|
|||||||
|
|
||||||
n.determine_network_topology()
|
n.determine_network_topology()
|
||||||
|
|
||||||
if 'snakemake' in globals():
|
|
||||||
solver_name = snakemake.config['solving']['solver']['name']
|
|
||||||
else:
|
|
||||||
solver_name = "gurobi"
|
|
||||||
|
|
||||||
n_clusters = distribute_clusters(n, n_clusters, solver_name=solver_name)
|
n_clusters = distribute_clusters(n, n_clusters, solver_name=solver_name)
|
||||||
|
|
||||||
def reduce_network(n, buses):
|
def reduce_network(n, buses):
|
||||||
@ -140,7 +135,8 @@ def plot_busmap_for_n_clusters(n, n_clusters=50):
|
|||||||
del cs, cr
|
del cs, cr
|
||||||
|
|
||||||
def clustering_for_n_clusters(n, n_clusters, aggregate_carriers=None,
|
def clustering_for_n_clusters(n, n_clusters, aggregate_carriers=None,
|
||||||
line_length_factor=1.25, potential_mode='simple', algorithm="kmeans"):
|
line_length_factor=1.25, potential_mode='simple',
|
||||||
|
solver_name="cbc", algorithm="kmeans"):
|
||||||
|
|
||||||
if potential_mode == 'simple':
|
if potential_mode == 'simple':
|
||||||
p_nom_max_strategy = np.sum
|
p_nom_max_strategy = np.sum
|
||||||
@ -151,7 +147,7 @@ def clustering_for_n_clusters(n, n_clusters, aggregate_carriers=None,
|
|||||||
"but is '{}'".format(potential_mode))
|
"but is '{}'".format(potential_mode))
|
||||||
|
|
||||||
clustering = get_clustering_from_busmap(
|
clustering = get_clustering_from_busmap(
|
||||||
n, busmap_for_n_clusters(n, n_clusters, algorithm),
|
n, busmap_for_n_clusters(n, n_clusters, solver_name, algorithm),
|
||||||
bus_strategies=dict(country=_make_consense("Bus", "country")),
|
bus_strategies=dict(country=_make_consense("Bus", "country")),
|
||||||
aggregate_generators_weighted=True,
|
aggregate_generators_weighted=True,
|
||||||
aggregate_generators_carriers=aggregate_carriers,
|
aggregate_generators_carriers=aggregate_carriers,
|
||||||
@ -233,7 +229,8 @@ if __name__ == "__main__":
|
|||||||
for tech in renewable_carriers]))
|
for tech in renewable_carriers]))
|
||||||
clustering = clustering_for_n_clusters(n, n_clusters, aggregate_carriers,
|
clustering = clustering_for_n_clusters(n, n_clusters, aggregate_carriers,
|
||||||
line_length_factor=line_length_factor,
|
line_length_factor=line_length_factor,
|
||||||
potential_mode=potential_mode)
|
potential_mode=potential_mode,
|
||||||
|
solver_name=snakemake.config['solving']['solver']['name'])
|
||||||
|
|
||||||
clustering.network.export_to_netcdf(snakemake.output.network)
|
clustering.network.export_to_netcdf(snakemake.output.network)
|
||||||
with pd.HDFStore(snakemake.output.clustermaps, mode='w') as store:
|
with pd.HDFStore(snakemake.output.clustermaps, mode='w') as store:
|
||||||
|
@ -21,9 +21,7 @@ from six.moves import reduce
|
|||||||
|
|
||||||
import pypsa
|
import pypsa
|
||||||
from pypsa.io import import_components_from_dataframe, import_series_from_dataframe
|
from pypsa.io import import_components_from_dataframe, import_series_from_dataframe
|
||||||
from pypsa.networkclustering import (busmap_by_stubs, busmap_by_kmeans,
|
from pypsa.networkclustering import busmap_by_stubs, aggregategenerators, aggregateoneport
|
||||||
_make_consense, get_clustering_from_busmap,
|
|
||||||
aggregategenerators, aggregateoneport)
|
|
||||||
|
|
||||||
from cluster_network import clustering_for_n_clusters, cluster_regions
|
from cluster_network import clustering_for_n_clusters, cluster_regions
|
||||||
from add_electricity import load_costs
|
from add_electricity import load_costs
|
||||||
@ -254,7 +252,8 @@ def cluster(n, n_clusters):
|
|||||||
potential_mode = (consense(pd.Series([snakemake.config['renewable'][tech]['potential']
|
potential_mode = (consense(pd.Series([snakemake.config['renewable'][tech]['potential']
|
||||||
for tech in renewable_carriers]))
|
for tech in renewable_carriers]))
|
||||||
if len(renewable_carriers) > 0 else 'conservative')
|
if len(renewable_carriers) > 0 else 'conservative')
|
||||||
clustering = clustering_for_n_clusters(n, n_clusters, potential_mode=potential_mode)
|
clustering = clustering_for_n_clusters(n, n_clusters, potential_mode=potential_mode,
|
||||||
|
solver_name=snakemake.config['solving']['solver']['name'])
|
||||||
|
|
||||||
return clustering.network, clustering.busmap
|
return clustering.network, clustering.busmap
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user