-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-attr.py
More file actions
28 lines (21 loc) · 1.01 KB
/
get-attr.py
File metadata and controls
28 lines (21 loc) · 1.01 KB
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
26
27
28
import networkx as nx
# Assuming G is a NetworkX graph created using pgr_createTopology or any other method
# Define source and target pairs
source_target_pairs = [(1, 5), (2, 4), (3, 6)]
total_reliability = 0
total_pairs = 0
# Iterate over each source-target pair
for source, target in source_target_pairs:
try:
# Find the shortest path between source and target nodes
shortest_path = nx.shortest_path(G, source=source, target=target, weight='length')
# Calculate the reliability of the path (you need to implement this based on your reliability model)
path_reliability = calculate_path_reliability(G, shortest_path)
# Update total reliability and total pairs
total_reliability += path_reliability
total_pairs += 1
except nx.NetworkXNoPath:
print(f"No path between {source} and {target}")
# Calculate average reliability
average_reliability = total_reliability / total_pairs
print(f"Average Two-Terminal Reliability: {average_reliability}")