def topological_sort(self):
'''
Returns a list topological sorted nodes
'''
if self.is_cyclic(self.FSs):
print 'cannot apply labels, graph contains cycles'
return
big_l = [] # Empty list that will contain the sorted elements
# Set of all nodes with no incoming edges
big_s = set([0])
bs_copy = self.BSs.copy()
while len(big_s) > 0:
n = big_s.pop()
big_l.append(n)
for m in self.FSs[n]:
bs_copy[m] = np.delete(bs_copy[m], np.where(bs_copy[m] == n))
# bs_copy[m].remove(n)
if len(bs_copy[m]) == 0:
big_s.add(int(m))
return big_l
评论列表
文章目录