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

オープン 初心者向け
#2,326 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@pcbeingused333 がすでに取り組んでいます。

2026年11月14日 から。

  • #2331 @pcbeingused333 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
api

調査の方向性

Python の Problem.addConstraint メソッドから始めてください。このメソッドは、ネイティブソルバーが CSR 行列しか受け取らないため、すでに Problem.constrs にある Constraint オブジェクトを拒否すべきです。issue のスニペットで再現し、2 回目の追加で 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時間
マージ済み PR(30日)
54

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

NVIDIA/cuopt のほかの issue

NVIDIA/cuopt の issue をすべて見る

似ている issue

Backend & API Design の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。