Hi guys, I am working with graphs which have internal loops (or cycles) between node connections. I want to calculate the depth of each node in the graph, although my attempts always fall into infinite loops. Is there anyway I can do that with DGL? Maybe remove graph cycles some how?
Here is what I tried, which falls into an infinite loop:
print("calculating logic depth!", self.graph.name, flush=True)
depths = np.zeros(self.graph.number_of_nodes(), dtype=int)
inputs = [node for node in self.graph.nodes() if self.graph.in_degrees(node) == 1 and self.graph.out_degrees(node) > 1]
outputs = [node for node in self.graph.nodes() if self.graph.out_degrees(node) == 1 and self.graph.in_degrees(node) > 1]
print("depths:", len(depths))
print("inputs:", len(inputs), flush=True)
print("outputs:", len(outputs), flush=True)
stack = []
for node in outputs:
print("output node:", node, flush=True)
stack.append((node, 0, [node]))
while stack:
node, depth, path = stack.pop()
depths[node] = max(depths[node], depth)
neighbors = self.graph.predecessors(node).numpy()
for neighbor in neighbors:
if neighbor not in path and depths[neighbor] < depth + 1:
stack.append((neighbor, depth + 1, path + [neighbor]))