Skip to content

Commit 6d956be

Browse files
committed
Translate scip.ipynb
1 parent 70ac17f commit 6d956be

File tree

1 file changed

+61
-61
lines changed

1 file changed

+61
-61
lines changed

docs/en/quickstart/scip.ipynb

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# SCIPで最適化問題を解く\n",
7+
"# Solving Optimization Problems with SCIP\n",
88
"\n",
9-
"`jijmodeling` の使い方を理解するために、このページではナップサック問題を解いてみましょう。ただし、`jijmodeling` は数理モデルを記述するためのツールであるため、単独では最適化問題を解くことはできません。なので、数理最適化ソルバー[SCIP](https://www.scipopt.org/)と組み合わせて解くこととします。\n",
9+
"To understand how to use `jijmodeling`, let's solve the knapsack problem on this page. However, since `jijmodeling` is a tool for describing mathematical models, it cannot solve optimization problems on its own. Therefore, we will solve it in combination with the mathematical optimization solver [SCIP](https://www.scipopt.org/).\n",
1010
"\n",
11-
"`jijmodeling` とSCIPを組み合わせて使うには、 `ommx-pyscipopt-adapter` ([GitHub](https://github.com/Jij-Inc/ommx/tree/main/python/ommx-pyscipopt-adapter), [PyPI](https://pypi.org/project/ommx-pyscipopt-adapter/)) というPythonパッケージをインストールする必要があります。以下のコマンドでインストールしてください。\n",
11+
"To use `jijmodeling` with SCIP, you need to install a Python package called `ommx-pyscipopt-adapter` ([GitHub](https://github.com/Jij-Inc/ommx/tree/main/python/ommx-pyscipopt-adapter), [PyPI](https://pypi.org/project/ommx-pyscipopt-adapter/)). Please install it with the following command:\n",
1212
"\n",
1313
"```bash\n",
1414
"pip install ommx-pyscipopt-adapter\n",
@@ -19,9 +19,9 @@
1919
"cell_type": "markdown",
2020
"metadata": {},
2121
"source": [
22-
"## 問題設定\n",
22+
"## Problem Setting\n",
2323
"\n",
24-
"ナップサック問題は以下のように数理モデルとして定式化することができます:\n",
24+
"The knapsack problem can be formulated as a mathematical model as follows:\n",
2525
"\n",
2626
"$$\n",
2727
"\\begin{align*}\n",
@@ -32,43 +32,43 @@
3232
"$$\n",
3333
"\n",
3434
":::{hint}\n",
35-
"ナップサック問題の定式化について詳しく知りたい場合は [こちら](https://www.documentation.jijzept.com/docs/tutorial/knapsack/) を参照してください。\n",
35+
"For more details on the formulation of the knapsack problem, please refer to [here](https://www.documentation.jijzept.com/docs/tutorial/knapsack/).\n",
3636
":::\n",
3737
"\n",
38-
"この数理モデルにあるそれぞれのパラメーターの意味は以下の通りです:\n",
38+
"The meaning of each parameter in this mathematical model is as follows:\n",
3939
"\n",
40-
"| パラメーター | 説明 |\n",
40+
"| Parameter | Description |\n",
4141
"| --- | --- |\n",
42-
"| $N$ |\tアイテムの総数 |\n",
43-
"| $v_{i}$ | アイテム $i$ の価値 |\n",
44-
"| $w_{i}$ | アイテム $i$ の重さ |\n",
45-
"| $W$ | ナップサックの耐荷重 |\n",
42+
"| $N$ |\tTotal number of items |\n",
43+
"| $v_{i}$ | Value of item $i$ |\n",
44+
"| $w_{i}$ | Weight of item $i$ |\n",
45+
"| $W$ | Weight capacity of the knapsack |\n",
4646
"\n",
47-
"今回の説明では、上記の数理モデルのパラメーター $v_{i}, w_{i}, W$ に、次の値を入力して得られる[インスタンス](what_is_instance)を解くことを考えます:\n",
47+
"In this explanation, we will solve an [instance](what_is_instance) obtained by inputting the following values into the parameters $v_{i}, w_{i}, W$ of the above mathematical model:\n",
4848
"\n",
49-
"| パラメーター | |\n",
49+
"| Parameter | Value |\n",
5050
"| --- | --- |\n",
5151
"| $v_{i}$ | `[10, 13, 18, 31, 7, 15]` |\n",
5252
"| $w_{i}$ | `[11, 15, 20, 35, 10, 33]` |\n",
5353
"| $W$ | `47` |\n",
5454
"\n",
5555
"(what_is_instance)=\n",
56-
":::{admonition} インスタンスとは\n",
57-
"`jijmodeling` では、数理モデルのパラメータに具体的な値を入れたものを”インスタンス”と呼んでいます。\n",
56+
":::{admonition} What is an instance?\n",
57+
"In `jijmodeling`, an instance is a mathematical model with specific values assigned to its parameters.\n",
5858
":::"
5959
]
6060
},
6161
{
6262
"cell_type": "markdown",
6363
"metadata": {},
6464
"source": [
65-
"## インスタンスの生成手順\n",
65+
"## Procedure for Generating an Instance\n",
6666
"\n",
67-
"`jijmodeling` を使うと、ソルバーに入力するためのインスタンスを次の3ステップで生成できます:\n",
67+
"Using `jijmodeling`, you can generate an instance to input into the solver in the following three steps:\n",
6868
"\n",
69-
"1. `jijmodeling` でナップサック問題を定式化する\n",
70-
"2. `Interpreter` オブジェクトにインスタンスデータを登録する\n",
71-
"3. `Interpreter` オブジェクトを使って数理モデルをインスタンスに変換する\n",
69+
"1. Formulate the knapsack problem with `jijmodeling`\n",
70+
"2. Register instance data in the `Interpreter` object\n",
71+
"3. Convert the mathematical model to an instance using the `Interpreter` object\n",
7272
"\n",
7373
"![Diagram of the process to generate an instance from a mathematical model](./assets/scip_01.png)"
7474
]
@@ -77,51 +77,51 @@
7777
"cell_type": "markdown",
7878
"metadata": {},
7979
"source": [
80-
"## Step1. JijModelingでナップサック問題を定式化する\n",
80+
"## Step1. Formulate the Knapsack Problem with JijModeling\n",
8181
"\n",
82-
"`jijmodeling` を使用してナップサック問題を定式化すると、以下のPythonコードになります:"
82+
"The following Python code formulates the knapsack problem using `jijmodeling`:"
8383
]
8484
},
8585
{
8686
"cell_type": "code",
87-
"execution_count": 13,
87+
"execution_count": 1,
8888
"metadata": {},
8989
"outputs": [
9090
{
9191
"data": {
9292
"text/latex": [
93-
"$$\\begin{array}{cccc}\\text{Problem:} & \\text{problem} & & \\\\& & \\max \\quad \\displaystyle \\sum_{i = 0}^{N - 1} v_{i} \\cdot x_{i} & \\\\\\text{{s.t.}} & & & \\\\ & \\text{重量制限} & \\displaystyle \\sum_{i = 0}^{N - 1} w_{i} \\cdot x_{i} \\leq W & \\\\\\text{{where}} & & & \\\\& x & 1\\text{-dim binary variable}\\\\\\end{array}$$"
93+
"$$\\begin{array}{cccc}\\text{Problem:} & \\text{problem} & & \\\\& & \\max \\quad \\displaystyle \\sum_{i = 0}^{N - 1} v_{i} \\cdot x_{i} & \\\\\\text{{s.t.}} & & & \\\\ & \\text{Weight Constraint} & \\displaystyle \\sum_{i = 0}^{N - 1} w_{i} \\cdot x_{i} \\leq W & \\\\\\text{{where}} & & & \\\\& x & 1\\text{-dim binary variable}\\\\\\end{array}$$"
9494
],
9595
"text/plain": [
96-
"<jijmodeling.Problem at 0x1234887d0>"
96+
"<jijmodeling.Problem at 0x12567f6f0>"
9797
]
9898
},
99-
"execution_count": 13,
99+
"execution_count": 1,
100100
"metadata": {},
101101
"output_type": "execute_result"
102102
}
103103
],
104104
"source": [
105105
"import jijmodeling as jm\n",
106106
"\n",
107-
"# アイテムの価値\n",
107+
"# Value of items\n",
108108
"v = jm.Placeholder(\"v\", ndim=1)\n",
109-
"# アイテムの重さ\n",
109+
"# Weight of items\n",
110110
"w = jm.Placeholder(\"w\", ndim=1)\n",
111-
"# ナップサックの耐荷重\n",
111+
"# Weight capacity of the knapsack\n",
112112
"W = jm.Placeholder(\"W\")\n",
113-
"# アイテムの総数\n",
113+
"# Total number of items\n",
114114
"N = v.len_at(0, latex=\"N\")\n",
115-
"# アイテムiをナップサックに入れる場合は1, 入れない場合は0を取る決定変数\n",
115+
"# Decision variable: 1 if item i is in the knapsack, 0 otherwise\n",
116116
"x = jm.BinaryVar(\"x\", shape=(N,)) \n",
117-
"# アイテムに割り当てられた番号を走る添え字\n",
117+
"# Index running over the assigned numbers of items\n",
118118
"i = jm.Element(\"i\", belong_to=(0, N))\n",
119119
"\n",
120120
"problem = jm.Problem(\"problem\", sense=jm.ProblemSense.MAXIMIZE)\n",
121-
"# 目的関数\n",
121+
"# Objective function\n",
122122
"problem += jm.sum(i, v[i] * x[i])\n",
123-
"# 制約条件: ナップサックの耐荷重を超えない\n",
124-
"problem += jm.Constraint(\"重量制限\", jm.sum(i, w[i] * x[i]) <= W)\n",
123+
"# Constraint: Do not exceed the weight capacity of the knapsack\n",
124+
"problem += jm.Constraint(\"Weight Constraint\", jm.sum(i, w[i] * x[i]) <= W)\n",
125125
"problem"
126126
]
127127
},
@@ -130,34 +130,34 @@
130130
"metadata": {},
131131
"source": [
132132
":::{hint}\n",
133-
"`jijmodeling` での定式化の方法については詳しく知りたい場合は[こちら](../tutorials/expressions.ipynb)を参照してください。\n",
133+
"For more details on how to formulate with `jijmodeling`, please refer to [here](../tutorials/expressions.ipynb).\n",
134134
":::"
135135
]
136136
},
137137
{
138138
"cell_type": "markdown",
139139
"metadata": {},
140140
"source": [
141-
"## Step2. `Interpreter` オブジェクトにインスタンスデータを登録する\n",
141+
"## Step2. Register Instance Data in the `Interpreter` Object\n",
142142
"\n",
143-
"Step1で定式化した数理モデルの `Placeholder` に入力するインスタンスデータを用意し、 `Interpreter` オブジェクトに登録します。\n",
143+
"Prepare the instance data to be input into the `Placeholder` of the mathematical model formulated in Step1, and register it in the `Interpreter` object.\n",
144144
"\n",
145-
"`Interpreter` クラスのコンストラクタの引数に、以下のキーと値を持つ辞書を渡すことでインスタンスデータを登録できます:\n",
145+
"You can register instance data by passing a dictionary with the following keys and values to the constructor of the `Interpreter` class:\n",
146146
"\n",
147-
"- キー:`Placeholder` オブジェクトの `name` プロパティに設定した文字列\n",
148-
"- 値:入力するデータ"
147+
"- Key: String set in the `name` property of the `Placeholder` object\n",
148+
"- Value: Data to be input"
149149
]
150150
},
151151
{
152152
"cell_type": "code",
153-
"execution_count": 15,
153+
"execution_count": 2,
154154
"metadata": {},
155155
"outputs": [],
156156
"source": [
157157
"instance_data = {\n",
158-
" \"v\": [10, 13, 18, 31, 7, 15], # アイテムの価値のデータ\n",
159-
" \"w\": [11, 15, 20, 35, 10, 33], # アイテムの重さのデータ\n",
160-
" \"W\": 47, # ナップサックの耐荷重のデータ\n",
158+
" \"v\": [10, 13, 18, 31, 7, 15], # Data of item values\n",
159+
" \"w\": [11, 15, 20, 35, 10, 33], # Data of item weights\n",
160+
" \"W\": 47, # Data of the knapsack's weight capacity\n",
161161
"}\n",
162162
"interpreter = jm.Interpreter(instance_data)"
163163
]
@@ -166,9 +166,9 @@
166166
"cell_type": "markdown",
167167
"metadata": {},
168168
"source": [
169-
"## Step3. `Interpreter` オブジェクトを使って数理モデルをインスタンスに変換する\n",
169+
"## Step3. Convert the Mathematical Model to an Instance Using the `Interpreter` Object\n",
170170
"\n",
171-
"数理モデルをインスタンスに変換するには、`Interpreter.eval_problem` メソッドを使用します。インスタンスデータが登録された `Interpreter` オブジェクトの `eval_problem` メソッドに `Problem` オブジェクトを渡すと、その `Problem` オブジェクトが持つ `Placeholder` にインスタンスデータを入力され、インスタンスに変換されます:"
171+
"To convert the mathematical model to an instance, use the `Interpreter.eval_problem` method. By passing the `Problem` object to the `eval_problem` method of the `Interpreter` object with registered instance data, the `Placeholder` in the `Problem` object will be filled with the instance data and converted to an instance:"
172172
]
173173
},
174174
{
@@ -185,55 +185,55 @@
185185
"metadata": {},
186186
"source": [
187187
":::{hint}\n",
188-
"`Interpreter.eval_problem` の返却値は `ommx.v1.Instance` オブジェクトです。OMMXについて詳しく知りたい場合は[こちら](https://github.com/Jij-Inc/ommx)を参照してください。\n",
188+
"The return value of `Interpreter.eval_problem` is an `ommx.v1.Instance` object. For more details about OMMX, please refer to [here](https://github.com/Jij-Inc/ommx).\n",
189189
":::"
190190
]
191191
},
192192
{
193193
"cell_type": "markdown",
194194
"metadata": {},
195195
"source": [
196-
"## 最適化問題を解く\n",
196+
"## Solving the Optimization Problem\n",
197197
"\n",
198-
"では、Step3で得られたインスタンスを最適化ソルバーSCIPで解いてみましょう。以下のPythonコードで目的関数の最適値を得ることができます:"
198+
"Now, let's solve the instance obtained in Step3 with the optimization solver SCIP. The following Python code can be used to obtain the optimal value of the objective function:"
199199
]
200200
},
201201
{
202202
"cell_type": "code",
203-
"execution_count": null,
203+
"execution_count": 4,
204204
"metadata": {},
205205
"outputs": [
206206
{
207207
"name": "stdout",
208208
"output_type": "stream",
209209
"text": [
210-
"目的関数の最適値: 41.0\n"
210+
"Optimal value of the objective function: 41.0\n"
211211
]
212212
}
213213
],
214214
"source": [
215215
"from ommx_pyscipopt_adapter import instance_to_model, model_to_solution\n",
216216
"\n",
217-
"# インスタンスをSCIPの読み取れる形に変換する\n",
217+
"# Convert the instance to a format readable by SCIP\n",
218218
"model = instance_to_model(instance)\n",
219-
"# SCIPでインスタンスを解く\n",
219+
"# Solve the instance with SCIP\n",
220220
"model.optimize()\n",
221-
"# SCIPで得られた結果を取得する\n",
221+
"# Retrieve the results obtained by SCIP\n",
222222
"solution = model_to_solution(model, instance)\n",
223223
"\n",
224-
"print(f\"目的関数の最適値: {solution.objective}\")"
224+
"print(f\"Optimal value of the objective function: {solution.objective}\")"
225225
]
226226
},
227227
{
228228
"cell_type": "markdown",
229229
"metadata": {},
230230
"source": [
231-
"また、`solution` の `decision_variables` プロパティを使うことで `pandas.DataFrame` オブジェクトとして決定変数の状態を表示できます:"
231+
"In addition, you can display the state of the decision variables as a `pandas.DataFrame` object using the `decision_variables` property of `solution`:"
232232
]
233233
},
234234
{
235235
"cell_type": "code",
236-
"execution_count": 18,
236+
"execution_count": 5,
237237
"metadata": {},
238238
"outputs": [
239239
{
@@ -331,7 +331,7 @@
331331
"5 x [5] 0.0"
332332
]
333333
},
334-
"execution_count": 18,
334+
"execution_count": 5,
335335
"metadata": {},
336336
"output_type": "execute_result"
337337
}
@@ -366,7 +366,7 @@
366366
"name": "python",
367367
"nbconvert_exporter": "python",
368368
"pygments_lexer": "ipython3",
369-
"version": "3.9.16"
369+
"version": "3.11.4"
370370
}
371371
},
372372
"nbformat": 4,

0 commit comments

Comments
 (0)