Compare commits

...

2 Commits

3 changed files with 362 additions and 117 deletions

View File

@ -0,0 +1,32 @@
import networkx as nx
import logging
class DistrictHeatingFactory:
"""
DistrictHeatingFactory class
"""
def __init__(self, city, graph):
self._city = city
self._network_graph = graph
def enrich(self):
"""
Enrich the network graph nodes with attributes from the city buildings.
"""
for node in self._network_graph.nodes(data=True):
node_id, node_attrs = node
if node_attrs.get('type') == 'building':
building_name = node_attrs.get('name')
building_found = False
for building in self._city.buildings:
if building.name == building_name:
building_attrs = vars(building)
for attr, value in building_attrs.items():
if attr not in self._network_graph.nodes[node_id]:
self._network_graph.nodes[node_id][attr] = value
building_found = True
break
if not building_found:
logging.error(msg=f"Building with name '{building_name}' not found in city.")

View File

@ -79,6 +79,7 @@ class DistrictHeatingNetworkCreator:
centroid = building_polygon.centroid
self.centroids.append(centroid)
self.building_names.append(str(building['id']))
print(self.building_names)
# Load road data
with open(self.roads_file, 'r') as file:
@ -282,7 +283,7 @@ class DistrictHeatingNetworkCreator:
for i, centroid in enumerate(self.centroids):
centroid_tuple = (centroid.x, centroid.y)
building_name = self.building_names[i]
self.final_mst.add_node(centroid_tuple, type='building', id=building_name)
self.final_mst.add_node(centroid_tuple, type='building', name=building_name)
nearest_point = None
min_distance = float('inf')
for node in self.final_mst.nodes():

File diff suppressed because one or more lines are too long