Skip to content

Commit f40c87c

Browse files
authored
MAINT: tidy up and update environment (#181)
* tidy up and update environment * add additional extensions * minor changes to lectures * adjust some math for lp_intro for aligned * fix opt_transport align* to aligned
1 parent 7672db0 commit f40c87c

File tree

6 files changed

+54
-52
lines changed

6 files changed

+54
-52
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
.DS_Store
12
_build/
23
lectures/_build/

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dependencies:
1414
- jupytext==1.11.2
1515
- ghp-import==1.1.0
1616
- jupinx==0.2.3
17+
- sphinxcontrib-youtube==1.0.1
1718
# Temporary Fixes
1819
- tornado>=6.1
1920

lectures/.DS_Store

-12 KB
Binary file not shown.

lectures/_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ latex:
1919
targetname: quantecon-python.tex
2020

2121
sphinx:
22-
extra_extensions: [sphinx_multitoc_numbering, sphinxext.rediraffe, sphinx_tojupyter]
22+
extra_extensions: [sphinx_multitoc_numbering, sphinxext.rediraffe, sphinx_tojupyter, sphinxcontrib.youtube, sphinx.ext.todo]
2323
config:
2424
nb_render_priority:
2525
html:

lectures/lp_intro.md

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ Let $x_i$ denote the quantity of Product $i$ that the firm produces.
118118
This problem can be formulated as:
119119
120120
$$
121-
\begin{align*}
121+
\begin{aligned}
122122
\max_{x_1,x_2} \ & z = 3 x_1 + 4 x_2 \\
123123
\mbox{subject to } \ & 2 x_1 + 5 x_2 \le 30 \\
124124
& 4 x_1 + 2 x_2 \le 20 \\
125125
& x_1, x_2 \ge 0 \\
126-
\end{align*}
126+
\end{aligned}
127127
$$
128128
129129
The following graph illustrates the firm's constraints and iso-revenue lines.
@@ -240,7 +240,7 @@ $$
240240
Thus, the mutual fund confronts the linear program:
241241
242242
$$
243-
\begin{align*}
243+
\begin{aligned}
244244
\max_{x} \ & 1.30 \cdot 3x_1 + 1.06 x_4 + 1.30 x_5 \\
245245
\mbox{subject to } \ & x_1 + x_2 = 100,000\\
246246
& x_1 - 1.06 x_2 + x_3 + x_5 = 0\\
@@ -251,7 +251,7 @@ $$
251251
& x_5 \le 50,000\\
252252
& x_j \ge 0, \quad j = 1,5\\
253253
& x_j \ \text{unrestricted}, \quad j = 2,3,4\\
254-
\end{align*}
254+
\end{aligned}
255255
$$
256256
257257
## Standard Form
@@ -267,14 +267,14 @@ it is useful to devote some effort to describe a **standard form**.
267267
Our standard form is:
268268
269269
$$
270-
\begin{align*}
270+
\begin{aligned}
271271
\min_{x} \ & c_1 x_1 + c_2 x_2 + \dots + c_n x_n \\
272272
\mbox{subject to } \ & a_{11} x_1 + a_{12} x_2 + \dots + a_{1n} x_n = b_1 \\
273273
& a_{21} x_1 + a_{22} x_2 + \dots + a_{2n} x_n = b_2 \\
274274
& \quad \vdots \\
275275
& a_{m1} x_1 + a_{m2} x_2 + \dots + a_{mn} x_n = b_m \\
276276
& x_1, x_2, \dots, x_n \ge 0 \\
277-
\end{align*}
277+
\end{aligned}
278278
$$
279279
280280
Let
@@ -294,18 +294,18 @@ $$
294294
The standard form LP problem can be expressed concisely as:
295295
296296
$$
297-
\begin{align*}
297+
\begin{aligned}
298298
\min_{x} \ & c'x \\
299299
\mbox{subject to } \ & Ax = b\\
300300
& x >= 0\\
301-
\end{align*}
301+
\end{aligned}
302302
$$ (lpproblem)
303303
304304
Here, $Ax = b$ means that the $i$-th entry of $Ax$ equals the $i$-th entry of $b$ for every $i$.
305305
306306
Similarly, $x >= 0$ means that $x_j$ is greater than $0$ for every $j$.
307307
308-
#### Useful Transformations
308+
### Useful Transformations
309309
310310
It is useful to know how to transform a problem that initially is not stated in the standard form into one that is.
311311
@@ -319,36 +319,36 @@ By deploying the following steps, any linear programming problem can be transfor
319319
320320
Let's apply the above steps to the two examples described above.
321321
322-
#### Example 1: Production Problem
322+
### Example 1: Production Problem
323323
324324
The original problem is:
325325
326326
$$
327-
\begin{align*}
327+
\begin{aligned}
328328
\max_{x_1,x_2} \ & 3 x_1 + 4 x_2 \\
329329
\mbox{subject to } \ & 2 x_1 + 5 x_2 \le 30 \\
330330
& 4 x_1 + 2 x_2 \le 20 \\
331331
& x_1, x_2 \ge 0 \\
332-
\end{align*}
332+
\end{aligned}
333333
$$
334334
335335
This problem is equivalent to the following problem with a standard form:
336336
337337
$$
338-
\begin{align*}
338+
\begin{aligned}
339339
\min_{x_1,x_2} \ & -(3 x_1 + 4 x_2) \\
340340
\mbox{subject to } \ & 2 x_1 + 5 x_2 + s_1 = 30 \\
341341
& 4 x_1 + 2 x_2 + s_2 = 20 \\
342342
& x_1, x_2, s_1, s_2 \ge 0 \\
343-
\end{align*}
343+
\end{aligned}
344344
$$
345345
346-
#### Example 2: Investment Problem
346+
### Example 2: Investment Problem
347347
348348
The original problem is:
349349
350350
$$
351-
\begin{align*}
351+
\begin{aligned}
352352
\max_{x} \ & 1.30 \cdot 3x_1 + 1.06 x_4 + 1.30 x_5 \\
353353
\mbox{subject to } \ & x_1 + x_2 = 100,000\\
354354
& x_1 - 1.06 x_2 + x_3 + x_5 = 0\\
@@ -359,13 +359,13 @@ $$
359359
& x_5 \le 50,000\\
360360
& x_j \ge 0, \quad j = 1,5\\
361361
& x_j \ \text{unrestricted}, \quad j = 2,3,4\\
362-
\end{align*}
362+
\end{aligned}
363363
$$
364364
365365
This problem is equivalent to the following problem with a standard form:
366366
367367
$$
368-
\begin{align*}
368+
\begin{aligned}
369369
\min_{x} \ & -(1.30 \cdot 3x_1 + 1.06 x_4^+ - 1.06 x_4^- + 1.30 x_5) \\
370370
\mbox{subject to } \ & x_1 + x_2^+ - x_2^- = 100,000\\
371371
& x_1 - 1.06 (x_2^+ - x_2^-) + x_3^+ - x_3^- + x_5 = 0\\
@@ -377,20 +377,20 @@ $$
377377
& x_j \ge 0, \quad j = 1,5\\
378378
& x_j^+, x_j^- \ge 0, \quad j = 2,3,4\\
379379
& s_j \ge 0, \quad j = 1,2,3,4\\
380-
\end{align*}
380+
\end{aligned}
381381
$$
382382
383383
## Computations
384384
385385
The package *scipy.optimize* provides a function ***linprog*** to solve linear programming problems with a form below:
386386
387387
$$
388-
\begin{align*}
388+
\begin{aligned}
389389
\min_{x} \ & c' x \\
390390
\mbox{subject to } \ & A_{ub}x \le b_{ub} \\
391391
& A_{eq}x = b_{eq} \\
392392
& l \le x \le u \\
393-
\end{align*}
393+
\end{aligned}
394394
$$
395395
396396
```{note}
@@ -404,12 +404,12 @@ Let's apply this great Python tool to solve our two example problems.
404404
The problem is:
405405
406406
$$
407-
\begin{align*}
407+
\begin{aligned}
408408
\max_{x_1,x_2} \ & 3 x_1 + 4 x_2 \\
409409
\mbox{subject to } \ & 2 x_1 + 5 x_2 \le 30 \\
410410
& 4 x_1 + 2 x_2 \le 20 \\
411411
& x_1, x_2 \ge 0 \\
412-
\end{align*}
412+
\end{aligned}
413413
$$
414414
415415
```{code-cell} ipython3
@@ -449,7 +449,7 @@ This problem is to maximize the objective, so that we need to put a minus sign i
449449
The problem is:
450450
451451
$$
452-
\begin{align*}
452+
\begin{aligned}
453453
\max_{x} \ & 1.30 \cdot 3x_1 + 1.06 x_4 + 1.30 x_5 \\
454454
\mbox{subject to } \ & x_1 + x_2 = 100,000\\
455455
& x_1 - 1.06 x_2 + x_3 + x_5 = 0\\
@@ -460,7 +460,7 @@ $$
460460
& x_5 \le 50,000\\
461461
& x_j \ge 0, \quad j = 1,5\\
462462
& x_j \ \text{unrestricted}, \quad j = 2,3,4\\
463-
\end{align*}
463+
\end{aligned}
464464
$$
465465
466466
Let's solve this problem using *linprog*.
@@ -508,15 +508,15 @@ Associated with a linear programming of form {eq}`linprog` with $m$ constraints
508508
there is an **dual** linear programming problem that takes the form (please see {cite}`bertsimas_tsitsiklis1997`)
509509
510510
$$
511-
\begin{align*}
511+
\begin{aligned}
512512
\max_{p} \ & b' p \\
513513
\mbox{subject to } \ & p_i \ge 0, & i \in M_1 \\
514514
& p_i \le 0, & i \in M_2 \\
515515
& p_i\ \text{unrestricted}, & i \in M_3 \\
516516
& A_j' p \le c_j, & j \in N_1 \\
517517
& A_j' p \ge c_j, & j \in N_2 \\
518518
& A_j' p = c_j, & j \in N_3 \\
519-
\end{align*}
519+
\end{aligned}
520520
$$
521521
522522
Where $A_j$ is $j$-th column of the $m$ by $n$ matrix $A$.
@@ -562,30 +562,30 @@ The following table summarizes relationships between objects in primal and dual
562562
As an example, the dual problem of the standard form {eq}`lpproblem` is:
563563
564564
$$
565-
\begin{align*}
565+
\begin{aligned}
566566
\max_{p} \ & b'p \\
567567
\mbox{subject to } \ & A'p \le c\\
568-
\end{align*}
568+
\end{aligned}
569569
$$
570570
571571
As another example, consider a linear programming problem with form:
572572
573573
$$
574-
\begin{align*}
574+
\begin{aligned}
575575
\max_{x} \ & c'x \\
576576
\mbox{subject to } \ & A x \le b\\
577577
& x \ge 0\\
578-
\end{align*}
578+
\end{aligned}
579579
$$ (linprog2)
580580
581581
Its dual problem is:
582582
583583
$$
584-
\begin{align*}
584+
\begin{aligned}
585585
\min_{p} \ & b'p \\
586586
\mbox{subject to } \ & A' p \ge c\\
587587
& p \ge 0\\
588-
\end{align*}
588+
\end{aligned}
589589
$$
590590
591591
## Duality Theorems
@@ -690,12 +690,12 @@ This problem is one specific instance of the problem {eq}`linprog2`, whose econo
690690
Its dual problem is:
691691
692692
$$
693-
\begin{align*}
693+
\begin{aligned}
694694
\min_{x_1,x_2} \ & 30 p_1 + 20 p_2 \\
695695
\mbox{subject to } \ & 2 p_1 + 4 p_2 \ge 3 \\
696696
& 5 p_1 + 2 p_2 \ge 4 \\
697697
& p_1, p_2 \ge 0 \\
698-
\end{align*}
698+
\end{aligned}
699699
$$
700700
701701
We then solve this dual problem by function *linprog*. Since parameters used here are defined before when solving the primal problem, we don't need to define them here.
@@ -714,7 +714,7 @@ The optimal of the dual problem is 27.5, which is the same as the primal problem
714714
The dual problem is:
715715
716716
$$
717-
\begin{align*}
717+
\begin{aligned}
718718
\min_{p} \ & 100,000 p_1 - 20,000 p_4 - 20,000 p_5 - 20,000 p_6 + 50,000 p_7 \\
719719
\mbox{subject to } \ & p_1 + p_2 + p_3 \ge 1.30 \cdot 3 \\
720720
& p_1 - 1.06 p_2 + p_4 = 0 \\
@@ -724,7 +724,7 @@ $$
724724
& p_i \ \text{unrestricted}, \quad i = 1,2,3 \\
725725
& p_i \le 0, \quad i = 4,5,6 \\
726726
& p_7 \ge 0 \\
727-
\end{align*}
727+
\end{aligned}
728728
$$
729729
730730
We then solve this dual problem by function *linprog*.

lectures/opt_transport.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ The optimal transport problem was studied in early work about linear programming
2626

2727
We shall solve our problems first by using the scipy function *linprog* and then the quantecon program *linprog_simplex*.
2828

29-
Let's start with some imports.
30-
3129
```{code-cell} ipython3
32-
# !pip list outdated
33-
# !pip install -- upgrade quantecon
30+
:tags: [hide-output]
31+
!pip install --upgrade quantecon
3432
```
3533

34+
Let's start with some imports.
35+
3636
```{code-cell} ipython3
3737
import numpy as np
3838
from scipy.optimize import linprog
@@ -62,12 +62,12 @@ A planner wants to minimize total transportation costs subject to the following
6262
The planner's problem can be expressed as the following constrained minimization problem:
6363

6464
$$
65-
\begin{align*}
65+
\begin{aligned}
6666
\min_{x_{ij}} \ & \sum_{i=1}^m \sum_{j=1}^n c_{ij} x_{ij} \\
6767
\mbox{subject to } \ & \sum_{j=1}^n x_{ij} = p_i, & i = 1, 2, \dots, m \\
6868
& \sum_{i=1}^m x_{ij} = q_j, & j = 1, 2, \dots, n \\
6969
& x_{ij} \ge 0 \\
70-
\end{align*}
70+
\end{aligned}
7171
$$ (plannerproblem)
7272
7373
This is an **optimal transport problem** with
@@ -105,12 +105,12 @@ Let
105105
Where $\mathbf{1}_n$ denotes $n$-dimensional column vector $(1, 1, \dots, 1)'$, our problem can now be expressed compactly as:
106106
107107
$$
108-
\begin{align*}
108+
\begin{aligned}
109109
\min_{X} \ & \operatorname{tr} (C' X) \\
110110
\mbox{subject to } \ & X \ \mathbf{1}_n = p \\
111111
& X' \ \mathbf{1}_m = q \\
112112
& X \ge 0 \\
113-
\end{align*}
113+
\end{aligned}
114114
$$
115115
116116
We can convert the matrix $X$ into a vector by stacking all of its columns into a column vector.
@@ -176,11 +176,11 @@ $$
176176
Our problem can now be expressed in terms of an $mn$-dimensional vector of decision variables:
177177
178178
$$
179-
\begin{align*}
179+
\begin{aligned}
180180
\min_{z} \ & \operatorname{vec}(C)' z \\
181181
\mbox{subject to } \ & A z = b \\
182182
& z \ge 0 \\
183-
\end{align*}
183+
\end{aligned}
184184
$$ (decisionvars)
185185
186186
where
@@ -451,10 +451,10 @@ Let $u, v$ denotes vectors of dual decision variables with entries $(u_i), (v_j)
451451
The **dual** to **minimization** problem {eq}`plannerproblem` is the **maximization** problem:
452452
453453
$$
454-
\begin{align*}
454+
\begin{aligned}
455455
\max_{u_i, v_j} \ & \sum_{i=1}^m p_i u_i + \sum_{j=1}^n q_j v_j \\
456456
\mbox{subject to } \ & u_i + v_j \le c_{ij}, \ i = 1, 2, \dots, m;\ j = 1, 2, \dots, n \\
457-
\end{align*}
457+
\end{aligned}
458458
$$ (dualproblem)
459459
460460
The dual problem is also a linear programming problem.
@@ -476,10 +476,10 @@ Components of the vectors $u$ and $v$ of **values** are **shadow prices** of th
476476
We can write the dual problem as
477477
478478
$$
479-
\begin{align*}
479+
\begin{aligned}
480480
\max_{u_i, v_j} \ & p u + q v \\
481481
\mbox{subject to } \ & A' \begin{bmatrix} u \\ v \\ \end{bmatrix} = \operatorname{vec}(C) \\
482-
\end{align*}
482+
\end{aligned}
483483
$$ (dualproblem2)
484484
485485
For the same numerical example described above, let's solve the dual problem.

0 commit comments

Comments
 (0)