-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
FEAT: Add linprog_simplex
#413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
A few comments at the moment:
|
Sure, I'll work on those. |
See the comments following #216 (comment). |
This is an excellent contribution! I hope that this allows the repeated games code to be more effective than it initially was in Python. @jstac is planning on having more numba based optimization routines (the discussion @oyamad linked to) and I agree with everyone that having an optimize submodule is a great idea. @oyamad, let me know if you need another set of eyes while reviewing this code. A quick glance reveals that the documentation is well done and thorough, but I haven't carefully read the code. |
@cc7768 Your review will be appreciated. One of the great things of this PR is that a big set of tests is already prepared (from SciPy). As long as the tests pass (they do), we can first discuss for the "best" public API, which should depend on possible use cases. @QBatista Can you make available somewhere your Python notebook in which your |
Here is the notebook: https://nbviewer.jupyter.org/github/QBatista/Notebooks/blob/master/linprog_simplex%20%5BWIP%5D.ipynb I also fixed a bug that was related to a misunderstanding of how the already existing |
What variable does |
I meant that I thought only the |
If the documentation says an array is "modified in place", the one should not expect that a particular part of that array will not be modified. |
Ok, sounds good. |
@oyamad I am not sure how you want me to use the lexico-minimum ratio test. Bland's rule determines how both the pivot row and pivot column are chosen while the lexico-minimum test as implemented in |
I also figured out what was going wrong with the |
Which part of that paper should I look at? |
Part 2 (up to the proof of theorem 5) describes how to solve the generalized matrix problem in which the LP problem is embedded. Part 3 describes one of the possible ways of embedding it. The term "lexicographic rule" is not explicitly used in the paper, but the variant is referred to as using the lexicographic rule, for example, by Pan (2014) which you showed me. |
A quick Google search found this. |
Ok, I can implement this. I think it's the same as in the paper but explained in much simpler terms. The pivot column is chosen arbitrarily among nonbasic variables; should I try different rules and compare them? |
Is |
It should be for choosing the pivot row, but my point is about the pivot column. For example, the pivot column can be chosen to be the index of the first nonbasic variable found or that of the one with the largest coefficient. |
To clarify, |
I don't see the issue. Why does the way to choose the pivot column matter (for the purpose of tie breaking), once the right hand side is perturbed? |
It doesn't matter for the specific purpose of tie breaking, but wouldn't it interact with the rule for choosing the pivot column in terms of overall performance? This might not actually have much of an impact on the performance, especially if ties don't occur frequently, but I was intrigued because there is no explicit choice of a rule. |
A quick Google search found this (for the revised simplex). Also Pan (2014) has a chapter on "Pivot Rule". |
Thanks, this looks very useful! |
d7e6d56
to
a57af7f
Compare
@oyamad I've reorganized the commit history -- is this good for you? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just went through entire code and have effectively nothing useful to say. I made one comment in a file about being consistent between Roman numerals and numbers. I didn't check the algorithm itself very carefully, but I'm convinced it is doing what we expect given that the code is giving the right answer to the (extensive) tests that you have included.
The only other thing that we might consider is moving this into the optimize
sub-package . What do @oyamad and @mmcky think about this?
quantecon/linprog_simplex.py
Outdated
|
||
infeasible_err_msg = "The problem appears to be infeasible" | ||
unbounded_obj = "The problem appears to be unbounded." | ||
max_iter_p1 = "The maximum number of iterations has been reached in Phase I" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small thing, but in max_iter_p2
you use "Phase 2" and in max_iter_p1
you use "Phase I" -- Either change this to "Phase 1" or the other to "Phase II" just to be consistent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cc7768 Thanks!
4390252
to
5259498
Compare
- Add `make_tableau` and `standardize_lp_problem` - Refactor `pivot_operation`, `min_ratio_test` and `lex_min_ratio_test`
- Return namedtuple with dual variables - Set default tolerance based on reference [3] - Modify tests to work with returning a namedtuple
df73c24
to
3f7ddd2
Compare
@QBatista is this still being worked on? Can we close these PR's |
@mmcky Yes, I'll close this PR for now. |
Implements the original simplex method using Bland's rule and accelerated with Numba to be used in the repeated games outerapproximation algorithm implementation.
Performance comparison
For assessing the performance, I picked one of the real-world problems from the NETLIB LP test problem set, which are available in Scipy (see here).
Line profiling
Limitations
The solver fails on some problems that can be solved using interior point methods such as
SHARE1B.npz
.Bland's rule can slow down the process massively. On the
BLEND.npz
example, the solver does not even reach phase II after more than 100 million iterations while Scipy's implementation without Bland's rule converges after 130 iterations. Scipy's implementation with Bland's rule did not converge after 500K iterations.Numerical instability causes issues for some real world problems. For example,
AGG.npz
fails with the default tolerance but gets very close to the solution if the tolerance is lowered to 1e-7. Scipy's interior-point method works on this problem with the default tolerance.@oyamad Should we aim to solve all the problems in Netlib LP? This is beyond the aim of this PR but it might be a nice goal if we want a fast and reliable LP solver.