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
While this routine uses the same simplex algorithm as
479
-
`scipy.optimize.linprog`, the code is accelerated by using a just-in-time
484
+
While `scipy.optimize.linprog` uses the HiGHS solver by default,
485
+
`quantecon.optimize.linprog_simplex` implements the simplex algorithm accelerated by using a just-in-time
480
486
compiler shipped in the `numba` library.
481
487
482
-
As you will see very soon, by using `scipy.optimize.linprog` the time required to solve an optimal transportation problem can be reduced significantly.
488
+
As you will see very soon, by using `quantecon.optimize.linprog_simplex` the time required to solve an optimal transportation problem can be reduced significantly.
483
489
484
490
```{code-cell} ipython3
485
491
# construct matrices/vectors for linprog_simplex
@@ -502,7 +508,13 @@ minimization, we need to put a negative sign before vector `c`.
Since the two LP solvers use the same simplex algorithm, we expect to get exactly the same solutions
511
+
While the two LP solvers use different algorithms (HiGHS vs. simplex), both should find optimal solutions.
512
+
513
+
The solutions differs since there are multiple optimal solutions, but the objective values are the same
514
+
515
+
```{code-cell} ipython3
516
+
- res_qe.fun == res.fun
517
+
```
506
518
507
519
```{code-cell} ipython3
508
520
res_qe.x.reshape((m, n), order='C')
@@ -526,11 +538,6 @@ Let's do a speed comparison between `scipy.optimize.linprog` and `quantecon.opti
526
538
527
539
As you can see, the `quantecon.optimize.linprog_simplex` is much faster.
528
540
529
-
(Note however, that the SciPy version is probably more stable than the
530
-
QuantEcon version, having been tested more extensively over a longer period of
531
-
time.)
532
-
533
-
534
541
## The Dual Problem
535
542
536
543
Let $u, v$ denotes vectors of dual decision variables with entries $(u_i), (v_j)$.
@@ -584,48 +591,23 @@ print("u:", res_dual.x[:m])
584
591
print("v:", res_dual.x[-n:])
585
592
```
586
593
587
-
We can also solve the dual problem using [quantecon.optimize.linprog_simplex](https://quanteconpy.readthedocs.io/en/latest/optimize/linprog_simplex.html).
And the shadow prices computed by the two programs are identical.
594
+
Fortunately, `quantecon.optimize.linprog_simplex` already computes and returns the dual variables alongside the primal solution, eliminating the need for a separate dual solve.
594
595
595
-
```{code-cell} ipython3
596
-
res_dual_qe.x
597
-
```
596
+
The dual variables (shadow prices) can be extracted directly from the primal solution:
598
597
599
598
```{code-cell} ipython3
600
-
res_dual.x
599
+
# The dual variables are returned automatically by linprog_simplex
0 commit comments