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
Copy file name to clipboardExpand all lines: in-work/lp_intro.md
+24Lines changed: 24 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -154,7 +154,11 @@ The following cell instantiates a solver and creates two variables specifying th
154
154
```{code-cell} ipython3
155
155
# Instantiate a GLOP(Google Linear Optimization Package) solver
156
156
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.
157
160
161
+
```{code-cell} ipython3
158
162
# Create the two variables and let them take on any non-negative value.
159
163
x1 = solver.NumVar(0, solver.infinity(), 'x1')
160
164
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
177
181
solver.Maximize(3 * x1 + 4 * x2)
178
182
```
179
183
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
+
180
186
```{code-cell} ipython3
181
187
# Solve the system.
182
188
status = solver.Solve()
@@ -281,7 +287,11 @@ The following cell instantiates a solver and creates two variables specifying th
281
287
```{code-cell} ipython3
282
288
# Instantiate a GLOP(Google Linear Optimization Package) solver
283
289
solver = pywraplp.Solver.CreateSolver('GLOP')
290
+
```
284
291
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
285
295
# Create the variables using the ranges available from constraints
Let's solve the problem and check the status using `pywraplp.Solver.OPTIMAL`.
324
+
313
325
```{code-cell} ipython3
314
326
# Solve the system.
315
327
status = solver.Solve()
@@ -456,7 +468,11 @@ c_ex1 = np.array([3, 4])
456
468
A_ex1 = np.array([[2, 5],
457
469
[4, 2]])
458
470
b_ex1 = np.array([30,20])
471
+
```
459
472
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
460
476
# Solve the problem
461
477
# we put a negative sign on the objective as linprog does minimization
0 commit comments