Use max operation in a constraint in Linear Programming

I have liner programme with set of $x_{3n}$ variables where $x_{ij}$ are {0,1}. I am solving this linear programme using LP-Solve.

Using these variables, I want to form following constraint :

$max(x_1 , x_2.., x_n) + max(x_{n+1} , x_{n+2}.. , x_{2n}) + max(x_{2n+1} , x_{2n+2}..., x_{3n}) >= q$

Constraint is : Sum of max variable in set of variables should be greater than q.

How can I write constraint using $max$ operation in LP Solve?

• Brute force over the possibilities for which inputs are maximal. ​ ​ – user12859 Feb 25 '16 at 10:45
• Max over 0/1 variables is the same as logical OR. See cs.stackexchange.com/q/12102/755 for some techniques you can try. – D.W. Feb 25 '16 at 12:00
• What is it now, an LP or IP? – Raphael Feb 25 '16 at 15:25
• @ Raphael..it is LP but values of decision variables can be binary only. – Abhay Feb 28 '16 at 6:59
• It's not LP if the variables are restricted to be binary or integers. That's called ILP (integer linear programming). – D.W. Feb 29 '16 at 0:19

Introduce variables $m_1,m_2,m_3$ to represent the three maxes.

Add the linear inequality $m_1 + m_2 + m_3 \ge q$.

Then, add the following extra inequalities for $m_1$:

• $0 \le m_1 \le 1$
• $m_1 \le x_1 + x_2 + \dots + x_n$
• $x_1 \le m_1$, $x_2 \le m_1$, $\dots$, $x_n \le m_1$

and similarly for $m_2$ and $m_3$.

• @ D.W. thanks ..it's working :). Previously I followed the second answer given in the link you shared but it was taking too much time to solve the problem. – Abhay Feb 28 '16 at 6:56
• ,I did, but to show and display it publicly I have to earn 15 reputations :(. I will definitely do once I earn 15 reputations. – Abhay Mar 1 '16 at 4:13
• @D.W. I understand the necessity for the final bullet point and was able to come up with it independently, but could you explain the reason for the other two? It seems the other two would happen implicitly due to constraints on x_i. – Christian Mar 22 '18 at 20:25
• @Christian, the first is necessary, otherwise we might find a solution where $m_1$ is bigger than 1 (which won't be the max of $x_1,\dots,x_n$). The second is necessary, otherwise we might have $x_1=\cdots=x_n=0$ but $m_1=1$ (which wouldn't be the max). – D.W. Mar 22 '18 at 21:08
• @D.W. Thanks for clarifying. I was thinking through the lens of a minimization problem where those things would be impossible and hadn't considered the more general case. – Christian Mar 23 '18 at 21:53