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
The following code runs correctly for count = 2, but fails with count = 1.
#!/usr/bin/env python
from cylp.cy import CyClpSimplex
from cylp.py.modeling.CyLPModel import CyLPArray
count = 2
s = CyClpSimplex()
x = s.addVariable('x', count)
s += 0.0 <= x <= 10.0
s.objective = CyLPArray([20]*count) * x
s.optimizationDirection = 'max'
status = s.primal()
result = s.primalVariableSolution['x']
print(status)
print(result)
The error raised:
meh.py:9: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
x = s.addVariable('x', count)
meh.py:12: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
s += 0.0 <= x <= 10.0
Traceback (most recent call last):
File "meh.py", line 14, in <module>
s.objective = CyLPArray([20]*count) * x
File "CyClpSimplex.pyx", line 141, in cylp.cy.CyClpSimplex.CyClpSimplex.objective.__set__ (cylp/cy/CyClpSimplex.cpp:4559)
File "CyClpSimplex.pyx", line 1192, in cylp.cy.CyClpSimplex.CyClpSimplex.setObjectiveArray (cylp/cy/CyClpSimplex.cpp:17461)
ValueError: Buffer has wrong number of dimensions (expected 1, got 0)
This can be worked around by adding another variable, which can be completely unconstrained and not included in the objective function definition. However, this shouldn't be required.
The text was updated successfully, but these errors were encountered:
I had a similar issue and worked around it by deleting an "np.squeeze" operation in CyLPModel.py, which transforms an np.array([[0]]) into np.array(0).
I guess deleting that operation in the function def objective(...): could make your case work.
I found another example that leads to a very similar error message but removing the 2 np.squeeze at the beginning of the CyLPConstraint.perform() did not solve it:
Traceback (most recent call last):
File "...", line 7, in <module>
s.objective = x.sum()
File "cylp/cy/CyClpSimplex.pyx", line 147, in cylp.cy.CyClpSimplex.CyClpSimplex.objective.__set__
File "cylp/cy/CyClpSimplex.pyx", line 1207, in cylp.cy.CyClpSimplex.CyClpSimplex.setObjectiveArray
ValueError: Buffer has wrong number of dimensions (expected 1, got 0)
The following code runs correctly for
count = 2
, but fails withcount = 1
.The error raised:
This can be worked around by adding another variable, which can be completely unconstrained and not included in the objective function definition. However, this shouldn't be required.
The text was updated successfully, but these errors were encountered: