@@ -452,7 +452,8 @@ def get_shs_consumers(self):
452452 return df .copy ()
453453
454454 def find_index_longest_distribution_link (self ):
455- # Find the links longer than two times of the allowed distance
455+ # Find the links longer than the allowed distance
456+ self .distribution_links = self .links [self .links ["link_type" ] == "distribution" ]
456457 critical_link = self .distribution_links [
457458 self .distribution_links ["length" ] > self .distribution_cable_max_length
458459 ]
@@ -1183,6 +1184,8 @@ def _cut_leaf_poles_on_condition(self):
11831184 for pole in leaf_poles :
11841185 if pole in exclude_lst :
11851186 continue
1187+ if pole not in self .nodes .index :
1188+ continue
11861189 consumer_of_pole = self .nodes [self .nodes ["parent" ] == pole ]
11871190 branch = self .nodes [self .nodes .index == pole ]["branch" ].iloc [0 ]
11881191 consumer_of_branch = self .nodes [self .nodes ["branch" ] == branch ].index
@@ -1249,6 +1252,8 @@ def _remove_poles_and_links(self, pole):
12491252
12501253 def _correct_n_distribution_links_of_parent_poles (self , pole ):
12511254 parent_pole = self .nodes [self .nodes .index == pole ]["parent" ].iloc [0 ]
1255+ if parent_pole == "unknown" or pd .isna (parent_pole ):
1256+ return
12521257 self .nodes .loc [parent_pole , "n_distribution_links" ] -= 1
12531258
12541259 def _determine_shs_consumers (self , max_iter = 20 ):
@@ -1580,19 +1585,20 @@ def _break_long_link(self, mst_pole_from, mst_pole_to, added_poles):
15801585 label_node_from = index_added_pole if to_from else mst_pole_from ,
15811586 label_node_to = mst_pole_to if to_from else index_added_pole ,
15821587 )
1583- elif counter == n_added_poles - 1 :
1584- # The last `added poles` should be connected to
1588+ else :
1589+ # Connect each subsequent pole to the previous added pole.
1590+ self ._add_links (
1591+ label_node_from = added_pole_indices [counter - 1 ],
1592+ label_node_to = index_added_pole ,
1593+ )
1594+ if counter == n_added_poles - 1 :
1595+ # The last `added poles` should also be connected to
15851596 # the end or to the beginning of the long link,
15861597 # depending on the `to_from` flag.
15871598 self ._add_links (
15881599 label_node_from = mst_pole_from if to_from else index_added_pole ,
15891600 label_node_to = index_added_pole if to_from else mst_pole_to ,
15901601 )
1591- else :
1592- self ._add_links (
1593- label_node_from = added_pole_indices [counter - 1 ],
1594- label_node_to = index_added_pole ,
1595- )
15961602 self .nodes .loc [index_added_pole , "how_added" ] = "long-distance"
15971603
15981604 def create_minimum_spanning_tree (self ):
0 commit comments