Coverage for src/distopf/pyomo_models/objectives.py: 100%
10 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-11-13 17:34 -0800
« prev ^ index » next coverage.py v7.10.6, created at 2025-11-13 17:34 -0800
1from distopf.pyomo_models.protocol import LindistModelProtocol
2import pyomo.environ as pyo
5def loss_objective_rule(model: LindistModelProtocol):
6 """
7 Calculate total system losses using the resistance parameters.
8 For each branch-phase combination, calculates (P² + Q²) * R
9 """
10 total_loss = 0
11 for _id, ph in model.branch_phase_set:
12 for t in model.time_set:
13 total_loss += (model.p_flow[_id, ph, t] ** 2) * model.r[_id, ph + ph]
14 total_loss += (model.q_flow[_id, ph, t] ** 2) * model.r[_id, ph + ph]
15 return total_loss
18loss_objective = pyo.Objective(
19 rule=loss_objective_rule,
20 sense=pyo.minimize,
21)