How can I implement constraints of x1 not equal to x2 in intlinprog ?

6 views (last 30 days)
Considering that mixed integer linear programming has a discontinuous search space this should be possible. my current implementation tries to use something like abs(x1-x2)>=E but I end up with a no feasible region error.
  1 Comment
RJ on 20 Apr 2018
to note: Splitting the abs function into two separate inequalities does not lead to a feasible space and that is the exact problem I am trying to solve here. thank you

Sign in to comment.

Answers (2)

Alan Weiss
Alan Weiss on 23 Apr 2018
I'm not sure that this is the best approach, but I think that it is a correct approach. Assume that x1 and x2 are each bounded by M, so |x1 - x2| <= 2 M. Define two binary (Boolean) variables y1 and y2 as control variables. Tie them to the optimization as follows:
x1 - x2 - 2*M*y1 <= 0; % ensures y1 = 1 when x1 - x2 >= 1
x1 - x2 - 2*M*y1 >= -2*M + 1 % ensures y1 = 0 when x1 - x2 <= 0
x2 - x1 - 2*M*y2 <= 0;
x2 - x1 - 2*M*y2 >= -2*M + 1
y1 + y2 >= 1;
The first constraint ensures that y1 = 1 whenever x1 > x2. The second constraint ensures that y1 = 0 whenever x1 <= x2, so these two constraints together ensure that y1 is the indicator function that x1 > x2. The third and fourth constraints are the parallel to the first, and ensure that y2 is the indicator function of x2 > x1. The last constraint ensures that at least one of y1 and y2 is 1.
I think that this is correct, but I am not sure that it is the most efficient formulation. Might as well give it a try and see.
Alan Weiss
MATLAB mathematical toolbox documentation

Stephan on 23 Apr 2018
im highly interested in that question and i hope anybody has a better answer then me. I found that in the forum so far:
Maybe this will help you.
Best Regards

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by