2

Given a 1-dimensional array of binary variables, for example

x = [0,1,0,0,1] 

I would like to create a new variable y such that y <= max(x). In other words

y = 0 only if sum(x) = 0.

y = 1 only if sum(x) > 0.

How do I convert this into a set of linear constraints?

I know this must be possible because IBM CP Optimizer Suite can handle this automatically, but I don't have access to it.

1 Answer 1

3

Try something simple like y <= sum(x) which will force y to zero if all the x are zero.

Then for forcing y to 1 you have several choices. You could simply add a constraint that y >= x for every variable in x, or use a big M constraint like My >= sum(x) where M is some constant which is the maximum number of variables in x that can be simultaneously equal to 1. Adding the separate constraints might give a tighter linear relaxation, especially if there are many x variables.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.