You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This pull request update some of the the lp_intro.md lecture according to #469 (mainly involving typos, styles)
In particular, the changes include:
- [x] Unbold non-definition words and use italics for emphases
- [x] Remove capitalization in the titles
- [x] Add period for the first sentence in example 1
- [x] use "`ortools.linear_solver`"
- [x] "... using it's status" -> "... using its status"
- Round the print in the format string for printing.
- "three year" -> "three-year"
- "Let's us" -> "Let's"
- "LP" -> "Linear programming"
- In the dot point in the "useful transformations" section, remove the capitalization of the second word.
- 'bounds' -> `bounds`
- We did not discuss complementary slackness, so we can delete it.
One thing I find is that the column header is automatically in bold, so I cannot fix it by changing the md file.
Copy file name to clipboardExpand all lines: lectures/lp_intro.md
+28-32Lines changed: 28 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -32,16 +32,14 @@ Linear programs come in pairs:
32
32
33
33
* an associated **dual** problem.
34
34
35
-
If a primal problem involves **maximization**, the dual problem involves **minimization**.
35
+
If a primal problem involves *maximization*, the dual problem involves *minimization*.
36
36
37
-
If a primal problem involves **minimization**, the dual problem involves **maximization**.
37
+
If a primal problem involves *minimization**, the dual problem involves **maximization*.
38
38
39
39
We provide a standard form of a linear program and methods to transform other forms of linear programming problems into a standard form.
40
40
41
41
We tell how to solve a linear programming problem using [SciPy](https://scipy.org/) and [Google OR-Tools](https://developers.google.com/optimization).
42
42
43
-
We describe the important concept of complementary slackness and how it relates to the dual problem.
44
-
45
43
Let's start with some standard imports.
46
44
47
45
```{code-cell} ipython3
@@ -56,7 +54,7 @@ Let's start with some examples of linear programming problem.
56
54
57
55
58
56
59
-
## Example 1: Production Problem
57
+
## Example 1: production problem
60
58
61
59
This example was created by {cite}`bertsimas_tsitsiklis1997`
62
60
@@ -144,9 +142,9 @@ In this example, the optimal set is the point $(2.5, 5)$.
144
142
145
143
146
144
147
-
### Computation: Using OR-Tools
145
+
### Computation: using OR-Tools
148
146
149
-
Let's try to solve the same problem using the package *ortools.linear_solver*
147
+
Let's try to solve the same problem using the package `ortools.linear_solver`.
150
148
151
149
152
150
@@ -157,7 +155,7 @@ The following cell instantiates a solver and creates two variables specifying th
157
155
solver = pywraplp.Solver.CreateSolver('GLOP')
158
156
```
159
157
160
-
Let's us create two variables $x_1$ and $x_2$ such that they can only have nonnegative values.
158
+
Let's create two variables $x_1$ and $x_2$ such that they can only have nonnegative values.
161
159
162
160
```{code-cell} ipython3
163
161
# Create the two variables and let them take on any non-negative value.
@@ -182,34 +180,32 @@ Let's specify the objective function. We use `solver.Maximize` method in the cas
182
180
solver.Maximize(3 * x1 + 4 * x2)
183
181
```
184
182
185
-
Once we solve the problem, we can check whether the solver was successful in solving the problem using it's status. If it's successful, then the status will be equal to `pywraplp.Solver.OPTIMAL`.
183
+
Once we solve the problem, we can check whether the solver was successful in solving the problem using its status. If it's successful, then the status will be equal to `pywraplp.Solver.OPTIMAL`.
186
184
187
185
```{code-cell} ipython3
188
186
# Solve the system.
189
187
status = solver.Solve()
190
188
191
189
if status == pywraplp.Solver.OPTIMAL:
192
190
print('Objective value =', solver.Objective().Value())
print('The problem does not have an optimal solution.')
198
194
```
199
195
200
-
## Example 2: Investment Problem
196
+
## Example 2: investment problem
201
197
202
198
We now consider a problem posed and solved by {cite}`hu_guo2018`.
203
199
204
-
A mutual fund has $ \$ 100,000$ to be invested over a threeyear horizon.
200
+
A mutual fund has $ \$ 100,000$ to be invested over a three-year horizon.
205
201
206
202
Three investment options are available:
207
203
208
-
1.**Annuity:** the fund can pay a same amount of new capital at the beginning of each of three years and receive a payoff of 130\% of **total capital** invested at the end of the third year. Once the mutual fund decides to invest in this annuity, it has to keep investing in all subsequent years in the three year horizon.
204
+
1. Annuity: the fund can pay a same amount of new capital at the beginning of each of three years and receive a payoff of 130\% of total capital invested at the end of the third year. Once the mutual fund decides to invest in this annuity, it has to keep investing in all subsequent years in the three year horizon.
209
205
210
-
2.**Bank account:** the fund can deposit any amount into a bank at the beginning of each year and receive its capital plus 6\% interest at the end of that year. In addition, the mutual fund is permitted to borrow no more than $20,000 at the beginning of each year and is asked to pay back the amount borrowed plus 6\% interest at the end of the year. The mutual fund can choose whether to deposit or borrow at the beginning of each year.
206
+
2. Bank account: the fund can deposit any amount into a bank at the beginning of each year and receive its capital plus 6\% interest at the end of that year. In addition, the mutual fund is permitted to borrow no more than $20,000 at the beginning of each year and is asked to pay back the amount borrowed plus 6\% interest at the end of the year. The mutual fund can choose whether to deposit or borrow at the beginning of each year.
211
207
212
-
3.**Corporate bond:** At the beginning of the second year, a corporate bond becomes available.
208
+
3. Corporate bond: At the beginning of the second year, a corporate bond becomes available.
213
209
The fund can buy an amount
214
210
that is no more than $ \$ $50,000 of this bond at the beginning of the second year and at the end of the third year receive a payout of 130\% of the amount invested in the bond.
215
211
@@ -279,9 +275,9 @@ $$
279
275
280
276
281
277
282
-
### Computation: Using OR-Tools
278
+
### Computation: using OR-Tools
283
279
284
-
Let's try to solve the above problem using the package *ortools.linear_solver*.
280
+
Let's try to solve the above problem using the package `ortools.linear_solver`.
285
281
286
282
The following cell instantiates a solver and creates two variables specifying the range of values that they can have.
287
283
@@ -290,7 +286,7 @@ The following cell instantiates a solver and creates two variables specifying th
290
286
solver = pywraplp.Solver.CreateSolver('GLOP')
291
287
```
292
288
293
-
Let's us create five variables $x_1, x_2, x_3, x_4,$ and $x_5$ such that they can only have the values defined in the above constraints.
289
+
Let's create five variables $x_1, x_2, x_3, x_4,$ and $x_5$ such that they can only have the values defined in the above constraints.
294
290
295
291
```{code-cell} ipython3
296
292
# Create the variables using the ranges available from constraints
The standard form LP problem can be expressed concisely as:
387
+
The standard form linear programming problem can be expressed concisely as:
392
388
393
389
$$
394
390
\begin{aligned}
@@ -408,15 +404,15 @@ It is useful to know how to transform a problem that initially is not stated in
408
404
409
405
By deploying the following steps, any linear programming problem can be transformed into an equivalent standard form linear programming problem.
410
406
411
-
1. **Objective Function:** If a problem is originally a constrained **maximization** problem, we can construct a new objective function that is the additive inverse of the original objective function. The transformed problem is then a **minimization** problem.
407
+
1. Objective function: If a problem is originally a constrained *maximization* problem, we can construct a new objective function that is the additive inverse of the original objective function. The transformed problem is then a *minimization* problem.
412
408
413
-
2. **Decision Variables:** Given a variable $x_j$ satisfying $x_j \le 0$, we can introduce a new variable $x_j' = - x_j$ and substitute it into original problem. Given a free variable $x_i$ with no restriction on its sign, we can introduce two new variables $x_j^+$ and $x_j^-$ satisfying $x_j^+, x_j^- \ge 0$ and replace $x_j$ by $x_j^+ - x_j^-$.
409
+
2. Decision variables: Given a variable $x_j$ satisfying $x_j \le 0$, we can introduce a new variable $x_j' = - x_j$ and substitute it into original problem. Given a free variable $x_i$ with no restriction on its sign, we can introduce two new variables $x_j^+$ and $x_j^-$ satisfying $x_j^+, x_j^- \ge 0$ and replace $x_j$ by $x_j^+ - x_j^-$.
414
410
415
-
3. **Inequality constraints:** Given an inequality constraint $\sum_{j=1}^n a_{ij}x_j \le 0$, we can introduce a new variable $s_i$, called a **slack variable** that satisfies $s_i \ge 0$ and replace the original constraint by $\sum_{j=1}^n a_{ij}x_j + s_i = 0$.
411
+
3. Inequality constraints: Given an inequality constraint $\sum_{j=1}^n a_{ij}x_j \le 0$, we can introduce a new variable $s_i$, called a **slack variable** that satisfies $s_i \ge 0$ and replace the original constraint by $\sum_{j=1}^n a_{ij}x_j + s_i = 0$.
416
412
417
413
Let's apply the above steps to the two examples described above.
418
414
419
-
### Example 1: Production Problem
415
+
### Example 1: production problem
420
416
421
417
The original problem is:
422
418
@@ -442,9 +438,9 @@ $$
442
438
443
439
444
440
445
-
### Computation: Using SciPy
441
+
### Computation: using SciPy
446
442
447
-
The package *scipy.optimize* provides a function ***linprog*** to solve linear programming problems with a form below:
443
+
The package `scipy.optimize` provides a function `linprog` to solve linear programming problems with a form below:
448
444
449
445
$$
450
446
\begin{aligned}
@@ -456,7 +452,7 @@ $$
456
452
$$
457
453
458
454
```{note}
459
-
By default $l = 0$ and $u = \text{None}$ unless explicitly specified with the argument 'bounds'.
455
+
By default $l = 0$ and $u = \text{None}$ unless explicitly specified with the argument `bounds`.
460
456
```
461
457
462
458
Let's now try to solve the Problem 1 using SciPy.
@@ -488,7 +484,7 @@ else:
488
484
489
485
The optimal plan tells the factory to produce $2.5$ units of Product 1 and $5$ units of Product 2; that generates a maximizing value of revenue of $27.5$.
490
486
491
-
We are using the *linprog* function as a **black box**.
487
+
We are using the `linprog` function as a *black box*.
492
488
493
489
Inside it, Python first transforms the problem into standard form.
494
490
@@ -499,12 +495,12 @@ Here the vector of slack variables is a two-dimensional NumPy array that equals
499
495
See the [official documentation](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.linprog.html#scipy.optimize.linprog) for more details.
500
496
501
497
```{note}
502
-
This problem is to maximize the objective, so that we need to put a minus sign in front of parameter vector c.
498
+
This problem is to maximize the objective, so that we need to put a minus sign in front of parameter vector $c$.
503
499
```
504
500
505
501
506
502
507
-
### Example 2: Investment Problem
503
+
### Example 2: investment problem
508
504
509
505
The original problem is:
510
506
@@ -710,7 +706,7 @@ $$
710
706
# Instantiate a GLOP(Google Linear Optimization Package) solver
711
707
solver = pywraplp.Solver.CreateSolver('GLOP')
712
708
```
713
-
Let's us create two variables $x_1$ and $x_2$ such that they can only have nonnegative values.
709
+
Let's create two variables $x_1$ and $x_2$ such that they can only have nonnegative values.
714
710
715
711
```{code-cell} ipython3
716
712
# Create the two variables and let them take on any non-negative value.
0 commit comments