|
1 | 1 | {
|
2 | 2 | "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 |
| - }, |
70 | 3 | {
|
71 | 4 | "cell_type": "markdown",
|
72 | 5 | "id": "4bb9ca8e-e701-4e76-863a-c39115b5b33e",
|
|
86 | 19 | },
|
87 | 20 | {
|
88 | 21 | "cell_type": "code",
|
89 |
| - "execution_count": 24, |
| 22 | + "execution_count": null, |
90 | 23 | "id": "ef8dcd2a-1aef-498c-b26f-13248b5169f1",
|
91 | 24 | "metadata": {},
|
92 | 25 | "outputs": [],
|
93 | 26 | "source": [
|
| 27 | + "import jijmodeling as jm\n", |
| 28 | + "\n", |
94 | 29 | "i = jm.Element(\"i\", (0, 3))"
|
95 | 30 | ]
|
96 | 31 | },
|
|
139 | 74 | },
|
140 | 75 | {
|
141 | 76 | "cell_type": "code",
|
142 |
| - "execution_count": 26, |
| 77 | + "execution_count": null, |
143 | 78 | "id": "e973ef97-c3a4-4715-b5d6-20cfe14e78c6",
|
144 | 79 | "metadata": {},
|
145 | 80 | "outputs": [],
|
146 | 81 | "source": [
|
147 | 82 | "import jijmodeling as jm\n",
|
| 83 | + "\n", |
148 | 84 | "i = jm.Element(\"i\", (0, 100))\n",
|
149 | 85 | "x = jm.BinaryVar(\"x\", shape=(100,))\n",
|
150 | 86 | "\n",
|
|
0 commit comments