Skip to content

Commit

Permalink
Merge pull request #123 from oemof/Fix/networkx_graph
Browse files Browse the repository at this point in the history
Fix nx graph methods
  • Loading branch information
joroeder authored Apr 20, 2023
2 parents c6cbe11 + f57664d commit 0c58e40
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 7 additions & 2 deletions dhnx/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,24 @@
import pandas as pd


def thermal_network_to_nx_graph(thermal_network):
def thermal_network_to_nx_graph(thermal_network, type_of_graph=None):
r"""
Parameters
----------
thermal_network : dhnx.network.ThermalNetwork
type_of_graph : networkx graph class
Must be either Graph() or DiGraph()
Returns
-------
nx_graph : nx:MultiDigraph
networkx graph of thermal_network
"""
nx_graph = nx.DiGraph() # TODO: Check if this line can be removed.
if type_of_graph is None:
type_of_graph = nx.Graph()

nx_graph = type_of_graph

edges = thermal_network.components['pipes'].copy()

Expand Down
12 changes: 11 additions & 1 deletion dhnx/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import os

import networkx as nx
import pandas as pd

from .graph import thermal_network_to_nx_graph
Expand Down Expand Up @@ -112,7 +113,16 @@ def to_csv_folder(self, dirname):
exporter.save()

def to_nx_graph(self):
nx_graph = thermal_network_to_nx_graph(self)
nx_graph = thermal_network_to_nx_graph(
self, type_of_graph=nx.DiGraph(),
)

return nx_graph

def to_nx_undirected_graph(self):
nx_graph = thermal_network_to_nx_graph(
self, type_of_graph=nx.Graph(),
)

return nx_graph

Expand Down

0 comments on commit 0c58e40

Please sign in to comment.