Skip to content

Commit

Permalink
Work on notebooks (added Toby's notebooks!)
Browse files Browse the repository at this point in the history
  • Loading branch information
spiralulam committed Nov 16, 2023
1 parent 6484356 commit e78b759
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 156 deletions.
2 changes: 2 additions & 0 deletions docs/notebooks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ These Jupyter Notebooks provide some examples on how to work with ENTMOOT. Their

notebooks/multi_obj_pareto
notebooks/multi_obj_with_constraints
notebooks/constraint_classes
notebooks/single_obj:maximisation
174 changes: 18 additions & 156 deletions docs/notebooks/constraint_classes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -33,7 +33,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -53,70 +53,9 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Set parameter Username\n",
"Academic license - for non-commercial use only - expires 2024-09-06\n",
"Read LP format model from file C:\\Users\\tobyb\\AppData\\Local\\Temp\\tmpzrofd3mo.pyomo.lp\n",
"Reading time = 0.02 seconds\n",
"x1: 2774 rows, 1913 columns, 9130 nonzeros\n",
"Gurobi Optimizer version 10.0.2 build v10.0.2rc0 (win64)\n",
"\n",
"CPU model: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz, instruction set [SSE2|AVX|AVX2|AVX512]\n",
"Thread count: 4 physical cores, 8 logical processors, using up to 8 threads\n",
"\n",
"Optimize a model with 2774 rows, 1913 columns and 9130 nonzeros\n",
"Model fingerprint: 0x31e842ff\n",
"Variable types: 1292 continuous, 621 integer (621 binary)\n",
"Coefficient statistics:\n",
" Matrix range [1e-06, 1e+06]\n",
" Objective range [1e+00, 2e+00]\n",
" Bounds range [1e+00, 5e+00]\n",
" RHS range [1e-04, 5e+00]\n",
"Presolve removed 273 rows and 260 columns\n",
"Presolve time: 0.05s\n",
"Presolved: 2501 rows, 1653 columns, 8080 nonzeros\n",
"Variable types: 1282 continuous, 371 integer (371 binary)\n",
"Found heuristic solution: objective 24.8382603\n",
"Found heuristic solution: objective 19.1248452\n",
"\n",
"Root relaxation: objective 2.576224e+00, 577 iterations, 0.01 seconds (0.01 work units)\n",
"\n",
" Nodes | Current Node | Objective Bounds | Work\n",
" Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time\n",
"\n",
" 0 0 2.57622 0 18 19.12485 2.57622 86.5% - 0s\n",
"H 0 0 3.6397521 2.57622 29.2% - 0s\n",
"H 0 0 3.3869028 3.24087 4.31% - 0s\n",
" 0 0 3.38690 0 6 3.38690 3.38690 0.00% - 0s\n",
"\n",
"Cutting planes:\n",
" Gomory: 4\n",
" Cover: 83\n",
" Implied bound: 402\n",
" Clique: 185\n",
" MIR: 4\n",
" Flow cover: 13\n",
" Network: 8\n",
" RLT: 30\n",
" Relax-and-lift: 98\n",
" PSD: 4\n",
"\n",
"Explored 1 nodes (877 simplex iterations) in 0.14 seconds (0.13 work units)\n",
"Thread count was 8 (of 8 available processors)\n",
"\n",
"Solution count 4: 3.3869 3.63975 19.1248 24.8383 \n",
"\n",
"Optimal solution found (tolerance 1.00e-04)\n",
"Best objective 3.386902819809e+00, best bound 3.386902819809e+00, gap 0.0000%\n"
]
}
],
"outputs": [],
"source": [
"from entmoot.constraints import NChooseKConstraint\n",
"model_pyo = problem_config.get_pyomo_model_core()\n",
Expand All @@ -139,17 +78,9 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0.0, 0.0, 4.088297585401641, 4.888952150927435, 4.944564863420855]\n"
]
}
],
"outputs": [],
"source": [
"print(res_pyo.opt_point)\n",
"assert 1 <= sum(x > 1e-6 for x in res_pyo.opt_point) <= 3"
Expand All @@ -173,7 +104,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -196,7 +127,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -213,7 +144,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -245,69 +176,9 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Set parameter Username\n",
"Academic license - for non-commercial use only - expires 2024-09-06\n",
"Read LP format model from file C:\\Users\\tobyb\\AppData\\Local\\Temp\\tmp0tfjrq6i.pyomo.lp\n",
"Reading time = 0.01 seconds\n",
"x1: 2775 rows, 1913 columns, 9133 nonzeros\n",
"Gurobi Optimizer version 10.0.2 build v10.0.2rc0 (win64)\n",
"\n",
"CPU model: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz, instruction set [SSE2|AVX|AVX2|AVX512]\n",
"Thread count: 4 physical cores, 8 logical processors, using up to 8 threads\n",
"\n",
"Optimize a model with 2775 rows, 1913 columns and 9133 nonzeros\n",
"Model fingerprint: 0x8879e895\n",
"Variable types: 1292 continuous, 621 integer (621 binary)\n",
"Coefficient statistics:\n",
" Matrix range [1e-06, 1e+06]\n",
" Objective range [1e+00, 2e+00]\n",
" Bounds range [1e+00, 5e+00]\n",
" RHS range [1e-04, 1e+01]\n",
"Presolve removed 273 rows and 260 columns\n",
"Presolve time: 0.05s\n",
"Presolved: 2502 rows, 1653 columns, 8084 nonzeros\n",
"Variable types: 1282 continuous, 371 integer (371 binary)\n",
"Found heuristic solution: objective 10.1607516\n",
"\n",
"Root relaxation: objective 2.501750e+00, 463 iterations, 0.00 seconds (0.00 work units)\n",
"\n",
" Nodes | Current Node | Objective Bounds | Work\n",
" Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time\n",
"\n",
" 0 0 2.50175 0 11 10.16075 2.50175 75.4% - 0s\n",
"H 0 0 10.1529199 2.50175 75.4% - 0s\n",
"H 0 0 2.8865055 2.50175 13.3% - 0s\n",
" 0 0 2.60484 0 3 2.88651 2.60484 9.76% - 0s\n",
" 0 0 2.60484 0 6 2.88651 2.60484 9.76% - 0s\n",
" 0 0 2.60484 0 5 2.88651 2.60484 9.76% - 0s\n",
"H 0 0 2.8764756 2.60484 9.44% - 0s\n",
" 0 0 2.69557 0 11 2.87648 2.69557 6.29% - 0s\n",
"H 0 0 2.8510016 2.69557 5.45% - 0s\n",
"* 0 0 0 2.8510016 2.85100 0.00% - 0s\n",
"\n",
"Cutting planes:\n",
" Cover: 1\n",
" Clique: 5\n",
" RLT: 1\n",
" Relax-and-lift: 6\n",
"\n",
"Explored 1 nodes (786 simplex iterations) in 0.16 seconds (0.12 work units)\n",
"Thread count was 8 (of 8 available processors)\n",
"\n",
"Solution count 5: 2.851 2.87648 2.88651 ... 10.1608\n",
"\n",
"Optimal solution found (tolerance 1.00e-04)\n",
"Best objective 2.851001621749e+00, best bound 2.851001621749e+00, gap 0.0000%\n"
]
}
],
"outputs": [],
"source": [
"# optimise the model\n",
"params_pyomo = {\"solver_name\": \"gurobi\"}\n",
Expand All @@ -317,27 +188,19 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0.0, 2.43082, 3.2917799999999997, 4.888964463647816, 3.6007]\n"
]
}
],
"outputs": [],
"source": [
"print(res_pyo.opt_point)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "enttest",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "enttest"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -349,10 +212,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.9"
},
"orig_nbformat": 4
"version": "3.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}

0 comments on commit e78b759

Please sign in to comment.