Skip to content

Commit

Permalink
Update syntehtic network with flh matrices, fixed networkx export fun…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
ddceruti committed Dec 2, 2024
1 parent e73fd97 commit 269402b
Show file tree
Hide file tree
Showing 13 changed files with 8 additions and 37 deletions.
2 changes: 0 additions & 2 deletions examples/one-producer/run_sts.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def main(filepath, outputpath, plots=True, solver='gurobi', mode='economic'):

# modify either in code or in the config file
settings.economics.source_c_inv = [0.] # no investment costs for sources
settings.temperatures.supply = 90

model_sets = tt.sets.create(mat)
model = tt.single_timestep.model(
Expand Down Expand Up @@ -110,7 +109,6 @@ def main(filepath, outputpath, plots=True, solver='gurobi', mode='economic'):
f.savefig(os.path.join(outputpath, 'district_optimal.svg'),
bbox_inches='tight')


if __name__ == '__main__':
main(filepath=os.path.join(DATAPATH), outputpath=os.path.join(OUTPUTPATH),
plots=PLOTS, solver=SOLVER, mode='economic')
Expand Down
19 changes: 0 additions & 19 deletions examples/synthetic-network/convert_npy_to_parquet.py

This file was deleted.

Binary file removed examples/synthetic-network/data/A_c.npy
Binary file not shown.
Binary file removed examples/synthetic-network/data/A_i.npy
Binary file not shown.
Binary file removed examples/synthetic-network/data/A_p.npy
Binary file not shown.
Binary file removed examples/synthetic-network/data/Q_c.npy
Binary file not shown.
2 changes: 0 additions & 2 deletions examples/synthetic-network/data/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ solver:
time_limit: 10000

economics:
source_flh: [2500] # h/y
source_c_inv: [0] # Investment costs for each source
source_c_irr: [0.08] # Interest rate for each source
source_lifetime: [40.] # years for source investments
source_price: [80e-3] # Price for heat production at supply in €/kW
consumer_flh: 2500 # h/y
heat_price: 120e-3 # Selling Price for heat in €/kW
pipes_c_irr: 0.08 # Interest rate
pipes_lifetime: 40. # years for piping investments
Binary file not shown.
Binary file not shown.
Binary file removed examples/synthetic-network/data/l_i.npy
Binary file not shown.
Binary file removed examples/synthetic-network/data/rel_positions.npy
Binary file not shown.
14 changes: 4 additions & 10 deletions examples/synthetic-network/run_sts.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ def main(filepath, outputpath, plots=True, solver='gurobi', mode='forced'):
settings = tt.settings.load(os.path.join(filepath, 'config.yaml'))
print(settings)
settings.economics.source_c_inv = [0.] # no investment costs for sources
settings.economics.source_flh = [2500.] # full load hours
settings.economics.consumers_flh = [2500.] # full load hours

model_sets = tt.sets.create(mat)
model = tt.single_timestep.model(
Expand Down Expand Up @@ -118,11 +116,6 @@ def main(filepath, outputpath, plots=True, solver='gurobi', mode='forced'):

network = tt.postprocessing.to_networkx_graph(opt_mats)

print(len(network.edges))
print(mat['a_i'].shape[1])
print(len(network.nodes))
print(mat['a_i'].shape[0])

fig, ax = plt.subplots(figsize=(20, 20), layout='constrained')
node_colors = []
node_label = []
Expand All @@ -133,7 +126,7 @@ def main(filepath, outputpath, plots=True, solver='gurobi', mode='forced'):

for node in network.nodes(data=True):
node_colors.append(node[1]['color'])
node_label.append(node[1]['type'])
node_label.append(node[1]['type_'])
node_id[node[0]] = str(node[0])
node_pos.append([node[1]['x'], node[1]['y']])

Expand All @@ -145,13 +138,14 @@ def main(filepath, outputpath, plots=True, solver='gurobi', mode='forced'):
edgelist=network.edges, width=edges_p, ax=ax,
label=edges_label, alpha=0.3, edge_color='grey')
nx.draw_networkx_nodes(network, pos=node_pos, node_color=node_colors,
ax=ax, label=node)
ax=ax, label=node_label)

nx.draw_networkx_labels(network, pos=node_pos, labels=node_id, ax=ax)#
nx.draw_networkx_edge_labels(network, pos=node_pos, edge_labels=edges_label, ax=ax)
adjancency = nx.to_numpy_array(network, weight=None)
print(adjancency)

fig.show()
plt.pause(120)
fig.savefig(os.path.join(outputpath, 'networkx.svg'), bbox_inches='tight')
# close all figures
plt.close('all')
Expand Down
8 changes: 4 additions & 4 deletions topotherm/postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,19 +358,19 @@ def to_networkx_graph(matrices):
for q in range(matrices['a_c'].shape[0]):
x, y = matrices['position'][q, 0], matrices['position'][q, 1]
if ges[q] == 1:
G.add_node(q, color='Red', type='consumer', x=x, y=y)
G.add_node(q, color='Red', type_='consumer', x=x, y=y)
elif ges[q] == 0:
G.add_node(q, color='Green', type='internal', x=x, y=y)
G.add_node(q, color='Green', type_='internal', x=x, y=y)
if ges[q] <= -1:
G.add_node(q, color='Orange', type='source', x=x, y=y)
G.add_node(q, color='Orange', type_='source', x=x, y=y)

# edge_labels = dict()
# Add the edges to the graph
for k in range(matrices['a_i'].shape[1]):
s = (np.where(matrices['a_i'][:, k] == 1)[0][0],
np.where(matrices['a_i'][:, k] == -1)[0][0])
G.add_edge(s[0], s[1],
weight=matrices['l_i'][k],
weight=matrices['l_i'][k].item(),
d=matrices['d_i_0'][k],
p=matrices['p'][k])

Expand Down

0 comments on commit 269402b

Please sign in to comment.