question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: optimize: using `integrality` prevents `linprog` from accepting a list for `c`

See original GitHub issue

Describe 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:closed
  • Created 10 months ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jgborchcommented, Nov 9, 2022

@nboudrie and I will be taking on this issue.

0reactions
WarrenWeckessercommented, Dec 2, 2022
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found