Skip to content

Commit

Permalink
deploy: 5a2e66a
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandrozocca committed Oct 30, 2023
1 parent 09e47b5 commit c653488
Show file tree
Hide file tree
Showing 36 changed files with 1,098 additions and 925 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion _sources/notebooks/04/power-network.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
" !pip install highspy >/dev/null 2>/dev/null\n",
" \n",
"solver = 'appsi_highs'\n",
" \n",
"\n",
"import pyomo.environ as pyo\n",
"SOLVER = pyo.SolverFactory(solver)\n",
" \n",
Expand Down
448 changes: 253 additions & 195 deletions _sources/notebooks/05/cutting-stock.ipynb

Large diffs are not rendered by default.

23 changes: 18 additions & 5 deletions _sources/notebooks/05/milk-pooling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"```\n",
"```{index} single: Pyomo; block\n",
"```\n",
"```{index} single: solver; cbc\n",
"```{index} single: solver; highs\n",
"```\n",
"```{index} single: solver; couenne, ipopt\n",
"```{index} single: solver; ipopt\n",
"```\n",
"# Milk pooling and blending\n",
"\n",
Expand All @@ -26,6 +26,19 @@
"This notebook considers a simple example of a wholesale milk distributor to show how **non-convexity** arises in the optimization of pooling and blending operations. Non-convexity is due to presence of **bilinear** terms that are the product of two decision variables where one is a scale-dependent **extensive** quantity measuring the amount or flow of a product, and the other is scale-independent **intensive** quantity such as product composition. The notebook then shows how to develop and solve a convex approximation of the problem, and finally demonstrates solution the use of `ipotp`, a solver specifically designed to find global solutions to nonlinear optimization (NLO) problems."
]
},
{
"cell_type": "markdown",
"id": "ab42f8ca",
"metadata": {},
"source": [
"## Preamble: Install Pyomo and a solver\n",
"\n",
"This cell selects and verifies a global SOLVER for the notebook.\n",
"\n",
"If run on Google Colab, the cell installs Pyomo and ipopt, then sets SOLVER to use the ipopt solver. If run elsewhere, it assumes Pyomo and the Mosek solver\n",
"have been previously installed and sets SOLVER to use the Mosek solver via the Pyomo SolverFactory. It then verifies that SOLVER is available."
]
},
{
"cell_type": "code",
"execution_count": 1,
Expand All @@ -37,6 +50,8 @@
"source": [
"import sys, os\n",
"\n",
"solver_LO = \"appsi_highs\"\n",
"\n",
"if 'google.colab' in sys.modules:\n",
" !pip install idaes-pse --pre >/dev/null 2>/dev/null\n",
" !pip install highspy >/dev/null 2>/dev/null\n",
Expand All @@ -48,7 +63,6 @@
"\n",
"import pyomo.environ as pyo \n",
"\n",
"solver_LO = \"appsi_highs\"\n",
"SOLVER_LO = pyo.SolverFactory(solver_LO)\n",
"SOLVER_NLO = pyo.SolverFactory(solver_NLO)\n",
"\n",
Expand All @@ -67,8 +81,7 @@
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import pyomo.environ as pyo"
"import matplotlib.pyplot as plt"
]
},
{
Expand Down
109 changes: 58 additions & 51 deletions _sources/notebooks/05/refinery-production.ipynb

Large diffs are not rendered by default.

38 changes: 21 additions & 17 deletions _sources/notebooks/06/building-insulation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"```\n",
"```{index} single: conic optimization; second order cones\n",
"```\n",
"```{index} single: solver; Mosek\n",
"```{index} single: solver; mosek\n",
"```\n",
"```{index} single: application; building insulation\n",
"```\n",
Expand All @@ -26,6 +26,18 @@
"Thermal insulation is installed in buildings to reduce annual energy costs. However, the installation costs money, so the decision of how much insulation to install is a trade-off between the annualized capital costs of insulation and the annual operating costs for heating and air conditioning. This notebook shows the formulation and solution of an optimization problem using conic optimization."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Preamble: Install Pyomo and a solver\n",
"\n",
"This cell selects and verifies a global SOLVER for the notebook.\n",
"\n",
"If run on Google Colab, the cell installs Pyomo and ipopt, then sets SOLVER to use the ipopt solver. If run elsewhere, it assumes Pyomo and the Mosek solver\n",
"have been previously installed and sets SOLVER to use the Mosek solver via the Pyomo SolverFactory. It then verifies that SOLVER is available."
]
},
{
"cell_type": "code",
"execution_count": 1,
Expand All @@ -34,22 +46,21 @@
},
"outputs": [],
"source": [
"import sys\n",
"import sys, os\n",
"\n",
"if 'google.colab' in sys.modules:\n",
" !pip install idaes-pse --pre >/dev/null 2>/dev/null\n",
" !idaes get-extensions --to ./bin \n",
" os.environ['PATH'] += ':bin'\n",
" \n",
" solver = \"ipopt\"\n",
" import pyomo.kernel as pmo\n",
" import pyomo.environ as pyo\n",
" SOLVER = pyo.SolverFactory(solver)\n",
"\n",
"else:\n",
" solver = \"mosek_direct\"\n",
" import pyomo.kernel as pmo\n",
" SOLVER = pmo.SolverFactory(solver)"
"\n",
"import pyomo.kernel as pmo\n",
"import pyomo.environ as pyo \n",
"SOLVER = pmo.SolverFactory(solver)\n",
"\n",
"assert SOLVER.available(), f\"Solver {solver} is not available.\""
]
},
{
Expand Down Expand Up @@ -157,6 +168,7 @@
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pandas as pd\n",
"\n",
"f = lambda x: alpha / (R0 + x / k)\n",
"g = lambda x: beta * (a + b * x)\n",
Expand Down Expand Up @@ -345,9 +357,6 @@
},
"outputs": [],
"source": [
"import pyomo.kernel as pmo\n",
"\n",
"\n",
"def insulate(df, alpha, beta, R0, T):\n",
" m = pmo.block()\n",
"\n",
Expand Down Expand Up @@ -480,8 +489,6 @@
}
],
"source": [
"import pandas as pd\n",
"\n",
"# application parameters\n",
"alpha = 30 # $ K / W annualized cost per sq meter per W/sq m/K\n",
"beta = 0.05 # equivalent annual cost factor\n",
Expand Down Expand Up @@ -619,9 +626,6 @@
}
],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"k = list(df[\"k\"])\n",
"a = list(df[\"a\"])\n",
"b = list(df[\"b\"])\n",
Expand Down
14 changes: 7 additions & 7 deletions _sources/notebooks/06/economic-order-quantity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"import sys, os\n",
"\n",
"if 'google.colab' in sys.modules:\n",
" !pip install idaes-pse --pre >/dev/null 2>/dev/null\n",
" !idaes get-extensions --to ./bin \n",
" os.environ['PATH'] += ':bin'\n",
" \n",
" solver = \"ipopt\"\n",
" import pyomo.environ as pyo \n",
" SOLVER = pyo.SolverFactory(solver)\n",
"\n",
"else:\n",
" solver = \"mosek_direct\"\n",
" import pyomo.kernel as pmo\n",
" SOLVER = pmo.SolverFactory(solver)"
"\n",
"import pyomo.kernel as pmo\n",
"import pyomo.environ as pyo \n",
"SOLVER = pmo.SolverFactory(solver)\n",
"\n",
"assert SOLVER.available(), f\"Solver {solver} is not available.\""
]
},
{
Expand Down
244 changes: 138 additions & 106 deletions _sources/notebooks/06/investment-wheel.ipynb

Large diffs are not rendered by default.

27 changes: 10 additions & 17 deletions _sources/notebooks/06/kelly-criterion.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"```\n",
"```{index} single: conic optimization; exponential cones\n",
"```\n",
"```{index} single: solver; Mosek\n",
"```{index} single: solver; mosek\n",
"```\n",
"```{index} single: application; portfolio\n",
"```\n",
Expand All @@ -37,22 +37,21 @@
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"import sys, os\n",
"\n",
"if 'google.colab' in sys.modules:\n",
" !pip install idaes-pse --pre >/dev/null 2>/dev/null\n",
" !idaes get-extensions --to ./bin \n",
" os.environ['PATH'] += ':bin'\n",
" \n",
" solver = \"ipopt\"\n",
" import pyomo.kernel as pmo\n",
" import pyomo.environ as pyo \n",
" SOLVER = pyo.SolverFactory(solver)\n",
"\n",
"else:\n",
" solver = \"mosek_direct\"\n",
" import pyomo.kernel as pmo\n",
" SOLVER = pmo.SolverFactory(solver)"
"\n",
"import pyomo.kernel as pmo\n",
"import pyomo.environ as pyo \n",
"SOLVER = pmo.SolverFactory(solver)\n",
"\n",
"assert SOLVER.available(), f\"Solver {solver} is not available.\""
]
},
{
Expand Down Expand Up @@ -190,7 +189,8 @@
}
],
"source": [
"import pyomo.kernel as pmo\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"# parameter values\n",
"b = 1.25\n",
Expand Down Expand Up @@ -297,9 +297,6 @@
}
],
"source": [
"import pyomo.kernel as pmo\n",
"import numpy as np\n",
"\n",
"# parameter values\n",
"b = 1.25\n",
"p = 0.51\n",
Expand Down Expand Up @@ -369,10 +366,6 @@
}
],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"\n",
"def kelly_sim(p, b, lambd=0, K=None, ax=None):\n",
" w = kelly_rc(p, b, lambd)\n",
" m = p * np.log((1 + b * w)) + (1 - p) * np.log((1 - w))\n",
Expand Down
12 changes: 6 additions & 6 deletions _sources/notebooks/06/markowitz_portfolio_revisited.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"outputs": [],
"source": [
"import sys\n",
"import sys, os\n",
"\n",
"if 'google.colab' in sys.modules:\n",
" !pip install idaes-pse --pre >/dev/null 2>/dev/null\n",
Expand All @@ -49,11 +49,11 @@
"else:\n",
" solver = \"mosek_direct\"\n",
"\n",
"import pyomo.environ as pyo\n",
"if not pyo.SolverFactory(solver).available():\n",
" print(f\"Solver {solver} is not available\")\n",
"else:\n",
" SOLVER = pyo.SolverFactory(solver)"
"import pyomo.kernel as pmo\n",
"import pyomo.environ as pyo \n",
"SOLVER = pmo.SolverFactory(solver)\n",
"\n",
"assert SOLVER.available(), f\"Solver {solver} is not available.\""
]
},
{
Expand Down
15 changes: 6 additions & 9 deletions _sources/notebooks/06/optimal-growth-portfolios.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,21 @@
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"import sys, os\n",
"\n",
"if 'google.colab' in sys.modules:\n",
" !pip install idaes-pse --pre >/dev/null 2>/dev/null\n",
" !idaes get-extensions --to ./bin \n",
" os.environ['PATH'] += ':bin'\n",
" \n",
" solver = \"ipopt\"\n",
" import pyomo.environ as pyo \n",
" SOLVER = pyo.SolverFactory(solver)\n",
"\n",
"else:\n",
" solver = \"mosek_direct\"\n",
" import pyomo.kernel as pmo\n",
" SOLVER = pmo.SolverFactory(solver)\n",
"\n",
"if not SOLVER.available():\n",
" print(f\"Solver {solver} is not available\")"
"import pyomo.kernel as pmo\n",
"import pyomo.environ as pyo \n",
"SOLVER = pmo.SolverFactory(solver)\n",
"\n",
"assert SOLVER.available(), f\"Solver {solver} is not available.\""
]
},
{
Expand Down
22 changes: 6 additions & 16 deletions _sources/notebooks/06/svm-conic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,21 @@
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"import sys, os\n",
"\n",
"if 'google.colab' in sys.modules:\n",
" !pip install idaes-pse --pre >/dev/null 2>/dev/null\n",
" !idaes get-extensions --to ./bin \n",
" os.environ['PATH'] += ':bin'\n",
" \n",
" solver = \"ipopt\"\n",
" import pyomo.environ as pyo \n",
" SOLVER = pyo.SolverFactory(solver)\n",
"\n",
"else:\n",
" solver = \"mosek_direct\"\n",
" import pyomo.kernel as pmo\n",
" SOLVER = pmo.SolverFactory(solver)\n",
"\n",
"if not SOLVER.available():\n",
" print(f\"Solver {solver} is not available\")"
"import pyomo.kernel as pmo\n",
"import pyomo.environ as pyo \n",
"SOLVER = pmo.SolverFactory(solver)\n",
"\n",
"assert SOLVER.available(), f\"Solver {solver} is not available.\""
]
},
{
Expand Down Expand Up @@ -763,9 +760,6 @@
}
],
"source": [
"import pyomo.kernel as pmo\n",
"\n",
"\n",
"def conicDualSVMFactory(X, y, c=1):\n",
" n, p = X.shape\n",
" F = np.array(\n",
Expand Down Expand Up @@ -1029,10 +1023,6 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pyomo.kernel as pmo\n",
"\n",
"\n",
"def kernelSVMFactory(X, y, c, tol=1e-8, kernel=lambda x, z: (x @ z)):\n",
" n, p = X.shape\n",
"\n",
Expand Down
Loading

0 comments on commit c653488

Please sign in to comment.