-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from oemof/Feature/Add_discrete_pipe_example
Add example with discrete DN numbers
- Loading branch information
Showing
12 changed files
with
144 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
examples/optimisation/discrete_DN_numbers/discrete_DN_numbers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
""" | ||
Discrete DN number examples. | ||
This examples shows how to perform an optimisation with an investment | ||
in discrete DN numbers. | ||
Please see the `pipes.csv` in the invest_data/network. | ||
For each of the DN numbers a separate row is given in the table. | ||
""" | ||
import matplotlib.pyplot as plt | ||
import dhnx | ||
|
||
# Initialize thermal network | ||
network = dhnx.network.ThermalNetwork() | ||
network = network.from_csv_folder('twn_data') | ||
|
||
# Load investment parameter | ||
invest_opt = dhnx.input_output.load_invest_options('invest_data') | ||
|
||
# plot network | ||
static_map = dhnx.plotting.StaticMap(network) | ||
static_map.draw(background_map=False) | ||
plt.title('Given network') | ||
plt.scatter(network.components.consumers['lon'], network.components.consumers['lat'], | ||
color='tab:green', label='consumers', zorder=2.5, s=50) | ||
plt.scatter(network.components.producers['lon'], network.components.producers['lat'], | ||
color='tab:red', label='producers', zorder=2.5, s=50) | ||
plt.scatter(network.components.forks['lon'], network.components.forks['lat'], | ||
color='tab:grey', label='forks', zorder=2.5, s=50) | ||
plt.text(-2, 32, 'P0', fontsize=14) | ||
plt.legend() | ||
plt.show() | ||
|
||
# Execute investment optimization | ||
network.optimize_investment(invest_options=invest_opt) | ||
|
||
# ####### Postprocessing and Plotting ########### | ||
|
||
# get results | ||
results_edges = network.results.optimization['components']['pipes'] | ||
print(results_edges[['from_node', 'to_node', 'hp_type', 'capacity', | ||
'direction', 'costs', 'losses']]) | ||
|
||
# print(results_edges[['invest_costs[€]']].sum()) | ||
print('Objective value: ', network.results.optimization['oemof_meta']['objective']) | ||
|
||
# assign new ThermalNetwork with invested pipes | ||
twn_results = network | ||
twn_results.components['pipes'] = results_edges[results_edges['capacity'] > 0.001] | ||
|
||
# plot invested edges | ||
static_map_2 = dhnx.plotting.StaticMap(twn_results) | ||
static_map_2.draw(background_map=False) | ||
plt.title('Result network') | ||
plt.scatter(network.components.consumers['lon'], network.components.consumers['lat'], | ||
color='tab:green', label='consumers', zorder=2.5, s=50) | ||
plt.scatter(network.components.producers['lon'], network.components.producers['lat'], | ||
color='tab:red', label='producers', zorder=2.5, s=50) | ||
plt.scatter(network.components.forks['lon'], network.components.forks['lat'], | ||
color='tab:grey', label='forks', zorder=2.5, s=50) | ||
plt.text(-2, 32, 'P0', fontsize=14) | ||
for r, c in twn_results.components['pipes'].iterrows(): | ||
size = c["hp_type"] | ||
type = c["from_node"].split("-")[0] | ||
id = c["from_node"].split("-")[1] | ||
lat_0 = twn_results.components[type].loc[id].lat | ||
lon_0 = twn_results.components[type].loc[id].lon | ||
type = c["to_node"].split("-")[0] | ||
id = c["to_node"].split("-")[1] | ||
lat_1 = twn_results.components[type].loc[id].lat | ||
lon_1 = twn_results.components[type].loc[id].lon | ||
lat_mid = lat_0 + 0.5 * (lat_1 - lat_0) | ||
lon_mid = lon_0 + 0.5 * (lon_1 - lon_0) | ||
plt.text(lon_mid, lat_mid, size, va="center", ha="center") | ||
|
||
plt.legend() | ||
plt.show() |
2 changes: 2 additions & 0 deletions
2
examples/optimisation/discrete_DN_numbers/invest_data/consumers/bus.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
label_2,active,excess,shortage,shortage costs,excess costs | ||
heat,1,0,0,999999,9999 |
2 changes: 2 additions & 0 deletions
2
examples/optimisation/discrete_DN_numbers/invest_data/consumers/demand.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
label_2,active,nominal_value | ||
heat,1,1 |
6 changes: 6 additions & 0 deletions
6
examples/optimisation/discrete_DN_numbers/invest_data/network/pipes.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
label_3,active,nonconvex,l_factor,l_factor_fix,cap_max,cap_min,capex_pipes,fix_costs | ||
DN-25,1,1,0,0.007656,28,27,0,466 | ||
DN-32,1,1,0,0.0086405,54,53,0,491 | ||
DN-40,1,1,0,0.0095755,98,97,0,522 | ||
DN-50,1,1,0,0.009141,179,178,0,563 | ||
DN-63,1,1,0,0.0114125,335,334,0,620 |
2 changes: 2 additions & 0 deletions
2
examples/optimisation/discrete_DN_numbers/invest_data/producers/bus.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
,label_2,active,excess,shortage,shortage costs,excess costs | ||
1,heat,1,0,0,9999,9999 |
2 changes: 2 additions & 0 deletions
2
examples/optimisation/discrete_DN_numbers/invest_data/producers/source.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
label_2,active | ||
heat,1 |
9 changes: 9 additions & 0 deletions
9
examples/optimisation/discrete_DN_numbers/twn_data/consumers.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
id,lat,lon,P_heat_max | ||
0,30,40,15 | ||
1,10,40,18 | ||
2,10,60,25 | ||
3,30,70,36 | ||
4,50,60,25 | ||
5,90,40,12 | ||
6,60,10,50 | ||
7,60,30,20 |
12 changes: 12 additions & 0 deletions
12
examples/optimisation/discrete_DN_numbers/twn_data/forks.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
id,lat,lon | ||
0,30,20 | ||
1,20,20 | ||
2,20,40 | ||
3,20,60 | ||
4,20,70 | ||
5,20,80 | ||
6,40,90 | ||
7,60,70 | ||
8,80,40 | ||
9,80,20 | ||
10,60,20 |
21 changes: 21 additions & 0 deletions
21
examples/optimisation/discrete_DN_numbers/twn_data/pipes.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
id,from_node,to_node,length | ||
0,producers-0,forks-0,20 | ||
2,forks-0,forks-1,10 | ||
3,forks-1,forks-2,20 | ||
4,forks-2,forks-3,20 | ||
5,forks-3,forks-4,10 | ||
6,forks-4,forks-5,10 | ||
7,forks-5,forks-6,30 | ||
8,forks-6,forks-7,30 | ||
9,forks-7,forks-8,30 | ||
10,forks-8,forks-9,20 | ||
11,forks-9,forks-10,10 | ||
12,forks-10,forks-0,30 | ||
13,forks-2,consumers-0,10 | ||
14,forks-2,consumers-1,10 | ||
15,forks-3,consumers-2,10 | ||
16,forks-4,consumers-3,10 | ||
17,forks-7,consumers-4,10 | ||
18,forks-8,consumers-5,10 | ||
19,forks-10,consumers-7,10 | ||
20,forks-10,consumers-6,10 |
2 changes: 2 additions & 0 deletions
2
examples/optimisation/discrete_DN_numbers/twn_data/producers.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
id,lat,lon,active | ||
0,30,0,1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,6 @@ passenv = | |
* | ||
deps = | ||
pytest | ||
pytest-travis-fold | ||
.[tests] | ||
commands = | ||
{posargs:pytest -vv --ignore=src} | ||
|