Skip to content
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

ENH: modularize presolve in linprog #11691 #12510

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f463c83
Update presolve framework (initial step)
janvle Mar 2, 2020
e84067a
Remove semicolon
janvle Mar 2, 2020
232bc0c
Update if-branches _clean_input()
janvle Mar 10, 2020
f7bad2d
Comment line to explain sign reversal in _get_Abc
janvle Mar 10, 2020
6762307
Remove build log
janvle Mar 10, 2020
467cd2a
Missing tox.ini
janvle Mar 10, 2020
4233745
Merge branch 'master' into presolve
janvle Mar 10, 2020
2e5f937
Update presolve changes so far
janvle Mar 12, 2020
061ac48
Fix errors in presolve row singleton removal
janvle Mar 12, 2020
1e3514b
Update other presolve-routines and presolve itself
janvle Mar 13, 2020
7876d37
Merge remote-tracking branch 'upstream/master'
janvle Mar 18, 2020
57dcafa
Merge branch 'revstack' into presolve
janvle Mar 21, 2020
f34b291
Introduce modular implementation of _presolve()
janvle Mar 29, 2020
25af139
Add presolve summary to linprog result structure
janvle Apr 6, 2020
c47d26f
Ouput presolve results
janvle Apr 28, 2020
8ae73d6
Merge remote-tracking branch 'upstream/master'
janvle Jul 5, 2020
00d3e85
Merge branch 'master' into presolve
janvle Jul 5, 2020
70494ed
Update presolve routines and associated tests
janvle Jul 6, 2020
e726f66
Modify equalities feasibility check for sparse matrices
janvle Jul 7, 2020
8d16b73
Update _presolve_infeasible_inequality_constraints()
janvle Jul 7, 2020
80bd64a
Decrease number of calls to sparse __get_item, to speed up presolve i…
janvle Jul 7, 2020
c6348bb
Removed spurious comments and test with dense matrices G and H in _pr…
janvle Jul 7, 2020
98e3cff
Update test__presolve.py tests
janvle Jul 7, 2020
84f3b1c
Redo updates to test__prosolve.py
janvle Jul 8, 2020
9c4cb6e
Merge remote-tracking branch 'upstream/master'
janvle Jul 8, 2020
33de625
Merge branch 'master' into presolve
janvle Jul 8, 2020
c4da5a4
Disable warning in modified _remove_redundancy.py
janvle Jul 8, 2020
05ccf96
Change sparse format intermediat matrices from CSR to LIL
janvle Jul 8, 2020
f09b046
Add files via upload
janvle Jul 8, 2020
bda2a1a
Merge branch 'presolve' of https://github.com/janvle/scipy into presolve
janvle Jul 8, 2020
a0422c5
Update test__presolve.py to conform to PEP8
janvle Jul 8, 2020
0bc033d
Revert unintended changes to .gitmodules
janvle Jul 10, 2020
ef50b47
Revert unintended change (sphinx theme)
janvle Jul 10, 2020
3857745
Revert unintended change: directory scipy-mathjax
janvle Jul 10, 2020
6bb8402
Revert unintended delete: scipychanges.patch
janvle Jul 10, 2020
a65a814
Revert unintended change: missing scipychanges.patch
janvle Jul 10, 2020
1db9caf
Add files via upload
janvle Jul 10, 2020
cd18687
Merge remote-tracking branch 'refs/remotes/origin/presolve' into pres…
janvle Jul 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
[submodule "doc/scipy-sphinx-theme"]
path = doc/scipy-sphinx-theme
url = https://github.com/scipy/scipy-sphinx-theme.git
[submodule "doc/sphinxext"]
path = doc/sphinxext
url = https://github.com/numpy/numpydoc.git
[submodule "doc/source/_static/scipy-mathjax"]
path = doc/source/_static/scipy-mathjax
url = https://github.com/scipy/scipy-mathjax.git
1 change: 0 additions & 1 deletion doc/scipy-sphinx-theme
Submodule scipy-sphinx-theme deleted from 59c27f
1 change: 0 additions & 1 deletion doc/source/_static/scipy-mathjax
Submodule scipy-mathjax deleted from 3d21c5
1 change: 0 additions & 1 deletion doc/sphinxext
Submodule sphinxext deleted from 278cf2
13 changes: 0 additions & 13 deletions scipy/_lib/_uarray/scipychanges.patch

This file was deleted.

30 changes: 18 additions & 12 deletions scipy/optimize/_linprog.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,50 +506,55 @@ def linprog(c, A_ub=None, b_ub=None, A_eq=None, b_eq=None,
x: array([10., -3.]) # may vary

"""
meth = method.lower()

meth = method.lower()
if x0 is not None and meth != "revised simplex":
warning_message = "x0 is used only when method is 'revised simplex'. "
warn(warning_message, OptimizeWarning)

lp = _LPProblem(c, A_ub, b_ub, A_eq, b_eq, bounds, x0)

lp, solver_options = _parse_linprog(lp, options)
tol = solver_options.get('tol', 1e-9)

iteration = 0
complete = False # will become True if solved in presolve
undo = []
complete = False # will become True if solved in presolve
revstack = []

# Keep the original arrays to calculate slack/residuals for original
# problem.
lp_o = deepcopy(lp)

# Solve trivial problem, eliminate variables, tighten bounds, etc.
c0 = 0 # we might get a constant term in the objective
if solver_options.pop('presolve', True):
rr = solver_options.pop('rr', True)
(lp, c0, x, undo, complete, status, message) = _presolve(lp, rr, tol)
(lp, revstack, complete, status, message, presolve_effect) = _presolve(lp, rr, tol)
else:
message = None
presolve_effect = None

C, b_scale = 1, 1 # for trivial unscaling if autoscale is not used
postsolve_args = (lp_o._replace(bounds=lp.bounds), undo, C, b_scale)
postsolve_args = (lp_o._replace(bounds=lp.bounds), revstack, C, b_scale)

if not complete:
A, b, c, c0, x0 = _get_Abc(lp, c0)
if complete:
x = np.zeros(lp.c.shape)
else:
A, b, c, _, x0 = _get_Abc(lp, 0)
Copy link
Contributor

@mdhaber mdhaber Jul 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you eliminated the need for c0 entirely? If the option 'disp': True will the value of the original objective function at each iteration print correctly? Will the correct value of the objective function be sent to any callback functions? If so, _get_Abc doesn't need to return it, and _linprog_simplex etc... don't need to accept it as an argument; we can remove the idea from the code.

if solver_options.pop('autoscale', False):
A, b, c, x0, C, b_scale = _autoscale(A, b, c, x0)
postsolve_args = postsolve_args[:-2] + (C, b_scale)

if meth == 'simplex':
x, status, message, iteration = _linprog_simplex(
c, c0=c0, A=A, b=b, callback=callback,
c, c0=0, A=A, b=b, callback=callback,
postsolve_args=postsolve_args, **solver_options)
elif meth == 'interior-point':
x, status, message, iteration = _linprog_ip(
c, c0=c0, A=A, b=b, callback=callback,
c, c0=0, A=A, b=b, callback=callback,
postsolve_args=postsolve_args, **solver_options)
elif meth == 'revised simplex':
x, status, message, iteration = _linprog_rs(
c, c0=c0, A=A, b=b, x0=x0, callback=callback,
c, c0=0, A=A, b=b, x0=x0, callback=callback,
postsolve_args=postsolve_args, **solver_options)
else:
raise ValueError('Unknown solver %s' % method)
Expand All @@ -572,6 +577,7 @@ def linprog(c, A_ub=None, b_ub=None, A_eq=None, b_eq=None,
'status': status,
'message': message,
'nit': iteration,
'success': status == 0}
'success': status == 0,
'presolve': presolve_effect}

return OptimizeResult(sol)
Loading