Skip to content

Commit 38b0863

Browse files
committed
update notebooks
1 parent a0aab3d commit 38b0863

File tree

290 files changed

+3005
-951
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

290 files changed

+3005
-951
lines changed

examples/notebook/algorithms/knapsack.ipynb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"id": "google",
66
"metadata": {},
77
"source": [
8-
"##### Copyright 2024 Google LLC."
8+
"##### Copyright 2025 Google LLC."
99
]
1010
},
1111
{
@@ -132,7 +132,11 @@
132132
]
133133
}
134134
],
135-
"metadata": {},
135+
"metadata": {
136+
"language_info": {
137+
"name": "python"
138+
}
139+
},
136140
"nbformat": 4,
137141
"nbformat_minor": 5
138142
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "google",
6+
"metadata": {},
7+
"source": [
8+
"##### Copyright 2025 Google LLC."
9+
]
10+
},
11+
{
12+
"cell_type": "markdown",
13+
"id": "apache",
14+
"metadata": {},
15+
"source": [
16+
"Licensed under the Apache License, Version 2.0 (the \"License\");\n",
17+
"you may not use this file except in compliance with the License.\n",
18+
"You may obtain a copy of the License at\n",
19+
"\n",
20+
" http://www.apache.org/licenses/LICENSE-2.0\n",
21+
"\n",
22+
"Unless required by applicable law or agreed to in writing, software\n",
23+
"distributed under the License is distributed on an \"AS IS\" BASIS,\n",
24+
"WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
25+
"See the License for the specific language governing permissions and\n",
26+
"limitations under the License.\n"
27+
]
28+
},
29+
{
30+
"cell_type": "markdown",
31+
"id": "basename",
32+
"metadata": {},
33+
"source": [
34+
"# set_cover"
35+
]
36+
},
37+
{
38+
"cell_type": "markdown",
39+
"id": "link",
40+
"metadata": {},
41+
"source": [
42+
"<table align=\"left\">\n",
43+
"<td>\n",
44+
"<a href=\"https://colab.research.google.com/github/google/or-tools/blob/main/examples/notebook/algorithms/set_cover.ipynb\"><img src=\"https://raw.githubusercontent.com/google/or-tools/main/tools/colab_32px.png\"/>Run in Google Colab</a>\n",
45+
"</td>\n",
46+
"<td>\n",
47+
"<a href=\"https://github.com/google/or-tools/blob/main/ortools/algorithms/samples/set_cover.py\"><img src=\"https://raw.githubusercontent.com/google/or-tools/main/tools/github_32px.png\"/>View source on GitHub</a>\n",
48+
"</td>\n",
49+
"</table>"
50+
]
51+
},
52+
{
53+
"cell_type": "markdown",
54+
"id": "doc",
55+
"metadata": {},
56+
"source": [
57+
"First, you must install [ortools](https://pypi.org/project/ortools/) package in this colab."
58+
]
59+
},
60+
{
61+
"cell_type": "code",
62+
"execution_count": null,
63+
"id": "install",
64+
"metadata": {},
65+
"outputs": [],
66+
"source": [
67+
"%pip install ortools"
68+
]
69+
},
70+
{
71+
"cell_type": "markdown",
72+
"id": "description",
73+
"metadata": {},
74+
"source": [
75+
"\n",
76+
"A simple set-covering problem.\n"
77+
]
78+
},
79+
{
80+
"cell_type": "code",
81+
"execution_count": null,
82+
"id": "code",
83+
"metadata": {},
84+
"outputs": [],
85+
"source": [
86+
"from ortools.algorithms.python import set_cover\n",
87+
"\n",
88+
"\n",
89+
"def main():\n",
90+
" model = set_cover.SetCoverModel()\n",
91+
" model.add_empty_subset(2.0)\n",
92+
" model.add_element_to_last_subset(0)\n",
93+
" model.add_empty_subset(2.0)\n",
94+
" model.add_element_to_last_subset(1)\n",
95+
" model.add_empty_subset(1.0)\n",
96+
" model.add_element_to_last_subset(0)\n",
97+
" model.add_element_to_last_subset(1)\n",
98+
"\n",
99+
" inv = set_cover.SetCoverInvariant(model)\n",
100+
" greedy = set_cover.GreedySolutionGenerator(inv)\n",
101+
" has_found = greedy.next_solution()\n",
102+
" if not has_found:\n",
103+
" print(\"No solution found by the greedy heuristic.\")\n",
104+
" return\n",
105+
" solution = inv.export_solution_as_proto()\n",
106+
"\n",
107+
" print(f\"Total cost: {solution.cost}\") # == inv.cost()\n",
108+
" print(f\"Total number of selected subsets: {solution.num_subsets}\")\n",
109+
" print(\"Chosen subsets:\")\n",
110+
" for subset in solution.subset:\n",
111+
" print(f\" {subset}\")\n",
112+
"\n",
113+
"\n",
114+
"main()\n",
115+
"\n"
116+
]
117+
}
118+
],
119+
"metadata": {
120+
"language_info": {
121+
"name": "python"
122+
}
123+
},
124+
"nbformat": 4,
125+
"nbformat_minor": 5
126+
}

examples/notebook/algorithms/simple_knapsack_program.ipynb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"id": "google",
66
"metadata": {},
77
"source": [
8-
"##### Copyright 2024 Google LLC."
8+
"##### Copyright 2025 Google LLC."
99
]
1010
},
1111
{
@@ -119,7 +119,11 @@
119119
]
120120
}
121121
],
122-
"metadata": {},
122+
"metadata": {
123+
"language_info": {
124+
"name": "python"
125+
}
126+
},
123127
"nbformat": 4,
124128
"nbformat_minor": 5
125129
}

examples/notebook/constraint_solver/cp_is_fun_cp.ipynb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"id": "google",
66
"metadata": {},
77
"source": [
8-
"##### Copyright 2024 Google LLC."
8+
"##### Copyright 2025 Google LLC."
99
]
1010
},
1111
{
@@ -91,6 +91,7 @@
9191
"from ortools.constraint_solver import pywrapcp\n",
9292
"\n",
9393
"\n",
94+
"\n",
9495
"def main():\n",
9596
" # Constraint programming engine\n",
9697
" solver = pywrapcp.Solver(\"CP is fun!\")\n",
@@ -155,7 +156,11 @@
155156
]
156157
}
157158
],
158-
"metadata": {},
159+
"metadata": {
160+
"language_info": {
161+
"name": "python"
162+
}
163+
},
159164
"nbformat": 4,
160165
"nbformat_minor": 5
161166
}

0 commit comments

Comments
 (0)