candidates = []
cycles = list(nx.simple_cycles(directed_graph))
n_cycles = len(cycles)
print("Cycles: {}".format(cycles))
// number of candidates to be the best new graph
cycles_len = np.array([len(cycle) for cycle in cycles])
n_candidates = np.prod(cycles_len)
After Change
def check_and_correct_binary_mask(nodes, binary_mask_):
binary_mask = deepcopy(binary_mask_)binary_mask = np.array(binary_mask)
directed_graph = get_digraph_from_binary_mask(nodes, binary_mask)
sources, sinks = find_sources_and_sinks(directed_graph)
while not nx.is_directed_acyclic_graph(directed_graph):