Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
test time
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-van-Woudenberg committed May 1, 2024
1 parent ad5e1ae commit 55db9d3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
2 changes: 1 addition & 1 deletion book/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ author: Tom van Woudenberg and Maria Nogal
email: [email protected]
logo: pages/figures/logo.jpg
only_build_toc_files : True
copyright: Delft University of Technology, CC BY 4.0

execute:
execute_notebooks: 'off'
Expand All @@ -15,7 +16,6 @@ html:
sphinx:
config:
bibtex_reference_style: author_year
html_show_copyright: false
html_js_files:
- https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js
thebe_config:
Expand Down
45 changes: 30 additions & 15 deletions book/pages/moo_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@
"\n",
"Click {fa}`rocket` --> {guilabel}`Live Code` to activate live coding on this page!\n",
"\n",
"\n",
"\n",
"\n",
"## Problem\n",
"In this problem we're trying to optimize a diesel engine for maximum power and minimum CO<sub>2</sub> emissions. Depending on the optimal engine speed, the power and CO<sub>2</sub> emissions change.\n",
"\n",
"The following data is available:\n",
"\n",
"| Rotations per minute | CO<sub>2</sub> Emissions | Power |\n",
"| Rotations per minute | CO<sub>2</sub> Emissions | Power |\n",
"|------|---------------|---------|\n",
"| 800 | 708. | 161.141 |\n",
"| 800 | 708 | 161.141 |\n",
"| 1000 | 696.889 | 263.243 |\n",
"| 1200 | 688.247 | 330.51 |\n",
"| 1200 | 688.247 | 330.51 |\n",
"| 1400 | 682.897 | 381.561 |\n",
"| 1700 | 684.955 | 391.17 |\n",
"| 1800 | 697.3 | 370. |\n",
"| 1700 | 684.955 | 391.17 |\n",
"| 1800 | 697.3 | 370 |\n",
"\n",
"This data is interpolated to obtain a continuous relation:"
]
Expand Down Expand Up @@ -191,6 +188,8 @@
":::{card} Test yourself\n",
"Try and adjust the values for $x$. Can you find the optimal solution? How does it change for different models?\n",
"<iframe src=\"../_static/power.html\" style=\"overflow:hidden;height:580;width:100%\" height=\"580\" width=\"100%\"> frameborder=\"0\"></iframe>\n",
"\n",
"<iframe src=\"https://tudelft.h5p.com/content/1292260165388503037/embed\" aria-label=\"Pareto optimal\" width=\"1088\" height=\"637\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\" allow=\"autoplay *; geolocation *; microphone *; camera *; midi *; encrypted-media *\"></iframe><script src=\"https://tudelft.h5p.com/js/h5p-resizer.js\" charset=\"UTF-8\"></script>\n",
":::"
]
},
Expand Down Expand Up @@ -419,14 +418,14 @@
"id": "18dba09c",
"metadata": {},
"source": [
"Now let's solve the problem for each of the three models.\n",
"Now let's solve the problem for each of the three models. We're gonna time them to see how long the analysis takes.\n",
"\n",
"#### Weighted objective function"
]
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 48,
"id": "d2d014c1",
"metadata": {},
"outputs": [
Expand All @@ -443,11 +442,14 @@
" jac: [-5.684e-06]\n",
" nfev: 26\n",
" njev: 13\n",
" hess_inv: <1x1 LbfgsInvHessProduct with dtype=float64>\n"
" hess_inv: <1x1 LbfgsInvHessProduct with dtype=float64>\n",
"CPU times: total: 46.9 ms\n",
"Wall time: 20.6 ms\n"
]
}
],
"source": [
"%%time\n",
"result = sp.optimize.minimize(fun = weighted_obj, x0 = x0, bounds = bounds)\n",
"print(result)"
]
Expand All @@ -462,7 +464,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 49,
"id": "89a9bfc1",
"metadata": {},
"outputs": [
Expand All @@ -479,11 +481,14 @@
" jac: [-5.684e-06]\n",
" nfev: 50\n",
" njev: 25\n",
" hess_inv: <1x1 LbfgsInvHessProduct with dtype=float64>\n"
" hess_inv: <1x1 LbfgsInvHessProduct with dtype=float64>\n",
"CPU times: total: 31.2 ms\n",
"Wall time: 25 ms\n"
]
}
],
"source": [
"%%time\n",
"result2 = sp.optimize.minimize(fun = goal_attainment, x0 = x0, bounds=bounds)\n",
"print(result2)"
]
Expand All @@ -500,11 +505,21 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 50,
"id": "476d4e0d",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: total: 922 ms\n",
"Wall time: 945 ms\n"
]
}
],
"source": [
"%%time\n",
"x_pareto_opt =[]\n",
"for delta_p in np.linspace(0,1,100):\n",
" delta_c = 1- delta_p\n",
Expand Down

0 comments on commit 55db9d3

Please sign in to comment.