Skip to content

Commit

Permalink
update workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
yurchisin committed Nov 13, 2024
1 parent 3403a23 commit 783f8e2
Show file tree
Hide file tree
Showing 6 changed files with 666 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"Before we begin, I wanted to make a quick note about a line of code you'll see repeated throughout the notebook: %%script false --no-raise-error\n",
"\n",
"\n",
"- **NOTE:** This is just cell magic (if you're unfamiliar, think of it as using the cmd line) telling the notebook not to run this cell. We'll use it in various places to demonstrate ideas or code snippets that are not meant to produce an output"
"- **NOTE:** This is just cell magic (if you're unfamiliar, think of it as using the cmd line) telling the notebook not to run this cell. We'll use it in various places to demonstrate ideas or code snippets that are not meant to produce an output."
]
},
{
Expand Down Expand Up @@ -215,7 +215,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"As you can see, the dataset fields are mainly data structures holding other object. Now we won't go into all these here, but it can be useful to see how they are set up. Let's take a look at one such object. "
"As you can see, the dataset fields are mainly data structures holding other objects. Now we won't go into all these here, but it can be useful to see how they are set up. Let's take a look at one such object. "
]
},
{
Expand Down Expand Up @@ -1306,7 +1306,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We can see that the warehouses are aligned closely with the most prominent disaster sights*, so assuming they are built to a level that can survive and protect against those disasters, Madagascar should be in a strong position in terms of coverage. However, there's more than meets the eye. Let's dive a little deeper!\n",
"We can see that the warehouses are aligned closely with the most prominent disaster sites*, so assuming they are built to a level that can survive and protect against those disasters, Madagascar should be in a strong position in terms of coverage. However, there's more than meets the eye. Let's dive a little deeper!\n",
"\n",
"Hopefully, now that you've gotten a sense of the country and the layout, we'll turn off some of the more detailed parts (such as roads and urbanization) so it's simpler to see what’s going on.\n",
"\n",
Expand Down Expand Up @@ -2423,7 +2423,7 @@
"source": [
"As we can see from above, the supplies skew heavily towards buckets, water containers, and mosquito nets, which makes sense for an island nation. But while it's great that we have a lot of buckets, it won't do us too much good if none of them are at the coast, for instance.\n",
"\n",
"- **NOTE:** From here out in the case study, we're going to focus on just buckets as they're the most prevalent item and, for the purposes of this case, it's time consuming and repetitive to analyze all 15 item types of supplies available. \n",
"- **NOTE:** From here on out in the case study, we're going to focus on just buckets as they're the most prevalent item and, for the purposes of this case, it's time consuming and repetitive to analyze all 15 item types of supplies available. \n",
"\n",
"As you'll see later in the notebook, it's a simple matter to apply the analysis of any one of the supply items to all 15 of them."
]
Expand Down Expand Up @@ -3407,7 +3407,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We can see that the supplies are largely located on the eastern coast line of the country"
"We can see that the supplies are largely located on the eastern coastline of the country."
]
},
{
Expand Down Expand Up @@ -5556,7 +5556,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"ESUPS's platform [Stockholm](https://www.esups-stockholm.org/#/private/signin), which is their platform for hosting this model (you can apply for access by visiting the homepage linked above), has two main pages, the first is the context page, and explains the context of the problem that we've been discussing in the past few sections, along with additional details about their mission and collaborating organizations. We'll look at this one first!"
"ESUPS' platform [Stockholm](https://www.esups-stockholm.org/#/private/signin), which is hosting this model (you can apply for access by visiting the homepage linked above), has two main pages, the first is the context page, and explains the context of the problem that we've been discussing in the past few sections, along with additional details about their mission and collaborating organizations. We'll look at this one first!"
]
},
{
Expand Down Expand Up @@ -5610,7 +5610,7 @@
"\n",
"The design, though basic, allowed for rapid deployment and iteration, proving that in the early stages of development, it's more important to have a working solution than to strive for perfection. The dashboard's ability to deliver key insights swiftly and effectively earned it significant merit, as it laid the groundwork for future improvements and set the stage for more advanced iterations. This approach underscores a vital lesson in development: sometimes, a good solution delivered quickly can be more valuable than a perfect one delivered too late.\n",
"\n",
"The initial success provided a strong foundation upon which ESUPS could build. The insights gained from this deployment informed the development of a new version, which addresses the limitations of the first while enhancing user experience and data communication. The new dashboard takes these lessons to heart, incorporating more advanced features and a more intuitive design, ensuring that ESUPS continues to meet the needs of its partners more effectively. Now, let’s explore how this new version improves upon the original and further advances ESUPS's mission."
"The initial success provided a strong foundation upon which ESUPS could build. The insights gained from this deployment informed the development of a new version, which addresses the limitations of the first while enhancing user experience and data communication. The new dashboard takes these lessons to heart, incorporating more advanced features and a more intuitive design, ensuring that ESUPS continues to meet the needs of its partners more effectively. Now, let’s explore how this new version improves upon the original and further advances ESUPS' mission."
]
},
{
Expand Down Expand Up @@ -5701,7 +5701,7 @@
"source": [
"<div class=\"alert alert-warning\">\n",
" <strong>Note!</strong>\n",
" <p>Decision variables in mathematical optimization problems are typically assumed to be nonnegative. So while you'll see these constraints in formulations (ei.e. the algebraic representations), you may not see the code for it since it's likely assumed to be nonnegative.</p>\n",
" <p>Decision variables in mathematical optimization problems are typically assumed to be nonnegative. So while you'll see these constraints in formulations (i.e. the algebraic representations), you may not see the code for it since it's likely assumed to be nonnegative.</p>\n",
"</div>"
]
},
Expand Down Expand Up @@ -5812,7 +5812,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Now Let's Analyze the results!"
"Now let's analyze the results!"
]
},
{
Expand Down Expand Up @@ -6009,7 +6009,7 @@
"\n",
"Now that we've got the initial problem outlined, let's start making it more realistic with two additions:\n",
"1.\tInstead of preparing for only one disaster, let's prepare for all the disasters that might occur.\n",
"2.\tInstead of being an omniscient observer, let's say we aren't sure where the next disaster will be"
"2.\tInstead of being an omniscient observer, let's say we aren't sure where the next disaster will be."
]
},
{
Expand All @@ -6023,19 +6023,19 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Before we begin, let's explicitly define our new problem with the additional requirements outlined in the previous section so we're all on the same page. Our first step is to add in the fact that there are more disasters than just one. We can do that by including a variable to denote which disaster we're talking about\n",
"Before we begin, let's explicitly define our new problem with the additional requirements outlined in the previous section so we're all on the same page. Our first step is to add in the fact that there are more disasters than just one. We can do that by including a variable to denote which disaster we're talking about.\n",
"\n",
"Let:\n",
"\n",
"- $k$ the disaster scenario at hand i.e. a storm, earthquake, or epidemic\n",
"- $k$ be the disaster scenario at hand i.e. a storm, earthquake, or epidemic\n",
"- $j$ be the location of the disaster"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In scenario $k$ with the disaster located at $j$, the time for a warehouse $i$ to send $y_i$ items is "
"In scenario $k$ with the disaster located at $j$, the time for a warehouse $i$ to send $y_i$ items is: "
]
},
{
Expand Down Expand Up @@ -6116,14 +6116,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"If you haven't seen expected value before or if it's just a been a while and you'd like a refresher, try some of the practice problems below!"
"If you haven't seen expected value before or if it's just been a while and you'd like a refresher, try some of the practice problems below!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"When we solve expected value for discrete outcomes, we take the value/outcome/payoff of each possible event and discount it by the probability that it actually occurs. So it follows the form\n",
"When we solve expected value for discrete outcomes, we take the value/outcome/payoff of each possible event and discount it by the probability that it actually occurs. So it follows the form:\n",
"\n",
"$$\n",
"E[X]=p_1(x_1)+p_2(x_2)+ ... + p_n(x_n)\n",
Expand Down Expand Up @@ -6515,7 +6515,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"How do we calculate the probability though? Well, we have good long-term data on what disasters have affected which countries. For now, we can go through that data and calculate the probability of disaster k by counting how many times it has occurred and dividing by the number of total disasters i.e.\n",
"How do we calculate the probability though? Well, we have good long-term data on what disasters have affected which countries. For now, we can go through that data and calculate the probability of disaster k by counting how many times it has occurred and dividing by the number of total disasters:\n",
"\n",
"$$ P^k = \\frac{k}{\\|K\\|}$$"
]
Expand Down Expand Up @@ -6804,11 +6804,11 @@
"y^k_i \\leq x_i,\\space \\forall i \\in I \\hspace{.2cm}\\text{(you can't send more than a warehouse has)}\\\\\n",
"$$\n",
"\n",
"So far, we've just been using the actual allocation we have at each warehouse for $x_i$. But what if those changes? Suddenly we would have an entirely new solution. So, if we say that the output of Gurobi (i.e. the allocations $y^k_i \\in Y$) is some function based on our starting amount warehouses ($X$ where $x_i\\in X$), then we can say\n",
"So far, we've just been using the actual allocation we have at each warehouse for $x_i$. But what if those change? Suddenly we would have an entirely new solution. So, if we say that the output of Gurobi (i.e. the allocations $y^k_i \\in Y$) is some function based on our starting amount of warehouses ($X$ where $x_i\\in X$), then we can say:\n",
"\n",
"$$Y=f(X)$$ \n",
"\n",
"And when we frame it this way, it becomes much more simple to solve! All we need to do is minimize the travel times $Y$. In other words, our problem becomes \n",
"And when we frame it this way, it becomes much more simple to solve! All we need to do is minimize the travel times $Y$. In other words, our problem becomes: \n",
"\n",
"\n",
"$$ \\min_{X} f(X) $$\n",
Expand All @@ -6827,15 +6827,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"While this may initially look intimidating, it is one of the easiest changes to make to our current code. All we are doing is making a decision variable instead of a constant and then constraining it. Let’s substitute back in our equation from the last section with the new constraints to see this firsthand. To denote a new decision variable (i.e. a variable that can be changed), all we need to do is add it under the minimization sign. This means minimizing with respect to $x$ and $y$\n",
"While this may initially look intimidating, it is one of the easiest changes to make to our current code. All we are doing is making a decision variable instead of a constant and then constraining it. Let’s substitute back in our equation from the last section the new constraints to see this firsthand. To denote a new decision variable (i.e. a variable that can be changed), all we need to do is add it under the minimization sign. This means minimizing with respect to $x$ and $y$:\n",
"\n",
"$$\n",
"\\min_{x,y} \\sum_k P^k \\sum_i \\tau_{ij}\\cdot y^k_i\n",
"$$\n",
"\n",
"Then all we need to do is update the constraints. I've included the line to make it easier to see what's new as our list grows. It has no mathematical significance. \n",
"\n",
"So how do we Implement this in Gurobi?\n",
"So how do we implement this in Gurobi?\n",
"\n",
"$$\n",
"\\begin{aligned}\n",
Expand Down Expand Up @@ -6980,9 +6980,9 @@
"\n",
"The second additional facet considered in our real-life model that we haven't encountered yet is transportation mode. We alluded to it a little in the cost section, but often there is the option to fly or ship goods into a region, which can be especially useful when far away or the roads are clogged or otherwise unusable (such is often the case after a disaster).\n",
"\n",
"So how do we implement this? Well let's take a look back at $y_i^k$, our variable which says how many goods to send from warehouse $i$ to disaster $k$. All we want to do is reflect and updated description: how many goods to send from warehouse $i$ to disaster $k$ via mode $r$. This can easily be represented as $y_{ir}^k$, let's explain what's happened. Before is $y$ was an array of length $K$ with each index holding sub array of length $I$ (which we could also write as size $K \\times I$), now each index in our subarrays also have an array of length $3$ to represent how much is sent via truck, plane, or boat. So our final array is of dimensions $K \\times I \\times R $. This may seem intimidating at first, but remember, adding a dimension just means adding one more nested for loop!\n",
"So how do we implement this? Well let's take a look back at $y_i^k$, our variable which says how many goods to send from warehouse $i$ to disaster $k$. All we want to do is reflect and update the description: how many goods to send from warehouse $i$ to disaster $k$ via mode $r$. This can easily be represented as $y_{ir}^k$, let's explain what's happened. Before this $y$ was an array of length $K$ with each index holding sub array of length $I$ (which we could also write as size $K \\times I$), now each index in our subarrays also have an array of length $3$ to represent how much is sent via truck, plane, or boat. So, our final array is of dimensions $K \\times I \\times R $. This may seem intimidating at first, but remember, adding a dimension just means adding one more nested for loop!\n",
"\n",
"Let's look at how we would implement this. Remember, from a math point of view, all we've done is say $y_i^k$ can be broken down into $3$ modes instead of 1. So, it's rewritten as"
"Let's look at how we would implement this. Remember, from a math point of view, all we've done is say $y_i^k$ can be broken down into $3$ modes instead of 1. So, it's rewritten as:"
]
},
{
Expand Down
5 changes: 5 additions & 0 deletions optimization202/ESUPS_case_study/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
gurobipy==11.0.3
ipython==8.26.0
ipywidgets==8.1.3
numpy<2
pandas==2.2.2
pandera==0.20.3
plotly==5.23.0
pydantic==2.8.2
scipy==1.14.1
tqdm==4.66.4
typing_extensions==4.12.2
networkx
Loading

0 comments on commit 783f8e2

Please sign in to comment.