def _iter_over_viol_set(viol_set, mb, PTDF, abs_ptdf_tol, rel_ptdf_tol): for i in viol_set: bn = PTDF.branches_keys_masked[i] if mb.pf[bn].expr is None: expr = libbranch.get_power_flow_expr_ptdf_approx( mb, bn, PTDF, abs_ptdf_tol=abs_ptdf_tol, rel_ptdf_tol=rel_ptdf_tol) mb.pf[bn] = expr yield i, bn
def add_initial_monitored_branches(mb, branches, branches_in_service, ptdf_options, PTDF): ## static information between runs rel_ptdf_tol = ptdf_options['rel_ptdf_tol'] abs_ptdf_tol = ptdf_options['abs_ptdf_tol'] constr = mb.ineq_pf_branch_thermal_bounds viol_in_mb = mb._idx_monitored for i, bn in _iter_over_initial_set(branches, branches_in_service, PTDF): thermal_limit = PTDF.branch_limits_array_masked[i] mb.pf[bn] = libbranch.get_power_flow_expr_ptdf_approx( mb, bn, PTDF, abs_ptdf_tol=abs_ptdf_tol, rel_ptdf_tol=rel_ptdf_tol) constr[bn], _ = _generate_branch_thermal_bounds(mb, bn, thermal_limit) viol_in_mb.append(i)