add constraint for slack variables
- Dominant language
- JetBrains MPS
- Stars
- 192
- Forks
- 70
- PR merge metrics
- No merged PRs in 30d
Description
Hello, I'm writing the cutting plane algorithm. I want to add constraints to cut the original solution.
I find that it is not supported to add constraints for the slack variables in Cylp. I find that Cylp Model only supports the CylpVar. Model.variables doesn't include slack variables, so I can't use CylpModel to add constraint.
And I find that CLP_addConstraint doesn't support slack variables, either.
This is the code
```
def CLP_addConstraint(self, numberInRow,
np.ndarray[np.int32_t, ndim=1] columns,
np.ndarray[np.double_t, ndim=1] elements,
rowLower,
rowUpper):
'''
Add a constraint to the problem, CLP style. See CLP documentation.
Not commonly used in cylp.
For cylp modeling tool see :mod:`cylp.python.modeling.CyLPModel`.
'''
# TODO: This makes adding a row real slower,
# but it is better than a COIN EXCEPTION!
if (columns >= self.nVariables).any():
raise Exception('CyClpSimplex.pyx:addConstraint: Column ' \
'index out of range (number of columns: ' \
'%d)' % (self.nVariables))
self.CppSelf.addRow(numberInRow, columns.data,
elements.data, rowLower, rowUpper)
```
If I comment the if lines and use slack variables in the constraint.
For a two variables problem, it will return an error.
```
model.CLP_addConstraint(4,np.array([0,1,2,3],dtype=np.dtype(np.int32)),np.array([1.,2.,3.,4.]),-10,10)
Column index out of range(number of columns 2)
```
If there are some difficulties, I will try to use original variables to represent the constraint like Cuppy.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.