Skip to content

Commit ff44e15

Browse files
committed
suggestions
1 parent 72095a6 commit ff44e15

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

in-work/lp_intro.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ The following cell instantiates a solver and creates two variables specifying th
154154
```{code-cell} ipython3
155155
# Instantiate a GLOP(Google Linear Optimization Package) solver
156156
solver = pywraplp.Solver.CreateSolver('GLOP')
157+
```
158+
159+
Let's us create two variables $x_1$ and $x_2$ such that they can only have nonnegative values.
157160

161+
```{code-cell} ipython3
158162
# Create the two variables and let them take on any non-negative value.
159163
x1 = solver.NumVar(0, solver.infinity(), 'x1')
160164
x2 = solver.NumVar(0, solver.infinity(), 'x2')
@@ -177,6 +181,8 @@ Let's specify the objective function. We use `solver.Maximize` method in the cas
177181
solver.Maximize(3 * x1 + 4 * x2)
178182
```
179183

184+
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`.
185+
180186
```{code-cell} ipython3
181187
# Solve the system.
182188
status = solver.Solve()
@@ -281,7 +287,11 @@ The following cell instantiates a solver and creates two variables specifying th
281287
```{code-cell} ipython3
282288
# Instantiate a GLOP(Google Linear Optimization Package) solver
283289
solver = pywraplp.Solver.CreateSolver('GLOP')
290+
```
284291

292+
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.
293+
294+
```{code-cell} ipython3
285295
# Create the variables using the ranges available from constraints
286296
x1 = solver.NumVar(0, solver.infinity(), 'x1')
287297
x2 = solver.NumVar(-20_000, solver.infinity(), 'x2')
@@ -310,6 +320,8 @@ Let's specify the objective function.
310320
solver.Maximize(1.30 * 3 * x1 + 1.06 * x4 + 1.30 * x5)
311321
```
312322

323+
Let's solve the problem and check the status using `pywraplp.Solver.OPTIMAL`.
324+
313325
```{code-cell} ipython3
314326
# Solve the system.
315327
status = solver.Solve()
@@ -456,7 +468,11 @@ c_ex1 = np.array([3, 4])
456468
A_ex1 = np.array([[2, 5],
457469
[4, 2]])
458470
b_ex1 = np.array([30,20])
471+
```
459472
473+
Once we solve the problem, we can check whether the solver was successful in solving the problem using the boolean attribute `success`. If it's successful, then the `success` attribute is set to `True`.
474+
475+
```{code-cell} ipython3
460476
# Solve the problem
461477
# we put a negative sign on the objective as linprog does minimization
462478
res_ex1 = linprog(-c_ex1, A_ub=A_ex1, b_ub=b_ex1, method='revised simplex')
@@ -543,7 +559,12 @@ bounds_ex2 = [( 0, None),
543559
(-20000, None),
544560
(-20000, None),
545561
( 0, 50000)]
562+
```
563+
564+
Let's solve the problem and check the status using `success` attribute.
546565
566+
567+
```{code-cell} ipython3
547568
# Solve the problem
548569
res_ex2 = linprog(-c_ex2, A_eq=A_ex2, b_eq=b_ex2,
549570
bounds=bounds_ex2, method='revised simplex')
@@ -694,7 +715,10 @@ $$
694715
```{code-cell} ipython3
695716
# Instantiate a GLOP(Google Linear Optimization Package) solver
696717
solver = pywraplp.Solver.CreateSolver('GLOP')
718+
```
719+
Let's us create two variables $x_1$ and $x_2$ such that they can only have nonnegative values.
697720
721+
```{code-cell} ipython3
698722
# Create the two variables and let them take on any non-negative value.
699723
x = solver.NumVar(0, solver.infinity(), 'x')
700724
y = solver.NumVar(0, solver.infinity(), 'y')

0 commit comments

Comments
 (0)