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

Allowing non-negative integer variables #1446

Closed
Midnighter opened this issue Jul 21, 2021 · 3 comments
Closed

Allowing non-negative integer variables #1446

Midnighter opened this issue Jul 21, 2021 · 3 comments

Comments

@Midnighter
Copy link

Is your feature request related to a problem? Please describe.

I don't understand why it should not be possible to create non-negative integer variables. At the moment, this is forbidden due to the following exception being raised:

counts = cp.Variable(shape=5, integer=True, nonneg=True)
ValueError: Cannot set more than one special attribute in Variable.

Describe the solution you'd like

I don't see why this should pose a problem and it would just require some special casing for the logic that raises the ValueError.

Describe alternatives you've considered

I know that I can add a constraint counts >= 0 but counts.sign is 'UNKNOWN' when it should really be 'NONNEGATIVE'.

@SteveDiamond
Copy link
Collaborator

The reason we forbid this is because we project the optimal value of variables returned by the solver onto the constraints encoded in the variable attributes, and in the fully general case of arbitrary attributes this becomes another convex optimization problem (e.g., PSD + nonneg). Whereas if we restrict things to a single attribute then we have closed form solutions.

This particular combination of attributes is of course simple and could in theory be supported. But I'm not super comfortable permitting multiple attributes in some cases but not others.

@Midnighter
Copy link
Author

Alright. Fair enough.

@rileyjmurray
Copy link
Collaborator

rileyjmurray commented Jul 22, 2021

@Midnighter if you need counts.sign == "NONNEGATIVE" for DCP reasons, then you could probably add a nonneg_wrap atom much like our psd_wrap atom: https://github.com/cvxpy/cvxpy/blob/master/cvxpy/atoms/affine/wraps.py.

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

3 participants