diff --git a/Lecture Notes/W1 - Basic Inventory Models.md b/Lecture Notes/W1 - Basic Inventory Models.md index 12e804e..b91d62a 100644 --- a/Lecture Notes/W1 - Basic Inventory Models.md +++ b/Lecture Notes/W1 - Basic Inventory Models.md @@ -18,14 +18,14 @@ A coffee shop needs to decide how much coffee beans to purchase and how frequent #### Assumption -1. Everything is deterministic -2. Demand is constant (always the same amount of customers) -3. Only 1 product (1 type of coffee) -4. No backorders (coffee bean provider is always available) -5. Zero load time (supply instantly appears when ordered) -6. No discounts (coffee is always flat rate) +- Everything is deterministic +- Demand is constant (always the same amount of customers) +- Only 1 product (1 type of coffee) +- No backorders (coffee bean provider is always available) +- Zero load time (supply instantly appears when ordered) +- No discounts (coffee is always flat rate) -#### Input +### Variables $d$ : Total annual demand (in this case pounds of coffee needed per year) @@ -39,13 +39,10 @@ $c$ $h$ : Holding / Storage cost per item per year - -#### Decision Variables / Output - -$Q$ +$Q$ [!badge variant="success" text="Decision Variable"] : Quantity -#### Optimal Order Quantity $Q^*$ +### Optimal Order Quantity $Q^*$ Since orders are fulfilled instantly, we only order a batch of coffee beans when stock goes to 0. @@ -119,18 +116,9 @@ $$ ## The News Vendor Model -### Scenario. Selling Newspapers - A newspaper vendor needs to decide how many newspapers to buy from the news publisher. Newspapers expire in a day. Expired newspapers can be salvaged (returned to vendor) for a lower price. -#### Decision Variable - -$B$ -: The number of newspapers to buy from the supplier - ---- - -#### Input & Objective Function +### Variables $d$ : Discrete R.V., the uncertain demand of newspapers @@ -147,6 +135,9 @@ $c$ $s$ : Salvage price, sale price for expired newspapers. (e.g. recycling the paper) +$B$ [!badge variant="success" text="Decision Variable"] +: The number of newspapers to buy from the supplier + The 3 prices have the following inequality: @@ -292,7 +283,7 @@ s\uparrow\implies p-s\darr \implies\frac{p-c}{p-s}\uarr\implies B^*\uarr $$ ## Buying services -[!badge variant='warning' text="Key Example."] +[!badge variant='warning' text="Key Example"] ### Scenario. Signing a contract @@ -301,24 +292,28 @@ Suppose we want to sign a contract with a lighting company to purchase their mai - Contract too much: We get refunded for remaining services at a less price - Contract too little: We need to pay more for the extra services on the fly -#### Decision Variable - -|Variable| Definition| -| --- | --- | -| $B$ | The number of services to buy from the contracting company | +#### Variables -#### Input & Objective Function +$D$ +: A discrete random variable, the uncertain number of services we actually need +$c$ +: Price of each service on the contract -|Variable| Definition| -| --- | --- | -| $D$ | A discrete random variable, the uncertain number of services we actually need | +$s$ +: Refund price + +$p$ +: Price of extra services + +$q(d)$ +: PMF of $D$, same as $\Bbb P(D=d)$, in this case $d = 0,1,2,\dots$ + +$Q(d)$ +: CDF of $D$, same as $\Bbb P(D\leqslant d)$ -| $c$ | Price of each service on the contract | -| $s$ | Refund price | -| $p$ | Price of extra services | -| $q(d)$ | PMF of $D$, same as $\Bbb P(D=d)$, in this case $d = 0,1,2,\dots$ | -| $Q(d)$ | CDF of $D$, same as $\Bbb P(D\leqslant d)$ | +$B$ [!badge variant="success" text="Decision Variable"] +: The number of services to buy from the contracting company The objective is to minimize the expected total cost $\text {TC}$ by picking the optimal $B$. diff --git a/Lecture Notes/W2 - Linear Programming.md b/Lecture Notes/W2 - Linear Programming.md index c441e42..bec7489 100644 --- a/Lecture Notes/W2 - Linear Programming.md +++ b/Lecture Notes/W2 - Linear Programming.md @@ -6,7 +6,7 @@ icon: check-circle # W2 - Linear Programming -!!!secondary +!!!warning We will use $\bold x$ to indicate a vector, $x_i$ to indicate the element of $\bold x$. The $\leqslant, \geqslant$ comparators are element–wise comparison. $\bold 0$ is the zero vector. !!! @@ -112,7 +112,7 @@ $$ ||| -!!! **Def.** Standard Form +!!!info **Def.** Standard Form $$ \begin{aligned} diff --git a/Lecture Notes/W3 - Network Flow Pt 1.md b/Lecture Notes/W3 - Network Flow Pt 1.md index f367f84..5ed1fe3 100644 --- a/Lecture Notes/W3 - Network Flow Pt 1.md +++ b/Lecture Notes/W3 - Network Flow Pt 1.md @@ -9,15 +9,9 @@ icon: check-circle #### Scenario. Sending supplies to stores -Suppose you own a clothing business and owns both factories and stores. +Suppose you own a clothing business and owns both factories and stores. Let $\bigcirc$ be the factories (supply nodes) and $\triangle$ be the stores (demand node). The supply system looks like a directed graph: -Let $\bigcirc$ be the factories (supply nodes) and $\triangle$ be the stores (demand node). - -The supply system looks like a directed graph: - -![](/assets/Screenshot_2023-10-14_at_00.00.58.png){class="image-m"} - -The placements are arbitrary +![The placements are arbitrary](/assets/Screenshot_2023-10-14_at_00.00.58.png){class="image-m"} There’s also a unit cost to ship cloths from $i$ to $j$. @@ -25,23 +19,27 @@ $$ {\Large\text{\textcircled{$\normalsize i$}}}\xrightarrow{\normalsize c_{ij}}{\Large\triangle}\!\!\!\!\!\!j $$ -#### Inputs +### Variables + +$I$ +: Set of supply nodes -|Variable| Definition| -| --- | --- | -| $I$ | Set of supply nodes | -| $J$ | Set of demand nodes | -| $s_i$ | Supply capacity of node $i$ | -| $d_j$ | Demand at node $j$ | -| $c_{ij}$ | Unit transportation cost to go from $i$ to $j$ | +$J$ +: Set of demand nodes -#### Decision Variables +$s_i$ +: Supply capacity of node $i$ -|Variable| Definition| -| --- | --- | -| $x_{ij}$ | Amount of items to ship from supply node $i$ to demand node $j$. $\forall i\in I, j\in J$ | +$d_j$ +: Demand at node $j$ -#### Objective +$c_{ij}$ +: Unit transportation cost to go from $i$ to $j$ + +$x_{ij}$ [!badge variant="success" text="Decision Variable"] +: Amount of items to ship from supply node $i$ to demand node $j$. $\forall i\in I, j\in J$ + +### Objective We want to minimize the total shipping cost. @@ -56,7 +54,7 @@ x_{ij}&\geqslant 0 \end{aligned} $$ -!!!primary **Proposition.** Integer Constraints ⇒ Integer Solutions, Existence +!!!secondary **Proposition.** Integer Constraints ⇒ Integer Solutions, Existence 1. If $d_j, s_i\in \Z$, the solution are also integers. 2. If the total demand is less than total supply, the the problem is feasible. @@ -78,8 +76,7 @@ Define $x_{ij}$ to be the **flow** on the arc $i\to j$. Each node $i$ has the flow conservation constraint -!!! -**Def.** Flow Conservation +!!!info **Def.** Flow Conservation For each node $i$, @@ -91,7 +88,7 @@ $$ $$ !!! -#### Objective +### Objective Minimize the total cost. $c_{ij}$ is the unit cost to go from $i\to j$. @@ -106,7 +103,7 @@ $$ l_{ij}\leqslant x_{ij}\leqslant u_{ij} $$ -### Special Case: Transportation Problem +## Special Case: Transportation Problem Continue from above, define the vertices to be: @@ -139,17 +136,20 @@ A ={}&\{i\to j: i\text{ is supply node}, j\text{ is demand node}\}\cup{}\\ \end{aligned} $$ -#### Decision Variables +### Decision Variables + +$y_i$ and $z_j$ are new for this model. -$y_i$ and $z_j$ are new +$x_{ij}$ +: Amount of items to ship from supply node $i$ to demand node $j$. + +$y_i$ +: The flow from $u$ to $i$ for each supply node $i$ -|Variable| Definition| -| --- | --- | -| $x_{ij}$ | Amount of items to ship from supply node $i$ to demand node $j$. | -| $y_i$ | The flow from $u$ to $i$ for each supply node $i$ | -| $z_j$ | The from from $j$ to $u$ for each demand node $j$ | +$z_j$ +: The from from $j$ to $u$ for each demand node $j$ -#### Objective +### Objective Minimize the total cost. @@ -159,7 +159,7 @@ $$ Note that the under-braced parts are 0, because we only use $y_i, z_j$ for flow conservation. There’s no unit cost associated with arcs from or into $u$. -#### Constraints +### Constraints For each supply node $i$, total flow out should equal to total flow in. diff --git a/Lecture Notes/W4 - Network Flow Pt 2.md b/Lecture Notes/W4 - Network Flow Pt 2.md index 956d079..a9e2b70 100644 --- a/Lecture Notes/W4 - Network Flow Pt 2.md +++ b/Lecture Notes/W4 - Network Flow Pt 2.md @@ -32,4 +32,3 @@ $$ \min\sum_{(i\to j)\in A}c_{ij}x_{ij} + \sum_{(i\to j)\in A}d_{ij}y_{ij} $$ -idk what happened this week \ No newline at end of file diff --git a/Lecture Notes/W5 - Dynamic Programming Pt 1.md b/Lecture Notes/W5 - Dynamic Programming Pt 1.md index 09468f8..fae9c35 100644 --- a/Lecture Notes/W5 - Dynamic Programming Pt 1.md +++ b/Lecture Notes/W5 - Dynamic Programming Pt 1.md @@ -48,7 +48,7 @@ We could solve the shortest path problem with a general LP solver, but we have m The following pseudocode is from my own [algorithm notes](https://www.notion.so/Single-Source-Shortest-Paths-ccab559c3b5c4f018913429bf3b1091c?pvs=21) but it does the same thing as what we did in class. -||| :icon-code: Pseudocode +|||:icon-code: Pseudocode ```c function Initialize(G, start): for each vertex v in G: @@ -74,7 +74,7 @@ function NonNegativeDijkstras(G, start): pred[v] = u queue.UpdatePriority(v, dist[v]) ``` -||| :icon-rocket: Complexity +|||:icon-rocket: Complexity ``` // matched to each line @@ -104,7 +104,7 @@ O(log V) for heaps where `queue.ExtractMin()` grabs the vertex with the shortest distance. -#### EX. In-class practice graph +=== **Ex.** In-class practice graph ![Source: Canvas, `Shortest_path_problem_in_class.pdf`](/assets/Screenshot_2023-10-23_at_15.33.56.png){class="image-m"} @@ -129,6 +129,8 @@ Running Dijkstra’s algorithm with $\text{start} = A$ gives us shortest path fr │ L │ ['A', 'E', 'F', 'G', 'K', 'L'] │ 61 │ <== Path from A to L ╰──────────────┴────────────────────────────────┴────────────╯ ``` +=== + ### Optimal Substructure @@ -183,16 +185,16 @@ The graph should also be connected, no isolated subgraphs We don’t want (1) basically, since there’s complete tour. [Source](https://www.mdpi.com/2075-1680/10/1/19) -#### The ****Dantzig-Fulkerson-Johnson (DFJ) formulation**** +#### The Dantzig-Fulkerson-Johnson (DFJ) formulation $$ \forall S\sub V, S\ne \varnothing,\text{ define }\delta ^+(S) =\{i\to j\in A:i\in S, j\notin S\}\\[10pt] \sum_{a\in \delta^+(S)}x_a\geqslant 1 $$ -This constraint is what makes TSP an NP-Hard problem, the number of possible $S$’s is the size of the power set of $V$, which is $|{\cal P}(V)|=2^{|V|}$ +This constraint is what makes TSP an NP-Hard problem, the number of possible $S$’s is the size of the power set of $V$, which is ${\cal P}(V)=2^{V}$ -#### **The Miller–Tucker–Zemlin (MTZ)** formulation +#### The Miller–Tucker–Zemlin (MTZ) formulation For each node $i\in V$, label with $u_i\in\N$ except the starting node. @@ -255,20 +257,27 @@ $$ Every DP problem has the following properties: -|Variable| Definition| -| --- | --- | -| $t=1,2,\dots ,T$ | Stages | -| $s_t$ | State at time $t$ | -| $v_t(s_t)$ | Value function | -| $c(s_{t-1}, s_t)$ | Transition cost | + +Stages +: $t=1,2,\dots ,T$ + +State at stage $t$ +: $s_t$ + +Value function +: $v_t(s_t)$ + +Transition cost +: $c(s_{t-1}, s_t)$ $$ v_t(s_t) = \min/\max\{v_{t-1}(s_{t-1}) + c(s_{t-1}, s_t)\} $$ -#### Thm. Principle of optimality +!!!success Theorem. Principle of optimality If $v_t(s_t)$ is optimal, then all the subproblems $v_{t-1}(s_{t-1})$ are also optimal. +!!! ### 0-1 Knapsack @@ -294,11 +303,14 @@ If we don’t have the integer constraint $x_i\in\{0,1\}$, we can just take the #### DP Formulation -|Element| Corresponding varaible| -| --- | --- | -| Stage | The maximum item index $1, 2,\dots,n$. If we are in stage $k$, we only consider items $1,2,\dots, k$. | -| State | $w$, remaining capacity of the backpack | -| Value function | $v_k(w)$, max profit given capacity $w$ and items $1,2,\dots k$ | +Stage +: The maximum item index $1, 2,\dots,n$. If we are in stage $k$, we only consider items $1,2,\dots, k$. + +State +: $w$, remaining capacity of the backpack + +Value function +: $v_k(w)$, max profit given capacity $w$ and items $1,2,\dots k$ $$ v_k(w) = \max\left\{\begin{gathered}v_{k-1}(w-a_k) + c_k\\v_{k-1}(w)\end{gathered}\right\} diff --git a/Lecture Notes/W6 - Dynamic Programming Pt 2.md b/Lecture Notes/W6 - Dynamic Programming Pt 2.md index ba44b17..6b5728e 100644 --- a/Lecture Notes/W6 - Dynamic Programming Pt 2.md +++ b/Lecture Notes/W6 - Dynamic Programming Pt 2.md @@ -10,7 +10,7 @@ icon: circle Going back to the coffee shop example: A coffee shop needs to decide how much coffee beans to purchase and how frequently should they purchase. Now suppose we also own a roastery with a bunch of roasters, where we can roast our own coffee beans. -#### Inputs +#### Variables $t$ : Time period @@ -36,12 +36,12 @@ $K$ $c(a_t)$ : Production cost function - > $$ - > c(a_t) = \begin{cases} - > 0 & \text{if }a_t = 0\\ - > K + b\cdot a_t & \text{if }a_t > 0 - > \end{cases} - > $$ +$$ +c(a_t) = \begin{cases} +0 & \text{if }a_t = 0\\ +K + b\cdot a_t & \text{if }a_t > 0 +\end{cases} +$$ Note that “period” is the interval between each timestamp @@ -195,7 +195,7 @@ $r_t(s_t, a_t)$ : Reward function for the state, action pair at time $t$ $\Bbb P(s_{t+1}\mid s_t, a_t)$ -: Transition probability of going to state $s_{t+1}$ given we took action $a_t$ at state $s_t$. +: Transition probability of actually going to state $s_{t+1}$ given we took action $a_t$ at state $s_t$. $R(s_N)$ or $r_N(s_N)$ : Reward if we end on state $s_N$ @@ -211,7 +211,7 @@ $$ For the stochastic case, replace $v_{t+1}$ with expected value, since it’s possible we might not get to the state $s_{t+1}$. The next state became a random variable: $$ -v_t(s_t) = \underset{a_t\in A}{\max/\min}\,\Big\{r_t(s_t, a_t) + {\color{darkorange}\Bbb E}[v_{t+1}(s_{t+1})\mid s_t, a_t]\Big\} +v_t(s_t) = \underset{a_t\in A}{\max/\min}\,\Big\{r_t(s_t, a_t) + \Bbb E[v_{t+1}(s_{t+1})\mid s_t, a_t]\Big\} $$ Expand with the definition of $\Bbb E$: