[BUG] Python: Problem.addConstraint accepts the same Constraint twice

未关闭 适合新手
#2,326 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@pcbeingused333 已经在做这个了。

开始于 2026年11月14日。

  • #2331 来自 @pcbeingused333 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
api

调研方向

从 Python 的 Problem.addConstraint 方法开始,它应当拒绝已经存在于 Problem.constrs 中的 Constraint 对象,因为原生求解器只接收 CSR 矩阵。使用 issue 中的代码片段复现,然后检查第二次添加是否抛出 ValueError,并且 p.constrs 和 c.index 保持不变。#2224 对应的 Java 修复 #2226 可作为预期行为的参考。

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

描述

bug

In the Python API, Problem.addConstraint accepts the same Constraint object twice. The second call overwrites constr.index and appends the constraint to Problem.constrs again, so the problem has two rows for one Constraint, and both rows map to the second index.

from cuopt.linear_programming.problem import Problem

p = Problem("dup")
x = p.addVariable(lb=0, ub=1, name="x")
c = x <= 1
p.addConstraint(c)
p.addConstraint(c)  # accepted; c.index becomes 1 and p.constrs holds c twice

Expected: ValueError, with p.constrs and c.index left unchanged.

Same bug as the Java one in #2224 (fixed in #2226). The check belongs in Problem.addConstraint, because the native solver only receives a CSR matrix.

🤖 Generated with Claude Code

主要语言
Cuda
星标
1.1k
派生
266
平均合并
1 天 23 小时
30 天内合并 PR
54

环境准备

从这里开始

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

NVIDIA/cuopt 的其他 Issue

查看 NVIDIA/cuopt 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 发到你的邮箱

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