SKILL.md
Locational Marginal Prices (LMPs)
LMPs are the marginal cost of serving one additional MW of load at each bus. In optimization terms, they are the dual values (shadow prices) of the nodal power balance constraints.
LMP Extraction from CVXPY
To extract LMPs, you must:
- Store references to the balance constraints
- Solve the problem
- Read the dual values after solving
import cvxpy as cp
# Store balance constraints separately for dual extraction
balance_constraints = []
for i in range(n_bus):
pg_at_bus = sum(Pg[g] for g in range(n_gen) if gen_bus[g] == i)
pd = buses[i, 2] / baseMVA
# Create constraint and store reference
balance_con = pg_at_bus - pd == B[i, :] @ theta
balance_constraints.append(balance_con)
constraints.append(balance_con)
# Solve
prob = cp.Problem(cp.Minimize(cost), constraints)
prob.solve(solver=cp.CLARABEL)
# Extract LMPs from duals
lmp_by_bus = []
for i in range(n_bus):
bus_num = int(buses[i, 0])
dual_val = balance_constraints[i].dual_value
# Scale: constraint is in per-unit, multiply by baseMVA to get $/MWh
lmp = float(dual_val) * baseMVA if dual_val is not None else 0.0
lmp_by_bus.append({
"bus": bus_num,
"lmp_dollars_per_MWh": round(lmp, 2)
})
LMP Sign Convention
For a balance constraint written as generation - load == net_export:
- Positive LMP: Increasing load at that bus increases total cost (typical case)
- Negative LMP: Increasing load at that bus decreases total cost
Negative LMPs commonly occur when:
- Cheap generation is trapped behind a congested line (can't export power)
- Adding load at that bus relieves congestion by consuming local excess generation
- The magnitude can be very large in heavily congested networks (thousands of $/MWh)
Negative LMPs are physically valid and expected in congested systems — they are not errors.
