Module ml4opf.functional.incidence
Incidence matrices and related functions.
Functions
def adjacency(fbus: torch.Tensor, tbus: torch.Tensor, n_bus: int, n_branch: int) ‑> torch.Tensor-
Sparse adjacency matrix.
Each row corresponds to a bus and each column corresponds to a bus. The value is 1 if there is a branch between the buses, and 0 otherwise.
Args
fbus:Tensor- From bus indices. (nbranch,)
tbus:Tensor- To bus indices. (nbranch,)
n_bus:int- Number of buses.
n_branch:int- Number of branches.
Returns
Tensor- Sparse adjacency matrix. (nbus, nbus)
def branch_from_incidence(fbus: torch.Tensor, n_bus: int, n_branch: int) ‑> torch.Tensor-
Sparse branch from incidence matrix.
Each row corresponds to a bus and each column corresponds to a branch. The value is 1 if the branch is from the bus, and 0 otherwise.
Args
fbus:Tensor- From bus indices. (nbranch,)
n_bus:int- Number of buses.
n_branch:int- Number of branches.
Returns
Tensor- Sparse branch from incidence matrix. (nbus, nbranch)
def branch_incidence(fbus: torch.Tensor, tbus: torch.Tensor, n_bus: int, n_branch: int) ‑> torch.Tensor-
Sparse branch incidence matrix.
Each row corresponds to a bus and each column corresponds to a branch. The value is 1 if the branch is from the bus, -1 if the branch is to the bus, and 0 otherwise.
Args
fbus:Tensor- From bus indices. (nbranch,)
tbus:Tensor- To bus indices. (nbranch,)
n_bus:int- Number of buses.
n_branch:int- Number of branches.
Returns
Tensor- Sparse branch incidence matrix. (nbus, nbranch)
def branch_to_incidence(tbus: torch.Tensor, n_bus: int, n_branch: int) ‑> torch.Tensor-
Sparse branch to incidence matrix.
Each row corresponds to a bus and each column corresponds to a branch. The value is 1 if the branch is to the bus, and 0 otherwise.
Args
tbus:Tensor- To bus indices. (nbranch,)
n_bus:int- Number of buses.
n_branch:int- Number of branches.
Returns
Tensor- Sparse branch to incidence matrix. (nbus, nbranch)
def generator_incidence(gen_bus: torch.Tensor, n_bus: int, n_gen: int) ‑> torch.Tensor-
Sparse generator incidence matrix.
Each row corresponds to a bus and each column corresponds to a generator. The value is 1 if the generator is at the bus, and 0 otherwise.
Args
gen_bus:Tensor- Generator bus indices. (ngen,)
n_bus:int- Number of buses.
n_gen:int- Number of generators.
Returns
Tensor- Sparse generator incidence matrix. (nbus, ngen)
def load_incidence(load_bus: torch.Tensor, n_bus: int, n_load: int) ‑> torch.Tensor-
Sparse load incidence matrix.
Each row corresponds to a bus and each column corresponds to a load. The value is 1 if the load is at the bus, and 0 otherwise.
Args
load_bus:Tensor- Load bus indices. (nload,)
n_bus:int- Number of buses.
n_load:int- Number of loads.
Returns
Tensor- Sparse load incidence matrix. (nbus, nload)
def map_to_bus_matrix(x: torch.Tensor, x_matrix: torch.Tensor)-
Map component-wise values to bus-wise values using matrix multiplication.
def map_to_bus_pad(x: torch.Tensor, x_per_bus: torch.Tensor)-
Map component-wise values to bus-wise values using zero-padding.