diff --git a/docs/en/releases/unreleased.ipynb b/docs/en/releases/unreleased.ipynb index 3cb1937..46a7b15 100644 --- a/docs/en/releases/unreleased.ipynb +++ b/docs/en/releases/unreleased.ipynb @@ -711,12 +711,53 @@ }, { "cell_type": "markdown", - "id": "dd292ce1", + "id": "9364f11d", "metadata": {}, "source": [ "In previous releases, the `latex` specifications were ignored in the code above, and the bounds were displayed as $L \\leq x \\leq U$.\n", "Starting with this release, the settings are preserved as shown above, and the bounds are displayed as $\\ell \\leq x \\leq \\mathcal{U}$.\n", "\n", + "### Fixed a bug where problem evaluation with constraint detection crashed when decision variables were subscripted by tuples\n", + "\n", + "We fixed a bug where `eval_problem` crashed when decision variables were subscripted with tuples and constraint detection was enabled (this is the case by default, or when the `constraint_detection` keyword argument was set to something other than `False`). For example, the following code used to crash in previous versions:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7197eb7a", + "metadata": {}, + "outputs": [], + "source": [ + "import jijmodeling as jm\n", + "\n", + "\n", + "@jm.Problem.define(\"dict-keyed binary var with tuple subscripts\")\n", + "def problem(problem: jm.DecoratedProblem):\n", + " N = problem.Natural()\n", + " K = problem.Placeholder(ndim=1, dtype=(jm.DataType.NATURAL, jm.DataType.NATURAL))\n", + " x = problem.BinaryVar(dict_keys=K)\n", + "\n", + " problem += problem.Constraint(\n", + " \"sweeps\",\n", + " (jm.sum(x[k] for k in K if k[0] == i) <= 1 for i in jm.range(N)),\n", + " )\n", + "\n", + "\n", + "instance_data = {\n", + " \"N\": 3,\n", + " \"K\": [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1)],\n", + "}\n", + "\n", + "compiler = jm.Compiler.from_problem(problem, instance_data)\n", + "instance = compiler.eval_problem(problem, constraint_detection=True)" + ] + }, + { + "cell_type": "markdown", + "id": "dd292ce1", + "metadata": {}, + "source": [ "## Other Changes\n", "\n", "- Relaxed version bounds to allow installation on any Python 3 version from Python 3.11 onwards.\n", diff --git a/docs/ja/releases/unreleased.ipynb b/docs/ja/releases/unreleased.ipynb index abce24a..a35116e 100644 --- a/docs/ja/releases/unreleased.ipynb +++ b/docs/ja/releases/unreleased.ipynb @@ -692,10 +692,51 @@ }, { "cell_type": "markdown", + "id": "28161888", "metadata": {}, "source": [ "これまでのリリースでは、上記のコードでは `latex` 指定が無視され、$L \\leq x \\leq U$ のように表示されていましたが、上記のように設定が保たれるようになり、$\\ell \\leq x \\leq \\mathcal{U}$ と表示されるようになりました。\n", "\n", + "### 決定変数がタプルで添字付けされている場合に制約検出付きの問題評価がクラッシュするバグの修正\n", + "\n", + "決定変数がタプル型のキーを持つ辞書で添字付けされている時、制約検出が有効な状態(デフォルトや、 `constraint_detection` キーワード引数が `False` 以外の場合)で `eval_problem` がクラッシュするバグを修正しました。たとえば、以前のバージョンでは以下のコードはクラッシュしていました。" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bde30e3c", + "metadata": {}, + "outputs": [], + "source": [ + "import jijmodeling as jm\n", + "\n", + "\n", + "@jm.Problem.define(\"dict-keyed binary var with tuple subscripts\")\n", + "def problem(problem: jm.DecoratedProblem):\n", + " N = problem.Natural()\n", + " K = problem.Placeholder(ndim=1, dtype=(jm.DataType.NATURAL, jm.DataType.NATURAL))\n", + " x = problem.BinaryVar(dict_keys=K)\n", + "\n", + " problem += problem.Constraint(\n", + " \"sweeps\",\n", + " (jm.sum(x[k] for k in K if k[0] == i) <= 1 for i in jm.range(N)),\n", + " )\n", + "\n", + "\n", + "instance_data = {\n", + " \"N\": 3,\n", + " \"K\": [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1)],\n", + "}\n", + "\n", + "compiler = jm.Compiler.from_problem(problem, instance_data)\n", + "instance = compiler.eval_problem(problem, constraint_detection=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ "## その他の変更\n", "\n", "- バージョン条件を緩和し、Python 3.11 以降の任意の Python 3 でのインストールを許容しました。\n", diff --git a/markdowns/en/releases/unreleased.md b/markdowns/en/releases/unreleased.md index 2921e46..b2c1c78 100644 --- a/markdowns/en/releases/unreleased.md +++ b/markdowns/en/releases/unreleased.md @@ -226,6 +226,35 @@ problem In previous releases, the `latex` specifications were ignored in the code above, and the bounds were displayed as $L \leq x \leq U$. Starting with this release, the settings are preserved as shown above, and the bounds are displayed as $\ell \leq x \leq \mathcal{U}$. +### Fixed a bug where problem evaluation with constraint detection crashed when decision variables were subscripted by tuples + +We fixed a bug where `eval_problem` crashed when decision variables were subscripted with tuples and constraint detection was enabled (this is the case by default, or when the `constraint_detection` keyword argument was set to something other than `False`). For example, the following code used to crash in previous versions: + +```{code-cell} ipython3 +import jijmodeling as jm + + +@jm.Problem.define("dict-keyed binary var with tuple subscripts") +def problem(problem: jm.DecoratedProblem): + N = problem.Natural() + K = problem.Placeholder(ndim=1, dtype=(jm.DataType.NATURAL, jm.DataType.NATURAL)) + x = problem.BinaryVar(dict_keys=K) + + problem += problem.Constraint( + "sweeps", + (jm.sum(x[k] for k in K if k[0] == i) <= 1 for i in jm.range(N)), + ) + + +instance_data = { + "N": 3, + "K": [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1)], +} + +compiler = jm.Compiler.from_problem(problem, instance_data) +instance = compiler.eval_problem(problem, constraint_detection=True) +``` + ## Other Changes - Relaxed version bounds to allow installation on any Python 3 version from Python 3.11 onwards. diff --git a/markdowns/ja/releases/unreleased.md b/markdowns/ja/releases/unreleased.md index 8be5f8f..52d4169 100644 --- a/markdowns/ja/releases/unreleased.md +++ b/markdowns/ja/releases/unreleased.md @@ -219,6 +219,35 @@ problem これまでのリリースでは、上記のコードでは `latex` 指定が無視され、$L \leq x \leq U$ のように表示されていましたが、上記のように設定が保たれるようになり、$\ell \leq x \leq \mathcal{U}$ と表示されるようになりました。 +### 決定変数がタプルで添字付けされている場合に制約検出付きの問題評価がクラッシュするバグの修正 + +決定変数がタプル型のキーを持つ辞書で添字付けされている時、制約検出が有効な状態(デフォルトや、 `constraint_detection` キーワード引数が `False` 以外の場合)で `eval_problem` がクラッシュするバグを修正しました。たとえば、以前のバージョンでは以下のコードはクラッシュしていました。 + +```{code-cell} ipython3 +import jijmodeling as jm + + +@jm.Problem.define("dict-keyed binary var with tuple subscripts") +def problem(problem: jm.DecoratedProblem): + N = problem.Natural() + K = problem.Placeholder(ndim=1, dtype=(jm.DataType.NATURAL, jm.DataType.NATURAL)) + x = problem.BinaryVar(dict_keys=K) + + problem += problem.Constraint( + "sweeps", + (jm.sum(x[k] for k in K if k[0] == i) <= 1 for i in jm.range(N)), + ) + + +instance_data = { + "N": 3, + "K": [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1)], +} + +compiler = jm.Compiler.from_problem(problem, instance_data) +instance = compiler.eval_problem(problem, constraint_detection=True) +``` + ## その他の変更 - バージョン条件を緩和し、Python 3.11 以降の任意の Python 3 でのインストールを許容しました。