From b5034fe44996b5b61b4e1aa0358486ce3c6fb33a Mon Sep 17 00:00:00 2001 From: Alessandro Zocca Date: Mon, 20 Nov 2023 22:37:32 +0100 Subject: [PATCH] Add notebook numbering --- _toc.yml | 24 +++++++++---------- ...ing.ipynb => 01-production-planning.ipynb} | 2 +- notebooks/01/01.00.md | 6 ++--- ...ynb => 02-production-planning-basic.ipynb} | 2 +- ... => 03-production-planning-advanced.ipynb} | 2 +- notebooks/02/{bim.ipynb => 01-bim.ipynb} | 2 +- ...gression.ipynb => 02-lad-regression.ipynb} | 2 +- notebooks/02/02.00.md | 18 +++++++------- ...nb => 03-mad-portfolio-optimization.ipynb} | 2 +- .../02/{bim-dual.ipynb => 04-bim-dual.ipynb} | 4 ++-- .../{bim-maxmin.ipynb => 05-bim-maxmin.ipynb} | 4 ++-- ...actional.ipynb => 06-bim-fractional.ipynb} | 7 ++---- ...ipynb => 07-bim-rawmaterialplanning.ipynb} | 5 ++-- ...nb => 08-L1-regression-wine-quality.ipynb} | 0 ...-multiproductionfaciliity_worstcase.ipynb} | 0 notebooks/03/bim-perturbed.ipynb | 6 ++--- notebooks/03/bim-production-revisited.ipynb | 2 +- .../03/recharging-electric-vehicle.ipynb | 2 +- notebooks/03/shift-scheduling.ipynb | 2 +- 19 files changed, 44 insertions(+), 48 deletions(-) rename notebooks/01/{production-planning.ipynb => 01-production-planning.ipynb} (99%) rename notebooks/01/{production-planning-basic.ipynb => 02-production-planning-basic.ipynb} (99%) rename notebooks/01/{production-planning-advanced.ipynb => 03-production-planning-advanced.ipynb} (99%) rename notebooks/02/{bim.ipynb => 01-bim.ipynb} (99%) rename notebooks/02/{lad-regression.ipynb => 02-lad-regression.ipynb} (99%) rename notebooks/02/{mad-portfolio-optimization.ipynb => 03-mad-portfolio-optimization.ipynb} (99%) rename notebooks/02/{bim-dual.ipynb => 04-bim-dual.ipynb} (97%) rename notebooks/02/{bim-maxmin.ipynb => 05-bim-maxmin.ipynb} (90%) rename notebooks/02/{bim-fractional.ipynb => 06-bim-fractional.ipynb} (98%) rename notebooks/02/{bim-rawmaterialplanning.ipynb => 07-bim-rawmaterialplanning.ipynb} (99%) rename notebooks/02/{L1-regression-wine-quality.ipynb => 08-L1-regression-wine-quality.ipynb} (100%) rename notebooks/02/{multiproductionfaciliity_worstcase.ipynb => 09-multiproductionfaciliity_worstcase.ipynb} (100%) diff --git a/_toc.yml b/_toc.yml index ac3c6c58..d60d5313 100644 --- a/_toc.yml +++ b/_toc.yml @@ -5,21 +5,21 @@ root: intro.md chapters: - file: notebooks/01/01.00.md sections: - - file: notebooks/01/production-planning.ipynb - - file: notebooks/01/production-planning-basic.ipynb - - file: notebooks/01/production-planning-advanced.ipynb + - file: notebooks/01/01-production-planning.ipynb + - file: notebooks/01/02_production-planning-basic.ipynb + - file: notebooks/01/03-production-planning-advanced.ipynb - file: notebooks/02/02.00.md sections: - - file: notebooks/02/bim.ipynb - - file: notebooks/02/lad-regression.ipynb - - file: notebooks/02/mad-portfolio-optimization.ipynb - - file: notebooks/02/bim-dual.ipynb - - file: notebooks/02/bim-maxmin.ipynb - - file: notebooks/02/bim-fractional.ipynb - - file: notebooks/02/bim-rawmaterialplanning - - file: notebooks/02/L1-regression-wine-quality.ipynb - - file: notebooks/02/multiproductionfaciliity_worstcase.ipynb + - file: notebooks/02/01-bim.ipynb + - file: notebooks/02/02-lad-regression.ipynb + - file: notebooks/02/03-mad-portfolio-optimization.ipynb + - file: notebooks/02/04-bim-dual.ipynb + - file: notebooks/02/05-bim-maxmin.ipynb + - file: notebooks/02/06-bim-fractional.ipynb + - file: notebooks/02/07-bim-rawmaterialplanning + - file: notebooks/02/08-L1-regression-wine-quality.ipynb + - file: notebooks/02/09-multiproductionfaciliity_worstcase.ipynb - file: notebooks/03/03.00.md sections: diff --git a/notebooks/01/production-planning.ipynb b/notebooks/01/01-production-planning.ipynb similarity index 99% rename from notebooks/01/production-planning.ipynb rename to notebooks/01/01-production-planning.ipynb index 86ba2416..999e24d4 100644 --- a/notebooks/01/production-planning.ipynb +++ b/notebooks/01/01-production-planning.ipynb @@ -22,7 +22,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# A first production planning problem" + "# 1.1 A first production planning problem" ] }, { diff --git a/notebooks/01/01.00.md b/notebooks/01/01.00.md index c98f3ffa..9d4c6141 100644 --- a/notebooks/01/01.00.md +++ b/notebooks/01/01.00.md @@ -32,8 +32,8 @@ and similarly for a maximization problem. Different types of function $f$ and se In this introductory chapter, we present a simple example of optimization in the context of production planning. -- We first explain the structure and formalism of the corresponding optimization problem in a [first notebook](production-planning.ipynb) -- We then implement and solve the optimization in Pyomo in a [second notebook](production-planning-basic.ipynb), which also serves as a Pyomo tutorial. -- Lastly, we discuss some advance Pyomo features in a [third notebook](production-planning-advanced.ipynb). +- We first explain the structure and formalism of the corresponding optimization problem in a [first notebook](01-production-planning.ipynb) +- We then implement and solve the optimization in Pyomo in a [second notebook](02-production-planning-basic.ipynb), which also serves as a Pyomo tutorial. +- Lastly, we discuss some advance Pyomo features in a [third notebook](03-production-planning-advanced.ipynb). Go to the [next chapter](../02/02.00.md) about linear optimization. \ No newline at end of file diff --git a/notebooks/01/production-planning-basic.ipynb b/notebooks/01/02-production-planning-basic.ipynb similarity index 99% rename from notebooks/01/production-planning-basic.ipynb rename to notebooks/01/02-production-planning-basic.ipynb index 6c19bcd3..40169671 100644 --- a/notebooks/01/production-planning-basic.ipynb +++ b/notebooks/01/02-production-planning-basic.ipynb @@ -19,7 +19,7 @@ "```{index} single: solver; HiGHS\n", "```\n", "\n", - "# A basic Pyomo model\n", + "# 1.2 A basic Pyomo model\n", "\n", "Pyomo is an algebraic modeling language for mathematical optimization that is integrated within the Python programming environment. It enables users to create optimization models consisting of decision variables, expressions, objective functions, and constraints. Pyomo provides tools to transform models, and then solve them using a variety of open-source and commercial solvers. As an open-source project, Pyomo is not tied to any specific vendor, solver, or class of mathematical optimization problems, and is constantly evolving through contributions from third-party developers.\n", "\n", diff --git a/notebooks/01/production-planning-advanced.ipynb b/notebooks/01/03-production-planning-advanced.ipynb similarity index 99% rename from notebooks/01/production-planning-advanced.ipynb rename to notebooks/01/03-production-planning-advanced.ipynb index 6a9560ad..7a4fc3b5 100644 --- a/notebooks/01/production-planning-advanced.ipynb +++ b/notebooks/01/03-production-planning-advanced.ipynb @@ -18,7 +18,7 @@ "```{index} single: solver; cbc\n", "```\n", "\n", - "# A data-driven Pyomo Model\n", + "# 1.3 A data-driven Pyomo Model\n", "\n", "In this notebook, we'll revisit the production planning example. However, this time we'll demonstrate how Python's data structures, combined with Pyomo's capabilities, can create an optimization model scales with problem data. This enables the model to adjust to new products, varying prices, or changing demand. We refer to this as \"data-driven\" modeling.\n", "\n", diff --git a/notebooks/02/bim.ipynb b/notebooks/02/01-bim.ipynb similarity index 99% rename from notebooks/02/bim.ipynb rename to notebooks/02/01-bim.ipynb index b61c85eb..84645fc8 100644 --- a/notebooks/02/bim.ipynb +++ b/notebooks/02/01-bim.ipynb @@ -16,7 +16,7 @@ "```{index} single: application; production planning\n", "```\n", "\n", - "# BIM production" + "# 2.1 BIM production" ] }, { diff --git a/notebooks/02/lad-regression.ipynb b/notebooks/02/02-lad-regression.ipynb similarity index 99% rename from notebooks/02/lad-regression.ipynb rename to notebooks/02/02-lad-regression.ipynb index d4bc315b..574de6c9 100644 --- a/notebooks/02/lad-regression.ipynb +++ b/notebooks/02/02-lad-regression.ipynb @@ -10,7 +10,7 @@ "```{index} single: application; regression\n", "```\n", "\n", - "# Least Absolute Deviation (LAD) Regression\n", + "# 2.2 Least Absolute Deviation (LAD) Regression\n", "\n", "Linear regression is a supervised machine learning technique that dates back to at least the 19th century. It remains a cornerstone of modern data analysis, generating a linear model that predicts the values of a dependent variable based on one or more independent variables. This notebook introduces an alternative approach to traditional linear regression, employing linear optimization to optimize based on the Least Absolute Deviation (LAD) metric. \n", "\n", diff --git a/notebooks/02/02.00.md b/notebooks/02/02.00.md index d8a5105e..a17311d5 100644 --- a/notebooks/02/02.00.md +++ b/notebooks/02/02.00.md @@ -18,14 +18,14 @@ Linear problems can (i) be maximization problems, (ii) involve equality constrai This chapter includes several with companion Pyomo implementation that explore various modeling and implementation aspects of LOs: -* A first LO example, modelling [the microchip production problem of company BIM](bim.ipynb) -* [Least Absolute Deviation (LAD) Regression](lad-regression.ipynb) -* [Mean Absolute Deviation (MAD) portfolio optimization](mad-portfolio-optimization.ipynb) -* [The dual problem of the microchip production problem](bim-dual.ipynb) -* [A variant of BIM problem: maximizing the lowest possible profit](bim-maxmin.ipynb) -* [Two variants of the BIM problem using fractional objective or additional fixed costs](bim-fractional.ipynb) -* [The BIM production problem using demand forecasts](bim-rawmaterialplanning) -* [Extra material: Wine quality prediction problem using $L_1$ regression](L1-regression-wine-quality.ipynb) -* [Extra material: Multi-product facility production](multiproductionfaciliity_worstcase.ipynb) +* A first LO example, modelling [the microchip production problem of company BIM](01-bim.ipynb) +* [Least Absolute Deviation (LAD) Regression](02-lad-regression.ipynb) +* [Mean Absolute Deviation (MAD) portfolio optimization](03-mad-portfolio-optimization.ipynb) +* [The dual problem of the microchip production problem](04-bim-dual.ipynb) +* [A variant of BIM problem: maximizing the lowest possible profit](05-bim-maxmin.ipynb) +* [Two variants of the BIM problem using fractional objective or additional fixed costs](06-bim-fractional.ipynb) +* [The BIM production problem using demand forecasts](07-bim-rawmaterialplanning) +* [Extra material: Wine quality prediction problem using $L_1$ regression](08-L1-regression-wine-quality.ipynb) +* [Extra material: Multi-product facility production](09-multiproductionfaciliity_worstcase.ipynb) Go to the [next chapter](../03/03.00.md) about mixed-integer linear optimization. \ No newline at end of file diff --git a/notebooks/02/mad-portfolio-optimization.ipynb b/notebooks/02/03-mad-portfolio-optimization.ipynb similarity index 99% rename from notebooks/02/mad-portfolio-optimization.ipynb rename to notebooks/02/03-mad-portfolio-optimization.ipynb index 27d9bf13..937e23f4 100644 --- a/notebooks/02/mad-portfolio-optimization.ipynb +++ b/notebooks/02/03-mad-portfolio-optimization.ipynb @@ -20,7 +20,7 @@ "```{index} web scraping\n", "```\n", "\n", - "# Mean Absolute Deviation (MAD) portfolio optimization\n", + "# 2.3 Mean Absolute Deviation (MAD) portfolio optimization\n", "\n", "Portfolio optimization and modern portfolio theory has a long and important history in finance and investment. The principal idea is to find a blend of investments in financial securities that achieves an optimal trade-off between financial risk and return. The introduction of modern portfolio theory is generally attributed to the 1952 doctoral thesis of [Harry Markowitz](https://en.wikipedia.org/wiki/Harry_Markowitz) who subsequently was award a share of the 1990 Nobel Memorial Prize in Economics for his fundamental contributions to this field. The well-known \"Markowitz Model\" models measure risk using covariance of the portfolio with respect to constituent assets, then solves a minimum variance problem by quadratic optimization problem subject to constraints to allocate of wealth among assets.\n", "\n", diff --git a/notebooks/02/bim-dual.ipynb b/notebooks/02/04-bim-dual.ipynb similarity index 97% rename from notebooks/02/bim-dual.ipynb rename to notebooks/02/04-bim-dual.ipynb index 119d358f..11ca6d13 100644 --- a/notebooks/02/bim-dual.ipynb +++ b/notebooks/02/04-bim-dual.ipynb @@ -14,7 +14,7 @@ "```{index} single: application; production planning\n", "```\n", "\n", - "# Dual of the BIM production problem" + "# 2.4 Dual of the BIM production problem" ] }, { @@ -61,7 +61,7 @@ "source": [ "## Derivation of the dual problem\n", "\n", - "In a [previous notebook](bim.ipynb), we introduce the BIM production problem and showed that it can be modeled as the following LO problem:\n", + "In a [previous notebook](01-bim.ipynb), we introduce the BIM production problem and showed that it can be modeled as the following LO problem:\n", "\n", "$$\n", "\\begin{align*}\n", diff --git a/notebooks/02/bim-maxmin.ipynb b/notebooks/02/05-bim-maxmin.ipynb similarity index 90% rename from notebooks/02/bim-maxmin.ipynb rename to notebooks/02/05-bim-maxmin.ipynb index d7244a85..2cd8e6ec 100644 --- a/notebooks/02/bim-maxmin.ipynb +++ b/notebooks/02/05-bim-maxmin.ipynb @@ -9,7 +9,7 @@ "```{index} single: solver; highs\n", "```\n", "\n", - "# BIM production for worst case" + "# 2.5 BIM production for worst case" ] }, { @@ -79,7 +79,7 @@ "source": [ "## BIM problem variant: Maximizing the lowest possible profit\n", "\n", - "In the same way we can minimize a maximum like above, we can also maximize the minimum. Let us consider the [BIM microchip production problem](bim.ipynb), but suppose that there is uncertainty regarding the selling prices of the microchips. Instead of just the nominal prices 12$ and 9$, BIM estimates that prices may more generally take values $P=\\{ (12,9), (11,10), (8, 11) \\}$. The optimization problem for a production plan that achieves the maximum among the lowest possible profits can be formulated using the trick mentioned above and can be implemented in Pyomo as follows." + "In the same way we can minimize a maximum like above, we can also maximize the minimum. Let us consider the [BIM microchip production problem](01-bim.ipynb), but suppose that there is uncertainty regarding the selling prices of the microchips. Instead of just the nominal prices 12$ and 9$, BIM estimates that prices may more generally take values $P=\\{ (12,9), (11,10), (8, 11) \\}$. The optimization problem for a production plan that achieves the maximum among the lowest possible profits can be formulated using the trick mentioned above and can be implemented in Pyomo as follows." ] }, { diff --git a/notebooks/02/bim-fractional.ipynb b/notebooks/02/06-bim-fractional.ipynb similarity index 98% rename from notebooks/02/bim-fractional.ipynb rename to notebooks/02/06-bim-fractional.ipynb index c7dcfb8a..61d09ce6 100644 --- a/notebooks/02/bim-fractional.ipynb +++ b/notebooks/02/06-bim-fractional.ipynb @@ -9,7 +9,7 @@ "```{index} single: solver; highs\n", "```\n", "\n", - "# BIM production variants" + "# 2.6 BIM production variants" ] }, { @@ -53,7 +53,7 @@ "source": [ "## Two variants of the BIM problem: fractional objective and additional fixed costs\n", "\n", - "Recall the BIM production model introduced earlier [here](bim.ipynb), that is\n", + "Recall the BIM production model introduced earlier [here](01-bim.ipynb), that is\n", "\n", "$$\n", "\\begin{align*}\n", @@ -97,9 +97,6 @@ } ], "source": [ - "import pyomo.environ as pyo\n", - "\n", - "\n", "def BIM_with_revenues_minus_costs():\n", " m = pyo.ConcreteModel(\"BIM with revenues minus costs\")\n", "\n", diff --git a/notebooks/02/bim-rawmaterialplanning.ipynb b/notebooks/02/07-bim-rawmaterialplanning.ipynb similarity index 99% rename from notebooks/02/bim-rawmaterialplanning.ipynb rename to notebooks/02/07-bim-rawmaterialplanning.ipynb index 0d554e34..2eadb8c6 100644 --- a/notebooks/02/bim-rawmaterialplanning.ipynb +++ b/notebooks/02/07-bim-rawmaterialplanning.ipynb @@ -22,7 +22,7 @@ "```{index} pandas dataframe\n", "```\n", "\n", - "# BIM production using demand forecasts" + "# 2.7 BIM production using demand forecasts" ] }, { @@ -66,7 +66,7 @@ "source": [ "## The problem: Optimal material acquisition and production planning using demand forecasts\n", "\n", - "This example is a continuation of the BIM chip production problem illustrated [here](bim.ipynb). Recall hat BIM produces logic and memory chips using copper, silicon, germanium, and plastic and that each chip requires the following quantities of raw materials:\n", + "This example is a continuation of the BIM chip production problem illustrated [here](01-bim.ipynb). Recall hat BIM produces logic and memory chips using copper, silicon, germanium, and plastic and that each chip requires the following quantities of raw materials:\n", "\n", "
\n", "\n", @@ -372,7 +372,6 @@ ], "source": [ "import pandas as pd\n", - "import pyomo.environ as pyo\n", "from io import StringIO\n", "from IPython.display import display\n", "\n", diff --git a/notebooks/02/L1-regression-wine-quality.ipynb b/notebooks/02/08-L1-regression-wine-quality.ipynb similarity index 100% rename from notebooks/02/L1-regression-wine-quality.ipynb rename to notebooks/02/08-L1-regression-wine-quality.ipynb diff --git a/notebooks/02/multiproductionfaciliity_worstcase.ipynb b/notebooks/02/09-multiproductionfaciliity_worstcase.ipynb similarity index 100% rename from notebooks/02/multiproductionfaciliity_worstcase.ipynb rename to notebooks/02/09-multiproductionfaciliity_worstcase.ipynb diff --git a/notebooks/03/bim-perturbed.ipynb b/notebooks/03/bim-perturbed.ipynb index a0a4dd87..0375a43f 100644 --- a/notebooks/03/bim-perturbed.ipynb +++ b/notebooks/03/bim-perturbed.ipynb @@ -10,7 +10,7 @@ "```{index} single: application; production planning\n", "```\n", "\n", - "# BIM production with perturbed data" + "# 3.1 BIM production with perturbed data" ] }, { @@ -25,7 +25,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "b97ff6f2-b423-4f2c-9626-4f77a71bbc7f", "metadata": { "colab": { @@ -57,7 +57,7 @@ "source": [ "## Problem description\n", "\n", - "The company BIM realizes that a $1\\%$ fraction of the copper always gets wasted while producing both types of microchips, more specifically $1\\%$ of the required amount. This means that it actually takes $4.04$ gr of copper to produce a logic chip and $2.02$ gr of copper to produce a memory chip. If we rewrite the linear problem of [the basic BIM problem](../02/bim.ipynb) and modify accordingly the coefficients in the corresponding constraints, we obtain the following problem \n", + "The company BIM realizes that a $1\\%$ fraction of the copper always gets wasted while producing both types of microchips, more specifically $1\\%$ of the required amount. This means that it actually takes $4.04$ gr of copper to produce a logic chip and $2.02$ gr of copper to produce a memory chip. If we rewrite the linear problem of [the basic BIM problem](../02/01-bim.ipynb) and modify accordingly the coefficients in the corresponding constraints, we obtain the following problem \n", "\n", "$$\n", "\\begin{align*}\n", diff --git a/notebooks/03/bim-production-revisited.ipynb b/notebooks/03/bim-production-revisited.ipynb index 821c6171..19463b95 100644 --- a/notebooks/03/bim-production-revisited.ipynb +++ b/notebooks/03/bim-production-revisited.ipynb @@ -62,7 +62,7 @@ "source": [ "## Problem description\n", "\n", - "We consider again the [BIM raw material planning problem](../02/bim-rawmaterialplanning.ipynb) from Chapter 2 but with more sophisticated pricing and acquisition protocols. There are now three suppliers, each of which can deliver the following materials:\n", + "We consider again the [BIM raw material planning problem](../02/01-bim-rawmaterialplanning.ipynb) from Chapter 2 but with more sophisticated pricing and acquisition protocols. There are now three suppliers, each of which can deliver the following materials:\n", " - A: **silicon**, **germanium** and **plastic**\n", " - B: **copper**\n", " - C: all the above\n", diff --git a/notebooks/03/recharging-electric-vehicle.ipynb b/notebooks/03/recharging-electric-vehicle.ipynb index 9c2a8d77..e14de31b 100644 --- a/notebooks/03/recharging-electric-vehicle.ipynb +++ b/notebooks/03/recharging-electric-vehicle.ipynb @@ -15,7 +15,7 @@ "```\n", "```{index} pandas dataframe\n", "```\n", - "# Recharging strategy for an electric vehicle\n", + "# 3.3 Recharging strategy for an electric vehicle\n", "\n", "Whether it is to visit family, take a sightseeing tour or call on business associates, planning a road trip is a familiar and routine task. Here we consider a road trip on a pre-determined route for which need to plan rest and recharging stops. This example demonstrates use of Pyomo disjunctions to model the decisions on where to stop. " ] diff --git a/notebooks/03/shift-scheduling.ipynb b/notebooks/03/shift-scheduling.ipynb index 1ff4a436..deb5616f 100644 --- a/notebooks/03/shift-scheduling.ipynb +++ b/notebooks/03/shift-scheduling.ipynb @@ -16,7 +16,7 @@ "```\n", "```{index} Gantt charts\n", "```\n", - "# Workforce shift scheduling" + "# 3.2 Workforce shift scheduling" ] }, {