In a linear program, I would like some variables to: 1. Take the same values 2. Group some variables i.e. some variables should take same values or lie within certain percentage. 3. All different values

The objective function is given by: enter image description here

  • $\begingroup$ You specified $x_i \ge 0$ for all $i$. For (2), did you maybe mean $>0$ instead of $\ge 0$? $\endgroup$ – RobPratt Apr 30 at 0:53
  • $\begingroup$ Yes, I intended to say greater than zero in (2) and not greater than equal to $\endgroup$ – Sam Apr 30 at 9:08

(1) This is correct, and there's nothing wrong with having a whole lot of constraints that each require $x_6 = x_j$ for some $j$. But if you know in advance that these variables will all equal each other, why not just define a new variable that equals all of them? That is, create a variable $x_{6-10}$ that equals $x_6$ through $x_{10}$ and use this variable everywhere any of the $x_6$ through $x_{10}$ variables appear?

(2) Using the logic described here, you can create a binary variable $y_6$ that equals 1 if $x_6 \ge 0$, and another binary variable $y_8$ that equals 1 if $x_8 \ge 0$. Then you can enforce the "if-then" implications using the logic described here.

(3) Some solvers have a built-in feature that allows you to specify that certain variables must be different from each other; see Matrix in ampl: constraint that the values ​are all different. But I think this only works for integer variables. For continuous variables, I think you need to use big-Ms for this, although maybe others will chime in with better ideas.

| improve this answer | |
  • $\begingroup$ Thank you. As Rob pointed out the ambiguity in my question (2), I intended to say greater than zero in (2) and not greater than equal to zero. Would this change your answer? $\endgroup$ – Sam Apr 30 at 9:09
  • $\begingroup$ You can't really do strict inequalities for continuous variables. The best you can do is something like $x_i \ge \delta$ for some small $\delta > 0$. Then the logic described in the answers linked to above still applies. $\endgroup$ – LarrySnyder610 Apr 30 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.