add_piecewise_formulation: incremental method with a fractional `active` gate only reaches the first segment

未关闭
#1,211 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
58/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend, databases

调研方向

Start by locating add_piecewise_formulation and _add_incremental in Linopy, then inspect the incremental constraints and the existing tests for piecewise formulations. Reproduce the fractional active=0.5 case with the supplied HiGHS example. Done means fractional gates either produce the expected scaled range and curve behavior, or are rejected with a clear error.

由索引模型根据 Issue 内容生成。

描述

bug

[!NOTE]
The following content was generated by AI.

Version Checks (indicate both or one)
  • I have confirmed this bug exists on the lastest release of Linopy.
  • I have confirmed this bug exists on the current master branch of Linopy.
Issue Description

add_piecewise_formulation(method="incremental", active=...) accepts a continuous active, but a fractional gate can then use only the first segment.

The incremental rows are delta_k <= active, delta_k <= z_k and z_{k+1} <= delta_k with binary z. With active = 0.5, delta_1 <= 0.5 forces z_2 = 0, so delta_2 = 0. For a binary gate the rows are correct.

Where it matters: PyPSA's linearised unit commitment passes the relaxed status (in [0, 1]) as active. A unit that is half on is then capped at half of its first breakpoint, not at half of its full range (PyPSA/PyPSA#2128 now refuses this case).

Reproducible Example
import linopy

for s_val in (1.0, 0.5):
    m = linopy.Model()
    x = m.add_variables(lower=0, name="x")
    y = m.add_variables(lower=0, name="y")
    s = m.add_variables(lower=s_val, upper=s_val, name="s")
    m.add_piecewise_formulation(
        (y, linopy.breakpoints([0, 50, 150])),
        (x, linopy.breakpoints([0, 50, 100])),
        method="incremental",
        active=s,
    )
    m.add_objective(-x)
    m.solve("highs", output_flag=False)
    print(f"s={s_val}: max x = {float(x.solution)} (expected {100 * s_val})")

Output:

s=1.0: max x = 100.0 (expected 100.0)
s=0.5: max x = 25.0 (expected 50.0)
Expected Behavior

Either of the two:

  1. Support a fractional gate. The curve holds for the share that is on, i.e. the perspective y = s * f(x / s). In _add_incremental, replace z_{k+1} <= delta_k with delta_k >= active - (1 - z_k) and delta_{k+1} <= z_k (segment k fills to active before k+1 opens). For a binary gate this is the same feasible set as today. I checked it with HiGHS on a non-convex curve: max x = 50 at s = 0.5, y(x=30) = 0.5 * f(60) at s = 0.5, and y(x=60) = f(60) at s = 1.
  2. Reject a non-binary active with a clear error, if (1) is out of scope.
Installed Versions

linopy 0.10.0.post1.dev112+gcc56119a7 (master), HiGHS solver, Python 3.13.

主要语言
Python
星标
264
派生
95
平均合并
11 小时 33 分钟
30 天内合并 PR
86

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

PyPSA/linopy 的其他 Issue

查看 PyPSA/linopy 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。