# If then Constraint

 2 Hello all: I want to implement the following constraint in my linear programing model: If A=B then C=1 Else C=0 I have been looking around and there are similar problems but nobody has been helpful to address the 'non equal to' condition. Thank you in advance. asked 27 Sep '14, 17:45 Chicago 33●1●5 accept rate: 0%

 3 As I understand the question, you want $$c$$ to be binary, and $$c=1$$ if and only if $$A=B$$. I will make a couple of assumptions: There is a (large) positive $$M$$ such that $$|A-B|\le M$$ for every feasible $$(A,B)$$. There is a (small) positive $$\epsilon$$ such that whenever $$A\neq B$$, we can assume there is a solution satisfying $$|A-B| \ge \epsilon$$. Here's the formulation: \begin{align} A &\le B + My - \epsilon z \\ B &\le A + Mz - \epsilon y \\ c+y+z&=1 \\ c,y,z &\in \{0,1\} \end{align} Now, if $$c=1$$, then $$y=z=0$$. In this case, the constraints reduce to $$A \le B$$ and $$B \le A$$, so $$A=B$$. Otherwise, $$c=0$$. Then $$y+z=1$$. There are two cases. In the first case, $$y=1,z=0$$. Then the constraints reduce to $$A \le B + M$$, which is always satisfied, and $$B \le A-\epsilon$$, which implies $$B < A$$. In the second case, $$y=0,z=1$$. The analysis in this case is similar and implies $$A < B$$. So if $$c=0$$, then $$A \neq B$$. You can also reduce the number of variables by replacing all occurrences of $$z$$ by $$1-c-y$$. But, the MIP solver will probably do this anyway. answered 27 Sep '14, 19:46 Austin Buchanan 1.3k●5●13 accept rate: 42% Thank you so much! This was indeed helpful! Kudos! (27 Sep '14, 21:55) Chicago
 0 I would suggest the usage of an indicator constraint. I had a similar problem which is when @Florian suggested the usage of an indicator constraint. More information could be found in the cplex docs. You can find the syntax for the appropriate language over there. link text Thanks to Florian answered 16 Oct '14, 05:17 crypto 67●2●7 accept rate: 0%
 toggle preview community wiki

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "Title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

Tags:

×28
×14
×6
×1