Skip to content

Commit c2617e0

Browse files
taqrotakuro saito
and
takuro saito
authored
delete unnecessary section (#40)
以下のリリースにより、既存のprobelemの目的関数に項を追加する際に、problemを再定義しなくても良くなった。 https://jij-inc.github.io/JijModeling-Tutorials/ja/releases/jijmodeling-1.10.0.html#id4 --------- Co-authored-by: takuro saito <t.saito@j-ij.com>
1 parent 6c6173a commit c2617e0

File tree

2 files changed

+11
-138
lines changed

2 files changed

+11
-138
lines changed

docs/en/references/tips.ipynb

Lines changed: 5 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,5 @@
11
{
22
"cells": [
3-
{
4-
"cell_type": "markdown",
5-
"id": "401c06b6-0401-4615-bdfe-05ec1e2c2ed5",
6-
"metadata": {},
7-
"source": [
8-
"# Tips\n",
9-
"\n",
10-
"## Adding Terms to the Objective Function\n",
11-
"\n",
12-
"The objective function of `Problem` is designed to be overwritten. Therefore, be careful that adding a new objective function will overwrite the existing one."
13-
]
14-
},
15-
{
16-
"cell_type": "code",
17-
"execution_count": 22,
18-
"id": "e52f2f5a-0db6-44e4-a2d4-90089b10f091",
19-
"metadata": {},
20-
"outputs": [],
21-
"source": [
22-
"import jijmodeling as jm\n",
23-
"\n",
24-
"c = jm.Placeholder(\"c\", ndim=1)\n",
25-
"N = c.len_at(0)\n",
26-
"x = jm.BinaryVar(\"x\", shape=(N,))\n",
27-
"i = jm.Element(\"i\", (0, N))\n",
28-
"problem = jm.Problem(\"my problem\")\n",
29-
"problem += jm.sum(i, c[i] * x[i]) # Set the objective function\n",
30-
"\n",
31-
"# If you want to add another variable or expression later,\n",
32-
"# you need to start by creating a new objective function\n",
33-
"d = jm.Placeholder(\"d\", ndim=1)\n",
34-
"M = d.len_at(0)\n",
35-
"y = jm.BinaryVar(\"y\", shape=(M,))\n",
36-
"j = jm.Element(\"j\", (0, M))\n",
37-
"problem += jm.sum(i, c[i] * x[i]) + jm.sum(j, d[j] * y[j])"
38-
]
39-
},
40-
{
41-
"cell_type": "markdown",
42-
"id": "7287b601-5e1e-4d5c-a58d-ece7e05673e0",
43-
"metadata": {},
44-
"source": [
45-
"If you want to construct a more complex objective function, it is recommended to assemble simple terms or expressions before writing out the final expression. For example:"
46-
]
47-
},
48-
{
49-
"cell_type": "code",
50-
"execution_count": 23,
51-
"id": "9a9caf33-e82c-4eef-94da-fc38638a0a1f",
52-
"metadata": {},
53-
"outputs": [],
54-
"source": [
55-
"sum_of_xs = jm.sum(i, c[i] * x[i])\n",
56-
"sum_of_ys = jm.sum(j, d[j] * y[j])\n",
57-
"problem += sum_of_xs + sum_of_ys"
58-
]
59-
},
60-
{
61-
"cell_type": "markdown",
62-
"id": "27a7cd4e-0e1c-4395-88c9-0e2ed823a6c8",
63-
"metadata": {},
64-
"source": [
65-
":::{caution}\n",
66-
"Currently, `jijmodeling` does not support mathematical models with multiple objective functions.\n",
67-
":::"
68-
]
69-
},
703
{
714
"cell_type": "markdown",
725
"id": "4bb9ca8e-e701-4e76-863a-c39115b5b33e",
@@ -86,11 +19,13 @@
8619
},
8720
{
8821
"cell_type": "code",
89-
"execution_count": 24,
22+
"execution_count": null,
9023
"id": "ef8dcd2a-1aef-498c-b26f-13248b5169f1",
9124
"metadata": {},
9225
"outputs": [],
9326
"source": [
27+
"import jijmodeling as jm\n",
28+
"\n",
9429
"i = jm.Element(\"i\", (0, 3))"
9530
]
9631
},
@@ -139,12 +74,13 @@
13974
},
14075
{
14176
"cell_type": "code",
142-
"execution_count": 26,
77+
"execution_count": null,
14378
"id": "e973ef97-c3a4-4715-b5d6-20cfe14e78c6",
14479
"metadata": {},
14580
"outputs": [],
14681
"source": [
14782
"import jijmodeling as jm\n",
83+
"\n",
14884
"i = jm.Element(\"i\", (0, 100))\n",
14985
"x = jm.BinaryVar(\"x\", shape=(100,))\n",
15086
"\n",

docs/ja/references/tips.ipynb

Lines changed: 6 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,5 @@
11
{
22
"cells": [
3-
{
4-
"cell_type": "markdown",
5-
"id": "401c06b6-0401-4615-bdfe-05ec1e2c2ed5",
6-
"metadata": {},
7-
"source": [
8-
"# Tips\n",
9-
"\n",
10-
"## 目的関数への項の追加\n",
11-
"\n",
12-
"`Problem`の目的関数は上書きする仕様になっています。そのため、新しい目的関数を加えると既に設定されている目的関数を上書きしてしまうことに注意してください。"
13-
]
14-
},
15-
{
16-
"cell_type": "code",
17-
"execution_count": 22,
18-
"id": "e52f2f5a-0db6-44e4-a2d4-90089b10f091",
19-
"metadata": {},
20-
"outputs": [],
21-
"source": [
22-
"import jijmodeling as jm\n",
23-
"\n",
24-
"c = jm.Placeholder(\"c\", ndim=1)\n",
25-
"N = c.len_at(0)\n",
26-
"x = jm.BinaryVar(\"x\", shape=(N,))\n",
27-
"i = jm.Element(\"i\", (0, N))\n",
28-
"problem = jm.Problem(\"my problem\")\n",
29-
"problem += jm.sum(i, c[i] * x[i]) # 目的関数を設定\n",
30-
"\n",
31-
"# 後から別の変数や式を追加したくなった場合は、\n",
32-
"# 新しい目的関数として式を作るところから始める必要があります\n",
33-
"d = jm.Placeholder(\"d\", ndim=1)\n",
34-
"M = d.len_at(0)\n",
35-
"y = jm.BinaryVar(\"y\", shape=(M,))\n",
36-
"j = jm.Element(\"j\", (0, M))\n",
37-
"problem += jm.sum(i, c[i] * x[i]) + jm.sum(j, d[j] * y[j])"
38-
]
39-
},
40-
{
41-
"cell_type": "markdown",
42-
"id": "7287b601-5e1e-4d5c-a58d-ece7e05673e0",
43-
"metadata": {},
44-
"source": [
45-
"より複雑な目的関数を構築したい場合は、最終的な式を書き出す前に、簡単な項や式を組み立てから足し合わせることをおすすめします。例えば、以下のようにすると良いでしょう。"
46-
]
47-
},
48-
{
49-
"cell_type": "code",
50-
"execution_count": 23,
51-
"id": "9a9caf33-e82c-4eef-94da-fc38638a0a1f",
52-
"metadata": {},
53-
"outputs": [],
54-
"source": [
55-
"sum_of_xs = jm.sum(i, c[i] * x[i])\n",
56-
"sum_of_ys = jm.sum(j, d[j] * y[j])\n",
57-
"problem += sum_of_xs + sum_of_ys"
58-
]
59-
},
60-
{
61-
"cell_type": "markdown",
62-
"id": "27a7cd4e-0e1c-4395-88c9-0e2ed823a6c8",
63-
"metadata": {},
64-
"source": [
65-
":::{caution}\n",
66-
"現在の`jijmodeling`では複数の目的関数を持つ数理モデルをサポートしていません。\n",
67-
":::"
68-
]
69-
},
703
{
714
"cell_type": "markdown",
725
"id": "4bb9ca8e-e701-4e76-863a-c39115b5b33e",
@@ -86,11 +19,14 @@
8619
},
8720
{
8821
"cell_type": "code",
89-
"execution_count": 24,
22+
"execution_count": null,
9023
"id": "ef8dcd2a-1aef-498c-b26f-13248b5169f1",
9124
"metadata": {},
9225
"outputs": [],
9326
"source": [
27+
"import jijmodeling as jm\n",
28+
"\n",
29+
"\n",
9430
"i = jm.Element(\"i\", (0, 3))"
9531
]
9632
},
@@ -139,12 +75,13 @@
13975
},
14076
{
14177
"cell_type": "code",
142-
"execution_count": 26,
78+
"execution_count": null,
14379
"id": "e973ef97-c3a4-4715-b5d6-20cfe14e78c6",
14480
"metadata": {},
14581
"outputs": [],
14682
"source": [
14783
"import jijmodeling as jm\n",
84+
"\n",
14885
"i = jm.Element(\"i\", (0, 100))\n",
14986
"x = jm.BinaryVar(\"x\", shape=(100,))\n",
15087
"\n",

0 commit comments

Comments
 (0)