economic-dispatch
Formulate and solve DC-OPF energy + spinning-reserve co-optimization with standard capacity coupling using MATPOWER `gen`/`gencost`.
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-14
- Stars
- ★ 0
- Forks
- 1
01 前言 Front Matter
- name
- economic-dispatch
- description
- Formulate and solve DC-OPF energy + spinning-reserve co-optimization with standard capacity coupling using MATPOWER `gen`/`gencost`.
02 资源文件 1
- 参考文档references/cost-functions.md1.6 KB
03 SKILL.md 正文
Steps
- Load and validate MATPOWER arrays and reserve inputs:
(Sanity-check shapes likebuses = np.array(data["bus"]); gens = np.array(data["gen"]) branches = np.array(data["branch"]); gencost = np.array(data["gencost"]) reserve_capacity = np.array(data["reserve_capacity"]) reserve_requirement = float(data["reserve_requirement"])(bus, gen, branch, gencost)and reserve requirement magnitude.) - Map each generator to its bus index using bus-number mapping:
gen_bus = [bus_num_to_idx[int(g[0])] for g in gens] - Define decision variables:
Pgin per-unit (soPg_MW = Pg*baseMVA)Rgin MW
Pg = cp.Variable(n_gen) Rg = cp.Variable(n_gen) - Add generator bounds and reserve constraints (standard capacity coupling):
constraints = [] for i in range(n_gen): constraints += [Pg[i] >= gens[i,9]/baseMVA, Pg[i] <= gens[i,8]/baseMVA] constraints += [Rg[i] >= 0, Rg[i] <= reserve_capacity[i]] constraints += [Pg[i]*baseMVA + Rg[i] <= gens[i,8]] # coupling constraints.append(cp.sum(Rg) >= reserve_requirement) - Build total production cost using MATPOWER polynomial
gencost(MODEL=2), withPin MW:cost = 0 for i in range(n_gen): ncost = int(gencost[i,3]) P = Pg[i]*baseMVA if ncost >= 3: c2,c1,c0 = gencost[i,4], gencost[i,5], gencost[i,6] cost += c2*cp.square(P) + c1*P + c0 elif ncost == 2: c1,c0 = gencost[i,4], gencost[i,5] cost += c1*P + c0 else: cost += gencost[i,4] if ncost >= 1 else 0 - Solve with a robust conic/QP solver (CLARABEL works well for this formulation):
prob = cp.Problem(cp.Minimize(cost), constraints) prob.solve(solver=cp.CLARABEL)
Expected Result
An optimal dispatch Pg and reserve schedule Rg meeting all limits and reserve requirement, with an objective value in $/hour.
04 同仓库更多 Skills
video-frame-extraction
Extract frames from video files and save them as images using OpenCV
openai-vision
Analyze images and multi-frame sequences using OpenAI GPT vision models
image-ocr
Extract text content from images using Tesseract OCR via Python, including structured field extraction from receipts and forms
video-frame-extraction
Extract frames from video files and save them as images using OpenCV
openai-vision
Analyze images and multi-frame sequences using OpenAI GPT vision models
image-ocr
Extract text content from images using Tesseract OCR via Python, including structured field extraction from receipts and forms