DC-OPF with Reserves Skill
Solves economic dispatch on a power network with:
- DC power flow (lossless, angle-based)
- Generator limits and polynomial cost minimization
- Transmission line flow limits (rateA)
- Spinning reserve requirements with capacity coupling (Pg + Rg <= Pmax)
Usage
pythonimport sys sys.path.insert(0, '/app/environment/skills/evo-dc-dispatch/scripts') from utils import run_dcopf # End-to-end: load network, solve, validate, write report report = run_dcopf('/root/network.json', '/root/report.json')
Key Functions
load_network(filepath)- Load MATPOWER JSONparse_network(data)- Parse into structured format with bus/gen/branch/cost databuild_Bbus_and_Bf(net)- Build DC power flow matrices (Bf for branch flows, Bbus for bus balance)solve_dcopf_with_reserves(net)- Formulate and solve LP with scipy.optimize.linprog (HiGHS)compute_line_loading(net, solution)- Calculate line loading percentagesbuild_report(net, solution)- Construct output report dictionaryvalidate_report(net, solution, report)- Verify all constraints satisfiedrun_dcopf(input_path, output_path)- End-to-end entry point
Problem Formulation
Variables: Pg (generation), Rg (reserve), theta (bus angles) - all in per-unit
Objective: minimize sum(c1_i * Pg_i) for linear cost generators
Constraints:
- Bus power balance: Cg @ Pg - Bbus @ theta = Pd + Pshift_bus
- Line flow limits: |Bf @ theta + Pshift| <= rateA
- Generator bounds: Pmin <= Pg <= Pmax
- Capacity coupling: Pg + Rg <= Pmax
- Reserve bounds: 0 <= Rg <= reserve_capacity
- System reserve: sum(Rg) >= reserve_requirement
- Reference bus angle = 0
Output Format
report.json with generator_dispatch, totals, most_loaded_lines, operating_margin_MW


