BUG: optimize: using `integrality` prevents `linprog` from accepting a list for `c`
See original GitHub issueDescribe your issue.
If integrality
is used in linprog
, then c
must be a numpy array. Otherwise an exception is raised because c
does not have a shape
attribute.
The fix is probably as simple as passing c
through np.asarray()
first.
Reproducing Code Example
In [35]: from scipy.optimize import linprog
In [36]: linprog([1, 1], A_ub=[[-1, 0]], b_ub=[-2.5], integrality=[1, 1])
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In [36], line 1
----> 1 linprog([1, 1], A_ub=[[-1, 0]], b_ub=[-2.5], integrality=[1, 1])
File ~/repos/git/forks/scipy/build-install/lib/python3.10/site-packages/scipy/optimize/_linprog.py:623, in linprog(c, A_ub, b_ub, A_eq, b_eq, bounds, method, callback, options, x0, integrality)
621 warn(warning_message, OptimizeWarning)
622 elif np.any(integrality):
--> 623 integrality = np.broadcast_to(integrality, c.shape)
625 lp = _LPProblem(c, A_ub, b_ub, A_eq, b_eq, bounds, x0, integrality)
626 lp, solver_options = _parse_linprog(lp, options, meth)
AttributeError: 'list' object has no attribute 'shape'
Error message
See above.
SciPy/NumPy/Python version information
1.10.0.dev0+2184.5057eff 1.24.0.dev0+1048.g939910660 sys.version_info(major=3, minor=10, micro=8, releaselevel=‘final’, serial=0)
Issue Analytics
- State:
- Created 10 months ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
BUG: linprog integrality only accepts list, not array #16681
linprog (integrality=None) is documented as integrality : 1-D array, optional but it only accepts listlike and not array due to a conditional in...
Read more >scipy.optimize.linprog — SciPy v1.9.3 Manual
Guess values of the decision variables, which will be refined by the optimization algorithm. This argument is currently used only by the 'revised...
Read more >Linear Programming with Google or-tools in C++: Use ...
Is you problem purely integral? You can use the native CP-sat API. It is a better linear integer solver, and supports callback in...
Read more >MATLAB linprog - Solve linear programming problems
Solve a simple linear program with linear inequalities, linear equalities, and bounds. For this example, use these linear inequality constraints: x ( 1...
Read more >Mixed Integer Linear Programming with Python - Read the Docs
The model class represents the optimization model. The code below creates an empty Mixed-Integer. Linear Programming problem with default ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@nboudrie and I will be taking on this issue.
This was fixed by https://github.com/scipy/scipy/pull/17513.