add building type and id to centroid nodes

This commit is contained in:
Majid Rezaei 2024-06-11 08:58:47 -04:00
parent fcceeaa5f8
commit da0a8a4204
3 changed files with 9 additions and 4 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
__pycache__/
*.pyc
.DS_Store
.idea
.idea
.input_files/

View File

@ -221,13 +221,14 @@ class DistrictHeatingNetworkCreator:
"""
Add centroids to the final MST graph and connect them to their associated node on the graph.
"""
for centroid in self.centroids:
for i, centroid in enumerate(self.centroids):
centroid_tuple = (centroid.x, centroid.y)
self.final_mst.add_node(centroid_tuple, type='centroid')
building_id = self.building_ids[i]
self.final_mst.add_node(centroid_tuple, type='building', id=building_id)
nearest_point = None
min_distance = float('inf')
for node in self.final_mst.nodes():
if self.final_mst.nodes[node].get('type') != 'centroid':
if self.final_mst.nodes[node].get('type') != 'building':
node_point = Point(node)
distance = centroid.distance(node_point)
if distance < min_distance:

View File

@ -16,4 +16,7 @@ elapsed_time = end_time - start_time
print(f"The simulation took {elapsed_time:.4f} seconds to run.")
for node in network_graph.nodes(data=True):
print(f"Node: {node[0]}, Type: {node[1].get('type', 'unknown')}, ID: {node[1].get('id', 'N/A')}")
dhn_creator.plot_network_graph()