Skip to content

Commit 18952a9

Browse files
committed
[lp_intro] update suggestions
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.
1 parent 8bd8fa6 commit 18952a9

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

lectures/lp_intro.md

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,14 @@ Linear programs come in pairs:
3232

3333
* an associated **dual** problem.
3434

35-
If a primal problem involves **maximization**, the dual problem involves **minimization**.
35+
If a primal problem involves *maximization*, the dual problem involves *minimization*.
3636

37-
If a primal problem involves **minimization**, the dual problem involves **maximization**.
37+
If a primal problem involves *minimization**, the dual problem involves **maximization*.
3838

3939
We provide a standard form of a linear program and methods to transform other forms of linear programming problems into a standard form.
4040

4141
We tell how to solve a linear programming problem using [SciPy](https://scipy.org/) and [Google OR-Tools](https://developers.google.com/optimization).
4242

43-
We describe the important concept of complementary slackness and how it relates to the dual problem.
44-
4543
Let's start with some standard imports.
4644

4745
```{code-cell} ipython3
@@ -56,7 +54,7 @@ Let's start with some examples of linear programming problem.
5654

5755

5856

59-
## Example 1: Production Problem
57+
## Example 1: production problem
6058

6159
This example was created by {cite}`bertsimas_tsitsiklis1997`
6260

@@ -144,9 +142,9 @@ In this example, the optimal set is the point $(2.5, 5)$.
144142

145143

146144

147-
### Computation: Using OR-Tools
145+
### Computation: using OR-Tools
148146

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`.
150148

151149

152150

@@ -157,7 +155,7 @@ The following cell instantiates a solver and creates two variables specifying th
157155
solver = pywraplp.Solver.CreateSolver('GLOP')
158156
```
159157

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.
161159

162160
```{code-cell} ipython3
163161
# 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
182180
solver.Maximize(3 * x1 + 4 * x2)
183181
```
184182

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`.
186184

187185
```{code-cell} ipython3
188186
# Solve the system.
189187
status = solver.Solve()
190188
191189
if status == pywraplp.Solver.OPTIMAL:
192190
print('Objective value =', solver.Objective().Value())
193-
x1_sol = round(x1.solution_value(), 2)
194-
x2_sol = round(x2.solution_value(), 2)
195-
print(f'(x1, x2): ({x1_sol}, {x2_sol})')
191+
print(f'(x1, x2): ({x1.solution_value():.2}, {x2.solution_value():.2})')
196192
else:
197193
print('The problem does not have an optimal solution.')
198194
```
199195

200-
## Example 2: Investment Problem
196+
## Example 2: investment problem
201197

202198
We now consider a problem posed and solved by {cite}`hu_guo2018`.
203199

204-
A mutual fund has $ \$ 100,000$ to be invested over a three year horizon.
200+
A mutual fund has $ \$ 100,000$ to be invested over a three-year horizon.
205201

206202
Three investment options are available:
207203

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.
209205

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.
211207

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.
213209
The fund can buy an amount
214210
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.
215211

@@ -279,9 +275,9 @@ $$
279275

280276

281277

282-
### Computation: Using OR-Tools
278+
### Computation: using OR-Tools
283279

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`.
285281

286282
The following cell instantiates a solver and creates two variables specifying the range of values that they can have.
287283

@@ -290,7 +286,7 @@ The following cell instantiates a solver and creates two variables specifying th
290286
solver = pywraplp.Solver.CreateSolver('GLOP')
291287
```
292288

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.
294290

295291
```{code-cell} ipython3
296292
# Create the variables using the ranges available from constraints
@@ -388,7 +384,7 @@ c = \begin{bmatrix} c_1 \\ c_2 \\ \vdots \\ c_n \\ \end{bmatrix}, \quad
388384
x = \begin{bmatrix} x_1 \\ x_2 \\ \vdots \\ x_n \\ \end{bmatrix}. \quad
389385
$$
390386

391-
The standard form LP problem can be expressed concisely as:
387+
The standard form linear programming problem can be expressed concisely as:
392388

393389
$$
394390
\begin{aligned}
@@ -408,15 +404,15 @@ It is useful to know how to transform a problem that initially is not stated in
408404
409405
By deploying the following steps, any linear programming problem can be transformed into an equivalent standard form linear programming problem.
410406
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.
412408
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^-$.
414410
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$.
416412
417413
Let's apply the above steps to the two examples described above.
418414
419-
### Example 1: Production Problem
415+
### Example 1: production problem
420416
421417
The original problem is:
422418
@@ -442,9 +438,9 @@ $$
442438
443439
444440
445-
### Computation: Using SciPy
441+
### Computation: using SciPy
446442
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:
448444
449445
$$
450446
\begin{aligned}
@@ -456,7 +452,7 @@ $$
456452
$$
457453
458454
```{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`.
460456
```
461457
462458
Let's now try to solve the Problem 1 using SciPy.
@@ -488,7 +484,7 @@ else:
488484
489485
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$.
490486
491-
We are using the *linprog* function as a **black box**.
487+
We are using the `linprog` function as a *black box*.
492488
493489
Inside it, Python first transforms the problem into standard form.
494490
@@ -499,12 +495,12 @@ Here the vector of slack variables is a two-dimensional NumPy array that equals
499495
See the [official documentation](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.linprog.html#scipy.optimize.linprog) for more details.
500496
501497
```{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$.
503499
```
504500
505501
506502
507-
### Example 2: Investment Problem
503+
### Example 2: investment problem
508504
509505
The original problem is:
510506
@@ -710,7 +706,7 @@ $$
710706
# Instantiate a GLOP(Google Linear Optimization Package) solver
711707
solver = pywraplp.Solver.CreateSolver('GLOP')
712708
```
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.
714710
715711
```{code-cell} ipython3
716712
# Create the two variables and let them take on any non-negative value.

0 commit comments

Comments
 (0)