Spaces:
Sleeping
Sleeping
File size: 686 Bytes
5e9a040 d6f1e58 5e9a040 d6f1e58 5e9a040 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import pandas as pd
import networkx as nx
def analyze_trace(source_node):
df = pd.read_csv("data/network_topology.csv")
# Build directed graph from the CSV
G = nx.from_pandas_edgelist(df, source='Source', target='Target', create_using=nx.DiGraph())
# Get all nodes
nodes = list(G.nodes())
# Default: no path found
path = ["Unknown"]
# Attempt to find path to CoreNetwork
target_node = "CoreNetwork"
if source_node in G and target_node in G:
try:
path = nx.shortest_path(G, source=source_node, target=target_node)
except nx.NetworkXNoPath:
path = ["No path to CoreNetwork"]
return path, nodes
|