Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add constraint for slack variables #112

Open
abdxyz opened this issue Dec 9, 2020 · 0 comments
Open

add constraint for slack variables #112

abdxyz opened this issue Dec 9, 2020 · 0 comments

Comments

@abdxyz
Copy link

abdxyz commented Dec 9, 2020

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, <int*>columns.data,
                            <double*>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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant