It is difficult to see which tasks in a project are actually causing delays because some are buried deep in a sequence while others are only reachable through a single, narrow path.
It analyzes a project's structure to calculate a score that identifies which tasks are the most critical bottlenecks based on their position and connection points.
It helps identify which specific tasks are most likely to stall a project's progress.
It was run in the sandbox and it failed. run output shows an error/traceback — the artifact does NOT run clean.
$ python3 graph_path_reachability_score.py
Traceback (most recent call last):
File "/work/graph_path_reachability_score.py", line 83, in <module>
result = analyzer.calculate_bottleneck_score(node)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/work/graph_path_reachability_score.py", line 63, in calculate_bottleneck_score
bottleneck_score = trds * (1 - reachability['connectivityDensity']) * (reachability['shortestPathDepth'] or 1)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
KeyError: 'shortestPathDepth'No screenshot — there is nothing working to show. This is recorded as an unfinished sketch so the attempt stays visible instead of being quietly dropped.
All of it — 88 lines, one file, standard library only.
# Graph-Path Reachability Score implementation combining TRDS and graph reachability analysis
class GraphPathReachabilityScore:
def __init__(self, graph):
self.graph = graph # Expected format: {node: [dependencies]}
def calculate_trds(self, node, visited=None):
"""
Temporal-Relational Dependency Score with recursive path weighting
"""
if visited is None:
visited = set()
if node in visited:
return 0 # Prevent cycles
visited.add(node)
score = 1.0 # Base score for the node itself
# Recursive case: sum scores of dependencies weighted by depth
for dependency in self.graph.get(node, []):
depth_weight = 1.0 / (len(self.graph.get(node, [])) or 1)
score += depth_weight * self.calculate_trds(dependency, visited)
return score
def calculate_reachability(self, start_node):
"""
Recursive Graph-Node Reachability Score with BFS for shortest paths
"""
from collections import deque
visited = set()
queue = deque([(start_node, 0)]) # (node, distance)
while queue:
node, distance = queue.popleft()
if node in visited:
continue
visited.add(node)
for neighbor in self.graph.get(node, []):
queue.append((neighbor, distance + 1))
# Calculate connectivity density
total_nodes = len(self.graph)
reachable_nodes = len(visited)
connectivity_density = reachable_nodes / total_nodes if total_nodes else 0
return {
'shortest_pathDepth': distance,
'connectivityDensity': connectivity_density
}
def calculate_bottleneck_score(self, node):
"""
Combines TRDS with reachability metrics for final bottleneck score
"""
trds = self.calculate_trds(node)
reachability = self.calculate_reachability(node)
# Combine scores (example formula - can be adjusted based on research)
bottleneck_score = trds * (1 - reachability['connectivityDensity']) * (reachability['shortestPathDepth'] or 1)
return {
'trds': trds,
'reachability': reachability,
'bottleneck_score': bottleneck_score
}
# Example usage
if __name__ == "__main__":
# Define a sample dependency graph
dependency_graph = {
'A': ['B', 'C'],
'B': ['D'],
'C': ['D'],
'D': []
}
analyzer = GraphPathReachabilityScore(dependency_graph)
for node in dependency_graph:
result = analyzer.calculate_bottleneck_score(node)
print(f"Node {node}:")
print(f" TRDS: {result['trds']:.2f}")
print(f" Reachability depth: {result['reachability']['shortestPathDepth']}")
print(f" Connectivity density: {result['reachability']['connectivityDensity']:.2f}")
print(f" Bottleneck score: {result['bottleneck_score']:.2f}\n")