I was trying out a method where I try to turn at every node in branch_map. However, one major flaw was that the starting point of a loop is the first non-null element in a row in branch_map. Even this will have to be changed to every non-null element in every row in branch_map. So the old code was:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pick a row | |
for c1 in range(number_of_nodes-1): | |
# Diagonal elements are null | |
# So choose the column next to diagonal | |
c2=c1+1 | |
#check if it exists | |
while not branch_map[c1][c2]: | |
# If not move to next column | |
c2=c2+1 | |
# Check if the column is within dimensions | |
if (c2>=number_of_nodes): | |
# If not, break out and move to next row | |
break | |
else: | |
# Starting branch found | |
# Check is there are parallel branches between the nodes | |
for c3 in range(len(branch_map[c1][c2])-1): | |
loop_list.append([[c1, c2], [c1, c2]]) | |
loop_count+=1 | |
# Initialize the loop iterator list with the first element. | |
loop_iter=[] | |
loop_iter.append([[c1, c2]]) | |
loop_count=find_loop(branch_map, loop_list, loop_iter, \ | |
[c1, c2], loop_count) |
The new code is:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pick a row | |
for c1 in range(number_of_nodes-1): | |
# Diagonal elements are null | |
# So choose the column next to diagonal | |
for c2 in range(c1+1, number_of_nodes): | |
#check if it exists | |
if branch_map[c1][c2]: | |
# Starting branch found | |
# Check is there are parallel branches between the nodes | |
for c3 in range(len(branch_map[c1][c2])-1): | |
loop_list.append([[c1, c2], [c1, c2]]) | |
loop_count+=1 | |
# Initialize the loop iterator list with the first element. | |
loop_iter=[] | |
loop_iter.append([[c1, c2]]) | |
loop_count=find_loop(branch_map, loop_list, loop_iter, \ | |
[c1, c2], loop_count) |
So essentially a for loop has been placed that iterates through the entire starting row.
No comments:
Post a Comment