coin-or / coin-or/CyLP

Cylp model for lower bound to be numpy matrix in the constraint

Open
#111 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JetBrains MPS
Stars
192
Forks
70
PR merge metrics
No merged PRs in 30d

Description

It seems that Cylp model doesn't support both the upper bound and lower bound to be numpy array.
Do you plan to add this feature?
```
import numpy as np
from cylp.cy import CyClpSimplex
from cylp.py.modeling.CyLPModel import CyLPArray

A = [[50, 31], [-3, 2, ]]
b_l = [-10000, -10000]
b_u = [250, 4]
c = [-1, -0.64]
l = [1, 0]
u = [10000, 10000]

model = CyClpSimplex()
x = model.addVariable('x', len(c))
A = np.matrix(A)
b_l = np.matrix(b_l)
# b_l = -1000
b_u = np.matrix(b_u)
l = CyLPArray(l)
u = CyLPArray(u)
c = CyLPArray(c)
model += (b_l <= A * x <= b_u)
model += l <= x <= u
model.objective = c * x

model.primal()
# print(model.getBasisStatus())
print(model.primalConstraintSolution) # row value
print(model.primalVariableSolutionAll) # row slack

print(model.dualConstraintSolution) # dual variable
print(model.dualVariableSolution) # dual slack
```

If I run this code, it will get the following error.
```
Traceback (most recent call last):
File "/media/dxy/mathu-solver/cylp_tesp.py", line 21, in
model += (b_l <= A * x <= b_u)
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.