Network Scores#
Network-topology scoring functions used by node-ranking workflows.
API path: node_ranking.network_scores
Topology-based score functions for node-ranking workflows.
The functions in this module operate directly on the network representation or on precomputed PTDF data. They do not require an economic-dispatch solution.
- compute_edge_betweenness(G, weight=None, normalized=True)[source]#
Compute edge betweenness centrality for all edges.
Delegates to networkx.edge_betweenness_centrality with the provided weight and normalized options.
- Parameters:
G (nx.Graph) – Input network.
weight (str or None, default=None) – Optional edge-attribute name used as a shortest-path weight. If
None, the graph is treated as unweighted.normalized (bool, default=True) – Whether to return normalized centrality values.
- Returns:
Mapping from edge endpoints to edge-betweenness score.
- Return type:
dict[tuple[hashable, hashable], float]
- compute_node_betweenness_centrality(G)[source]#
Compute node betweenness centrality for all nodes.
Betweenness centrality is the fraction of shortest paths between node pairs that pass through each node. This implementation is unweighted and normalized.
- Parameters:
G (nx.Graph) – Input network.
- Returns:
Mapping from node label to normalized betweenness centrality.
- Return type:
dict[hashable, float]
- compute_node_degree_centrality(G)[source]#
Compute node degree centrality for all nodes.
Degree centrality is the node degree divided by the maximum possible degree,
n - 1, so scores lie in[0, 1]for simple graphs.- Parameters:
G (nx.Graph) – Input network.
- Returns:
Mapping from node label to normalized degree centrality.
- Return type:
dict[hashable, float]
- compute_node_ptdf_contribution_scores(
- ptdf,
- edges,
- nodes,
- mask,
- G,
- method='sum',
- fmax_attr='F_max',
Compute PTDF-based node contribution scores.
Each non-slack node receives a score based on the magnitude of its PTDF column across all lines. The score can be aggregated by sum, by maximum line impact, or by a capacity-weighted sum. The slack node is assigned score 0 because PTDF columns are only defined for the non-slack buses in the reduced representation.
- Parameters:
ptdf ((m, n-1) np.ndarray) – PTDF rows=lines, cols=non-slack buses (order = mask).
edges (list[(u, v, data)]) – Edges matching ptdf rows.
nodes (list) – All node labels (order used to build B).
mask (list[int]) – Indices of non-slack buses corresponding to ptdf columns.
G (nx.Graph) – Graph with edge attribute fmax_attr.
method ({"sum","max","weighted_sum"}) –
“sum”: sum_l abs(PTDF_{l,k})
”max”: max_l abs(PTDF_{l,k})
”weighted_sum”: sum_l abs(PTDF_{l,k}) * F_max(l)
fmax_attr (str) – Edge attribute used as weight for “weighted_sum”.
- Returns:
scores – Contribution score for each node in the full node set. Slack node has score 0.
- Return type:
dict[node_label, score]