Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify optimisation input #117

Draft
wants to merge 9 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions dhnx/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,15 +314,43 @@ def reproject(self, crs):
def optimize_operation(self):
self.results.operation = optimize_operation(self)

def optimize_investment(self, invest_options, **kwargs):
def optimize_investment(
self, pipeline_invest_options,
additional_invest_options=None, **kwargs):
"""

Parameters
----------
pipeline_invest_options : pandas.DataFrame
Table with the investment options for the district heating
pipelines.
The table requires the columns:
- "":
- "":
- "":
- "":
additional_invest_options : dict
Optional dictionary with pandas.DataFrame with additional
oemof-solph components for the consumers and the producers.
kwargs

Returns
-------

"""

oemof_opti_model = setup_optimise_investment(
self, invest_options, **kwargs
self,
pipeline_invest_options,
additional_invest_options=additional_invest_options,
**kwargs
)

self.results.optimization = solve_optimisation_investment(
oemof_opti_model
)

return self.results.optimization

def simulate(self, *args, **kwargs):
self.results.simulation = simulate(self, *args, **kwargs)
3 changes: 2 additions & 1 deletion dhnx/optimization/dhs_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def add_nodes_dhs(opti_network, gd, nodes, busd):
d_labels['l_2'] = 'heat'
d_labels['l_3'] = 'bus'

# add a solph.Bus to every fork
for n, _ in opti_network.thermal_network.components['forks'].iterrows():
d_labels['l_4'] = 'forks-' + str(n)
d_labels['l_1'] = 'infrastructure'
Expand All @@ -66,7 +67,7 @@ def add_nodes_dhs(opti_network, gd, nodes, busd):
# add heatpipes for all lines
for p, q in opti_network.thermal_network.components['pipes'].iterrows():

pipe_data = opti_network.invest_options['network']['pipes']
pipe_data = opti_network.pipelines_invest_options

d_labels['l_1'] = 'infrastructure'
d_labels['l_2'] = 'heat'
Expand Down
30 changes: 21 additions & 9 deletions dhnx/optimization/optimization_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class OemofInvestOptimizationModel(InvestOptimizationModel):
----------
settings : dict
Dictionary holding the optimisation settings. See .
pipelines_invest_options : pandas.DataFrame
Table with the investment options for DHS pipelines.
invest_options : dict
Dictionary holding the investment options for the district heating system.
nodes : list
Expand Down Expand Up @@ -83,10 +85,12 @@ class OemofInvestOptimizationModel(InvestOptimizationModel):
Calls *check_input()*, *complete_exist_data()*, *get_pipe_data()*, and *setup_oemof_es()*.

"""
def __init__(self, thermal_network, settings, investment_options):
def __init__(self, thermal_network, pipeline_invest_options,
settings, additional_invest_options):

self.settings = settings
self.invest_options = investment_options
self.pipelines_invest_options = pipeline_invest_options
self.invest_options = additional_invest_options
self.nodes = [] # list of all nodes
self.buses = {} # dict of all buses
self.es = solph.EnergySystem()
Expand Down Expand Up @@ -222,8 +226,8 @@ def clean_df(df):
for k, v in self.thermal_network.components.items():
self.thermal_network.components[k] = clean_df(v)

pipes = self.invest_options['network']['pipes']
self.invest_options['network']['pipes'] = clean_df(pipes)
pipes = self.pipelines_invest_options
self.pipelines_invest_options = clean_df(pipes)

for node_typ in ['consumers', 'producers']:
for k, v in self.invest_options[node_typ].items():
Expand Down Expand Up @@ -307,7 +311,7 @@ def check_existing(self):
self.thermal_network.components['pipes']['hp_type'] = None

edges = self.thermal_network.components['pipes']
pipe_types = self.invest_options['network']['pipes']
pipe_types = self.pipelines_invest_options

hp_list = list({x for x in edges['hp_type'].tolist()
if isinstance(x, str)})
Expand Down Expand Up @@ -631,7 +635,7 @@ def recalc_costs_losses():
df = df[['from_node', 'to_node', 'length']].copy()

# putting the results of the investments in heatpipes to the pipes:
df_hp = self.invest_options['network']['pipes']
df_hp = self.pipelines_invest_options

# list of active heat pipes
active_hp = list(df_hp['label_3'].values)
Expand Down Expand Up @@ -664,7 +668,8 @@ def optimize_operation(thermal_network):


def setup_optimise_investment(
thermal_network, invest_options, heat_demand='scalar', num_ts=1,
thermal_network, pipeline_invest_options,
additional_invest_options=None, heat_demand='scalar', num_ts=1,
time_res=1, start_date='1/1/2018', frequence='H', solver='cbc',
solve_kw=None, solver_cmdline_options=None, simultaneity=1,
bidirectional_pipes=False, dump_path=None, dump_name='dump.oemof',
Expand All @@ -676,7 +681,9 @@ def setup_optimise_investment(
----------
thermal_network : ThermalNetwork
See the ThermalNetwork class.
invest_options : dict
pipeline_invest_options : pandas.DataFrame
Table with the investment options for the DHS pipelines.
additional_invest_options : dict
Dictionary holding the investment options for the district heating system.
heat_demand : str
'scalar': Peak heat load is used as heat consumers’ heat demand.
Expand Down Expand Up @@ -738,7 +745,12 @@ def setup_optimise_investment(
'write_lp_file': write_lp_file,
}

model = OemofInvestOptimizationModel(thermal_network, settings, invest_options)
model = OemofInvestOptimizationModel(
thermal_network,
pipeline_invest_options,
settings,
additional_invest_options,
)

return model

Expand Down
24 changes: 22 additions & 2 deletions examples/optimisation/minimal_network/minimal_network.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
import matplotlib.pyplot as plt
import pandas as pd
import dhnx


# Initialize thermal network
network = dhnx.network.ThermalNetwork()
network = network.from_csv_folder('twn_data')

# DHS pipeline invest data
df_pipes = pd.DataFrame(
{
"label_3": "your-pipe-type-label",
"active": 1,
"nonconvex": 1,
"l_factor": 0.000002,
"l_factor_fix": 0.001,
"cap_max": 10000,
"cap_min": 25,
"capex_pipes": 5,
"fix_costs": 200,
}, index=[0],
)

# Load investment parameter
invest_opt = dhnx.input_output.load_invest_options('invest_data')

# Execute investment optimization
network.optimize_investment(invest_options=invest_opt,
write_lp_file=True)
network.optimize_investment(
pipeline_invest_options=df_pipes,
additional_invest_options=invest_opt,
write_lp_file=True,
print_logging_info=True,
)

# ####### Postprocessing and Plotting ###########
# Draw network
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"cells": [
{
"cell_type": "markdown",
"source": [
"# Tutorial"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Loading